-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentManager.h
More file actions
85 lines (66 loc) · 2.28 KB
/
ComponentManager.h
File metadata and controls
85 lines (66 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef COMPONENTMANAGER_H
#define COMPONENTMANAGER_H
#include "Component.h"
#include "ComponentList.h"
#include <unordered_map>
#include <vector>
#include <iostream>
using namespace std;
// For convenience
//typedef unordered_map<ComponentType, ComponentList*> typeToListMap;
typedef unordered_map<ComponentType, ComponentList*> typeToListMap;
class ComponentManager
{
private:
// GameObject, which maps objectIDs to collections of
// components working together which comprise one coherent object
ComponentList gameObjects;
// Mapping from component type to the list of the components
typeToListMap componentLists;
public:
ComponentManager();
~ComponentManager();
// There should be a destructor for calling the destructors of every single component.
// GameObject, which contains a list of components, can be
// easily modelled with the Component class
class GameObject : public Component
{
// I can make this dynamic, but right now just give it a max
// capacity of components
public:
static const int SIZE_LIMIT = 8;
Component* components[SIZE_LIMIT];
int dependencyCount = 0;
GameObject() : Component(ComponentType::GAMEOBJECT)
{
// Set empty values to NULL
for (int i = 0; i < SIZE_LIMIT; i++) components[i] = NULL;
}
~GameObject() {}
// If the dependencyCount is greater than 0, count it as alive
ComponentState getState()
{
if (dependencyCount > 0) return ComponentState::ALIVE;
else return Component::getState();
}
// These are dummies to satisfy the interface
void update(float dt) { }
void applyBuffer() { }
};
// GameObject related things
int newGameObject();
int newGameObject(vector<Component*> components);
GameObject* getGameObject(int objID);
// This is ugly and I'm considering making the game object manager
// part of a separate class
void gameObjAddComponent(int objID, Component* c);
bool gameObjHasComponentOfType(int objID, ComponentType type);
Component* gameObjGetComponentOfType(int objID, ComponentType type);
int gameObjDependencyCount(int objID);
void gameObjRegisterDependency(int objID);
void gameObjRemoveDependency(int objID);
// ComponentLists
int addComponent (Component* myComponent, ComponentType type);
ComponentList* getComponents(ComponentType type);
};
#endif