forked from tmj-fstate/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 16
/
command.cpp
358 lines (339 loc) · 21.3 KB
/
command.cpp
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
/*
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/.
*/
#include "stdafx.h"
#include "command.h"
#include "Globals.h"
#include "Logs.h"
#include "Timer.h"
#include "utilities.h"
namespace simulation {
command_queue Commands;
commanddescription_sequence Commands_descriptions = {
{ "aidriverenable", command_target::vehicle, command_mode::oneoff },
{ "aidriverdisable", command_target::vehicle, command_mode::oneoff },
{ "jointcontrollerset", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerincrease", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerincreasefast", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerdecrease", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerdecreasefast", command_target::vehicle, command_mode::oneoff },
{ "mastercontrollerset", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerincrease", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerincreasefast", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerdecrease", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerdecreasefast", command_target::vehicle, command_mode::oneoff },
{ "secondcontrollerset", command_target::vehicle, command_mode::oneoff },
{ "mucurrentindicatorothersourceactivate", command_target::vehicle, command_mode::oneoff },
{ "independentbrakeincrease", command_target::vehicle, command_mode::continuous },
{ "independentbrakeincreasefast", command_target::vehicle, command_mode::oneoff },
{ "independentbrakedecrease", command_target::vehicle, command_mode::continuous },
{ "independentbrakedecreasefast", command_target::vehicle, command_mode::oneoff },
{ "independentbrakeset", command_target::vehicle, command_mode::oneoff },
{ "independentbrakebailoff", command_target::vehicle, command_mode::oneoff },
{ "universalbrakebutton1", command_target::vehicle, command_mode::oneoff },
{ "universalbrakebutton2", command_target::vehicle, command_mode::oneoff },
{ "universalbrakebutton3", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeincrease", command_target::vehicle, command_mode::continuous },
{ "trainbrakedecrease", command_target::vehicle, command_mode::continuous },
{ "trainbrakeset", command_target::vehicle, command_mode::oneoff },
{ "trainbrakecharging", command_target::vehicle, command_mode::oneoff },
{ "trainbrakerelease", command_target::vehicle, command_mode::oneoff },
{ "trainbrakefirstservice", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeservice", command_target::vehicle, command_mode::oneoff },
{ "trainbrakefullservice", command_target::vehicle, command_mode::oneoff },
{ "trainbrakehandleoff", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeemergency", command_target::vehicle, command_mode::oneoff },
{ "trainbrakebasepressureincrease", command_target::vehicle, command_mode::oneoff },
{ "trainbrakebasepressuredecrease", command_target::vehicle, command_mode::oneoff },
{ "trainbrakebasepressurereset", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeoperationtoggle", command_target::vehicle, command_mode::oneoff },
{ "manualbrakeincrease", command_target::vehicle, command_mode::oneoff },
{ "manualbrakedecrease", command_target::vehicle, command_mode::oneoff },
{ "alarmchaintoggle", command_target::vehicle, command_mode::oneoff },
{ "wheelspinbrakeactivate", command_target::vehicle, command_mode::oneoff },
{ "sandboxactivate", command_target::vehicle, command_mode::oneoff },
{ "autosandboxtoggle", command_target::vehicle, command_mode::oneoff },
{ "autosandboxactivate", command_target::vehicle, command_mode::oneoff },
{ "autosandboxdeactivate", command_target::vehicle, command_mode::oneoff },
{ "reverserincrease", command_target::vehicle, command_mode::oneoff },
{ "reverserdecrease", command_target::vehicle, command_mode::oneoff },
{ "reverserforwardhigh", command_target::vehicle, command_mode::oneoff },
{ "reverserforward", command_target::vehicle, command_mode::oneoff },
{ "reverserneutral", command_target::vehicle, command_mode::oneoff },
{ "reverserbackward", command_target::vehicle, command_mode::oneoff },
{ "waterpumpbreakertoggle", command_target::vehicle, command_mode::oneoff },
{ "waterpumpbreakerclose", command_target::vehicle, command_mode::oneoff },
{ "waterpumpbreakeropen", command_target::vehicle, command_mode::oneoff },
{ "waterpumptoggle", command_target::vehicle, command_mode::oneoff },
{ "waterpumpenable", command_target::vehicle, command_mode::oneoff },
{ "waterpumpdisable", command_target::vehicle, command_mode::oneoff },
{ "waterheaterbreakertoggle", command_target::vehicle, command_mode::oneoff },
{ "waterheaterbreakerclose", command_target::vehicle, command_mode::oneoff },
{ "waterheaterbreakeropen", command_target::vehicle, command_mode::oneoff },
{ "waterheatertoggle", command_target::vehicle, command_mode::oneoff },
{ "waterheaterenable", command_target::vehicle, command_mode::oneoff },
{ "waterheaterdisable", command_target::vehicle, command_mode::oneoff },
{ "watercircuitslinktoggle", command_target::vehicle, command_mode::oneoff },
{ "watercircuitslinkenable", command_target::vehicle, command_mode::oneoff },
{ "watercircuitslinkdisable", command_target::vehicle, command_mode::oneoff },
{ "fuelpumptoggle", command_target::vehicle, command_mode::oneoff },
{ "fuelpumpenable", command_target::vehicle, command_mode::oneoff },
{ "fuelpumpdisable", command_target::vehicle, command_mode::oneoff },
{ "oilpumptoggle", command_target::vehicle, command_mode::oneoff },
{ "oilpumpenable", command_target::vehicle, command_mode::oneoff },
{ "oilpumpdisable", command_target::vehicle, command_mode::oneoff },
{ "linebreakertoggle", command_target::vehicle, command_mode::oneoff },
{ "linebreakeropen", command_target::vehicle, command_mode::oneoff },
{ "linebreakerclose", command_target::vehicle, command_mode::oneoff },
{ "convertertoggle", command_target::vehicle, command_mode::oneoff },
{ "converterenable", command_target::vehicle, command_mode::oneoff },
{ "converterdisable", command_target::vehicle, command_mode::oneoff },
{ "convertertogglelocal", command_target::vehicle, command_mode::oneoff },
{ "converteroverloadrelayreset", command_target::vehicle, command_mode::oneoff },
{ "compressortoggle", command_target::vehicle, command_mode::oneoff },
{ "compressorenable", command_target::vehicle, command_mode::oneoff },
{ "compressordisable", command_target::vehicle, command_mode::oneoff },
{ "compressortogglelocal", command_target::vehicle, command_mode::oneoff },
{ "compressorpresetactivatenext", command_target::vehicle, command_mode::oneoff },
{ "compressorpresetactivateprevious", command_target::vehicle, command_mode::oneoff },
{ "compressorpresetactivatedefault", command_target::vehicle, command_mode::oneoff },
{ "motoroverloadrelaythresholdtoggle", command_target::vehicle, command_mode::oneoff },
{ "motoroverloadrelaythresholdsetlow", command_target::vehicle, command_mode::oneoff },
{ "motoroverloadrelaythresholdsethigh", command_target::vehicle, command_mode::oneoff },
{ "motoroverloadrelayreset", command_target::vehicle, command_mode::oneoff },
{ "notchingrelaytoggle", command_target::vehicle, command_mode::oneoff },
{ "epbrakecontroltoggle", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeoperationmodeincrease", command_target::vehicle, command_mode::oneoff },
{ "trainbrakeoperationmodedecrease", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeedincrease", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeeddecrease", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeedsetcargo", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeedsetpassenger", command_target::vehicle, command_mode::oneoff },
{ "brakeactingspeedsetrapid", command_target::vehicle, command_mode::oneoff },
{ "brakeloadcompensationincrease", command_target::vehicle, command_mode::oneoff },
{ "brakeloadcompensationdecrease", command_target::vehicle, command_mode::oneoff },
{ "mubrakingindicatortoggle", command_target::vehicle, command_mode::oneoff },
{ "alerteracknowledge", command_target::vehicle, command_mode::oneoff },
{ "hornlowactivate", command_target::vehicle, command_mode::oneoff },
{ "hornhighactivate", command_target::vehicle, command_mode::oneoff },
{ "whistleactivate", command_target::vehicle, command_mode::oneoff },
{ "radiotoggle", command_target::vehicle, command_mode::oneoff },
{ "radiochannelincrease", command_target::vehicle, command_mode::oneoff },
{ "radiochanneldecrease", command_target::vehicle, command_mode::oneoff },
{ "radiostopsend", command_target::vehicle, command_mode::oneoff },
{ "radiostoptest", command_target::vehicle, command_mode::oneoff },
{ "radiocall3send", command_target::vehicle, command_mode::oneoff },
// TBD, TODO: make cab change controls entity-centric
{ "cabchangeforward", command_target::vehicle, command_mode::oneoff },
{ "cabchangebackward", command_target::vehicle, command_mode::oneoff },
{ "viewturn", command_target::entity, command_mode::oneoff },
{ "movehorizontal", command_target::entity, command_mode::oneoff },
{ "movehorizontalfast", command_target::entity, command_mode::oneoff },
{ "movevertical", command_target::entity, command_mode::oneoff },
{ "moveverticalfast", command_target::entity, command_mode::oneoff },
{ "moveleft", command_target::entity, command_mode::oneoff },
{ "moveright", command_target::entity, command_mode::oneoff },
{ "moveforward", command_target::entity, command_mode::oneoff },
{ "moveback", command_target::entity, command_mode::oneoff },
{ "moveup", command_target::entity, command_mode::oneoff },
{ "movedown", command_target::entity, command_mode::oneoff },
// TBD, TODO: make coupling controls entity-centric
{ "carcouplingincrease", command_target::vehicle, command_mode::oneoff },
{ "carcouplingdisconnect", command_target::vehicle, command_mode::oneoff },
{ "doortoggleleft", command_target::vehicle, command_mode::oneoff },
{ "doortoggleright", command_target::vehicle, command_mode::oneoff },
{ "doorpermitleft", command_target::vehicle, command_mode::oneoff },
{ "doorpermitright", command_target::vehicle, command_mode::oneoff },
{ "doorpermitpresetactivatenext", command_target::vehicle, command_mode::oneoff },
{ "doorpermitpresetactivateprevious", command_target::vehicle, command_mode::oneoff },
{ "dooropenleft", command_target::vehicle, command_mode::oneoff },
{ "dooropenright", command_target::vehicle, command_mode::oneoff },
{ "dooropenall", command_target::vehicle, command_mode::oneoff },
{ "doorcloseleft", command_target::vehicle, command_mode::oneoff },
{ "doorcloseright", command_target::vehicle, command_mode::oneoff },
{ "doorcloseall", command_target::vehicle, command_mode::oneoff },
{ "doorsteptoggle", command_target::vehicle, command_mode::oneoff },
{ "doormodetoggle", command_target::vehicle, command_mode::oneoff },
{ "departureannounce", command_target::vehicle, command_mode::oneoff },
{ "doorlocktoggle", command_target::vehicle, command_mode::oneoff },
{ "pantographcompressorvalvetoggle", command_target::vehicle, command_mode::oneoff },
{ "pantographcompressoractivate", command_target::vehicle, command_mode::oneoff },
{ "pantographtogglefront", command_target::vehicle, command_mode::oneoff },
{ "pantographtogglerear", command_target::vehicle, command_mode::oneoff },
{ "pantographraisefront", command_target::vehicle, command_mode::oneoff },
{ "pantographraiserear", command_target::vehicle, command_mode::oneoff },
{ "pantographlowerfront", command_target::vehicle, command_mode::oneoff },
{ "pantographlowerrear", command_target::vehicle, command_mode::oneoff },
{ "pantographlowerall", command_target::vehicle, command_mode::oneoff },
{ "heatingtoggle", command_target::vehicle, command_mode::oneoff },
{ "heatingenable", command_target::vehicle, command_mode::oneoff },
{ "heatingdisable", command_target::vehicle, command_mode::oneoff },
{ "lightspresetactivatenext", command_target::vehicle, command_mode::oneoff },
{ "lightspresetactivateprevious", command_target::vehicle, command_mode::oneoff },
{ "headlighttoggleleft", command_target::vehicle, command_mode::oneoff },
{ "headlightenableleft", command_target::vehicle, command_mode::oneoff },
{ "headlightdisableleft", command_target::vehicle, command_mode::oneoff },
{ "headlighttoggleright", command_target::vehicle, command_mode::oneoff },
{ "headlightenableright", command_target::vehicle, command_mode::oneoff },
{ "headlightdisableright", command_target::vehicle, command_mode::oneoff },
{ "headlighttoggleupper", command_target::vehicle, command_mode::oneoff },
{ "headlightenableupper", command_target::vehicle, command_mode::oneoff },
{ "headlightdisableupper", command_target::vehicle, command_mode::oneoff },
{ "redmarkertoggleleft", command_target::vehicle, command_mode::oneoff },
{ "redmarkerenableleft", command_target::vehicle, command_mode::oneoff },
{ "redmarkerdisableleft", command_target::vehicle, command_mode::oneoff },
{ "redmarkertoggleright", command_target::vehicle, command_mode::oneoff },
{ "redmarkerenableright", command_target::vehicle, command_mode::oneoff },
{ "redmarkerdisableright", command_target::vehicle, command_mode::oneoff },
{ "headlighttogglerearleft", command_target::vehicle, command_mode::oneoff },
{ "headlighttogglerearright", command_target::vehicle, command_mode::oneoff },
{ "headlighttogglerearupper", command_target::vehicle, command_mode::oneoff },
{ "redmarkertogglerearleft", command_target::vehicle, command_mode::oneoff },
{ "redmarkertogglerearright", command_target::vehicle, command_mode::oneoff },
{ "redmarkerstoggle", command_target::vehicle, command_mode::oneoff },
{ "endsignalstoggle", command_target::vehicle, command_mode::oneoff },
{ "headlightsdimtoggle", command_target::vehicle, command_mode::oneoff },
{ "headlightsdimenable", command_target::vehicle, command_mode::oneoff },
{ "headlightsdimdisable", command_target::vehicle, command_mode::oneoff },
{ "motorconnectorsopen", command_target::vehicle, command_mode::oneoff },
{ "motorconnectorsclose", command_target::vehicle, command_mode::oneoff },
{ "motordisconnect", command_target::vehicle, command_mode::oneoff },
{ "interiorlighttoggle", command_target::vehicle, command_mode::oneoff },
{ "interiorlightenable", command_target::vehicle, command_mode::oneoff },
{ "interiorlightdisable", command_target::vehicle, command_mode::oneoff },
{ "interiorlightdimtoggle", command_target::vehicle, command_mode::oneoff },
{ "interiorlightdimenable", command_target::vehicle, command_mode::oneoff },
{ "interiorlightdimdisable", command_target::vehicle, command_mode::oneoff },
{ "instrumentlighttoggle", command_target::vehicle, command_mode::oneoff },
{ "instrumentlightenable", command_target::vehicle, command_mode::oneoff },
{ "instrumentlightdisable", command_target::vehicle, command_mode::oneoff },
{ "dashboardlighttoggle", command_target::vehicle, command_mode::oneoff },
{ "timetablelighttoggle", command_target::vehicle, command_mode::oneoff },
{ "generictoggle0", command_target::vehicle, command_mode::oneoff },
{ "generictoggle1", command_target::vehicle, command_mode::oneoff },
{ "generictoggle2", command_target::vehicle, command_mode::oneoff },
{ "generictoggle3", command_target::vehicle, command_mode::oneoff },
{ "generictoggle4", command_target::vehicle, command_mode::oneoff },
{ "generictoggle5", command_target::vehicle, command_mode::oneoff },
{ "generictoggle6", command_target::vehicle, command_mode::oneoff },
{ "generictoggle7", command_target::vehicle, command_mode::oneoff },
{ "generictoggle8", command_target::vehicle, command_mode::oneoff },
{ "generictoggle9", command_target::vehicle, command_mode::oneoff },
{ "batterytoggle", command_target::vehicle, command_mode::oneoff },
{ "batteryenable", command_target::vehicle, command_mode::oneoff },
{ "batterydisable", command_target::vehicle, command_mode::oneoff },
{ "motorblowerstogglefront", command_target::vehicle, command_mode::oneoff },
{ "motorblowerstogglerear", command_target::vehicle, command_mode::oneoff },
{ "motorblowersdisableall", command_target::vehicle, command_mode::oneoff },
{ "coolingfanstoggle", command_target::vehicle, command_mode::oneoff },
{ "tempomattoggle", command_target::vehicle, command_mode::oneoff },
{ "springbraketoggle", command_target::vehicle, command_mode::oneoff },
{ "springbrakeenable", command_target::vehicle, command_mode::oneoff },
{ "springbrakedisable", command_target::vehicle, command_mode::oneoff },
{ "springbrakeshutofftoggle", command_target::vehicle, command_mode::oneoff },
{ "springbrakeshutoffenable", command_target::vehicle, command_mode::oneoff },
{ "springbrakeshutoffdisable", command_target::vehicle, command_mode::oneoff },
{ "springbrakerelease", command_target::vehicle, command_mode::oneoff }
};
} // simulation
void command_queue::update()
{
double delta = Timer::GetDeltaTime();
for (user_command c : m_active_continuous)
{
auto const &desc = simulation::Commands_descriptions[ static_cast<std::size_t>( c ) ];
command_data data { c, GLFW_REPEAT, 0, 0, delta };
auto lookup = m_commands.emplace((size_t)desc.target, commanddata_sequence() );
lookup.first->second.emplace( data );
}
}
// posts specified command for specified recipient
void
command_queue::push( command_data const &Command, std::size_t const Recipient ) {
auto const &desc = simulation::Commands_descriptions[ static_cast<std::size_t>( Command.command ) ];
if (desc.mode == command_mode::continuous)
{
if (Command.action == GLFW_PRESS)
m_active_continuous.emplace(Command.command);
else if (Command.action == GLFW_RELEASE)
m_active_continuous.erase(Command.command);
else if (Command.action == GLFW_REPEAT)
return;
}
auto lookup = m_commands.emplace( Recipient, commanddata_sequence() );
// recipient stack was either located or created, so we can add to it quite safely
lookup.first->second.emplace( Command );
}
// retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve
bool
command_queue::pop( command_data &Command, std::size_t const Recipient ) {
auto lookup = m_commands.find( Recipient );
if( lookup == m_commands.end() ) {
// no command stack for this recipient, so no commands
return false;
}
auto &commands = lookup->second;
if( true == commands.empty() ) {
return false;
}
// we have command stack with command(s) on it, retrieve and pop the first one
Command = commands.front();
commands.pop();
return true;
}
void
command_relay::post( user_command const Command, double const Param1, double const Param2,
int const Action, std::uint16_t const Recipient) const {
auto const &command = simulation::Commands_descriptions[ static_cast<std::size_t>( Command ) ];
if( ( command.target == command_target::vehicle )
&& ( true == FreeFlyModeFlag )
&& ( ( false == DebugModeFlag )
&& ( true == Global.RealisticControlMode ) ) ) {
// in realistic control mode don't pass vehicle commands if the user isn't in one, unless we're in debug mode
return;
}
simulation::Commands.push(
command_data{
Command,
Action,
Param1,
Param2,
Timer::GetDeltaTime()},
static_cast<std::size_t>( command.target ) | Recipient );
/*
#ifdef _DEBUG
if( Action != GLFW_RELEASE ) {
// key was pressed or is still held
if( false == command.name.empty() ) {
if( false == (
( Command == user_command::moveleft )
|| ( Command == user_command::moveleftfast )
|| ( Command == user_command::moveright )
|| ( Command == user_command::moverightfast )
|| ( Command == user_command::moveforward )
|| ( Command == user_command::moveforwardfast )
|| ( Command == user_command::moveback )
|| ( Command == user_command::movebackfast )
|| ( Command == user_command::moveup )
|| ( Command == user_command::moveupfast )
|| ( Command == user_command::movedown )
|| ( Command == user_command::movedownfast )
|| ( Command == user_command::movevector )
|| ( Command == user_command::viewturn ) ) ) {
WriteLog( "Command issued: " + command.name );
}
}
}
else {
// key was released (but we don't log this)
WriteLog( "Key released: " + command.name );
}
#endif
*/
}
//---------------------------------------------------------------------------