Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CEventHandler
- {
- private:
- // Prevent EventHandlers being created before event sys had been opened
- //
- static RwUInt32 refCountEventHandlersCreated;
- public:
- /**
- *
- * Construct an instance of the CEventHandler class. Clients of CEventHandler should not call the
- * constructor directly but by using the \a InitCEventHandler macro, this is because the parameters
- * to the constructor change when \a RWS_EVENTVISUALIZATION is defined, the \a InitCEventHandler takes
- * care of this.
- *
- * \param pCEventVisualization A pointer to the CEventVisualization class which defines an interface
- * which if supported provides the 3D position of the event handler which is used by the event
- * Visualization system.
- *
- * \note Event Visualization is only enabled when RWS_EVENTVISUALIZATION is defined.
- *
- * Example showing the difference between using CEventHandler, and InitCEventHandler
- *
- * \verbatim
- class DisplayDebugTools : public CEventHandler
- {
- public:
- virtual void HandleEvents(CMsg &pMsg);
- DisplayDebugTools(void) : InitCEventHandler(m_pEntity) {}
- // using the constructor directly would require RWS_EVENTVISUALIZATION to be handled i.e.
- //
- #ifdef RWS_EVENTVISUALIZATION
- DisplayDebugTools(void) : CEventHandler(m_pEntity) {}
- #else
- DisplayDebugTools(void) : CEventHandler() {}
- #endif
- ~DisplayDebugTools(void);
- protected:
- C3DRwEntityPtr m_pEntity; // Note: C3DRwEntity is derived from CEventVisualization
- };
- \endverbatim
- *
- * \note If the event handler doesn't provide the CEventVisualization interface initialize the
- * event handler with 0 as the parameter, i.e. InitCEventHandler(0).
- */
- #ifdef RWS_EVENTVISUALIZATION
- CEventHandler(CEventVisualization *pCEventVisualization) :
- m_pCEventVisualization(pCEventVisualization), m_Active(true)
- {
- #ifndef NDEBUG
- refCountEventHandlersCreated++;
- #endif
- };
- /**
- *
- */
- #define InitCEventHandler(a) CEventHandler(a)
- #else
- CEventHandler() : m_Active(true)
- {
- #ifndef NDEBUG
- refCountEventHandlersCreated++;
- #endif
- };
- /**
- *
- */
- #define InitCEventHandler(a) CEventHandler()
- #endif
- virtual ~CEventHandler(void);
- static void Open(RwUInt32 linkBlockSize = 0, RwUInt32 regBlockSize = 0);
- static void Close(void);
- static void RegisterStreamChunkHandlers(void);
- static void UnRegisterStreamChunkHandlers(void);
- /**
- *
- * Purge - purges unused memory within the event system. Call can be slow.
- *
- */
- static void Purge(void)
- {
- // Purges sub-objects which use 'RwFreeList'.
- CLinkedMsg::PurgeMem();
- CRegisteredMsgs::PurgeMem();
- }
- /**
- *
- * Translate and process messages for this event handler \ref CEventHandler, this is how event
- * handlers receive an event,
- *
- * \param pMsg A reference to an event \ref CMsg, this is the event that caused HandleEvents
- * to be called.
- *
- * \note calling BaseClass::HandleEvents will pass on the event to the baseclass, this can
- * be used to extend the behavior of previously define event handler.
- *
- */
- virtual void HandleEvents(CMsg &pMsg) = 0;
- static void UnRegisterMsg(CEventId &Id);
- static void RegisterMsg(CEventId &Id,const char *p_msgname,const char *p_formatstring);
- static void ReplaceRegisteredMsg(CEventId &Id,const char *p_msgname,const char *p_formatstring);
- void ReplaceLinkedMsg(CEventId &Id,const char *p_msgname,const char *p_formatstring);
- static void ReplaceLinkedMsg(CEventHandler &rEventHand, CEventId &Id,const char *p_msgname,
- const char *p_formatstring, RwUInt16 priority = 0x8000);
- static void SetLinkPriority(CEventHandler &rEventHand, CEventId &Id,
- const char *p_formatString, RwUInt16 priority = 0x8000);
- static void DeleteEventHandlers(const CMsg *p_Msg);
- static void DeleteEventHandlers(const CEventId &Id);
- static void RegisterToDeleteEventHandlers(const CMsg *p_Msg);
- static void RegisterToDeleteEventHandlers(const CEventId &Id);
- static RwBool LinkMsgToEventHandler(
- CEventHandler *pCEventHandler,
- CEventId &Id,
- const char *p_formatstring = 0,
- RwUInt16 priority = 0x8000);
- void LinkMsg(CEventId &Id,const char *p_formatstring = 0,RwUInt16 priority = 0x8000);
- RwBool IsLinked(CEventId &Id);
- RwInt32 GetLinkedPriority(CEventId &Id);
- static void Delete(CEventHandler *pCEventHandler);
- void Delete(void) {Delete(this);}
- void UnLinkMsg(CEventId &Id);
- /**
- *
- * \ref UnRegisterForAutoDelete Removes the CEventHandler from the list of
- * CEventHandlers to be deleted when
- * CEventHandler::DeleteEventHandlers() is called.
- *
- */
- void UnRegisterForAutoDelete() { UnLinkMsg(iMsgDeleteEventHandler); }
- /**
- *
- * \ref RegisterToAutoDelete
- *
- * Registers a CEventHandler with the auto delete event
- * \ref iMsgDeleteEventHandler. All of the event handlers
- * registered with this event can be destroyed at the end of a level
- * when CEventHandler::DeleteEventHandlers (iMsgDeleteEventHandler)
- * is called.
- *
- */
- void RegisterForAutoDelete() { LinkMsg(iMsgDeleteEventHandler); }
- static void ProcessPendingUnlinks(CLinkedMsg *pErm);
- void SendMsgToEventHandler(CMsg &p_Msg,CEventHandler *pCEventHandler);
- void SendMsgToEventHandler(const CEventId &Id,CEventHandler *pCEventHandler);
- private:
- CEventHandler(const CEventHandler& rhs); // Disable copy constructor
- CEventHandler &operator = (const CEventHandler& rhs); // Disable copy operator,
- // Following section is used to visualize events.
- //
- #ifdef RWS_EVENTVISUALIZATION
- public:
- CEventVisualization *Get_m_pCEventVisualization(void) {return m_pCEventVisualization;}
- void Set_m_pCEventVisualization(CEventVisualization *pCEventVisualization)
- {m_pCEventVisualization = pCEventVisualization;}
- protected:
- /**
- *
- * \ref m_pCEventVisualization Pointer to an event Visualization class, provides methods
- * for extracting the 3D position or the event handler.
- *
- * \see CEventHandler constructor
- *
- * \note m_pCEventVisualization is only available if RWS_EVENTVISUALIZATION is defined
- */
- CEventVisualization *m_pCEventVisualization;
- protected:
- RwBool _SendMsg(CMsg &p_Msg);
- /**
- *
- * Broadcast event plus data.
- *
- * \param p_Msg A reference to a CMsg class containing the Id of the event and any additional data.
- *
- * \return true if any event handlers are linked to the event, otherwise false.
- *
- */
- RwBool SendMsg(CMsg &p_Msg)
- {
- if (p_Msg.Id != ERROR_NOT_A_VALID_MESSAGE_ID && p_Msg.Id->Erm.p_next)
- {
- return _SendMsg(p_Msg);
- }
- else
- {
- return false;
- }
- }
- /**
- *
- * Broadcast event. The data field of the sent message is set to 0.
- *
- * \param Id A reference to a CEventId class containing the Id of the event.
- *
- * \return true if any event handlers are linked to the event, otherwise false.
- *
- */
- RwBool SendMsg(const CEventId &Id)
- {
- if (Id != ERROR_NOT_A_VALID_MESSAGE_ID && Id->Erm.p_next)
- {
- CMsg iMsg(Id,0);
- return _SendMsg (iMsg);
- }
- else
- {
- return false;
- }
- }
- #endif
- public:
- RwBool m_Active; /**< Used to block a CEventHandler from receiving any further
- events after Delete has been called. */
- protected:
- } ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement