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 #include "Script/ScriptModule.h"
9 
10 namespace Leviathan {
11 
13 enum EVENT_TYPE {
41 
43 };
44 
47 static const std::map<std::string, EVENT_TYPE> EventListenerNameToEventMap = {
50 
53 static const std::map<std::string, EVENT_TYPE> EventListenerCommonNameToEventMap = {
56 
60 public:
62  virtual void AddDataToPacket(sf::Packet& packet) = 0;
63 
64  virtual ~BaseEventData();
65 };
66 
69 public:
70  DLLEXPORT ClientInterpolationEventData(int tick, int mspassed);
71 
72  DLLEXPORT ClientInterpolationEventData(sf::Packet& packet);
73 
74  DLLEXPORT void AddDataToPacket(sf::Packet& packet) override;
75 
76 private:
77  void CalculatePercentage();
78 
79 public:
82 
86 
91  float Percentage;
92 };
93 
96 public:
98  DLLEXPORT IntegerEventData(sf::Packet& packet);
99 
100  DLLEXPORT IntegerEventData(int ticknumber);
101 
102  virtual void AddDataToPacket(sf::Packet& packet);
103 
106 };
107 
109 class Event : public ReferenceCounted {
110 public:
112  DLLEXPORT Event(sf::Packet& packet);
116  DLLEXPORT ~Event();
117 
119  DLLEXPORT EVENT_TYPE GetType() const;
120 
121 
123  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
124 
125  // Data getting functions //
129 
131 
132 protected:
135 
138 };
139 
142 public:
144  DLLEXPORT GenericEvent(sf::Packet& packet);
145 
147  DLLEXPORT GenericEvent(const std::string& type, const NamedVars& copyvals);
148 
150  DLLEXPORT GenericEvent(const std::string& type);
151 
153  DLLEXPORT GenericEvent(std::string* takeownershipstr, NamedVars* takeownershipvars);
155 
157  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
158 
160  DLLEXPORT const NamedVars GetVariablesConst() const;
161 
164 
168 
170  DLLEXPORT std::string* GetTypePtr();
173  DLLEXPORT std::string GetType() const;
174 
176 
177 protected:
179  std::string* TypeStr;
180 
183 };
184 
185 } // namespace Leviathan
186 
187 #ifdef LEAK_INTO_GLOBAL
188 using Leviathan::Event;
190 #endif
REFERENCE_COUNTED_PTR_TYPE(Event)
DLLEXPORT GenericEvent(sf::Packet &packet)
Constructs this object from a packet.
Definition: Event.cpp:113
Class that represents a statically defined event.
Definition: Event.h:109
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:179
DLLEXPORT std::string * GetTypePtr()
Returns the TypeStr ptr.
Definition: Event.cpp:140
virtual void AddDataToPacket(sf::Packet &packet)=0
Adds this to a packet for retrieving it later.
EVENT_TYPE Type
Events type.
Definition: Event.h:134
DLLEXPORT NamedVars * GetVariables()
Returns a direct pointer to this objects variables.
Definition: Event.cpp:155
EVENT_TYPE
Engine events that are triggered at certain times.
Definition: Event.h:13
#define LISTENERNAME_ONLISTENUPDATE
Definition: ScriptModule.h:34
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137
DLLEXPORT std::string GetType() const
Returns the name of the event.
Definition: Event.cpp:145
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:95
DLLEXPORT IntegerEventData * GetIntegerDataForEvent() const
Gets the data if this is an event that has only one integer data member.
Definition: Event.cpp:82
#define LISTENERNAME_ONSHOW
Definition: ScriptModule.h:32
DLLEXPORT ClientInterpolationEventData(int tick, int mspassed)
Definition: Event.cpp:182
DLLEXPORT const NamedVars GetVariablesConst() const
Gets this event&#39;s variables.
Definition: Event.cpp:150
DLLEXPORT EVENT_TYPE GetType() const
Gets the Type of the event.
Definition: Event.cpp:29
DLLEXPORT IntegerEventData(sf::Packet &packet)
Loads from a packet.
Definition: Event.cpp:205
int IntegerDataValue
Current engine tick count.
Definition: Event.h:105
static const std::map< std::string, EVENT_TYPE > EventListenerCommonNameToEventMap
Definition: Event.h:53
Class that represents a dynamically defined event.
Definition: Event.h:141
virtual void AddDataToPacket(sf::Packet &packet)
Adds this to a packet for retrieving it later.
Definition: Event.cpp:218
DLLEXPORT NamedVars * GetNamedVarsRefCounted()
Proxy for script to get Variables.
Definition: Event.cpp:160
DLLEXPORT Event(sf::Packet &packet)
Loads this event from a packet.
Definition: Event.cpp:44
#define LISTENERNAME_ONHIDE
Definition: ScriptModule.h:33
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Saves this event to a packet.
Definition: Event.cpp:34
static const std::map< std::string, EVENT_TYPE > EventListenerNameToEventMap
Definition: Event.h:47
DLLEXPORT ~Event()
Definition: Event.cpp:23
virtual ~BaseEventData()
Definition: Event.cpp:223
DLLEXPORT ClientInterpolationEventData * GetDataForClientInterpolationEvent() const
Definition: Event.cpp:75
DLLEXPORT ~GenericEvent()
Definition: Event.cpp:106
#define LISTENERNAME_ONINIT
Definition: ScriptModule.h:36
#define LISTENERNAME_ONRELEASE
Definition: ScriptModule.h:37
Data for EVENT_TYPE_CLIENT_INTERPOLATION.
Definition: Event.h:68
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:182
#define LISTENERNAME_ONTICK
Definition: ScriptModule.h:40
#define DLLEXPORT
Definition: Include.h:115
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:59
int TickNumber
The current tick to use for interpolation.
Definition: Event.h:81
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Serializes this event to a packet.
Definition: Event.cpp:132
REFERENCE_COUNTED_PTR_TYPE(GenericEvent)
DLLEXPORT void AddDataToPacket(sf::Packet &packet) override
Adds this to a packet for retrieving it later.
Definition: Event.cpp:199