From bc19e5957201165ea8810a0f469e19f5337e26e4 Mon Sep 17 00:00:00 2001 From: Kitetsu Date: Wed, 20 Sep 2023 16:31:13 +0200 Subject: [PATCH] POC: Add first version of poc MINOR --- .gitignore | 50 +++++++++++++++++++ src/poc/CMakeLists.txt | 47 +++++++++++++++++ src/poc/fclean.sh | 23 +++++++++ src/poc/src/CMakeLists.txt | 16 ++++++ src/poc/src/Registry.hpp | 48 ++++++++++++++++++ src/poc/src/SparseArray.hpp | 43 ++++++++++++++++ src/poc/src/main.cpp | 43 ++++++++++++++++ src/poc/src/system/ASystem.cpp | 25 ++++++++++ src/poc/src/system/ASystem.hpp | 29 +++++++++++ src/poc/src/system/CMakeLists.txt | 18 +++++++ src/poc/src/system/Collison.cpp | 32 ++++++++++++ src/poc/src/system/Collison.hpp | 24 +++++++++ src/poc/src/system/ISystem.hpp | 24 +++++++++ src/poc/src/system/Movement.cpp | 31 ++++++++++++ src/poc/src/system/Movement.hpp | 24 +++++++++ src/poc/src/system/managers/CMakeLists.txt | 14 ++++++ src/poc/src/system/managers/SystemManager.cpp | 34 +++++++++++++ src/poc/src/system/managers/SystemManager.hpp | 30 +++++++++++ 18 files changed, 555 insertions(+) create mode 100644 .gitignore create mode 100644 src/poc/CMakeLists.txt create mode 100755 src/poc/fclean.sh create mode 100644 src/poc/src/CMakeLists.txt create mode 100644 src/poc/src/Registry.hpp create mode 100644 src/poc/src/SparseArray.hpp create mode 100644 src/poc/src/main.cpp create mode 100644 src/poc/src/system/ASystem.cpp create mode 100644 src/poc/src/system/ASystem.hpp create mode 100644 src/poc/src/system/CMakeLists.txt create mode 100644 src/poc/src/system/Collison.cpp create mode 100644 src/poc/src/system/Collison.hpp create mode 100644 src/poc/src/system/ISystem.hpp create mode 100644 src/poc/src/system/Movement.cpp create mode 100644 src/poc/src/system/Movement.hpp create mode 100644 src/poc/src/system/managers/CMakeLists.txt create mode 100644 src/poc/src/system/managers/SystemManager.cpp create mode 100644 src/poc/src/system/managers/SystemManager.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b2399822 --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Misc +build/ +.idea/ +.vscode/ +.vs/ +*.ini +!dllTest/* + +#CMake +*.vcxproj* +CmakeCache* +CmakeFiles/ +Debug/ +cmake_* +*.dir/ +*.sln +x64/ diff --git a/src/poc/CMakeLists.txt b/src/poc/CMakeLists.txt new file mode 100644 index 00000000..17554fa1 --- /dev/null +++ b/src/poc/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.27) + +set(PROJECT_NAME poc) + +project( + ${PROJECT_NAME} + VERSION 1.0.0 + LANGUAGES CXX +) + +set(CMAKE_CXX_STANDARD 20) + +add_executable( + ${PROJECT_NAME} +) + +if(MSVC) + target_compile_options( + ${PROJECT_NAME} + PRIVATE + /W4 + ) +else() + target_compile_options( + ${PROJECT_NAME} + PRIVATE + -Wall -Wextra + ) +endif() + +add_subdirectory(src) + +if (WIN32) + add_custom_command( + TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.exe + ) +else() + add_custom_command( + TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + $ + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME} + ) +endif() diff --git a/src/poc/fclean.sh b/src/poc/fclean.sh new file mode 100755 index 00000000..77dd377e --- /dev/null +++ b/src/poc/fclean.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +[ -f Makefile ] && echo "Running make clean..." && make clean + +echo "Finding files..." +FILES=$(find . -name "*-prefix" -o -name "CMakeFiles" -o -name "CMakeCache.txt" -o -name "cmake_install.cmake" -o -name "Makefile" -o -name "_deps" -o -name "poc") +echo "Files to clean:" +echo "$FILES" + +if [[ "$1" != "-y" ]]; then + echo "Do you want to rm? (y/n)" + read -r ANSWER +else + ANSWER="y" +fi + +if [ "$ANSWER" == "y" ]; then + echo "Removing files..." + rm -rf $FILES + echo "Done!" +else + echo "Canceled!" +fi \ No newline at end of file diff --git a/src/poc/src/CMakeLists.txt b/src/poc/src/CMakeLists.txt new file mode 100644 index 00000000..9db8e421 --- /dev/null +++ b/src/poc/src/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.27) + +add_subdirectory(system) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/system/managers +) + +target_sources( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp +) diff --git a/src/poc/src/Registry.hpp b/src/poc/src/Registry.hpp new file mode 100644 index 00000000..5a6b687a --- /dev/null +++ b/src/poc/src/Registry.hpp @@ -0,0 +1,48 @@ +/* +** Registry.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/poc/src +** +** Made by brice +** Login +** +** Started on Wed Sep 20 4:21:18 PM 2023 brice +** Last update Wed Sep 20 4:21:18 PM 2023 brice +*/ + +#include +#include +#include +#include +#include "SparseArray.hpp" +#include + +class Registry { + public: + template + using array = std::shared_ptr>; + + template + array registerComponent() + { + if (_data.find(typeid(Component)) == _data.end()) { + _data[typeid(Component)] = std::make_shared>(); + } + return castReturn(); + }; + template + array getComponents() + { + return castReturn(); + }; + template + array const &getComponents() const + { + return castReturn(); + }; + private: + template + array castReturn() + { + return std::any_cast>(_data[typeid(Component)]); + } + std::unordered_map _data; +}; diff --git a/src/poc/src/SparseArray.hpp b/src/poc/src/SparseArray.hpp new file mode 100644 index 00000000..6f773384 --- /dev/null +++ b/src/poc/src/SparseArray.hpp @@ -0,0 +1,43 @@ +/* +** SparseArray.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/poc/src +** +** Made by brice +** Login +** +** Started on Wed Sep 20 4:21:15 PM 2023 brice +** Last update Wed Sep 20 4:21:15 PM 2023 brice +*/ + +#include +#include + +template +class SparseArray { + public: + void add(Component component) + { + _components.push_back(component); + }; + void erase(int id) + { + auto it = _components.begin(); + std::advance(it, id); + _components.erase(it); + }; + Component &operator[](size_t idx) + { + return _components[idx]; + } + + std::list::iterator begin() + { + return _components.begin(); + } + + std::list::iterator end() + { + return _components.end(); + } + private: + std::list _components; +}; diff --git a/src/poc/src/main.cpp b/src/poc/src/main.cpp new file mode 100644 index 00000000..8e7a840b --- /dev/null +++ b/src/poc/src/main.cpp @@ -0,0 +1,43 @@ +/* +** main.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/poc/src +** +** Made by brice +** Login +** +** Started on Wed Sep 20 4:21:09 PM 2023 brice +** Last update Wed Sep 20 4:21:09 PM 2023 brice +*/ + +#include +#include +#include "SystemManager.hpp" +#include "Collison.hpp" +#include "Movement.hpp" + +int main() +{ + Registry *registry = new Registry(); + Registry::array arrInt = registry->registerComponent(); + arrInt->add(4); + arrInt->add(69); + Registry::array arrFloat = registry->registerComponent(); + arrFloat->add(69.69); + Registry::array scdContainer = registry->getComponents(); + for (auto begin = arrInt->begin(); begin != arrInt->end(); begin++) { + std::cout << *begin << std::endl; + } + for (auto begin = scdContainer->begin(); begin != scdContainer->end(); begin++) { + std::cout << *begin << std::endl; + } + + System::SystemManager manager; + + manager.addSystem(std::make_unique(registry)); + manager.addSystem(std::make_unique(registry)); + + while (1) { + manager.updateSystems(); + sleep(1); + } + return 0; +} diff --git a/src/poc/src/system/ASystem.cpp b/src/poc/src/system/ASystem.cpp new file mode 100644 index 00000000..efed5863 --- /dev/null +++ b/src/poc/src/system/ASystem.cpp @@ -0,0 +1,25 @@ +/* +** ASystem.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Tue Sep 19 5:18:32 PM 2023 brice +** Last update Thu Sep 20 9:37:48 AM 2023 brice +*/ + +#include "ASystem.hpp" + +namespace System { + + ASystem::ASystem(Registry *registry) + : _registry(registry) + { + + } + + void ASystem::clientRun() + { + // To fill when network is ok + } +} diff --git a/src/poc/src/system/ASystem.hpp b/src/poc/src/system/ASystem.hpp new file mode 100644 index 00000000..ed0129ca --- /dev/null +++ b/src/poc/src/system/ASystem.hpp @@ -0,0 +1,29 @@ +/* +** ASystem.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Tue Sep 19 5:18:35 PM 2023 brice +** Last update Thu Sep 20 9:57:34 AM 2023 brice +*/ + +#pragma once + +#include "ISystem.hpp" +#include "Registry.hpp" + +namespace System { + class ASystem : public ISystem { + public: + ASystem(Registry *registry); + ~ASystem() = default; + + protected: + Registry *_registry; + private: + void clientRun() final; + + + }; +} diff --git a/src/poc/src/system/CMakeLists.txt b/src/poc/src/system/CMakeLists.txt new file mode 100644 index 00000000..f7ee7079 --- /dev/null +++ b/src/poc/src/system/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/Collison.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Movement.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ASystem.cpp +) + +add_subdirectory(managers) diff --git a/src/poc/src/system/Collison.cpp b/src/poc/src/system/Collison.cpp new file mode 100644 index 00000000..acb1b1d2 --- /dev/null +++ b/src/poc/src/system/Collison.cpp @@ -0,0 +1,32 @@ +/* +** Collison.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Wed Sep 20 9:36:31 AM 2023 brice +** Last update Thu Sep 20 12:03:08 PM 2023 brice +*/ + +#include +#include "Collison.hpp" + +namespace System { + + Collison::Collison(Registry *registry) + : ASystem(registry) + { + + } + + void Collison::run() + { + std::cout << "Increment sparse array int of 1" << std::endl; + Registry::array arrInt = _registry->getComponents(); + + for (auto begin = arrInt->begin(); begin != arrInt->end(); begin++) { + *begin += 1; + } + std::cout << "------------------------------------" << std::endl; + } +} diff --git a/src/poc/src/system/Collison.hpp b/src/poc/src/system/Collison.hpp new file mode 100644 index 00000000..25cd55ff --- /dev/null +++ b/src/poc/src/system/Collison.hpp @@ -0,0 +1,24 @@ +/* +** Collison.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Wed Sep 20 9:36:35 AM 2023 brice +** Last update Thu Sep 20 9:58:17 AM 2023 brice +*/ + +#pragma once + +#include "ASystem.hpp" + +namespace System { + class Collison : public ASystem { + public: + Collison(Registry *registry); + + void run() final; + protected: + private: + }; +} diff --git a/src/poc/src/system/ISystem.hpp b/src/poc/src/system/ISystem.hpp new file mode 100644 index 00000000..ae52ff02 --- /dev/null +++ b/src/poc/src/system/ISystem.hpp @@ -0,0 +1,24 @@ +/* +** ISystem.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Tue Sep 19 5:13:48 PM 2023 brice +** Last update Thu Sep 20 9:54:30 AM 2023 brice +*/ + +#pragma once + +namespace System { + class ISystem { + public: + virtual ~ISystem() = default; + + virtual void run() = 0; + + protected: + private: + virtual void clientRun() = 0; + }; +} diff --git a/src/poc/src/system/Movement.cpp b/src/poc/src/system/Movement.cpp new file mode 100644 index 00000000..35ba0e5e --- /dev/null +++ b/src/poc/src/system/Movement.cpp @@ -0,0 +1,31 @@ +/* +** Movement.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Wed Sep 20 10:19:53 AM 2023 brice +** Last update Thu Sep 20 2:34:00 PM 2023 brice +*/ + +#include +#include "Movement.hpp" + +namespace System { + Movement::Movement(Registry *registry) + : ASystem(registry) + { + + } + + void Movement::run() + { + std::cout << "Printing sparse array of int" << std::endl; + Registry::array arrInt = _registry->getComponents(); + + for (auto begin = arrInt->begin(); begin != arrInt->end(); begin++) { + std::cout << *begin << std::endl; + } + std::cout << "------------------------------------" << std::endl; + } +} diff --git a/src/poc/src/system/Movement.hpp b/src/poc/src/system/Movement.hpp new file mode 100644 index 00000000..d73f91a7 --- /dev/null +++ b/src/poc/src/system/Movement.hpp @@ -0,0 +1,24 @@ +/* +** Movement.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system +** +** Made by brice +** Login +** +** Started on Wed Sep 20 10:19:50 AM 2023 brice +** Last update Thu Sep 20 10:28:46 AM 2023 brice +*/ + +#pragma once + +#include "ASystem.hpp" + +namespace System { + class Movement : public ASystem { + public: + Movement(Registry *registry); + + void run() final; + protected: + private: + }; +} diff --git a/src/poc/src/system/managers/CMakeLists.txt b/src/poc/src/system/managers/CMakeLists.txt new file mode 100644 index 00000000..d045d69c --- /dev/null +++ b/src/poc/src/system/managers/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/SystemManager.cpp +) diff --git a/src/poc/src/system/managers/SystemManager.cpp b/src/poc/src/system/managers/SystemManager.cpp new file mode 100644 index 00000000..616ba4d3 --- /dev/null +++ b/src/poc/src/system/managers/SystemManager.cpp @@ -0,0 +1,34 @@ +/* +** SystemManager.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system/managers +** +** Made by brice +** Login +** +** Started on Wed Sep 20 10:25:26 AM 2023 brice +** Last update Thu Sep 20 2:34:27 PM 2023 brice +*/ + +#include "SystemManager.hpp" + + +namespace System { + SystemManager::SystemManager() + { + } + + SystemManager::~SystemManager() + { + } + + void SystemManager::updateSystems() + { + for (auto &system : _systems) { + system->run(); + } + } + + void SystemManager::addSystem(std::unique_ptr system) + { + _systems.push_back(std::move(system)); + } +} diff --git a/src/poc/src/system/managers/SystemManager.hpp b/src/poc/src/system/managers/SystemManager.hpp new file mode 100644 index 00000000..028d6ea7 --- /dev/null +++ b/src/poc/src/system/managers/SystemManager.hpp @@ -0,0 +1,30 @@ +/* +** SystemManager.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system/managers +** +** Made by brice +** Login +** +** Started on Wed Sep 20 10:25:23 AM 2023 brice +** Last update Thu Sep 20 11:23:54 AM 2023 brice +*/ + +#pragma once + +#include +#include +#include "ISystem.hpp" + +namespace System { + class SystemManager { + public: + SystemManager(); + ~SystemManager(); + + void updateSystems(); + + void addSystem(std::unique_ptr system); + + protected: + std::vector> _systems; + }; +}