ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Bond.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <vector> // to store the SparseSets
11#include <cstddef> // for size_t
12
13#include "Imago/ECS/Entity.hpp"
15
16namespace Imago::ECS
17{
18
29 class Bond {
30 private:
31
32 std::vector<SparseSetBase*> _ownedPools;
33 size_t _bondSize = 0;
34
35 // Nexus is the only object that can construct and own a Bond, so constructor is private and Nexus is friend
36 friend class Nexus;
37
42 explicit Bond(std::vector<SparseSetBase*> pools);
43
50 bool matches_all(Entity e) const;
51
57 void move_entity(Entity e, size_t pos);
58
64 void on_component_bound(Entity e);
65
73 void on_component_unbound(Entity e);
74
75 public:
76
77 // explicitly disallow copy and move behavior
78 Bond(const Bond&) = delete;
79 Bond& operator=(const Bond&) = delete;
80 Bond(Bond&&) = delete;
81 Bond& operator=(Bond&&) = delete;
82
86 size_t get_bond_size() const;
87
91 const std::vector<Entity>& get_entities() const;
92
96 size_t get_pool_count() const;
97 };
98}
Defines the Entity alias and the free functions used to pack and unpack it.
uint32_t Entity
A packed identifier: 20 bits of index, 12 bits of generation.
Definition Entity.hpp:20
Declares the SparseSetBase interface.
size_t get_pool_count() const
Returns the number of component pools in the bond.
Definition Bond.cpp:85
const std::vector< Entity > & get_entities() const
Returns the entity array of the first owned pool.
Definition Bond.cpp:81
size_t get_bond_size() const
Returns the number of Entities that are in the bond (have every component).
Definition Bond.cpp:77