Systems class
Some class for systems
AnimationsSystem || AnimationOneTimeSystem
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 withTextureRectComponent
. It calculates the elapsed time and advances the texture rect accordingly to create the animation effect.
Usage:
ECS::systems::AnimationSystem animationSystem;
float deltaTime = 0.016f; // deltaTime value since the last update
animationSystem.update(ecs, deltaTime);
ControllableSystem
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:
void update(Registry &ecs, std::vector<EntityEvent> &entityMoves, std::vector<u_char> &keyboardEntries, sf::RenderWindow &window, int &eventMemory)
: 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 inEntityMove
objects and added to the providedentityMoves
vector.
Usage:
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:
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
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:
ECS::systems::DrawSystem drawSystem;
drawSystem.update(ecs, window);
MovableSystem
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 theMovableSystem
class.void update(Registry &ecs, std::vector<EntityPos> &entityPositions)
: This method updates the position of entities by setting thePositionComponent
values based on the provided list of entity positions. It ensures that only entities with bothPositionComponent
andMovableComponent
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:
ECS::systems::MovableSystem movableSystem;
std::vector<ECS::systems::MovableSystem::EntityPos> entityPositions;
movableSystem.update(ecs, entityPositions);
ParallaxSystem
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 aParallaxComponent
. 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:
ECS::systems::ParallaxSystem parallaxSystem;
float deltaTime = 0.016f; // time elapsed since the last update
parallaxSystem.update(ecs, deltaTime);
ParticuleSystem
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:
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
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:
ECS::systems::PositionSystem positionSystem;
positionSystem.update(ecs);
ScaleSystem
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 theirScaleComponent
. It ensures that the entities are displayed at the correct scale.
Usage:
ECS::systems::ScaleSystem scaleSystem;
scaleSystem.update(ecs);
SoundSystem
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
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.
For example, in our program, we need to update the timer every second, which is possible thanks to this update.
Last updated