20#include <unordered_map>
38 template<
typename C,
typename... Args>
142 return static_cast<R *
>(
ret.get());
161 template <
typename C,
typename...
Args>
169 auto component = std::make_shared<C>(
C(std::forward<Args>(
args)...));
294 template<
typename...
S>
309 template <
typename Tuple, std::size_t...
Is>
310 static void for_each_impl(
Tuple &&
tuple, std::index_sequence<Is...>)
312 (..., process(std::get<Is>(std::forward<Tuple>(
tuple))));
314 template <
typename Tuple>
static void for_each(
Tuple &&
tuple)
316 for_each_impl(std::forward<Tuple>(
tuple),
317 std::make_index_sequence<
318 std::tuple_size_v<std::remove_reference_t<Tuple>>>{});
320 template <
typename...
T>
321 static std::vector<EntityId> query_components_tuple(std::tuple<T...>)
323 return query_components<
T...>();
325 template <
typename System>
static void process(
const System &
system)
328 std::vector<EntityId>
matches =
329 query_components_tuple(Dependencies{});
333 template <
typename C,
typename...
Components,
typename N = None>
334 static std::vector<EntityId> query_components()
336 if (!World::components)
364 static void query_components_rec(std::vector<EntityId> *entities)
366 if (entities->empty())
376 if (std::find(entities->begin(), entities->end(),
392template<
typename C,
typename...
Args>
394 World::add_component<C>(this->
id(), std::forward<Args>(
args)...);
401 return World::entity_to_component<C>(this->
id());
Entity & add_component(Args &&... args)
std::tuple< T... > Dependencies
static void init()
Initialize the world.
static UMapVec< TypeId, Component > * get_components()
Get the components container.
static void tick()
Tick the world.
static std::function< void()> run_systems
Run all systems.
static Entity new_entity()
Create a new entity.
static void register_systems()
static void add_component(EntityId e, Args &&... args)
Add a component to an entity.
static void remove_entity(EntityId e)
Remove an entity.
static void destroy()
Delete the world.
static void add_resource(R resource)
Add a resource to the world.
static R * get_resource()
Get a pointer to a resource.
static C * entity_to_component(EntityId e)
Get the component of an entity.
static UMap< TypeId, Resource > * get_resources()
Get the resources container.
static void remove_resource()
Remove a resource.
static std::set< EntityId > * get_entities()
Get the entities container.
std::unique_ptr< UMap< T, G > > UMapPtr
std::unordered_map< T, SPtr< G > > UMap
std::unique_ptr< std::set< T > > SetPtr
std::unordered_map< T, std::vector< SPtr< G > > > UMapVec
std::unique_ptr< UMapVec< T, G > > UMapVecPtr