Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeAbel committed Nov 5, 2023
1 parent 28dd2cd commit fafdfc6
Show file tree
Hide file tree
Showing 10 changed files with 898 additions and 11 deletions.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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<std::function<void(std::size_t, std::size_t)>> 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 <vector>
#include <functional>
class ExamplePlugin : public IPlugin {
public:
void initPlugin() override {
// Specific initialization for this plugin
}
std::vector<std::function<void(std::size_t, std::size_t)>> 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<std::size_t>(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
52 changes: 41 additions & 11 deletions libs/B-luga-graphics/README.md
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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).
48 changes: 48 additions & 0 deletions libs/B-luga-physics/README.md
Original file line number Diff line number Diff line change
@@ -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.
74 changes: 74 additions & 0 deletions libs/B-luga/Documentation/Clock.md
Original file line number Diff line number Diff line change
@@ -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<std::optional<std::chrono::high_resolution_clock::time_point>> _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.
Loading

0 comments on commit fafdfc6

Please sign in to comment.