aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/PhysX/src/buffering/ScbScene.h
blob: 3314227c50305ee19d197bdb4230e28fdedb3c88 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  

#ifndef PX_PHYSICS_SCB_SCENE
#define PX_PHYSICS_SCB_SCENE

#include "ScScene.h"

#include "ScbSceneBuffer.h"
#include "ScbType.h"
#include "PsFoundation.h"
#include "PsMutex.h"
#include "PsHashSet.h"

#if PX_SUPPORT_PVD
#include "PxPhysics.h"
#include "ScbScenePvdClient.h"
#endif

namespace physx
{

class NpMaterial;

namespace Sc
{
	class BodyDesc;
}

namespace Scb
{
	class Base;
	class RigidObject;
	class RigidStatic;
	class Body;
	class Actor;
	class Shape;
	class Constraint;
	class Material;
	class ParticleSystem;
	class Articulation;
	class ArticulationJoint;
	class Aggregate;
	class Cloth;

	struct ShapeBuffer;

	/**
	\brief Helper class to track inserted/removed/updated buffering objects.
	*/
	class ObjectTracker
	{
	public:
		 ObjectTracker() {}
		 
		/**
		\brief An object has been inserted while the simulation was running -> track it for insertion at sync point
		*/
		void scheduleForInsert(Base& element);

		/**
		\brief An object has been removed while the simulation was running -> track it for removal at sync point
		*/
		void scheduleForRemove(Base& element);

		/**
		\brief An object has been changed while the simulation was running -> track it for update at sync point
		*/
		void scheduleForUpdate(Base& element);
		
		/**
		\brief Get the list of dirty objects that require processing at a sync point.
		*/
		Base*const *		getBuffered()				{ return mBuffered.getEntries();	}

		/**
		\brief Get number of dirty objects that require processing at a sync point.
		*/
		PxU32				getBufferedCount()	const	{ return mBuffered.size();	}
		
		/**
		\brief Cleanup dirty objects after sync point.

		\li Transition pending insertion objects from eINSERT_PENDING to eIN_SCENE.
		\li Transition pending removal objects from eREMOVE_PENDING to eNOT_IN_SCENE.
		\li Destroy objects marked as eIS_RELEASED.
		\li Clear dirty list.
		*/
		void clear();
	
		void insert(Base& element);
		void remove(Base& element);
		
	private:
		Ps::CoalescedHashSet<Base*> mBuffered;	
	};

	typedef ObjectTracker	ShapeManager;
	typedef ObjectTracker	RigidStaticManager;
	typedef ObjectTracker	BodyManager;
	typedef ObjectTracker	ParticleSystemManager;
	typedef ObjectTracker	ArticulationManager;
	typedef ObjectTracker	ConstraintManager;
	typedef ObjectTracker	ArticulationJointManager;
	typedef ObjectTracker	AggregateManager;
	typedef ObjectTracker	ClothManager;

	enum MATERIAL_EVENT
	{
		MATERIAL_ADD,
		MATERIAL_UPDATE,
		MATERIAL_REMOVE
	};

	class MaterialEvent
	{
	public:
		PX_FORCE_INLINE	MaterialEvent(PxU32 handle, MATERIAL_EVENT type) : mHandle(handle), mType(type)	{}
		PX_FORCE_INLINE	MaterialEvent()																	{}

		PxU32			mHandle;//handle to the master material table
		MATERIAL_EVENT	mType;
	};

	class Scene : public Ps::UserAllocated
	{
		PX_NOCOPY(Scene)
	public:
		enum BufferFlag
		{
			BF_GRAVITY					= (1 << 0),
			BF_BOUNCETHRESHOLDVELOCITY  = (1 << 1),
			BF_FLAGS					= (1 << 2),
			BF_DOMINANCE_PAIRS			= (1 << 3),
			BF_SOLVER_BATCH_SIZE		= (1 << 4),
			BF_CLIENT_BEHAVIOR_FLAGS	= (1 << 5),
			BF_VISUALIZATION			= (1 << 6),
			BF_CULLING_BOX				= (1 << 7)
		};

	public:
											Scene(const PxSceneDesc& desc, PxU64 contextID);
											~Scene() {}	//use release() plz.

		//---------------------------------------------------------------------------------
		// Wrapper for Sc::Scene interface
		//---------------------------------------------------------------------------------
		void								release();

		PxScene*							getPxScene(); 

		PX_INLINE void						setGravity(const PxVec3& gravity);
		PX_INLINE PxVec3					getGravity() const;

		PX_INLINE void						setBounceThresholdVelocity(const PxReal t);
		PX_INLINE PxReal					getBounceThresholdVelocity() const;

		PX_INLINE void						setFlags(PxSceneFlags flags);
		PX_INLINE PxSceneFlags				getFlags() const;

		PX_INLINE void						setFrictionType(PxFrictionType::Enum type)	{ mScene.setFrictionType(type);		}
		PX_INLINE PxFrictionType::Enum		getFrictionType()					const	{ return mScene.getFrictionType();	}

		void 								addActor(Scb::RigidStatic&, bool noSim, PxBounds3* uninflatedBounds);
		void 								removeActor(Scb::RigidStatic&, bool wakeOnLostTouch, bool noSim);

		void 								addActor(Scb::Body&, bool noSim, PxBounds3* uninflatedBounds);
		void 								removeActor(Scb::Body&, bool wakeOnLostTouch, bool noSim);

		void								addConstraint(Scb::Constraint&);
		void								removeConstraint(Scb::Constraint&);

		void								addArticulation(Scb::Articulation&);
		void								removeArticulation(Scb::Articulation&);

		void								addArticulationJoint(Scb::ArticulationJoint&);
		void								removeArticulationJoint(Scb::ArticulationJoint&);

		void								addAggregate(Scb::Aggregate&);
		void								removeAggregate(Scb::Aggregate&);

	#if PX_USE_PARTICLE_SYSTEM_API
		void								addParticleSystem(Scb::ParticleSystem&);
		void								removeParticleSystem(Scb::ParticleSystem&, bool isRelease);
	#endif

	#if PX_USE_CLOTH_API
		void								addCloth(Scb::Cloth&);
		void								removeCloth(Scb::Cloth&);
	#endif

		void								addMaterial(const Sc::MaterialCore& mat);
		void								updateMaterial(const Sc::MaterialCore& mat);
		void								removeMaterial(const Sc::MaterialCore& mat);
		void								updateLowLevelMaterial(NpMaterial** masterMaterials);
		// These methods are only to be called at fetchResults!
		PX_INLINE PxU32						getNumActiveBodies()	const	{ return mScene.getNumActiveBodies();	}
		PX_INLINE Sc::BodyCore* const*		getActiveBodiesArray()	const	{ return mScene.getActiveBodiesArray();	}

		PX_INLINE PxSimulationEventCallback*	getSimulationEventCallback(PxClientID client) const;
		PX_INLINE void						setSimulationEventCallback(PxSimulationEventCallback* callback, PxClientID client);
		PX_INLINE PxContactModifyCallback*	getContactModifyCallback() const;
		PX_INLINE void						setContactModifyCallback(PxContactModifyCallback* callback);
		PX_INLINE PxCCDContactModifyCallback*	getCCDContactModifyCallback() const;
		PX_INLINE void						setCCDContactModifyCallback(PxCCDContactModifyCallback* callback);
		PX_INLINE PxU32						getCCDMaxPasses() const;
		PX_INLINE void						setCCDMaxPasses(PxU32 ccdMaxPasses);
		PX_INLINE	void					setBroadPhaseCallback(PxBroadPhaseCallback* callback, PxClientID client);
		PX_INLINE	PxBroadPhaseCallback*	getBroadPhaseCallback(PxClientID client)		const;
					PxBroadPhaseType::Enum	getBroadPhaseType()																				const;
					bool					getBroadPhaseCaps(PxBroadPhaseCaps& caps)														const;
					PxU32					getNbBroadPhaseRegions()																		const;
					PxU32					getBroadPhaseRegions(PxBroadPhaseRegionInfo* userBuffer, PxU32 bufferSize, PxU32 startIndex)	const;
					PxU32					addBroadPhaseRegion(const PxBroadPhaseRegion& region, bool populateRegion);
					bool					removeBroadPhaseRegion(PxU32 handle);

		// Collision filtering
		PX_INLINE void						setFilterShaderData(const void* data, PxU32 dataSize);
		PX_INLINE const void*				getFilterShaderData() const;
		PX_INLINE PxU32						getFilterShaderDataSize() const;
		PX_INLINE PxSimulationFilterShader	getFilterShader() const;
		PX_INLINE PxSimulationFilterCallback* getFilterCallback() const;

		// Groups
		PX_INLINE void						setDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2, const PxDominanceGroupPair& dominance);
		PX_INLINE PxDominanceGroupPair		getDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2) const;

		PX_INLINE void						setSolverBatchSize(PxU32 solverBatchSize);
		PX_INLINE PxU32						getSolverBatchSize() const;

		PX_INLINE void						simulate(PxReal timeStep, PxBaseTask* continuation)	{ mScene.simulate(timeStep, continuation);	}
		PX_INLINE void						collide(PxReal timeStep, PxBaseTask* continuation)	{ mScene.collide(timeStep, continuation);	}
		PX_INLINE void						advance(PxReal timeStep, PxBaseTask* continuation)	{ mScene.advance(timeStep, continuation);	}
		PX_INLINE void						endSimulation()										{ mScene.endSimulation();					}

		PX_INLINE void						flush(bool sendPendingReports);
		PX_INLINE void						fireBrokenConstraintCallbacks()		{ mScene.fireBrokenConstraintCallbacks(); }
		PX_INLINE void						fireTriggerCallbacks()				{ mScene.fireTriggerCallbacks();  }
		PX_INLINE void						fireQueuedContactCallbacks()		{ mScene.fireQueuedContactCallbacks(false); }
		PX_INLINE const Ps::Array<PxContactPairHeader>&
											getQueuedContactPairHeaders()		{ return mScene.getQueuedContactPairHeaders(); }
		PX_FORCE_INLINE void				postCallbacksPreSync()				{ mScene.postCallbacksPreSync(); }  //cleanup tasks after the pre-sync callbacks have fired

		PX_INLINE void						fireCallBacksPostSync()				{ mScene.fireCallbacksPostSync(); }	//callbacks that are fired on the core side, after the buffers get synced
		PX_INLINE void						postReportsCleanup();

		PX_INLINE const PxSceneLimits&		getLimits()	const						{ return mScene.getLimits();	}
		PX_INLINE void						setLimits(const PxSceneLimits& limits)	{ mScene.setLimits(limits);		}

		PX_INLINE void						getStats(PxSimulationStatistics& stats) const;

		PX_DEPRECATED PX_INLINE void					buildActiveTransforms(); // build the list of active transforms
		PX_DEPRECATED PX_INLINE PxActiveTransform*		getActiveTransforms(PxU32& nbTransformsOut, PxClientID client);

		PX_INLINE void						buildActiveActors(); // build the list of active actors
		PX_INLINE PxActor**					getActiveActors(PxU32& nbActorsOut, PxClientID client);

		PX_INLINE PxClientID				createClient();
		PX_INLINE void						setClientBehaviorFlags(PxClientID client, PxClientBehaviorFlags clientBehaviorFlags);
		PX_INLINE PxClientBehaviorFlags		getClientBehaviorFlags(PxClientID client) const;

#if PX_USE_CLOTH_API
		PX_INLINE void						setClothInterCollisionDistance(PxF32 distance);
		PX_INLINE PxF32						getClothInterCollisionDistance() const;
		PX_INLINE void						setClothInterCollisionStiffness(PxF32 stiffness); 
		PX_INLINE PxF32						getClothInterCollisionStiffness() const;
		PX_INLINE void						setClothInterCollisionNbIterations(PxU32 nbIterations);
		PX_INLINE PxU32						getClothInterCollisionNbIterations() const;
#endif

		PX_INLINE void						setVisualizationParameter(PxVisualizationParameter::Enum param, PxReal value);
		PX_INLINE PxReal					getVisualizationParameter(PxVisualizationParameter::Enum param) const;

		PX_INLINE void						setVisualizationCullingBox(const PxBounds3& box);
		PX_INLINE const PxBounds3&			getVisualizationCullingBox() const;

		void								shiftOrigin(const PxVec3& shift);

		//---------------------------------------------------------------------------------
		// Data synchronization
		//---------------------------------------------------------------------------------
	public:
		void								syncWriteThroughProperties();
		void								syncEntireScene();
		void								processPendingRemove();

		PX_FORCE_INLINE	PxU16*				allocShapeMaterialBuffer(PxU32 count, PxU32& startIdx)	{ return allocArrayBuffer(mShapeMaterialBuffer, count, startIdx);	}
		PX_FORCE_INLINE	const PxU16*		getShapeMaterialBuffer(PxU32 startIdx)			const	{ return &mShapeMaterialBuffer[startIdx];							}
		PX_FORCE_INLINE	Scb::Shape**		allocShapeBuffer(PxU32 count, PxU32& startIdx)			{ return allocArrayBuffer(mShapePtrBuffer, count, startIdx);		}
		PX_FORCE_INLINE	Scb::Shape**		getShapeBuffer(PxU32 startIdx)							{ return &mShapePtrBuffer[startIdx];								}
		PX_FORCE_INLINE	Scb::Actor**		allocActorBuffer(PxU32 count, PxU32& startIdx)			{ return allocArrayBuffer(mActorPtrBuffer, count, startIdx);		}
		PX_FORCE_INLINE	Scb::Actor**		getActorBuffer(PxU32 startIdx)							{ return &mActorPtrBuffer[startIdx];								}

						void				scheduleForUpdate(Scb::Base& object);
						PxU8*				getStream(ScbType::Enum type);

		PX_FORCE_INLINE void				removeShapeFromPendingUpdateList(Scb::Base& shape) { mShapeManager.remove(shape); }

		PX_FORCE_INLINE	const Sc::Scene&	getScScene()					const	{ return mScene;						}
		PX_FORCE_INLINE	Sc::Scene&			getScScene()							{ return mScene;						}
		PX_FORCE_INLINE void				prepareOutOfBoundsCallbacks()			{ mScene.prepareOutOfBoundsCallbacks();	}

	private:
						void				syncState();
		PX_FORCE_INLINE	Ps::IntBool			isBuffered(BufferFlag f)	const	{ return Ps::IntBool(mBufferFlags& f);	}
		PX_FORCE_INLINE	void				markUpdated(BufferFlag f)			{ mBufferFlags |= f;					}

		//---------------------------------------------------------------------------------
		// Miscellaneous
		//---------------------------------------------------------------------------------
	public:

		PX_FORCE_INLINE bool				isPhysicsBuffering()			const	{ return mIsBuffering;					}
		PX_FORCE_INLINE void				setPhysicsBuffering(bool buffering)		{ mIsBuffering = buffering;				}

		PX_FORCE_INLINE Sc::SimulationStage::Enum getSimulationStage()		const	{ return mScene.getSimulationStage(); }
		PX_FORCE_INLINE void				setSimulationStage(Sc::SimulationStage::Enum stage) { mScene.setSimulationStage(stage); }

#if PX_USE_PARTICLE_SYSTEM_API
		void								preSimulateUpdateAppThread(PxReal timeStep);	// Data updates that need to be handled in the application thread before the simulation potentially switches																					// to its own thread.
#endif

		PX_FORCE_INLINE bool				isValid()								const	{ return mScene.isValid();				}

		PX_FORCE_INLINE PxReal				getWakeCounterResetValue() const { return mWakeCounterResetValue; }

		void								switchRigidToNoSim(Scb::RigidObject&, bool isDynamic);
		void								switchRigidFromNoSim(Scb::RigidObject&, bool isDynamic);

		static size_t						getScOffset()	{ return reinterpret_cast<size_t>(&reinterpret_cast<Scene*>(0)->mScene); }

#if PX_SUPPORT_PVD
		PX_FORCE_INLINE	Vd::ScbScenePvdClient&			getScenePvdClient()			{ return mScenePvdClient; }
		PX_FORCE_INLINE	const Vd::ScbScenePvdClient&	getScenePvdClient() const	{ return mScenePvdClient; }
#endif
		PX_FORCE_INLINE	PxU64				getContextId() const { return mScene.getContextId(); }

	private:
						void				addShapeInternal(Scb::Shape&);
						void				addShapesInternal(PxU32 nbShapes, PxShape** PX_RESTRICT shapes, size_t scbOffset, PxActor** PX_RESTRICT owners, PxU32 offsetNpToCore, bool isDynamic);

		template<typename T> T*				allocArrayBuffer(Ps::Array<T>& buffer, PxU32 count, PxU32& startIdx);

	private:

	template<bool TIsDynamic, class T>
	PX_FORCE_INLINE void addActorT(T& actor, ObjectTracker& tracker, bool noSim, PxBounds3* uninflatedBounds);

	template<typename T>												void add(T& v, ObjectTracker& tracker, PxBounds3* uninflatedBounds);
	template<typename T>												void remove(T& v, ObjectTracker& tracker, bool wakeOnLostTouch = false);
	template<bool TIsDynamic, typename T>								void addRigidNoSim(T& v, ObjectTracker& tracker);
	template<bool TIsDynamic, typename T>								void removeRigidNoSim(T& v, ObjectTracker& tracker);
	template<typename T, typename S>									void processSimUpdates(S*const * scObjects, PxU32 nbObjects);
	template<typename T>												void processUserUpdates(ObjectTracker& tracker);
	template<typename T, bool syncOnRemove, bool wakeOnLostTouchCheck>	void processRemoves(ObjectTracker& tracker);
	template<typename T>												void processShapeRemoves(ObjectTracker& tracker);

					Sc::Scene							mScene;
 
					Ps::Array<MaterialEvent>			mSceneMaterialBuffer;
					Ps::Mutex							mSceneMaterialBufferLock;
				
					bool								mSimulationRunning;
					bool								mIsBuffering;

					Cm::FlushPool						mStream;  // Pool for temporarily buffering user changes on objects
					ShapeManager						mShapeManager;
					Ps::Array<PxU16>					mShapeMaterialBuffer;  // Buffered setMaterial() call might need to track list of materials (for multi material shapes)
					Ps::Array<Scb::Shape*>				mShapePtrBuffer;  // List of shape pointers to track buffered calls to resetFiltering(), for example
					Ps::Array<Scb::Actor*>				mActorPtrBuffer;
					RigidStaticManager					mRigidStaticManager;
					BodyManager							mBodyManager;
#if PX_USE_PARTICLE_SYSTEM_API
					ParticleSystemManager				mParticleSystemManager;
#endif
					ConstraintManager					mConstraintManager;
					ArticulationManager					mArticulationManager;
					ArticulationJointManager			mArticulationJointManager;
					AggregateManager					mAggregateManager;
#if PX_USE_CLOTH_API
					ClothManager						mClothManager;
#endif
#if PX_SUPPORT_PVD
					Vd::ScbScenePvdClient				mScenePvdClient;
#endif

	PX_FORCE_INLINE	void								updatePvdProperties()
					{
#if PX_SUPPORT_PVD
						// PT: TODO: shouldn't we test PxPvdInstrumentationFlag::eDEBUG here?						
                        if(mScenePvdClient.isConnected())
                            mScenePvdClient.updatePvdProperties(); 
#endif
					}

					PxReal								mWakeCounterResetValue;

					// note: If deletion of rigid objects is done before the sync of the simulation data then we
					//       might wanna consider having a separate list for deleted rigid objects (for performance
					//       reasons)

					//---------------------------------------------------------------------------------
					// On demand buffered data (simulation read-only data)
					//---------------------------------------------------------------------------------
					Scb::SceneBuffer					mBufferedData;
					PxU32								mBufferFlags;
	};

}  // namespace Scb

template<typename T>
T* Scb::Scene::allocArrayBuffer(Ps::Array<T>& buffer, PxU32 count, PxU32& startIdx)
{
	PxU32 oldSize = buffer.size();
	buffer.resize(oldSize + count);
	startIdx = oldSize;
	return &buffer[oldSize];
}
		
PX_INLINE void Scb::Scene::setGravity(const PxVec3& gravity)
{
	if(!isPhysicsBuffering())
	{
		mScene.setGravity(gravity);
		updatePvdProperties();
	}
	else
	{
		mBufferedData.mGravity = gravity;
		markUpdated(BF_GRAVITY);
	}
}

PX_INLINE PxVec3 Scb::Scene::getGravity() const
{
	if(isBuffered(BF_GRAVITY))
		return mBufferedData.mGravity;
	else
		return mScene.getGravity();
}

