-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from X-R-G-B/feature/RB-26-je-veux-un-premier-p…
…roof-of-concept POC: Add first version of poc
- Loading branch information
Showing
17 changed files
with
523 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
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 -pedantic | ||
) | ||
endif() | ||
|
||
add_subdirectory(src) | ||
|
||
if (WIN32) | ||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
$<TARGET_FILE:${PROJECT_NAME}> | ||
${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.exe | ||
) | ||
else() | ||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
$<TARGET_FILE:${PROJECT_NAME}> | ||
${CMAKE_SOURCE_DIR}/${PROJECT_NAME} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** R-Bus | ||
** File description: | ||
** Registry | ||
*/ | ||
|
||
#include <any> | ||
#include <typeinfo> | ||
#include <typeindex> | ||
#include <unordered_map> | ||
#include "SparseArray.hpp" | ||
#include <memory> | ||
|
||
class Registry { | ||
public: | ||
template <class Component> | ||
using array = std::shared_ptr<SparseArray<Component>>; | ||
|
||
template <class Component> | ||
array<Component> registerComponent() | ||
{ | ||
if (_data.find(typeid(Component)) == _data.end()) { | ||
_data[typeid(Component)] = std::make_shared<SparseArray<Component>>(); | ||
} | ||
return castReturn<Component>(); | ||
}; | ||
template <class Component> | ||
array<Component> getComponents() | ||
{ | ||
return castReturn<Component>(); | ||
}; | ||
template <class Component> | ||
array<Component> const &getComponents() const | ||
{ | ||
return castReturn<Component>(); | ||
}; | ||
private: | ||
template<class Component> | ||
array<Component> castReturn() | ||
{ | ||
return std::any_cast<array<Component>>(_data[typeid(Component)]); | ||
} | ||
std::unordered_map<std::type_index, std::any> _data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** R-Bus | ||
** File description: | ||
** SparseArray | ||
*/ | ||
|
||
#include <iterator> | ||
#include <list> | ||
|
||
template <typename Component> | ||
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<Component>::iterator begin() | ||
{ | ||
return _components.begin(); | ||
} | ||
|
||
std::list<Component>::iterator end() | ||
{ | ||
return _components.end(); | ||
} | ||
private: | ||
std::list<Component> _components; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** R-Bus | ||
** File description: | ||
** main | ||
*/ | ||
|
||
#include <iostream> | ||
#include <unistd.h> | ||
#include "SystemManager.hpp" | ||
#include "Collison.hpp" | ||
#include "Movement.hpp" | ||
|
||
int main() | ||
{ | ||
Registry *registry = new Registry(); | ||
Registry::array<int> arrInt = registry->registerComponent<int>(); | ||
arrInt->add(4); | ||
arrInt->add(69); | ||
Registry::array<float> arrFloat = registry->registerComponent<float>(); | ||
arrFloat->add(69.69); | ||
Registry::array<float> scdContainer = registry->getComponents<float>(); | ||
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<System::Collison>(registry)); | ||
manager.addSystem(std::make_unique<System::Movement>(registry)); | ||
|
||
while (1) { | ||
manager.updateSystems(); | ||
sleep(1); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
** ASystem.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** 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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
** ASystem.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** 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; | ||
|
||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
** Collison.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** Started on Wed Sep 20 9:36:31 AM 2023 brice | ||
** Last update Thu Sep 20 12:03:08 PM 2023 brice | ||
*/ | ||
|
||
#include <iostream> | ||
#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<int> arrInt = _registry->getComponents<int>(); | ||
|
||
for (auto begin = arrInt->begin(); begin != arrInt->end(); begin++) { | ||
*begin += 1; | ||
} | ||
std::cout << "------------------------------------" << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
** Collison.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/system | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** 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: | ||
}; | ||
} |
Oops, something went wrong.