Leviathan  0.8.0.0
Leviathan game engine
Event.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
8 
9 namespace Leviathan {
10 
12 enum EVENT_TYPE {
33  // EVENT_TYPE_FRAME_END,
37 
39 };
40 
41 #define LISTENERNAME_ONSHOW "OnShow"
42 #define LISTENERNAME_ONHIDE "OnHide"
43 #define LISTENERNAME_ONLISTENUPDATE "OnListenUpdate"
44 #define LISTENERNAME_ONCLICK "OnClick"
45 #define LISTENERNAME_ONINIT "OnInit"
46 #define LISTENERNAME_ONRELEASE "OnRelease"
47 #define LISTENERNAME_ONVALUECHANGE "OnValueChange"
48 #define LISTENERNAME_ONSUBMIT "OnSubmit"
49 #define LISTENERNAME_ONTICK "OnTick"
50 #define LISTENERNAME_ONCLOSECLICKED "OnCloseClicked"
51 #define LISTENERNAME_LISTSELECTIONACCEPTED "OnListSelectionAccepted"
52 
53 #define LISTENERVALUE_ONSHOW 100
54 #define LISTENERVALUE_ONHIDE 101
55 #define LISTENERVALUE_ONLISTENUPDATE 102
56 #define LISTENERVALUE_ONCLICK 103
57 #define LISTENERVALUE_ONINIT 104
58 #define LISTENERVALUE_ONRELEASE 105
59 #define LISTENERVALUE_ONVALUECHANGE 106
60 #define LISTENERVALUE_ONSUBMIT 107
61 #define LISTENERVALUE_ONTICK 108
62 #define LISTENERVALUE_ONCLOSECLICKED 109
63 #define LISTENERVALUE_LISTSELECTIONACCEPTED 110
64 
67 static const std::map<std::string, EVENT_TYPE> EventListenerNameToEventMap = {
70 
73 static const std::map<std::string, EVENT_TYPE> EventListenerCommonNameToEventMap = {
76 
80 public:
81 #ifdef LEVIATHAN_USING_SFML
82  virtual void AddDataToPacket(sf::Packet& packet) = 0;
84 #endif
85 
86  virtual ~BaseEventData();
87 };
88 
90 class FloatEventData : public BaseEventData {
91 public:
93  DLLEXPORT FloatEventData(float elapsed);
94 
95 #ifdef LEVIATHAN_USING_SFML
96  DLLEXPORT FloatEventData(sf::Packet& packet);
97 
98  virtual void AddDataToPacket(sf::Packet& packet);
99 #endif
100 
103 };
104 
106 class Event : public ReferenceCounted {
107 public:
108 #ifdef LEVIATHAN_USING_SFML
109  DLLEXPORT Event(sf::Packet& packet);
111 #endif
115  DLLEXPORT ~Event();
116 
118  DLLEXPORT EVENT_TYPE GetType() const;
119 
120 #ifdef LEVIATHAN_USING_SFML
121  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
123 #endif
124 
125  // Data getting functions //
128 
130 
131 protected:
134 
137 };
138 
141 public:
142 #ifdef LEVIATHAN_USING_SFML
143  DLLEXPORT GenericEvent(sf::Packet& packet);
145 #endif
146 
148  DLLEXPORT GenericEvent(const std::string& type, const NamedVars& copyvals);
149 
151  DLLEXPORT GenericEvent(const std::string& type);
152 
154  DLLEXPORT GenericEvent(std::string* takeownershipstr, NamedVars* takeownershipvars);
156 
157 #ifdef LEVIATHAN_USING_SFML
158  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
160 #endif
161 
163  DLLEXPORT const NamedVars GetVariablesConst() const;
164 
167 
171 
173  DLLEXPORT std::string* GetTypePtr();
176  DLLEXPORT std::string GetType() const;
177 
179 
180 protected:
182  std::string* TypeStr;
183 
186 };
187 
188 } // namespace Leviathan
189 
190 #ifdef LEAK_INTO_GLOBAL
191 using Leviathan::Event;
193 #endif
REFERENCE_COUNTED_PTR_TYPE(Event)
DLLEXPORT GenericEvent(sf::Packet &packet)
Constructs this object from a packet.
Definition: Event.cpp:101
#define LISTENERNAME_ONSHOW
Definition: Event.h:41
float FloatDataValue
Current engine tick count.
Definition: Event.h:102
Class that represents a statically defined event.
Definition: Event.h:106
std::string * TypeStr
String that defines this event's type.
Definition: Event.h:182
DLLEXPORT std::string * GetTypePtr()
Returns the TypeStr ptr.
Definition: Event.cpp:129
virtual void AddDataToPacket(sf::Packet &packet)=0
Adds this to a packet for retrieving it later.
EVENT_TYPE Type
Events type.
Definition: Event.h:133
DLLEXPORT NamedVars * GetVariables()
Returns a direct pointer to this objects variables.
Definition: Event.cpp:144
#define LISTENERNAME_ONINIT
Definition: Event.h:45
EVENT_TYPE
Engine events that are triggered at certain times.
Definition: Event.h:12
DLLEXPORT FloatEventData(float elapsed)
Loads from a packet.
Definition: Event.cpp:171
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:136
DLLEXPORT std::string GetType() const
Returns the name of the event.
Definition: Event.cpp:134
DLLEXPORT FloatEventData * GetFloatDataForEvent() const
Gets the data if this is an event that has only one integer data member.
Definition: Event.cpp:70
DLLEXPORT const NamedVars GetVariablesConst() const
Gets this event's variables.
Definition: Event.cpp:139
DLLEXPORT EVENT_TYPE GetType() const
Gets the Type of the event.
Definition: Event.cpp:27
static const std::map< std::string, EVENT_TYPE > EventListenerCommonNameToEventMap
Definition: Event.h:73
Class that represents a dynamically defined event.
Definition: Event.h:140
#define LISTENERNAME_ONLISTENUPDATE
Definition: Event.h:43
DLLEXPORT NamedVars * GetNamedVarsRefCounted()
Proxy for script to get Variables.
Definition: Event.cpp:149
#define LISTENERNAME_ONHIDE
Definition: Event.h:42
DLLEXPORT Event(sf::Packet &packet)
Loads this event from a packet.
Definition: Event.cpp:43
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Saves this event to a packet.
Definition: Event.cpp:33
static const std::map< std::string, EVENT_TYPE > EventListenerNameToEventMap
Definition: Event.h:67
DLLEXPORT ~Event()
Definition: Event.cpp:21
virtual ~BaseEventData()
Definition: Event.cpp:173
DLLEXPORT ~GenericEvent()
Definition: Event.cpp:93
#define LISTENERNAME_ONTICK
Definition: Event.h:49
NamedVars * Variables
Pointer to this event's variables.
Definition: Event.h:185
#define DLLEXPORT
Definition: Include.h:84
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:90
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Base type for all event data types.
Definition: Event.h:79
virtual void AddDataToPacket(sf::Packet &packet)
Adds this to a packet for retrieving it later.
Definition: Event.cpp:165
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Serializes this event to a packet.
Definition: Event.cpp:120
#define LISTENERNAME_ONRELEASE
Definition: Event.h:46
REFERENCE_COUNTED_PTR_TYPE(GenericEvent)