From 43b482df7f40c27f0e74abd311bfc81094026577 Mon Sep 17 00:00:00 2001 From: Nikita Fediuchin Date: Tue, 17 Sep 2024 00:06:24 +0200 Subject: [PATCH] Fix linux compilation --- include/ecsm.hpp | 236 ++++++++++++++++++++-------------------- include/type-string.hpp | 1 + tests/test-ecsm.cpp | 1 + 3 files changed, 120 insertions(+), 118 deletions(-) diff --git a/include/ecsm.hpp b/include/ecsm.hpp index c2bfb01..31bb402 100644 --- a/include/ecsm.hpp +++ b/include/ecsm.hpp @@ -144,124 +144,6 @@ class System virtual void disposeComponents(); }; -/*********************************************************************************************************************** - * @brief Base system class with components. - * @details See the @ref System. - * - * @tparam T type of the system component - * @tparam DestroyComponents system should call destroy() function of the components - */ -template -class ComponentSystem : public System -{ -protected: - /** - * @brief System component pool. - */ - LinearPool components; - - /** - * @brief Creates a new component instance for the entity. - * @details You should use @ref Manager to add components to the entity. - */ - ID createComponent(ID entity) override - { - return ID(components.create()); - } - /** - * @brief Destroys component instance. - * @details You should use @ref Manager to remove components from the entity. - */ - void destroyComponent(ID instance) override - { - components.destroy(ID(instance)); - } - /** - * @brief Copies component data from source to destination. - * @details You should use @ref Manager to copy component data of entities. - */ - void copyComponent(View source, View destination) override - { - if constexpr (DestroyComponents) - { - auto destinationView = View(destination); - destinationView->destroy(); - } - } -public: - /** - * @brief Returns specific component name of the system. - */ - const string& getComponentName() const override - { - static const string name = typeToString(typeid(T)); - return name; - } - /** - * @brief Returns specific component typeid() of the system. - * @note Override it to define a custom component of the system. - */ - type_index getComponentType() const override - { - return typeid(T); - } - /** - * @brief Returns specific component @ref View. - */ - View getComponent(ID instance) override - { - return View(components.get(ID(instance))); - } - /** - * @brief Actually destroys system components. - * @details Components are not destroyed immediately, only after the dispose call. - */ - void disposeComponents() override - { - components.dispose(); - } - - /** - * @brief Returns true if entity has specific component. - * @param entity target entity with component - * @note This function is faster than the Manager one. - */ - bool hasComponent(ID entity) const - { - assert(entity); - const auto entityView = Manager::Instance::get()->getEntities().get(entity); - const auto& entityComponents = entityView->getComponents(); - return entityComponents.find(typeid(T)) != entityComponents.end(); - } - /** - * @brief Returns entity specific component view. - * @param entity target entity with component - * @note This function is faster than the Manager one. - */ - View getComponent(ID entity) const - { - assert(entity); - const auto entityView = Manager::Instance::get()->getEntities().get(entity); - const auto& pair = entityView->getComponents().at(typeid(T)); - return components.get(ID(pair.second)); - } - /** - * @brief Returns entity specific component view if exist. - * @param entity target entity with component - * @note This function is faster than the Manager one. - */ - View tryGetComponent(ID entity) const - { - assert(entity); - const auto entityView = Manager::Instance::get()->getEntities().get(entity); - const auto& entityComponents = entityView->getComponents(); - auto result = entityComponents.find(typeid(T)); - if (result == entityComponents.end()) - return {}; - return components.get(ID(result->second.second)); - } -}; - /*********************************************************************************************************************** * @brief An object containing components. * @@ -1068,6 +950,124 @@ class Manager final : public Singleton void unlock() noexcept { locker.unlock(); } }; +/*********************************************************************************************************************** + * @brief Base system class with components. + * @details See the @ref System. + * + * @tparam T type of the system component + * @tparam DestroyComponents system should call destroy() function of the components + */ +template +class ComponentSystem : public System +{ +protected: + /** + * @brief System component pool. + */ + LinearPool components; + + /** + * @brief Creates a new component instance for the entity. + * @details You should use @ref Manager to add components to the entity. + */ + ID createComponent(ID entity) override + { + return ID(components.create()); + } + /** + * @brief Destroys component instance. + * @details You should use @ref Manager to remove components from the entity. + */ + void destroyComponent(ID instance) override + { + components.destroy(ID(instance)); + } + /** + * @brief Copies component data from source to destination. + * @details You should use @ref Manager to copy component data of entities. + */ + void copyComponent(View source, View destination) override + { + if constexpr (DestroyComponents) + { + auto destinationView = View(destination); + destinationView->destroy(); + } + } +public: + /** + * @brief Returns specific component name of the system. + */ + const string& getComponentName() const override + { + static const string name = typeToString(typeid(T)); + return name; + } + /** + * @brief Returns specific component typeid() of the system. + * @note Override it to define a custom component of the system. + */ + type_index getComponentType() const override + { + return typeid(T); + } + /** + * @brief Returns specific component @ref View. + */ + View getComponent(ID instance) override + { + return View(components.get(ID(instance))); + } + /** + * @brief Actually destroys system components. + * @details Components are not destroyed immediately, only after the dispose call. + */ + void disposeComponents() override + { + components.dispose(); + } + + /** + * @brief Returns true if entity has specific component. + * @param entity target entity with component + * @note This function is faster than the Manager one. + */ + bool hasComponent(ID entity) const + { + assert(entity); + const auto entityView = Manager::Instance::get()->getEntities().get(entity); + const auto& entityComponents = entityView->getComponents(); + return entityComponents.find(typeid(T)) != entityComponents.end(); + } + /** + * @brief Returns entity specific component view. + * @param entity target entity with component + * @note This function is faster than the Manager one. + */ + View getComponent(ID entity) const + { + assert(entity); + const auto entityView = Manager::Instance::get()->getEntities().get(entity); + const auto& pair = entityView->getComponents().at(typeid(T)); + return components.get(ID(pair.second)); + } + /** + * @brief Returns entity specific component view if exist. + * @param entity target entity with component + * @note This function is faster than the Manager one. + */ + View tryGetComponent(ID entity) const + { + assert(entity); + const auto entityView = Manager::Instance::get()->getEntities().get(entity); + const auto& entityComponents = entityView->getComponents(); + auto result = entityComponents.find(typeid(T)); + if (result == entityComponents.end()) + return {}; + return components.get(ID(result->second.second)); + } +}; + /*********************************************************************************************************************** * @brief Component indicating that this entity should not be destroyed. * @details Useful in cases when we need to mark important entities like main camera. diff --git a/include/type-string.hpp b/include/type-string.hpp index b3d6354..2eb6ace 100644 --- a/include/type-string.hpp +++ b/include/type-string.hpp @@ -19,6 +19,7 @@ #pragma once #include +#include #include #ifdef __GNUG__ diff --git a/tests/test-ecsm.cpp b/tests/test-ecsm.cpp index b6fde0c..0745287 100644 --- a/tests/test-ecsm.cpp +++ b/tests/test-ecsm.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "ecsm.hpp" + using namespace ecsm; struct TestComponent final : public Component