18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 05:57:08 +01:00
Commit Graph

16 Commits

Author SHA1 Message Date
Hirek 1bea280010 refactor(physics): the line breaker, the line contactors, the relays and the converter as components
The main circuit of physics::Vehicle becomes components, with English names
(physics/components/maincircuit.h):

  lineBreaker (LineBreaker)     Mains closed, MainsInitTime(Countdown)
                                initTime / initCountdown, MainsStart start,
                                JointEngineStart jointStart,
                                PantographsRequireMains pantographsRequireIt,
                                LineBreakerClosesOnlyAtNoPowerPos
                                closesOnlyAtNoPower,
                                EmergencyBrakeMainOffPressure emergencyOffPressure
  lineContactors (LineContactors) StLinFlag closed, StLinSwitchOff forcedOpen,
                                StLinSwitchType switchType,
                                LineContactorsInterlock interlock,
                                LastRelayTime lastSwitchTime
  protection (ProtectionRelays) NoVoltRelay noVoltage, OvervoltageRelay
                                overvoltage, GroundRelay(Start) ground(Start),
                                ControlPressureSwitch pressureSwitch,
                                HasControlPressureSwitch hasPressureSwitch,
                                PressureSwitchBrakeCylinder
                                pressureSwitchWatchesCylinders
  converter (PowerConverter)    the Converter* fields: start, startDelay(Timer),
                                allow(Local), running, overloadRelayStart,
                                overloadRelayOffWithLineBreaker; ConvOvldFlag
                                overloaded, ConvSwitchType switchType

The long comments of the fields went with them into the header. Where the
loading of the .fiz has using enum start_t, the member is this->converter:
the enumerator start_t::converter would hide it there.

No string literal changed (checked over all the changed files).

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-29 02:50:50 +01:00
Hirek 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
62f7a29b.
2026-11-28 23:56:46 +01:00
Hirek 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
62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed.
2026-11-28 18:32:58 +01:00
Hirek 54d3a1040a refactor(physics): EnumSet<E> for the sets of flags; the damage of a vehicle is VehicleDamage and DamageSet
- utilities/enumset.h: EnumSet<E>, a set of the values of an enum class whose
  values are bits, with the operations CouplingSet had (HasAll, HasAny,
  Empty, Set, Clear, Without, |, &, ^, ==, FromBits, Bits). CouplingSet is
  EnumSet<Coupling> now; an enum is a kind of the sets by IsEnumSetKind<E>,
  which gives it its operator |.
- the damage of a vehicle (DamageFlag) is a DamageSet of VehicleDamage
  instead of the int and the dtrain_* constants. A bit means one thing for a
  locomotive and another for a wagon; both names are there (thinWheel and
  loadShift, ventilator and loadDamage, engine and loadDestroyed).
- the SetDamage command of the scenery adds or takes away the damage by its
  number as SetFlag() did (setOrClear()); "WRECKED" is still the set of the
  number 255; the bearing divisor of the resistance stays the number 4.
- the damage of the tracks and of the catenary (dtrack_*, the traction's
  DamageFlag) are other flags and stay as they were.

No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b.
2026-11-28 01:22:57 +01:00
Hirek 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
62f7a29b.
2026-11-27 23:20:53 +01:00
Hirek e5639e9d48 refactor(physics): the commands between the vehicles are VehicleCommand, not text
The vehicles of a train passed their commands to each other as strings
(SendCtrlToNext("MainCtrl", ...)), and RunCommand() found out what to do by
comparing the text with 54 names. A misspelt name compiled and did nothing.

- physics/vehiclecommand.h/.cpp: enum class VehicleCommand, one value for
  each command a vehicle knows, plus none and unknown; ParseVehicleCommand()
  reads a text, VehicleCommandName() gives the name back
- SendCtrlToNext(), SetInternalCommand(), RunCommand() and its groups take
  VehicleCommand; Load= and UnLoad= carry the name of the load as the
  argument of RunCommand()
- the text is read once, where a command comes as text: PutCommand() (the
  events, Lua, the AI). TCommand keeps that text, as the AI reads the
  commands it knows itself (SetVelocity...) from it
