Cogs.Core
RigidBodySystem.h
1#pragma once
2#ifdef _WIN32
3#pragma warning(push)
4#pragma warning(disable: 4127) // conditional expression is constant
5#pragma warning(disable: 5033) // 'register' is no longer a supported storage class
6#endif
7#include <btBulletDynamicsCommon.h>
8#ifdef _WIN32
9#pragma warning(pop)
10#endif
11
12#include "EntityDefinition.h"
13#include "Systems/ComponentSystem.h"
14
15#include "RigidBodyComponent.h"
16
17#include "Services/TaskManager.h"
18
19namespace Cogs
20{
21 namespace Core
22 {
23 class PhysicsManager;
24
26 {
27 WeakEntityPtr entity;
28 bool contact = false;
29 bool trigger = false;
30 };
31
33 {
34 std::unique_ptr<btRigidBody> rigidBody;
35 btCollisionShape * collisionShape;
36 std::unique_ptr<btMotionState> motionState;
37 std::unique_ptr<SharedRigidBodyData> shared;
38 glm::vec3 scale;
39 glm::vec3 lastPosition;
40 bool kinematic;
41 };
42
43 class RigidBodySystem : public ComponentSystemWithDataPool<RigidBodyComponent, RigidBodyData>
44 {
46 public:
47 RigidBodySystem(Memory::Allocator * allocator, Cogs::SizeType capacity) : ComponentSystemWithDataPool(allocator, capacity) {}
48
49 void preUpdate(Context * context) final;
50 void update(Context * context) final;
51 void postUpdate(Context * context) final;
52
53 void destroyComponent(ComponentHandle component) final;
54 };
55
56 void updateMassProperties(RigidBodyData & data, float mass, const glm::vec3 & scale);
57 }
58}
Context * context
Pointer to the Context instance the system lives in.
void postUpdate()
Perform post update logic in the system.
void update()
Updates the system state to that of the current frame.
void preUpdate()
Run the pre-update method of the system.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
void destroyComponent(ComponentHandle component) final
Base allocator implementation.
Definition: Allocator.h:30
std::weak_ptr< ComponentModel::Entity > WeakEntityPtr
Weak Smart pointer for Entity access.
Definition: EntityPtr.h:18
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67