Go to the documentation of this file.
18 template<
typename ...Components>
22 std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...> &
_value;
24 explicit ViewEntity(std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...> &value)
30 return &(std::get<0>(this->
_value).get());
35 return std::get<0>(this->
_value);
40 return std::get<0>(this->
_value);
46 return std::get<std::reference_wrapper<T>>(this->
_value);
49 template<std::
size_t I>
52 return std::get<I>(this->
_value);
56 template<
typename It,
typename ...Components>
73 this->
_entity.emplace(*this->_it);
101 return this->_it == other.
_it;
120 virtual const std::vector<std::type_index> &
getTypes()
const = 0;
127 virtual ~IView() =
default;
132 template<
typename ...Components>
136 using entity_type = std::tuple<std::reference_wrapper<Entity>, std::reference_wrapper<Components>...>;
141 std::vector<std::type_index>
_types = {};
147 return iterator(this->_entities.begin());
152 return iterator(this->_entities.end());
157 return this->_entities.size();
162 return *
iterator(this->_entities.begin());
167 return *
iterator(--this->_entities.end());
170 const std::vector<std::type_index> &
getTypes()
const override
177 auto tuple = std::make_tuple<Components *...>(entity.
tryGetComponent<Components>()...);
178 if (std::apply([](
const auto *...component) {
return ((component ==
nullptr) || ...);}, tuple))
180 std::apply([&](
auto *...component) {
181 this->_entities.emplace_back(entity, *component...);
187 this->_entities.erase(std::remove_if(this->_entities.begin(), this->_entities.end(), [&entity](
const auto &ref) {
188 return std::get<0>(ref).get().getUid() == entity.getUid();
189 }), this->_entities.end());
194 explicit View(std::list<Entity> &scene)
196 this->_types = {
typeid(Components)...};
197 for (
auto &entity : scene)
204 ~View()
override =
default;
212 template<
typename ...Components>
214 :
public std::integral_constant<std::size_t, 1 + sizeof...(Components)>
217 template<
typename ...Components>
223 template<std::size_t N,
typename ...Components>
226 using type =
typename std::tuple_element<N - 1, std::tuple<Components...>>
::type;
T * tryGetComponent()
Get a component of a specific type or null if not found.
Definition: Entity.hpp:86
void emplace_back(Entity &entity) override
Definition: View.hpp:175
It _it
Definition: View.hpp:60
View(std::list< Entity > &scene)
Construct a view from a list of entities. Those entities are never copied but references to them are ...
Definition: View.hpp:194
typename std::tuple_element< N - 1, std::tuple< Components... > >::type type
Definition: View.hpp:226
Definition: Component.cpp:7
ViewEntity< Components... > front()
Definition: View.hpp:160
auto & get()
Definition: View.hpp:50
std::vector< std::type_index > _types
The list of types that every entity of the view has.
Definition: View.hpp:141
Entity & operator*()
Definition: View.hpp:33
const std::vector< std::type_index > & getTypes() const override
The list of types that every entity of the view has.
Definition: View.hpp:170
Entity * operator->()
Definition: View.hpp:28
virtual ~IView()=default
A default destructor.
An entity of the WAL's ECS.
Definition: Entity.hpp:20
std::optional< ViewEntity< Components... > > _entity
Definition: View.hpp:61
virtual void emplace_back(Entity &)=0
std::forward_iterator_tag iterator_category
Definition: View.hpp:64
std::tuple< std::reference_wrapper< Entity >, std::reference_wrapper< Components >... > & _value
Definition: View.hpp:22
pointer operator->()
Definition: View.hpp:77
ViewIterator< typename std::vector< entity_type >::iterator, Components... > iterator
Definition: View.hpp:143
iterator end()
Definition: View.hpp:150
virtual const std::vector< std::type_index > & getTypes() const =0
The list of types that every entity of the view has.
ViewIterator & operator++()
Definition: View.hpp:84
View & operator=(const View &)=delete
A view is not assignable.
std::tuple< std::reference_wrapper< Entity >, std::reference_wrapper< Components >... > entity_type
Definition: View.hpp:136
bool operator==(const ViewIterator &other) const
Definition: View.hpp:99
A view allowing one to easily access entities containing a set list of component. A view is always up...
Definition: View.hpp:133
std::ptrdiff_t difference_type
Definition: View.hpp:65
std::size_t size() const
Definition: View.hpp:155
ViewIterator operator++(int)
Definition: View.hpp:91
ViewEntity< Components... > back()
Definition: View.hpp:165
~View() override=default
A default destructor.
virtual void erase(const Entity &)=0
bool operator!=(const ViewIterator &other) const
Definition: View.hpp:104
std::vector< entity_type > _entities
The list of entities in the view.
Definition: View.hpp:139
iterator begin()
Definition: View.hpp:145
ViewIterator(It current)
Definition: View.hpp:109
ViewEntity(std::tuple< std::reference_wrapper< Entity >, std::reference_wrapper< Components >... > &value)
Definition: View.hpp:24
void erase(const Entity &entity) override
Definition: View.hpp:185
reference operator*()
Definition: View.hpp:70
T & get()
Definition: View.hpp:44
A basic view used to manipulate view without knowing their type at compile time.
Definition: View.hpp:116