Cogs.Core
ConstraintSystem.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
13#include "Systems/ComponentSystem.h"
14#include "ConstraintComponent.h"
15
16namespace Cogs
17{
18 namespace Core
19 {
20 class PhysicsManager;
21
23 {
24 template<typename T, typename... Args>
25 T * createConstraint(Args && ... args)
26 {
27 constraint = std::make_unique<T>(std::forward<Args>(args)...);
28
29 return static_cast<T *>(constraint.get());
30 }
31
32 std::unique_ptr<btTypedConstraint> constraint;
33
34 glm::mat4 transform;
35 glm::mat4 targetTransform;
36
37 btRigidBody * rigidBody = nullptr;
38 btRigidBody * targetRigidBody = nullptr;
39 };
40
41 template<typename T>
42 class ConstraintSystem : public ComponentSystemWithDataPool<T, ConstraintData>
43 {
44 public:
46 };
47
48 class FixedConstraintSystem : public ConstraintSystem<FixedConstraintComponent>
49 {
50 public:
51 FixedConstraintSystem(Memory::Allocator * allocator, Cogs::SizeType capacity) : ConstraintSystem(allocator, capacity) {}
52
53 void update(Context * context) final;
54
55 void destroyComponent(ComponentHandle component) final;
56 };
57
58 class HingeConstraintSystem : public ConstraintSystem<HingeConstraintComponent>
59 {
60 public:
61 HingeConstraintSystem(Memory::Allocator * allocator, Cogs::SizeType capacity) : ConstraintSystem(allocator, capacity) {}
62
63 void update(Context * context) final;
64
65 void destroyComponent(ComponentHandle component) final;
66 };
67
68 class SpringConstraintSystem : public ConstraintSystem<SpringConstraintComponent>
69 {
70 public:
71 SpringConstraintSystem(Memory::Allocator * allocator, Cogs::SizeType capacity) : ConstraintSystem(allocator, capacity) {}
72
73 void update(Context * context) final;
74
75 void destroyComponent(ComponentHandle component) final;
76 };
77
78 class GenericConstraintSystem : public ConstraintSystem<GenericConstraintComponent>
79 {
80 public:
81 GenericConstraintSystem(Memory::Allocator * allocator, Cogs::SizeType capacity) : ConstraintSystem(allocator, capacity) {}
82
83 void update(Context * context) final;
84
85 void destroyComponent(ComponentHandle component) final;
86 };
87 }
88}
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
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
Destroy the component held by the given handle.
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
void destroyComponent(ComponentHandle component) final
Destroy the component held by the given handle.
Base allocator implementation.
Definition: Allocator.h:30
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