diff --git a/README.md b/README.md index e69de29..6f7b827 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,85 @@ +# ECS Documentation + +## Table of Contents + +- [Introduction](#introduction) +- [Creating a Plugin](#creating-a-plugin) + - [Defining IPlugin](#defining-iplugin) + - [Implementing IPlugin](#implementing-iplugin) + - [Adding a Plugin via PluginHandler](#adding-a-plugin-via-pluginhandler) +- [Using exemple](#using-exemple) + +## Introduction + +This ECS (Entity Component System) is designed as a robust framework for building complex simulations and games. It uses a registry system implemented as a singleton that contains sparse arrays with dense data storage, ensuring efficient and fast component access patterns. + +Alongside the core ECS features, this system is equipped with a JSON parsing overlay, facilitating easy data manipulation and storage in a structured format. A SceneManager is present to manage different scenes or states within the application, providing seamless transitions and organized state handling. + +The ECS also includes a logger utility, which developers can use to track events, errors, and other significant occurrences throughout the application lifecycle, aiding in debugging and monitoring. + +Lastly, a clock manager is integrated into the system to handle timing, allowing for consistent updates across different systems, essential for synchronization in simulations and real-time applications. + +## Creating a Plugin + +Developers can extend the functionality of the ECS by creating plugins. A plugin is a concrete implementation of the `IPlugin` interface, which initializes specific systems and adds them to the global system management. + +### Defining IPlugin + +The `IPlugin` interface is defined as follows: + +```cpp +class IPlugin { +public: + virtual ~IPlugin() = default; + virtual void initPlugin() = 0; + virtual std::vector> getSystems() = 0; +}; +``` + +### Implementing IPlugin + +To create a new plugin, one should inherit from `IPlugin` and implement the `initPlugin` and `getSystems` methods. Here is an example implementation: + +```cpp +#include +#include + +class ExamplePlugin : public IPlugin { +public: + void initPlugin() override { + // Specific initialization for this plugin + } + + std::vector> getSystems() override { + // Return the list of systems as functions + return { + fstSystem, + scdSystem + }; + } +}; +``` + +### Adding a Plugin via PluginHandler + +Once the plugin is implemented, it can be added to the ECS using the `PluginHandler` class. Here's how you might add your plugin: + +```cpp +#include "PluginHandler.h" +#include "ExamplePlugin.h" + +int main() { + ExamplePlugin myPlugin; + + enum SystemManagers { MENU, GAME, PLUGIN}; + PluginHandler::addNewPlugin(myPlugin, static_cast(SystemManagers::PLUGIN)); + + // Proceed with the rest of the program +} +``` + +Using `addNewPlugin`, the plugin is initialized and the systems it provides are added to the appropriate system manager. If a `managerId` is provided, the system will be added to a specific system manager. + +## Using exemple + +This is a game using this ecs: https://github.com/X-R-G-B/R-dash diff --git a/libs/B-luga-graphics/README.md b/libs/B-luga-graphics/README.md index b7f5831..2b7d716 100644 --- a/libs/B-luga-graphics/README.md +++ b/libs/B-luga-graphics/README.md @@ -1,27 +1,38 @@ # B-luga-graphics -## Requirements +*Plugin for b-luga ECS that add integration with Raylib graphic library* -### Raylib +## Hightlight -You need to link the final executable with the raylib library. -And provide the include directory in the cmake file. +- Sprite, Text, Music, Sound +- Easy to use +- Some components can be created with json -You can do it like this: -```cmake -cmake_minimum_required(VERSION 3.20) +## Install +```cmake include(FetchContent) +FetchContent_Declare( + b-luga-graphics + URL "https://github.com/X-R-G-B/B-luga/releases/latest/download/b-luga-graphics.tar" + DOWNLOAD_EXTRACT_TIMESTAMP TRUE +) + FetchContent_Declare( raylib CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_CONFIGURATION_TYPES=\"Release;Release\"" "-DCONFIG=Release" - URL "https://github.com/X-R-G-B/R-Bus/releases/latest/download/raylib.tar" - DOWNLOAD_NO_PROGRESS FALSE + URL "https://github.com/X-R-G-B/B-luga/releases/latest/download/raylib.tar" DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) -FetchContent_MakeAvailable(raylib) +FetchContent_MakeAvailable(b-luga-graphics raylib) + +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + b-luga-graphics +) target_link_libraries( ${PROJECT_NAME} @@ -30,4 +41,23 @@ target_link_libraries( ) ``` -If you have stange linkage problem, try to incerse order of target_link_libraries between raylib and B-luga-graphics. +This will dowload the latest version of b-luga-graphics, and link it + add headers to the project with cmake + +## Documentation + +# Game Resource Creation and Management Plugin Documentation + +This plugin is an integrated tool for the creation and management of sprites, music, sounds, and text in video game projects. It also includes systems for displaying and playing these resources, as well as an encapsulation of the `raylib` C library, which is a simple and easy-to-use library for learning video game development and multimedia programming. + +## Features + +- **Sprite Creation**: Simplifies the importing and manipulation of sprites for games. +- **Music Management**: Allows loading and controlling music tracks. +- **Sound Effects**: Manages the import and playback of various sound effects. +- **Text Management**: Provides tools for integrating and manipulating on-screen text. +- **Display and Playback**: Includes dedicated systems for sprite display and sound and music playback. +- **`raylib` Encapsulation**: Integrates `raylib` library to streamline development. + +## Dependencies + +This plugin requires the installation of the `raylib` library to function. You can obtain it here: [raylib GitHub](https://github.com/raysan5/raylib). diff --git a/libs/B-luga-physics/README.md b/libs/B-luga-physics/README.md index e69de29..beb71c1 100644 --- a/libs/B-luga-physics/README.md +++ b/libs/B-luga-physics/README.md @@ -0,0 +1,48 @@ +# B-luga-physics + +*Plugin for b-luga ECS that add some physics and life* + +## Hightlight + +- Damage/Death systems +- Collision systems +- Basic and advanced Movements +- Some components can be created with json + +## Install + +```cmake +include(FetchContent) + +FetchContent_Declare( + b-luga-physics + URL "https://github.com/X-R-G-B/B-luga/releases/latest/download/b-luga-physics.tar" + DOWNLOAD_EXTRACT_TIMESTAMP TRUE +) + +FetchContent_MakeAvailable(b-luga-physics) + +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + b-luga-physics +) +``` + +This will dowload the latest version of b-luga-physics, and link it + add headers to the project with cmake + +## Documentation + +# ECS Physics Plugin Documentation + +This ECS (Entity-Component-System) physics plugin is designed to integrate seamlessly with your game engine to provide comprehensive physics management. This includes collision detection, damage handling, death states, and a variety of movement physics such as basic linear movement, zigzag patterns, and bouncing. + +## Features + +- **Collision Management**: Efficiently manages collisions between entities in the game world. +- **Damage System**: Automates the process of applying damage to entities upon collisions or other triggers. +- **Death Handling**: Provides a system for handling the destruction or deactivation of entities after reaching a death state. +- **Movement Physics**: + - **Basic**: Enables entities to move in straight paths. + - **ZigZag**: Allows entities to move in a predefined or random zigzag pattern. + - **Bounce**: Implements bounce physics upon collisions with other entities or world boundaries. diff --git a/libs/B-luga/Documentation/Clock.md b/libs/B-luga/Documentation/Clock.md new file mode 100644 index 0000000..b45cd8d --- /dev/null +++ b/libs/B-luga/Documentation/Clock.md @@ -0,0 +1,74 @@ +# Clock Class Documentation + +The `Clock` class is a utility for managing multiple high-resolution timers within an application. Each timer can be individually started, measured, and manipulated in terms of its elapsed time. + +## Public Methods + +### `Clock()` + +- **Description:** Constructor that initializes the `Clock` instance. + +### `std::size_t create(bool deferStart = false)` + +- **Description:** Creates a new timer. This timer is added to a collection of timers and can be referenced using the returned index value. +- **Parameters:** + - `deferStart`: A boolean indicating whether to start the timer immediately upon creation. If `true`, the timer starts in a deferred state. +- **Returns:** A `std::size_t` that serves as an identifier for the newly created timer. + +### `std::size_t elapsedMillisecondsSince(std::size_t id)` + +- **Description:** Calculates the elapsed time in milliseconds since the specified timer was started. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer whose elapsed time is to be calculated. +- **Returns:** The elapsed time in milliseconds as a `std::size_t`. Returns -1 if the timer has not been started. + +### `std::size_t elapsedSecondsSince(std::size_t id)` + +- **Description:** Calculates the elapsed time in seconds since the specified timer was started. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer whose elapsed time is to be calculated. +- **Returns:** The elapsed time in seconds as a `std::size_t`. Returns -1 if the timer has not been started. + +### `std::size_t elapsedNanosecondsSince(std::size_t id)` + +- **Description:** Calculates the elapsed time in nanoseconds since the specified timer was started. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer whose elapsed time is to be calculated. +- **Returns:** The elapsed time in nanoseconds as a `std::size_t`. Returns -1 if the timer has not been started. + +### `void decreaseSeconds(std::size_t id, std::size_t seconds)` + +- **Description:** Decreases the elapsed time of the specified timer by a given number of seconds. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer to be manipulated. + - `seconds`: The number of seconds to subtract from the timer's current elapsed time. + +### `void decreaseMilliseconds(std::size_t id, std::size_t milliseconds)` + +- **Description:** Decreases the elapsed time of the specified timer by a given number of milliseconds. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer to be manipulated. + - `milliseconds`: The number of milliseconds to subtract from the timer's current elapsed time. + +### `void decreaseNanoseconds(std::size_t id, std::size_t nanoseconds)` + +- **Description:** Decreases the elapsed time of the specified timer by a given number of nanoseconds. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer to be manipulated. + - `nanoseconds`: The number of nanoseconds to subtract from the timer's current elapsed time. + +### `void restart(std::size_t id)` + +- **Description:** Restarts the specified timer. The elapsed time is reset to the current time. +- **Parameters:** + - `id`: A `std::size_t` identifier for the timer to be restarted. + +## Private Members + +### `std::vector> _clocks` + +- **Description:** A collection of optional time points representing the start times of the timers. An `std::nullopt` value indicates a timer that has been created but not started or has been invalidated. + +--- + +This documentation provides a comprehensive guide to the methods available in the `Clock` class for creating and managing timers. It is important to manage the indices returned by the `create` method as they are needed to reference the specific timers for all subsequent operations. \ No newline at end of file diff --git a/libs/B-luga/Documentation/Json.md b/libs/B-luga/Documentation/Json.md new file mode 100644 index 0000000..15adff3 --- /dev/null +++ b/libs/B-luga/Documentation/Json.md @@ -0,0 +1,135 @@ +# Json Class Documentation + +## Overview +The `Json` class is a singleton class designed to manage JSON data from various files. It provides methods to register JSON files, retrieve data based on keys and IDs, and manipulate JSON objects. + +## Singleton Design Pattern +The `Json` class is implemented as a singleton, ensuring that only one instance of the class is created and accessible throughout the application. + +### getInstance +```cpp +static Json &getInstance() +``` +Returns a reference to the singleton `Json` instance. + +## JSON File Registration +### registerJsonFile +```cpp +void registerJsonFile(const std::string &path) +``` +Loads and registers a JSON file given its file path. + +## JSON Retrieval Methods +### getJsonObjectById +```cpp +template +nlohmann::json getJsonObjectById(const std::string &type, const T &id, const std::string &arrayName) +``` +Retrieves a JSON object from an array within the registered JSON data based on its `id`. + +### getDataByJsonType +There are several overloads of this method to retrieve JSON data based on the type: + +- For retrieving a JSON object given a data type and an index: +```cpp +template +T getDataByJsonType(const std::string &dataType, const std::string &index) +``` +- For retrieving a JSON object given just a data type: +```cpp +nlohmann::json getDataByJsonType(const std::string &dataType) +``` + +### findKeyRecursively +```cpp +void findKeyRecursively( + const nlohmann::json &data, + const std::string &key, + std::vector &results) +``` +Searches for a key recursively in the given JSON data and stores the results in a vector. + +### getDatasByKey +```cpp +std::vector getDatasByKey(std::vector dataTypes, const std::string &key) +``` +Retrieves all data associated with a specific key across different data types. + +### getDatasFromList +There are multiple methods to extract data from a list, given different parameters: +- With a list and an index: +```cpp +std::vector getDatasFromList(const nlohmann::json &list, const std::string &index) +``` +- With a list only: +```cpp +std::vector getDatasFromList(const nlohmann::json &list) +``` + +## Data Validation Method +### isDataExist +```cpp +static bool isDataExist(nlohmann::basic_json<> jsonData, const std::string &index) +``` +Checks if a given key exists in the JSON data. + +## Advanced Data Retrieval Methods +### getDatasByJsonType +```cpp +std::vector +getDatasByJsonType(const std::string &dataType, const std::vector &indexes) +``` +Retrieves a vector of JSON objects based on a data type and a sequence of indexes. + +### getDataFromJson +```cpp +template +T getDataFromJson(nlohmann::json jsonData, const std::string &index) +``` +Retrieves data of a specified type from a JSON object given a key. + +### getObjectsIdInArray +```cpp +template +std::vector getObjectsIdInArray(const std::string &dataType, const std::string &arrayName) +``` +Retrieves a vector of IDs from an array of JSON objects. + +### getDataByVector +Retrieves data by navigating through a series of indexes in nested JSON objects. +- For getting JSON data: +```cpp +nlohmann::json getDataByVector(const std::string &dataType, const std::vector &indexes) +``` +- Template version for different data types: +```cpp +template +T getDataByVector(const std::string &dataType, const std::vector &indexes) +``` + +## Private Methods +### Constructor and Destructor +The constructor and destructor are private to control the instantiation of the singleton class. + +### getDatasFromList (Overloaded Private Method) +```cpp +std::vector & +getDatasFromList(std::vector &datas, nlohmann::json &listData, const std::string &key) +``` +Aids in data extraction from a list for internal processing. + +### loadJsonData +```cpp +static nlohmann::json loadJsonData(const std::string &path) +``` +Loads JSON data from a file. + +## Data Members +### _jsonDatas +```cpp +std::unordered_map _jsonDatas; +``` +Stores JSON data associated with their resolved file paths. + +## Dependencies +- `nlohmann::json`: \ No newline at end of file diff --git a/libs/B-luga/Documentation/Registry.md b/libs/B-luga/Documentation/Registry.md new file mode 100644 index 0000000..59edce6 --- /dev/null +++ b/libs/B-luga/Documentation/Registry.md @@ -0,0 +1,171 @@ +# Registry Class + +The `Registry` class serves as a centralized storage and management system for all entities and their components in an ECS (Entity Component System). This class also manages layers for rendering order and allows for event callbacks tied to specific game events. + +## Enumerations + +### LayerType + +Defines the type of layers available for entities. + +- `BACKLAYER` +- `FRONTLAYER` +- `DEFAULTLAYER` + +### BackLayers + +Defines the ordering of back layers. + +- `BACK = 0` +- `BACKMAX` + +### FrontLayers + +Defines the ordering of front layers. + +- `FRONT = 0` +- `FRONTMAX` + +### Events + +Defines various events that can trigger callbacks. + +- `REMOVE_ENTITY` +- `TAKE_DAMAGE` +- `CLEAR` +- `ENTITY_DEATH` +- `START_LOOP` +- `END_LOOP` +- `BEFORE_LOOP` +- `AFTER_LOOP` + +## Member Functions + +### `static Registry &getInstance()` + +Singleton access to the Registry instance. + +### `template components getComponents()` + +Gets a reference to the sparse array holding components of the type specified by the template parameter. + +### `std::size_t addEntity()` + +Adds an entity to the registry and returns its ID. + +### `void removeEntity(std::size_t id)` + +Removes an entity and its components from the registry using the provided ID. + +### `void removeEntitiesToRemove()` + +Removes all entities that have been marked for removal. + +### `void addToRemove(std::size_t id)` + +Marks an entity to be removed later. + +### `void clear()` + +Clears all entities, components, and internal data structures. + +### `std::vector getEntitiesByComponents(std::vector types)` + +Returns a list of entities that have all the components of the provided types. + +### `std::vector getEntitiesWithOneOfComponents(std::vector types)` + +Returns a list of entities that have at least one of the components of the provided types. + +### `void setToBackLayers(std::size_t id, BackLayers layer)` + +Assigns an entity to a specified back layer. + +### `void setToDefaultLayer(std::size_t id)` + +Assigns an entity to the default layer. + +### `void setToFrontLayers(std::size_t id, FrontLayers layer)` + +Assigns an entity to a specified front layer. + +### `std::vector> getBackLayers()` + +Returns all back layers. + +### `std::vector getDefaultLayer()` + +Returns the default layer. + +### `std::vector> getFrontLayers()` + +Returns all front layers. + +### `void addAllie(std::size_t typeId, std::type_index type)` + +Adds an ally type to the specified entity type ID. + +### `void clearAllies(std::size_t typeId)` + +Clears allies for the specified entity type ID. + +### `void clearAllies()` + +Clears all ally relationships. + +### `bool checkAllies(std::size_t fstId, std::size_t scdId)` + +Checks if two entities are allies based on their components. + +### `void addEventCallback(Events event, std::function callback)` + +Adds a callback function for the specified event. + +### `void callback(Events event, std::size_t id)` + +Triggers event callbacks for a specific entity. + +### `void callback(Events event)` + +Triggers event callbacks without an entity context. + +### `Clock &getClock()` + +Returns a reference to the clock instance. + +## Private Member Functions + +### `void initLayers(bool back)` + +Initializes the layer data structures. + +### `void removeFromDefaultLayer(std::size_t id)` + +Removes an entity from the default layer. + +### `std::vector getExistings(std::type_index type)` + +Gets a list of existing entities with a component of the specified type. + +### `template void checkAddSparseArray()` + +Ensures that a sparse array exists for the specified component type. + +### `template void addComponentPlace()` + +Adds a place for a new component of the specified type. + +### `template void removeComponent(std::size_t id)` + +Removes the component of the specified type associated with an entity ID. + +### `template std::vector getExistingsId()` + +Returns existing entity IDs for the specified component type. + +## Private Member Variables + +- `_clock`: An instance of a `Clock` class to track time. +- `_entitiesNb`: The number of entities in the registry. +- `_backLayers`: A list of back layers. +- `_defaultLayer`: The default layer for entities. diff --git a/libs/B-luga/Documentation/SceneManager.md b/libs/B-luga/Documentation/SceneManager.md new file mode 100644 index 0000000..603e1f5 --- /dev/null +++ b/libs/B-luga/Documentation/SceneManager.md @@ -0,0 +1,93 @@ +# SceneManager Documentation + +## Overview + +The SceneManager is a central part of the ECS framework, responsible for managing different scenes within the application. Each scene represents a state or a level of the game/application, encapsulating specific entities, components, and systems. + +## Implementation Details + +```cpp +namespace Scene { + + enum class ReturnValue { OK = 0, RET_ERROR = 84 }; + + class SceneManager { + public: + // Singleton instance retrieval + static SceneManager &getInstance() + + // Main run loop + int run() + + // Scene change handler + void changeScene(std::size_t scene) + + // Getter for the current scene + [[nodiscard]] std::size_t getCurrentScene() const + + // Stops the run loop + void stop() + + // Sets up multiple scenes + void setScenes(std::vector> scenes) + + // Adds a single scene + void addScene(std::vector scene) + + private: + // Constructor + SceneManager() : _currentScene(0), _stop(false) {}; + + // Updates systems for the current scene + void updateSystemManagers(std::vector &scene) + + // Scene management variables + std::size_t _currentScene; + bool _stop; + std::vector> _scenes; + }; +} // namespace Scene +``` + +## Usage + +### Singleton Instance + +The SceneManager is implemented as a singleton, ensuring that there is only one instance of it throughout the application. You can access the instance using: + +```cpp +auto& sceneManager = Scene::SceneManager::getInstance(); +``` + +### Running the Scene Manager + +To run the scene manager, you simply call the `run` method: + +```cpp +int main() { + auto& sceneManager = Scene::SceneManager::getInstance(); + return sceneManager.run(); +} +``` + +### Set and Change Scenes + +See in ./Systems.md + +### Stopping the Scene Manager + +When you need to stop the scene manager, perhaps when the game is exiting or transitioning to a different state, use the `stop` method: + +```cpp +sceneManager.stop(); +``` + +### Retrieving the Current Scene + +To get the index of the current scene: + +```cpp +auto currentSceneIndex = sceneManager.getCurrentScene(); +``` + +The SceneManager serves as a powerful tool for managing the different phases or levels of your application, ensuring smooth transitions and efficient state management. \ No newline at end of file diff --git a/libs/B-luga/Documentation/SparseArray.md b/libs/B-luga/Documentation/SparseArray.md new file mode 100644 index 0000000..05ee068 --- /dev/null +++ b/libs/B-luga/Documentation/SparseArray.md @@ -0,0 +1,133 @@ +# SparseArray Class Documentation + +## Overview + +`SparseArray` is a template class that provides a data structure for efficient storage and retrieval of sparse data. This is particularly useful when there is a need to store elements at large indexes without allocating memory for unused indexes. It internally manages a dense array for the actual data and a sparse array to keep track of the occupied indices. + +## Template Parameter + +- `Component`: The type of elements stored in the `SparseArray`. + +## Public Methods + +### `void add()` + +Adds a placeholder for a new component to the sparse array, expanding its size. + +### `void insertBack(Component &value)` + +Inserts a new component at the back of the sparse array. + +#### Parameters + +- `value`: Reference to the component to be inserted. + +### `void insert(size_t id, Component &value)` + +Inserts a component at the specified ID in the sparse array. + +#### Parameters + +- `id`: The ID where the component should be inserted. +- `value`: Reference to the component to be inserted. + +### `void erase(std::size_t id)` + +Erases the component associated with the specified ID from the sparse array. + +#### Parameters + +- `id`: The ID of the component to be erased. + +### `Component &operator[](size_t id)` + +Provides access to the component by ID. + +#### Parameters + +- `id`: The ID of the component to access. + +#### Returns + +- A reference to the component at the given ID. + +### `Component &back()` + +Returns the last component in the dense array. + +#### Returns + +- A reference to the last component. + +### `typename std::vector::iterator begin()` + +Returns an iterator pointing to the beginning of the dense array. + +#### Returns + +- An iterator to the beginning of the dense array. + +### `typename std::vector::iterator end()` + +Returns an iterator pointing to the end of the dense array. + +#### Returns + +- An iterator to the end of the dense array. + +### `bool exist(std::size_t id)` + +Checks if a component exists at the specified ID. + +#### Parameters + +- `id`: The ID to check for a component's existence. + +#### Returns + +- `true` if a component exists at the ID, `false` otherwise. + +### `std::vector getExistingsId()` + +Gets a vector of all existing IDs in the sparse array. + +#### Returns + +- A vector of existing IDs. + +### `void clear()` + +Clears the sparse array, removing all components. + +## Private Methods + +Details of private methods are generally not included in public documentation, as they are meant for internal use only. + +## Example Usage + +```cpp +SparseArray mySparseArray; + +// Add a new element and insert at back +mySparseArray.add(); +int myValue = 10; +mySparseArray.insertBack(myValue); + +// Insert element at specific ID +int anotherValue = 20; +mySparseArray.insert(5, anotherValue); + +// Access element by ID +int value = mySparseArray[5]; + +// Erase element at ID +mySparseArray.erase(5); + +// Check if an ID exists +bool exists = mySparseArray.exist(10); + +// Get the last element +int lastValue = mySparseArray.back(); + +// Clear the array +mySparseArray.clear(); \ No newline at end of file diff --git a/libs/B-luga/Documentation/Systems.md b/libs/B-luga/Documentation/Systems.md new file mode 100644 index 0000000..cf176c2 --- /dev/null +++ b/libs/B-luga/Documentation/Systems.md @@ -0,0 +1,81 @@ +# SystemManagersDirector + +## SystemManagersDirector Overview + +`SystemManagersDirector` is a central hub for managing various `SystemManager` instances within the ECS framework. Each `SystemManager` is responsible for updating the systems associated with a particular state, scene, or functionality of the application, such as menus, gameplay, plugins, etc. + +## Implementation Details + +### SystemManagersDirector + +```cpp +namespace Systems { + class SystemManagersDirector { + public: + // Singleton instance retrieval + static SystemManagersDirector &getInstance() + + // Retrieve a specific SystemManager by ID + SystemManager &getSystemManager(std::size_t id) + + // Add a new SystemManager + void addSystemManager(std::size_t id, std::vector> systems) + + // Remove a SystemManager + void removeSystemManager(std::size_t id) + + // Reset state changes in all SystemManagers + void resetChanges() + + std::mutex mutex; + + private: + std::map _systemManagers; + SystemManagersDirector() = default; + }; +} // namespace Systems +``` + +### Usage + +#### Enums for SystemManagers + +It's recommended to use enums to represent the IDs of different `SystemManager` instances for readability and maintainability. + +```cpp +enum SystemManagers { MENU, GAME, PLUGIN }; +``` + +#### Adding SystemManagers + +You can add a new `SystemManager` like so: + +```cpp +auto& systemManagersDirector = Systems::SystemManagersDirector::getInstance(); +std::vector> systemsList = /* ... */; +systemManagersDirector.addSystemManager(systemsList, SystemManagers::MENU); +``` + +### SceneManager Integration + +`SceneManager` interacts with `SystemManagersDirector` by referring to the same `SystemManagers` enum IDs when adding scenes or setting up multiple scenes. + +#### Modifying Scenes + +```cpp +auto& sceneManager = Scene::SceneManager::getInstance(); + +// Adding a single scene +sceneManager.addScene({SystemManagers::MENU}); + +// Setting multiple scenes at once +sceneManager.setScenes({{SystemManagers::MENU}, {SystemManagers::GAME, SystemManagers::PLUGIN}}); +``` + +This integration ensures consistency and eases the management of which systems are active in a given scene. + +## Conclusion + +With the `SystemManagersDirector`, you have a centralized and organized way to manage different sets of systems associated with various parts of your application. By using enum IDs, the code remains clean and the mapping between scenes and their corresponding systems is intuitive. + +The `SceneManager`, working closely with the `SystemManagersDirector`, offers a straightforward interface for transitioning between scenes, which can encompass different gameplay states, menus, and plugins, effectively separating concerns and promoting modular design in your application. \ No newline at end of file diff --git a/libs/B-luga/README.md b/libs/B-luga/README.md index 8b13789..63a4cc3 100644 --- a/libs/B-luga/README.md +++ b/libs/B-luga/README.md @@ -1 +1,38 @@ +# B-luga + +*An ECS made for a 3rd year project at EPITECH* + +## Hightlight + +- Sparse Array +- Templated Components +- Integrated Json Parser +- Integrated Logger +- Easy Plugin Integration + +## Install + +```cmake +include(FetchContent) + +FetchContent_Declare( + b-luga + URL "https://github.com/X-R-G-B/B-luga/releases/latest/download/b-luga.tar" + DOWNLOAD_EXTRACT_TIMESTAMP TRUE +) + +FetchContent_MakeAvailable(b-luga) + +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + b-luga +) +``` + +This will dowload the latest version of b-luga, and link it + add headers to the project with cmake + +## Documentation + +[documentation](./Documentation)