mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 00:22:42 +01:00
af7744abda22f0a457ec3aa4545ce10453ff0cd8
9 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f65411a668 |
refactor(physics): the motion of the vehicle is private to it
The speed along the couplers, the location, the offsets from the track axis,
the accelerations, the distance counter and the distance moved since the last
check, the flat of the wheels and the truck hunting, the distance of the
derailment check, whether the vehicle is inside a consist and in the coupler
model, the analog demand of the integrated controller and the flow of the pipe
stabiliser are private to physics::Vehicle. TDynamicObject places and moves the
vehicle, the scenery puts road vehicles on their way and the contacts push them
through the operations (SetV(), SetLoc(), SetOffsetTrackH(), ...), and the
jolts of the track are ShakeVertically() and ShakeHorizontally(), the same
additions as before.
No change in behaviour: the golden traces recorded on
|
||
|
|
bc2af26dd5 |
refactor(physics): the compressed air supply and the pipes keep their state to themselves
The compressor, the main reservoir and the pipes along the train
(physics/components/airsupply.h) become classes, as the parts of the main
circuit: the definition in `config`, the state behind queries and operations.
The step of the compressor (the programmer of a unit, its supply and its start
delay, the governor and its lock, the venting over the top pressure) moves into
AirCompressor::Update(), with what it needs from the vehicle as plain values
(CompressorInputs); the vehicle follows the step up as before (the switching
delay, the counter of the debug panel, the sound of the relay). The leaks and
the pressure of the main reservoir move into AirSupply, and the reservoir is
filled and drawn through it.
The fault of the compressor the scenery can set no longer adds 100000001 to its
pressures from TDynamicObject::Damage(): AirCompressor::SetFault() does the same
arithmetic, so a fault behaves exactly as it did.
No change in behaviour: the golden traces recorded on
|
||
|
|
309926bb05 |
refactor(physics): the air supply and the pipes along the train as components
The air of physics::Vehicle becomes components of their own, with the fields
named in English (physics/components/airsupply.h):
air (AirSupply) the compressor and the main reservoir:
compressor (AirCompressor) MinCompressor, MaxCompressor and those of each
cab, CabDependentCompressor, CompressorSpeed,
CompressorPower, CompressorStartDelay,
CompressorTankValve, CompressorStart, the
CompressorList programmer and its switch, and
the state: CompressorFlag running,
CompressorAllow(Local) allow(Local),
CompressorGovernorLock, CompressorPowerTime
VeselVolume mainReservoirVolume
Compressor mainReservoirPressure
CompressedVolume compressedVolume
AirLeakRate leakRate
brakePipe, mainPipe the two pipes along the train, of one type,
(TrainPipe) TrainPipe: reservoir, pressure, couplersPending
(Pipe, PipePress, PipeCouplersPending and Pipe2,
ScndPipePress, ScndPipeCouplersPending before)
CompressorPower, a number 0 to 5, is the enum CompressorSupply (mainCircuit,
converterManual, converter, engine, frontUnitConverter, rearUnitConverter),
read from the same words of the .fiz. The CompressorList table is a
std::array of the same ints.
The exchange of air through the hoses (pneumatics.cpp) takes the pipe as one
TrainPipe of the vehicle instead of three member pointers.
No change in behaviour: 1149/1149 tests, golden traces exact against staging
|
||
|
|
d0387753f8 |
refactor(physics): TMoverParameters becomes physics::Vehicle, the mover is gone
The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:
physics/mover.h physics/vehicle.h
TMoverParameters physics::Vehicle (in namespace physics)
TDynamicObject::MoverParameters physics
mvOccupied, mvControlled occupied, controlled (TTrain, TController)
mvSecond, mvThird secondUnit, thirdUnit
mvPantographUnit pantographUnit
mover, Mover, movers physics, Physics, vehicles (locals, params)
m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
m_physics, otherPhysics, currentPhysics,
from_vehicles, renderPhysicsEventSounds
The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.
By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).
For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.
The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.
No change in behaviour: 1149/1149 tests, golden traces exact against staging
|
||
|
|
fbb9dc1e89 |
refactor(physics): the ends and the sides of a vehicle as scoped enums
end and side were unscoped enums: front, rear, left and right sat in the
global namespace (the test PCH had to leave mover.h out for it), and an end
went into any int, a side into an end, without a word from the compiler. They
become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the
names follow the rule for types, and leave "end" and "side" to the many
locals of that name. The numbers stay: front 0, rear 1, right 0, left 1.
- ByEnd<T> / BySide<T>: two values indexed by the enum, and by a number
where a loop or a format counts them. The arrays of the ends and the sides
are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights,
iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler,
m_couplersounds, m_mirrormotion, iInventory, and the voltages of the
couplers
- VehicleEnds / VehicleSides to go through them, Opposite() in place of
1 - end, NumberOf() where a number is needed
- the couplers and the collisions take the ends they work on as VehicleEnd:
CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit,
CompatibleCoupling and the rest of their family, DirF, DirPatch, and of
the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on;
Attach, Dettach and DettachStatus have overloads by the ends
- neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of
the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1
and 2 for "none" in places
The walks along the consist (FirstFind, Neighbour, the AI's coupling and
uncoupling) still carry the ends as numbers; where one of them meets a typed
end, NumberOf() and EndOf() say so, and keep the number as it was.
Kept as it was, and worth a look: TDynamicObject::SetLights() switches the
headlights A/B off by CabActive with the cases end::front and end::rear, that
is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are
NumberOf(VehicleEnd::front / rear) now, the same numbers.
No change in behaviour: 1144/1144 tests, golden traces exact against staging
|
||
|
|
2098614f8c |
refactor(physics): the couplings are Coupling and CouplingSet, not the bits of an int
What a coupling between two vehicles joins (the coupler, the brake hose, the
control cable, the high voltage...) was an int of bits, tested as
(flag & 36) == 36, (x & coupling::control) != 0, TestFlag(), SetFlag(x, -y),
compared with 0 and 3, with the same values twice (coupling:: and ctrain_).
- enum class Coupling (coupler, brakeHose, control, highVoltage, gangway,
mainHose, heating, permanent, power24v, power110v, power3x400v), the values
the scenery files and the definitions have always used; ctrain_* is gone
- CouplingSet, a set of them: HasAll(), HasAny(), Empty(), Set(), Clear()
(as SetFlag() and ClearFlag() worked), Without(), |, &, ^, ==, and a test
of any kind in a condition
- TCoupling's CouplingFlag, AllowedFlag, AutomaticCouplingFlag, PowerFlag and
PowerCoupling, TCommand's couplings (was Coupling), the coupling parameters
of the commands, Attach(), CompatibleCoupling(), Next(), Prev(),
FirstFind(), is_connected(), the AI's iCoupler are CouplingSet
- the numbers are read into a set where they come in: the .fiz (BuffCoupl,
negative AllowedFlag still meaning permanent), the scenery trainsets, the
AI's Connect command, InvCtrCplFlag; and written as numbers where they go
out: the scenery loader, the black box, the debug panels, DettachStatus()
- (CouplingFlag & 36) == 36 reads HasAll(Coupling::control | Coupling::mainHose)
No change in behaviour: 1144/1144 tests, golden traces exact against staging
|
||
|
|
c0bcdc23c7 | fix: Sonar on the brake pipe sub-steps: no shadowed enumerator, const test helper, template callback | ||
|
|
6ee2cc8eb8 |
fix: exchange the brake pipe air between vehicles after all of them stepped, in sub-steps
The air the brake hoses carry between the vehicles was taken explicitly inside each vehicle's step, at the physics step of 0.01 s. Through the hose between two 14 m freight wagons (Spg 0.792, 11.5 l of pipe) one step moved 11.8 l per bar, 2.06 times the 5.7 l that evens out the two pipes: the pipes overshot each other in turns and settled into a pattern in which every distributor saw the pipe up to 0.28 bar off the pressure left in it after the step. ESt3 valves charged at 5.0 bar saw 4.79 and lapped at the first stage, and the AI of a standing freight train never got its brakes released (the report of eu07/maszyna#368). The exchange now comes after every vehicle has stepped (vehicle_table::update_brake_pipes(), once per physics iteration), for the vehicles which stepped their pipe, in as many sub-steps as keep the air a hose carries in one below what evens out the pipes on its ends (3 for 14 m freight wagons, 2 for passenger cars), each going through the vehicles in the order they step. The distributors see the pressure the pipe holds, and an application reaches the end of the train as with a step of 0.001 s. |
||
|
|
466cbbbfa1 |
Test/core unit coverage (#235)
* test: real vehicles and golden traces in the unit tests The game's own vehicles (dynamic/ of the release used for the tests) as JSON of what the game's vehicle loader reads of their .fiz files, includes expanded: test_fiz.cpp converts them on demand and checks the loader reads the same sections, values and rows as of the game's file (fiz.h). Chosen to cover every engine type, brake valve, brake handle, local brake, coupler type, door type and brake delay set the game data uses. Golden traces (golden.h) characterise the simulation, compared within a relative tolerance or exactly, re-recorded with EU07_UNIT_TESTS_UPDATE_GOLDEN=1: - the parameters of every real vehicle as loaded, - the brakes of every real vehicle through charge, service steps, release, overcharge and emergency, on every brake delay setting, - every position of every driver's and local brake handle, - every powered vehicle started up the way the AI does it, driven to full power and braked to a stop (drive.h), - the real electric units and a locomotive with wagons driven whole, as trains of coupled vehicles stepped the way the game steps them (consist.h), - scenarios of the controls (scenario.h): doors, reversing and cab change, slip and sand, emergency stops, releasers, the ep and the electrodynamic brake, heating, loading, a collision, and frames of several physics iterations. * test: commands passed between vehicles Every command RunCommand knows run on every real vehicle and recorded, commands travelling through a train with a vehicle facing backwards, a coupling without the control cable, and loading and unloading by commands. * test: every switch of the cab, sent to the next vehicle Each switch sending its state to the train, each way and to each range, with the controllers and direction among them, on every real vehicle driving another of its kind, recorded for both. * test: the switches of the cab worked on a pair under the catenary The same switches with two seconds for the vehicles to act on each, so the pantographs rise, the main switch closes and the auxiliaries start. * test: gauges of trains in multiple and the damage descriptions The ammeters and the brake force the AI expects, recorded on the electric units and locomotives in multiple driven, the damage described on the driver's panel and ammeters showing the current of controlled vehicles. * test: give load commands their place, as the game does The loading test set its commands with SetInternalCommand, which leaves TCommand::Location as it is: uninitialised in a fresh vehicle, so the distance check of Load= and UnLoad= read garbage and the test failed now and then. The game gives them through PutCommand with the place of the platform, and so do the tests now. * test: brake valves and handles no vehicle of the game data has Fitted to a wagon and to an EU07: the valve variants and handles the loader knows that no real vehicle uses, the CV1 ones and the test handle among them, and a name the loader doesn't know. * test: braking from speed with the automatic ED brake, and a draisine Trains with the EP09, the E6ACT and the EW58 braked by ep, light and full service applications from speed, and the draisine pumped from rest and rolling. Only the E6ACT brings its electrodynamic brake in here. * test: the EP09's electrodynamic brake in service braking held to a stop start_up() took a vehicle for ready once its line breaker was closed and its reservoir full, which a train made already moving is at once: the EP09's manually started converter was never switched on, so there was no 110 V and no electrodynamic brake. It now waits for the converter. The EP09 with wagons is braked from 120 km/h by light, medium, high and full service applications held to a stop: the motors brake, the air of its cylinders is let out and given back as the train slows down. The flag of the electrodynamic brake stays on at a standstill below 2.1 bar. C strings given to CAPTURE are shown as text. * test: the converter switched on before a train is ready, the EW58's ep-staged electrodynamic brake start_up() called a train ready as soon as its line breaker closed and the air was there, so the converter of a unit having it in another car than the cab (the EW58's middle car) was never switched on, and its electrodynamic brake, gated by the 110 V, never came in. The converter and the compressor now always get switched on first. The EW58 brakes electrically by the stages of the ep brake, not by the pipe alone. * test: the ET42 and the 214M railbus among the real vehicles The ET42's halves (its own series motor branch: the motors in series at the high current setting) and the 214MA, a diesel railbus with the hydraulic torque converter, the retarder and the controller of an induction motor drive, converted from the game data and recorded in every sweep of the real vehicles. * test: the wagons' hand brakes released with the train's brakes; the 754, SM31 and SU46 release_brakes() released the hand brake of the driver's vehicle only, so every wagon set up braked kept its hand brake on and got dragged along. It now releases the hand and spring brakes of the whole train, as TController::AutoRewident() does when the AI takes it over, and the traces of the trains with wagons are recorded anew. The 754, the SM31 and the SU46 join the real vehicles for the kinds of the diesel-electrics' field shunting relays the others lack (RelayType 0, 1 and 46). * test: traction on a lost and too high catenary voltage, the ET42, the diesel-electrics' shunting relays The line breaker opened by the voltage relays of a series motor locomotive and by the limits of an induction motor one. The ET42 at the high current setting, which keeps its halves' motors in series, and its switched electrodynamic brake, whose current trips the overload relay from the top speed of the low setting. The field shunting of the diesel-electrics through each kind of their relays, at full power and notched back. * test: the EW58's electrodynamic brake stages, the EU47's speed control and braking at the voltage's limit The stages of the EW58's motor brake set by the positions of its ep handle, the first one alone over 100 km/h. The EU47's second controller holding, raising and lowering the speed set, its local brake setting the flag of the electrodynamic brake without the motors braking, and its brake feeding back less current into a catenary over the drive's MaxV. * test: diesel engines too cold and too hot to start, the 214M railbus's controller and retarder The heat of the diesel engines: at -10 degrees the ones with the lowest water temperature set don't start until the heater warms them, at 88 degrees the ones with a second water circuit don't start while it cools, and the SM42 run hot at full power is kept under its highest temperature by its fans and shutters. The 214M railbus's controller from the air brake through the retarder and neutral to power, its torque converter's lock-up and its gearbox. The controller helpers of the traction tests (full power, waiting for the line contactors, and notching back) move to test::scenario. * test: couplers coupled, uncoupled, broken and colliding; loads assigned, loaded and unloaded Coupling by hand touching or apart and of the same kind or not, with the sounds of what changes; uncoupling a screw coupler pressed together, stretched, with the hoses alone or broken; the automatic couplers of electric units coupling on contact, without the control cable between two kinds; a coupler broken with its brake hose; collisions over 15 km/h derailing. The pantographs set up by the pantstate load, a load of one kind at a time up to the capacity, and the steps of loading and unloading. * test: the battery drained and charged, the pantographs' tank and pressure switch, the 214M's speed control The EU07's battery drained without the converter by the lights and the small compressor until it opens the line breaker and nothing starts, charged by the converter, and switched off. The pantographs on their own leaking tank until the pressure switch opens the line breaker, and the small compressor pumping it up and priming the switch. The 214M railbus's speed control set by its buttons, steps and power limit, braking down with the retarder, and standing by. * test: the MHZ handles' buttons, the valves at speed, every brake material, the NESt3's relays The overload and the high pressure buttons of the MHZ handles. The KE and the LSt at speed in the R and P settings, under the anti-slip request and the releaser button. Every material of the brake shoes and disks the loader takes, braking a wagon from speed, the ones no game vehicle has among them. The CV1_R and the Oerlikon valve's relays set by its name (-ED, AL2 without ESt3) fitted to a wagon. * test: the loader's lists and lines: the 218M, SA134 and 22WEc, a compressor list, Pmax by speed, skipped lines The 218M (V2NList), the SA134 (HTCList) and the Elf 22WEc (ffBrakeList) join the real vehicles for the lists the others lack. Definitions made by the tests for what no game file has: a compressor list, whose table of whole numbers reads a factor of 0.9 as 0; the compressor's limits apart for the rear cab; the highest power of an induction motor drive by the speed, extrapolated past the table; and the lines the loader skips or trims (comments, a hash anywhere, leading spaces, carriage returns). * test: what the cab and the AI call on a vehicle: gauges of the train, the split ED brake, spring brake, cut-off The engine rotation of up to three vehicles in multiple and the lamps of the overload relay and the starting resistors read through the control cable; the engine's idle speed and the ET42's second controller shown in its dynamic brake; the controller of the electrodynamic brake apart from the local brake, which no game vehicle has yet; the spring brake shut off and released, the ep brake's fuse and the handle stepped by the AI; damaged motors cut off; the cab activated by itself; a road vehicle moved across a road, for which the tests' track gets a width; and the lamps and the buzzer of the security system left unattended. * test: the EP05 and its camshaft among the real vehicles, the headlights' colour and brightness The EP05, whose camshaft closes the line breaker and the line contactors by the camshaft's own position, converted from the game data and recorded in every sweep of the real vehicles. The Headlights section, which only the 214M's own file has, in a definition made by the test. * test: what the unit tests reach of the simulation core, what's dead or left, and what they found COVERAGE.md: the blocks of Mover.cpp, hamulce.cpp, Oerlikon_ESt.cpp and friction.cpp the tests run, the code nothing in the game runs, the code only data no game vehicle has would run, what's reachable and left, and the behaviour the tests found that may deserve a look. * test: check invariants of the physics on every step of every golden trace Rules any vehicle keeps whatever a test does (no NaN, cylinders and pipes within their limits, no current with the line breaker or contactors open, no force without power, distance as the speed runs, no acceleration over 5 g), checked on every step, with no comparison to a recorded file. The traces where a test or a game vehicle breaks one are excused with the reason; the vehicles' cases are in the findings of COVERAGE.md. * test: key figures of every golden trace, per part of the run Duration, speeds, distance, time to stop, the brake pipe's lowest pressure and time to recover, the peaks of the cylinders, the motor current and the tractive force, for each part between two events, in data/golden/<name>.figures. Compared within 0.5% or the last decimal, so they hold on any compiler, and an intended change of behaviour shows in a few readable lines. Traces sampled by hand keep none. * test: keep the golden samples out of the repository, recorded on the code before a change The samples of the golden traces are 29 MB and only mean something against the code before the change they check, so they're recorded locally before it (EU07_UNIT_TESTS_UPDATE_GOLDEN=1) and compared after it, and ignored by git. The key figures and the invariants stay, and are what the CI checks. Without samples recorded a trace compares only its key figures, but with EU07_UNIT_TESTS_GOLDEN_EXACT=1, the check of a change which shouldn't alter anything, it fails, so the check can't pass by having nothing to compare. * fix: draw the noise of the control pipe pressure in one order on every compiler The order of the two Random(10) calls in 'Random(10) - Random(10)' is unspecified: GCC draws them the other way round than MSVC Release, which mirrored the control pipe pressure around 5 bar and failed 32 unit tests on the Linux CI. The draws are sequenced in the order of MSVC Release, which the golden traces were recorded with. * test: count the start-up rounds with an integer, not a double (SonarCloud S2193) * test: behaviour in CHECKs, the key figures out of the repository The key figures of the golden traces are recorded with their samples on the code before a change, and compared after it, instead of being kept: a trace without them checks the invariants and its test's CHECKs, which is what the CI runs. The scenarios of the controls state what they show in CHECKs, and the runs of every real vehicle what holds for each of them. Writing them showed scenarios which didn't do what they were named for: the cab change stopped in the engine room, the slip runs put the controller to full power at once and never got the line contactors closed, and the train stopped by the alarm chain never got its pipe charged again. They do it now; the rest went to the findings. * test: the SonarCloud findings in the unit tests std::format for the texts put together, emplace_back, const references, string_view parameters, std::array and std::vector for the C arrays, the ranges algorithms, names no longer shadowing the coupler ends, comments in the empty loops; start_up(), trace::check() and the converter of the definitions split up. BrakeForceR() is const, which it always was in effect, so the gauges test needs no const_cast. The golden traces compare bit for bit. |