> For the complete documentation index, see [llms.txt](https://redboard.gitbook.io/r-type-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redboard.gitbook.io/r-type-1/client/ecs/systems/systems-class.md).

# Systems class

## AnimationsSystem || AnimationOneTimeSystem

```cpp
class AnimationSystem {
    public:
        void update(Registry &ecs, float deltaTime);
};

class AnimationOneTimeSystem {
    public:
        void update(Registry &ecs, float deltaTime);
};
```

The AnimationSystem is responsible for updating entity animations using each TextureRectComponent.

Methods:

* `void update(Registry &ecs, float deltaTime)`: This method updates the animation frames of entities with `TextureRectComponent`. It calculates the elapsed time and advances the texture rect accordingly to create the animation effect.

**Usage:**

```cpp
ECS::systems::AnimationSystem animationSystem;
float deltaTime = 0.016f; // deltaTime value since the last update
animationSystem.update(ecs, deltaTime);
```

## ControllableSystem

```cpp
class ControllableSystem {
    public:
        class EntityMove {
            private:
                entity_t entity;
                char move;
            public:
                EntityMove(entity_t entity) : entity(entity) {}
                void setMove(char move);
                char getMove();
                void setEntity(entity_t entity);
                entity_t getEntity() const;
        };
        ControllableSystem() = default;
        void update(Registry &ecs, std::vector<EntityEvent> &entityMoves, std::vector<u_char> &keyboardEntries, sf::RenderWindow &window, int &eventMemory);
    private:
};
```

The ControllableSystem is responsible for updating the controls for each entity with a ControllableComponent.

It keeps track of the actions performed by the keys and stores them in EntityMove instances.

Methods:

* <pre class="language-cpp" data-overflow="wrap"><code class="lang-cpp">void update(Registry &#x26;ecs, std::vector&#x3C;EntityEvent> &#x26;entityMoves, std::vector&#x3C;u_char> &#x26;keyboardEntries, sf::RenderWindow &#x26;window, int &#x26;eventMemory)
  </code></pre>

  : This method updates the control inputs for each entity with a `ControllableComponent`. It checks which keys are pressed and records the corresponding actions. The recorded actions are stored in `EntityMove` objects and added to the provided `entityMoves` vector.

Usage:

```cpp
ECS::systems::ControllableSystem controllableSystem;
std::vector<ECS::systems::ControllableSystem::EntityMove> entityMoves;
controllableSystem.update(ecs, entityMoves);
```

Inner Class: EntityMove

Methods:

* `void setMove(char move)`: Sets the action performed by the key.
* `char getMove()`: Returns the recorded action.
* `void setEntity(entity_t entity)`: Sets the entity associated with the action.
* `entity_t getEntity() const`: Returns the entity associated with the action.

Usage:

```cpp
ECS::systems::ControllableSystem::EntityMove entityMove(entity);

// Set the action performed by the key.
entityMove.setMove(move);

// Get the recorded action.
char action = entityMove.getMove();

// Set the entity associated with the action.
entityMove.setEntity(entity);

// Get the entity associated with the action.
entity_t associatedEntity = entityMove.getEntity();
```

## DrawSystem

```cpp
class DrawSystem {
    public:
        void update(Registry &ecs, sf::RenderWindow &window);
};
```

The DrawSystem is responsible for updating the sprites of entities that have a SpriteComponent and rendering them on the screen.

It also handles the updating of positions if the entity has a PositionComponent and texture rectangles if the entity has a TextureRectComponent.

Methods:

* `void update(Registry &ecs, sf::RenderWindow &window)`: This method updates the sprites of entities and draws them on the specified render window.

Usage:

```cpp
ECS::systems::DrawSystem drawSystem;
drawSystem.update(ecs, window);
```

## MovableSystem

```cpp
class MovableSystem {
    public:
        class EntityPos {
            private:
                entity_t entity;
                float x;
                float y;
            public:
                EntityPos(entity_t entity, float x, float y) : entity(entity), x(x), y(y) {}
                float getX() const { return x; }
                float getY() const { return y; }
                entity_t getEntity() const { return entity; }
        };
        MovableSystem() = default;
        void update(Registry &ecs, std::vector<EntityPos> &entityPositions);
    private:
};
```

The MoveSystem is responsible for updating the position of entities based on their PositionComponent and MovableComponent.

It processes a list of entity positions and updates the corresponding entities in the ECS registry.

Methods:

* `MovableSystem()`: Constructor for the `MovableSystem` class.
* `void update(Registry &ecs, std::vector<EntityPos> &entityPositions)`: This method updates the position of entities by setting the `PositionComponent` values based on the provided list of entity positions. It ensures that only entities with both `PositionComponent` and `MovableComponent` are updated.

Inner Class:

* `EntityPos`: This inner class represents the position and entity ID for an entity. It is used to store entity positions before updating them.

Usage:

```cpp
ECS::systems::MovableSystem movableSystem;
std::vector<ECS::systems::MovableSystem::EntityPos> entityPositions;
movableSystem.update(ecs, entityPositions);
```

## ParallaxSystem

```cpp
class ParallaxSystem {
    public:
        void update(Registry &ecs, float deltaTime, sf::Vector2u offset = {0, 0});
};
```

The ParallaxSystem is responsible for updating the parallax position of entities equipped with a ParallaxComponent.

This system allows you to create the illusion of a moving background in your game.

Methods:

* `void update(Registry &ecs, float deltaTime, sf::Vector2fu offset = {0, 0})`: This method updates the parallax position of each entity with a `ParallaxComponent`. It takes into account the scroll speed specified in the component and adjusts the entity's position accordingly. Additionally, it handles looping of the background to create a continuous parallax effect.

Usage:

```cpp
ECS::systems::ParallaxSystem parallaxSystem;
float deltaTime = 0.016f; // time elapsed since the last update
parallaxSystem.update(ecs, deltaTime);
```

## ParticuleSystem

```cpp
class ParticuleSystem {
    public:
        void update(Registry &ecs, std::vector<entity_t> &particules, std::unique_ptr<Fbr> &fbr, std::chrono::system_clock::time_point &lastParticleUpdate);
    };
}
```

The ParticuleSystem is repsonsible for updating and drawing entity based on a vector of entity using ParticuleComponent.\
\
Methods:

* `void update(Registry &ecs, std::vector<entity_t> &particules, std::unique_ptr<Fbr> &fbr, std::chrono::system_clock::time_point &lastParticleUpdate)`: This method update and draw rectangle of each particule entity cheking of the duration of the particule.

Usage:

```cpp
ECS::systems::ParticuleSystem particuleSystem;
std::vector<entity_t> particules;
std::vector<Fbr> fbr;
std::chrono::system_clock::time_point lastParticleUpdate;
particuleSystem.update(ecs, particules, fbr, lastParticleUpdate);
```

## PositionSystem

```cpp
class PositionSystem {
    public:
        void update(Registry &ecs);
};
```

The PositionSystem is responsible for updating the position of entities based on their PositionComponent and VelocityComponent.

Methods:

* `void update(Registry &ecs)`: This method updates the position of each entity by adding their velocity values to their current positions. It ensures that entities move correctly based on their velocity.

Usage:

```cpp
ECS::systems::PositionSystem positionSystem;
positionSystem.update(ecs);
```

## ScaleSystem

```cpp
class ScaleSystem {
    public:
        void update(Registry &ecs);
};
```

The ScaleSystem manages the scaling of sprite entities using the ScaleComponent and SpriteComponent.

Methods:

* `void update(Registry &ecs)`: This method updates the scale of each sprite entity based on their `ScaleComponent`. It ensures that the entities are displayed at the correct scale.

Usage:

```cpp
ECS::systems::ScaleSystem scaleSystem;
scaleSystem.update(ecs);
```

## SoundSystem

```cpp
class SoundSystem {
    public:
        void update(Registry &ecs, std::vector<entity_t> &sounds);
};
```

The SoundSystem manages sounds that you launch in your program.

Methods:

* `void update(Registry &ecs, std::vector<entity_t> &sounds)` : This methods kill the entity of your sound if it's not playing.

## TextSystem

```cpp
class TextSystem {
    public:
        void update(Registry &ecs, std::unordered_map<entity_t, std::string> &texts);
};
```

The TextSystem manages texts that you wrote in your program.

Methods:

* `void update(Registry &ecs, std::unordered_map<entity_t, std::string> &texts)`: This method will update all texts that you have in your program.&#x20;

For example, in our program, we need to update the timer every second, which is possible thanks to this update.
