Nui Engine
A game engine framework
Loading...
Searching...
No Matches
Event.h
1#pragma once
2#include "Core/Engine/ECS/Common.h"
3
4namespace Nui::ECS
5{
6 namespace Internal
7 {
12 {
13 public:
17 virtual ~EventSubscriberBase() = default;
18 };
19 }
20
25 template <typename T>
27 {
28 public:
32 virtual ~EventSubscriber() = default;
33
39 virtual void OnEvent(Context* context, const T& event) = 0;
40 };
41
45 namespace Events
46 {
51 {
56 };
57
62 {
67 };
68
73 template <typename T>
86
91 template <typename T>
104 }
105}
106
107// Use this macro to inherit from Nui::ECS::EventSubscriber<Type>
108#define NUI_EVENT_SUBSCRIBER(Type) public ECS::EventSubscriber<Type>
109
110// Use this macro to declare an event function in header files (needs use of NUI_EVENT_SUBSCRIBER macro with same type)
111#define NUI_DECLARE_EVENT(Type) virtual void OnEvent(Nui::ECS::Context* ctx, const Type& event) override
112
113// Use this macro to define an event function in source files (needs use of NUI_DECLARE_EVENT macro)
114#define NUI_DEFINE_EVENT(Class, Type) void Class::OnEvent(Nui::ECS::Context* ctx, const Type& event)
115
116// Use this macro to subscribe to an event function (needs use of NUI_DECLARE_EVENT & NUI_EVENT_SUBSCRIBER macro)
117#define NUI_SUBSCRIBE_EVENT(ECSContext, Type) ECSContext->SubscribeEvent<Type>(this)
118
119// Use this macro to unsubscribe from an event function (needs use of NUI_DECLARE_EVENT & NUI_EVENT_SUBSCRIBER macro)
120#define NUI_UNSUBSCRIBE_EVENT(ECSContext, Type) ECSContext->UnsubscribeEvent<Type>(this)
121
122// Use this macro to unsubscribe from all events - use in destructor/shutdown functions
123#define NUI_UNSUBSCRIBE_EVENTS_ALL(ECSContext) ECSContext->UnsubscribeAll(this)
This class provides a handle to a component.
Definition Component.h:52
The ECS context class manages entities, systems, and events in the ECS framework.
Definition Context.h:17
Class to represent an entity in an ECS Context.
Definition Entity.h:10
Base class for all event subscribers.
Definition Event.h:27
virtual void OnEvent(Context *context, const T &event)=0
Pure virtual function for handling event callback.
virtual ~EventSubscriber()=default
Virtual default destructor.
Base class for all event subscribers usually systems.
Definition Event.h:12
virtual ~EventSubscriberBase()=default
Virtual default destructor.
Event for when component is added.
Definition Event.h:75
Entity * Entity
Pointer to the entity.
Definition Event.h:79
ComponentHandle< T > Component
Handle to the component.
Definition Event.h:84
Event for when component is removed.
Definition Event.h:93
Entity * Entity
Pointer to the entity.
Definition Event.h:97
ComponentHandle< T > Component
Handle to the component.
Definition Event.h:102
Event for entity creation.
Definition Event.h:51
Entity * Entity
Pointer to the created entity.
Definition Event.h:55
Event for entity destruction.
Definition Event.h:62
Entity * Entity
Pointer to the destroyed entity.
Definition Event.h:66