SP3-18 Event/Messaging System #25

Merged
XiaoQiDigipen merged 8 commits from SP3-18-Events into main 2022-09-16 01:33:47 +08:00
2 changed files with 29 additions and 15 deletions
Showing only changes of commit 5af0bf7d25 - Show all commits

View File

@ -17,15 +17,6 @@ namespace SHADE
SHEventHandle SHEventManager::handleCounter{ 0 };
/****************************************************************************
* \brief Returns function pointer to entry point for events.
****************************************************************************/
EventManagerListener SHEventManager::GetListenerFunction()
{
return &CatchEvent;
}
/****************************************************************************
* \param ListenerConstPtr - Const pointer to listener that sent event.
* \param EventType - Templated type for every type of event

View File

@ -17,7 +17,33 @@
/******************************************************************************
INSTRUCTIONS FOR USE:
On broadcaster side:
1.
1. Create a struct/class to contain the data that you would need to send
in the event.
2. Create unique event identifier in SHEventDefines.h, follow the example
provided.
3. When ready to send the event, call
SHEventManager::BroadcastEvent<ExampleClass>(exampleClass, EVENT_IDENTIFIER);
Headers required: SHEventManager.h
On Receiver side:
1. Create a function with the signature:
SHEventHandle FunctionName(SHEvent);
2. In the init function of the class, copy the below in and replace the
necessary:
std::shared_ptr<SHEventReceiverSpec<ReceiverClass>> thisReceiver{
std::make_shared<SHEventReceiverSpec<ReceiverClass>>(this, &ReceiverClass::ReceiveFunction)
};
ReceiverPtr receiver = std::dynamic_pointer_cast<SHEventReceiver>(thisReceiver);
SHEventManager::SubscribeTo(EVENT_IDENTIFIER, receiver);
3. Note: The EventIdentifier should match all that is defined in
SHEventDefines.h so check there. When the receiver catches the event, it
needs to know the struct that the broadcaster is using to cast the void*
properly.
Headers required: SHEventManager.h, SHEventReceiver.h
******************************************************************************/
namespace SHADE
@ -32,10 +58,6 @@ namespace SHADE
class SHEventManager
{
public:
/****************************************************************************
* \brief Returns function pointer to entry point for events.
****************************************************************************/
static EventManagerListener GetListenerFunction();
/****************************************************************************
* \param ListenerConstPtr - Const pointer to listener that sent event.
@ -86,4 +108,5 @@ namespace SHADE
static void RegisterReceiverToType(SHEventIdentifier, ReceiverPtr);
};
}