forked from eu07/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.h
210 lines (194 loc) · 6.4 KB
/
Event.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Classes.h"
#include "dumb3d.h"
#include "Names.h"
#include "EvLaunch.h"
enum TEventType {
tp_Unknown,
tp_Sound,
tp_Exit,
tp_Disable,
tp_Velocity,
tp_Animation,
tp_Lights,
tp_UpdateValues,
tp_GetValues,
tp_PutValues,
tp_Switch,
tp_DynVel,
tp_TrackVel,
tp_Multiple,
tp_AddValues,
tp_CopyValues,
tp_WhoIs,
tp_LogValues,
tp_Visible,
tp_Voltage,
tp_Message,
tp_Friction,
tp_Lua
};
const int update_memstring = 0x0000001; // zmodyfikować tekst (UpdateValues)
const int update_memval1 = 0x0000002; // zmodyfikować pierwszą wartosć
const int update_memval2 = 0x0000004; // zmodyfikować drugą wartosć
const int update_memadd = 0x0000008; // dodać do poprzedniej zawartości
const int update_load = 0x0000010; // odczytać ładunek
const int update_only = 0x00000FF; // wartość graniczna
const int conditional_memstring = 0x0000100; // porównanie tekstu
const int conditional_memval1 = 0x0000200; // porównanie pierwszej wartości liczbowej
const int conditional_memval2 = 0x0000400; // porównanie drugiej wartości
const int conditional_trackoccupied = 0x1000000; // jeśli tor zajęty
const int conditional_trackfree = 0x2000000; // jeśli tor wolny
const int conditional_propability = 0x4000000; // zależnie od generatora lizcb losowych
const int conditional_memcompare = 0x8000000; // porównanie zawartości
union TParam
{
void *asPointer;
TMemCell *asMemCell;
scene::basic_node *asSceneNode;
glm::dvec3 const *asLocation;
TTrack *asTrack;
TAnimModel *asModel;
TAnimContainer *asAnimContainer;
TTrain *asTrain;
TDynamicObject *asDynamic;
TEvent *asEvent;
double asdouble;
int asInt;
sound_source *tsTextSound;
char *asText;
TCommandType asCommand;
TTractionPowerSource *psPower;
};
class TEvent // zmienne: ev*
{ // zdarzenie
public:
// types
// wrapper for binding between editor-supplied name, event, and execution conditional flag
using conditional_event = std::tuple<std::string, TEvent *, bool>;
// constructors
TEvent(std::string const &m = "");
~TEvent();
// metody
void Load(cParser *parser, Math3D::vector3 const &org);
// sends basic content of the class in legacy (text) format to provided stream
void
export_as_text( std::ostream &Output ) const;
static void AddToQuery( TEvent *Event, TEvent *&Start );
std::string CommandGet();
TCommandType Command();
double ValueGet(int n);
glm::dvec3 PositionGet() const;
bool StopCommand();
void StopCommandSent();
void Append(TEvent *e);
void
group( scene::group_handle Group );
scene::group_handle
group() const;
// members
std::string asName;
bool m_ignored { false }; // replacement for tp_ignored
bool bEnabled = false; // false gdy ma nie być dodawany do kolejki (skanowanie sygnałów)
int iQueued = 0; // ile razy dodany do kolejki
TEvent *evNext = nullptr; // następny w kolejce
TEventType Type = tp_Unknown;
double fStartTime = 0.0;
double fDelay = 0.0;
TDynamicObject const *Activator = nullptr;
TParam Params[13]; // McZapkie-070502 //Ra: zamienić to na union/struct
unsigned int iFlags = 0; // zamiast Params[8] z flagami warunku
std::string asNodeName; // McZapkie-100302 - dodalem zeby zapamietac nazwe toru
TEvent *evJoined = nullptr; // kolejny event z tą samą nazwą - od wersji 378
double fRandomDelay = 0.0; // zakres dodatkowego opóźnienia // standardowo nie będzie dodatkowego losowego opóźnienia
std::vector<conditional_event> m_children; // events which are placed in the query when this event is executed
bool m_conditionalelse { false }; // TODO: make a part of condition struct
private:
// methods
void Conditions( cParser *parser, std::string s );
// members
scene::group_handle m_group { null_handle }; // group this event belongs to, if any
};
inline
void
TEvent::group( scene::group_handle Group ) {
m_group = Group;
}
inline
scene::group_handle
TEvent::group() const {
return m_group;
}
class event_manager {
public:
// constructors
event_manager() = default;
// destructor
~event_manager();
// methods
// adds specified event launcher to the list of global launchers
void
queue( TEventLauncher *Launcher );
// legacy method, updates event queues
void
update();
// adds provided event to the collection. returns: true on success
// TBD, TODO: return handle to the event
bool
insert( TEvent *Event );
bool
insert( TEventLauncher *Launcher ) {
return m_launchers.insert( Launcher ); }
// returns first event in the queue
TEvent *
begin() {
return QueryRootEvent; }
// legacy method, returns pointer to specified event, or null
TEvent *
FindEvent( std::string const &Name );
// legacy method, inserts specified event in the event query
bool
AddToQuery( TEvent *Event, TDynamicObject const *Owner, double delay = 0.0 );
// legacy method, executes queued events
bool
CheckQuery();
// legacy method, initializes events after deserialization from scenario file
void
InitEvents();
// legacy method, initializes event launchers after deserialization from scenario file
void
InitLaunchers();
// sends basic content of the class in legacy (text) format to provided stream
void
export_as_text( std::ostream &Output ) const;
private:
// types
using event_sequence = std::deque<TEvent *>;
using event_map = std::unordered_map<std::string, std::size_t>;
using eventlauncher_sequence = std::vector<TEventLauncher *>;
// methods
// legacy method, verifies condition for specified event
bool
EventConditon( TEvent *Event );
// members
event_sequence m_events;
/*
// NOTE: disabled until event class refactoring
event_sequence m_eventqueue;
*/
// legacy version of the above
TEvent *QueryRootEvent { nullptr };
TEvent *m_workevent { nullptr };
event_map m_eventmap;
basic_table<TEventLauncher> m_launchers;
eventlauncher_sequence m_launcherqueue;
};
//---------------------------------------------------------------------------