mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-05 10:59:48 +00:00
Reworking the view
This commit is contained in:
@@ -10,8 +10,24 @@ namespace WAL
|
||||
{
|
||||
return this->_entities;
|
||||
}
|
||||
|
||||
Scene &Scene::operator=(const Scene &)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
Entity &Scene::addEntity(const std::string &name)
|
||||
{
|
||||
return this->_entities.emplace_back(*this, name);
|
||||
}
|
||||
|
||||
void Scene::_componentAdded(const Entity &entity, std::type_index type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Scene::_componentRemoved(const Entity &entity, std::type_index type)
|
||||
{
|
||||
|
||||
}
|
||||
} // namespace WAL
|
||||
@@ -3,11 +3,11 @@
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef WAL_SCENE
|
||||
#define WAL_SCENE
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "View/View.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace WAL
|
||||
@@ -18,20 +18,44 @@ namespace WAL
|
||||
private:
|
||||
//! @brief The list of registered entities
|
||||
std::vector<Entity> _entities = {};
|
||||
//! @brief A list of cached views.
|
||||
// std::vector<View> _views = {};
|
||||
|
||||
//! @brief Notify this scene that a component has been added to the given entity.
|
||||
//! @param entity The entity with the new component
|
||||
//! @param type The type of the component added.
|
||||
void _componentAdded(const Entity &entity, std::type_index type);
|
||||
//! @brief Notify this scene that a component has been removed to the given entity.
|
||||
//! @param entity The entity with the removed component
|
||||
//! @param type The type of the component removed.
|
||||
void _componentRemoved(const Entity &entity, std::type_index type);
|
||||
public:
|
||||
//! @brief Get the list of entities.
|
||||
std::vector<Entity> &getEntities();
|
||||
|
||||
//! @brief Add a new entity to the scene, you can use this method with the same arguments as the entity's constructor.
|
||||
//! @return The current scene is returned to allow you to chain call.
|
||||
template <class ...Params>
|
||||
Entity &addEntity(Params &&...params)
|
||||
//! @brief Add a new entity to the scene.
|
||||
//! @param name The name of the created entity.
|
||||
//! @return The created entity is returned.
|
||||
Entity &addEntity(const std::string &name);
|
||||
|
||||
template<typename ...Components>
|
||||
std::vector<std::reference_wrapper<Entity>> &view()
|
||||
{
|
||||
return this->_entities.emplace_back(std::forward<Params>(params)...);
|
||||
return this->view(typeid(Components)...);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "NotImplementedFunctions"
|
||||
template<typename ...Components>
|
||||
std::vector<std::reference_wrapper<Entity>> &view(const Components &...index) requires(std::is_same_v<Components...>)
|
||||
{
|
||||
static std::vector<std::reference_wrapper<Entity>> view;
|
||||
|
||||
std::copy_if(this->_entities.begin(), this->_entities.end(), std::back_inserter(view), [&index...](Entity &entity) {
|
||||
return (entity.hasComponent(index) && ...);
|
||||
});
|
||||
return view;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
//! @brief A default constructor
|
||||
Scene() = default;
|
||||
//! @brief A scene is copy constructable
|
||||
@@ -41,5 +65,11 @@ namespace WAL
|
||||
//! @brief A scene is assignable
|
||||
Scene &operator=(const Scene &);
|
||||
Scene(Scene &&) = default;
|
||||
|
||||
friend Entity;
|
||||
};
|
||||
} // namespace WAL
|
||||
} // namespace WAL
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user