From 397eb3d0defd32daca0b8a411944e6a48bffe817 Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Mon, 25 Sep 2023 14:19:59 +0200 Subject: [PATCH 01/15] Add current progress --- src/Client/CMakeLists.txt | 1 + .../EventManager/CMakeLists.txt | 0 .../EventManager/EventManager.cpp | 0 .../EventManager/EventManager.hpp | 0 src/{ECS => Client}/EventManager/Events.hpp | 2 +- src/Client/Systems/CMakeLists.txt | 2 - src/Client/Systems/ClientSystems.cpp | 61 +++++++++++-------- src/Client/Systems/ClientSystems.hpp | 2 + src/Client/Systems/Managers/CMakeLists.txt | 14 ----- .../Systems/Managers/GraphicManager.cpp | 48 --------------- .../Systems/Managers/GraphicManager.hpp | 30 --------- .../Systems/Managers/SystemEventsManager.cpp | 27 -------- .../Systems/Managers/SystemEventsManager.hpp | 29 --------- src/ECS/CMakeLists.txt | 1 - src/ECS/Systems/Managers/ASystemManager.hpp | 38 ------------ src/ECS/Systems/Managers/GameManager.cpp | 25 -------- src/ECS/Systems/Managers/GameManager.hpp | 29 --------- .../{ASystemManager.cpp => SystemManager.cpp} | 8 ++- src/ECS/Systems/Managers/SystemManager.hpp | 24 ++++++++ .../Managers/SystemManagersDirector.cpp | 49 +++++++++++++++ .../Managers/SystemManagersDirector.hpp | 24 ++++++++ src/ECS/Systems/Systems.cpp | 4 ++ src/ECS/Systems/Systems.hpp | 2 + src/main_client.cpp | 4 +- 24 files changed, 152 insertions(+), 272 deletions(-) rename src/{ECS => Client}/EventManager/CMakeLists.txt (100%) rename src/{ECS => Client}/EventManager/EventManager.cpp (100%) rename src/{ECS => Client}/EventManager/EventManager.hpp (100%) rename src/{ECS => Client}/EventManager/Events.hpp (86%) delete mode 100644 src/Client/Systems/Managers/CMakeLists.txt delete mode 100644 src/Client/Systems/Managers/GraphicManager.cpp delete mode 100644 src/Client/Systems/Managers/GraphicManager.hpp delete mode 100644 src/Client/Systems/Managers/SystemEventsManager.cpp delete mode 100644 src/Client/Systems/Managers/SystemEventsManager.hpp delete mode 100644 src/ECS/Systems/Managers/ASystemManager.hpp delete mode 100644 src/ECS/Systems/Managers/GameManager.cpp delete mode 100644 src/ECS/Systems/Managers/GameManager.hpp rename src/ECS/Systems/Managers/{ASystemManager.cpp => SystemManager.cpp} (75%) create mode 100644 src/ECS/Systems/Managers/SystemManager.hpp create mode 100644 src/ECS/Systems/Managers/SystemManagersDirector.cpp create mode 100644 src/ECS/Systems/Managers/SystemManagersDirector.hpp diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt index ddaf84ab..4d454098 100644 --- a/src/Client/CMakeLists.txt +++ b/src/Client/CMakeLists.txt @@ -13,3 +13,4 @@ target_sources( ) add_subdirectory(Systems) +add_subdirectory(EventManager) diff --git a/src/ECS/EventManager/CMakeLists.txt b/src/Client/EventManager/CMakeLists.txt similarity index 100% rename from src/ECS/EventManager/CMakeLists.txt rename to src/Client/EventManager/CMakeLists.txt diff --git a/src/ECS/EventManager/EventManager.cpp b/src/Client/EventManager/EventManager.cpp similarity index 100% rename from src/ECS/EventManager/EventManager.cpp rename to src/Client/EventManager/EventManager.cpp diff --git a/src/ECS/EventManager/EventManager.hpp b/src/Client/EventManager/EventManager.hpp similarity index 100% rename from src/ECS/EventManager/EventManager.hpp rename to src/Client/EventManager/EventManager.hpp diff --git a/src/ECS/EventManager/Events.hpp b/src/Client/EventManager/Events.hpp similarity index 86% rename from src/ECS/EventManager/Events.hpp rename to src/Client/EventManager/Events.hpp index f6890382..7aff7238 100644 --- a/src/ECS/EventManager/Events.hpp +++ b/src/Client/EventManager/Events.hpp @@ -12,7 +12,7 @@ #include "raylib.h" namespace Events { - static const auto events = { + static constexpr auto events = { KEY_LEFT, KEY_RIGHT, KEY_UP, diff --git a/src/Client/Systems/CMakeLists.txt b/src/Client/Systems/CMakeLists.txt index 464efe84..44698466 100644 --- a/src/Client/Systems/CMakeLists.txt +++ b/src/Client/Systems/CMakeLists.txt @@ -11,5 +11,3 @@ target_sources( PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ClientSystems.cpp ) - -add_subdirectory(Managers) diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 640efa45..f4719672 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -11,7 +11,7 @@ #include "CustomTypes.hpp" #include "Registry.hpp" -static const auto pixelRenderNumber = 50; +static constexpr auto pixelRenderNumber = 50; void GraphicSystems::pixelRenderer(std::size_t /*unused*/) { @@ -29,30 +29,6 @@ void GraphicSystems::pixelRenderer(std::size_t /*unused*/) } } -void EventsSystems::playerMovement(std::size_t /*unused*/) -{ - Registry::components arrPixel = - Registry::getInstance().getComponents(); - - for (auto &pixel : arrPixel) { - if (!pixel.has_value()) { - continue; - } - if (IsKeyDown(KEY_RIGHT)) { - pixel.value().x += 1; - } - if (IsKeyDown(KEY_LEFT)) { - pixel.value().x -= 1; - } - if (IsKeyDown(KEY_UP)) { - pixel.value().y -= 1; - } - if (IsKeyDown(KEY_DOWN)) { - pixel.value().y += 1; - } - } -} - void GraphicSystems::spriteRenderer(std::size_t /*unused*/) { Registry::components arrSprite = @@ -80,3 +56,38 @@ void GraphicSystems::spriteRenderer(std::size_t /*unused*/) WHITE); } } + +constexpr std::list> graphicSystems +{ + pixelRenderer, + spriteRenderer +} + +void EventsSystems::playerMovement(std::size_t /*unused*/) +{ + Registry::components arrPixel = + Registry::getInstance().getComponents(); + + for (auto &pixel : arrPixel) { + if (!pixel.has_value()) { + continue; + } + if (IsKeyDown(KEY_RIGHT)) { + pixel.value().x += 1; + } + if (IsKeyDown(KEY_LEFT)) { + pixel.value().x -= 1; + } + if (IsKeyDown(KEY_UP)) { + pixel.value().y -= 1; + } + if (IsKeyDown(KEY_DOWN)) { + pixel.value().y += 1; + } + } +} + +constexpr std::list> eventSystems +{ + playerMovement +} diff --git a/src/Client/Systems/ClientSystems.hpp b/src/Client/Systems/ClientSystems.hpp index 36383830..2e5dcc51 100644 --- a/src/Client/Systems/ClientSystems.hpp +++ b/src/Client/Systems/ClientSystems.hpp @@ -12,8 +12,10 @@ namespace GraphicSystems { void pixelRenderer(std::size_t /*unused*/); void spriteRenderer(std::size_t /*unused*/); + extern constexpr std::list> graphicSystems; } // namespace GraphicSystems namespace EventsSystems { void playerMovement(std::size_t /*unused*/); + extern constexpr std::list> eventSystems; } diff --git a/src/Client/Systems/Managers/CMakeLists.txt b/src/Client/Systems/Managers/CMakeLists.txt deleted file mode 100644 index c24e01fe..00000000 --- a/src/Client/Systems/Managers/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -target_include_directories( - ${PROJECT_NAME_CLIENT} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_sources( - ${PROJECT_NAME_CLIENT} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/GraphicManager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/SystemEventsManager.cpp -) diff --git a/src/Client/Systems/Managers/GraphicManager.cpp b/src/Client/Systems/Managers/GraphicManager.cpp deleted file mode 100644 index 6cf6937f..00000000 --- a/src/Client/Systems/Managers/GraphicManager.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** GraphicManager -*/ - -#include "GraphicManager.hpp" -#include -#include "raylib.h" -#include "ClientSystems.hpp" -#include "CustomTypes.hpp" - -namespace Systems { - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - GraphicManager GraphicManager::_instance = GraphicManager(); - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - - GraphicManager::GraphicManager() - { - const int screenWidth = 800; - const int screenHeight = 450; - const int frameRate = 60; - InitWindow(screenWidth, screenHeight, "Poc ECS"); - SetTargetFPS(frameRate); - - ASystemManager::addSystem(GraphicSystems::pixelRenderer); - ASystemManager::addSystem(GraphicSystems::spriteRenderer); - } - - GraphicManager::~GraphicManager() - { - CloseWindow(); - } - - GraphicManager &GraphicManager::getInstance() - { - return _instance; - } - - void GraphicManager::updateSystems() - { - BeginDrawing(); - ClearBackground(RAYWHITE); - ASystemManager::updateSystems(); - EndDrawing(); - } -} // namespace Systems diff --git a/src/Client/Systems/Managers/GraphicManager.hpp b/src/Client/Systems/Managers/GraphicManager.hpp deleted file mode 100644 index 02dfd779..00000000 --- a/src/Client/Systems/Managers/GraphicManager.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** GraphicManager -*/ - -#pragma once - -#include "ASystemManager.hpp" - -namespace Systems { - class GraphicManager : public ASystemManager { - public: - ~GraphicManager() override; - static GraphicManager &getInstance(); - void updateSystems() override; - - GraphicManager(GraphicManager const &) = delete; - GraphicManager(GraphicManager const &&) = delete; - void operator=(GraphicManager const &) = delete; - void operator=(GraphicManager const &&) = delete; - - private: - GraphicManager(); - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - static GraphicManager _instance; - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - }; -} // namespace Systems diff --git a/src/Client/Systems/Managers/SystemEventsManager.cpp b/src/Client/Systems/Managers/SystemEventsManager.cpp deleted file mode 100644 index 5785e718..00000000 --- a/src/Client/Systems/Managers/SystemEventsManager.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** SystemEventsManager -*/ - -#include "SystemEventsManager.hpp" -#include -#include "ClientSystems.hpp" -#include "CustomTypes.hpp" - -namespace Systems { - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - SystemEventsManager SystemEventsManager::_instance = SystemEventsManager(); - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - - SystemEventsManager::SystemEventsManager() - { - ASystemManager::addSystem(EventsSystems::playerMovement); - } - - SystemEventsManager &SystemEventsManager::getInstance() - { - return _instance; - } -} // namespace Systems diff --git a/src/Client/Systems/Managers/SystemEventsManager.hpp b/src/Client/Systems/Managers/SystemEventsManager.hpp deleted file mode 100644 index 7528dc08..00000000 --- a/src/Client/Systems/Managers/SystemEventsManager.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** SystemEventsManager -*/ - -#pragma once - -#include "ASystemManager.hpp" - -namespace Systems { - class SystemEventsManager : public ASystemManager { - public: - ~SystemEventsManager() override = default; - static SystemEventsManager &getInstance(); - - SystemEventsManager(SystemEventsManager const &) = delete; - SystemEventsManager(SystemEventsManager const &&) = delete; - void operator=(SystemEventsManager const &) = delete; - void operator=(SystemEventsManager const &&) = delete; - - private: - SystemEventsManager(); - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - static SystemEventsManager _instance; - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - }; -} // namespace Systems diff --git a/src/ECS/CMakeLists.txt b/src/ECS/CMakeLists.txt index 2ca81c74..e0d65fbe 100644 --- a/src/ECS/CMakeLists.txt +++ b/src/ECS/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.15) -add_subdirectory(EventManager) add_subdirectory(Systems) target_include_directories( diff --git a/src/ECS/Systems/Managers/ASystemManager.hpp b/src/ECS/Systems/Managers/ASystemManager.hpp deleted file mode 100644 index 89dee908..00000000 --- a/src/ECS/Systems/Managers/ASystemManager.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager -*/ - -#pragma once - -#include -#include -#include -#include - -namespace Systems { - class ASystemManager { - public: - virtual ~ASystemManager() = default; - ASystemManager(const ASystemManager &) = delete; - ASystemManager &operator=(const ASystemManager &) = delete; - ASystemManager(ASystemManager &&) = delete; - ASystemManager &operator=(ASystemManager &&) = delete; - - virtual void updateSystems(); - - virtual void addSystem(std::function /*sys*/); - - virtual void removeSystem(std::size_t /*id*/); - - protected: - ASystemManager() = default; - - std::list> &getSystems(); - - private: - std::list> _systems; - }; -} // namespace Systems diff --git a/src/ECS/Systems/Managers/GameManager.cpp b/src/ECS/Systems/Managers/GameManager.cpp deleted file mode 100644 index bb3eca77..00000000 --- a/src/ECS/Systems/Managers/GameManager.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager implementation -*/ - -#include "GameManager.hpp" -#include "Systems.hpp" - -namespace Systems { - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - GameManager GameManager::_instance = GameManager(); - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - - GameManager::GameManager() - { - ASystemManager::addSystem(Systems::collision); - } - - GameManager &GameManager::getInstance() - { - return _instance; - } -} // namespace Systems diff --git a/src/ECS/Systems/Managers/GameManager.hpp b/src/ECS/Systems/Managers/GameManager.hpp deleted file mode 100644 index fa55ed8c..00000000 --- a/src/ECS/Systems/Managers/GameManager.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** ASystemManager implementation -*/ - -#pragma once - -#include "ASystemManager.hpp" - -namespace Systems { - class GameManager : public ASystemManager { - public: - ~GameManager() override = default; - static GameManager &getInstance(); - - GameManager(GameManager const &) = delete; - GameManager(GameManager const &&) = delete; - void operator=(GameManager const &) = delete; - void operator=(GameManager const &&) = delete; - - private: - GameManager(); - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - static GameManager _instance; - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - }; -} // namespace Systems diff --git a/src/ECS/Systems/Managers/ASystemManager.cpp b/src/ECS/Systems/Managers/SystemManager.cpp similarity index 75% rename from src/ECS/Systems/Managers/ASystemManager.cpp rename to src/ECS/Systems/Managers/SystemManager.cpp index 91a59f1f..8a4955c2 100644 --- a/src/ECS/Systems/Managers/ASystemManager.cpp +++ b/src/ECS/Systems/Managers/SystemManager.cpp @@ -2,12 +2,18 @@ ** EPITECH PROJECT, 2023 ** R-Bus ** File description: -** ASystemManager implementation +** SystemManager implementation */ #include "ASystemManager.hpp" namespace Systems { + SystemManager::SystemManager() + {} + + SystemManager::SystemManager(std::list> systems) : _systems(systems) + {} + void ASystemManager::updateSystems() { std::size_t i = 0; diff --git a/src/ECS/Systems/Managers/SystemManager.hpp b/src/ECS/Systems/Managers/SystemManager.hpp new file mode 100644 index 00000000..ca6709fb --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManager.hpp @@ -0,0 +1,24 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManager +*/ + +#pragma once + +#include +#include + +namespace Systems { + class SystemManager { + public: + SystemManager(); + SystemManager(std::list> systems); + void updateSystems(); + void addSystem(std::function /*sys*/); + void removeSystem(std::size_t /*id*/); + private: + std::list> _systems; + }; +} // namespace Systems diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.cpp b/src/ECS/Systems/Managers/SystemManagersDirector.cpp new file mode 100644 index 00000000..3ca17626 --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManagersDirector.cpp @@ -0,0 +1,49 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManagersDirector implementation +*/ + +#include "SystemManagersDirector.hpp" +#include "Systems.hpp" + +namespace Systems { + + SystemManagersDirector SystemManagersDirector _instance = SystemManagersDirector(); + + SystemManagersDirector &SystemManagersDirector::getInstance() + { + return _instance; + } + + SystemManager &getSystemManager(std::size_t id) + { + return _systemManagers[id]; + } + + std::size_t SystemManagersDirector::addSystemManager() + { + _systemManagers.push_back(SystemManager()); + return _systemManagers.size() - 1; + } + + std::size_t SystemManagersDirector::addSystemManager(std::list> systems) + { + _systemManagers.push_back(SystemManager(systems)); + return _systemManagers.size() - 1; + } + + void SystemManagersDirector::removeSystem(std::size_t id) + { + auto it = _systemManagers.begin(); + std::advance(it, id); + _systemManagers.erase(it); + } + + SystemManagersDirector::SystemManagersDirector() + { + addSystemManager(ecsSystems); + } + +} \ No newline at end of file diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.hpp b/src/ECS/Systems/Managers/SystemManagersDirector.hpp new file mode 100644 index 00000000..0d138824 --- /dev/null +++ b/src/ECS/Systems/Managers/SystemManagersDirector.hpp @@ -0,0 +1,24 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** SystemManagersDirector +*/ + +#pragma once + +namespace Systems { + class SystemManagersDirector { + public: + static SystemManagersDirector &getInstance() + SystemManager &getSystemManager(std::size_t); + std::size_t addSystemManager(); + std::size_t addSystemManager(std::list>); + void removeSystem(std::size_t); + private: + static SystemManagersDirector _instance; + SystemManagersDirector(); + + std::list _systemManagers + } +} \ No newline at end of file diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 0b14486e..8eb6c2ec 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -13,5 +13,9 @@ namespace Systems { void collision(std::size_t /*unused*/) { + std::cout << "aa" << std::endl; + } + constexpr std::list> ecsSystems { + collision } } // namespace Systems diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index 2eab688b..95e4449d 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -8,7 +8,9 @@ #pragma once #include +#include namespace Systems { void collision(std::size_t); + extern constexpr std::list> ecsSystems; } diff --git a/src/main_client.cpp b/src/main_client.cpp index eb21c03b..d9eb8363 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -15,8 +15,8 @@ int main() { - const int sizeArrPix = 50; - const int sizeArrPixLarge = 100; + constexpr int sizeArrPix = 50; + constexpr int sizeArrPixLarge = 100; Systems::GameManager &gameManager = Systems::GameManager::getInstance(); Systems::GraphicManager &graphicManager = Systems::GraphicManager::getInstance(); From 0ffbe09f7ad4ac25f0ce07dbdd7c077cca42bc3e Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 09:35:58 +0200 Subject: [PATCH 02/15] ECS: Add current progress --- src/ECS/Systems/Managers/CMakeLists.txt | 4 ++-- src/ECS/Systems/Managers/SystemManager.cpp | 14 +++++--------- src/ECS/Systems/Managers/SystemManager.hpp | 2 +- .../Systems/Managers/SystemManagersDirector.cpp | 8 +++++--- .../Systems/Managers/SystemManagersDirector.hpp | 8 ++++++-- src/ECS/Systems/Systems.cpp | 1 + src/ECS/Systems/Systems.hpp | 1 - src/main_client.cpp | 4 +--- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/ECS/Systems/Managers/CMakeLists.txt b/src/ECS/Systems/Managers/CMakeLists.txt index c9215973..c594fa4b 100644 --- a/src/ECS/Systems/Managers/CMakeLists.txt +++ b/src/ECS/Systems/Managers/CMakeLists.txt @@ -10,6 +10,6 @@ target_sources( ${PROJECT_NAME_CLIENT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/ASystemManager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/GameManager.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SystemManagersDirector.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager.cpp ) diff --git a/src/ECS/Systems/Managers/SystemManager.cpp b/src/ECS/Systems/Managers/SystemManager.cpp index 71cb94e1..6b4df530 100644 --- a/src/ECS/Systems/Managers/SystemManager.cpp +++ b/src/ECS/Systems/Managers/SystemManager.cpp @@ -5,20 +5,16 @@ ** SystemManager implementation */ -#include "ASystemManager.hpp" +#include "SystemManager.hpp" namespace Systems { - SystemManager::SystemManager() - { - } - SystemManager::SystemManager( std::list> systems) - : _systems(systems) + : _systems(std::move(systems)) { } - void ASystemManager::updateSystems() + void SystemManager::updateSystems() { std::size_t i = 0; @@ -28,12 +24,12 @@ namespace Systems { } } - void ASystemManager::addSystem(std::function sys) + void SystemManager::addSystem(std::function sys) { _systems.push_back(sys); } - void ASystemManager::removeSystem(std::size_t id) + void SystemManager::removeSystem(std::size_t id) { auto it = _systems.begin(); std::advance(it, id); diff --git a/src/ECS/Systems/Managers/SystemManager.hpp b/src/ECS/Systems/Managers/SystemManager.hpp index 07d49f98..0c2fcdeb 100644 --- a/src/ECS/Systems/Managers/SystemManager.hpp +++ b/src/ECS/Systems/Managers/SystemManager.hpp @@ -13,7 +13,7 @@ namespace Systems { class SystemManager { public: - SystemManager(); + SystemManager() = default; SystemManager(std::list> systems); void updateSystems(); void addSystem(std::function /*sys*/); diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.cpp b/src/ECS/Systems/Managers/SystemManagersDirector.cpp index d02c0cf1..fc2e2deb 100644 --- a/src/ECS/Systems/Managers/SystemManagersDirector.cpp +++ b/src/ECS/Systems/Managers/SystemManagersDirector.cpp @@ -10,29 +10,31 @@ namespace Systems { + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) SystemManagersDirector SystemManagersDirector::_instance = SystemManagersDirector(); + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) SystemManagersDirector &SystemManagersDirector::getInstance() { return _instance; } - SystemManager &getSystemManager(std::size_t id) + SystemManager &SystemManagersDirector::getSystemManager(std::size_t id) { return _systemManagers[id]; } std::size_t SystemManagersDirector::addSystemManager() { - _systemManagers.push_back(SystemManager()); + _systemManagers.emplace_back(); return _systemManagers.size() - 1; } std::size_t SystemManagersDirector::addSystemManager( std::list> systems) { - _systemManagers.push_back(SystemManager(systems)); + _systemManagers.emplace_back(systems); return _systemManagers.size() - 1; } diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.hpp b/src/ECS/Systems/Managers/SystemManagersDirector.hpp index 6cddaf38..738129ac 100644 --- a/src/ECS/Systems/Managers/SystemManagersDirector.hpp +++ b/src/ECS/Systems/Managers/SystemManagersDirector.hpp @@ -7,6 +7,7 @@ #pragma once +#include #include "SystemManager.hpp" namespace Systems { @@ -20,9 +21,12 @@ namespace Systems { void removeSystem(std::size_t); private: - static SystemManagersDirector _instance; + std::vector _systemManagers; + SystemManagersDirector(); - std::list _systemManagers; + // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) + static SystemManagersDirector _instance; + // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) }; } // namespace Systems \ No newline at end of file diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index db274c36..e54550ba 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -9,6 +9,7 @@ #include #include "CustomTypes.hpp" #include "Registry.hpp" +#include "Systems.hpp" namespace Systems { void windowCollision(std::size_t /*unused*/) diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index ae75c0a5..66139a5e 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -6,7 +6,6 @@ */ #pragma once -#include #include #include diff --git a/src/main_client.cpp b/src/main_client.cpp index fb618840..e3ccbac3 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -14,9 +14,6 @@ void uglyCode() { - constexpr int sizeArrPix = 50; - constexpr int sizeArrPixLarge = 100; - Registry::components arrRectShape = Registry::getInstance().getComponents(); @@ -62,6 +59,7 @@ void uglyCode() int main() { + std::cout << "EnculĂ©" << std::endl; Systems::SystemManagersDirector &director = Systems::SystemManagersDirector::getInstance(); director.addSystemManager(Systems::EventsSystems::eventSystems); director.addSystemManager(Systems::GraphicSystems::graphicSystems); From b033be42675328250798e17e22c0aeffa6992b20 Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 14:25:58 +0200 Subject: [PATCH 03/15] Add current progress sprite killing window --- src/Client/Systems/CustomTypes.hpp | 2 + src/ECS/SparseArray.hpp | 2 + src/main_client.cpp | 72 +++++++++++------------------- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 3aaaa492..734f8b56 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -6,6 +6,7 @@ */ #include "raylib.h" +#include namespace Types { @@ -14,6 +15,7 @@ namespace Types { int y; }; + //Size in % struct Sprite { Texture2D sprite; float width; diff --git a/src/ECS/SparseArray.hpp b/src/ECS/SparseArray.hpp index fa368e21..025045c7 100644 --- a/src/ECS/SparseArray.hpp +++ b/src/ECS/SparseArray.hpp @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -40,6 +41,7 @@ class SparseArray { } std::optional &back() { + std::cout << "BACK" << std::endl; return _components.back(); } std::size_t size() diff --git a/src/main_client.cpp b/src/main_client.cpp index e3ccbac3..05bf7978 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -12,64 +12,46 @@ #include "Registry.hpp" #include "SystemManagersDirector.hpp" -void uglyCode() +void beautyCode() { - Registry::components arrRectShape = - Registry::getInstance().getComponents(); - - Registry::components arrPosition = - Registry::getInstance().getComponents(); - - Registry::components arrCollisionRect = - Registry::getInstance().getComponents(); - - Registry::components arrSprite = - Registry::getInstance().getComponents(); - - Registry::components arrRect = - Registry::getInstance().getComponents(); - - Registry::components arrPlayer = - Registry::getInstance().getComponents(); - - const Types::CollisionRect playerCollisionRect = {10, 20}; - const Types::Rect playerRect = {2.0F, 5.0F, 30.5F, 25.2F}; - const Types::RectangleShape rectShape = {10, 10}; - const Types::Position playerPosition = {0, 0}; - const Types::Position squarePosition = {-5, 45}; - const Types::Sprite playerSprite = { - LoadTexture("assets/R-TypeSheet/r-typesheet18.gif"), - 10, - 20}; - - // add rectangle shape entity of 10% of the screen at the middle - Registry::getInstance().addEntity(); - arrRectShape.back() = rectShape; - arrPosition.back() = squarePosition; - - // add player entity test - Registry::getInstance().addEntity(); - arrPosition.back() = playerPosition; - arrSprite.back() = playerSprite; - arrRect.back() = playerRect; - Types::Player myPlayer = {true}; - arrPlayer.back() = myPlayer; - arrCollisionRect.back() = playerCollisionRect; + Registry ®istry = Registry::getInstance(); + registry.addEntity(); + registry.getComponents().back() = {10, 10}; + registry.getComponents().back() = {-5, 45}; + registry.addEntity(); + registry.getComponents().back() = {0, 0}; + registry.getComponents().back() = {10, 20}; + std::cout << "before Sprite" << std::endl; + Registry::components sprites = registry.getComponents(); + std::cout << "mid" << std::endl; + sprites.back() = {LoadTexture("./assets/R-TypeSheet/r-typesheet1.gif"), 10, 20}; + std::cout << "after sprite" << std::endl; + registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; + registry.getComponents().back() = Types::Player(true); } +const int screenWidth = 1920; +const int screenHeight = 1080; +const int fps = 60; + int main() { - std::cout << "EnculĂ©" << std::endl; Systems::SystemManagersDirector &director = Systems::SystemManagersDirector::getInstance(); director.addSystemManager(Systems::EventsSystems::eventSystems); director.addSystemManager(Systems::GraphicSystems::graphicSystems); std::list managersIds = {1, 0, 2}; - uglyCode(); + beautyCode(); - while (true) { + InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); + SetTargetFPS(fps); + while (!WindowShouldClose()) { + BeginDrawing(); + ClearBackground(RAYWHITE); for (auto id : managersIds) { director.getSystemManager(id).updateSystems(); } + EndDrawing(); } + CloseWindow(); } From c6a4d7cc11408678eed8129d5b7e5e5c42118a7e Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 15:24:04 +0200 Subject: [PATCH 04/15] ECS: Add right CMake PATCH --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51522aaa..b3a5c6d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,15 +64,13 @@ if(CLANG_TIDY_EXE) set_target_properties(${PROJECT_NAME_CLIENT} PROPERTIES VS_GLOBAL_RunCodeAnalysis true VS_GLOBAL_EnableClangTidyCodeAnalysis true - VS_GLOBAL_ClangTidyChecks "-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,portability-*,readability-*,-readability-identifier-length,-modernize-use-trailing-return-type" ) set_target_properties(${PROJECT_NAME_SERVER} PROPERTIES VS_GLOBAL_RunCodeAnalysis true VS_GLOBAL_EnableClangTidyCodeAnalysis true - VS_GLOBAL_ClangTidyChecks "-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,portability-*,readability-*,-readability-identifier-length,-modernize-use-trailing-return-type" ) else() - set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors" "-header-filter=(src/ECS/)|(src/Client/)|(src/Server/)" "-checks=-*,clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,modernize-*,portability-*,readability-*,-readability-identifier-length,-modernize-use-trailing-return-type") + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors") set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") endif() endif() From a3af68a63b77737904080ece8d20a516cb535dfe Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 15:55:15 +0200 Subject: [PATCH 05/15] ECS: Add current progress --- src/main_client.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main_client.cpp b/src/main_client.cpp index 05bf7978..7be3d55a 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -41,10 +41,9 @@ int main() director.addSystemManager(Systems::GraphicSystems::graphicSystems); std::list managersIds = {1, 0, 2}; - beautyCode(); - InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); SetTargetFPS(fps); + beautyCode(); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(RAYWHITE); From 5ca7f2369f480900cd47297f888d66cb11f0bbac Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 16:16:48 +0200 Subject: [PATCH 06/15] ECS: Add functional new SystemManagers MAJOR --- src/ECS/SparseArray.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ECS/SparseArray.hpp b/src/ECS/SparseArray.hpp index 025045c7..fa368e21 100644 --- a/src/ECS/SparseArray.hpp +++ b/src/ECS/SparseArray.hpp @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include @@ -41,7 +40,6 @@ class SparseArray { } std::optional &back() { - std::cout << "BACK" << std::endl; return _components.back(); } std::size_t size() From 4fcc9475e95addd9080f2b311c5f455d5d305e81 Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 16:19:11 +0200 Subject: [PATCH 07/15] ECS: Fix main PATCH --- src/main_client.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main_client.cpp b/src/main_client.cpp index 7be3d55a..dcf71bff 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -21,11 +21,7 @@ void beautyCode() registry.addEntity(); registry.getComponents().back() = {0, 0}; registry.getComponents().back() = {10, 20}; - std::cout << "before Sprite" << std::endl; - Registry::components sprites = registry.getComponents(); - std::cout << "mid" << std::endl; - sprites.back() = {LoadTexture("./assets/R-TypeSheet/r-typesheet1.gif"), 10, 20}; - std::cout << "after sprite" << std::endl; + registry.getComponents().back() = {LoadTexture("./assets/R-TypeSheet/r-typesheet18.gif"), 10, 20}; registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; registry.getComponents().back() = Types::Player(true); } From 5af51439dfba82023ce501c0fb931d4158da2438 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 26 Sep 2023 14:34:43 +0000 Subject: [PATCH 08/15] FORMAT-AUTO: automatic format on pull request #23 --- src/Client/Systems/ClientSystems.cpp | 46 ++++++++++++++++------------ src/Client/Systems/ClientSystems.hpp | 6 ++-- src/Client/Systems/CustomTypes.hpp | 3 +- src/ECS/Systems/Systems.cpp | 2 +- src/main_client.cpp | 35 ++++++++++++--------- 5 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index c80f4ed1..e58bb363 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -64,12 +64,13 @@ namespace Systems { Vector2 spritePos = {0, 0}; const float denominator = 100.0; - float x = (position.x * static_cast(GetScreenWidth())) / denominator; + float x = + (position.x * static_cast(GetScreenWidth())) / denominator; float y = (position.y * static_cast(GetScreenHeight())) / denominator; - scale = (sprite.width * static_cast(GetScreenWidth())) / denominator - / static_cast(sprite.sprite.width); + scale = (sprite.width * static_cast(GetScreenWidth())) + / denominator / static_cast(sprite.sprite.width); spritePos = {x, y}; DrawTextureEx(sprite.sprite, spritePos, rotation, scale, tint); @@ -85,14 +86,15 @@ namespace Systems { auto tint = WHITE; const float denominator = 100.0; - float x = (position.x * static_cast(GetScreenWidth())) / denominator; + float x = + (position.x * static_cast(GetScreenWidth())) / denominator; float y = (position.y * static_cast(GetScreenHeight())) / denominator; float width = (sprite.width * static_cast(GetScreenWidth())) / denominator; - float height = - (sprite.height * static_cast(GetScreenHeight())) / denominator; + float height = (sprite.height * static_cast(GetScreenHeight())) + / denominator; DrawTexturePro( sprite.sprite, @@ -136,14 +138,21 @@ namespace Systems { { const float denominator = 100.0; - float x = (position.x * static_cast(GetScreenWidth())) / denominator; + float x = + (position.x * static_cast(GetScreenWidth())) / denominator; float y = (position.y * static_cast(GetScreenHeight())) / denominator; - float fsz = - (text.fontSize * static_cast(GetScreenWidth())) / denominator; + float fsz = (text.fontSize * static_cast(GetScreenWidth())) + / denominator; - DrawTextEx(text.font, text.text.data(), Vector2(x, y), fsz, 0, text.color); + DrawTextEx( + text.font, + text.text.data(), + Vector2(x, y), + fsz, + 0, + text.color); } void GraphicSystems::textRenderer(std::size_t /*unused*/) @@ -165,10 +174,11 @@ namespace Systems { } } - const std::list> GraphicSystems::graphicSystems - { - rectRenderer, spriteRenderer, textRenderer - }; + const std::list> + GraphicSystems::graphicSystems { + rectRenderer, + spriteRenderer, + textRenderer}; void EventsSystems::playerMovement(std::size_t /*unused*/) { @@ -202,8 +212,6 @@ namespace Systems { } } - const std::list> EventsSystems::eventSystems - { - playerMovement - }; -} + const std::list> + EventsSystems::eventSystems {playerMovement}; +} // namespace Systems diff --git a/src/Client/Systems/ClientSystems.hpp b/src/Client/Systems/ClientSystems.hpp index 98a73ba6..01ba9f56 100644 --- a/src/Client/Systems/ClientSystems.hpp +++ b/src/Client/Systems/ClientSystems.hpp @@ -7,9 +7,9 @@ #pragma once -#include -#include #include +#include +#include namespace Systems { namespace GraphicSystems { @@ -23,4 +23,4 @@ namespace Systems { void playerMovement(std::size_t /*unused*/); extern const std::list> eventSystems; } // namespace EventsSystems -} +} // namespace Systems diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 0f3de9b3..945aadcb 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -7,7 +7,6 @@ #include #include "raylib.h" -#include namespace Types { @@ -16,7 +15,7 @@ namespace Types { int y; }; - //Size in % + // Size in % struct Sprite { Texture2D sprite; float width; diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index e54550ba..d0de065d 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -5,11 +5,11 @@ ** Systems implementation */ +#include "Systems.hpp" #include #include #include "CustomTypes.hpp" #include "Registry.hpp" -#include "Systems.hpp" namespace Systems { void windowCollision(std::size_t /*unused*/) diff --git a/src/main_client.cpp b/src/main_client.cpp index 5618676c..ceb6eb57 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -17,35 +17,42 @@ void init() Registry ®istry = Registry::getInstance(); registry.addEntity(); registry.getComponents().back() = {10, 10}; - registry.getComponents().back() = {-5, 45}; + registry.getComponents().back() = {-5, 45}; registry.addEntity(); - registry.getComponents().back() = {0, 0}; + registry.getComponents().back() = {0, 0}; registry.getComponents().back() = {10, 20}; - registry.getComponents().back() = {LoadTexture("./assets/R-TypeSheet/r-typesheet18.gif"), 10, 20}; - registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; + registry.getComponents().back() = { + LoadTexture("./assets/R-TypeSheet/r-typesheet18.gif"), + 10, + 20}; + registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; registry.getComponents().back() = Types::Player(true); registry.addEntity(); registry.getComponents().back() = {40, 40}; - registry.getComponents().back() = { - "Player", - BLACK, - LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), - 5.5 - }; + registry.getComponents().back() = { + "Player", + BLACK, + LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), + 5.5}; } -const int screenWidth = 1920; +const int screenWidth = 1920; const int screenHeight = 1080; -const int fps = 60; +const int fps = 60; int main() { - Systems::SystemManagersDirector &director = Systems::SystemManagersDirector::getInstance(); + Systems::SystemManagersDirector &director = + Systems::SystemManagersDirector::getInstance(); director.addSystemManager(Systems::EventsSystems::eventSystems); director.addSystemManager(Systems::GraphicSystems::graphicSystems); std::list managersIds = {1, 0, 2}; - InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); + InitWindow( + screenWidth, + screenHeight, + "raylib [textures] examples - texture source and destination " + "rectangles"); SetTargetFPS(fps); init(); while (!WindowShouldClose()) { From aa23fd0833c7a92cb9cd9d6fd9e3f5f1af744e1b Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 16:53:25 +0200 Subject: [PATCH 09/15] ECS: Change lists to vectors + Format PATCH --- src/Client/EventManager/EventManager.hpp | 4 ++-- src/Client/EventManager/Events.hpp | 2 +- src/Client/Systems/ClientSystems.cpp | 4 ++-- src/Client/Systems/ClientSystems.hpp | 7 ++++--- src/Client/Systems/CustomTypes.hpp | 4 ++++ src/ECS/Registry.hpp | 7 ++++--- src/ECS/Systems/Managers/SystemManager.cpp | 2 +- src/ECS/Systems/Managers/SystemManager.hpp | 7 ++++--- .../Systems/Managers/SystemManagersDirector.cpp | 2 +- .../Systems/Managers/SystemManagersDirector.hpp | 2 +- src/ECS/Systems/Systems.cpp | 2 +- src/ECS/Systems/Systems.hpp | 5 +++-- src/main_client.cpp | 16 ++++++++-------- 13 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/Client/EventManager/EventManager.hpp b/src/Client/EventManager/EventManager.hpp index fdc5e9ca..bb3adb0c 100644 --- a/src/Client/EventManager/EventManager.hpp +++ b/src/Client/EventManager/EventManager.hpp @@ -7,7 +7,7 @@ #pragma once -#include +#include class EventManager { public: @@ -21,5 +21,5 @@ class EventManager { // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) static EventManager instance; // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - std::list _activeEvents; + std::vector _activeEvents; }; diff --git a/src/Client/EventManager/Events.hpp b/src/Client/EventManager/Events.hpp index 7aff7238..f6419a70 100644 --- a/src/Client/EventManager/Events.hpp +++ b/src/Client/EventManager/Events.hpp @@ -8,7 +8,7 @@ #pragma once #include -#include +#include #include "raylib.h" namespace Events { diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index e58bb363..da6f212a 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -174,7 +174,7 @@ namespace Systems { } } - const std::list> + const std::vector> GraphicSystems::graphicSystems { rectRenderer, spriteRenderer, @@ -212,6 +212,6 @@ namespace Systems { } } - const std::list> + const std::vector> EventsSystems::eventSystems {playerMovement}; } // namespace Systems diff --git a/src/Client/Systems/ClientSystems.hpp b/src/Client/Systems/ClientSystems.hpp index 01ba9f56..efcb1507 100644 --- a/src/Client/Systems/ClientSystems.hpp +++ b/src/Client/Systems/ClientSystems.hpp @@ -9,18 +9,19 @@ #include #include -#include +#include namespace Systems { namespace GraphicSystems { void rectRenderer(std::size_t /*unused*/); void spriteRenderer(std::size_t /*unused*/); void textRenderer(std::size_t /*unused*/); - extern const std::list> graphicSystems; + extern const std::vector> + graphicSystems; } // namespace GraphicSystems namespace EventsSystems { void playerMovement(std::size_t /*unused*/); - extern const std::list> eventSystems; + extern const std::vector> eventSystems; } // namespace EventsSystems } // namespace Systems diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 945aadcb..5d68cb46 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -17,6 +17,10 @@ namespace Types { // Size in % struct Sprite { + Sprite(const std::string path, float _width, float _height) + : sprite(LoadTexture(path.c_str())), + width(_width), + height(_height) {}; Texture2D sprite; float width; float height; diff --git a/src/ECS/Registry.hpp b/src/ECS/Registry.hpp index 6a874ef4..583db235 100644 --- a/src/ECS/Registry.hpp +++ b/src/ECS/Registry.hpp @@ -10,11 +10,11 @@ #include #include #include -#include #include #include #include #include +#include #include "raylib.h" #include "SparseArray.hpp" @@ -83,8 +83,9 @@ class Registry { static Registry _instance; // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - std::list> _addComponentPlaceFunctions; - std::list> + std::vector> + _addComponentPlaceFunctions; + std::vector> _removeComponentFunctions; std::unordered_map _data; std::size_t _entitiesNb; diff --git a/src/ECS/Systems/Managers/SystemManager.cpp b/src/ECS/Systems/Managers/SystemManager.cpp index 6b4df530..df21c3b4 100644 --- a/src/ECS/Systems/Managers/SystemManager.cpp +++ b/src/ECS/Systems/Managers/SystemManager.cpp @@ -9,7 +9,7 @@ namespace Systems { SystemManager::SystemManager( - std::list> systems) + std::vector> systems) : _systems(std::move(systems)) { } diff --git a/src/ECS/Systems/Managers/SystemManager.hpp b/src/ECS/Systems/Managers/SystemManager.hpp index 0c2fcdeb..76cc3cd0 100644 --- a/src/ECS/Systems/Managers/SystemManager.hpp +++ b/src/ECS/Systems/Managers/SystemManager.hpp @@ -8,18 +8,19 @@ #pragma once #include -#include +#include namespace Systems { class SystemManager { public: SystemManager() = default; - SystemManager(std::list> systems); + SystemManager( + std::vector> systems); void updateSystems(); void addSystem(std::function /*sys*/); void removeSystem(std::size_t /*id*/); private: - std::list> _systems; + std::vector> _systems; }; } // namespace Systems diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.cpp b/src/ECS/Systems/Managers/SystemManagersDirector.cpp index fc2e2deb..a69b6b1b 100644 --- a/src/ECS/Systems/Managers/SystemManagersDirector.cpp +++ b/src/ECS/Systems/Managers/SystemManagersDirector.cpp @@ -32,7 +32,7 @@ namespace Systems { } std::size_t SystemManagersDirector::addSystemManager( - std::list> systems) + std::vector> systems) { _systemManagers.emplace_back(systems); return _systemManagers.size() - 1; diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.hpp b/src/ECS/Systems/Managers/SystemManagersDirector.hpp index 738129ac..1ff0c716 100644 --- a/src/ECS/Systems/Managers/SystemManagersDirector.hpp +++ b/src/ECS/Systems/Managers/SystemManagersDirector.hpp @@ -17,7 +17,7 @@ namespace Systems { SystemManager &getSystemManager(std::size_t); std::size_t addSystemManager(); std::size_t - addSystemManager(std::list>); + addSystemManager(std::vector>); void removeSystem(std::size_t); private: diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index d0de065d..7664d359 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -52,6 +52,6 @@ namespace Systems { playerIt++; } } - const std::list> ecsSystems { + const std::vector> ecsSystems { windowCollision}; } // namespace Systems diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index 66139a5e..898da316 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -8,9 +8,10 @@ #pragma once #include -#include +#include +#include namespace Systems { void windowCollision(std::size_t); - extern const std::list> ecsSystems; + extern const std::vector> ecsSystems; } // namespace Systems diff --git a/src/main_client.cpp b/src/main_client.cpp index ceb6eb57..5232f1af 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -22,18 +22,18 @@ void init() registry.getComponents().back() = {0, 0}; registry.getComponents().back() = {10, 20}; registry.getComponents().back() = { - LoadTexture("./assets/R-TypeSheet/r-typesheet18.gif"), - 10, - 20}; + ("./assets/R-TypeSheet/r-typesheet18.gif"), + 10, + 20}; registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; registry.getComponents().back() = Types::Player(true); registry.addEntity(); registry.getComponents().back() = {40, 40}; registry.getComponents().back() = { - "Player", - BLACK, - LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), - 5.5}; + "Player", + BLACK, + LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), + 5.5}; } const int screenWidth = 1920; @@ -46,7 +46,7 @@ int main() Systems::SystemManagersDirector::getInstance(); director.addSystemManager(Systems::EventsSystems::eventSystems); director.addSystemManager(Systems::GraphicSystems::graphicSystems); - std::list managersIds = {1, 0, 2}; + std::vector managersIds = {1, 0, 2}; InitWindow( screenWidth, From c3c39ab155ae8de45a5340c852925a0551e36a16 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 26 Sep 2023 14:53:29 +0000 Subject: [PATCH 10/15] FORMAT-AUTO: automatic format on pull request #23 --- src/main_client.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main_client.cpp b/src/main_client.cpp index 5232f1af..d4395f56 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -22,18 +22,18 @@ void init() registry.getComponents().back() = {0, 0}; registry.getComponents().back() = {10, 20}; registry.getComponents().back() = { - ("./assets/R-TypeSheet/r-typesheet18.gif"), - 10, - 20}; + ("./assets/R-TypeSheet/r-typesheet18.gif"), + 10, + 20}; registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; registry.getComponents().back() = Types::Player(true); registry.addEntity(); registry.getComponents().back() = {40, 40}; registry.getComponents().back() = { - "Player", - BLACK, - LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), - 5.5}; + "Player", + BLACK, + LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), + 5.5}; } const int screenWidth = 1920; From 010da28ab9877d8c58befdfffa7c0d36c6a5678a Mon Sep 17 00:00:00 2001 From: guillaume abel <91884836+guillaumeAbel@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:54:46 +0200 Subject: [PATCH 11/15] Update src/ECS/Systems/Managers/SystemManagersDirector.hpp Co-authored-by: TTENSHII <87119012+TTENSHII@users.noreply.github.com> --- src/ECS/Systems/Managers/SystemManagersDirector.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.hpp b/src/ECS/Systems/Managers/SystemManagersDirector.hpp index 1ff0c716..1548ecdd 100644 --- a/src/ECS/Systems/Managers/SystemManagersDirector.hpp +++ b/src/ECS/Systems/Managers/SystemManagersDirector.hpp @@ -29,4 +29,4 @@ namespace Systems { static SystemManagersDirector _instance; // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) }; -} // namespace Systems \ No newline at end of file +} // namespace Systems From e9928ebc96b8770a050dd464b2aea18280254b53 Mon Sep 17 00:00:00 2001 From: guillaume abel <91884836+guillaumeAbel@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:55:40 +0200 Subject: [PATCH 12/15] Update src/ECS/Systems/Managers/SystemManagersDirector.cpp Co-authored-by: TTENSHII <87119012+TTENSHII@users.noreply.github.com> --- src/ECS/Systems/Managers/SystemManagersDirector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ECS/Systems/Managers/SystemManagersDirector.cpp b/src/ECS/Systems/Managers/SystemManagersDirector.cpp index a69b6b1b..239ff303 100644 --- a/src/ECS/Systems/Managers/SystemManagersDirector.cpp +++ b/src/ECS/Systems/Managers/SystemManagersDirector.cpp @@ -50,4 +50,4 @@ namespace Systems { addSystemManager(ecsSystems); } -} // namespace Systems \ No newline at end of file +} // namespace Systems From 8d4a6ccc9e9a0e98bd63cab1ef7695b899c02bc6 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 26 Sep 2023 16:24:53 +0000 Subject: [PATCH 13/15] FORMAT-AUTO: automatic format on pull request #23 --- src/main_client.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main_client.cpp b/src/main_client.cpp index 195432f7..88937967 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -19,9 +19,9 @@ void init() registry.getComponents().back() = {0, 0}; registry.getComponents().back() = {10, 20}; registry.getComponents().back() = { - "./assets/R-TypeSheet/r-typesheet18.gif", - 10, - 20}; + "./assets/R-TypeSheet/r-typesheet18.gif", + 10, + 20}; registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; registry.getComponents().back() = Types::Player(true); registry.addEntity(); @@ -30,10 +30,10 @@ void init() registry.addEntity(); registry.getComponents().back() = {40, 40}; registry.getComponents().back() = { - "Player", - BLACK, - LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), - 5.5}; + "Player", + BLACK, + LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), + 5.5}; registry.addEntity(); registry.getComponents().back() = Types::SoundEffect("assets/Audio/Sounds/yes.ogg"); From 60f336393d1ffe4099a63b0423a31977f939347c Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 18:26:38 +0200 Subject: [PATCH 14/15] ECS: Call music PATCH --- src/main_client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main_client.cpp b/src/main_client.cpp index 195432f7..0c31a5a7 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -40,6 +40,7 @@ void init() registry.addEntity(); registry.getComponents().back() = Types::MusicStream("assets/Audio/Musics/Title.mp3"); + registry.getComponents().back().needToPlay = True; } const int screenWidth = 1920; From 6b7deb4419982bbab6b759d7d486bcb2500e03ff Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 26 Sep 2023 19:22:04 +0200 Subject: [PATCH 15/15] ECS: Fix magic values PATCH --- src/main_client.cpp | 66 --------------------------------------------- 1 file changed, 66 deletions(-) diff --git a/src/main_client.cpp b/src/main_client.cpp index c1737606..93f282df 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -5,72 +5,6 @@ ** main */ -#include -#include "raylib.h" -#include "ClientSystems.hpp" -#include "CustomTypes.hpp" -#include "Registry.hpp" -#include "SystemManagersDirector.hpp" - -void init() -{ - Registry ®istry = Registry::getInstance(); - registry.addEntity(); - registry.getComponents().back() = {0, 0}; - registry.getComponents().back() = {10, 20}; - registry.getComponents().back() = { - "./assets/R-TypeSheet/r-typesheet18.gif", - 10, - 20}; - registry.getComponents().back() = {2.0F, 5.0F, 30.5F, 25.2F}; - registry.getComponents().back() = Types::Player(true); - registry.addEntity(); - registry.getComponents().back() = {0, 0}; - registry.getComponents().back() = {10, 10}; - registry.addEntity(); - registry.getComponents().back() = {40, 40}; - registry.getComponents().back() = { - "Player", - BLACK, - LoadFont("assets/Fonts/soliden/SolidenTrial-Black.otf"), - 5.5}; - registry.addEntity(); - registry.getComponents().back() = - Types::SoundEffect("assets/Audio/Sounds/yes.ogg"); - registry.addEntity(); - registry.getComponents().back() = - Types::MusicStream("assets/Audio/Musics/Title.mp3"); - registry.getComponents().back().needToPlay = True; -} - -const int screenWidth = 1920; -const int screenHeight = 1080; -const int fps = 60; - int main() { - Systems::SystemManagersDirector &director = - Systems::SystemManagersDirector::getInstance(); - director.addSystemManager(Systems::EventsSystems::eventSystems); - director.addSystemManager(Systems::GraphicSystems::graphicSystems); - std::vector managersIds = {1, 0, 2}; - - InitWindow( - screenWidth, - screenHeight, - "raylib [textures] examples - texture source and destination " - "rectangles"); - SetTargetFPS(fps); - InitAudioDevice(); - init(); - while (!WindowShouldClose()) { - BeginDrawing(); - ClearBackground(RAYWHITE); - for (auto id : managersIds) { - director.getSystemManager(id).updateSystems(); - } - EndDrawing(); - } - CloseAudioDevice(); - CloseWindow(); }