physicsPlugin.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _T3D_PHYSICS_PHYSICSPLUGIN_H_
  23. #define _T3D_PHYSICS_PHYSICSPLUGIN_H_
  24. #ifndef _SIMSET_H_
  25. #include "console/simSet.h"
  26. #endif
  27. #ifndef _TSIGNAL_H_
  28. #include "core/util/tSignal.h"
  29. #endif
  30. #ifndef _TORQUE_STRING_H_
  31. #include "core/util/str.h"
  32. #endif
  33. #ifndef _TDICTIONARY_H_
  34. #include "core/util/tDictionary.h"
  35. #endif
  36. #ifndef _UTIL_DELEGATE_H_
  37. #include "core/util/delegate.h"
  38. #endif
  39. #ifndef _T3D_PHYSICSCOMMON_H_
  40. #include "T3D/physics/physicsCommon.h"
  41. #endif
  42. class Player;
  43. class SceneRenderState;
  44. class SceneManager;
  45. class SceneObject;
  46. class PhysicsObject;
  47. class PhysicsBody;
  48. class PhysicsWorld;
  49. class PhysicsPlayer;
  50. class PhysicsCollision;
  51. typedef Delegate<PhysicsObject*( const SceneObject *)> CreatePhysicsObjectFn;
  52. typedef Map<StringNoCase, CreatePhysicsObjectFn> CreateFnMap;
  53. ///
  54. class PhysicsPlugin
  55. {
  56. protected:
  57. /// The current active physics plugin.
  58. static PhysicsPlugin* smSingleton;
  59. static PhysicsResetSignal smPhysicsResetSignal;
  60. // Our map of Strings to PhysicsWorld pointers.
  61. Map<StringNoCase, PhysicsWorld*> mPhysicsWorldLookup;
  62. static String smServerWorldName;
  63. static String smClientWorldName;
  64. /// A SimSet of objects to delete before the
  65. /// physics reset/restore event occurs.
  66. SimObjectPtr<SimSet> mPhysicsCleanup;
  67. /// Delegate method for debug drawing.
  68. static void _debugDraw( SceneManager *graph, const SceneRenderState *state );
  69. public:
  70. /// Note this should go away when we have "real" singleplayer.
  71. static bool smSinglePlayer;
  72. static bool isSinglePlayer() { return smSinglePlayer; }
  73. /// Number of threads to use if supported by the plugin.
  74. static U32 smThreadCount;
  75. static U32 getThreadCount() { return smThreadCount; }
  76. /// Returns the active physics plugin.
  77. /// @see PHYSICSPLUGIN
  78. static PhysicsPlugin* getSingleton() { return smSingleton; }
  79. /// Allow gpu acceleration if supported
  80. static bool smGpuAccelerationAllowed;
  81. static bool gpuAccelerationAllowed() { return smGpuAccelerationAllowed; }
  82. ///
  83. static bool activate( const char *library );
  84. PhysicsPlugin();
  85. virtual ~PhysicsPlugin();
  86. /// Cleans up, deactivates, and deletes the plugin.
  87. virtual void destroyPlugin() = 0;
  88. virtual void reset() = 0;
  89. /// Returns the physics cleanup set.
  90. SimSet* getPhysicsCleanup() const { return mPhysicsCleanup; }
  91. void enableDebugDraw( bool enabled );
  92. virtual PhysicsCollision* createCollision() = 0;
  93. virtual PhysicsBody* createBody() = 0;
  94. virtual PhysicsPlayer* createPlayer() = 0;
  95. virtual bool isSimulationEnabled() const = 0;
  96. virtual void enableSimulation( const String &worldName, bool enable ) = 0;
  97. virtual void setTimeScale( const F32 timeScale ) = 0;
  98. virtual const F32 getTimeScale() const = 0;
  99. static PhysicsResetSignal& getPhysicsResetSignal() { return smPhysicsResetSignal; }
  100. virtual bool createWorld( const String &worldName ) = 0;
  101. virtual void destroyWorld( const String &worldName ) = 0;
  102. virtual PhysicsWorld* getWorld( const String &worldName ) const = 0;
  103. protected:
  104. /// Overload this to toggle any physics engine specific stuff
  105. /// when debug rendering is enabled or disabled.
  106. virtual void _onDebugDrawEnabled( bool enabled ) {}
  107. };
  108. /// Helper macro for accessing the physics plugin. It will
  109. /// return NULL if no plugin is initialized.
  110. /// @see PhysicsPlugin
  111. #define PHYSICSMGR PhysicsPlugin::getSingleton()
  112. #endif // _T3D_PHYSICS_PHYSICSPLUGIN_H_