Skip to content

SFME::ECS

Sztergbaum Roman edited this page Feb 12, 2018 · 73 revisions

Welcome to the page of the SFME::ECS module

Modules contents

A complete example can be found here

Include hierarchy can be found here

How works the System

SFME have 3 differents kinds of systems:

  • PreUpdate : These systems are the first to be updated in the game loop, they are generally used to retrieve user input, or manage network events for example.
  • LogicUpdate -> Looped as long as it is allowed (for example GameLogic, Physics, Movement)
  • PostUpdate -> Called after the PreUpdate and the LogicUpdate. (for example Rendering, Interpolation)

The pseudo code will look like this :

    while(running) {
            updateSystems(SystemType::PreUpdate);
            _timeStep.startFrame();
            while (_timeStep.isUpdateRequired()) {
                updateSystems(SystemType::LogicUpdate);
                _timeStep.performUpdate();
            }
            updateSystems(SystemType::PostUpdate);
    }

This game loop is based on the gafferon on games tutorial: Fix your timestep

This class will manage the systems of the entity component system. You will be able to add, remove, retrieve or delete systems through it.

The class is templated on the entity manager and she is a receiver.

Class Signature

template <typename EntityManager>
class SystemManager final : public sfme::mediator::Receiver<SystemManager<EntityManager>>;

Constructor

SystemManager(sfme::mediator::EventManager &evtMgr, EntityManager &ettMgr) noexcept;
Parameters
  • evtMgr The event manager will be provided to the system when it is created.
  • ettMgr The entity manager will be provided to the system when it is created.

Member function : update

void update() noexcept;
Notes

This is the function that will update your systems. Based on the logic of the different kinds of SFME systems, this function will take care of updating your systems in the right order. If you decide to mark a system, it will be automatically deleted at the next loop turn through this function

How can i use it ? click here for jump to the source code
#include <SFME/ecs/ecs.hpp>
#include "ecs_common_example.hpp"

int main()
{
    //! Managers
    sfme::mediator::EventManager evtMgr;
    sfme::example::EntityManager ettMgr;
    sfme::ecs::SystemManager<sfme::example::EntityManager> systemMgr{evtMgr, ettMgr};

    //! System Loading
    systemMgr.loadSystems<sfme::example::system::PostUpdate,
        sfme::example::system::PreUpdate,
        sfme::example::system::Logic>();

    //! Game Loop
    for (int i = 0; i < 50000; ++i) {
        systemMgr.update();
    }
    return 0;
}

Member function: createSystem

template <typename System, typename ...Args>
System &createSystem(Args &&...args) noexcept;

Include Hierarchy

Clone this wiki locally