5#include <unordered_map>
6#include "CoreMinimal.h"
8#include "UObject/Object.h"
9#include "BaseManager.generated.h"
11#define DECLARE_EVENT_HANDLER(TEvent) protected: void HandleEvent_Impl(class TEvent* Event);
13#define DEFINE_EVENT_HANDLER(TEventType) \
14static_assert(std::is_base_of<UBaseEvent, TEventType>::value, "Trying to create definiton for invalid event"); \
15Handlers[TEventType::StaticClass()] = [this](UBaseEvent* Event) -> void \
17HandleEvent_Impl(Cast<TEventType>(Event)); \
22PRAGMA_DISABLE_OPTIMIZATION
37 template <typename TEventType, typename... TInitializeArgs>
38 void SendEvent(TInitializeArgs... Arguments)
40 EventLogService::NewEvent<TEventType>(Arguments...);
70 using THandlers = std::unordered_map<THandlerKey, THandler, THandlerHash, THandlerComp>;
76PRAGMA_ENABLE_OPTIMIZATION
78template <
typename TManagerType>
79FUNCTION_NON_NULL_RETURN_START
81FUNCTION_NON_NULL_RETURN_END
83 static_assert(std::is_base_of<UBaseManager, TManagerType>::value,
"TManagerType should derive from UBaseManager");
84 TManagerType* Manager = NewObject<TManagerType>(Owner, TargetManagerClass);
85 Manager->SetPrivateOwner(Owner);
#define DECLARE_EVENT_HANDLER(TEvent)
PRAGMA_ENABLE_OPTIMIZATION FUNCTION_NON_NULL_RETURN_START TManagerType * NewManager(APlayerController *Owner, UClass *TargetManagerClass) FUNCTION_NON_NULL_RETURN_END
The UBaseEvent class serves as the base class for all events for our event-managers system....
It provides functionalities for handling events, sending events, and managing a private owner....
APlayerController * PrivateOwner
UPROPERTY()
std::unordered_map< THandlerKey, THandler, THandlerHash, THandlerComp > THandlers
TFunction< void(UBaseEvent *)> THandler
void SetPrivateOwner(APlayerController *Owner)
void SendEvent(TInitializeArgs... Arguments)
APlayerController * GetPrivateOwner() const
bool operator()(THandlerKey lhs, THandlerKey rhs) const
std::size_t operator()(THandlerKey code) const