CommonExampleInterface.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef COMMON_EXAMPLE_INTERFACE_H
  2. #define COMMON_EXAMPLE_INTERFACE_H
  3. struct CommandProcessorCreationInterface
  4. {
  5. virtual ~CommandProcessorCreationInterface() {}
  6. virtual class CommandProcessorInterface* createCommandProcessor() = 0;
  7. virtual void deleteCommandProcessor(CommandProcessorInterface*) = 0;
  8. };
  9. struct CommonExampleOptions
  10. {
  11. struct GUIHelperInterface* m_guiHelper;
  12. //Those are optional, some examples will use them others don't. Each example should work with them being 0.
  13. int m_option;
  14. const char* m_fileName;
  15. class SharedMemoryInterface* m_sharedMem;
  16. CommandProcessorCreationInterface* m_commandProcessorCreation;
  17. bool m_skipGraphicsUpdate;
  18. CommonExampleOptions(struct GUIHelperInterface* helper, int option = 0)
  19. : m_guiHelper(helper),
  20. m_option(option),
  21. m_fileName(0),
  22. m_sharedMem(0),
  23. m_commandProcessorCreation(0),
  24. m_skipGraphicsUpdate(false)
  25. {
  26. }
  27. };
  28. class CommonExampleInterface
  29. {
  30. public:
  31. typedef class CommonExampleInterface*(CreateFunc)(CommonExampleOptions& options);
  32. virtual ~CommonExampleInterface()
  33. {
  34. }
  35. virtual void initPhysics() = 0;
  36. virtual void exitPhysics() = 0;
  37. virtual void updateGraphics() {}
  38. virtual void stepSimulation(float deltaTime) = 0;
  39. virtual void renderScene() = 0;
  40. virtual void physicsDebugDraw(int debugFlags) = 0; //for now we reuse the flags in Bullet/src/LinearMath/btIDebugDraw.h
  41. //reset camera is only called when switching demo. this way you can restart (initPhysics) and watch in a specific location easier
  42. virtual void resetCamera(){};
  43. virtual bool mouseMoveCallback(float x, float y) = 0;
  44. virtual bool mouseButtonCallback(int button, int state, float x, float y) = 0;
  45. virtual bool keyboardCallback(int key, int state) = 0;
  46. virtual void vrControllerMoveCallback(int controllerId, float pos[4], float orientation[4], float analogAxis, float auxAnalogAxes[10]) {}
  47. virtual void vrControllerButtonCallback(int controllerId, int button, int state, float pos[4], float orientation[4]) {}
  48. virtual void vrHMDMoveCallback(int controllerId, float pos[4], float orientation[4]) {}
  49. virtual void vrGenericTrackerMoveCallback(int controllerId, float pos[4], float orientation[4]) {}
  50. virtual void processCommandLineArgs(int argc, char* argv[]){};
  51. };
  52. class ExampleEntries
  53. {
  54. public:
  55. virtual ~ExampleEntries() {}
  56. virtual void initExampleEntries() = 0;
  57. virtual void initOpenCLExampleEntries() = 0;
  58. virtual int getNumRegisteredExamples() = 0;
  59. virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index) = 0;
  60. virtual const char* getExampleName(int index) = 0;
  61. virtual const char* getExampleDescription(int index) = 0;
  62. virtual int getExampleOption(int index) = 0;
  63. };
  64. CommonExampleInterface* StandaloneExampleCreateFunc(CommonExampleOptions& options);
  65. #ifdef B3_USE_STANDALONE_EXAMPLE
  66. #define B3_STANDALONE_EXAMPLE(ExampleFunc) \
  67. CommonExampleInterface* StandaloneExampleCreateFunc(CommonExampleOptions& options) \
  68. { \
  69. return ExampleFunc(options); \
  70. }
  71. #else //B3_USE_STANDALONE_EXAMPLE
  72. #define B3_STANDALONE_EXAMPLE(ExampleFunc)
  73. #endif //B3_USE_STANDALONE_EXAMPLE
  74. #endif //COMMON_EXAMPLE_INTERFACE_H