Nebula
Loading...
Searching...
No Matches
physxstate.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
10
11#include "physicsinterface.h"
12#include "physics/callbacks.h"
14#include "util/set.h"
15
16#define MAX_SHAPE_OVERLAPS 256
17
18// we aim for 60hz physics
19#define PHYSICS_RATE 0.016
20
21namespace Physics
22{
23
24class PhysxState : public physx::PxSimulationEventCallback
25{
26public:
27 physx::PxFoundation * foundation;
28 physx::PxPhysics * physics;
29 physx::PxPvd *pvd;
30 physx::PxPvdTransport *transport;
37
39
42
45
46 physx::PxOverlapHit overlapBuffer[MAX_SHAPE_OVERLAPS];
47
49 PhysxState();
51 void Setup();
53 void Shutdown();
54
56 void Update(Timing::Time delta);
57
59 void BeginSimulating(Timing::Time delta, IndexT scene);
61 void EndSimulating(IndexT scene);
62
64 void FlushSimulation(IndexT scene);
65
67 physx::PxRigidActor* CreateActor(ActorType type, Math::mat4 const & transform);
69 physx::PxRigidActor* CreateActor(ActorType type, Math::vec3 const& location, Math::quat const& orientation);
71 void DiscardActor(ActorId id);
72
74 void ConnectPVD();
76 void DisconnectPVD();
77
80 void onConstraintBreak(physx::PxConstraintInfo* constraints, physx::PxU32 count) {}
82 void onWake(physx::PxActor** actors, physx::PxU32 count);
84 void onSleep(physx::PxActor** actors, physx::PxU32 count);
86 void onContact(const physx::PxContactPairHeader& pairHeader, const physx::PxContactPair* pairs, physx::PxU32 nbPairs);
88 void onTrigger(physx::PxTriggerPair* pairs, physx::PxU32 count) {}
90
91 void onAdvance(const physx::PxRigidBody*const* bodyBuffer, const physx::PxTransform* poseBuffer, const physx::PxU32 count) {}
92};
93
94extern PhysxState state;
95}
Definition callbacks.h:19
Definition callbacks.h:33
Definition physxstate.h:25
Util::Set< Ids::Id32 > awakeActors
Definition physxstate.h:36
physx::PxPvdTransport * transport
Definition physxstate.h:30
void Shutdown()
Definition physxstate.cc:58
physx::PxRigidActor * CreateActor(ActorType type, Math::mat4 const &transform)
create new empty actor
Definition physxstate.cc:202
void Setup()
Setup Px subsystems.
Definition physxstate.cc:34
physx::PxOverlapHit overlapBuffer[MAX_SHAPE_OVERLAPS]
Definition physxstate.h:46
void onAdvance(const physx::PxRigidBody *const *bodyBuffer, const physx::PxTransform *poseBuffer, const physx::PxU32 count)
Definition physxstate.h:91
void onTrigger(physx::PxTriggerPair *pairs, physx::PxU32 count)
Definition physxstate.h:88
Util::StackArray< IndexT, 8 > activeSceneIds
Definition physxstate.h:43
physx::PxFoundation * foundation
Definition physxstate.h:27
Util::Dictionary< Util::StringAtom, IndexT > materialNameTable
Definition physxstate.h:38
Util::StackArray< Physics::Scene, 8 > activeScenes
Definition physxstate.h:40
void onContact(const physx::PxContactPairHeader &pairHeader, const physx::PxContactPair *pairs, physx::PxU32 nbPairs)
Definition physxstate.cc:149
void DisconnectPVD()
disconnect from pvd again
Definition physxstate.cc:94
physx::PxPvd * pvd
Definition physxstate.h:29
PhysxState()
Definition physxstate.cc:26
void BeginSimulating(Timing::Time delta, IndexT scene)
explicit call to simulate, will process async in the background
Definition physxstate.cc:342
Physics::Allocator allocator
Definition physxstate.h:33
Physics::Material FallbackMaterial
Definition physxstate.h:35
Util::StackArray< IndexT, 8 > deadSceneIds
Definition physxstate.h:44
Physics::ErrorCallback errorCallback
Definition physxstate.h:34
Util::Delegate< void(ActorId *, SizeT)> onWakeCallback
Definition physxstate.h:32
void ConnectPVD()
connect to an instance of pvd
Definition physxstate.cc:78
void onConstraintBreak(physx::PxConstraintInfo *constraints, physx::PxU32 count)
these are implementations of PxSimulationEventCallback
Definition physxstate.h:80
void EndSimulating(IndexT scene)
explicit call to fetch the results of the simulation
Definition physxstate.cc:371
void Update(Timing::Time delta)
convenience function to do a sync full simulation step. Do not mix Update and Begin/EndFrame!
Definition physxstate.cc:305
void onSleep(physx::PxActor **actors, physx::PxU32 count)
Definition physxstate.cc:130
physx::PxPhysics * physics
Definition physxstate.h:28
void onWake(physx::PxActor **actors, physx::PxU32 count)
Definition physxstate.cc:111
void FlushSimulation(IndexT scene)
will block until a potential simulation step is done
Definition physxstate.cc:409
Util::StackArray< Physics::Material, 16 > materials
Definition physxstate.h:41
Util::Delegate< void(ActorId *, SizeT)> onSleepCallback
Definition physxstate.h:31
void DiscardActor(ActorId id)
deregister an actor
Definition physxstate.cc:245
Nebula's dynamic array class.
Definition array.h:60
Nebula delegate class, allows to store a function, method or lambda call into a C++ object for later ...
Definition delegate.h:39
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A collection of unique values with quick lookup.
Definition set.h:34
Diverse functions for manipulating physics actors.
Definition actorcontext.cc:18
ActorType
Definition physicsinterface.h:35
PhysxState state
Definition physxstate.cc:420
double Time
the time datatype
Definition time.h:18
#define MAX_SHAPE_OVERLAPS
Private PhysX state object.
Definition physxstate.h:16
A 4x4 single point precision float matrix.
Definition mat4.h:49
A quaternion is usually used to represent an orientation in 3D space.
Definition quat.h:30
A 3D vector.
Definition vec3.h:40
Definition physicsinterface.h:50
Definition physicsinterface.h:42
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48