From ae2e41983275f7008a70d7d38861b56117651f7f Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 2 Jun 2021 23:30:39 +0200 Subject: [PATCH] Creating a templated view class --- lib/wal/CMakeLists.txt | 2 +- lib/wal/sources/Scene/Scene.hpp | 3 +++ lib/wal/sources/View/View.hpp | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/wal/sources/View/View.hpp diff --git a/lib/wal/CMakeLists.txt b/lib/wal/CMakeLists.txt index e8cd8655..ba2a60a0 100644 --- a/lib/wal/CMakeLists.txt +++ b/lib/wal/CMakeLists.txt @@ -17,6 +17,6 @@ add_library(wal sources/Component/Component.cpp sources/System/System.cpp sources/Models/Callback.hpp -) + sources/View/View.hpp) target_include_directories(wal PUBLIC sources) \ No newline at end of file diff --git a/lib/wal/sources/Scene/Scene.hpp b/lib/wal/sources/Scene/Scene.hpp index bddf1e5c..840d2ec5 100644 --- a/lib/wal/sources/Scene/Scene.hpp +++ b/lib/wal/sources/Scene/Scene.hpp @@ -7,6 +7,7 @@ #include #include +#include "View/View.hpp" #include "Entity/Entity.hpp" namespace WAL @@ -17,6 +18,8 @@ namespace WAL private: //! @brief The list of registered entities std::vector _entities = {}; + //! @brief A list of cached views. +// std::vector _views = {}; public: //! @brief Get the list of entities. std::vector &getEntities(); diff --git a/lib/wal/sources/View/View.hpp b/lib/wal/sources/View/View.hpp new file mode 100644 index 00000000..9f004188 --- /dev/null +++ b/lib/wal/sources/View/View.hpp @@ -0,0 +1,35 @@ +// +// Created by Zoe Roux on 2021-06-02. +// + + +#pragma once + +#include +#include + +namespace WAL +{ + //! @brief A view caching entities containing requested components + template + class View + { + //! @brief A list of reference to entities that contains the + std::vector> entities; + + explicit View(std::vector &entities) + : entities() + { + std::copy_if(entities.begin(), entities.end(), std::back_inserter(this->entities), [](Entity &entity) { + return (entity.hasComponent() && ...); + }); + } + + //! @brief A default copy constructor. + View(const View &) = default; + //! @brief A default destructor. + ~View() = default; + //! @brief A View is assignable. + View &operator=(const View &) = default; + }; +} \ No newline at end of file