Instructions on how to use events

This commit is contained in:
Xiao Qi 2022-09-15 18:33:36 +08:00
parent ddf6a7bee5
commit 5af0bf7d25
2 changed files with 29 additions and 15 deletions

View File

@ -16,16 +16,7 @@ namespace SHADE
std::unordered_map<SHEventHandle, SHEventDataPtr> SHEventManager::dataEventMap; std::unordered_map<SHEventHandle, SHEventDataPtr> SHEventManager::dataEventMap;
SHEventHandle SHEventManager::handleCounter{ 0 }; 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 ListenerConstPtr - Const pointer to listener that sent event.
* \param EventType - Templated type for every type of event * \param EventType - Templated type for every type of event

View File

@ -17,7 +17,33 @@
/****************************************************************************** /******************************************************************************
INSTRUCTIONS FOR USE: INSTRUCTIONS FOR USE:
On broadcaster side: 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 namespace SHADE
@ -32,10 +58,6 @@ namespace SHADE
class SHEventManager class SHEventManager
{ {
public: public:
/****************************************************************************
* \brief Returns function pointer to entry point for events.
****************************************************************************/
static EventManagerListener GetListenerFunction();
/**************************************************************************** /****************************************************************************
* \param ListenerConstPtr - Const pointer to listener that sent event. * \param ListenerConstPtr - Const pointer to listener that sent event.
@ -86,4 +108,5 @@ namespace SHADE
static void RegisterReceiverToType(SHEventIdentifier, ReceiverPtr); static void RegisterReceiverToType(SHEventIdentifier, ReceiverPtr);
}; };
} }