BVB Source Codes

CRYENGINE Show CustomEventsManager.cpp Source code

Return Download CRYENGINE: download CustomEventsManager.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4.  
  5. #include "CustomEvents/CustomEventsManager.h"
  6.  
  7. ///////////////////////////////////////////////////
  8. // Manager implementation to associate custom events
  9. ///////////////////////////////////////////////////
  10.  
  11. //------------------------------------------------------------------------------------------------------------------------
  12. CCustomEventManager::CCustomEventManager()
  13.         : m_curHighestEventId(CUSTOMEVENTID_INVALID)
  14. {
  15. }
  16.  
  17. //------------------------------------------------------------------------------------------------------------------------
  18. CCustomEventManager::~CCustomEventManager()
  19. {
  20.         Clear();
  21. }
  22.  
  23. //------------------------------------------------------------------------------------------------------------------------
  24. bool CCustomEventManager::RegisterEventListener(ICustomEventListener* pListener, const TCustomEventId eventId)
  25. {
  26.         SCustomEventData& eventData = m_customEventsData[eventId];   // Creates new entry if doesn't exist
  27.         TCustomEventListeners& listeners = eventData.m_listeners;
  28.         return listeners.Add(pListener);
  29. }
  30.  
  31. //------------------------------------------------------------------------------------------------------------------------
  32. bool CCustomEventManager::UnregisterEventListener(ICustomEventListener* pListener, const TCustomEventId eventId)
  33. {
  34.         TCustomEventsMap::iterator eventsDataIter = m_customEventsData.find(eventId);
  35.         if (eventsDataIter != m_customEventsData.end())
  36.         {
  37.                 SCustomEventData& eventData = eventsDataIter->second;
  38.                 TCustomEventListeners& listeners = eventData.m_listeners;
  39.  
  40.                 if (listeners.Contains(pListener))
  41.                 {
  42.                         listeners.Remove(pListener);
  43.                         return true;
  44.                 }
  45.                 else
  46.                 {
  47.                         CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CCustomEventManager::UnregisterEventListener: Listener isn't registered for event id: %u", eventId);
  48.                 }
  49.         }
  50.         else
  51.         {
  52.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CCustomEventManager::UnregisterEventListener: No event data exists for event id: %u", eventId);
  53.         }
  54.  
  55.         return false;
  56. }
  57.  
  58. //------------------------------------------------------------------------------------------------------------------------
  59. bool CCustomEventManager::UnregisterEvent(TCustomEventId eventId)
  60. {
  61.         TCustomEventsMap::iterator eventsDataIter = m_customEventsData.find(eventId);
  62.         if (eventsDataIter != m_customEventsData.end())
  63.         {
  64.                 SCustomEventData& eventData = eventsDataIter->second;
  65.                 TCustomEventListeners& listeners = eventData.m_listeners;
  66.                 listeners.Clear(true);
  67.                 m_customEventsData.erase(eventsDataIter);
  68.                 return true;
  69.         }
  70.  
  71.         return false;
  72. }
  73.  
  74. //------------------------------------------------------------------------------------------------------------------------
  75. void CCustomEventManager::Clear()
  76. {
  77.         m_customEventsData.clear();
  78.         m_curHighestEventId = CUSTOMEVENTID_INVALID;
  79. }
  80.  
  81. //------------------------------------------------------------------------------------------------------------------------
  82. void CCustomEventManager::FireEvent(const TCustomEventId eventId, const TFlowInputData& customData)
  83. {
  84.         TCustomEventsMap::iterator eventsDataIter = m_customEventsData.find(eventId);
  85.         if (eventsDataIter != m_customEventsData.end())
  86.         {
  87.                 SCustomEventData& eventData = eventsDataIter->second;
  88.                 TCustomEventListeners& listeners = eventData.m_listeners;
  89.                 listeners.ForEachListener([&](ICustomEventListener* pListener){ pListener->OnCustomEvent(eventId, customData); });
  90.         }
  91.         else
  92.         {
  93.                 CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CCustomEventManager::FireEvent: No event data exists for event id: %u", eventId);
  94.         }
  95. }
  96.  
  97. //------------------------------------------------------------------------------------------------------------------------
  98. TCustomEventId CCustomEventManager::GetNextCustomEventId()
  99. {
  100.         const TCustomEventId curNextId = m_curHighestEventId + 1;
  101.         m_curHighestEventId = curNextId;
  102.         return curNextId;
  103. }
  104.  
downloadCustomEventsManager.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top