Instructions on how to use events
This commit is contained in:
parent
ddf6a7bee5
commit
5af0bf7d25
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue