R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Registry.cpp
Go to the documentation of this file.
1#include "Registry.hpp"
2
4{
5 dispatcher = _dispatcher;
6 queue = _queue;
7 setup_systems(*this);
8 setup_components(*this);
9}
10
12{
13 for (auto& system : _systems) {
14 system();
15 }
16}
17
18std::vector<GameMessage> Registry::sync_game()
19{
20 return syncGameState(*this);
21}
22
24{
25 std::size_t entity_id = _next_entity_id++;
26 _entities.push_back(entity_id);
27 return Entity(entity_id);
28}
29
30Entity Registry::entity_from_index(std::size_t idx) const
31{
32 return Entity(idx);
33}
34
35void Registry::kill_entity(const Entity &entity)
36{
37 auto end = std::remove(_entities.begin(), _entities.end(), entity);
38
39 for (auto& [type, container] : _components) {
40 _erase_functions[type](entity);
41 }
42}
std::vector< GameMessage > syncGameState(Registry &r)
Creates the.
Represents an entity in an Entity-Component-System (ECS) architecture.
Definition Entity.hpp:12
A utility class for dispatching and handling game events.
A thread-safe queue for storing and managing GameMessage objects.
Definition Queue.hpp:17
Entity entity_from_index(std::size_t idx) const
Retrieves an entity by its index.
Definition Registry.cpp:30
void run_systems()
Executes all registered systems.
Definition Registry.cpp:11
void kill_entity(const Entity &entity)
Deletes an entity and removes all its components.
Definition Registry.cpp:35
Entity spawn_entity()
Creates a new entity.
Definition Registry.cpp:23
EventDispatcher * dispatcher
Definition Registry.hpp:191
std::vector< GameMessage > sync_game()
Creates a list of GameMessages that syncs the player to the game.
Definition Registry.cpp:18
Registry(EventDispatcher *_dispatcher, Queue *_queue)
Default constructor.
Definition Registry.cpp:3
Queue * queue
Definition Registry.hpp:192
void setup_systems(Registry &r)
Sets up all the necessary systems for the game.
Definition Systems.cpp:13
void setup_components(Registry &r)
Registers components in the given registry.
Definition Systems.cpp:26