main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "OpenGLExampleBrowser.h"
  2. #include "Bullet3Common/b3CommandLineArgs.h"
  3. #include "../Utils/b3Clock.h"
  4. #include "ExampleEntries.h"
  5. #include "Bullet3Common/b3Logging.h"
  6. #include "../Importers/ImportObjDemo/ImportObjExample.h"
  7. #include "../Importers/ImportBsp/ImportBspExample.h"
  8. #include "../Importers/ImportColladaDemo/ImportColladaSetup.h"
  9. #include "../Importers/ImportSTLDemo/ImportSTLSetup.h"
  10. #include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
  11. #include "../Importers/ImportSDFDemo/ImportSDFSetup.h"
  12. #include "../Importers/ImportSTLDemo/ImportSTLSetup.h"
  13. #include "../Importers/ImportBullet/SerializeSetup.h"
  14. #include "LinearMath/btAlignedAllocator.h"
  15. static double gMinUpdateTimeMicroSecs = 1000.;
  16. static bool interrupted = false;
  17. static OpenGLExampleBrowser* sExampleBrowser = 0;
  18. #ifndef _WIN32
  19. #include <signal.h>
  20. #include <err.h>
  21. #include <unistd.h>
  22. static void cleanup(int signo)
  23. {
  24. if (!interrupted)
  25. { // this is the second time, we're hanging somewhere
  26. b3Printf("Aborting and deleting SharedMemoryCommon object");
  27. delete sExampleBrowser;
  28. sleep(1);
  29. sExampleBrowser = 0;
  30. errx(EXIT_FAILURE, "aborted example on signal %d", signo);
  31. }
  32. else
  33. {
  34. b3Printf("no action");
  35. exit(EXIT_FAILURE);
  36. }
  37. interrupted = true;
  38. warnx("caught signal %d", signo);
  39. }
  40. #endif //_WIN32
  41. int main(int argc, char* argv[])
  42. {
  43. #ifndef _WIN32
  44. struct sigaction action;
  45. memset(&action, 0x0, sizeof(action));
  46. action.sa_handler = cleanup;
  47. static const int signos[] = {SIGHUP, SIGINT, SIGQUIT, SIGABRT, SIGSEGV, SIGPIPE, SIGTERM};
  48. for (int ii(0); ii < sizeof(signos) / sizeof(*signos); ++ii)
  49. {
  50. if (0 != sigaction(signos[ii], &action, NULL))
  51. {
  52. err(EXIT_FAILURE, "signal %d", signos[ii]);
  53. }
  54. }
  55. #endif
  56. {
  57. b3CommandLineArgs args(argc, argv);
  58. b3Clock clock;
  59. args.GetCmdLineArgument("minUpdateTimeMicroSecs", gMinUpdateTimeMicroSecs);
  60. ExampleEntriesAll examples;
  61. examples.initExampleEntries();
  62. OpenGLExampleBrowser* exampleBrowser = new OpenGLExampleBrowser(&examples);
  63. sExampleBrowser = exampleBrowser; //for <CTRL-C> etc, cleanup shared memory
  64. bool init = exampleBrowser->init(argc, argv);
  65. exampleBrowser->registerFileImporter(".urdf", ImportURDFCreateFunc);
  66. exampleBrowser->registerFileImporter(".sdf", ImportSDFCreateFunc);
  67. exampleBrowser->registerFileImporter(".obj", ImportObjCreateFunc);
  68. exampleBrowser->registerFileImporter(".stl", ImportSTLCreateFunc);
  69. exampleBrowser->registerFileImporter(".bullet", SerializeBulletCreateFunc);
  70. clock.reset();
  71. if (init)
  72. {
  73. do
  74. {
  75. float deltaTimeInSeconds = clock.getTimeMicroseconds() / 1000000.f;
  76. if (deltaTimeInSeconds > 0.1)
  77. {
  78. deltaTimeInSeconds = 0.1;
  79. }
  80. if (deltaTimeInSeconds < (gMinUpdateTimeMicroSecs / 1e6))
  81. {
  82. b3Clock::usleep(gMinUpdateTimeMicroSecs / 10.);
  83. }
  84. else
  85. {
  86. clock.reset();
  87. exampleBrowser->update(deltaTimeInSeconds);
  88. }
  89. } while (!exampleBrowser->requestedExit() && !interrupted);
  90. }
  91. delete exampleBrowser;
  92. }
  93. #ifdef BT_DEBUG_MEMORY_ALLOCATIONS
  94. int numBytesLeaked = btDumpMemoryLeaks();
  95. btAssert(numBytesLeaked == 0);
  96. #endif //BT_DEBUG_MEMORY_ALLOCATIONS
  97. return 0;
  98. }