- two commands sent but known to no vehicle stay as they were, passed on and
  not done: EpFuseSwitch and SandboxAutoAllow
- removed the unused GetExternalCommand(), CommandOut, ValueOut and
  CommandLast (written, never read)
- the names are the ones the sceneries and scripts have always used, compared
  exactly; new tests check that every command reads back from its name

No change in behaviour: 1144/1144 tests (2 new), golden traces exact against
staging 62f7a29b.
2026-11-27 20:40:13 +01:00
Hirek 5a537e69f2 refactor(physics): McZapkie/ becomes physics/, its files get English names
The folder of the vehicle physics was named after the author of its first
version (2001). Its name now says what it holds, and so do its files:

  McZapkie/MOVER.h, Mover.cpp       -> physics/mover.h, mover.cpp
  McZapkie/hamulce.h, hamulce.cpp   -> physics/brakes.h, brakes.cpp
  McZapkie/Oerlikon_ESt.h, .cpp     -> physics/oerlikonest.h, .cpp
  friction, collision, couplerphysics, derailment: same names in physics/

Every include names the folder ("physics/mover.h"); the McZapkie include
directory is gone from CMakeLists.txt. The comments and documents that
named the old paths name the new ones. The credits to McZapkie stay.

Renames only: git sees every file as renamed (98-100%). 1142/1142 tests,
golden traces exact against staging 62f7a29b.
2026-11-27 17:11:46 +01:00
jerrrrycho f90005e649 fix(physics): a legacy derailment makes no crash inside its own train
With physics.collisions new and the legacy derailment (the default
physics.derailment monitor), a vehicle derailed the old way manufactured
collisions with the vehicles coupled to it:

- Derail() cuts its speed by 35 % in one step; the coupled vehicles kept
  theirs and ran into it at a third of the speed of the train
  (moczniki_eu06_eu07, tomaszewo_raj49843). The vehicles coupled to it
  now get the same change of velocity.
- crush_hit() took it as an immovable wall and its motion ignored every
  force (decelerating at g, then stuck by resistances x1e20), so the
  train behind it stopped against it at once and crushed by the energy
  of the whole train (l053-sluzba-2-night: 0.3 m on both ends at 8 km/h).
  It is now a wall only to vehicles not coupled to it; it keeps the
  legacy deceleration of g as a friction of its weight, and the forces
  of its train act on it, so the train pushes it on and it holds the
  train back. Alone it stops as before.
- Vehicles of the pile-up found inside each other kept what their
  springs took in pressed past the stop as buffer energy, which let a
  later small closing velocity crush them; a pair parting at the start of
  the step and knocked back in during it was crushed with the springs
  added to its closing velocity (l053_calkowo-sluzba-tlk-1,
  linia61_osobowy3: crush at -7.1 km/h). The contact found inside each
  other takes in nothing until the buffers part, and a pair parting at
  the start of the step is left to the legacy collision.

The monitor test of a locomotive into a wagon at 60 km/h now counts one
hit: the second one was the locomotive resting on the legacy wall,
parting at the start of the step, at 0.3 km/h.
2026-11-17 17:36:15 +01:00
jerrrrycho d9c72e3d7c fix(physics): a repaired vehicle has its crushed ends rebuilt and its collision derailment cleared
Neither resetconsist nor the repair of a coupler cleared what a collision left: the crush of the ends (which keeps
shifting the stop of the buffers in CouplerForce() and in the pair input of the coupler physics, so the next hit of
the repaired consist started past it and sooner over the override threshold), the energy of the contact, the hit of
the step and the reports of the log; nor the reason of a derailment in a collision and the state of the push off.

repair_damage() rebuilds both ends of the vehicle, rerail() clears CollisionDerail and the push off monitor along with
the state of the criteria of derailment (so SetDamage taking dtrain_out off does as well), and the repair of a coupler
rebuilds its end, the crush past the draw gear having torn it off.
2026-11-16 07:56:12 +01:00
jerrrrycho c774a1ff1c fix(physics): a pushed wheel climbs the rail over the distance it rolls, not over a time at a stand
check_pushed_off() counted the time Y/Q of the leading wheel stayed over the climbing limit, at any speed: a locomotive
at its starting effort pressing a braked rake pushed the empty wagon in front of it off the rails in five steps of
0.01 s without it moving, and an 80 t locomotive running onto a free empty 3WL at 9 km/h pushed it off with the
half-sine of its buffer springs (565 kN for some 0.06 s, over the climbing limit past about 400 kN in a curve of
150 m).

