mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 00:59:18 +02:00
fix(cab): the line contactors lamp goes out with the pressure switch (eu07/maszyna#470) The lamp of the open line contactors, which tells the start can be made, went out at 1 bar in the brake cylinders, while the pressure switch cuts the start off only at 2 bar (or below 3.6 bar in the main pipe), so with the brakes partly applied the start could be made with the lamp out. With a pressure switch fitted the lamp now follows it; without one it goes out at 1 bar as before. The same holds for the lamp of the second unit, which used to keep its last state between 1 bar and the cut-off. The condition is TMoverParameters::LineContactorsLampLit(). Tests: tests/unit/test_line_contactors.cpp. refactor: Sonar findings of PR 217 - horn_supply::pneumatic shadowed the pneumatic enumerator of the sound flags (cpp:S1117), it's horn_supply::air; the supplies read with using enum (S6177), - CouplerForce(): the automatic coupling refused or caught without another level of nested ifs (S134), the same outcome: too fast, the coupling is locked; caught, coupled and locked; otherwise left to try again, - CompressorCheck(): the power the compressor doesn't draw yet noted without a TODO (S1135), - tests: the previous crash damage setting in an in-class initializer (S3230), the loops which stop early with break rather than in their conditions (S886), the stand-ins of test::pair in a std::vector rather than an array (S5945), units in the comments of the example without /* */ (S1103). test: the cases the changes of the branch left without a test - Cntrl.: BDelay1 to BDelay4 reach the brake delays (now through std::format), the default start types of the ground and converter overload relays of a multiple unit and of other vehicles (out of the nested conditionals), - the compressor: fed from the low voltage it waits from the low voltage coming on; the pressure switch stops it above the cut-out pressure, without one the excess air is vented (the vented fraction rewritten), - the horns: a vehicle without any air sounds as before, the threshold pressure, an electric horn on 110 V, - the positions of a cab control below zero, and a control without position sounds. refactor(cab): the kind of the train heating switch as a flag Read once with the vehicle definition, rather than compared as text in each of the switch commands. feat(cab): train heating switch springing back (MaSzyna-EU07/maszyna#85) TrainHeating=[toggle]|impulse in the Switches: section of the vehicle definition makes the train heating switch an unstable one: it goes up to switch the heating on, down to switch it off, and back to the middle once let go, instead of staying where it was put. The position of such a switch isn't set from the heating state when the cab is entered. Tests: tests/unit/test_switches.cpp. feat(sound): mirror sounds (MaSzyna-EU07/maszyna#84, eu07/maszyna#322) The sound definitions of a vehicle (.mmd) take mirroropen: and mirrorclose:, played as a mirror sets off unfolding or folding, and the locations section mirrors: <offset>... end, the offsets along the vehicle of the mirror pairs, as for the doors (negative ahead of the centre), each pair at the sides of the vehicle. As the animation, only the mirrors at the occupied cab sound. The start of a move is mirror_moves::motion in vehicle/mirrors.h. Tests: tests/unit/test_mirrors.cpp. feat(cab): joint oil and fuel pump switch (MaSzyna-EU07/maszyna#81) A cab control oilfuelpump_sw: switches both the oil and the fuel pump at once, with the new command oilfuelpumptoggle (no key by default). As a two-state switch it turns both pumps off when both are on and both on otherwise; as an impulse switch it's held to start them, like the separate pump switches. Its position follows the pumps when the cab is entered. refactor(editor): text fields filled without strncpy (MaSzyna-EU07/maszyna#112) The last three strncpy calls Sonar flags (cpp:S5816), in the road and track editors, copy the text into the ImGui field buffers with std::string::copy and terminate it right after; the text gets cut to the buffer as before. fix: automatic coupler crashes, horns, compressor start delay, radio and cab lever sounds - automatic couplers don't catch above the safe collision speed (#86): with crash damage on they couple at a closing speed of 15 km/h at most, a faster hit locks the coupling until the vehicles part and the collision runs its course. On the way: CollisionVelocity() read a head-on 10 + 10 km/h as 14.1 km/h (quaternions turn by half the angle), it's now taken from the touching ends; CollisionDetect() took the other vehicle's speed the wrong way round for vehicles facing each other. Head-on hits now derail sooner, at the intended limit, - a single horn lever can't sound both tones at once (eu07/maszyna#392), - a skid ends once the vehicle stops on locked wheels (eu07/maszyna#479), - electronic destination signs are blanked at the end of the timetable (eu07/maszyna#446), - horns need the air or the voltage to sound (eu07/maszyna#290, #76): HornType=[Pneumatic]|Electric and Horn3Type in Cntrl.; a pneumatic horn needs 0.2 MPa in the main reservoir (or the main pipe without one), an electric one the low voltage; the lever stays where it was put, - compressor start delay (#67): CompressorStartDelay [s] in Brake., counted from the compressor getting its power, after the engine starts say; none by default, - the channel and volume buttons of a radio without power do nothing (eu07/maszyna#429); the power check of the radio is TMoverParameters::RadioPowered(), - a lever moved smoothly sounds the positions it passes (#83). Sonar findings in the functions changed: nesting, nested conditionals, commented-out code, std::format, references to const. Unit tests: test::pair for two vehicles running into each other, test_couplers, test_horn, test_wheelslip, test_compressor, test_radio, test_gauge_positions.
539 lines
12 KiB
C++
539 lines
12 KiB
C++
/*
|
|
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,
|
|
dynamicbrakecontrollerincrease,
|
|
dynamicbrakecontrollerdecrease,
|
|
dynamicbrakecontrollerset,
|
|
dynamicbrakecontrollerincreasefast,
|
|
dynamicbrakecontrollerdecreasefast,
|
|
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,
|
|
radiocall1send,
|
|
radiocall3send,
|
|
radiovolumeincrease,
|
|
radiovolumedecrease,
|
|
radiovolumeset,
|
|
cabchangeforward,
|
|
cabchangebackward,
|
|
|
|
modernlightdimmerdecrease,
|
|
modernlightdimmerincrease,
|
|
|
|
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,
|
|
generictoggle10,
|
|
generictoggle11,
|
|
generictoggle12,
|
|
generictoggle13,
|
|
generictoggle14,
|
|
generictoggle15,
|
|
generictoggle16,
|
|
generictoggle17,
|
|
generictoggle18,
|
|
generictoggle19,
|
|
generictoggle20,
|
|
generictoggle21,
|
|
generictoggle22,
|
|
generictoggle23,
|
|
generictoggle24,
|
|
generictoggle25,
|
|
generictoggle26,
|
|
generictoggle27,
|
|
generictoggle28,
|
|
generictoggle29,
|
|
|
|
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,
|
|
wiperswitchincrease,
|
|
wiperswitchdecrease,
|
|
lightsset,
|
|
oilfuelpumptoggle,
|
|
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
|
|
using commanddata_sequence = std::deque<command_data>;
|
|
using commands_map = std::unordered_map<uint32_t, commanddata_sequence>;
|
|
// 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) const;
|
|
|
|
// 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 {
|
|
|
|
using commanddescription_sequence = std::vector<command_description>;
|
|
|
|
extern command_queue Commands;
|
|
// TODO: add name to command map, and wrap these two into helper object
|
|
extern commanddescription_sequence Commands_descriptions;
|
|
|
|
extern std::unordered_map<std::string, user_command> const commandMap;
|
|
}
|
|
|
|
// 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;
|
|
// types
|
|
// members
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|