Saga
Saga Game Engine
Loading...
Searching...
No Matches
componentGroup.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <unordered_map>
5#include <memory>
6#include "../Entity/entity.h"
7#include "gameworld.h"
9
10namespace Saga {
11
16public:
20 virtual ~IComponentGroup() = default;
27 virtual void addEntity(std::shared_ptr<GameWorld> world, const Entity& entity) = 0;
28
34 virtual void removeEntity(Entity entity) = 0;
35};
36
44template <typename... Component>
46public:
50 virtual ~ComponentGroup() {}
51
58 virtual void addEntity(std::shared_ptr<GameWorld> world, const Entity& entity) override;
59
65 virtual void removeEntity(Entity entity) override;
66
67 typename std::vector<std::tuple<Entity, ComponentReference<Component>...>>::iterator begin();
68 typename std::vector<std::tuple<Entity, ComponentReference<Component>...>>::iterator end();
69 typename std::vector<std::tuple<Entity, ComponentReference<Component>...>>::const_iterator begin() const;
70 typename std::vector<std::tuple<Entity, ComponentReference<Component>...>>::const_iterator end() const;
71private:
72 std::vector<std::tuple<Entity, ComponentReference<Component>...>> allData;
73 std::unordered_map<Entity, size_t> entityToIndex;
74
82 std::tuple<Entity, ComponentReference<Component>...> createTuple(std::shared_ptr<GameWorld> world, const Entity& entity);
83};
84
85} // namespace Saga
86
87#include "componentGroup.inl"
Effectively a list of tuples each entry containing an Entity and ComponentReference to each of the co...
Definition: componentGroup.h:45
virtual ~ComponentGroup()
Destroy the Component Group object.
Definition: componentGroup.h:50
std::vector< std::tuple< Entity, ComponentReference< Component >... > >::iterator end()
Definition: componentGroup.inl:47
virtual void removeEntity(Entity entity) override
Remove an entity from the ComponentGroup.
Definition: componentGroup.inl:22
std::vector< std::tuple< Entity, ComponentReference< Component >... > >::iterator begin()
Definition: componentGroup.inl:44
virtual void addEntity(std::shared_ptr< GameWorld > world, const Entity &entity) override
Add an Entity to the Group. This entity must contain all the required components. If such an entity a...
Definition: componentGroup.inl:11
Generic group of components.
Definition: componentGroup.h:15
virtual ~IComponentGroup()=default
Destroy the IComponentGroup object.
virtual void removeEntity(Entity entity)=0
Handle removing an entity from a group.
virtual void addEntity(std::shared_ptr< GameWorld > world, const Entity &entity)=0
Handle adding an entity to a group. This entity must have all the components specified by the group.
Definition: app.cpp:8