Plasma Engine  2.0
Loading...
Searching...
No Matches
EventMessage.h
1#pragma once
2
3#include <Core/World/World.h>
4#include <Foundation/Communication/Message.h>
5
7struct PL_CORE_DLL plEventMessage : public plMessage
8{
9 PL_DECLARE_MESSAGE_TYPE(plEventMessage, plMessage);
10
11 plGameObjectHandle m_hSenderObject;
12 plComponentHandle m_hSenderComponent;
13
14 PL_ALWAYS_INLINE void FillFromSenderComponent(const plComponent* pSenderComponent)
15 {
16 if (pSenderComponent != nullptr)
17 {
18 m_hSenderComponent = pSenderComponent->GetHandle();
19 m_hSenderObject = pSenderComponent->GetOwner()->GetHandle();
20 }
21 }
22};
23
24namespace plInternal
25{
26 struct PL_CORE_DLL EventMessageSenderHelper
27 {
28 static bool SendEventMessage(plMessage& ref_msg, plComponent* pSenderComponent, plGameObject* pSearchObject, plSmallArray<plComponentHandle, 1>& inout_cachedReceivers);
29 static bool SendEventMessage(plMessage& ref_msg, const plComponent* pSenderComponent, const plGameObject* pSearchObject, plSmallArray<plComponentHandle, 1>& inout_cachedReceivers);
30 static void PostEventMessage(const plMessage& msg, const plComponent* pSenderComponent, const plGameObject* pSearchObject, plSmallArray<plComponentHandle, 1>& inout_cachedReceivers, plTime delay, plObjectMsgQueueType::Enum queueType);
31 };
32} // namespace plInternal
33
37template <typename EventMessageType>
38class plEventMessageSender : public plMessageSenderBase<EventMessageType>
39{
40public:
41 PL_ALWAYS_INLINE bool SendEventMessage(EventMessageType& inout_msg, plComponent* pSenderComponent, plGameObject* pSearchObject)
42 {
43 if constexpr (PL_IS_DERIVED_FROM_STATIC(plEventMessage, EventMessageType))
44 {
45 inout_msg.FillFromSenderComponent(pSenderComponent);
46 }
47 return plInternal::EventMessageSenderHelper::SendEventMessage(inout_msg, pSenderComponent, pSearchObject, m_CachedReceivers);
48 }
49
50 PL_ALWAYS_INLINE bool SendEventMessage(EventMessageType& inout_msg, const plComponent* pSenderComponent, const plGameObject* pSearchObject) const
51 {
52 if constexpr (PL_IS_DERIVED_FROM_STATIC(plEventMessage, EventMessageType))
53 {
54 inout_msg.FillFromSenderComponent(pSenderComponent);
55 }
56 return plInternal::EventMessageSenderHelper::SendEventMessage(inout_msg, pSenderComponent, pSearchObject, m_CachedReceivers);
57 }
58
59 PL_ALWAYS_INLINE void PostEventMessage(EventMessageType& ref_msg, plComponent* pSenderComponent, plGameObject* pSearchObject,
61 {
62 if constexpr (PL_IS_DERIVED_FROM_STATIC(plEventMessage, EventMessageType))
63 {
64 ref_msg.FillFromSenderComponent(pSenderComponent);
65 }
66 plInternal::EventMessageSenderHelper::PostEventMessage(ref_msg, pSenderComponent, pSearchObject, m_CachedReceivers, delay, queueType);
67 }
68
69 PL_ALWAYS_INLINE void PostEventMessage(EventMessageType& ref_msg, const plComponent* pSenderComponent, const plGameObject* pSearchObject,
71 {
72 if constexpr (PL_IS_DERIVED_FROM_STATIC(plEventMessage, EventMessageType))
73 {
74 ref_msg.FillFromSenderComponent(pSenderComponent);
75 }
76 plInternal::EventMessageSenderHelper::PostEventMessage(ref_msg, pSenderComponent, pSearchObject, m_CachedReceivers, delay, queueType);
77 }
78
79 PL_ALWAYS_INLINE void Invalidate()
80 {
81 m_CachedReceivers.Clear();
82 m_CachedReceivers.GetUserData<plUInt32>() = 0;
83 }
84
85private:
86 mutable plSmallArray<plComponentHandle, 1> m_CachedReceivers;
87};
Base class of all component types.
Definition Component.h:25
plComponentHandle GetHandle() const
Returns a handle to this component.
Definition Component_inl.h:53
plGameObject * GetOwner()
Returns the owner game object if the component is attached to one or nullptr.
Definition Component_inl.h:43
A message sender that sends all messages to the next component derived from plEventMessageHandlerComp...
Definition EventMessage.h:39
This class represents an object inside the world.
Definition GameObject.h:32
plGameObjectHandle GetHandle() const
Returns a handle to this object.
Definition GameObject_inl.h:64
Base class for all message types. Each message type has it's own id which is used to dispatch message...
Definition Message.h:22
void Clear()
Clears the array.
Definition SmallArray_inl.h:222
Definition SmallArray.h:219
A handle to a component.
Definition Declarations.h:138
Base class for all messages that are sent as 'events'.
Definition EventMessage.h:8
A handle to a game object.
Definition Declarations.h:76
Definition EventMessage.h:27
Base class for all message senders.
Definition Message.h:144
Enum
Definition Declarations.h:274
@ NextFrame
Process the message in the PreAsync phase of the next frame.
Definition Declarations.h:277
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12