Nadal's limit is that of a wheel rolling under its angle of attack: the creep of the flange contact turns the friction
upwards, helping the flange up. A wheel that doesn't roll has the friction against the lift, and with a flange of 70
degrees and a friction over 1 / tan 70 = 0.36 no lateral force gets it up. So the flange now climbs over the distance
the wheels roll with Y/Q over the limit without a break, the 2 m window of the criteria of derailment (the window of
EN 14363; the climb distance criteria replaced the 50 ms of AAR Chapter XI for the same reason). A hit counts the
distance rolled over the time its peak lasted. A push which takes the whole load off the leading wheels lifts them off
the rail, rolling or not: that, held for 0.05 s, still derails the vehicle by the time.

collision::pushed_forces() gives Y and Q of the wheel (pushed_ratio() their ratio), pushed_monitor counts the climb
over the distance and the lift over the time. Tests: both cases of the review stay on the rails (the ST44 pressing at
386 kN, Y/Q 1.29 in a yard curve of 120 m, the 3WL moving 0.11 m; the EU07 at 9 km/h, 565 kN, Y/Q 1.68 for 8 steps), a
heavy train propelling an empty 3WL into a braked rake in a curve of 150 m still pushes it off as it slides on.
2026-11-16 07:56:12 +01:00
jerrrrycho c554fff1ae test(physics): the coaches of the Baltyk case at their masses of the log, 36 t and 41.6 t 2026-11-16 01:17:08 +01:00
jerrrrycho b5a0a8121d fix(physics): vehicles put down inside each other don't crush; automatic couplers have no side buffers
The rerun of calkowo_v2_kontenera with the energy budget still crushed and overrode its two
locomotives, at 9-13 km/h: the scenery puts the SM42 onto the SU45 with their middles 2.7 m
apart. The springs at the stops of both ends and the neighbours found at either end shake
such a pair up past the energy of the buffers. Pressed past the stop of their buffers and the
crush of their ends by more than 0.5 m (more than a hit takes them in a step), the pair is
inside each other: no crush, the legacy collision pushes them apart, and the log tells it once
(Bad scenery: A and B are inside each other ...).

An automatic coupler, or its adapter, has no buffers at the side: its draft gear takes in what
its springs of the .fiz do, so the budget leaves no EN 15551 capacity to such a pair. The
EN57-2000 hitting a standing one at 20 km/h (en57_2000_crush_new) crushes again.

The PoC cases of the energy budget, for the record: 15 km/h straight crushes 3 ends (0.18 m)
where it crushed 2 (0.16 m), the same empty pushed off; at 25-40 km/h fewer ends deep in the
trains crush on the straight, a few more in the curve, the locomotive overrides in all of them.
2026-11-16 01:00:36 +01:00
jerrrrycho 0f61567bcb fix(physics): only the energy of a hit past the buffers of EN 15551 crushes the ends
Found running every scenario of the install with physics.collisions new: two locomotives
(SU45 117 t, SM42 84 t) put down by calkowo_v2_kontenera inside each other crushed both their
ends at 5 km/h right after the start, deeper hit after hit, until both overrode (0.60 m); in
baltyk_sdm the coaches of a train pushed into a vehicle derailed at the end of the track (a
wall) crushed at 5-8 km/h. Some 50 kJ of relative motion, which the buffers take in with room
to spare. The crush went by the closing velocity at the stop of the buffers alone: buffers
pressed all the way from the start of the contact (put down overlapping, or knocked onto each
other by a hit elsewhere) left the whole hit to the underframes, every step anew.

Each pair now counts the energy of its contact (collision::contact_energy): what the springs
of the buffers take in while they're pressed and the pair closes in, kept down to what they
hold once they spring back, reset when they part. A hit may crush only what it brings to the
stop past what the buffers of EN 15551 of both ends would take in, by their BufferCategory
(the key now also gives that energy) or 30 kJ a buffer by default:

    budget = 1/2 mu v^2 - max(0, capacity - absorbed)

