Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Network.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : UnRaider
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Network
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments:
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History -------------------------------------------------
  17. *
  18. * 2002.06.21:
  19. * Mongoose - Created
  20. =================================================================*/
  21. #include <Network.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. extern network_frame_t gPiggyBack;
  26. void from_network_layer(network_packet_t *p, unsigned int *last_id)
  27. {
  28. static unsigned int i = 0;
  29. if (!p)
  30. {
  31. return;
  32. }
  33. *last_id = i++;
  34. sleep(1);
  35. p->send = 1;
  36. p->pos[0] = i*3;
  37. p->pos[1] = i*3+1;
  38. p->pos[2] = i*3+2;
  39. printf("<S>ending { %f %f %f }\n", p->pos[0], p->pos[1], p->pos[2]);
  40. }
  41. void to_network_layer(network_packet_t p)
  42. {
  43. printf("<R>ecieved { %f %f %f }\n", p.pos[0], p.pos[1], p.pos[2]);
  44. gPiggyBack.data.pos[0] = gPiggyBack.seq*4;
  45. gPiggyBack.data.pos[1] = gPiggyBack.seq*4+1;
  46. gPiggyBack.data.pos[2] = gPiggyBack.seq*4+2;
  47. gPiggyBack.data.send = 1;
  48. gPiggyBack.data.yaw = 90.0f;
  49. }
  50. int main(int argc, char *argv[])
  51. {
  52. printf("\n\n[Network class test]\n");
  53. Network &test = *Network::Instance();
  54. if (argc > 3)
  55. {
  56. if (argv[1][1] == 'v')
  57. {
  58. test.setDebug(true);
  59. }
  60. switch (argv[1][0])
  61. {
  62. case 'c':
  63. test.setRemoteHost(argv[2]);
  64. test.setPort(atoi(argv[3]));
  65. test.runClient();
  66. break;
  67. case 's':
  68. test.setBindHost(argv[2]);
  69. test.setPort(atoi(argv[3]));
  70. test.runServer();
  71. break;
  72. default:
  73. printf("Error in command line, run %s for help\n", argv[0]);
  74. }
  75. }
  76. else if (argc > 2)
  77. {
  78. test.setPort(atoi(argv[2]));
  79. test.runServer();
  80. }
  81. else
  82. {
  83. printf("Server: %s s [bind_host_name] port\n", argv[0]);
  84. printf("Client: %s c remote_host_name remote_host_port\n", argv[0]);
  85. printf("Append 'v' behind c/s option for verbose. eg cv\n");
  86. }
  87. killNetworkSingleton();
  88. return 0;
  89. }