-
Notifications
You must be signed in to change notification settings - Fork 51
/
command.h
503 lines (469 loc) · 12.5 KB
/
command.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*
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 <unordered_map>
#include <queue>
#include <unordered_set>
enum class user_command {
aidriverenable = 0,
aidriverdisable,
jointcontrollerset,
mastercontrollerincrease,
mastercontrollerincreasefast,
mastercontrollerdecrease,
mastercontrollerdecreasefast,
mastercontrollerset,
secondcontrollerincrease,
secondcontrollerincreasefast,
secondcontrollerdecrease,
secondcontrollerdecreasefast,
secondcontrollerset,
mucurrentindicatorothersourceactivate,
independentbrakeincrease,
independentbrakeincreasefast,
independentbrakedecrease,
independentbrakedecreasefast,
independentbrakeset,
independentbrakebailoff,
universalbrakebutton1,
universalbrakebutton2,
universalbrakebutton3,
trainbrakeincrease,
trainbrakedecrease,
trainbrakeset,
trainbrakecharging,
trainbrakerelease,
trainbrakefirstservice,
trainbrakeservice,
trainbrakefullservice,
trainbrakehandleoff,
trainbrakeemergency,
trainbrakebasepressureincrease,
trainbrakebasepressuredecrease,
trainbrakebasepressurereset,
trainbrakeoperationtoggle,
manualbrakeincrease,
manualbrakedecrease,
alarmchaintoggle,
alarmchainenable,
alarmchaindisable,
wheelspinbrakeactivate,
sandboxactivate,
autosandboxtoggle,
autosandboxactivate,
autosandboxdeactivate,
reverserincrease,
reverserdecrease,
reverserforwardhigh,
reverserforward,
reverserneutral,
reverserbackward,
waterpumpbreakertoggle,
waterpumpbreakerclose,
waterpumpbreakeropen,
waterpumptoggle,
waterpumpenable,
waterpumpdisable,
waterheaterbreakertoggle,
waterheaterbreakerclose,
waterheaterbreakeropen,
waterheatertoggle,
waterheaterenable,
waterheaterdisable,
watercircuitslinktoggle,
watercircuitslinkenable,
watercircuitslinkdisable,
fuelpumptoggle,
fuelpumpenable,
fuelpumpdisable,
oilpumptoggle,
oilpumpenable,
oilpumpdisable,
linebreakertoggle,
linebreakeropen,
linebreakerclose,
convertertoggle,
converterenable,
converterdisable,
convertertogglelocal,
converteroverloadrelayreset,
compressortoggle,
compressorenable,
compressordisable,
compressortogglelocal,
compressorpresetactivatenext,
compressorpresetactivateprevious,
compressorpresetactivatedefault,
motoroverloadrelaythresholdtoggle,
motoroverloadrelaythresholdsetlow,
motoroverloadrelaythresholdsethigh,
motoroverloadrelayreset,
universalrelayreset1,
universalrelayreset2,
universalrelayreset3,
notchingrelaytoggle,
epbrakecontroltoggle,
epbrakecontrolenable,
epbrakecontroldisable,
trainbrakeoperationmodeincrease,
trainbrakeoperationmodedecrease,
brakeactingspeedincrease,
brakeactingspeeddecrease,
brakeactingspeedsetcargo,
brakeactingspeedsetpassenger,
brakeactingspeedsetrapid,
brakeloadcompensationincrease,
brakeloadcompensationdecrease,
mubrakingindicatortoggle,
alerteracknowledge,
cabsignalacknowledge,
hornlowactivate,
hornhighactivate,
whistleactivate,
radiotoggle,
radioenable,
radiodisable,
radiochannelincrease,
radiochanneldecrease,
radiochannelset,
radiostopsend,
radiostopenable,
radiostopdisable,
radiostoptest,
radiocall3send,
radiovolumeincrease,
radiovolumedecrease,
radiovolumeset,
cabchangeforward,
cabchangebackward,
viewturn,
movehorizontal,
movehorizontalfast,
movevertical,
moveverticalfast,
moveleft,
moveright,
moveforward,
moveback,
moveup,
movedown,
nearestcarcouplingincrease,
nearestcarcouplingdisconnect,
nearestcarcoupleradapterattach,
nearestcarcoupleradapterremove,
occupiedcarcouplingdisconnect,
occupiedcarcouplingdisconnectback,
doortoggleleft,
doortoggleright,
doorpermitleft,
doorpermitright,
doorpermitpresetactivatenext,
doorpermitpresetactivateprevious,
dooropenleft,
dooropenright,
dooropenall,
doorcloseleft,
doorcloseright,
doorcloseall,
doorsteptoggle,
doormodetoggle,
mirrorstoggle,
departureannounce,
doorlocktoggle,
pantographcompressorvalvetoggle,
pantographcompressorvalveenable,
pantographcompressorvalvedisable,
pantographcompressoractivate,
pantographtogglefront,
pantographtogglerear,
pantographraisefront,
pantographraiserear,
pantographlowerfront,
pantographlowerrear,
pantographlowerall,
pantographselectnext,
pantographselectprevious,
pantographtoggleselected,
pantographraiseselected,
pantographlowerselected,
pantographvalvesupdate,
pantographvalvesoff,
heatingtoggle,
heatingenable,
heatingdisable,
lightspresetactivatenext,
lightspresetactivateprevious,
headlighttoggleleft,
headlightenableleft,
headlightdisableleft,
headlighttoggleright,
headlightenableright,
headlightdisableright,
headlighttoggleupper,
headlightenableupper,
headlightdisableupper,
redmarkertoggleleft,
redmarkerenableleft,
redmarkerdisableleft,
redmarkertoggleright,
redmarkerenableright,
redmarkerdisableright,
headlighttogglerearleft,
headlightenablerearleft,
headlightdisablerearleft,
headlighttogglerearright,
headlightenablerearright,
headlightdisablerearright,
headlighttogglerearupper,
headlightenablerearupper,
headlightdisablerearupper,
redmarkertogglerearleft,
redmarkerenablerearleft,
redmarkerdisablerearleft,
redmarkertogglerearright,
redmarkerenablerearright,
redmarkerdisablerearright,
redmarkerstoggle,
endsignalstoggle,
headlightsdimtoggle,
headlightsdimenable,
headlightsdimdisable,
motorconnectorsopen,
motorconnectorsclose,
motordisconnect,
interiorlighttoggle,
interiorlightenable,
interiorlightdisable,
interiorlightdimtoggle,
interiorlightdimenable,
interiorlightdimdisable,
compartmentlightstoggle,
compartmentlightsenable,
compartmentlightsdisable,
instrumentlighttoggle,
instrumentlightenable,
instrumentlightdisable,
dashboardlighttoggle,
dashboardlightenable,
dashboardlightdisable,
timetablelighttoggle,
timetablelightenable,
timetablelightdisable,
generictoggle0,
generictoggle1,
generictoggle2,
generictoggle3,
generictoggle4,
generictoggle5,
generictoggle6,
generictoggle7,
generictoggle8,
generictoggle9,
batterytoggle,
batteryenable,
batterydisable,
cabactivationtoggle,
cabactivationenable,
cabactivationdisable,
motorblowerstogglefront,
motorblowerstogglerear,
motorblowersdisableall,
coolingfanstoggle,
tempomattoggle,
springbraketoggle,
springbrakeenable,
springbrakedisable,
springbrakeshutofftoggle,
springbrakeshutoffenable,
springbrakeshutoffdisable,
springbrakerelease,
distancecounteractivate,
speedcontrolincrease,
speedcontroldecrease,
speedcontrolpowerincrease,
speedcontrolpowerdecrease,
speedcontrolbutton0,
speedcontrolbutton1,
speedcontrolbutton2,
speedcontrolbutton3,
speedcontrolbutton4,
speedcontrolbutton5,
speedcontrolbutton6,
speedcontrolbutton7,
speedcontrolbutton8,
speedcontrolbutton9,
inverterenable1,
inverterenable2,
inverterenable3,
inverterenable4,
inverterenable5,
inverterenable6,
inverterenable7,
inverterenable8,
inverterenable9,
inverterenable10,
inverterenable11,
inverterenable12,
inverterdisable1,
inverterdisable2,
inverterdisable3,
inverterdisable4,
inverterdisable5,
inverterdisable6,
inverterdisable7,
inverterdisable8,
inverterdisable9,
inverterdisable10,
inverterdisable11,
inverterdisable12,
invertertoggle1,
invertertoggle2,
invertertoggle3,
invertertoggle4,
invertertoggle5,
invertertoggle6,
invertertoggle7,
invertertoggle8,
invertertoggle9,
invertertoggle10,
invertertoggle11,
invertertoggle12,
globalradiostop,
timejump,
timejumplarge,
timejumpsmall,
setdatetime,
setweather,
settemperature,
vehiclemoveforwards,
vehiclemovebackwards,
vehicleboost,
debugtoggle,
focuspauseset,
pausetoggle,
entervehicle,
resetconsist,
fillcompressor,
consistreleaser,
queueevent,
setlight,
insertmodel,
deletemodel,
dynamicmove,
consistteleport,
pullalarmchain,
sendaicommand,
spawntrainset,
destroytrainset,
quitsimulation,
none = -1
};
enum class command_target {
userinterface,
/*
// NOTE: there's no need for consist- and unit-specific commands at this point, but it's a possibility.
// since command targets are mutually exclusive these don't reduce ranges for individual vehicles etc
consist = 0x4000,
unit = 0x8000,
*/
// values are combined with object id. 0xffff objects of each type should be quite enough ("for everyone")
vehicle = 0x10000,
signal = 0x20000,
entity = 0x40000,
simulation = 0x80000
};
enum class command_mode {
oneoff,
continuous
};
struct command_description {
std::string name;
command_target target;
command_mode mode;
};
struct command_data {
user_command command;
int action; // press, repeat or release
double param1;
double param2;
double time_delta;
bool freefly;
glm::vec3 location;
std::string payload;
};
// command_queues: collects and holds commands from input sources, for processing by their intended recipients
// NOTE: this won't scale well.
// TODO: turn it into a dispatcher and build individual command sequences into the items, where they can be examined without lookups
class command_queue {
public:
// types
typedef std::deque<command_data> commanddata_sequence;
typedef std::unordered_map<uint32_t, commanddata_sequence> commands_map;
// methods
// posts specified command for specified recipient into m_intercept_queue
void
push( command_data const &Command, uint32_t const Recipient );
// retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve
bool
pop( command_data &Command, uint32_t const Recipient );
// generates active continuous commands
void
update();
// checks if given command must be scheduled on server
bool
is_network_target(const uint32_t Recipient);
// pops commands from intercept queue
commands_map pop_intercept_queue();
// pushes commands into main queue
void push_commands(const commands_map &commands);
private:
// members
// contains command ready to execution
commands_map m_commands;
// contains intercepted commands to be read by application layer
commands_map m_intercept_queue;
void push_direct( command_data const &Command, uint32_t const Recipient );
// hash operator for m_active_continuous
struct command_set_hash {
uint64_t operator() (const std::pair<user_command, uint32_t> &pair) const {
return ((uint64_t)pair.first << 32) | ((uint64_t) pair.second);
}
};
// currently pressed continuous commands
std::unordered_set<std::pair<user_command, uint32_t>, command_set_hash> m_active_continuous;
};
template<typename A, typename B>
void add_to_dequemap(std::unordered_map<A, std::deque<B>> &lhs, const std::unordered_map<A, std::deque<B>> &rhs) {
for (auto const &kv : rhs) {
auto lookup = lhs.emplace(kv.first, std::deque<B>());
for (B const &data : kv.second)
lookup.first->second.emplace_back(data);
}
}
// NOTE: simulation should be a (light) wrapper rather than namespace so we could potentially instance it,
// but realistically it's not like we're going to run more than one simulation at a time
namespace simulation {
typedef std::vector<command_description> commanddescription_sequence;
extern command_queue Commands;
// TODO: add name to command map, and wrap these two into helper object
extern commanddescription_sequence Commands_descriptions;
}
// command_relay: composite class component, passes specified command to appropriate command stack
class command_relay {
public:
// methods
// posts specified command for the specified recipient
void
post(user_command const Command, double const Param1, double const Param2,
int const Action, uint16_t Recipient, glm::vec3 Position = glm::vec3(0.0f) , const std::string *Payload = nullptr) const;
private:
// types
// members
};
//---------------------------------------------------------------------------