Support creating entities with prescribes values of some components

This commit is contained in:
Nikita Lisitsa 2022-10-28 23:44:00 +03:00
parent 20401bee45
commit ca85b7ee18

View file

@ -550,7 +550,8 @@ namespace psemek::util
static species_handle entity_species(entity_handle entity) { return {ecs_detail::unpack(entity.value).species}; }
entity_handle add_entity(species_handle species);
template <typename ... Components>
entity_handle add_entity(species_handle species, typename Components::data ... components);
ecs_detail::entity_id entity_count(species_handle species) const;
void remove_entity(entity_handle entity);
bool entity_active(entity_handle entity);
@ -635,9 +636,11 @@ namespace psemek::util
return {result};
}
inline ecs::entity_handle ecs::add_entity(species_handle species)
template <typename ... Components>
inline ecs::entity_handle ecs::add_entity(species_handle species, typename Components::data ... components)
{
entity_handle entity{species_[species.value]->add_entity()};
((get<Components>(entity) = std::move(components)), ...);
for (auto const & ctor : constructors_)
ctor(entity);
for (auto const & ctor : species_constructors_[species.value])