ezEngine  Milestone 7
GlobalEvent.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Foundation/Types/Variant.h>
6 #include <Foundation/Containers/Map.h>
7 #include <Foundation/Strings/String.h>
9 
34 class EZ_FOUNDATION_DLL ezGlobalEvent : public ezEnumerable<ezGlobalEvent>
35 {
37 
38 public:
39 
40  struct EZ_FOUNDATION_DLL EventData
41  {
42  EventData();
43 
44  ezUInt32 m_uiNumTimesFired;
45  ezUInt16 m_uiNumEventHandlersRegular;
46  ezUInt16 m_uiNumEventHandlersOnce;
47  };
48 
50 
51 public:
52 
54  typedef void (*EZ_GLOBAL_EVENT_HANDLER)(const ezVariant& param0, const ezVariant& param1, const ezVariant& param2, const ezVariant& param3);
55 
57  ezGlobalEvent(const char* szEventName, EZ_GLOBAL_EVENT_HANDLER EventHandler, bool bOnlyOnce); // [tested]
58 
62  static void Broadcast(const char* szEventName, ezVariant param0 = ezVariant(), ezVariant param1 = ezVariant(), ezVariant param2 = ezVariant(), ezVariant param3 = ezVariant()); // [tested]
63 
67  static void PrintGlobalEventStatistics(); // [tested]
68 
70  static void UpdateGlobalEventStatistics();
71 
73  static const EventMap& GetEventStatistics() { return s_KnownEvents; }
74 
75 private:
76  bool m_bOnlyOnce;
77  bool m_bHasBeenFired;
78  const char* m_szEventName;
79  EZ_GLOBAL_EVENT_HANDLER m_EventHandler;
80 
81  static EventMap s_KnownEvents;
82 };
83 
84 
86 #define EZ_ON_GLOBAL_EVENT(name) \
87  static void EventHandler_##name (const ezVariant& param0, const ezVariant& param1, const ezVariant& param2, const ezVariant& param3); \
88  static ezGlobalEvent s_EventHandler_##name (#name, EventHandler_##name, false); \
89  static void EventHandler_##name (const ezVariant& param0, const ezVariant& param1, const ezVariant& param2, const ezVariant& param3)
90 
92 #define EZ_ON_GLOBAL_EVENT_ONCE(name) \
93  static void EventHandler_##name (const ezVariant& param0, const ezVariant& param1, const ezVariant& param2, const ezVariant& param3); \
94  static ezGlobalEvent s_EventHandler_##name (#name, EventHandler_##name, true); \
95  static void EventHandler_##name (const ezVariant& param0, const ezVariant& param1, const ezVariant& param2, const ezVariant& param3)
96 
97 
98