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 {
40 
42 };
43 
44 #define LISTENERNAME_ONSHOW "OnShow"
45 #define LISTENERNAME_ONHIDE "OnHide"
46 #define LISTENERNAME_ONLISTENUPDATE "OnListenUpdate"
47 #define LISTENERNAME_ONCLICK "OnClick"
48 #define LISTENERNAME_ONINIT "OnInit"
49 #define LISTENERNAME_ONRELEASE "OnRelease"
50 #define LISTENERNAME_ONVALUECHANGE "OnValueChange"
51 #define LISTENERNAME_ONSUBMIT "OnSubmit"
52 #define LISTENERNAME_ONTICK "OnTick"
53 #define LISTENERNAME_ONCLOSECLICKED "OnCloseClicked"
54 #define LISTENERNAME_LISTSELECTIONACCEPTED "OnListSelectionAccepted"
55 
56 #define LISTENERVALUE_ONSHOW 100
57 #define LISTENERVALUE_ONHIDE 101
58 #define LISTENERVALUE_ONLISTENUPDATE 102
59 #define LISTENERVALUE_ONCLICK 103
60 #define LISTENERVALUE_ONINIT 104
61 #define LISTENERVALUE_ONRELEASE 105
62 #define LISTENERVALUE_ONVALUECHANGE 106
63 #define LISTENERVALUE_ONSUBMIT 107
64 #define LISTENERVALUE_ONTICK 108
65 #define LISTENERVALUE_ONCLOSECLICKED 109
66 #define LISTENERVALUE_LISTSELECTIONACCEPTED 110
67 
70 static const std::map<std::string, EVENT_TYPE> EventListenerNameToEventMap = {
73 
76 static const std::map<std::string, EVENT_TYPE> EventListenerCommonNameToEventMap = {
79 
83 public:
84 #ifdef LEVIATHAN_USING_SFML
85  virtual void AddDataToPacket(sf::Packet& packet) = 0;
87 #endif
88 
89  virtual ~BaseEventData();
90 };
91 
94 public:
95  DLLEXPORT ClientInterpolationEventData(int tick, int mspassed);
96 
97 #ifdef LEVIATHAN_USING_SFML
98  DLLEXPORT ClientInterpolationEventData(sf::Packet& packet);
99 
100  DLLEXPORT void AddDataToPacket(sf::Packet& packet) override;
101 #endif
102 
103 private:
104  void CalculatePercentage();
105 
106 public:
109 
113 
118  float Percentage;
119 };
120 
123 public:
125  DLLEXPORT IntegerEventData(int ticknumber);
126 
127 #ifdef LEVIATHAN_USING_SFML
128  DLLEXPORT IntegerEventData(sf::Packet& packet);
129 
130  virtual void AddDataToPacket(sf::Packet& packet);
131 #endif
132 
135 };
136 
138 class Event : public ReferenceCounted {
139 public:
140 #ifdef LEVIATHAN_USING_SFML
141  DLLEXPORT Event(sf::Packet& packet);
143 #endif
147  DLLEXPORT ~Event();
148 
150  DLLEXPORT EVENT_TYPE GetType() const;
151 
152 #ifdef LEVIATHAN_USING_SFML
153  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
155 #endif
156 
157  // Data getting functions //
161 
163 
164 protected:
167 
170 };
171 
174 public:
175 #ifdef LEVIATHAN_USING_SFML
176  DLLEXPORT GenericEvent(sf::Packet& packet);
178 #endif
179 
181  DLLEXPORT GenericEvent(const std::string& type, const NamedVars& copyvals);
182 
184  DLLEXPORT GenericEvent(const std::string& type);
185 
187  DLLEXPORT GenericEvent(std::string* takeownershipstr, NamedVars* takeownershipvars);
189 
190 #ifdef LEVIATHAN_USING_SFML
191  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
193 #endif
194 
196  DLLEXPORT const NamedVars GetVariablesConst() const;
197 
200 
204 
206  DLLEXPORT std::string* GetTypePtr();
209  DLLEXPORT std::string GetType() const;
210 
212 
213 protected:
215  std::string* TypeStr;
216 
219 };
220 
221 } // namespace Leviathan
222 
223 #ifdef LEAK_INTO_GLOBAL
224 using Leviathan::Event;
226 #endif
REFERENCE_COUNTED_PTR_TYPE(Event)
DLLEXPORT GenericEvent(sf::Packet &packet)
Constructs this object from a packet.
Definition: Event.cpp:116
#define LISTENERNAME_ONSHOW
Definition: Event.h:44
Class that represents a statically defined event.
Definition: Event.h:138
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:215
DLLEXPORT std::string * GetTypePtr()
Returns the TypeStr ptr.
Definition: Event.cpp:144
virtual void AddDataToPacket(sf::Packet &packet)=0
Adds this to a packet for retrieving it later.
EVENT_TYPE Type
Events type.
Definition: Event.h:166
DLLEXPORT NamedVars * GetVariables()
Returns a direct pointer to this objects variables.
Definition: Event.cpp:159
#define LISTENERNAME_ONINIT
Definition: Event.h:48
EVENT_TYPE
Engine events that are triggered at certain times.
Definition: Event.h:12
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:169
DLLEXPORT std::string GetType() const
Returns the name of the event.
Definition: Event.cpp:149
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:122
DLLEXPORT IntegerEventData * GetIntegerDataForEvent() const
Gets the data if this is an event that has only one integer data member.
Definition: Event.cpp:84
DLLEXPORT ClientInterpolationEventData(int tick, int mspassed)
Definition: Event.cpp:186
DLLEXPORT IntegerEventData(int ticknumber)
Loads from a packet.
Definition: Event.cpp:227
DLLEXPORT const NamedVars GetVariablesConst() const
Gets this event&#39;s variables.
Definition: Event.cpp:154
DLLEXPORT EVENT_TYPE GetType() const
Gets the Type of the event.
Definition: Event.cpp:29
int IntegerDataValue
Current engine tick count.
Definition: Event.h:134
static const std::map< std::string, EVENT_TYPE > EventListenerCommonNameToEventMap
Definition: Event.h:76
Class that represents a dynamically defined event.
Definition: Event.h:173
#define LISTENERNAME_ONLISTENUPDATE
Definition: Event.h:46
virtual void AddDataToPacket(sf::Packet &packet)
Adds this to a packet for retrieving it later.
Definition: Event.cpp:221
DLLEXPORT NamedVars * GetNamedVarsRefCounted()
Proxy for script to get Variables.
Definition: Event.cpp:164
#define LISTENERNAME_ONHIDE
Definition: Event.h:45
DLLEXPORT Event(sf::Packet &packet)
Loads this event from a packet.
Definition: Event.cpp:45
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Saves this event to a packet.
Definition: Event.cpp:35
static const std::map< std::string, EVENT_TYPE > EventListenerNameToEventMap
Definition: Event.h:70
DLLEXPORT ~Event()
Definition: Event.cpp:23
virtual ~BaseEventData()
Definition: Event.cpp:231
DLLEXPORT ClientInterpolationEventData * GetDataForClientInterpolationEvent() const
Definition: Event.cpp:77
DLLEXPORT ~GenericEvent()
Definition: Event.cpp:108
Data for EVENT_TYPE_CLIENT_INTERPOLATION.
Definition: Event.h:93
#define LISTENERNAME_ONTICK
Definition: Event.h:52
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:218
#define DLLEXPORT
Definition: Include.h:84
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:82
int TickNumber
The current tick to use for interpolation.
Definition: Event.h:108
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Serializes this event to a packet.
Definition: Event.cpp:135
#define LISTENERNAME_ONRELEASE
Definition: Event.h:49
REFERENCE_COUNTED_PTR_TYPE(GenericEvent)
DLLEXPORT void AddDataToPacket(sf::Packet &packet) override
Adds this to a packet for retrieving it later.
Definition: Event.cpp:204