From 230d0b523dfc68d458a8d9b4b4a0c506975ebd28 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 20 May 2021 16:14:30 +0200 Subject: [PATCH] Adding scene functions --- lib/wal/sources/Scene/Scene.cpp | 5 +++++ lib/wal/sources/Scene/Scene.hpp | 25 ++++++++++++++++++++++++- lib/wal/sources/Scene/SceneManager.cpp | 11 +++++------ lib/wal/sources/Scene/SceneManager.hpp | 11 +++++------ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/wal/sources/Scene/Scene.cpp b/lib/wal/sources/Scene/Scene.cpp index b0a3b3a7..2fa115f5 100644 --- a/lib/wal/sources/Scene/Scene.cpp +++ b/lib/wal/sources/Scene/Scene.cpp @@ -10,5 +10,10 @@ namespace WAL { return this->_entities; } + + void Scene::removeAll(std::function &predicate) + { + this->_entities.erase(std::remove_if(this->_entities.begin(), this->_entities.end(), predicate), this->_entities.end()); + } } diff --git a/lib/wal/sources/Scene/Scene.hpp b/lib/wal/sources/Scene/Scene.hpp index bf86de44..23ee5f63 100644 --- a/lib/wal/sources/Scene/Scene.hpp +++ b/lib/wal/sources/Scene/Scene.hpp @@ -6,6 +6,7 @@ #pragma once #include +#include #include "Entity/Entity.hpp" namespace WAL @@ -15,9 +16,31 @@ namespace WAL { private: //! @brief The list of registered entities - std::vector _entities; + std::vector _entities = {}; public: //! @brief Get the list of entities. std::vector &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 + Scene &addEntity(Params ...params) + { + this->_entities.emplace_back(params...); + return *this; + } + + //! @brief Remove every entity of this scene that matches the given predicate + //! @param predicate The predicate used to filer entities + void removeAll(std::function &predicate); + + //! @brief A default constructor + Scene() = default; + //! @brief A scene is copy constructable + Scene(const Scene &) = default; + //! @brief A default destructor + ~Scene() = default; + //! @brief A scene is assignable + Scene &operator=(const Scene &) = default; }; } diff --git a/lib/wal/sources/Scene/SceneManager.cpp b/lib/wal/sources/Scene/SceneManager.cpp index 21c38221..6bfda2bb 100644 --- a/lib/wal/sources/Scene/SceneManager.cpp +++ b/lib/wal/sources/Scene/SceneManager.cpp @@ -6,16 +6,16 @@ namespace WAL { - SceneManager &WAL::SceneManager::addScene(WAL::Scene &&scene) + Scene &WAL::SceneManager::addScene(WAL::Scene &&scene) { this->_scenes.push_front(scene); - return *this; + return this->getCurrent(); } - SceneManager &SceneManager::addBackScene(Scene &&scene) + Scene &SceneManager::addBackScene(Scene &&scene) { this->_scenes.insert(++this->_scenes.begin(), scene); - return *this; + return *(this->_scenes.begin() + 1); } Scene &SceneManager::getCurrent() @@ -25,9 +25,8 @@ namespace WAL return this->_scenes.front(); } - SceneManager &SceneManager::closeCurrent() + void SceneManager::closeCurrent() { this->_scenes.pop_front(); - return *this; } } \ No newline at end of file diff --git a/lib/wal/sources/Scene/SceneManager.hpp b/lib/wal/sources/Scene/SceneManager.hpp index 16268e75..d77b5f3c 100644 --- a/lib/wal/sources/Scene/SceneManager.hpp +++ b/lib/wal/sources/Scene/SceneManager.hpp @@ -17,19 +17,18 @@ namespace WAL std::deque _scenes = {}; public: //! @brief Add a scene to the container and move to it. - //! @return The manager instance used to call this function is returned. This allow method chaining. - SceneManager &addScene(Scene &&scene); + //! @return The newly added scene, to chain call. + Scene &addScene(Scene &&scene); //! @brief Add a scene before the current scene. This could be useful for lobbies or scene where the next scene can be constructed. - //! @return The manager instance used to call this function is returned. This allow method chaining. - SceneManager &addBackScene(Scene &&scene); + //! @return The newly added scene, to chain call. + Scene &addBackScene(Scene &&scene); //! @breif Get the current scene Scene &getCurrent(); //! @brief Remove the current scene and switch to the previous scene on the stack. - //! @return The manager instance used to call this function is returned. This allow method chaining. - SceneManager &closeCurrent(); + void closeCurrent(); //! @brief A default constructor SceneManager() = default;