void Scb::Scene::setBounceThresholdVelocity(const PxReal t)
{
	if(!isPhysicsBuffering())
	{
		mScene.setBounceThresholdVelocity(t);
		updatePvdProperties();
	}
	else
	{
		mBufferedData.mBounceThresholdVelocity = t;
		markUpdated(BF_BOUNCETHRESHOLDVELOCITY);
	}
}

PxReal Scb::Scene::getBounceThresholdVelocity() const
{
	if(isBuffered(BF_BOUNCETHRESHOLDVELOCITY))
		return mBufferedData.mBounceThresholdVelocity;
	else
		return mScene.getBounceThresholdVelocity();
}

PX_INLINE void Scb::Scene::setFlags(PxSceneFlags flags)
{
	if(!isPhysicsBuffering())
	{
		mScene.setPublicFlags(flags);
		const bool pcm = (flags & PxSceneFlag::eENABLE_PCM);
		mScene.setPCM(pcm);
		const bool contactCache = !(flags & PxSceneFlag::eDISABLE_CONTACT_CACHE);
		mScene.setContactCache(contactCache);
		updatePvdProperties();
	}
	else
	{
		mBufferedData.mFlags = flags;
		markUpdated(BF_FLAGS);
	}
}

PX_INLINE PxSceneFlags Scb::Scene::getFlags() const
{
	if(isBuffered(BF_FLAGS))
		return mBufferedData.mFlags;
	else
		return mScene.getPublicFlags();
}

///////////////////////////////////////////////////////////////////////////////

PX_INLINE PxSimulationEventCallback* Scb::Scene::getSimulationEventCallback(PxClientID client) const
{
	return mScene.getSimulationEventCallback(client);
}

