Add util::ecs::species() for iterating over all species
This commit is contained in:
parent
24917370ea
commit
61885dde25
1 changed files with 37 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <psemek/util/to_string.hpp>
|
||||
#include <psemek/util/type_name.hpp>
|
||||
#include <psemek/util/function.hpp>
|
||||
#include <psemek/util/range.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <typeindex>
|
||||
|
|
@ -447,6 +448,37 @@ namespace psemek::util
|
|||
void begin(species_handle, Components const & ...) {}
|
||||
};
|
||||
|
||||
struct species_iterator
|
||||
{
|
||||
species_iterator(ecs_detail::species_handle h)
|
||||
: h_(h)
|
||||
{}
|
||||
|
||||
species_handle operator*() const
|
||||
{
|
||||
return species_handle{h_};
|
||||
}
|
||||
|
||||
species_iterator & operator++()
|
||||
{
|
||||
++h_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator == (species_iterator const & it1, species_iterator const & it2)
|
||||
{
|
||||
return it1.h_ == it2.h_;
|
||||
}
|
||||
|
||||
friend bool operator != (species_iterator const & it1, species_iterator const & it2)
|
||||
{
|
||||
return !(it1 == it2);
|
||||
}
|
||||
|
||||
private:
|
||||
ecs_detail::species_handle h_;
|
||||
};
|
||||
|
||||
enum class policy
|
||||
{
|
||||
sparse,
|
||||
|
|
@ -456,7 +488,10 @@ namespace psemek::util
|
|||
template <typename ... Components>
|
||||
species_handle register_species(std::string name, policy p, Components && ... components);
|
||||
|
||||
ecs_detail::species_handle species_count() const { return species_.size(); }
|
||||
util::range<species_iterator> species() const
|
||||
{
|
||||
return {species_iterator{0}, species_iterator{species_.size()}};
|
||||
}
|
||||
|
||||
std::string_view species_name(species_handle species) const { return species_[species.value]->name(); }
|
||||
|
||||
|
|
@ -518,7 +553,7 @@ namespace psemek::util
|
|||
template <typename ... Components>
|
||||
ecs::species_handle ecs::register_species(std::string name, policy p, Components && ... components)
|
||||
{
|
||||
auto result = species_count();
|
||||
auto result = species_.size();
|
||||
if (p == policy::sparse)
|
||||
species_.push_back(std::make_unique<ecs_detail::sparse_species_impl<Components...>>(std::move(name), result, std::move(components)...));
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue