SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
CollisionManager.h
1#ifndef CollisionManager_H
2#define CollisionManager_H
3
4#include <vector>
5#include <list>
6
7#include "CollisionTestSelfCommand.h"
8#include "CollisionTestPairCommand.h"
9#include "CollisionTerrainCommand.h"
10#include "CollisionDispatch.h"
11#include "CollisionDispatchTerrain.h"
12
13class CollidableGroup;
15
23class CollisionManager
24{
25public:
29 using PWTypeID = int;
30
34 static const PWTypeID PWID_UNDEFINED = -1;
35
36 CollisionManager();
37 CollisionManager(const CollisionManager&) = delete;
38 CollisionManager& operator=(const CollisionManager&) = delete;
39 ~CollisionManager();
40
47
51 void ProcessElements();
52
58 template <typename C>
60 {
61 static PWTypeID myTypeID = TypeIDNextNumber++;
62
63 SetGroupForTypeID(myTypeID);
64
65 DebugMsg::out("CollisionManager: TypeID %d registered\n", myTypeID);
66 return myTypeID;
67 }
68
69 void UpdateGroupAABBs();
70 bool TestGroupCollision(CollidableGroup* g1, CollidableGroup* g2);
71 void DebugRender();
72
73private:
77 const int MAX_COLLISION_GROUP = 64;
78
83
87 using CollidableGroupCollection = std::vector<CollidableGroup*>;
88
93
99
103 using CollisionTestCommands = std::list<CollisionTestCommandBase*>;
104
109
110public:
115 template <typename C>
117 {
120 colTestCommands.push_back(new CollisionTestSelfCommand(pG, pDispatch));
121 }
122
128 template <typename C1, typename C2>
136
137 //Terrain
138 template <typename Type>
139 void SetCollisionTerrain()
140 {
143 colTestCommands.push_back(new CollisionTerrainCommand(pG, pDispatch));
144 }
145};
146
147#endif
Manages a collection of collidable objects.
Definition CollidableGroup.h:17
Handles the dispatching of collision callbacks between two collidable objects.
Definition CollisionDispatch.h:17
Handles the dispatching of collision callbacks between two collidable objects.
Definition CollisionDispatchTerrain.h:17
void SetGroupForTypeID(CollisionManager::PWTypeID ind)
Sets the group for the specified type ID.
Definition CollisionManager.cpp:27
static PWTypeID TypeIDNextNumber
The next type ID number.
Definition CollisionManager.h:82
void SetCollisionPair()
Sets the collision pair test for the specified collidable types.
Definition CollisionManager.h:129
CollidableGroup * GetColGroup(PWTypeID id)
Gets the collidable group for the specified type ID.
Definition CollisionManager.cpp:35
std::list< CollisionTestCommandBase * > CollisionTestCommands
Type alias for the collision test commands.
Definition CollisionManager.h:103
PWTypeID GetTypeID()
Gets the type ID for the specified collidable type.
Definition CollisionManager.h:59
const int MAX_COLLISION_GROUP
The maximum number of collision groups.
Definition CollisionManager.h:77
CollisionTestCommands colTestCommands
The collision test commands.
Definition CollisionManager.h:108
static const PWTypeID PWID_UNDEFINED
The undefined type ID.
Definition CollisionManager.h:34
void ProcessElements()
Processes all registered collisions.
Definition CollisionManager.cpp:40
void SetCollisionSelf()
Sets the collision self test for the specified collidable type.
Definition CollisionManager.h:116
std::vector< CollidableGroup * > CollidableGroupCollection
Type alias for the collidable group collection.
Definition CollisionManager.h:87
CollidableGroupCollection ColGroupCollection
The collidable group collection.
Definition CollisionManager.h:92
int PWTypeID
Type alias for the type ID.
Definition CollisionManager.h:29
Command to handle collision tests within a single collidable group.
Definition CollisionTerrainCommand.h:17
Base class for collision test commands.
Definition CollisionTestCommandBase.h:12
Command to handle collision tests between two collidable groups.
Definition CollisionTestPairCommand.h:17
Command to handle collision tests within a single collidable group.
Definition CollisionTestSelfCommand.h:17