PX_INLINE void Scb::Scene::setSimulationEventCallback(PxSimulationEventCallback* callback, PxClientID client)
{
	if(!isPhysicsBuffering())
		mScene.setSimulationEventCallback(callback, client);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setSimulationEventCallback() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxContactModifyCallback* Scb::Scene::getContactModifyCallback() const
{
	return mScene.getContactModifyCallback();
}

PX_INLINE void Scb::Scene::setContactModifyCallback(PxContactModifyCallback* callback)
{
	if(!isPhysicsBuffering())
		mScene.setContactModifyCallback(callback);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setContactModifyCallback() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxCCDContactModifyCallback* Scb::Scene::getCCDContactModifyCallback() const
{
	return mScene.getCCDContactModifyCallback();
}

PX_INLINE void Scb::Scene::setCCDContactModifyCallback(PxCCDContactModifyCallback* callback)
{
	if(!isPhysicsBuffering())
		mScene.setCCDContactModifyCallback(callback);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setCCDContactModifyCallback() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxU32 Scb::Scene::getCCDMaxPasses() const
{
	return mScene.getCCDMaxPasses();
}

PX_INLINE void Scb::Scene::setCCDMaxPasses(PxU32 ccdMaxPasses)
{
	if(!isPhysicsBuffering())
		mScene.setCCDMaxPasses(ccdMaxPasses);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setCCDMaxPasses() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxBroadPhaseCallback* Scb::Scene::getBroadPhaseCallback(PxClientID client) const
{
	return mScene.getBroadPhaseCallback(client);
}

PX_INLINE void Scb::Scene::setBroadPhaseCallback(PxBroadPhaseCallback* callback, PxClientID client)
{
	if(!isPhysicsBuffering())
		mScene.setBroadPhaseCallback(callback, client);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setBroadPhaseCallback() not allowed while simulation is running. Call will be ignored.");
}

///////////////////////////////////////////////////////////////////////////////

PX_INLINE void Scb::Scene::setFilterShaderData(const void* data, PxU32 dataSize)
{
	if(!isPhysicsBuffering())
		mScene.setFilterShaderData(data, dataSize);
	else
		Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "PxScene::setFilterShaderData() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE const void* Scb::Scene::getFilterShaderData() const
{
	return mScene.getFilterShaderDataFast();
}

PX_INLINE PxU32 Scb::Scene::getFilterShaderDataSize() const
{
	return mScene.getFilterShaderDataSizeFast();
}

PX_INLINE PxSimulationFilterShader Scb::Scene::getFilterShader() const
{
	return mScene.getFilterShaderFast();
}

PX_INLINE PxSimulationFilterCallback* Scb::Scene::getFilterCallback() const
{
	return mScene.getFilterCallbackFast();
}

PX_INLINE void Scb::Scene::flush(bool sendPendingReports)
{
	PX_ASSERT(!isPhysicsBuffering());

	mShapeMaterialBuffer.reset();
	mShapePtrBuffer.reset();
	mActorPtrBuffer.reset();

	//!!! TODO: Clear all buffers used for double buffering changes (see ObjectTracker::mBufferPool)

	mScene.flush(sendPendingReports);
}

PX_INLINE void Scb::Scene::postReportsCleanup()
{
	PX_ASSERT(!isPhysicsBuffering());
	mScene.postReportsCleanup();
}

PX_INLINE void Scb::Scene::setDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2, const PxDominanceGroupPair& dominance)
{
	if(!isPhysicsBuffering())
	{
		mScene.setDominanceGroupPair(group1, group2, dominance);
		updatePvdProperties();
	}
	else
	{
		mBufferedData.setDominancePair(group1, group2, dominance);
		markUpdated(BF_DOMINANCE_PAIRS);
	}
}

PX_INLINE PxDominanceGroupPair Scb::Scene::getDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2) const
{
	if(isBuffered(BF_DOMINANCE_PAIRS))
	{
		PxDominanceGroupPair dominance(0, 0);
		if(mBufferedData.getDominancePair(group1, group2, dominance))
			return dominance;
	}

	return mScene.getDominanceGroupPair(group1, group2);
}

PX_INLINE void Scb::Scene::setSolverBatchSize(PxU32 solverBatchSize)
{
	if(!isPhysicsBuffering())
	{
		mScene.setSolverBatchSize(solverBatchSize);
		updatePvdProperties();
	}
	else
	{
		mBufferedData.mSolverBatchSize = solverBatchSize;
		markUpdated(BF_SOLVER_BATCH_SIZE);
	}
}

PX_INLINE PxU32 Scb::Scene::getSolverBatchSize() const
{
	if(isBuffered(BF_SOLVER_BATCH_SIZE))
		return mBufferedData.mSolverBatchSize;
	else
		return mScene.getSolverBatchSize();
}

PX_INLINE void Scb::Scene::getStats(PxSimulationStatistics& stats) const
{
	PX_ASSERT(!isPhysicsBuffering());

	mScene.getStats(stats);
}

PX_DEPRECATED PX_INLINE void Scb::Scene::buildActiveTransforms()
{
	PX_ASSERT(!isPhysicsBuffering());

	mScene.buildActiveTransforms();
}

PX_DEPRECATED PX_INLINE PxActiveTransform* Scb::Scene::getActiveTransforms(PxU32& nbTransformsOut, PxClientID client)
{
	if(!isPhysicsBuffering())
		return mScene.getActiveTransforms(nbTransformsOut, client);
	else
	{
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::getActiveTransforms() not allowed while simulation is running. Call will be ignored.");
		nbTransformsOut = 0;
		return NULL;
	}
}

PX_INLINE void Scb::Scene::buildActiveActors()
{
	PX_ASSERT(!isPhysicsBuffering());

	mScene.buildActiveActors();
}

PX_INLINE PxActor** Scb::Scene::getActiveActors(PxU32& nbActorsOut, PxClientID client)
{
	if(!isPhysicsBuffering())
		return mScene.getActiveActors(nbActorsOut, client);
	else
	{
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::getActiveActors() not allowed while simulation is running. Call will be ignored.");
		nbActorsOut = 0;
		return NULL;
	}
}

PX_INLINE PxClientID Scb::Scene::createClient()
{
	mBufferedData.mClientBehaviorFlags.pushBack(PxClientBehaviorFlag_eNOT_BUFFERED);		//PxClientBehaviorFlag_eNOT_BUFFERED means its not storing anything.  Do this either way to make sure this buffer is big enough for behavior bit set/gets later.

	if(!isPhysicsBuffering())
	{
		PxClientID i = mScene.createClient();
		PX_ASSERT(mBufferedData.mClientBehaviorFlags.size()-1 == i);
		return i;
	}
	else
	{
		mBufferedData.mNumClientsCreated++;
		return PxClientID(mBufferedData.mClientBehaviorFlags.size()-1);	//mScene.createClient();
	}
}

PX_INLINE void Scb::Scene::setClientBehaviorFlags(PxClientID client, PxClientBehaviorFlags clientBehaviorFlags)
{
	if(!isPhysicsBuffering())
	{
		mScene.setClientBehaviorFlags(client, clientBehaviorFlags);
		updatePvdProperties();
	}
	else
	{
		PX_ASSERT(mBufferedData.mClientBehaviorFlags.size() > client);
		mBufferedData.mClientBehaviorFlags[client] = clientBehaviorFlags;
		markUpdated(BF_CLIENT_BEHAVIOR_FLAGS);
	}
}

PX_INLINE PxClientBehaviorFlags Scb::Scene::getClientBehaviorFlags(PxClientID client) const
{
	PX_ASSERT(mBufferedData.mClientBehaviorFlags.size() > client);
	if(isBuffered(BF_CLIENT_BEHAVIOR_FLAGS) && (mBufferedData.mClientBehaviorFlags[client] != PxClientBehaviorFlag_eNOT_BUFFERED))
		return mBufferedData.mClientBehaviorFlags[client];
	else
		return mScene.getClientBehaviorFlags(client);
}

#if PX_USE_CLOTH_API

PX_INLINE void Scb::Scene::setClothInterCollisionDistance(PxF32 distance)
{
	if(!isPhysicsBuffering())
		mScene.setClothInterCollisionDistance(distance);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setClothInterCollisionDistance() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxF32	Scb::Scene::getClothInterCollisionDistance() const
{
	return mScene.getClothInterCollisionDistance();
}

PX_INLINE void Scb::Scene::setClothInterCollisionStiffness(PxF32 stiffness)
{
	if(!isPhysicsBuffering())
		mScene.setClothInterCollisionStiffness(stiffness);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setClothInterCollisionStiffness() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxF32 Scb::Scene::getClothInterCollisionStiffness() const
{
	return mScene.getClothInterCollisionStiffness();
}

PX_INLINE void Scb::Scene::setClothInterCollisionNbIterations(PxU32 nbIterations)
{
	if(!isPhysicsBuffering())
		mScene.setClothInterCollisionNbIterations(nbIterations);
	else
		Ps::getFoundation().error(PxErrorCode::eDEBUG_WARNING, __FILE__, __LINE__, "PxScene::setClothInterCollisionNbIterations() not allowed while simulation is running. Call will be ignored.");
}

PX_INLINE PxU32 Scb::Scene::getClothInterCollisionNbIterations() const
{
	return mScene.getClothInterCollisionNbIterations();
}

#endif

PX_INLINE void Scb::Scene::setVisualizationParameter(PxVisualizationParameter::Enum param, PxReal value)
{
	if(!isPhysicsBuffering())
		mScene.setVisualizationParameter(param, value);
	else
	{
		PX_ASSERT(param < PxVisualizationParameter::eNUM_VALUES);
		mBufferedData.mVisualizationParamChanged[param] = 1;
		mBufferedData.mVisualizationParam[param] = value;
		markUpdated(BF_VISUALIZATION);
	}
}

PX_INLINE PxReal Scb::Scene::getVisualizationParameter(PxVisualizationParameter::Enum param) const
{
	PX_ASSERT(param < PxVisualizationParameter::eNUM_VALUES);

	if(isBuffered(BF_VISUALIZATION) && mBufferedData.mVisualizationParamChanged[param])
		return mBufferedData.mVisualizationParam[param];
	else
		return mScene.getVisualizationParameter(param);
}

PX_INLINE void Scb::Scene::setVisualizationCullingBox(const PxBounds3& box)
{
	if(!isPhysicsBuffering())
		mScene.setVisualizationCullingBox(box);
	else
	{
		mBufferedData.mVisualizationCullingBox = box;
		markUpdated(BF_CULLING_BOX);
	}
}

PX_INLINE const PxBounds3& Scb::Scene::getVisualizationCullingBox() const
{
	if(isBuffered(BF_CULLING_BOX))
		return mBufferedData.mVisualizationCullingBox;
	else
		return mScene.getVisualizationCullingBox();
}

}

#endif