Nui Engine
A game engine framework
Loading...
Searching...
No Matches
Event.h
1
#pragma once
2
#include "Core/Engine/ECS/Common.h"
3
4
namespace
Nui::ECS
5
{
6
namespace
Internal
7
{
11
class
EventSubscriberBase
12
{
13
public
:
17
virtual
~EventSubscriberBase
() =
default
;
18
};
19
}
20
25
template
<
typename
T>
26
class
EventSubscriber
:
public
Internal::EventSubscriberBase
27
{
28
public
:
32
virtual
~EventSubscriber
() =
default
;
33
39
virtual
void
OnEvent
(
Context
* context,
const
T& event) = 0;
40
};
41
45
namespace
Events
46
{
50
struct
OnEntityCreate
51
{
55
Entity
*
Entity
;
56
};
57
61
struct
OnEntityDestroy
62
{
66
Entity
*
Entity
;
67
};
68
73
template
<
typename
T>
74
struct
OnComponentAdd
75
{
79
Entity
*
Entity
;
80
84
ComponentHandle<T>
Component
;
85
};
86
91
template
<
typename
T>
92
struct
OnComponentRemove
93
{
97
Entity
*
Entity
;
98
102
ComponentHandle<T>
Component
;
103
};
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)
Nui::ECS::ComponentHandle
This class provides a handle to a component.
Definition
Component.h:52
Nui::ECS::Context
The ECS context class manages entities, systems, and events in the ECS framework.
Definition
Context.h:17
Nui::ECS::Entity
Class to represent an entity in an ECS Context.
Definition
Entity.h:10
Nui::ECS::EventSubscriber
Base class for all event subscribers.
Definition
Event.h:27
Nui::ECS::EventSubscriber::OnEvent
virtual void OnEvent(Context *context, const T &event)=0
Pure virtual function for handling event callback.
Nui::ECS::EventSubscriber::~EventSubscriber
virtual ~EventSubscriber()=default
Virtual default destructor.
Nui::ECS::Internal::EventSubscriberBase
Base class for all event subscribers usually systems.
Definition
Event.h:12
Nui::ECS::Internal::EventSubscriberBase::~EventSubscriberBase
virtual ~EventSubscriberBase()=default
Virtual default destructor.
Nui::ECS::Events::OnComponentAdd
Event for when component is added.
Definition
Event.h:75
Nui::ECS::Events::OnComponentAdd::Entity
Entity * Entity
Pointer to the entity.
Definition
Event.h:79
Nui::ECS::Events::OnComponentAdd::Component
ComponentHandle< T > Component
Handle to the component.
Definition
Event.h:84
Nui::ECS::Events::OnComponentRemove
Event for when component is removed.
Definition
Event.h:93
Nui::ECS::Events::OnComponentRemove::Entity
Entity * Entity
Pointer to the entity.
Definition
Event.h:97
Nui::ECS::Events::OnComponentRemove::Component
ComponentHandle< T > Component
Handle to the component.
Definition
Event.h:102
Nui::ECS::Events::OnEntityCreate
Event for entity creation.
Definition
Event.h:51
Nui::ECS::Events::OnEntityCreate::Entity
Entity * Entity
Pointer to the created entity.
Definition
Event.h:55
Nui::ECS::Events::OnEntityDestroy
Event for entity destruction.
Definition
Event.h:62
Nui::ECS::Events::OnEntityDestroy::Entity
Entity * Entity
Pointer to the destroyed entity.
Definition
Event.h:66
Engine
Core
Engine
ECS
Event.h
Generated by
1.11.0