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   /// Allow gpu acceleration if supported
101   static bool smGpuAccelerationAllowed;
102   static bool gpuAccelerationAllowed() { return smGpuAccelerationAllowed; }
103
104   ///
105   static bool activate( const char *library );
106
107   PhysicsPlugin();
108   virtual ~PhysicsPlugin();
109
110   /// Cleans up, deactivates, and deletes the plugin.
111   virtual void destroyPlugin() = 0;
112
113   virtual void reset() = 0;
114
115   /// Returns the physics cleanup set.
116   SimSet* getPhysicsCleanup() const { return mPhysicsCleanup; }      
117
118   void enableDebugDraw( bool enabled );
119
120   virtual PhysicsCollision* createCollision() = 0;
121
122   virtual PhysicsBody* createBody() = 0;
123
124   virtual PhysicsPlayer* createPlayer() = 0;
125
126   virtual bool isSimulationEnabled() const = 0;
127   virtual void enableSimulation( const String &worldName, bool enable ) = 0;
128
129   virtual void setTimeScale( const F32 timeScale ) = 0;
130   virtual const F32 getTimeScale() const = 0;
131
132   static PhysicsResetSignal& getPhysicsResetSignal() { return smPhysicsResetSignal; } 
133
134   virtual bool createWorld( const String &worldName ) = 0;
135   virtual void destroyWorld( const String &worldName ) = 0;
136
137   virtual PhysicsWorld* getWorld( const String &worldName ) const = 0;
138
139protected:
140
141   /// Overload this to toggle any physics engine specific stuff
142   /// when debug rendering is enabled or disabled.
143   virtual void _onDebugDrawEnabled( bool enabled ) {}
144
145};
146
147/// Helper macro for accessing the physics plugin.  It will
148/// return NULL if no plugin is initialized.
149/// @see PhysicsPlugin
150#define PHYSICSMGR PhysicsPlugin::getSingleton()
151
152#endif // _T3D_PHYSICS_PHYSICSPLUGIN_H_
153