Adding an iterator

This commit is contained in:
Zoe Roux
2021-06-04 18:59:42 +02:00
parent eac5c2c847
commit a40b61845a
12 changed files with 220 additions and 98 deletions
+5 -8
View File
@@ -26,25 +26,22 @@ namespace WAL
void Scene::_componentAdded(Entity &entity, const std::type_index &type)
{
for (auto &view : this->_views) {
if (std::find(view->types.begin(), view->types.end(), type) == view->types.end())
if (std::find(view->getTypes().begin(), view->getTypes().end(), type) == view->getTypes().end())
continue;
bool valid = std::all_of(view->types.begin(), view->types.end(), [&entity](const auto &type){
bool valid = std::all_of(view->getTypes().begin(), view->getTypes().end(), [&entity](const auto &type){
return entity.hasComponent(type);
});
if (valid)
view->entities.emplace_back(entity);
view->emplace_back(entity);
}
}
void Scene::_componentRemoved(const Entity &entity, const std::type_index &type)
{
for (auto &view : this->_views) {
if (std::find(view->types.begin(), view->types.end(), type) == view->types.end())
if (std::find(view->getTypes().begin(), view->getTypes().end(), type) == view->getTypes().end())
continue;
view->entities.erase(std::remove_if(view->entities.begin(), view->entities.end(), [&entity](const auto &ref)
{
return &ref.get() == &entity;
}), view->entities.end());
view->erase(entity);
}
}
} // namespace WAL
+1 -1
View File
@@ -24,7 +24,7 @@ namespace WAL
//! @brief The list of registered entities
std::list<Entity> _entities = {};
//! @brief The list of cached views to update.
std::vector<std::shared_ptr<BaseView>> _views = {};
std::vector<std::shared_ptr<IView>> _views = {};
//! @brief Notify this scene that a component has been added to the given entity.
//! @param entity The entity with the new component