11#ifndef REGISTRY_IMPL_HPP
12#define REGISTRY_IMPL_HPP
23 template <
class Component>
25 componentsArrays[std::type_index(
typeid(
Component))] = std::make_any<SparseArray<Component>>();
27 return std::any_cast<SparseArray<Component> &>(componentsArrays[std::type_index(
typeid(
Component))]);
30 template <
class ... Components>
35 template <IsTuple Tuple>
42 template <
class Component>
44 return std::any_cast<SparseArray<Component> &>(componentsArrays[std::type_index(
typeid(
Component))]);
47 template <
class Component>
49 return std::any_cast<SparseArray<Component> &>(componentsArrays.at(std::type_index(
typeid(
Component))));
52 template <
typename...
Component,
typename>
57 template <
typename Component,
typename ... Params>
63 template <
typename ...
Component,
typename>
70 template<SystemImplementation System>
72 systems[std::type_index(
typeid(
System))] = std::shared_ptr<ISystem>(&
s, +[](
ISystem*){});
75 template<SystemImplementation System>
77 systems[std::type_index(
typeid(
System))] = std::make_shared<System>(std::move(
s));
87 systems[std::type_index(
typeid(
System))] = std::make_shared<System>(std::forward<Args>(
args)...);
92 (systems.erase(std::type_index(
typeid(
System))), ...);
97 (systems[std::type_index(
typeid(
System))]->update(*
this), ...);
Component is a template define in Registry. (not a class)
Abstract base class representing a system in the ECS architecture.
Entity class from ECS.
Definition Entity.hpp:29
define the Registry class
Definition Registry.hpp:47
void addComponent(Entity const &to, Component &&...c)
Definition Registry_impl.hpp:53
void emplaceSystem(Params &&... params)
add a system to the registry
void callSystem()
call a system
Definition Registry_impl.hpp:96
void removeSystem()
remove a system from the registry
Definition Registry_impl.hpp:91
void registerComponents()
register a list of components
Definition Registry_impl.hpp:31
SparseArray< Component > & registerComponent()
handling components (define in Registry_impl.hpp)
Definition Registry_impl.hpp:24
SparseArray< Component > & getComponents()
get components of a given type
Definition Registry_impl.hpp:43
void addSystem(System &s)
handling systems
Definition Registry_impl.hpp:71
void registerComponentsByExtraction()
register every components by extraction from a tuple
Definition Registry_impl.hpp:36
void emplaceComponent(Entity const &to, Params &&... p)
emplace a component to the given entity
Definition Registry_impl.hpp:58
void removeComponent(Entity const &from)
remove a component from the given entity
Definition Registry_impl.hpp:64
SparseArray class.
Definition SparseArray.hpp:48
Concept that ensures a type derives from System.
Definition System.hpp:58