Torque3D Documentation / _generateds / physicsPlugin.h

physicsPlugin.h

Engine/source/T3D/physics/physicsPlugin.h

More...

Classes:

Public Defines

define

Helper macro for accessing the physics plugin.

Public Typedefs

CreatePhysicsObjectFn 

Detailed Description

Public Defines

PHYSICSMGR() ()

Helper macro for accessing the physics plugin.

It will return NULL if no plugin is initialized.

Public Typedefs

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