Spinning Topp Logo BlackTopp Studios
inc
physicsmanager.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _physicsphysicsmanager_cpp
41 #define _physicsphysicsmanager_cpp
42 
43 #include "Physics/physicsmanager.h"
44 #include "Physics/collision.h"
45 
46 #include "Physics/ghostproxy.h"
47 #include "Physics/rigidproxy.h"
48 #include "Physics/softproxy.h"
49 
50 #include "Physics/conetwistconstraint.h"
51 #include "Physics/gearconstraint.h"
52 #include "Physics/generic6dofconstraint.h"
53 #include "Physics/generic6dofspringconstraint.h"
54 #include "Physics/hingeconstraint.h"
55 #include "Physics/hinge2constraint.h"
56 #include "Physics/point2pointconstraint.h"
57 #include "Physics/sliderconstraint.h"
58 #include "Physics/universalconstraint.h"
59 
60 #include "Graphics/graphicsmanager.h"
61 
62 // WorldObject Manager includes are here for the debug draw work unit dependency setting
63 #include "actormanager.h"
64 #include "areaeffectmanager.h"
65 #include "debrismanager.h"
66 
67 #include "stringtool.h"
68 #include "linegroup.h"
69 #include "vector3.h"
70 #include "worldtrigger.h"
71 #include "worldobject.h"
72 #include "crossplatform.h"
73 #include "entresol.h"
74 #include "world.h"
75 #include "timer.h"
76 
77 #include "Physics/collisiondispatcher.h.cpp"
78 
79 #include <queue>
80 #include <algorithm>
81 
82 #include <btBulletDynamicsCommon.h>
83 #include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
84 #include <BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h>
85 #include <BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h>
86 #include <BulletCollision/CollisionDispatch/btGhostObject.h>
87 
88 // This define is needed to avoid a declaration collision for uint64_t between a bullet typedef and the one in stdint.h
89 #define __PHYSICS_COMMON_H__ 1
90 
91 #ifdef MEZZ_WINDOWS
92 #include <BulletMultiThreaded/Win32ThreadSupport.h>
93 #else
94 #include <BulletMultiThreaded/PosixThreadSupport.h>
95 #endif
96 
97 #include <BulletMultiThreaded/btParallelConstraintSolver.h>
98 #include <BulletMultiThreaded/SpuGatheringCollisionDispatcher.h>
99 #include <BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h>
100 
101 
102 namespace Mezzanine
103 {
104  /// @internal
105  /// @namespace Mezzanine::debug
106  /// @brief This namespace is for internal debugging tools. In general it shouldn't be used in game code.
107  /// @details This whole debug namespace is a dirty hack. This is where internal only classes and functions go
108  /// that can and maybe should be ommited from release builds
109  namespace debug
110  {
111  /// @internal
112  /// @class InternalDebugDrawer
113  /// @brief This is used to draw wireframse for the Physics subsystem
114  class InternalDebugDrawer : public btIDebugDraw
115  {
116  private:
117  /// @internal
118  /// @brief This stores the wireframe being used for rendering.
119  Mezzanine::LineGroup* WireFrame;
120  /// @internal
121  /// @brief A pointer to the safe logger for debug output.
122  Mezzanine::Logger* ErrorLogger;
123  /// @internal
124  /// @brief This stores whether or not to render physics debug lines
125  /// @details This stores whether or not to render physics debud lines. 0 = Do not draw anything. 1 = Draw model wireframes.
126  /// Later we will add support for contact drawing, individual modeling drawing, etc...
127  int DebugDrawing;
128 
129  /// @brief Parent World To draw in
130  World* ParentWorld;
131 
132  public:
133  /// @internal
134  /// @brief Basic Constructor
135  InternalDebugDrawer(World * ParentWorld);
136  /// @internal
137  /// @brief Destructor
138  virtual ~InternalDebugDrawer();
139 
140  /// @internal
141  /// @brief Clears data as necessary for updating debug geometry.
142  virtual void PrepareForUpdate();
143  /// @internal
144  /// @brief Copies all the line data to render buffers so they can be seen on screen.
145  virtual void FinalizeUpdate();
146 
147  /// @internal
148  /// @brief This will prepare a line segment for being drawn
149  /// @details This adds the points for a line to the internal list of points to be rendered.
150  /// @param from The first point of the line
151  /// @param to The second point of the line
152  /// @param color Currently ignored
153  virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
154  /// @internal
155  /// @brief Currently Unused
156  /// @details Currently Unused
157  /// @param PointOnB Currently Unused
158  /// @param normalOnB Currently Unused
159  /// @param distance Currently Unused
160  /// @param lifeTime Currently Unused
161  /// @param color Currently Unused
162  virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color);
163  /// @internal
164  /// @brief Currently Unused
165  /// @details Currently Unused
166  /// @param location Currently Unused
167  /// @param textString Currently Unused
168  virtual void draw3dText(const btVector3& location, const char* textString);
169 
170  /// @internal
171  /// @brief This is used to decide how much the debug render should draw
172  /// @details Currently this accepts btIDebugDraw::DBG_NoDebug or btIDebugDraw::DBG_DrawWireframe and setting these will either start or stop
173  /// Wireframe rendering. All other btIDebugDraw values are ignored.
174  /// @param debugMode An Int which contains either btIDebugDraw::DBG_NoDebug or btIDebugDraw::DBG_DrawWireframe
175  virtual void setDebugMode(int debugMode);
176  /// @internal
177  /// @brief This will return the current debug mode.
178  /// @details Currently this can only return btIDebugDraw::DBG_NoDebug or btIDebugDraw::DBG_DrawWireframe
179  /// @return Returns the Current debug mode, currently either btIDebugDraw::DBG_NoDebug or btIDebugDraw::DBG_DrawWireframe
180  virtual int getDebugMode() const;
181 
182  /// @internal
183  /// @brief Sets the safe logger to sent debug output to.
184  /// @param Logger A pointer to the safe logger for debug output.
185  virtual void SetLogger(Mezzanine::Logger* Logger);
186  /// @internal
187  /// @brief Used by the physics subsystem to report errors using the renderer
188  /// @details We *Believe* that this is used by the physics subsystem to report errors about rendering to the developer/user. As such, we
189  /// Have redirected all input from this function to the Entresol::Log function.
190  /// @param warningString We *Believe* These are messagesfrom the physics subsystem, and that this should not directly called otherwise
191  virtual void reportErrorWarning(const char* warningString);
192  };
193 
195  WireFrame(NULL),
196  DebugDrawing(Physics::DDM_NoDebug),
197  ParentWorld(ParentWorld)
198  { }
199 
201  {
202  if( this->WireFrame != NULL )
203  delete this->WireFrame;
204  }
205 
207  {
208  if( this->WireFrame == NULL ) {
209  this->WireFrame = new Mezzanine::LineGroup(this->ParentWorld);
210  if( this->DebugDrawing != Physics::DDM_NoDebug ) {
211  this->WireFrame->AddToWorld();
212  }
213  }
214  this->WireFrame->AddToWorld();
215  this->WireFrame->ClearLines();
216  }
217 
219  {
220  this->WireFrame->DrawLines();
221  }
222 
223  void InternalDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
224  { this->WireFrame->DrawLine( Vector3(from), Vector3(to), ColourValue(color.getX(),color.getY(),color.getZ()) ); }
225 
226  void InternalDebugDrawer::drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
227  { }
228 
229  void InternalDebugDrawer::draw3dText(const btVector3& location,const char* textString)
230  { }
231 
233  {
234  this->DebugDrawing = debugMode;
235  if( this->WireFrame != NULL ) {
236  if( this->DebugDrawing != Physics::DDM_NoDebug ) {
237  this->WireFrame->AddToWorld();
238  }else{
239  this->WireFrame->RemoveFromWorld();
240  }
241  }
242  }
243 
245  { return this->DebugDrawing; }
246 
248  { this->ErrorLogger = Logger; }
249 
250  void InternalDebugDrawer::reportErrorWarning(const char* warningString)
251  { (*this->ErrorLogger) << warningString << std::endl; }
252  }// debug
253 
254  #ifdef GetObject
255  #undef GetObject
256  #endif
257  namespace Physics
258  {
259  ///////////////////////////////////////////////////////////
260  // SimulationWorkUnit functions
261 
262  SimulationWorkUnit::SimulationWorkUnit(const SimulationWorkUnit& Other)
263  { }
264 
265  SimulationWorkUnit& SimulationWorkUnit::operator=(const SimulationWorkUnit& Other)
266  { return *this; }
267 
268  SimulationWorkUnit::SimulationWorkUnit(PhysicsManager* Target) :
269  TargetManager(Target) { }
270 
272  { }
273 
274  ///////////////////////////////////////////////////////////////////////////////
275  // Utility
276 
278  { this->TargetManager->DoPerFrameWork(CurrentThreadStorage); }
279 
280  ///////////////////////////////////////////////////////////
281  // SimulationMonopolyWorkUnit functions
282 
283  SimulationMonopolyWorkUnit::SimulationMonopolyWorkUnit(const SimulationMonopolyWorkUnit& Other)
284  { }
285 
286  SimulationMonopolyWorkUnit& SimulationMonopolyWorkUnit::operator=(const SimulationMonopolyWorkUnit& Other)
287  { return *this; }
288 
289  SimulationMonopolyWorkUnit::SimulationMonopolyWorkUnit(PhysicsManager* Target) :
290  TargetManager(Target) { }
291 
293  { }
294 
295  ///////////////////////////////////////////////////////////////////////////////
296  // Utility
297 
299  {}
300 
302  { return this->TargetManager->ThreadCount; }
303 
305  { this->TargetManager->DoPerFrameWork(CurrentThreadStorage); }
306 
307  ///////////////////////////////////////////////////////////
308  // WorldTriggerUpdate functions
309 
311  { }
312 
314  { return *this; }
315 
317  TargetManager(Target) { }
318 
320  { }
321 
322  ///////////////////////////////////////////////////////////////////////////////
323  // Utility
324 
326  {
327  // No real logging necessary
329  }
330 
331  ///////////////////////////////////////////////////////////
332  // DebugDrawWorkUnit functions
333 
335  { }
336 
338  { return *this; }
339 
341  TargetManager(Target) { }
342 
344  { }
345 
346  ///////////////////////////////////////////////////////////////////////////////
347  // Utility
348 
350  {
351  // No real logging necessary
353  Drawer->SetLogger( &CurrentThreadStorage.GetUsableLogger() );
354  if( Drawer && Drawer->getDebugMode() ) //this part is responsible for drawing the wireframes
355  {
356  Drawer->PrepareForUpdate();
357  this->TargetManager->BulletDynamicsWorld->debugDrawWorld();
358  Drawer->FinalizeUpdate();
359  }
360  Drawer->SetLogger(NULL);
361  }
362 
363  ///////////////////////////////////////////////////////////
364  // Physicsmanager functions
365 
366  const String PhysicsManager::ImplementationName = "DefaultPhysicsManager";
367  const ManagerBase::ManagerType PhysicsManager::InterfaceType = ManagerBase::MT_PhysicsManager;
368 
370  WorldManager(Creator),
371  StepSize(1.0/60.0),
372  TimeMultiplier(1.0),
373  DebugRenderMode(0),
374  SubstepModifier(1),
375  ThreadCount(0),
376  SimulationPaused(false),
377 
378  GhostCallback(NULL),
379  BulletSolverThreads(NULL),
380  BulletDispatcherThreads(NULL),
381  BulletBroadphase(NULL),
382  BulletCollisionConfiguration(NULL),
383  BulletDispatcher(NULL),
384  BulletSolver(NULL),
385  BulletDynamicsWorld(NULL),
386  BulletDrawer(NULL),
387 
388  SimulationWork(NULL),
389  WorldTriggerUpdateWork(NULL),
390  DebugDrawWork(NULL)
391  {
394  this->Construct(Info);
395  }
396 
398  WorldManager(Creator),
399  StepSize(1.0/60.0),
400  TimeMultiplier(1.0),
401  DebugRenderMode(0),
402  SubstepModifier(1),
403  ThreadCount(0),
404  SimulationPaused(false),
405 
406  GhostCallback(NULL),
407  BulletSolverThreads(NULL),
408  BulletDispatcherThreads(NULL),
409  BulletBroadphase(NULL),
410  BulletCollisionConfiguration(NULL),
411  BulletDispatcher(NULL),
412  BulletSolver(NULL),
413  BulletDynamicsWorld(NULL),
414  BulletDrawer(NULL),
415 
416  SimulationWork(NULL),
417  WorldTriggerUpdateWork(NULL),
418  DebugDrawWork(NULL)
419  {
420  this->Construct(Info);
421  }
422 
423  PhysicsManager::PhysicsManager(World* Creator, const XML::Node& XMLNode) :
424  WorldManager(Creator),
425  StepSize(1.0/60.0),
426  TimeMultiplier(1.0),
427  DebugRenderMode(0),
428  SubstepModifier(1),
429  ThreadCount(0),
430  SimulationPaused(false),
431 
432  GhostCallback(NULL),
433  BulletSolverThreads(NULL),
434  BulletDispatcherThreads(NULL),
435  BulletBroadphase(NULL),
436  BulletCollisionConfiguration(NULL),
437  BulletDispatcher(NULL),
438  BulletSolver(NULL),
439  BulletDynamicsWorld(NULL),
440  BulletDrawer(NULL),
441 
442  SimulationWork(NULL),
443  WorldTriggerUpdateWork(NULL),
444  DebugDrawWork(NULL)
445  {
447  XML::Attribute CurrAttrib;
448 
449  XML::Node WorldSettings = XMLNode.GetChild("WorldSettings");
450  if(!WorldSettings.Empty()) {
451  CurrAttrib = WorldSettings.GetAttribute("LimitlessWorld");
452  if(!CurrAttrib.Empty()) {
454  }else{
455  CurrAttrib = WorldSettings.GetAttribute("WorldUpperBounds");
456  if(!CurrAttrib.Empty())
458  CurrAttrib = WorldSettings.GetAttribute("WorldLowerBounds");
459  if(!CurrAttrib.Empty())
461  CurrAttrib = WorldSettings.GetAttribute("MaxProxies");
462  if(!CurrAttrib.Empty())
463  Info.MaxProxies = CurrAttrib.AsWhole();
464  }
465  CurrAttrib = WorldSettings.GetAttribute("SoftRigidWorld");
466  if(!CurrAttrib.Empty()) {
468  }
469  CurrAttrib = WorldSettings.GetAttribute("MultiThreaded");
470  if(!CurrAttrib.Empty()) {
472  }
473  }
474 
475  this->Construct(Info);
476 
477  XML::Node StepModifier = XMLNode.GetChild("SubStepModifier");
478  if(!StepModifier.Empty()) {
479  CurrAttrib = WorldSettings.GetAttribute("Modifier");
480  if(!CurrAttrib.Empty()) {
482  }
483  }
484 
485  XML::Node DebugRender = XMLNode.GetChild("DebugRendering");
486  if(!DebugRender.Empty()) {
487  int RenderMode = 0;
488  CurrAttrib = WorldSettings.GetAttribute("RenderingMode");
489  if(!CurrAttrib.Empty())
490  RenderMode = CurrAttrib.AsInt();
491 
492  if(0 != RenderMode) {
493  this->SetDebugRenderingMode(RenderMode);
494  }
495  }
496  }
497 
499  {
500  btCollisionObjectArray ObjectArray( BulletDynamicsWorld->getCollisionObjectArray() );
501  for( Integer X = 0 ; X < BulletDynamicsWorld->getNumCollisionObjects() ; ++X )
502  {
503  CollidableProxy* Prox = static_cast<CollidableProxy*>( ObjectArray[X]->getUserPointer() );
504  Prox->RemoveFromWorld();
505  }
506 
507  this->DestroyAllConstraints();
508  this->DestroyAllProxies();
509  this->DestroyAllWorldTriggers();
510 
511  this->Deinitialize();
512 
513  //Destroy the physical world that we loved and cherished
514  this->Destroy();
515  }
516 
518  {
519  this->CallBackWorld = NULL;
521 
522  // Create the broadphase
524  this->BulletBroadphase = new btDbvtBroadphase();
525  }else{
526  if( Info.MaxProxies < 65536 ) {
527  this->BulletBroadphase = new btAxisSweep3(Info.GeographyLowerBounds.GetBulletVector3(),
529  Info.MaxProxies);
530  }else{
531  this->BulletBroadphase = new bt32BitAxisSweep3(Info.GeographyLowerBounds.GetBulletVector3(),
533  Info.MaxProxies);
534  }
535  }
536 
537  // Create the collision configuration
538  //if( Info.PhysicsFlags & ManagerConstructionInfo::PCF_SoftRigidWorld ) {
539  this->BulletCollisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
540  /*}else{
541  this->BulletCollisionConfiguration = new btDefaultCollisionConfiguration();
542  }// */
543 
544  // Create the dispatcher (narrowphase)
546  #ifdef MEZZ_WINDOWS
547  Win32ThreadSupport::Win32ThreadConstructionInfo BulletThreadInfo( "DispatcherThreads",
548  processCollisionTask,
549  createCollisionLocalStoreMemory,
550  ThreadCount );
551  this->BulletDispatcherThreads = new Win32ThreadSupport(BulletThreadInfo);
552  #else //WINDOWS
553  PosixThreadSupport::ThreadConstructionInfo BulletThreadInfo( "DispatcherThreads",
554  processCollisionTask,
555  createCollisionLocalStoreMemory,
556  ThreadCount );
557  this->BulletDispatcherThreads = new PosixThreadSupport(BulletThreadInfo);
558  #endif //WINDOWS
560  }else{
562  }
563 
564  // Create the constraint solver
565  /*if( Info.PhysicsFlags & ManagerConstructionInfo::PCF_Multithreaded ) {
566  #ifdef MEZZ_WINDOWS
567  Win32ThreadSupport::Win32ThreadConstructionInfo BulletThreadInfo( "SolverThreads",
568  SolverThreadFunc,
569  SolverlsMemoryFunc,
570  ThreadCount );
571  this->BulletSolverThreads = new Win32ThreadSupport(BulletThreadInfo);
572  #else //WINDOWS
573  PosixThreadSupport::ThreadConstructionInfo BulletThreadInfo( "SolverThreads",
574  SolverThreadFunc,
575  SolverlsMemoryFunc,
576  ThreadCount );
577  this->BulletSolverThreads = new PosixThreadSupport(BulletThreadInfo);
578  #endif //WINDOWS
579  this->BulletSolver = new btParallelConstraintSolver(this->BulletSolverThreads);
580  }else{// */
581  this->BulletSolver = new btSequentialImpulseConstraintSolver();
582  //}
583 
584  // Create the world
585  //if( Info.PhysicsFlags & ManagerConstructionInfo::PCF_SoftRigidWorld ) {
586  this->BulletDynamicsWorld = new btSoftRigidDynamicsWorld( this->BulletDispatcher,
587  this->BulletBroadphase,
588  this->BulletSolver,
590  /*}else{
591  this->BulletDynamicsWorld = new btDiscreteDynamicsWorld( this->BulletDispatcher,
592  this->BulletBroadphase,
593  this->BulletSolver,
594  this->BulletCollisionConfiguration);
595  }// */
596 
597  // Set up the work units
599  this->SimulationWork = new SimulationMonopolyWorkUnit(this);
600  }else{
601  this->SimulationWork = new SimulationWorkUnit(this);
602  }
604  this->DebugDrawWork = new DebugDrawWorkUnit(this);
605 
606  // Configure the extra data
607  btGImpactCollisionAlgorithm::registerAlgorithm(this->BulletDispatcher);
608 
609  this->GhostCallback = new btGhostPairCallback();
610  this->BulletBroadphase->getOverlappingPairCache()->setInternalGhostPairCallback(this->GhostCallback);
611 
612  this->BulletDynamicsWorld->setInternalTickCallback((btInternalTickCallback)PhysicsManager::InternalTickCallback,0,false);
613 
614  this->BulletDynamicsWorld->getWorldInfo().m_dispatcher = this->BulletDispatcher;
615  this->BulletDynamicsWorld->getWorldInfo().m_broadphase = this->BulletBroadphase;
616  this->BulletDynamicsWorld->getWorldInfo().m_sparsesdf.Initialize();
617 
618  this->BulletDynamicsWorld->getDispatchInfo().m_enableSPU = true;
619  this->BulletDynamicsWorld->getDispatchInfo().m_useContinuous = true;
620  //this->BulletDynamicsWorld->getSolverInfo().m_splitImpulse = true;
621  //this->BulletDynamicsWorld->getSolverInfo().m_numIterations = 20;
622  //this->BulletDynamicsWorld->getSolverInfo().m_globalCfm = 0.15;
623  //this->BulletDynamicsWorld->getSolverInfo().m_erp = 0.4;
624 
625  this->SetWorldGravity(Info.Gravity);
626  this->SetWorldSoftGravity(Info.Gravity);
627  this->WorldConstructionInfo = Info;
628  }
629 
631  {
632  delete this->BulletDynamicsWorld;
633  this->BulletDynamicsWorld = NULL;
634  delete this->BulletDispatcher;
635  this->BulletDispatcher = NULL;
636  delete this->BulletCollisionConfiguration;
637  this->BulletCollisionConfiguration = NULL;
638  delete this->BulletSolver;
639  this->BulletSolver = NULL;
640  delete this->BulletBroadphase;
641  this->BulletBroadphase = NULL;
642  delete this->GhostCallback;
643  this->GhostCallback = NULL;
644  if( this->BulletDrawer ) {
645  delete this->BulletDrawer;
646  this->BulletDrawer = NULL;
647  }
648  if( this->BulletSolverThreads ) {
649  delete this->BulletSolverThreads;
650  this->BulletSolverThreads = NULL;
651  }
652  if( this->BulletDispatcherThreads ) {
653  delete this->BulletDispatcherThreads;
654  this->BulletDispatcherThreads = NULL;
655  }
656 
657  delete this->SimulationWork;
658  this->SimulationWork = NULL;
659 
660  delete this->WorldTriggerUpdateWork;
661  this->WorldTriggerUpdateWork = NULL;
662 
663  delete this->DebugDrawWork;
664  this->DebugDrawWork = NULL;
665  }
666 
668  {
669  if( !Triggers.empty() )
670  {
671  for( std::vector<WorldTrigger*>::iterator Trig = Triggers.begin() ; Trig != Triggers.end() ; Trig++ )
672  {
673  if((*Trig)->ConditionsAreMet())
674  (*Trig)->ApplyTrigger();
675  }
676  }
677  }
678 
680  {
681  //Update the collisions that already exist as necessary
682  for( PhysicsManager::CollisionMapIterator ColIt = Collisions.begin() ; ColIt != Collisions.end() ; ColIt++ )
683  (*ColIt).second->Update();
684  //Process the collisions that are in the creation queue
686  static_cast<ParallelCollisionDispatcher*>( this->BulletDispatcher )->GetAlgoCreationQueue() :
687  static_cast<CollisionDispatcher*>( this->BulletDispatcher )->GetAlgoCreationQueue() );
688  if(AlgoQueue->empty())
689  return;
690  #ifdef MEZZDEBUG
691  /*StringStream logstream;
692  logstream << "Processing " << AlgoQueue->size() << " algorithms for collisions.";
693  Entresol::GetSingletonPtr()->Log(logstream.str());
694  Entresol::GetSingletonPtr()->DoMainLoopLogging();// */
695  #endif
696  btCollisionAlgorithm* NewAlgo = AlgoQueue->front();
697  while( NewAlgo != NULL )
698  {
699  /*for( PhysicsManager::CollisionMapIterator ColIt = this->Collisions.begin() ; ColIt != this->Collisions.end() ; ++ColIt )
700  {
701  if( NewAlgo == (*ColIt).second->InternalAlgo ) {
702 
703  break;
704  }
705  }// */
706  // Old method involving detecting the actual WorldObject pair
707  CollidableProxy* ProxA = NULL;
708  CollidableProxy* ProxB = NULL;
709  /// @todo This is an absurd round-about way to get the data we need,
710  /// and bullet will probably have to be extended to change this so it's actually good.
711  btBroadphasePairArray& PairArray = BulletBroadphase->getOverlappingPairCache()->getOverlappingPairArray();
712  for( Integer X = 0 ; X < PairArray.size() ; ++X )
713  {
714  if( NewAlgo == PairArray[X].m_algorithm ) {
715  btCollisionObject* COA = (btCollisionObject*)PairArray[X].m_pProxy0->m_clientObject;
716  ProxA = static_cast<CollidableProxy*>( COA->getUserPointer() );
717  btCollisionObject* COB = (btCollisionObject*)PairArray[X].m_pProxy1->m_clientObject;
718  ProxB = static_cast<CollidableProxy*>( COB->getUserPointer() );
719  break;
720  }
721  }
722 
723  if( ( ProxA != NULL && ProxA->GetCollisionResponse() ) && ( ProxB != NULL && ProxB->GetCollisionResponse() ) ) {
724  // Create the collision
725  CollidablePair NewPair(ProxA,ProxB);
726  /*PhysicsManager::CollisionMapIterator ColIt = Collisions.find(NewPair);
727  if(ColIt == Collisions.end()) {
728  Physics::Collision* NewCol = new Physics::Collision(ProxA,ProxB,NewAlgo);
729  //NewCol->GetActorA()->_NotifyCollisionState(NewCol,Physics::Collision::Col_Begin);
730  //NewCol->GetActorB()->_NotifyCollisionState(NewCol,Physics::Collision::Col_Begin);
731  Collisions.insert( CollisionSortPair(NewPair,NewCol) );
732  }// */
733  PhysicsManager::CollisionMapIterator ColIt = this->Collisions.begin();
734  while( ColIt != this->Collisions.end() )
735  {
736  if( NewAlgo == (*ColIt).second->InternalAlgo )
737  break;
738  ++ColIt;
739  }
740 
741  if( ColIt == this->Collisions.end() ) {
742  Physics::Collision* NewCol = new Physics::Collision(ProxA,ProxB,NewAlgo);
743  //NewCol->GetActorA()->_NotifyCollisionState(NewCol,Physics::Collision::Col_Begin);
744  //NewCol->GetActorB()->_NotifyCollisionState(NewCol,Physics::Collision::Col_Begin);
745  Collisions.insert( CollisionSortPair(NewPair,NewCol) );
746  }
747  }// */
748  AlgoQueue->pop_front();
749  if(AlgoQueue->size() > 0) NewAlgo = AlgoQueue->front();
750  else NewAlgo = NULL;
751  }// */
752  AlgoQueue->clear();
753  }
754 
756  void PhysicsManager::InternalTickCallback(btDynamicsWorld* world, btScalar timeStep)
757  {
758  if( CallBackWorld != NULL ) {
760  }
761  }
762 
763  ///////////////////////////////////////////////////////////////////////////////
764  // Simulation Management
765 
767  { this->SimulationPaused = Pause; }
768 
770  { return this->SimulationPaused; }
771 
773  { return TimeMultiplier; }
774 
776  { TimeMultiplier = value; }
777 
778  ///////////////////////////////////////////////////////////////////////////////
779  // Gravity Management
780 
782  { this->BulletDynamicsWorld->setGravity(pgrav.GetBulletVector3()); }
783 
785  {
786  Vector3 grav(this->BulletDynamicsWorld->getGravity());
787  return grav;
788  }
789 
791  { this->BulletDynamicsWorld->getWorldInfo().m_gravity = sgrav.GetBulletVector3(); }
792 
794  {
795  Vector3 sgrav(this->BulletDynamicsWorld->getWorldInfo().m_gravity);
796  return sgrav;
797  }
798 
799  ///////////////////////////////////////////////////////////////////////////////
800  // Creating Proxies
801 
803  {
804  GhostProxy* NewProxy = new GhostProxy(this->ProxyIDGen.GenerateID(),this);
805  this->Proxies.push_back(NewProxy);
806  return NewProxy;
807  }
808 
810  {
811  GhostProxy* NewProxy = new GhostProxy(this->ProxyIDGen.GenerateID(),Shape,this);
812  this->Proxies.push_back(NewProxy);
813  if( AddToWorld ) {
814  NewProxy->AddToWorld();
815  }
816  return NewProxy;
817  }
818 
820  {
821  GhostProxy* NewProxy = new GhostProxy(SelfRoot,this);
822  this->ProxyIDGen.ReserveID(NewProxy->GetProxyID());
823  this->Proxies.push_back(NewProxy);
824  return NewProxy;
825  }
826 
828  {
829  RigidProxy* NewProxy = new RigidProxy(this->ProxyIDGen.GenerateID(),Mass,this);
830  this->Proxies.push_back(NewProxy);
831  return NewProxy;
832  }
833 
834  RigidProxy* PhysicsManager::CreateRigidProxy(const Real Mass, CollisionShape* Shape, const Boole AddToWorld)
835  {
836  RigidProxy* NewProxy = new RigidProxy(this->ProxyIDGen.GenerateID(),Mass,Shape,this);
837  this->Proxies.push_back(NewProxy);
838  if( AddToWorld ) {
839  NewProxy->AddToWorld();
840  }
841  return NewProxy;
842  }
843 
845  {
846  RigidProxy* NewProxy = new RigidProxy(SelfRoot,this);
847  this->ProxyIDGen.ReserveID(NewProxy->GetProxyID());
848  this->Proxies.push_back(NewProxy);
849  return NewProxy;
850  }
851 
853  {
854  SoftProxy* NewProxy = new SoftProxy(this->ProxyIDGen.GenerateID(),Mass,this);
855  this->Proxies.push_back(NewProxy);
856  return NewProxy;
857  }
858 
860  {
861  SoftProxy* NewProxy = new SoftProxy(SelfRoot,this);
862  this->ProxyIDGen.ReserveID(NewProxy->GetProxyID());
863  this->Proxies.push_back(NewProxy);
864  return NewProxy;
865  }
866 
867  ///////////////////////////////////////////////////////////////////////////////
868  // Proxy Management
869 
871  { return this->Proxies.at(Index); }
872 
874  {
875  if( Mezzanine::PT_Physics_All_Proxies & Type ) {
876  for( ConstProxyIterator ProxIt = this->Proxies.begin() ; ProxIt != this->Proxies.end() ; ++ProxIt )
877  {
878  if( (*ProxIt)->GetProxyType() == Type ) {
879  if( 0 == Which ) return (*ProxIt);
880  else --Which;
881  }
882  }
883  }
884  return NULL;
885  }
886 
888  {
889  for( ConstProxyIterator ProxIt = this->Proxies.begin() ; ProxIt != this->Proxies.end() ; ++ProxIt )
890  {
891  if( (*ProxIt)->GetProxyID() == ID ) {
892  return (*ProxIt);
893  }
894  }
895  return NULL;
896  }
897 
899  { return this->Proxies.size(); }
900 
902  {
903  for( ProxyIterator ProxIt = this->Proxies.begin() ; ProxIt != this->Proxies.end() ; ++ProxIt )
904  {
905  if( ToBeDestroyed == (*ProxIt) ) {
906  WorldObject* Parent = (*ProxIt)->GetParentObject();
907  if( Parent )
908  Parent->_NotifyProxyDestroyed( (*ProxIt) );
909 
910  this->ProxyIDGen.ReleaseID( ToBeDestroyed->GetProxyID() );
911  delete (*ProxIt);
912  this->Proxies.erase(ProxIt);
913  return;
914  }
915  }
916  }
917 
919  {
920  for( ProxyIterator ProxIt = this->Proxies.begin() ; ProxIt != this->Proxies.end() ; ++ProxIt )
921  {
922  WorldObject* Parent = (*ProxIt)->GetParentObject();
923  if( Parent )
924  Parent->_NotifyProxyDestroyed( (*ProxIt) );
925 
926  this->ProxyIDGen.ReleaseID( (*ProxIt)->GetProxyID() );
927  delete (*ProxIt);
928  }
929  this->Proxies.clear();
930  }
931 
933  { return this->Proxies.begin(); }
934 
936  { return this->Proxies.end(); }
937 
939  { return this->Proxies.begin(); }
940 
942  { return this->Proxies.end(); }
943 
944  ///////////////////////////////////////////////////////////////////////////////
945  // Constraint Creation
946 
948  {
949  ConeTwistConstraint* NewConstraint = new ConeTwistConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
950  this->Constraints.push_back(NewConstraint);
951  return NewConstraint;
952  }
953 
955  {
956  ConeTwistConstraint* NewConstraint = new ConeTwistConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,TransA,this);
957  this->Constraints.push_back(NewConstraint);
958  return NewConstraint;
959  }
960 
962  {
963  ConeTwistConstraint* NewConstraint = new ConeTwistConstraint(SelfRoot,this);
964  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
965  this->Constraints.push_back(NewConstraint);
966  return NewConstraint;
967  }
968 
970  {
971  GearConstraint* NewConstraint = new GearConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,AxisA,AxisB,this);
972  this->Constraints.push_back(NewConstraint);
973  return NewConstraint;
974  }
975 
976  GearConstraint* PhysicsManager::CreateGearConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& AxisA, const Vector3& AxisB, const Real Ratio)
977  {
978  GearConstraint* NewConstraint = new GearConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,AxisA,AxisB,Ratio,this);
979  this->Constraints.push_back(NewConstraint);
980  return NewConstraint;
981  }
982 
984  {
985  GearConstraint* NewConstraint = new GearConstraint(SelfRoot,this);
986  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
987  this->Constraints.push_back(NewConstraint);
988  return NewConstraint;
989  }
990 
992  {
993  Generic6DofConstraint* NewConstraint = new Generic6DofConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
994  this->Constraints.push_back(NewConstraint);
995  return NewConstraint;
996  }
997 
999  {
1000  Generic6DofConstraint* NewConstraint = new Generic6DofConstraint(this->ConstraintIDGen.GenerateID(),ProxyB,TransB,this);
1001  this->Constraints.push_back(NewConstraint);
1002  return NewConstraint;
1003  }
1004 
1006  {
1007  Generic6DofConstraint* NewConstraint = new Generic6DofConstraint(SelfRoot,this);
1008  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1009  this->Constraints.push_back(NewConstraint);
1010  return NewConstraint;
1011  }
1012 
1014  {
1015  Generic6DofSpringConstraint* NewConstraint = new Generic6DofSpringConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
1016  this->Constraints.push_back(NewConstraint);
1017  return NewConstraint;
1018  }
1019 
1021  {
1022  Generic6DofSpringConstraint* NewConstraint = new Generic6DofSpringConstraint(SelfRoot,this);
1023  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1024  this->Constraints.push_back(NewConstraint);
1025  return NewConstraint;
1026  }
1027 
1028  HingeConstraint* PhysicsManager::CreateHingeConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& PivotInA, const Vector3& PivotInB, const Vector3& AxisInA, const Vector3& AxisInB)
1029  {
1030  HingeConstraint* NewConstraint = new HingeConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,PivotInA,PivotInB,AxisInA,AxisInB,this);
1031  this->Constraints.push_back(NewConstraint);
1032  return NewConstraint;
1033  }
1034 
1036  {
1037  HingeConstraint* NewConstraint = new HingeConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
1038  this->Constraints.push_back(NewConstraint);
1039  return NewConstraint;
1040  }
1041 
1043  {
1044  HingeConstraint* NewConstraint = new HingeConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,PivotInA,AxisInA,this);
1045  this->Constraints.push_back(NewConstraint);
1046  return NewConstraint;
1047  }
1048 
1050  {
1051  HingeConstraint* NewConstraint = new HingeConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,TransA,this);
1052  this->Constraints.push_back(NewConstraint);
1053  return NewConstraint;
1054  }
1055 
1057  {
1058  HingeConstraint* NewConstraint = new HingeConstraint(SelfRoot,this);
1059  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1060  this->Constraints.push_back(NewConstraint);
1061  return NewConstraint;
1062  }
1063 
1064  Hinge2Constraint* PhysicsManager::CreateHinge2Constraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& Anchor, const Vector3& Axis1, const Vector3& Axis2)
1065  {
1066  Hinge2Constraint* NewConstraint = new Hinge2Constraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,Anchor,Axis1,Axis2,this);
1067  this->Constraints.push_back(NewConstraint);
1068  return NewConstraint;
1069  }
1070 
1072  {
1073  Hinge2Constraint* NewConstraint = new Hinge2Constraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
1074  this->Constraints.push_back(NewConstraint);
1075  return NewConstraint;
1076  }
1077 
1079  {
1080  Hinge2Constraint* NewConstraint = new Hinge2Constraint(SelfRoot,this);
1081  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1082  this->Constraints.push_back(NewConstraint);
1083  return NewConstraint;
1084  }
1085 
1087  {
1088  Point2PointConstraint* NewConstraint = new Point2PointConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,PivotA,PivotB,this);
1089  this->Constraints.push_back(NewConstraint);
1090  return NewConstraint;
1091  }
1092 
1094  {
1095  Point2PointConstraint* NewConstraint = new Point2PointConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,PivotA,this);
1096  this->Constraints.push_back(NewConstraint);
1097  return NewConstraint;
1098  }
1099 
1101  {
1102  Point2PointConstraint* NewConstraint = new Point2PointConstraint(SelfRoot,this);
1103  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1104  this->Constraints.push_back(NewConstraint);
1105  return NewConstraint;
1106  }
1107 
1109  {
1110  SliderConstraint* NewConstraint = new SliderConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
1111  this->Constraints.push_back(NewConstraint);
1112  return NewConstraint;
1113  }
1114 
1116  {
1117  SliderConstraint* NewConstraint = new SliderConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,TransA,this);
1118  this->Constraints.push_back(NewConstraint);
1119  return NewConstraint;
1120  }
1121 
1123  {
1124  SliderConstraint* NewConstraint = new SliderConstraint(SelfRoot,this);
1125  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1126  this->Constraints.push_back(NewConstraint);
1127  return NewConstraint;
1128  }
1129 
1130  UniversalConstraint* PhysicsManager::CreateUniversalConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& Anchor, const Vector3& Axis1, const Vector3& Axis2)
1131  {
1132  UniversalConstraint* NewConstraint = new UniversalConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,Anchor,Axis1,Axis2,this);
1133  this->Constraints.push_back(NewConstraint);
1134  return NewConstraint;
1135  }
1136 
1138  {
1139  UniversalConstraint* NewConstraint = new UniversalConstraint(this->ConstraintIDGen.GenerateID(),ProxyA,ProxyB,TransA,TransB,this);
1140  this->Constraints.push_back(NewConstraint);
1141  return NewConstraint;
1142  }
1143 
1145  {
1146  UniversalConstraint* NewConstraint = new UniversalConstraint(SelfRoot,this);
1147  this->ConstraintIDGen.ReserveID(NewConstraint->GetConstraintID());
1148  this->Constraints.push_back(NewConstraint);
1149  return NewConstraint;
1150  }
1151 
1152  ///////////////////////////////////////////////////////////////////////////////
1153  // Constraint Management
1154 
1156  { return this->Constraints[Index]; }
1157 
1159  { return this->Constraints.size(); }
1160 
1162  {
1163  for( ConstraintIterator ConIt = this->Constraints.begin() ; ConIt < this->Constraints.end() ; ConIt++ )
1164  {
1165  if( (*ConIt) == Con ) {
1166  (*ConIt)->EnableConstraint(false);
1167  this->ConstraintIDGen.ReleaseID((*ConIt)->GetConstraintID());
1168  delete (*ConIt);
1169  this->Constraints.erase(ConIt);
1170  return;
1171  }
1172  }
1173  }
1174 
1176  {
1177  for( ConstraintIterator ConIt = this->Constraints.begin() ; ConIt != this->Constraints.end() ; ConIt++ )
1178  {
1179  (*ConIt)->EnableConstraint(false);
1180  this->ConstraintIDGen.ReleaseID((*ConIt)->GetConstraintID());
1181  delete (*ConIt);
1182  }
1183  this->Constraints.clear();
1184  }
1185 
1186  ///////////////////////////////////////////////////////////////////////////////
1187  // Trigger Management
1188 
1190  { this->Triggers.push_back(Trig); }
1191 
1193  {
1194  for( ConstWorldTriggerIterator Trig = this->Triggers.begin() ; Trig != this->Triggers.end() ; Trig++ )
1195  {
1196  if( Name == (*Trig)->GetName() ) {
1197  return *Trig;
1198  }
1199  }
1200  return NULL;
1201  }
1202 
1204  { return this->Triggers.at(Index); }
1205 
1207  { return this->Triggers.size(); }
1208 
1210  {
1211  for( WorldTriggerIterator T = this->Triggers.begin() ; T != this->Triggers.end() ; T++ )
1212  {
1213  if( Trig == (*T) ) {
1214  this->Triggers.erase(T);
1215  return;
1216  }
1217  }
1218  }
1219 
1221  {
1222  for( WorldTriggerIterator Trig = this->Triggers.begin() ; Trig != this->Triggers.end() ; Trig++ )
1223  delete (*Trig);
1224  this->Triggers.clear();
1225  }
1226 
1227  ///////////////////////////////////////////////////////////////////////////////
1228  // Collision Management
1229 
1231  {
1232  CollidablePair Pair(A,B);
1233  return this->GetCollision(&Pair);
1234  }
1235 
1237  {
1238  ConstCollisionMapIterator ColIt = this->Collisions.find(*Pair);
1239  if(ColIt != this->Collisions.end()) return (*ColIt).second;
1240  else return NULL;
1241  }
1242 
1244  { return this->Collisions.size(); }
1245 
1247  {
1248  //((CollisionDispatcher*)BulletDispatcher)->releaseManifoldManual(Col->Manifold);
1249  btBroadphasePair* btPair = this->BulletBroadphase->getOverlappingPairCache()->findPair(
1250  Col->ProxyA->_GetBasePhysicsObject()->getBroadphaseHandle(),
1251  Col->ProxyB->_GetBasePhysicsObject()->getBroadphaseHandle());
1252  this->BulletBroadphase->getOverlappingPairCache()->removeOverlappingPair(
1253  Col->ProxyA->_GetBasePhysicsObject()->getBroadphaseHandle(),
1254  Col->ProxyB->_GetBasePhysicsObject()->getBroadphaseHandle(),
1255  this->BulletDispatcher);// */
1256  this->BulletBroadphase->getOverlappingPairCache()->cleanOverlappingPair(*btPair,this->BulletDispatcher);
1257  delete btPair;
1258  }
1259 
1261  {
1262  // A proxy not in the world can't have collisions
1263  if( Proxy->IsInWorld() ) {
1264  this->BulletBroadphase->getOverlappingPairCache()->cleanProxyFromPairs( Proxy->_GetBasePhysicsObject()->getBroadphaseHandle(), this->BulletDispatcher );
1265 
1266  CollisionMapIterator ColIt = this->Collisions.begin();
1267  while( ColIt != this->Collisions.end() )
1268  {
1269  Physics::Collision* ToBeDestroyed = (*ColIt).second;
1270  if( Proxy == (*ColIt).second->ProxyA || Proxy == (*ColIt).second->ProxyB ) {
1271  CollisionMapIterator Delete = ColIt;
1272  ++ColIt;
1273  this->Collisions.erase(Delete);
1274  delete ToBeDestroyed;
1275  }else{
1276  ++ColIt;
1277  }
1278  }
1279  }
1280  }
1281 
1283  {
1284  for( CollisionMapIterator ColIt = this->Collisions.begin() ; ColIt != this->Collisions.end() ; ++ColIt )
1285  {
1286  delete (*ColIt).second;
1287  }
1288  this->Collisions.clear();
1289  }
1290 
1292  { return this->Collisions.begin(); }
1293 
1295  { return this->Collisions.end(); }
1296 
1298  { return this->Collisions.begin(); }
1299 
1301  { return this->Collisions.end(); }
1302 
1303  ///////////////////////////////////////////////////////////////////////////////
1304  // Debug Management
1305 
1306  void PhysicsManager::SetDebugRenderingMode(const Integer DebugRenderingMode)
1307  {
1308  this->DebugRenderMode = DebugRenderingMode;
1309  if( this->BulletDrawer ) {
1310  this->BulletDrawer->setDebugMode( DebugRenderingMode );
1311  }
1312  }
1313 
1315  { return this->DebugRenderMode; }
1316 
1317  ///////////////////////////////////////////////////////////////////////////////
1318  // Utility
1319 
1321  {
1322  this->Destroy();
1323  if( Info != NULL ) {
1324  this->Construct( *Info );
1325  }else{
1327  }
1328 
1329  if( this->Initialized && this->BulletDrawer == NULL ) {
1331  this->BulletDrawer->setDebugMode( this->DebugRenderMode );
1332  this->BulletDynamicsWorld->setDebugDrawer( this->BulletDrawer );
1333  }
1334  }
1335 
1337  {
1338  // Clean the broadphase of AABB data
1339  btOverlappingPairCache* Pairs = this->BulletBroadphase->getOverlappingPairCache();
1340  int NumPairs = Pairs->getNumOverlappingPairs();
1341  btBroadphasePairArray PairArray = Pairs->getOverlappingPairArray();
1342  for( Integer X = 0 ; X < NumPairs ; X++ )
1343  {
1344  btBroadphasePair& CurrPair = PairArray.at(X);
1345  Pairs->removeOverlappingPair(CurrPair.m_pProxy0,CurrPair.m_pProxy1,this->BulletDispatcher);
1346  }
1347 
1348  // Clean the dispatcher(narrowphase) of shape data
1349  int numManifolds = this->BulletDispatcher->getNumManifolds();
1350  for ( int i = 0 ; i < numManifolds ; i++ )
1351  {
1352  this->BulletDispatcher->releaseManifold(this->BulletDispatcher->getManifoldByIndexInternal(i));
1353  }
1354 
1355  this->BulletBroadphase->resetPool(this->BulletDispatcher);
1356  this->BulletSolver->reset();
1357  this->BulletDynamicsWorld->stepSimulation(1.f/60.f,1,1.f/60.f);
1358  }
1359 
1361  { SubstepModifier = Modifier; }
1362 
1364  {
1365  // Implement later
1366  }
1367 
1369  {
1370  // Configure our area effects so they have an updated list and apply their effects immediately.
1371  this->BulletDynamicsWorld->updateAabbs();
1372  this->BulletBroadphase->calculateOverlappingPairs(this->BulletDispatcher);
1373  this->BulletDispatcher->dispatchAllCollisionPairs(this->BulletDynamicsWorld->getPairCache(),this->BulletDynamicsWorld->getDispatchInfo(),this->BulletDispatcher);
1374 
1375  // Set our ideal simulation step size
1376  //Real InvSubStepMod = 1.0 / this->SubstepModifier;
1377  //Real TargetTimeSeconds = static_cast<Real>( this->TheEntresol->GetTargetFrameTimeMicroseconds() ) * 0.000001;
1378  //this->StepSize = std::max( TargetTimeSeconds * InvSubStepMod, static_cast<Real>( 1.0 / 120.0 ) );
1379  //this->StepSize = TargetTimeSeconds * InvSubStepMod;
1380  this->StepSize = (static_cast<Real>( this->TheEntresol->GetTargetFrameTimeMicroseconds() ) * 0.000001) / this->SubstepModifier;
1381  }
1382 
1384  {
1385  if( !this->Initialized ) {
1387 
1388  // Create the debugdrawer
1390  this->BulletDrawer->setDebugMode( this->DebugRenderMode );
1391  this->BulletDynamicsWorld->setDebugDrawer( this->BulletDrawer );
1392 
1393  // Simulation work configuration
1395  this->TheEntresol->GetScheduler().AddWorkUnitMonopoly( static_cast<Threading::MonopolyWorkUnit*>( this->SimulationWork ), "SimulationWorkMonopoly" );
1396  }else{
1397  this->TheEntresol->GetScheduler().AddWorkUnitMain( this->SimulationWork, "SimulationWorkMain" );
1398  }
1399  Graphics::GraphicsManager* GraphicsMan = static_cast<Graphics::GraphicsManager*>( this->TheEntresol->GetManager(ManagerBase::MT_GraphicsManager) );
1400  if( GraphicsMan )
1401  this->SimulationWork->AddDependency( GraphicsMan->GetRenderWork() );
1402 
1403  ActorManager* ActorMan = static_cast<ActorManager*>( this->ParentWorld->GetManager(ManagerBase::MT_ActorManager) );
1404  AreaEffectManager* AEMan = static_cast<AreaEffectManager*>( this->ParentWorld->GetManager(ManagerBase::MT_AreaEffectManager) );
1405  DebrisManager* DebrisMan = static_cast<DebrisManager*>( this->ParentWorld->GetManager(ManagerBase::MT_DebrisManager) );
1406  // Debug Draw work configuration
1407  // Must add as affinity since it manipulates raw buffers and makes rendersystem calls under the hood.
1408  this->TheEntresol->GetScheduler().AddWorkUnitAffinity( this->DebugDrawWork, "DebugDrawWork" );
1409  this->DebugDrawWork->AddDependency( this->SimulationWork );
1410  if( ActorMan )
1411  this->DebugDrawWork->AddDependency( ActorMan->GetActorUpdateWork() );
1412  if( AEMan )
1414  if( DebrisMan )
1415  this->DebugDrawWork->AddDependency( DebrisMan->GetDebrisUpdateWork() );
1416 
1417  // World Trigger Update work configuration
1418  this->TheEntresol->GetScheduler().AddWorkUnitMain( this->WorldTriggerUpdateWork, "WorldTriggerUpdateWork" );
1420  if( DebrisMan )
1422 
1423  this->Initialized = true;
1424  }
1425  }
1426 
1428  {
1429  if( this->Initialized ) {
1430  // Destroy the debugdrawer
1431  delete this->BulletDrawer;
1432  this->BulletDrawer = NULL;
1433  this->BulletDynamicsWorld->setDebugDrawer( this->BulletDrawer );
1434 
1435  // Simulation work configuration
1437  this->TheEntresol->GetScheduler().RemoveWorkUnitMonopoly( static_cast<Threading::MonopolyWorkUnit*>( this->SimulationWork ) );
1438  }else{
1440  }
1442 
1443  if( this->TheEntresol ) {
1446  }
1447 
1448  // Debug Draw work configuration
1449  // Must add as affinity since it manipulates raw buffers and makes rendersystem calls under the hood.
1452 
1453  // World Trigger Update work configuration
1456 
1457  this->Initialized = false;
1458  }
1459  }
1460 
1462  {
1463  if( this->SimulationIsPaused() )
1464  return;
1465 
1466  Real FloatTime = Real(CurrentThreadStorage.GetLastFrameTime()) * 0.000001 * this->GetTimeMultiplier(); // Convert from MicroSeconds to Seconds
1467  int MaxSteps = ( FloatTime < this->StepSize ) ? 1 : int( FloatTime / this->StepSize ) + 1;
1468 
1469  Logger& ThreadLog = CurrentThreadStorage.GetUsableLogger();
1470  ThreadLog << "Attempting to step the physics simulation by " << FloatTime << " seconds with " << MaxSteps << " maximum substeps." << std::endl;
1471  Timer PhysicsTimer;
1472  PhysicsTimer.Start();
1473 
1474  CallBackWorld = this;
1475  this->BulletDynamicsWorld->stepSimulation( FloatTime, MaxSteps, this->StepSize );
1476  CallBackWorld = NULL;
1477 
1478  PhysicsTimer.Stop();
1479  ThreadLog << "StepSimulation took " << PhysicsTimer.GetCurrentTimeInMilliseconds() << " milliseconds." << std::endl;
1480  }
1481 
1483  { return this->SimulationWork; }
1484 
1486  { return this->WorldTriggerUpdateWork; }
1487 
1489  { return this->DebugDrawWork; }
1490 
1491  ///////////////////////////////////////////////////////////////////////////////
1492  // Type Identifier Methods
1493 
1495  { return PhysicsManager::InterfaceType; }
1496 
1499 
1500  ///////////////////////////////////////////////////////////////////////////////
1501  // Internal Methods
1502 
1503  btSoftRigidDynamicsWorld* PhysicsManager::_GetPhysicsWorldPointer()
1504  { return this->BulletDynamicsWorld; }
1505 
1506  const btSoftRigidDynamicsWorld* PhysicsManager::_GetPhysicsWorldPointer() const
1507  { return this->BulletDynamicsWorld; }
1508 
1509  ///////////////////////////////////////////////////////////////////////////////
1510  // DefaultPhysicsManagerFactory Methods
1511 
1513  { }
1514 
1516  { }
1517 
1520 
1522  { return PhysicsManager::InterfaceType; }
1523 
1525  {
1526  if( Params.empty() ) {
1527  return new PhysicsManager(Creator);
1528  }
1529  ManagerConstructionInfo PhysInfo;
1530  for( NameValuePairList::const_iterator ParIt = Params.begin() ; ParIt != Params.end() ; ++ParIt )
1531  {
1532  String Lower = (*ParIt).first;
1533  StringTools::ToLowerCase(Lower);
1534  if( "geographyupperbounds" == Lower )
1535  {
1536  PhysInfo.GeographyUpperBounds = StringTools::ConvertToVector3( (*ParIt).second );
1537  }
1538  else if( "geographylowerbounds" == Lower )
1539  {
1540  PhysInfo.GeographyLowerBounds = StringTools::ConvertToVector3( (*ParIt).second );
1541  }
1542  else if( "maxproxies" == Lower )
1543  {
1544  PhysInfo.MaxProxies = StringTools::ConvertToUInt32( (*ParIt).second );
1545  }
1546  else if( "gravity" == Lower )
1547  {
1548  PhysInfo.Gravity = StringTools::ConvertToVector3( (*ParIt).second );
1549  }
1550  else if( "softrigidworld" == Lower )
1551  {
1552  if(StringTools::ConvertToBool( (*ParIt).second ))
1554  }
1555  else if( "limitlessworld" == Lower )
1556  {
1557  if(StringTools::ConvertToBool( (*ParIt).second ))
1559  }
1560  else if( "multithreaded" == Lower )
1561  {
1562  if(StringTools::ConvertToBool( (*ParIt).second ))
1564  }
1565  }
1566  return new PhysicsManager(Creator,PhysInfo);
1567  }
1568 
1570  { return new PhysicsManager(Creator,XMLNode); }
1571 
1573  { delete ToBeDestroyed; }
1574  }//Physics
1575 }//Mezzanine
1576 
1577 #endif
virtual void AddDependency(iWorkUnit *NewDependency)
Force this WorkUnit to Start after another has completed.
Definition: workunit.cpp:99
virtual void AddWorkUnitMonopoly(MonopolyWorkUnit *MoreWork, const String &WorkUnitName)
Add a MonopolyWorkUnit for execution at the beginning of the frame.
This is the base class for all collision shapes.
virtual ~SimulationMonopolyWorkUnit()
Class destructor.
UIDGenerator ProxyIDGen
Generator responsible for creating unique IDs for CollidableProxy instances.
virtual void draw3dText(const btVector3 &location, const char *textString)
Currently Unused.
virtual ~DefaultPhysicsManagerFactory()
Class destructor.
virtual ~DebugDrawWorkUnit()
Class destructor.
void DestroyConstraint(Constraint *Con)
Removes a constraint from the world and destroys it.
Whole GetNumConstraints()
Gets the number of constraints currently in the world.
void DrawLine(const Vector3 &Start, const Vector3 &End, const ColourValue &Colour)
This adds Two points to the list.
Definition: linegroup.cpp:388
virtual void AddToWorld()
Performs all the necessary task to ensure this object is connected to it's respective world and ready...
Definition: ghostproxy.cpp:103
ProxyIterator BeginCollidableProxy()
Gets an iterator to the first Collidable Proxy in this manager.
WorldManager * GetManager(const Whole ManagerToGet)
This is will find the manager of a given type.
Definition: world.cpp:324
virtual ManagerBase::ManagerType GetInterfaceType() const
This returns the type of this manager.
DebugDrawWorkUnit * DebugDrawWork
The work unit that updates the debug drawer with the latest physics rendering.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
This is used to draw wireframse for the Physics subsystem.
UInt32 ConvertToUInt32(const String &ToConvert)
Converts a string into a UInt32.
Definition: stringtool.cpp:456
std::stringstream Logger
In case we ever replace the stringstream with another class, this will allow us to swap it out...
Definition: datatypes.h:180
DebugDrawWorkUnit(const DebugDrawWorkUnit &Other)
Protected copy constructor. THIS IS NOT ALLOWED.
Threading::DefaultWorkUnit * SimulationWork
The work unit that does the stepping of the simulation.
WorldTriggerUpdateWorkUnit * GetWorldTriggerUpdateWork()
Gets a pointer to the work unit that updates all WorldTriggers.
WorldTriggerContainer::iterator WorldTriggerIterator
Iterator type for WorldTrigger instances stored by this class.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Default implementation of WorkUnit. This represents on piece of work through time.
Definition: workunit.h:160
virtual void Pause(const UInt32 PL)
Sets the pause state of this manager, or has no effect depending on the value passed in...
virtual Whole UsingThreadCount()
Gets the number of threads this work unit will attempt to use during it's monopoly.
virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
This does any required update of the Graphical Scene graph and REnders one frame. ...
Whole GetNumWorldTriggers()
Gets the number of triggers currently in the world.
Whole GetTargetFrameTimeMicroseconds() const
Retrieves the amount of milliseconds we would like each iteration of the Main Loop to be...
Definition: entresol.cpp:609
Vector3 GeographyLowerBounds
The lower limits of the worlds AABB.
virtual void AddWorkUnitMain(iWorkUnit *MoreWork, const String &WorkUnitName)
Add a normal Mezzanine::Threading::iWorkUnit to this For fcheduling.
WorldManager * CreateManager(World *Creator, const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
PhysicsManager * TargetManager
A pointer to the manager this work unit is processing.
A manager responsible for the storage and management of all areaeffects in use.
static void InternalTickCallback(btDynamicsWorld *world, btScalar timeStep)
Internal Callback that is called each substep of the simulation.
This file contains the declaration for the manager that manages debris objects in a world...
Real TimeMultiplier
A Multiplier that adjusts how fast physics runs relative to clock time.
virtual void ProcessAllTriggers()
Calls the ConditionsAreMet() and ApplyTrigger() functions of every stored trigger.
WorldTriggerUpdateWorkUnit & operator=(const WorldTriggerUpdateWorkUnit &Other)
Protected assignment operator. THIS IS NOT ALLOWED.
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
virtual void ProcessAllCollisions()
Checks the internal collision data and generates/updates collisions as necessary. ...
void SetSimulationSubstepModifier(const Whole &Modifier)
Sets the modifier to be used when stepping the physics simulation.
virtual UInt32 GetProxyID() const
Gets the unique ID of this proxy.
Definition: worldproxy.cpp:78
This is the proxy object for ghost objects with no contact response.
Definition: ghostproxy.h:55
void SetDebugRenderingMode(const Integer DebugRenderingMode)
Enables and Disables Physics Debug Drawing.
virtual void UseThreads(const Whole &AmountToUse)
A no-op but declared for compatibility with Monopoly work unit.
void MainLoopInitialize()
Does all of the necessary configuration to prepare for a running simulation.
void AddToWorld()
Configures this LineGroup to render in the scene.
Definition: linegroup.cpp:394
void SetTimeMultiplier(const Real &value)
Change how fast the physicsworks relatve to well time.
virtual void RemoveWorkUnitMain(iWorkUnit *LessWork)
Remove a WorkUnit from the main pool of WorkUnits (and not from the groups of Affinity or MonpolyWork...
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
void ResetPhysicsWorld(ManagerConstructionInfo *Info=0)
Resets all the internal physics structures in this manager.
This is a constraint for permitting movement on only a singular linear or angular axis...
std::pair< CollidablePair, Collision * > CollisionSortPair
A std::pair to assist with collision sorting operations.
UIDGenerator ConstraintIDGen
Generator responsible for creating unique IDs for Constraint instances.
void SetWorldSoftGravity(const Vector3 &sgrav)
Sets the gravity for soft bodies.
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
Vector3 Gravity
The gravity to set for the world.
CollidableProxy * GetProxyByID(const UInt32 ID) const
Gets the CollidableProxy via its ID.
Enables multi-threaded acceleration structures.
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
Vector3 ConvertToVector3(const String &ToConvert)
Convert three numbers in a string into a Vector3.
Definition: stringtool.cpp:298
Constraint * GetConstraint(const Whole &Index)
Gets a constraint by index.
WorldTriggerContainer Triggers
A container storing all of the worldtriggers owned by this manager.
Threading::FrameScheduler & GetScheduler()
Gets the core structure responsible for scheduling work in the Entresol main loop.
Definition: entresol.cpp:495
IDType GenerateID()
Generates a new ID unique to the pool made by this generator.
AreaEffectUpdateWorkUnit * GetAreaEffectUpdateWork()
Gets the work unit responsible for updating area effects stored by this manager.
ConstraintContainer Constraints
A container storing all of the constraints owned by this manager.
Create simple but specific limits on any axis of movement or rotation.
CollisionMapIterator EndCollision()
Get a CollisionIterator to one past the last Collision.
void DrawLines()
Updates the render buffers with the needed data to draw the lines in this LineGroup.
Definition: linegroup.cpp:391
This is the base class for all constraints supported.
Definition: constraint.h:116
GhostProxy * CreateGhostProxy()
Creates a new GhostProxy.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
ConeTwistConstraint * CreateConeTwistConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Transform &TransA, const Transform &TransB)
Creates a new ConeTwistConstraint.
UniversalConstraint * CreateUniversalConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &Anchor, const Vector3 &Axis1, const Vector3 &Axis2)
Creates a new UniversalConstraint.
bool Empty() const
Is this storing anything at all?
ConstraintContainer::iterator ConstraintIterator
Iterator type for Constraint instances stored by this class.
Enables support for soft bodies in the simulation.
virtual String GetImplementationTypeName() const
This Allows any manager name to be sent to a stream. Primarily used for logging.
PhysicsManager(World *Creator)
Default settings constructor.
This is a Mezzanine::Threading::iWorkUnit for the single threaded processing of physics simulations...
This is a Mezzanine::Threading::iWorkUnit for the updating of WorldTriggers.
This is a constraint for sharing the rotation of one object along an angular axis with another...
void ClearLines()
Clears all data pertaining to points in this line group.
Definition: linegroup.cpp:385
void DoPerFrameWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
The work that needs to be done each frame.
HingeConstraint * CreateHingeConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &PivotInA, const Vector3 &PivotInB, const Vector3 &AxisInA, const Vector3 &AxisInB)
Creates a new HingeConstraint.
ProxyContainer Proxies
A container storing all of the proxies owned by this manager.
void ToLowerCase(String &Source)
Converts all upper case characters in a string to their respective lower case.
Definition: stringtool.cpp:193
DebugDrawWorkUnit * GetDebugDrawWork()
Gets a pointer to the work unit that updates the debug drawer.
Physics::Collision * GetCollision(CollidableProxy *A, CollidableProxy *B)
Gets a Collision by collidable pair.
Whole ThreadCount
The number of threads the internal thread providers should allocate.
btThreadSupportInterface * BulletDispatcherThreads
A pointer to the thread provider for the internal dispatcher (narrowphase).
Whole SubstepModifier
A modifier that will determine how many substeps each frame the physics simulation should perform...
debug::InternalDebugDrawer * BulletDrawer
A pointer to the debug drawer for rendering the physics world.
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
Vector3 GetWorldGravity()
Gets the gravity.
virtual void AddToWorld()
Performs all the necessary task to ensure this object is connected to it's respective world and ready...
Definition: rigidproxy.cpp:116
void PauseSimulation(Boole Pause)
Pauses the simulation, preventing the physics world from taking action.
PhysicsManager * TargetManager
A pointer to the manager this work unit is processing.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
void RemoveFromWorld()
Unhooks this LineGroup from the scene, stopping it from rendering.
Definition: linegroup.cpp:400
This is a constraint that will limit the movement allowed from one body to within a cone area around ...
Tries to make a point relative to each of two actors match in 3d space, without regard to rotation...
A thread specific collection of double-buffered and algorithm specific resources. ...
virtual void setDebugMode(int debugMode)
This is used to decide how much the debug render should draw.
This is the base class from which classes that are insertable into the physical world.
Definition: worldobject.h:60
PhysicsManager * TargetManager
A pointer to the manager this work unit is processing.
void DestroyManager(WorldManager *ToBeDestroyed)
Destroys a Manager created by this factory.
SliderConstraint * CreateSliderConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Transform &TransA, const Transform &TransB)
Creates a new SliderConstraint.
void ClearPhysicsMetaData()
Clears all data relating to actors and other simulation objects from the physics world.
Boole SimulationPaused
Whether or not the physics simulation is to step each frame.
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
btCollisionConfiguration * BulletCollisionConfiguration
A pointer to the internal collision configuration that enables certain types of objects to collide...
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
InternalDebugDrawer(World *ParentWorld)
Basic Constructor.
Boole ConvertToBool(const String &ToConvert, const Boole Default)
Converts a string into a Boole.
Definition: stringtool.cpp:379
virtual void RemoveFromWorld()=0
Unhooks this proxy from it's respective world.
void RemoveCollisionsContainingProxy(CollidableProxy *Proxy)
Removes all stored collisions that involve the specified CollidableProxy.
Whole GetCurrentTimeInMilliseconds()
Gets the Current time in Milliseconds.
Definition: timer.cpp:98
virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
This does any required update of the Graphical Scene graph and REnders one frame. ...
A manager responsible for the storage and management of all Debris that exist in a world...
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
Definition: vector3.cpp:555
Boole ReserveID(const IDType ID)
Adds a specific ID to the pool of used IDs.
This is a group of consectutive line segments to be rendered together.
Definition: linegroup.h:64
virtual void Destroy()
Tear down this physics world.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is the proxy object for soft/compressable bodies.
Definition: softproxy.h:55
SoftProxy * CreateSoftProxy(const Real Mass)
Creates a new SoftProxy.
This is an abstract class for creating in-game triggers.
Definition: worldtrigger.h:53
Whole MaxProxies
The maximum number of Actors and Area Effects you expect to have in the world at one time...
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
DebrisUpdateWorkUnit * GetDebrisUpdateWork()
Gets the work unit responsible for updating Debriss stored by this manager.
ProxyType
Used by all World proxies to describe what their derived types are.
Definition: enumerations.h:91
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
WorldTriggerUpdateWorkUnit * WorldTriggerUpdateWork
The work unit that processes all world triggers.
This is an event class used to track collsions in the physics world.
Definition: collision.h:72
bool Empty() const
Is this storing anything at all?
virtual void RemoveWorkUnitAffinity(iWorkUnit *LessWork)
Remove a WorkUnit from the Affinity pool of WorkUnits (and not from the Main group or MonpolyWorkUnit...
UInt32 GetNumProxies() const
Gets the number of CollidableProxy instances in this manager.
Generic6DofSpringConstraint * CreateGeneric6DofSpringConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Transform &TransA, const Transform &TransB)
Creates a new Generic6DofSpringConstraint.
Used to provide better reporting of collisions.
virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
This does any required update of the Graphical Scene graph and REnders one frame. ...
void Start()
Activates the Timer.
Definition: timer.cpp:113
void AddWorldTrigger(WorldTrigger *Trig)
Adds a trigger to the world.
This is a convience class that will configure a 6DoF spring constraint with 2 angular and 1 linear (w...
void DestroyAllCollisions()
Destroys all collisions currently being stored and processed in the manager.
WorldTriggerUpdateWorkUnit(const WorldTriggerUpdateWorkUnit &Other)
Protected copy constructor. THIS IS NOT ALLOWED.
virtual int getDebugMode() const
This will return the current debug mode.
Entresol * TheEntresol
The actual pointer to the Entresol core class.
Definition: managerbase.h:108
This is a Mezzanine::Threading::iWorkUnit for the multi-threaded processing of physics simulations...
RenderWorkUnit * GetRenderWork()
Gets the work unit responsible for performing the graphics render of all scenes.
CollisionMap::iterator CollisionMapIterator
Iterator type for sorted Collision instances.
virtual void AddWorkUnitAffinity(iWorkUnit *MoreWork, const String &WorkUnitName)
Add a normal Mezzanine::Threading::iWorkUnit to this For scheduling.
btSoftRigidDynamicsWorld * _GetPhysicsWorldPointer()
This returns a pointer to the bullet physics world. This is for internal use only.
void DestroyAllConstraints()
Destroys all constraints currently in the manager.
virtual void Construct(const ManagerConstructionInfo &Info)
This takes care of all the real work in contructing this.
Logger & GetUsableLogger()
Get the usable logger for this thread specific resource.
WorldTriggerContainer::const_iterator ConstWorldTriggerIterator
Const Iterator type for WorldTrigger instances stored by this class.
virtual ~PhysicsManager()
Class destructor.
Vector3 GetWorldSoftGravity()
Gets the soft body gravity.
RigidProxy * CreateRigidProxy(const Real Mass)
Creates a new RigidProxy.
void DestroyAllWorldTriggers()
Destroys all triggers currently in the manager.
This is a helper class for storing pairs of collidable proxies in associative containers.
virtual void drawContactPoint(const btVector3 &PointOnB, const btVector3 &normalOnB, btScalar distance, int lifeTime, const btVector3 &color)
Currently Unused.
CollidableProxy * ProxyB
The second CollidableProxy invovled in the collision.
Definition: collision.h:90
void DestroyAllProxies()
Deletes all stored CollidableProxy instances.
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
This is a proxy from which rigid body proxys are handled.
Definition: rigidproxy.h:102
void RemoveWorldTrigger(WorldTrigger *Trig)
Removes a trigger from the world.
This is a Mezzanine::Threading::iWorkUnit for the updating of the physics debug drawer.
virtual btCollisionObject * _GetBasePhysicsObject() const =0
Accessor for the internal physics object.
Stores information about relative location and rotation in 3d space.
Definition: transform.h:62
ProxyIterator EndCollidableProxy()
Gets an iterator to one passed the last Collidable Proxy in this manager.
Generic6DofConstraint * CreateGeneric6DofConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Transform &TransA, const Transform &TransB)
Creates a new Generic6DofConstraint.
This is the base class for all managers that belong to a single world instance.
Definition: worldmanager.h:55
This is a proxy from which physics objects that can collide with each other are handled.
DebugDrawWorkUnit & operator=(const DebugDrawWorkUnit &Other)
Protected assignment operator. THIS IS NOT ALLOWED.
virtual void ClearDependencies()
Drop any information about what work units this one depends on.
Definition: workunit.cpp:110
void RemoveCollision(Physics::Collision *Col)
Removes an existing collision from the world.
virtual Boole GetCollisionResponse() const
Will this respond to 3d collisions.
std::list< btCollisionAlgorithm * > AlgoList
Convenience datatype for a collection of Collision Algorithms.
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
Used to provide better reporting of collisions in a multithreaded environment.
EntresolManager * GetManager(const Whole RetrieveType, UInt16 WhichOne=0)
This is will find the manager of a given type.
Definition: entresol.cpp:792
virtual void RemoveWorkUnitMonopoly(MonopolyWorkUnit *LessWork)
Remove a WorkUnit from the Monopoly pool of WorkUnits (and not from the Main or Affinity group)...
virtual void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)
This will prepare a line segment for being drawn.
This is simply a place for storing all the Physics Related functions.
btBroadphaseInterface * BulletBroadphase
A pointer to the physics broadphase of the simulation.
This is a constraint that duplicate the angular motion of one object to another, adjusted by the prov...
btSoftRigidDynamicsWorld * BulletDynamicsWorld
A pointer to the internal physics world.
Integer GetDebugRenderingMode() const
Is Physics Debug Drawing currently enabled?
void SetWorldGravity(const Vector3 &pgrav)
Sets the gravity.
This is a constraint to be used to restrict the movement between two objects to angular rotation on a...
Threading::DefaultWorkUnit * GetSimulationWork()
Gets a pointer to the work unit that steps the simulation.
World * ParentWorld
A pointer to the world that created this manager.
Definition: worldmanager.h:60
CollidableProxy * ProxyA
The first CollidableProxy involved in the collision.
Definition: collision.h:87
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
ProxyContainer::iterator ProxyIterator
Iterator type for CollidableProxy instances stored by this class.
A basic timer class to assist in timed operations.
Definition: timer.h:67
virtual void Deinitialize()
Removes this manager from any necessary configuration so it can be safely disposed of...
This is intended to store basic graphics setting for the user.
Whole GetCPUCount()
Get the amount of logical processors, a reasononable amount to use for thread creation.
void Stop()
Deactivates the Timer.
Definition: timer.cpp:119
Whole PhysicsFlags
The flags to initialize the physics system with.
Real StepSize
The amount of time (in seconds) a single simulation step should advance.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
CollidableProxy * GetProxy(const UInt32 Index) const
Gets a CollidableProxy instance by index.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Boole SimulationIsPaused()
Gets Whether or not the simulation is currently paused.
void DestroyProxy(CollidableProxy *ToBeDestroyed)
Deletes a CollidableProxy.
This class represents a world for objects to interact within.
Definition: world.h:74
virtual Boole IsInWorld() const
Gets whether or not this object is inside of it's world.
Integer DebugRenderMode
The current rendering mode for the debug drawer.
virtual void SetLogger(Mezzanine::Logger *Logger)
Sets the safe logger to sent debug output to.
GearConstraint * CreateGearConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &AxisA, const Vector3 &AxisB)
Creates a new GearConstraint.
btGhostPairCallback * GhostCallback
A pointer to the callback that enables ghost objects internally.
WorldTrigger * GetWorldTrigger(const String &Name)
Gets a trigger by name.
Boole ReleaseID(const IDType ID)
Frees up an ID so that it can be reused.
btSequentialImpulseConstraintSolver * BulletSolver
A pointer to the internal constraint solver.
CollisionMapIterator BeginCollision()
Get an CollisionIterator to the first Collision.
ActorUpdateWorkUnit * GetActorUpdateWork()
Gets the work unit responsible for updating actors stored by this manager.
virtual UInt32 GetConstraintID() const
Gets the unique ID of this constraint.
virtual void PrepareForUpdate()
Clears data as necessary for updating debug geometry.
static PhysicsManager * CallBackWorld
The World that will be used for the InternalTickCallback.
Whole GetNumCollisions()
Gets the number of Collisions currently in the world.
virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
This does any required update of the Graphical Scene graph and REnders one frame. ...
virtual ~InternalDebugDrawer()
Destructor.
Vector3 GeographyUpperBounds
The upper limits of the worlds AABB.
Real GetTimeMultiplier() const
How much faster or slower that reality is the physic ssystem.
btThreadSupportInterface * BulletSolverThreads
A pointer to the thread provider for the internal constraint solver.
Hinge2Constraint * CreateHinge2Constraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &Anchor, const Vector3 &Axis1, const Vector3 &Axis2)
Creates a new Hinge2Constraint.
Creates a constraint as configurable as the 6Dof constraint, but has added support for spring motion...
btCollisionDispatcher * BulletDispatcher
A pointer to the internal dispatcher (narrowphase).
virtual void reportErrorWarning(const char *warningString)
Used by the physics subsystem to report errors using the renderer.
Point2PointConstraint * CreatePoint2PointConstraint(RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &PivotA, const Vector3 &PivotB)
Creates a new Point2PointConstraint.
CollisionMap Collisions
A container tracking all of the existing collisions in the physics world.
PhysicsManager * TargetManager
A pointer to the manager this work unit is processing.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Whole GetLastFrameTime() const
How long was the previous frame?
ManagerConstructionInfo WorldConstructionInfo
A copy of the information used to initialize this manager.
This is a helper class storing information needed for the construction of a PhysicsManager.
virtual ~SimulationWorkUnit()
Class destructor.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
static const String ImplementationName
A String containing the name of this manager implementation.
ProxyContainer::const_iterator ConstProxyIterator
Const Iterator type for CollidableProxy instances stored by this class.
CollisionMap::const_iterator ConstCollisionMapIterator
Const Iterator type for sorted Collision instances.
virtual void _NotifyProxyDestroyed(WorldProxy *ToBeDestroyed)=0
Notifies that a proxy belonging to this WorldObject is being forcibly destroyed, and it needs to upda...
virtual void FinalizeUpdate()
Copies all the line data to render buffers so they can be seen on screen.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
A manager responsible for the storage and management of all actors that exist in a world...
Definition: actormanager.h:94
Boole Initialized
Simple Boole indicating whether or not this manager has been initialized.
Definition: managerbase.h:111
virtual ~WorldTriggerUpdateWorkUnit()
Class destructor.