ScummVM API documentation
dgWorld.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #if !defined(AFX_DGPHYSICSWORLD_H__EC18C699_D48D_448F_A510_A865B2CC0789__INCLUDED_)
23 #define AFX_DGPHYSICSWORLD_H__EC18C699_D48D_448F_A510_A865B2CC0789__INCLUDED_
24 
25 
26 #include "dgBody.h"
27 #include "dgContact.h"
28 #include "dgCollision.h"
29 #include "dgCollisionScene.h"
30 #include "dgBodyMasterList.h"
31 #include "dgWorldDynamicUpdate.h"
32 
33 //#include "dgBallConstraint.h"
34 //#include "dgHingeConstraint.h"
35 //#include "dgSlidingConstraint.h"
36 //#include "dgUniversalConstraint.h"
37 //#include "dgCorkscrewConstraint.h"
38 #include "dgBroadPhaseCollision.h"
39 //#include "dgUpVectorConstraint.h"
40 //#include "dgPointToCurveConstraint.h"
41 
42 
43 #define DG_REDUCE_CONTACT_TOLERANCE dgFloat32 (1.0e-2f)
44 #define DG_PRUNE_CONTACT_TOLERANCE dgFloat32 (1.0e-2f)
45 #define DG_RESTING_CONTACT_PENETRATION dgFloat32 (1.0f / 256.0f)
46 #define DG_IMPULSIVE_CONTACT_PENETRATION dgFloat32 (1.0f / 256.0f + DG_RESTING_CONTACT_PENETRATION)
47 
48 #define DG_SLEEP_ENTRIES 8
49 #define DG_MAX_DESTROYED_BODIES_BY_FORCE 8
50 
51 //#define DG_SPANNING_MEMORY_POOL_SIZE ((1<<16))
52 
53 class dgCollisionPoint;
54 class dgUserConstraint;
55 class dgBallConstraint;
56 class dgHingeConstraint;
61 class dgUserMeshCreation;
62 //class dgConnectorConstraint;
63 //class dgPointToCurveConstraint;
64 
65 
66 class dgBodyCollisionList: public dgTree<dgCollision *, dgUnsigned32> {
67 public:
68  dgBodyCollisionList(dgMemoryAllocator *const allocator)
70 
71  }
72 };
73 
74 class dgBodyMaterialList: public dgTree<dgContactMaterial, dgUnsigned32> {
75 public:
76  dgBodyMaterialList(dgMemoryAllocator *const allocator)
78 
79  }
80 };
81 
83 
84 enum dgPerformanceCounters {
85 
86 
87 
88  m_worldTicks = 0,
89 
90  m_collisionTicks,
91  m_broadPhaceTicks,
92  m_narrowPhaseTicks,
93 
94  m_dynamicsTicks,
95  m_dynamicsBuildSpanningTreeTicks,
96  m_dynamicsSolveSpanningTreeTicks,
97 
98  m_forceCallback,
99  m_counterSize,
100 };
101 
102 class dgWorld;
103 
104 typedef dgUnsigned32(dgApi *OnIslandUpdate)(const dgWorld *const world, void *island, dgInt32 bodyCount);
105 typedef void (dgApi *OnDestroyCollision)(const dgWorld *const world, dgCollision *shape);
106 typedef void (dgApi *OnBodyDestructionByExeciveForce)(const dgBody *const body, const dgContact *joint);
107 
109 public:
110  dgFloat32 m_maxAccel;
111  dgFloat32 m_maxAlpha;
112  dgFloat32 m_maxVeloc;
113  dgFloat32 m_maxOmega;
114  dgInt32 m_steps;
115 };
116 
117 DG_MSC_VECTOR_ALIGMENT
118 class dgWorld:
119  public dgBodyMasterList,
120  public dgBroadPhaseCollision,
121  public dgBodyMaterialList,
122  public dgBodyCollisionList,
123  public dgActiveContacts,
124  public dgCollidingPairCollector {
125 public:
126 
128  public:
130  : m_count(0) {
131  }
132  dgInt32 m_count;
133  dgFloat32 m_force[DG_MAX_DESTROYED_BODIES_BY_FORCE];
134  const dgBody *m_bodies[DG_MAX_DESTROYED_BODIES_BY_FORCE];
135  const dgContact *m_joint[DG_MAX_DESTROYED_BODIES_BY_FORCE];
136  };
137 
138 
139  DG_CLASS_ALLOCATOR(allocator)
140 
141  dgWorld(dgMemoryAllocator *const allocator);
142  ~dgWorld();
143 
144 // void SetGlobalScale (dgFloat32 scale);
145 // dgFloat32 GetGlobalScale () const;
146 
147  void SetSolverMode(dgInt32 mode);
148  void SetFrictionMode(dgInt32 mode);
149  void SetHardwareMode(dgInt32 mode);
150  dgInt32 GetHardwareMode(char *description) const;
151 
152  void SetThreadsCount(dgInt32 count);
153  dgInt32 GetThreadsCount() const;
154  dgInt32 GetMaxThreadsCount() const;
155 // dgInt32 GetThreadNumber() const;
156  void EnableThreadOnSingleIsland(dgInt32 mode);
157  dgInt32 GetThreadOnSingleIsland() const;
158 
159  void FlushCache();
160 
161  void *GetUserData() const;
162  void SetUserData(void *const userData);
163 
164  void Update(dgFloat32 timestep);
165  void UpdateCollision();
166  dgInt32 Collide(dgCollision *const collisionA, const dgMatrix &matrixA, dgCollision *const collisionB, const dgMatrix &matrixB,
167  dgTriplex *const points, dgTriplex *const normals, dgFloat32 *const penetration, dgInt32 maxSize, dgInt32 threadIndex);
168 
169  dgInt32 CollideContinue(dgCollision *const collisionA, const dgMatrix &matrixA, const dgVector &velocA, const dgVector &omegaA,
170  dgCollision *const collisionB, const dgMatrix &matrixB, const dgVector &velocB, const dgVector &omegaB,
171  dgFloat32 &timeStep, dgTriplex *const points, dgTriplex *const normals, dgFloat32 *const penetration, dgInt32 maxSize, dgInt32 threadIndex);
172  dgInt32 CollideContinueSimd(dgCollision *const collisionA, const dgMatrix &matrixA, const dgVector &velocA, const dgVector &omegaA,
173  dgCollision *const collisionB, const dgMatrix &matrixB, const dgVector &velocB, const dgVector &omegaB,
174  dgFloat32 &timeStep, dgTriplex *const points, dgTriplex *const normals, dgFloat32 *const penetration, dgInt32 maxSize, dgInt32 threadIndex);
175 
176 
177  dgInt32 ClosestPoint(const dgTriplex &point, dgCollision *const collision, const dgMatrix &matrix, dgTriplex &contact, dgTriplex &normal, dgInt32 threadIndex) const;
178  dgInt32 ClosestPoint(dgCollision *const collisionA, const dgMatrix &matrixA, dgCollision *const collisionB, const dgMatrix &matrixB,
179  dgTriplex &contactA, dgTriplex &contactB, dgTriplex &normalAB, dgInt32 threadIndex) const;
180 
181 
182  void SetFrictionThreshold(dgFloat32 acceletion);
183 
184 
185  dgBody *GetIslandBody(const void *const island, dgInt32 index) const;
186 
187 
188  void SetIslandUpdateCallback(OnIslandUpdate callback);
189  void SetDestroyCollisionCallback(OnDestroyCollision shape);
190  void SetLeavingWorldCallback(OnLeavingWorldAction callback);
191  void SetBodyDestructionByExeciveForce(OnBodyDestructionByExeciveForce callback);
192 // void ForEachBodyInAABB (const dgVector& q0, const dgVector& q1, OnLeavingWorldAction callback);
193 
194  dgBody *CreateBody(dgCollision *const collision, const dgMatrix &matrix);
195  void DestroyBody(dgBody *const body);
196  void DestroyAllBodies();
197 
198 // void AddToBreakQueue (const dgContact* const contactJoint, dgFloat32 masValue);
199  void AddToBreakQueue(const dgContact *const contactJoint, dgBody *const body, dgFloat32 maxForce);
200 
201  // modify the velocity and angular velocity of a body in such a way
202  // that the velocity of pointPosit is increase by pointDeltaVeloc
203  // pointVeloc and pointPosit are in world space
204  void AddBodyImpulse(dgBody *body, const dgVector &pointDeltaVeloc, const dgVector &pointPosit);
205 
206  void ApplyImpulseArray(dgBody *body, dgInt32 count, dgInt32 strideInBytes, const dgFloat32 *const impulseArray, const dgFloat32 *const pointArray);
207 
208  // apply the transform matrix to the body and recurse trough all bodies attached to this body with a
209  // bilateral joint contact joint are ignored.
210  void BodySetMatrix(dgBody *body, const dgMatrix &matrix);
211 // void FreezeBody (dgBody *body);
212 // void UnfreezeBody (dgBody *body);
213 // dgInt32 GetActiveBodiesCount() const;
214 
215  dgInt32 GetBodiesCount() const;
216  dgInt32 GetConstraintsCount() const;
217 
218 
219  dgUnsigned32 GetBoxID() const;
220  dgUnsigned32 GetConeID() const;
221  dgUnsigned32 GetSphereID() const;
222  dgUnsigned32 GetConvexID() const;
223  dgUnsigned32 GetEllipseID() const;
224  dgUnsigned32 GetCapsuleID() const;
225  dgUnsigned32 GetCylinderID() const;
226  dgUnsigned32 GetConvexHullID() const;
227  dgUnsigned32 GetChamferCylinderID() const;
228  dgUnsigned32 GetConvexHullModifierID() const;
229  dgUnsigned32 GetPolygonSoupID() const;
230  dgUnsigned32 GetSceneID() const;
231  dgUnsigned32 GetCompoundCollisionID() const;
232 
233  dgCollision *CreateNull();
234  dgCollision *CreateSphere(dgFloat32 radiusdg, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
235  dgCollision *CreateCone(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
236  dgCollision *CreateCapsule(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
237  dgCollision *CreateCylinder(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
238  dgCollision *CreateBox(dgFloat32 dx, dgFloat32 dy, dgFloat32 dz, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
239  dgCollision *CreateEllipse(dgFloat32 rx, dgFloat32 ry, dgFloat32 rz, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
240  dgCollision *CreateConvexHull(dgInt32 count, const dgFloat32 *vertexArray, dgInt32 strideInBytes, dgFloat32 tolerance, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
241  dgCollision *CreateChamferCylinder(dgFloat32 radius, dgFloat32 height, dgInt32 shapeID, const dgMatrix &offsetMatrix = dgGetIdentityMatrix());
242  dgCollision *CreateConvexModifier(dgCollision *convexCollision);
243  dgCollision *CreateCollisionCompound(dgInt32 count, dgCollision *const array[]);
244 // dgCollision* CreateCollisionCompoundBreakable (dgInt32 count, dgMeshEffect* const solidArray[], dgMeshEffect* const splitePlanes[],
245 // dgMatrix* const matrixArray, dgInt32* const idArray, dgFloat32* const mass, dgInt32 debriID,
246 // dgCollisionCompoundBreakableCallback callback, void* buildUsedData);
247 
248  dgCollision *CreateCollisionCompoundBreakable(dgInt32 count, dgMeshEffect *const solidArray[], const dgInt32 *const idArray,
249  const dgFloat32 *const densities, const dgInt32 *const internalFaceMaterial, dgInt32 debriID, dgFloat32 gap);
250 
251 
252  dgCollision *CreateBVH();
253  dgCollision *CreateStaticUserMesh(const dgVector &boxP0, const dgVector &boxP1, const dgUserMeshCreation &data);
254  dgCollision *CreateBVHFieldCollision(dgInt32 width, dgInt32 height, dgInt32 contructionMode,
255  const dgUnsigned16 *const elevationMap, const dgInt8 *const atributeMap, dgFloat32 horizontalScale, dgFloat32 vertcalScale);
256 
257  dgCollision *CreateScene();
258 
259  void Serialize(const dgCollision *shape, dgSerialize deserialization, void *const userData) const;
260  dgCollision *CreateFromSerialization(dgDeserialize deserialization, void *const userData);
261 
262  void RemoveFromCache(dgCollision *const collision);
263  void ReleaseCollision(dgCollision *const collision);
264 
265  dgUpVectorConstraint *CreateUpVectorConstraint(const dgVector &pin, dgBody *body);
266 
267  dgBallConstraint *CreateBallConstraint(const dgVector &pivot, dgBody *const body0, dgBody *refBody = NULL);
268  dgHingeConstraint *CreateHingeConstraint(const dgVector &pivot, const dgVector &pin, dgBody *const body0, dgBody *refBody = NULL);
269  dgSlidingConstraint *CreateSlidingConstraint(const dgVector &pivot, const dgVector &pin, dgBody *const body0, dgBody *refBody = NULL);
270  dgCorkscrewConstraint *CreateCorkscrewConstraint(const dgVector &pivot, const dgVector &pin, dgBody *const body0, dgBody *refBody = NULL);
271  dgUniversalConstraint *CreateUniversalConstraint(const dgVector &pivot, const dgVector &pin0, const dgVector &pin1, dgBody *const body0, dgBody *body1 = NULL);
272 
273 
274  void DestroyConstraint(dgConstraint *constraint);
275  dgUnsigned32 CreateBodyGroupID();
276  void RemoveAllGroupID();
277 
278  dgUnsigned32 GetDefualtBodyGroupID() const;
279  dgContactMaterial *GetMaterial(dgUnsigned32 bodyGroupId0, dgUnsigned32 bodyGroupId1) const;
280 
281  dgContactMaterial *GetFirstMaterial() const;
282  dgContactMaterial *GetNextMaterial(dgContactMaterial *material) const;
283 
284  OnGetPerformanceCountCallback GetPerformaceFuntion()const ;
285  void SetPerfomanceCounter(OnGetPerformanceCountCallback callback);
286 
287 // dgUnsigned32 GetPerfomanceTicks (dgInt32 thread, dgUnsigned32 entry) const;
288  dgUnsigned32 GetPerfomanceTicks(dgUnsigned32 entry) const;
289  dgUnsigned32 GetThreadPerfomanceTicks(dgUnsigned32 threadIndex) const;
290 
291  void dgGetUserLock() const;
292  void dgReleasedUserLock() const;
293  void dgGetIndirectLock(dgInt32 *lockVar);
294  void dgReleaseIndirectLock(dgInt32 *lockVar);
295 
296 
297  dgBody *GetSentinelBody() const;
298  dgMemoryAllocator *GetAllocator() const;
299 
300 private:
301  void CalculateContacts(dgCollidingPairCollector::dgPair *const pair, dgFloat32 timestep, dgInt32 threadIndex);
302  void CalculateContactsSimd(dgCollidingPairCollector::dgPair *const pair, dgFloat32 timestep, dgInt32 threadIndex);
303 
304  void SortContacts(dgContactPoint *const contact, dgInt32 count) const;
305  dgInt32 ReduceContacts(dgInt32 count, dgContactPoint *const contact, dgInt32 maxCount, dgFloat32 tol, dgInt32 arrayIsSorted = 0) const;
306  dgInt32 PruneContacts(dgInt32 count, dgContactPoint *const contact, dgInt32 maxCount = (DG_CONSTRAINT_MAX_ROWS / 3)) const;
307 
308  dgInt32 CalculateHullToHullContacts(dgCollisionParamProxy &proxy) const;
309  dgInt32 CalculateHullToHullContactsSimd(dgCollisionParamProxy &proxy) const;
310  dgInt32 CalculateBoxToSphereContacts(dgCollisionParamProxy &proxy) const;
311  dgInt32 CalculateSphereToSphereContacts(dgCollisionParamProxy &proxy) const;
312  dgInt32 CalculateCapsuleToSphereContacts(dgCollisionParamProxy &proxy) const;
313  dgInt32 CalculateCapsuleToCapsuleContacts(dgCollisionParamProxy &proxy) const;
314  dgInt32 SphereSphereCollision(const dgVector &sph0, dgFloat32 radius0, const dgVector &sph1, dgFloat32 radius1, dgCollisionParamProxy &proxy) const;
315 
316 
317  dgInt32 ValidateContactCache(dgBody *const convexBody, dgBody *const otherBody, dgContact *const contact) const;
318 
319 
320  dgInt32 CalculatePolySoupToBoxContactsDescrete(dgBody *soup, dgBody *box, dgContactPoint *const contact, dgInt32 maxContacts) const;
321  dgInt32 CalculatePolySoupToHullContactsDescrete(dgCollisionParamProxy &proxy) const;
322  dgInt32 CalculatePolySoupToHullContactsDescreteSimd(dgCollisionParamProxy &proxy) const;
323 
324  dgInt32 CalculatePolySoupToSphereContactsDescrete(dgCollisionParamProxy &proxy) const;
325  dgInt32 CalculatePolySoupToElipseContactsDescrete(dgCollisionParamProxy &proxy) const;
326  dgInt32 CalculatePolySoupToSphereContactsContinue(dgCollisionParamProxy &proxy) const;
327  dgInt32 CalculateConvexToNonConvexContactsContinue(dgCollisionParamProxy &proxy) const;
328  dgInt32 CalculateConvexToNonConvexContactsContinueSimd(dgCollisionParamProxy &proxy) const;
329 
330 
331 // dgInt32 CalculateConvexToConvexContinuesContacts (dgFloat32& timestep, dgBody* body1, dgBody* body2, dgContactPoint contactOut[]) const;
332 // dgInt32 CalculateConvexToConvexContinuesContacts (dgCollisionParamProxy& proxy) const;
333 // dgInt32 CalculateConvexToConvexContinuesContacts (dgCollisionParamProxy& proxy) const;
334 // dgInt32 CalculateConvexToConvexContacts (dgFloat32& timestep, dgBody* conv1, dgBody* conv2, dgFloat32 penetrationPadding, dgContactPoint* const contact) const;
335 // dgInt32 CalculateConvexToConvexContactsSimd (dgFloat32& timestep, dgBody* conv1, dgBody* conv2, dgFloat32 penetrationPadding, dgContactPoint* const contact) const;
336  dgInt32 CalculateConvexToConvexContacts(dgCollisionParamProxy &proxy) const;
337  dgInt32 CalculateConvexToConvexContactsSimd(dgCollisionParamProxy &proxy) const;
338 
339 // dgInt32 CalculateConvexToNonConvexContacts (dgFloat32& timestep, dgBody* conv, dgBody* nConv, dgContactPoint* const contact, dgInt32 maxContacts) const;
340  dgInt32 CalculateConvexToNonConvexContacts(dgCollisionParamProxy &proxy) const;
341  dgInt32 CalculateConvexToNonConvexContactsSimd(dgCollisionParamProxy &proxy) const;
342 
343  dgInt32 FilterPolygonEdgeContacts(dgInt32 count, dgContactPoint *const contact) const;
344 
345  void ProcessTriggers(dgCollidingPairCollector::dgPair *const pair, dgFloat32 timestep, dgInt32 threadIndex);
346  void ProcessContacts(dgCollidingPairCollector::dgPair *const pair, dgFloat32 timestep, dgInt32 threadIndex);
347  void ProcessCachedContacts(dgContact *const contact, const dgContactMaterial *const material, dgFloat32 timestep, dgInt32 threadIndex) const;
348 
349  void ConvexContacts(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
350  void ConvexContactsSimd(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
351  void CompoundContacts(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
352  void CompoundContactsSimd(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
353 
354  void SceneContacts(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
355  void SceneContacts(const dgCollisionScene::dgProxy &sceneProxy, dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
356 
357  void SceneContactsSimd(dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
358  void SceneContactsSimd(const dgCollisionScene::dgProxy &sceneProxy, dgCollidingPairCollector::dgPair *const pair, dgCollisionParamProxy &proxy) const;
359 
360  dgInt32 ClosestPoint(dgCollisionParamProxy &proxy) const;
361  dgInt32 ClosestCompoundPoint(dgBody *const compoundConvexA, dgBody *const collisionB, dgTriplex &contactA, dgTriplex &contactB, dgTriplex &normalAB, dgInt32 threadIndex) const;
362 
363  bool AreBodyConnectedByJoints(dgBody *const origin, dgBody *const target);
364 
365  void AddSentinelBody();
366 
367 
368  static void InitConvexCollision();
369  static dgUnsigned32 dgApi GetPerformanceCount();
370 
371  dgUnsigned32 m_dynamicsLru;
372  dgUnsigned32 m_broadPhaseLru;
373  dgUnsigned32 m_inUpdate;
374  dgUnsigned32 m_solverMode;
375  dgUnsigned32 m_frictionMode;
376  dgUnsigned32 m_bodyGroupID;
377  dgUnsigned32 m_defualtBodyGroupID;
378  dgUnsigned32 m_bodiesUniqueID;
379  dgUnsigned32 m_numberOfTheads;
380  dgUnsigned32 m_maxTheads;
381 
382 
383  dgFloat32 m_freezeAccel2;
384  dgFloat32 m_freezeAlpha2;
385  dgFloat32 m_freezeSpeed2;
386  dgFloat32 m_freezeOmega2;
387  dgFloat32 m_frictiomTheshold;
388 
389  dgSolverSleepTherfesholds m_sleepTable[DG_SLEEP_ENTRIES];
390 
391  dgInt32 m_genericLRUMark;
392  dgInt32 m_islandMemorySizeInBytes;
393  dgInt32 m_bodiesMemorySizeInBytes;
394  dgInt32 m_jointsMemorySizeInBytes;
395  dgInt32 m_pairMemoryBufferSizeInBytes;
396  void *m_jointsMemory;
397  void *m_bodiesMemory;
398  void *m_islandMemory;
399  void *m_pairMemoryBuffer;
400 
401 
402  dgInt32 m_singleIslandMultithreading;
403  dgInt32 m_contactBuffersSizeInBytes[DG_MAXIMUN_THREADS];
404  dgInt32 m_jacobiansMemorySizeInBytes[DG_MAXIMUN_THREADS];
405  dgInt32 m_internalForcesMemorySizeInBytes[DG_MAXIMUN_THREADS];
406  void *m_jacobiansMemory[DG_MAXIMUN_THREADS];
407  void *m_internalForcesMemory[DG_MAXIMUN_THREADS];
408  void *m_contactBuffers[DG_MAXIMUN_THREADS];
409 
410  dgBody *m_sentionelBody;
411  dgCollisionPoint *m_pointCollision;
412 
413  void *m_userData;
414  dgMemoryAllocator *m_allocator;
415  dgCpuClass m_cpu;
416  OnIslandUpdate m_islandUpdate;
417  OnDestroyCollision m_destroyCollision;
418  OnLeavingWorldAction m_leavingWorldNotify;
419  OnGetPerformanceCountCallback m_getPerformanceCount;
420  OnBodyDestructionByExeciveForce m_destroyBodyByExeciveForce;
421 
422  dgDetroyBodyByForce m_destroyeddBodiesPool;
423  dgUnsigned32 m_perfomanceCounters[m_counterSize];
424 
425  dgTree<void *, unsigned> m_perInstanceData;
426 
427  dgThreads m_threadsManager;
428  dgWorldDynamicUpdate m_dynamicSolver;
429 
430  friend class dgBody;
431  friend class dgActiveContacts;
432  friend class dgBroadPhaseCell;
433  friend class dgUserConstraint;
434  friend class dgBodyMasterList;
435  friend class dgJacobianMemory;
436  friend class dgCollisionScene;
437  friend class dgCollisionConvex;
438  friend class dgCollisionCompound;
439  friend class dgCollisionHeightField;
440  friend class dgWorldDynamicUpdate;
441  friend class dgParallelSolverSolve;
442  friend class dgBroadPhaseCollision;
443  friend class dgSolverWorlkerThreads;
444  friend class dgCollidingPairCollector;
445  friend class dgParallelSolverClear;
446  friend class dgParallelSolverUpdateForce;
447  friend class dgParallelSolverUpdateVeloc;
448  friend class dgParallelSolverBodyInertia;
450 
451  friend class dgBroadPhaseApplyExternalForce;
452  friend class dgParallelSolverCalculateForces;
458 
461 } DG_GCC_VECTOR_ALIGMENT ;
462 
463 
464 inline void dgWorld::dgGetUserLock() const {
465  if (m_numberOfTheads > 1) {
466  m_threadsManager.dgGetLock();
467  }
468 }
469 
470 inline void dgWorld::dgReleasedUserLock() const {
471  if (m_numberOfTheads > 1) {
472  m_threadsManager.dgReleaseLock();
473  }
474 }
475 
476 
477 inline void dgWorld::dgGetIndirectLock(dgInt32 *lockVar) {
478  m_threadsManager.dgGetIndirectLock(lockVar);
479 }
480 
481 inline void dgWorld::dgReleaseIndirectLock(dgInt32 *lockVar) {
482  m_threadsManager.dgReleaseIndirectLock(lockVar);
483 }
484 
485 inline dgMemoryAllocator *dgWorld::GetAllocator() const {
486  return m_allocator;
487 }
488 
489 inline void dgWorld::AddToBreakQueue(const dgContact *const contactJoint, dgBody *const body, dgFloat32 maxForce) {
490 // if (body->GetCollision()->GetBreakImpulse() < maxForce) {
491  if (m_destroyeddBodiesPool.m_count < DG_MAX_DESTROYED_BODIES_BY_FORCE) {
492  if (body->m_isInDerstruionArrayLRU != body->m_dynamicsLru) {
493  body->m_isInDerstruionArrayLRU = body->m_dynamicsLru;
494  m_destroyeddBodiesPool.m_force[m_destroyeddBodiesPool.m_count] = maxForce;
495  m_destroyeddBodiesPool.m_bodies[m_destroyeddBodiesPool.m_count] = body;
496  m_destroyeddBodiesPool.m_joint[m_destroyeddBodiesPool.m_count] = contactJoint;
497  m_destroyeddBodiesPool.m_count ++;
498  } else {
499  for (dgInt32 i = 0; i < m_destroyeddBodiesPool.m_count; i ++) {
500  if (m_destroyeddBodiesPool.m_bodies[i] == body) {
501  if (maxForce > m_destroyeddBodiesPool.m_force[i]) {
502  m_destroyeddBodiesPool.m_force[i] = maxForce;
503  m_destroyeddBodiesPool.m_joint[i] = contactJoint;
504  }
505  }
506  }
507  }
508  }
509 // }
510 }
511 
512 
513 //inline void dgWorld::AddToBreakQueue (const dgContact* const contactJoint, dgFloat32 maxImpulse)
514 //{
515 // AddToBreakQueue (contactJoint, contactJoint->m_body0, maxForce);
516 // AddToBreakQueue (contactJoint, contactJoint->m_body1, maxForce);
517 //}
518 
519 
520 
521 #endif // !defined(AFX_DGPHYSICSWORLD_H__EC18C699_D48D_448F_A510_A865B2CC0789__INCLUDED_)
Definition: dgWorldDynamicUpdate.h:226
Definition: dgWorldDynamicUpdate.h:129
Definition: dgWorldDynamicUpdate.h:101
Definition: dgContact.h:201
Definition: dgWorldDynamicUpdate.h:143
Definition: dgContact.h:51
Definition: dgBodyMasterList.h:56
Definition: dgBroadPhaseCollision.h:170
Definition: dgBody.h:85
Definition: dgWorldDynamicUpdate.h:239
Definition: dgCollisionUserMesh.h:37
Definition: dgWorldDynamicUpdate.h:282
Definition: dgVector.h:86
Definition: dgCorkscrewConstraint.h:32
Definition: dgBroadPhaseCollision.h:66
Definition: dgBroadPhaseCollision.h:136
Definition: dgWorld.h:108
Definition: dgWorldDynamicUpdate.h:158
Definition: dgBallConstraint.h:32
Definition: dgWorldDynamicUpdate.h:203
Definition: dgBroadPhaseCollision.h:146
Definition: dgUserConstraint.h:30
Definition: dgMeshEffect.h:78
Definition: dgBroadPhaseCollision.h:158
Definition: dgContact.h:88
Definition: dgWorldDynamicUpdate.h:168
Definition: dgWorldDynamicUpdate.h:342
Definition: dgTree.h:88
Definition: dgWorld.h:66
Definition: dgHingeConstraint.h:32
Definition: dgWorldDynamicUpdate.h:117
Definition: dgWorldDynamicUpdate.h:188
Definition: dgWorld.h:127
Definition: dgContact.h:44
Definition: dgWorldDynamicUpdate.h:257
Definition: dgCollisionScene.h:29
Definition: dgCollisionConvex.h:39
Definition: dgUpVectorConstraint.h:32
Definition: dgSlidingConstraint.h:31
Definition: dgCollisionHeightField.h:32
Definition: dgCollisionScene.h:47
Definition: dgContact.h:138
Definition: dgCollision.h:178
Definition: dgMatrix.h:41
Definition: dgMemory.h:80
Definition: dgBroadPhaseCollision.h:124
Definition: dgUniversalConstraint.h:32
Definition: dgWorld.h:74
Definition: dgConstraint.h:169
Definition: dgWorld.h:118
Definition: dgCollisionSphere.h:78
Definition: dgThreads.h:40
Definition: dgTypes.h:70
Definition: dgContact.h:53
Definition: dgCollisionCompound.h:31
Definition: dgContact.h:102