Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Add first version of poc #2

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .gitignore
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/
47 changes: 47 additions & 0 deletions src/poc/CMakeLists.txt
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()
16 changes: 16 additions & 0 deletions src/poc/src/CMakeLists.txt
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
)
45 changes: 45 additions & 0 deletions src/poc/src/Registry.hpp
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;
};
40 changes: 40 additions & 0 deletions src/poc/src/SparseArray.hpp
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;
};
40 changes: 40 additions & 0 deletions src/poc/src/main.cpp
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();
Saverio976 marked this conversation as resolved.
Show resolved Hide resolved
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;
}
25 changes: 25 additions & 0 deletions src/poc/src/system/ASystem.cpp
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
}
}
29 changes: 29 additions & 0 deletions src/poc/src/system/ASystem.hpp
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);
Saverio976 marked this conversation as resolved.
Show resolved Hide resolved
~ASystem() = default;

protected:
Registry *_registry;
Saverio976 marked this conversation as resolved.
Show resolved Hide resolved
private:
void clientRun() final;


};
}
18 changes: 18 additions & 0 deletions src/poc/src/system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.27)
Saverio976 marked this conversation as resolved.
Show resolved Hide resolved

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)
32 changes: 32 additions & 0 deletions src/poc/src/system/Collison.cpp
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;
}
}
24 changes: 24 additions & 0 deletions src/poc/src/system/Collison.hpp
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:
};
}
Loading