-
Notifications
You must be signed in to change notification settings - Fork 2
ECS Events
An Event is a piece of logic that can contain data. An event can be sent everywhere you have access to the registry and are all added in the same queue. The queue is emptied in the event listener, which is in the applications. Events are handled by systems that are badly named Event Handlers.
In our game engine, developers and the community can create custom systems and components. Components are written in C++.
In this tutorial, we'll send a SwitchScene event. This event requires nothing, we will just send an event containing a path to the desired scene.
First go into a file where you can access to the registry and include the following files:
#include "AEvent.hpp"
Then, we'll create a vector of values, which will be sent in the event
std::vector<std::any> values = {};
Now, we can fill this vector with the scene we want to go in:
// It is compulsory to cast in the right type to avoid bad any casts issues
values.push_back((std::string)"Path_To_The_Scene.json");
Then, create an event with the event type and the values and send it:
std::shared_ptr<IEvent> event = std::make_shared<AEvent>("SwitchScene", values);
registry->addEvent(event);
Here we are ! We just sent our first event !
But that's not the end. How will the event be handled ?
To know it, I'll let you check the EventHandler Documentation.