main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2015 Google Inc. http://bulletphysics.org
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #include "PhysicsServerExample.h"
  14. #include "PhysicsClientExample.h"
  15. #include "Bullet3Common/b3CommandLineArgs.h"
  16. #include "../CommonInterfaces/CommonExampleInterface.h"
  17. #include "../CommonInterfaces/CommonGUIHelperInterface.h"
  18. #include "SharedMemoryCommon.h"
  19. #include <stdlib.h>
  20. int gSharedMemoryKey = -1;
  21. static SharedMemoryCommon* example = NULL;
  22. static bool interrupted = false;
  23. #ifndef _WIN32
  24. #include <signal.h>
  25. #include <err.h>
  26. #include <unistd.h>
  27. static void cleanup(int signo)
  28. {
  29. if (interrupted) { // this is the second time, we're hanging somewhere
  30. // if (example) {
  31. // example->abort();
  32. // }
  33. b3Printf("Aborting and deleting SharedMemoryCommon object");
  34. sleep(1);
  35. delete example;
  36. errx(EXIT_FAILURE, "aborted example on signal %d", signo);
  37. }
  38. interrupted = true;
  39. warnx("caught signal %d", signo);
  40. }
  41. #endif//_WIN32
  42. int main(int argc, char* argv[])
  43. {
  44. #ifndef _WIN32
  45. struct sigaction action;
  46. memset(&action, 0x0, sizeof(action));
  47. action.sa_handler = cleanup;
  48. static const int signos[] = { SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGSEGV, SIGPIPE, SIGTERM };
  49. for (int ii(0); ii < sizeof(signos) / sizeof(*signos); ++ii) {
  50. if (0 != sigaction(signos[ii], &action, NULL)) {
  51. err(EXIT_FAILURE, "signal %d", signos[ii]);
  52. }
  53. }
  54. #endif
  55. b3CommandLineArgs args(argc, argv);
  56. DummyGUIHelper noGfx;
  57. CommonExampleOptions options(&noGfx);
  58. args.GetCmdLineArgument("shared_memory_key", gSharedMemoryKey);
  59. if (args.CheckCmdLineFlag("client"))
  60. {
  61. example = (SharedMemoryCommon*)PhysicsClientCreateFunc(options);
  62. }else
  63. {
  64. // options.m_option |= PHYSICS_SERVER_ENABLE_COMMAND_LOGGING;
  65. // options.m_option |= PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG;
  66. example = (SharedMemoryCommon*)PhysicsServerCreateFunc(options);
  67. }
  68. example->initPhysics();
  69. while (example->isConnected() && !(example->wantsTermination() || interrupted))
  70. {
  71. example->stepSimulation(1.f/60.f);
  72. }
  73. example->exitPhysics();
  74. delete example;
  75. return 0;
  76. }