collision::hit() stops the crush once its work reaches the budget, the rest springs back.
The crush of a whole hit thus never takes more than the hit brought past the buffers; a train
behind pushing the pair on brings in more through the velocity of the next step. The monitor
goes by the same budget. The log of a crush tells the energies.

Pressing alone, a locomotive pushing a braked train at a stand, and vehicles put down
overlapping don't crush. The crash cases keep crushing: the hits of two masses, EU07 into a
430W, the EN 15227 units at 36 km/h and the 15 km/h PoC cases as before; at 25-40 km/h fewer
ends deep in the trains crush (the buffers of the couplings there take in their energy).
2026-11-16 00:26:18 +01:00
jerrrrycho 8070f79a3a feat(physics): physics.collisions new|old|monitor, apart from the model of the derailment
The crush of the ends, the override and the push off the track went by physics.derailment new. They have a switch of
their own now, physics.collisions, new by default: the derailment in a curve and the collisions can each be new or the
legacy ones. old is exactly the legacy rule of the safe closing speed weighed by the masses. monitor runs as old, and
for a hit on the buffers the crush model would not take elastically it logs once what the crush of the whole hit would
be (collision monitor: the closing speed, the crush of each end, the force, whether the draw gear tears off and which
vehicle would ride up onto the other one), without changing anything. The push off the track is not monitored: it
builds up from the crushed ends of the new model. The road vehicles keep the legacy rule with any value.

The tests that pin the legacy collisions pin physics.collisions old.
2026-11-15 20:09:57 +01:00
jerrrrycho 65fa4a1cc6 fix(physics): the traffic of the roads keeps the legacy collisions; the log of a crush tells what it went by
Found running line 107 with every train driven by the AI: two cars of its
traffic (Fiat 126p, Skoda 1100) met head-on at 119 km/h. With physics.derailment
new they bounced off each other elastically: their couplers have no steel to
speak of, so the steel took the hit and the legacy rule of 15 km/h was off. The
crush of the ends is for rail vehicles now; road vehicles keep the legacy rule
and derail as before.

The log of a crushed end, of an override and of a push off the track tells the
masses and the kinds of the vehicles, the crush and the force each end gives
at, the force of the hit and of the springs, the closing velocity and the
force, time and Y/Q of a push.
2026-11-15 13:32:08 +01:00
jerrrrycho 369f58a04a feat(physics): collisions crush the ends of the vehicles, override and push them off the track
With physics.derailment new, CollisionDetect() hands a hit on the stop of the
buffers harder than the steel takes elastically to crush_hit() (collision.h):

- the weaker end crushes for good at its crush force, the vehicles take the
  limited impulse, the depth stays with the end (TCoupling::crush) and lets the
  buffers of the pair meet closer, in both models of the coupling
- the crush lets the lighter vehicle, or the one with its buffers higher, climb
  onto the other one; the end crushed by 0.15 m tears off its draw gear, with
  the brake hose both parts of the train brake in emergency, and an automatic
  coupler torn off doesn't couple again
- after the collisions of each step the force pressing the ends pushes a light
  vehicle off the track by Y / Q held for 0.05 s
- off the rails in a collision the vehicle is upright off the rails as by the
  criteria of the speed: it slides with the friction of the ballast and keeps
  taking the hits and passing the forces on, instead of standing as a wall.
  CollisionDerail and the log tell the override from the push off; a crushed
  end logs the collision

It works in CollisionDetect(), which both models of the coupling reach once
their buffers go solid, so the trains of the AI the physical model of the
coupling doesn't cover crush alike. Hits the steel takes, and the draw gear
going solid, stay the legacy collision. physics.derailment old and off keep
the legacy collisions: the rule of 15 km/h weighed by the masses, the chance
of the coupler smashed, a derailed vehicle a wall; the tests of that rule run
with old.

The buffers of a category of EN 15551 and the crush, crash zone, anticlimber
and buffer height of an end are new optional keys of BuffCoupl.
2026-11-15 12:41:41 +01:00