Bomberman
EventSystem.hpp
Go to the documentation of this file.
1 //
2 // Created by Zoe Roux on 6/1/21.
3 //
4 
5 #pragma once
6 
7 #include <System/System.hpp>
8 #include <vector>
9 #include <functional>
10 
11 namespace BBM
12 {
13  class EventSystem : public WAL::System<>
14  {
15  private:
17  std::list<std::function<void (WAL::Entity &)>> _events;
19  std::list<std::function<void (WAL::Wal &)>> _globalEvents;
20  public:
22  void dispatchEvent(const std::function<void (WAL::Entity &)>& event);
23 
25  void dispatchEvent(const std::function<void (WAL::Wal &)>& event);
26 
28  void onUpdate(WAL::ViewEntity<> &entity, std::chrono::nanoseconds dtime) override;
30  void onSelfUpdate(std::chrono::nanoseconds dtime) override;
31 
33  explicit EventSystem(WAL::Wal &wal);
35  EventSystem(const EventSystem &) = default;
37  ~EventSystem() override = default;
39  EventSystem &operator=(const EventSystem &) = delete;
40  };
41 }
BBM::EventSystem::_globalEvents
std::list< std::function< void(WAL::Wal &)> > _globalEvents
The list of events that occurred in the last update.
Definition: EventSystem.hpp:19
WAL::ViewEntity
Definition: View.hpp:19
System.hpp
BBM
Definition: AnimationsComponent.cpp:9
WAL::Wal
The main WAL class, it is used to setup and run the ECS.
Definition: Wal.hpp:27
WAL::Entity
An entity of the WAL's ECS.
Definition: Entity.hpp:20
BBM::EventSystem::onSelfUpdate
void onSelfUpdate(std::chrono::nanoseconds dtime) override
A method called after all entities that this system manage has been updated.
Definition: EventSystem.cpp:29
BBM::EventSystem::EventSystem
EventSystem(WAL::Wal &wal)
A default constructor.
Definition: EventSystem.cpp:9
BBM::EventSystem::operator=
EventSystem & operator=(const EventSystem &)=delete
An event system is not assignable.
WAL::System
A base system of WAL.
Definition: System.hpp:22
BBM::EventSystem::~EventSystem
~EventSystem() override=default
A default destructor.
BBM::EventSystem::_events
std::list< std::function< void(WAL::Entity &)> > _events
The list of events that occurred in the last update.
Definition: EventSystem.hpp:17
BBM::EventSystem::dispatchEvent
void dispatchEvent(const std::function< void(WAL::Entity &)> &event)
Inform the system that a new event has occurred and it should run the given method on every entities.
Definition: EventSystem.cpp:13
BBM::EventSystem
Definition: EventSystem.hpp:13
BBM::EventSystem::onUpdate
void onUpdate(WAL::ViewEntity<> &entity, std::chrono::nanoseconds dtime) override
Definition: EventSystem.cpp:23