Nebula
Loading...
Searching...
No Matches
physicsmanager.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
10#include "core/refcounted.h"
11#include "core/singleton.h"
12#include "game/manager.h"
13#include "game/category.h"
14#include "game/component.h"
15#include "game/entity.h"
16#include "game/world.h"
17#include "basegamefeature/components/basegamefeature.h"
19#include "physicsinterface.h"
22#include "components/physicsfeature.h"
23#include "game/api.h"
24
25namespace PhysicsFeature
26{
27
40
42{
45public:
47 virtual ~PhysicsManager();
48
49 void OnActivate() override;
50 void OnDeactivate() override;
51 void OnDecay() override;
52 void OnCleanup(Game::World* world) override;
53
54 // initializes the PhysicsActor component, which is the handle that owns the physx actor of an entity and the shape if any
55 static void InitPhysicsActor(Game::World*, Game::Entity, PhysicsFeature::PhysicsActor*);
56
57
58 static void InitPhysicsResource(Game::World*, Game::Entity, PhysicsFeature::PhysicsResource*);
59 static void InitRigidbody(Game::World*, Game::Entity, PhysicsFeature::Rigidbody*);
60 static void InitStaticBody(Game::World*, Game::Entity, PhysicsFeature::StaticBody*);
61 static void InitBoxCollider(Game::World*, Game::Entity, PhysicsFeature::BoxCollider*);
62 static void InitSphereCollider(Game::World*, Game::Entity, PhysicsFeature::SphereCollider*);
63 static void InitCapsuleCollider(Game::World*, Game::Entity, PhysicsFeature::CapsuleCollider*);
64 static void InitPlaneCollider(Game::World*, Game::Entity, PhysicsFeature::PlaneCollider*);
65 static void InitMeshCollider(Game::World*, Game::Entity, PhysicsFeature::MeshCollider*);
66 static void InitHeightFieldCollider(Game::World*, Game::Entity, PhysicsFeature::HeightFieldCollider*);
67
70 static void Mark(Game::World*, Game::Entity, uint32_t pending);
71
77
82
86
91
95
98
101
103
105
107 template <typename COMPONENT_TYPE>
108 static void OnColliderComponentDecay(Game::World*, Game::Entity, COMPONENT_TYPE*);
109
111 template <typename COMPONENT_TYPE>
112 static void OnBodyComponentDecay(Game::World*, Game::Entity, COMPONENT_TYPE*);
113
114private:
118
119 // rebuilds everything which was queued since the last frame. An entity stays queued while the
120 // actor of the body its shape hangs off is not built yet. Geometry which cannot be loaded is a
121 // warned failure, nothing polls for the resource, whoever streams it pings when it is ready
122 void RebuildQueued();
123
125};
126
127//------------------------------------------------------------------------------
131template <typename COMPONENT_TYPE>
132inline void
137
138//------------------------------------------------------------------------------
143template <typename COMPONENT_TYPE>
144inline void
149
150} // namespace PhysicsFeature
The main programming interface for the Game Subsystem.
__DeclareClass(RefCounted)
Managers are objects which care about some specific functionality of a feature.
Definition manager.h:32
A container of entities, their components, and processors.
Definition world.h:92
Basically a bitfield with packed ComponentIds.
Definition tablesignature.h:26
Definition physicsmanager.h:42
void OnDecay() override
An entity whose handle goes away takes its physx actor with it.
Definition physicsmanager.cc:1138
static Physics::ShapeId GetShapeForEntity(Game::World *, Game::Entity)
Definition physicsmanager.cc:375
static void InitSphereCollider(Game::World *, Game::Entity, PhysicsFeature::SphereCollider *)
Definition physicsmanager.cc:1085
void OnDeactivate() override
called when removed from game server
Definition physicsmanager.cc:1296
static void InitRigidbody(Game::World *, Game::Entity, PhysicsFeature::Rigidbody *)
Definition physicsmanager.cc:1057
static void InitCapsuleCollider(Game::World *, Game::Entity, PhysicsFeature::CapsuleCollider *)
Definition physicsmanager.cc:1095
static void InitHeightFieldCollider(Game::World *, Game::Entity, PhysicsFeature::HeightFieldCollider *)
Definition physicsmanager.cc:1125
static void MarkBodyChanged(Game::World *, Game::Entity)
the body component of the entity changed: actor type, mass, damping, gravity, ccd,...
Definition physicsmanager.cc:148
static void InitPhysicsResource(Game::World *, Game::Entity, PhysicsFeature::PhysicsResource *)
Definition physicsmanager.cc:1048
static void MarkComponentChange(Game::World *, Game::Entity, Game::ComponentId)
the value of a component was written on an entity which already has a handle.
Definition physicsmanager.cc:166
static void InitPhysicsActor(Game::World *, Game::Entity, PhysicsFeature::PhysicsActor *)
Definition physicsmanager.cc:1019
static void InitMeshCollider(Game::World *, Game::Entity, PhysicsFeature::MeshCollider *)
Definition physicsmanager.cc:1115
static void MarkPoseChanged(Game::World *, Game::Entity)
the entity moved.
Definition physicsmanager.cc:157
void InitPhysicsFrameEvent()
builds the processors and callbacks of the physics frame event.
Definition physicsmanager.cc:1245
static void MarkShapeChanged(Game::World *, Game::Entity)
the collider components of the entity were changed, or added to an entity which already had a handle.
Definition physicsmanager.cc:136
static bool HasCollider(Game::World *, Game::Entity)
true when the entity has any of the collider components
Definition physicsmanager.cc:335
static void OnBodyComponentDecay(Game::World *, Game::Entity, COMPONENT_TYPE *)
decay callback of the body components, which releases the physx actor of the entity
Definition physicsmanager.h:145
static void Mark(Game::World *, Game::Entity, uint32_t pending)
queues up work for an entity, see PhysicsPending.
Definition physicsmanager.cc:109
Util::Array< Game::Entity > rebuildQueue
Definition physicsmanager.h:124
void RebuildQueued()
Rebuilds everything which has been queued since the last frame, and nothing else.
Definition physicsmanager.cc:971
static void ReleaseShapeForEntity(Game::World *, Game::Entity)
Definition physicsmanager.cc:429
void OnActivate() override
called when added to game server
Definition physicsmanager.cc:1285
static MemDb::TableSignature const & ColliderSignature()
the collider components as a signature.
Definition physicsmanager.cc:324
static bool IsColliderComponent(Game::ComponentId)
true when the component is one of the collider components
Definition physicsmanager.cc:348
static void InitPlaneCollider(Game::World *, Game::Entity, PhysicsFeature::PlaneCollider *)
Definition physicsmanager.cc:1105
static void InitBoxCollider(Game::World *, Game::Entity, PhysicsFeature::BoxCollider *)
Definition physicsmanager.cc:1075
static void OnColliderComponentDecay(Game::World *, Game::Entity, COMPONENT_TYPE *)
decay callback of the collider components, see MarkShapeChanged
Definition physicsmanager.h:133
static void InitStaticBody(Game::World *, Game::Entity, PhysicsFeature::StaticBody *)
Definition physicsmanager.cc:1066
void OnCleanup(Game::World *world) override
called before unloading game state
Definition physicsmanager.cc:1305
Nebula's dynamic array class.
Definition array.h:61
MemDb::AttributeId ComponentId
Definition componentid.h:15
Definition charactermanager.cc:22
PhysicsPending
what the physics manager has queued for an entity, mixed together in the pending field of the Physics...
Definition physicsmanager.h:32
@ PendingStructural
the actor has to look through its shapes for owners which no longer have a component....
Definition physicsmanager.h:37
@ PendingAll
Definition physicsmanager.h:38
@ PendingBody
create or update the physx actor of the body component
Definition physicsmanager.h:36
@ PendingPose
push the pose of the actor, and the local pose of its shapes
Definition physicsmanager.h:34
@ PendingShape
build or update the shapes of the collider components
Definition physicsmanager.h:35
@ PendingNone
nothing queued for the entity
Definition physicsmanager.h:33
#define __DeclareSingleton(type)
Definition osxsingleton.h:24
An entity is essentially just an Id with some utility functions attached.
Definition entity.h:35
Definition physicsinterface.h:91