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-2017 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 {
42 
44 };
45 
48 static const std::map<std::string, EVENT_TYPE> EventListenerNameToEventMap = {
51 
54 static const std::map<std::string, EVENT_TYPE> EventListenerCommonNameToEventMap = {
57 
61 public:
63  virtual void AddDataToPacket(sf::Packet& packet) = 0;
64 
65  virtual ~BaseEventData();
66 };
67 
70 public:
71  DLLEXPORT ClientInterpolationEventData(int tick, int mspassed);
72 
73  DLLEXPORT ClientInterpolationEventData(sf::Packet& packet);
74 
75  DLLEXPORT void AddDataToPacket(sf::Packet& packet) override;
76 
77 private:
78  void CalculatePercentage();
79 
80 public:
83 
87 
92  float Percentage;
93 };
94 
97 public:
99  DLLEXPORT PhysicsStartEventData(sf::Packet& packet);
101  DLLEXPORT PhysicsStartEventData(const float& time, void* worldptr);
102 
103  virtual void AddDataToPacket(sf::Packet& packet);
104 
106  float TimeStep;
107 
111 };
112 
115 public:
117  DLLEXPORT IntegerEventData(sf::Packet& packet);
118 
119  DLLEXPORT IntegerEventData(int ticknumber);
120 
121  virtual void AddDataToPacket(sf::Packet& packet);
122 
125 };
126 
128 class Event : public ReferenceCounted {
129 public:
131  DLLEXPORT Event(sf::Packet& packet);
134  DLLEXPORT Event(EVENT_TYPE type, BaseEventData* data);
135  DLLEXPORT ~Event();
136 
138  DLLEXPORT EVENT_TYPE GetType() const;
139 
140 
142  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
143 
144  // Data getting functions //
145  DLLEXPORT PhysicsStartEventData* GetDataForPhysicsStartEvent() const;
146  DLLEXPORT ClientInterpolationEventData* GetDataForClientInterpolationEvent() const;
148  DLLEXPORT IntegerEventData* GetIntegerDataForEvent() const;
149 
151 
152 protected:
155 
158 };
159 
162 public:
164  DLLEXPORT GenericEvent(sf::Packet& packet);
165 
167  DLLEXPORT GenericEvent(const std::string& type, const NamedVars& copyvals);
168 
170  DLLEXPORT GenericEvent(const std::string& type);
171 
173  DLLEXPORT GenericEvent(std::string* takeownershipstr, NamedVars* takeownershipvars);
174  DLLEXPORT ~GenericEvent();
175 
177  DLLEXPORT void AddDataToPacket(sf::Packet& packet) const;
178 
180  DLLEXPORT const NamedVars GetVariablesConst() const;
181 
183  DLLEXPORT NamedVars* GetVariables();
184 
187  DLLEXPORT NamedVars* GetNamedVarsRefCounted();
188 
190  DLLEXPORT std::string* GetTypePtr();
193  DLLEXPORT std::string GetType() const;
194 
195  REFERENCE_COUNTED_PTR_TYPE(GenericEvent);
196 
197 protected:
199  std::string* TypeStr;
200 
203 };
204 
205 } // namespace Leviathan
206 
207 #ifdef LEAK_INTO_GLOBAL
208 using Leviathan::Event;
210 #endif
Class that represents a statically defined event.
Definition: Event.h:128
std::string * TypeStr
String that defines this event&#39;s type.
Definition: Event.h:199
float TimeStep
The time step in seconds.
Definition: Event.h:106
virtual void AddDataToPacket(sf::Packet &packet)=0
Adds this to a packet for retrieving it later.
EVENT_TYPE Type
Events type.
Definition: Event.h:154
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:157
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:114
#define LISTENERNAME_ONSHOW
Definition: ScriptModule.h:32
int IntegerDataValue
Current engine tick count.
Definition: Event.h:124
static const std::map< std::string, EVENT_TYPE > EventListenerCommonNameToEventMap
Definition: Event.h:54
Class that represents a dynamically defined event.
Definition: Event.h:161
#define LISTENERNAME_ONHIDE
Definition: ScriptModule.h:33
static const std::map< std::string, EVENT_TYPE > EventListenerNameToEventMap
Definition: Event.h:48
virtual ~BaseEventData()
Definition: Event.cpp:259
#define LISTENERNAME_ONINIT
Definition: ScriptModule.h:36
#define LISTENERNAME_ONRELEASE
Definition: ScriptModule.h:37
Data for EVENT_TYPE_CLIENT_INTERPOLATION.
Definition: Event.h:69
NamedVars * Variables
Pointer to this event&#39;s variables.
Definition: Event.h:202
#define LISTENERNAME_ONTICK
Definition: ScriptModule.h:40
#define DLLEXPORT
Definition: Include.h:118
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Data for EVENT_TYPE_PHYSICS_BEGIN.
Definition: Event.h:96
Base type for all event data types.
Definition: Event.h:60
int TickNumber
The current tick to use for interpolation.
Definition: Event.h:82
#define REFERENCE_COUNTED_PTR_TYPE(x)