-
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. The function will also release the entities marked through the function of the entity manager: sweepEntities.
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;- System Represents the type of system you want to load.
- Args Represents the arguments possibly necessary to the creation of the system.
Returns a reference to the loaded System.
If the system is already loaded, it will be returned to you. The EntityManager and the EventManager will be sent implicitly to the creation of each system.
How can i use it ? click here for jump to the source code
#include "ecs_common_example.hpp"
namespace fs = std::experimental::filesystem;
int main()
{
sfme::mediator::EventManager evtMgr;
sfme::example::EntityManager ettMgr;
sfme::ecs::SystemManager<sfme::example::EntityManager> systemMgr{evtMgr, ettMgr,
fs::current_path() / "example/systems"};
//! Simple system creation
systemMgr.createSystem<sfme::example::system::Logic>();
//! Simple system creation with user data.
systemMgr.createSystem<sfme::example::system::WithUserData>(1, 2);
//! Multiple systems creation
systemMgr.loadSystems<sfme::example::system::PostUpdate, sfme::example::system::PreUpdate>();
//! Simple plugged system creation
systemMgr.loadPlugin("sfme_ecs_foo_plugin_example");
//! Multiple plugged system creation
systemMgr.loadPlugins();
return 0;
}