-
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.
MINOR
- Loading branch information
Showing
18 changed files
with
555 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.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 | ||
$<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,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 |
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.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 | ||
) |
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,48 @@ | ||
/* | ||
** Registry.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/poc/src | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** Started on Wed Sep 20 4:21:18 PM 2023 brice | ||
** Last update Wed Sep 20 4:21:18 PM 2023 brice | ||
*/ | ||
|
||
#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,43 @@ | ||
/* | ||
** SparseArray.hpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/poc/src | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** Started on Wed Sep 20 4:21:15 PM 2023 brice | ||
** Last update Wed Sep 20 4:21:15 PM 2023 brice | ||
*/ | ||
|
||
#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,43 @@ | ||
/* | ||
** main.cpp for R-Bus in /home/kitetsu/Epitech/R-Bus/src/poc/src | ||
** | ||
** Made by brice | ||
** Login <[email protected]> | ||
** | ||
** Started on Wed Sep 20 4:21:09 PM 2023 brice | ||
** Last update Wed Sep 20 4:21:09 PM 2023 brice | ||
*/ | ||
|
||
#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; | ||
} | ||
} |
Oops, something went wrong.