-
Notifications
You must be signed in to change notification settings - Fork 0
SFME::ECS
Welcome to the page of the SFME::ECS module
A complete example can be found here
Include hierarchy can be found here
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: These systems are the second to be updated in the game loop, they are generally used for game logic such as movement or collisions for example.
- PostUpdate: These systems are the last to be updated in the game loop, they are generally used for rendering or interpolation for example.
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.
template <typename EntityManager>
class SystemManager final : public sfme::mediator::Receiver<SystemManager<EntityManager>>;SystemManager(sfme::mediator::EventManager &evtMgr, EntityManager &ettMgr) noexcept;- 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.
void update() noexcept;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;
}template <typename System, typename ...Args>
System &createSystem(Args &&...args) noexcept;