41 return static_cast<ecs_flags>(
static_cast<uint32_t
>(aLhs) | static_cast<uint32_t>(aRhs));
46 return static_cast<ecs_flags>(
static_cast<uint32_t
>(aLhs) & static_cast<uint32_t>(aRhs));
51 return aLhs =
static_cast<ecs_flags>(
static_cast<uint32_t
>(aLhs) | static_cast<uint32_t>(aRhs));
56 return aLhs =
static_cast<ecs_flags>(
static_cast<uint32_t
>(aLhs) & static_cast<uint32_t>(aRhs));
71 struct uuid_exists : std::runtime_error {
uuid_exists(
const std::string& aContext) : std::runtime_error(
"neogfx::i_ecs::uuid_exists: " + aContext) {} };
82 typedef std::map<component_id, std::unique_ptr<i_component>>
components_t;
86 typedef std::map<system_id, std::unique_ptr<i_system>>
systems_t;
93 virtual void destroy_entity(
entity_id aEntityId) = 0;
95 virtual bool all_systems_paused()
const = 0;
96 virtual void pause_all_systems() = 0;
97 virtual void resume_all_systems() = 0;
99 virtual const archetype_registry_t& archetypes()
const = 0;
100 virtual archetype_registry_t& archetypes() = 0;
101 virtual const component_factories_t& component_factories()
const = 0;
102 virtual component_factories_t& component_factories() = 0;
103 virtual const components_t& components()
const = 0;
104 virtual components_t& components() = 0;
105 virtual const shared_component_factories_t& shared_component_factories()
const = 0;
106 virtual shared_component_factories_t& shared_component_factories() = 0;
107 virtual const shared_components_t& shared_components()
const = 0;
108 virtual shared_components_t& shared_components() = 0;
109 virtual const system_factories_t& system_factories()
const = 0;
110 virtual system_factories_t& system_factories() = 0;
111 virtual const systems_t& systems()
const = 0;
112 virtual systems_t& systems() = 0;
116 virtual bool component_instantiated(
component_id aComponentId)
const = 0;
119 virtual bool shared_component_instantiated(
component_id aComponentId)
const = 0;
122 virtual bool system_instantiated(
system_id aSystemId)
const = 0;
127 virtual void free_entity_id(
entity_id aId) = 0;
131 virtual void register_archetype(std::shared_ptr<const i_entity_archetype> aArchetype) = 0;
132 virtual bool component_registered(
component_id aComponentId)
const = 0;
134 virtual bool shared_component_registered(
component_id aComponentId)
const = 0;
136 virtual bool system_registered(
system_id aSystemId)
const = 0;
139 virtual handle_t to_handle(handle_id aId)
const = 0;
140 virtual handle_id add_handle(
const std::type_info& aTypeInfo, handle_t aHandle) = 0;
141 virtual handle_t update_handle(handle_id aId,
const std::type_info& aTypeInfo, handle_t aHandle) = 0;
142 virtual handle_t release_handle(handle_id aId) = 0;
148 auto newEntity = create_entity(aArchetypeId);
149 populate(newEntity, std::forward<ComponentData>(aComponentData)...);
150 archetype(aArchetypeId).populate_default_components(*
this, newEntity);
156 if (!archetype_registered(aArchetype))
157 register_archetype(aArchetype);
158 return create_entity(aArchetype.id(), std::forward<ComponentData>(aComponentData)...);
161 template <
typename ComponentData,
typename... ComponentDataRest>
164 populate(aEntity, std::forward<ComponentData>(aComponentData));
165 populate(aEntity, std::forward<ComponentDataRest>(aComponentDataRest)...);
167 template <
typename ComponentData>
170 component<ecs_data_type_t<ComponentData>>().populate(aEntity, std::forward<ComponentData>(aComponentData));
172 template <
typename ComponentData,
typename... ComponentDataRest>
173 void populate_shared(
const std::string& aName, ComponentData&& aComponentData, ComponentDataRest&&... aComponentDataRest)
175 populate_shared(aName, std::forward<ComponentData>(aComponentData));
176 populate_shared(aName, std::forward<ComponentDataRest>(aComponentDataRest)...);
178 template <
typename ComponentData>
181 shared_component<ecs_data_type_t<ComponentData>>().populate(aName, std::forward<ComponentData>(aComponentData));
183 template <
typename ComponentData>
188 template <
typename ComponentData>
193 template <
typename ComponentData>
197 register_component<ecs_data_type_t<ComponentData>>();
200 template <
typename ComponentData>
205 template <
typename ComponentData>
210 template <
typename ComponentData>
214 register_shared_component<ecs_data_type_t<ComponentData>>();
217 template <
typename System>
222 template <
typename System>
227 template <
typename System>
231 register_system<ecs_data_type_t<System>>();
235 template <
typename ComponentData>
240 template <
typename ComponentData>
245 template <
typename ComponentData>
250 template <
typename ComponentData>
253 register_shared_component(
ecs_data_type_t<ComponentData>::meta::id(), [&]() {
return std::unique_ptr<i_shared_component>{std::make_unique<static_shared_component<ecs_data_type_t<ComponentData>>>(*this)}; });
255 template <
typename System>
260 template <
typename System>
265 [&]() {
return std::unique_ptr<i_system>{std::make_unique<ecs_data_type_t<System>>(*this)}; });
268 template <
typename Handle>
271 return reinterpret_cast<Handle
>(to_handle(aId));
273 template <
typename Context,
typename Handle>
276 return add_handle(
typeid(Context), reinterpret_cast<handle_t>(aHandle));
278 template <
typename Context,
typename Handle>
281 if constexpr(std::is_pointer<Handle>::value)
282 return reinterpret_cast<Handle
>(update_handle(aId,
typeid(Context), reinterpret_cast<handle_t>(aHandle)));
284 return static_cast<Handle
>(
reinterpret_cast<intptr_t
>(update_handle(aId,
typeid(Context), reinterpret_cast<handle_t>(aHandle))));
286 template <
typename Handle>
289 if constexpr(std::is_pointer<Handle>::value)
290 return reinterpret_cast<Handle
>(release_handle(aId));
292 return static_cast<Handle
>(
reinterpret_cast<intptr_t
>(release_handle(aId)));
296 template <
typename Data>
305 std::scoped_lock<std::recursive_mutex> iLockGuard;
308 template <
typename Data>
317 std::scoped_lock<std::recursive_mutex> iLockGuard;
component_scoped_lock(const i_ecs &aEcs)
entity_archetype_not_found()
static_shared_component< ComponentData > & shared_component()
const static_component< ComponentData > & component() const
Handle to_handle(handle_id aId) const
static_component< ComponentData > & component()
Handle update_handle(handle_id aId, Handle aHandle)
std::remove_cv_t< std::remove_reference_t< _Ty > > ecs_data_type_t
void populate(entity_id aEntity, ComponentData &&aComponentData)
std::map< component_id, component_factory > component_factories_t
bool component_instantiated() const
ecs_data_type_t< System > & system()
virtual const i_shared_component & shared_component(component_id aComponentId) const =0
void populate_shared(const std::string &aName, ComponentData &&aComponentData)
shared_component_scoped_lock(const i_ecs &aEcs)
std::map< system_id, std::unique_ptr< i_system > > systems_t
void populate_shared(const std::string &aName, ComponentData &&aComponentData, ComponentDataRest &&... aComponentDataRest)
constexpr component_data_field_type operator|(component_data_field_type aLhs, component_data_field_type aRhs)
bool system_instantiated() const
std::function< std::unique_ptr< i_system >)> system_factory
std::map< component_id, shared_component_factory > shared_component_factories_t
to_const_reference_t< T > to_const(T &&object)
std::map< entity_archetype_id, std::shared_ptr< const i_entity_archetype > > archetype_registry_t
std::function< std::unique_ptr< i_shared_component >)> shared_component_factory
void register_component()
bool shared_component_instantiated() const
virtual const i_component & component(component_id aComponentId) const =0
std::map< component_id, std::unique_ptr< i_component > > components_t
entity_id create_entity(const Archetype &aArchetype, ComponentData &&... aComponentData)
uuid_exists(const std::string &aContext)
bool shared_component_registered() const
constexpr component_data_field_type operator &(component_data_field_type aLhs, component_data_field_type aRhs)
void register_shared_component()
entity_id create_entity(const entity_archetype_id &aArchetypeId, ComponentData &&... aComponentData)
handle_id add_handle(Handle aHandle)
Handle release_handle(handle_id aId)
std::map< system_id, system_factory > system_factories_t
std::function< std::unique_ptr< i_component >)> component_factory
bool system_registered() const
bool component_registered() const
const static_shared_component< ComponentData > & shared_component() const
void populate(entity_id aEntity, ComponentData &&aComponentData, ComponentDataRest &&... aComponentDataRest)
#define declare_event(declName,...)
constexpr component_data_field_type & operator|=(component_data_field_type &aLhs, component_data_field_type aRhs)
std::map< component_id, std::unique_ptr< i_shared_component > > shared_components_t
const ecs_data_type_t< System > & system() const
constexpr component_data_field_type & operator &=(component_data_field_type &aLhs, component_data_field_type aRhs)