Skip to content

Commit e0517d3

Browse files
authored
Merge pull request #48 from YGNI-RType/dev
Release v0.2.0
2 parents 04d4e96 + 0646d0b commit e0517d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2474
-582
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ Temporary Items
128128
### VisualStudioCode ###
129129
.vscode/*
130130
# !.vscode/settings.json
131-
!.vscode/tasks.json
132-
!.vscode/launch.json
131+
# !.vscode/tasks.json
132+
# !.vscode/launch.json
133133
!.vscode/extensions.json
134134
!.vscode/*.code-snippets
135135

include/GEngine/BaseEngine.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ class BaseEngine {
2727

2828
void start(void);
2929

30-
const world_t &getWorld(void) {
31-
return m_ecs.getComponentMap();
32-
} // TODO keep ?
30+
const world_t &getWorld(void);
3331

3432
template <typename Type>
35-
void subscribeCallback(std::function<void(Type &)> callback) {
36-
m_ecs.subscribeCallback(callback);
37-
}
33+
void subscribeCallback(std::function<void(Type &)> callback);
3834

3935
template <typename T>
40-
void publishEvent(T &e) {
41-
m_ecs.publishEvent<T>(e);
42-
}
36+
void publishEvent(T &e);
37+
38+
void setFirstEntity(ecs::entity::Entity start);
4339

4440
private:
4541
ecs::ECS m_ecs;

include/GEngine/BaseEngine.inl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ template <typename T>
1717
inline void BaseEngine::registerComponent(void) {
1818
m_ecs.registerComponent<T>();
1919
}
20+
21+
template <typename Type>
22+
void BaseEngine::subscribeCallback(std::function<void(Type &)> callback) {
23+
m_ecs.subscribeCallback(callback);
24+
}
25+
26+
template <typename T>
27+
void BaseEngine::publishEvent(T &e) {
28+
m_ecs.publishEvent<T>(e);
29+
}
2030
} // namespace gengine

include/GEngine/GEngine.hpp

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/*
2+
** EPITECH PROJECT, 2024
3+
** GameEngine
4+
** File description:
5+
** GEngine.hpp
6+
*/
7+
8+
#pragma once
9+
10+
#include "GEngine/BaseEngine.hpp"
11+
#include "GEngine/driver/Engine.hpp"
12+
#include "GEngine/game/Engine.hpp"
13+
#include "GEngine/libdev/Component.hpp"
14+
#include <memory>
15+
#include <mutex>
16+
#include <utility> // For std::forward
17+
#include <vector>
18+
19+
#include "GEngine/libdev/System.hpp"
20+
21+
/**
22+
* @brief Registry class for managing components and systems registration.
23+
*/
24+
struct Registry {
25+
/**
26+
* @brief Constructor for the Registry class.
27+
*
28+
* @param engines A vector of reference wrappers to engines for component and system registration.
29+
*/
30+
Registry(gengine::BaseEngine &local, gengine::BaseEngine &remote)
31+
: m_local(local)
32+
, m_remote(remote) {
33+
}
34+
35+
/**
36+
* @brief Register a component type with the engines.
37+
*
38+
* This method iterates through the engines and registers the specified component type.
39+
*
40+
* @tparam ComponentType The type of component to register.
41+
*/
42+
template <typename ComponentType>
43+
void registerComponent(void) {
44+
m_local.registerComponent<ComponentType>();
45+
m_remote.registerComponent<ComponentType>();
46+
}
47+
48+
/**
49+
* @brief Register a system type with the engines.
50+
*
51+
* This method iterates through the engines and registers the specified system type
52+
* with the provided parameters.
53+
*
54+
* @tparam SystemType The type of system to register.
55+
* @tparam Args Variadic template parameters for system construction arguments.
56+
* @param params Parameters for constructing the system.
57+
*/
58+
template <typename SystemType, class... Args>
59+
void registerSystem(Args &&...params) {
60+
if constexpr (!std::is_base_of<gengine::LocalSystem, SystemType>::value)
61+
m_remote.registerSystem<SystemType>(std::forward<Args>(params)...);
62+
if constexpr (!std::is_base_of<gengine::RemoteSystem, SystemType>::value)
63+
m_local.registerSystem<SystemType>(std::forward<Args>(params)...);
64+
}
65+
66+
private:
67+
gengine::BaseEngine &m_local;
68+
gengine::BaseEngine &m_remote;
69+
};
70+
71+
extern "C" {
72+
/**
73+
* @brief Declare game components and systems for the engine.
74+
*
75+
* This function declares all game components and systems needed for the engine.
76+
* It is intended to be called during the initialization of the GEngine instance.
77+
*
78+
* @param r Pointer to the Registry instance for registering components and systems.
79+
*/
80+
void GEngineDeclareComponents(Registry *r);
81+
82+
/**
83+
* @brief Declare driver components and systems for the engine.
84+
*
85+
* This function declares all driver components and systems needed for the engine.
86+
* It is intended to be called during the initialization of the GEngine instance.
87+
*
88+
* @param r Pointer to the Registry instance for registering components and systems.
89+
*/
90+
void GEngineDeclareSystems(Registry *r);
91+
92+
/**
93+
* @brief Declare shared components and events for the engine.
94+
*
95+
* This function declares shared components and events that can be used across different systems in the engine.
96+
* It is intended to be called during the initialization of the GEngine instance.
97+
*
98+
* @param r Pointer to the Registry instance for registering components and systems.
99+
*/
100+
void GEngineDeclareEvents(Registry *r);
101+
}
102+
103+
/**
104+
* @brief Main class for the Game Engine singleton.
105+
*
106+
* This class manages the initialization and access to the game engine components and systems.
107+
* It ensures that the engine is instantiated only once and provides methods to access its features.
108+
*/
109+
class GEngine {
110+
public:
111+
/**
112+
* @brief Initialize the GEngine singleton instance.
113+
*
114+
* This function ensures that the GEngine instance is initialized only once using a thread-safe mechanism.
115+
* It also registers the necessary game engine elements by calling the registerElements method.
116+
*/
117+
static void init(void) {
118+
std::call_once(initFlag, []() {
119+
instance.reset(new GEngine());
120+
instance->registerElements();
121+
});
122+
}
123+
124+
/**
125+
* @brief Get the singleton instance of GEngine.
126+
*
127+
* This method returns a reference to the GEngine instance. If the instance is not yet created,
128+
* it calls the init method to create it.
129+
*
130+
* @return Reference to the GEngine instance.
131+
*/
132+
static GEngine &getInstance(void) {
133+
if (!instance)
134+
init();
135+
return *instance;
136+
}
137+
138+
/**
139+
* @brief Get the pointer to the singleton instance of GEngine.
140+
*
141+
* This method returns a pointer to the GEngine instance. If the instance is not yet created,
142+
* it calls the init method to create it.
143+
*
144+
* @return Pointer to the GEngine instance.
145+
*/
146+
static GEngine *getInstancePointer(void) {
147+
if (!instance)
148+
init();
149+
return instance.get();
150+
}
151+
152+
/**
153+
* @brief Destructor.
154+
*
155+
* This destructor is private to prevent deletion of the singleton instance through
156+
* deletion of pointers to GEngine.
157+
*/
158+
~GEngine() = default;
159+
160+
static gengine::BaseEngine &getLocal(void) {
161+
if (!instance)
162+
init();
163+
return instance->m_local;
164+
}
165+
166+
static gengine::BaseEngine &getRemote(void) {
167+
if (!instance)
168+
init();
169+
return instance->m_remote;
170+
}
171+
172+
private:
173+
/**
174+
* @brief Private constructor to prevent direct instantiation.
175+
*
176+
* This constructor is private to enforce the singleton pattern, preventing the creation
177+
* of multiple instances of GEngine.
178+
*/
179+
GEngine() = default;
180+
181+
/**
182+
* @brief Register all game engine components and systems.
183+
*
184+
* This function calls the necessary functions to declare the various components and systems of the game engine.
185+
* It ensures that all necessary elements are properly registered during initialization.
186+
*/
187+
static void registerElements(void) {
188+
if (!instance)
189+
init();
190+
191+
auto sharedRegistry = std::make_unique<Registry>(instance->m_local, instance->m_remote);
192+
193+
GEngineDeclareComponents(sharedRegistry.get());
194+
GEngineDeclareSystems(sharedRegistry.get());
195+
GEngineDeclareEvents(sharedRegistry.get());
196+
}
197+
198+
// Delete copy constructor and assignment operator to enforce singleton pattern
199+
GEngine(const GEngine &) = delete;
200+
GEngine &operator=(const GEngine &) = delete;
201+
202+
// Singleton instance and initialization flag
203+
static std::unique_ptr<GEngine> instance;
204+
static std::once_flag initFlag;
205+
206+
gengine::BaseEngine m_local; ///< Instance of the game engine.
207+
gengine::BaseEngine m_remote; ///< Instance of the driver engine.
208+
};
209+
210+
// Initialize static members
211+
// std::unique_ptr<GEngine> GEngine::instance = nullptr;
212+
// std::once_flag GEngine::initFlag;

include/GEngine/GEngine.inl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
** EPITECH PROJECT, 2024
3+
** GameEngine
4+
** File description:
5+
** GEngine.inl
6+
*/
7+
8+
#include "GEngine.hpp"
9+
10+
// Registry::Registry(std::vector<std::reference_wrapper<gengine::BaseEngine>> &engines)
11+
// : m_engines(engines) {}
12+
13+
// template <typename ComponentType>
14+
// void Registry::registerComponent(void) {
15+
// for (gengine::BaseEngine &engine : m_engines)
16+
// engine.registerComponent<ComponentType>();
17+
// }
18+
19+
// template <typename SystemType, class ...Args>
20+
// void Registry::registerSystem(Args &&...params) {
21+
// for (gengine::BaseEngine &engine : m_engines)
22+
// engine.registerSystem<SystemType>(std::forward<Args>(params)...);
23+
// }

include/GEngine/interface/components/RemoteDriver.hpp renamed to include/GEngine/interface/components/RemoteLocal.hpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
** EPITECH PROJECT, 2024
33
** GameEngine
44
** File description:
5-
** RemoteDriver.hpp
5+
** RemoteLocal.hpp
66
*/
77

88
#pragma once
@@ -14,41 +14,52 @@
1414

1515
namespace gengine::interface::component {
1616

17-
class RemoteDriver : public gengine::Component<RemoteDriver> {
17+
class RemoteLocal : public gengine::Component<RemoteLocal> {
1818
public:
1919
// Constructor - Generates a new UUID upon object creation
20-
RemoteDriver();
20+
RemoteLocal();
21+
22+
RemoteLocal(const uuids::uuid &uuid);
2123

2224
// Copy constructor
23-
RemoteDriver(const RemoteDriver &other);
25+
RemoteLocal(const RemoteLocal &other);
2426

2527
// Assignment operator
26-
RemoteDriver &operator=(const RemoteDriver &other);
28+
RemoteLocal &operator=(const RemoteLocal &other);
2729

2830
// Overloading the == operator to compare based on UUID
29-
bool operator==(const RemoteDriver &other) const;
31+
bool operator==(const RemoteLocal &other) const;
3032

3133
// Getter for the UUID as a string (hexadecimal format)
3234
std::string getUUIDString() const;
3335

3436
// Getter for the raw UUID bytes (for network transmission)
3537
const uuids::uuid &getUUIDBytes() const;
3638

37-
bool operator<(const RemoteDriver &other) const {
39+
bool operator<(const RemoteLocal &other) const {
3840
return false;
3941
}
4042

43+
static void generateUUID(uuids::uuid &toGenerate);
44+
45+
void setWhoIAm(const uuids::uuid &toSet) {
46+
m_whoIAm = toSet;
47+
}
48+
49+
uuids::uuid getWhoIAm(void) const {
50+
return m_whoIAm;
51+
}
52+
4153
private:
4254
uuids::uuid m_uuid;
43-
44-
void generateUUID();
55+
uuids::uuid m_whoIAm;
4556
};
4657
} // namespace gengine::interface::component
4758

4859
namespace std {
4960
template <>
50-
struct hash<gengine::interface::component::RemoteDriver> {
51-
std::size_t operator()(const gengine::interface::component::RemoteDriver &driver) const {
61+
struct hash<gengine::interface::component::RemoteLocal> {
62+
std::size_t operator()(const gengine::interface::component::RemoteLocal &driver) const {
5263
const uuids::uuid &uuid = driver.getUUIDBytes();
5364
std::size_t hash_value = 0;
5465
auto bytes = uuid.as_bytes();

include/GEngine/interface/events/RemoteDriver.hpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)