18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 08:35:01 +01:00
Commit Graph

5 Commits

Author SHA1 Message Date
maj00r
1b26caca24 fix: inverted clamp bounds give the upper bound again, as the old clamp did (#412)
* fix: inverted clamp bounds give the upper bound again, as the old clamp did

The project's own clamp() of 26.05 applied the lower bound first and the
upper one last, so bounds given the wrong way round always gave the upper
one. Its calls became std::clamp (undefined for such bounds) and, where the
bounds can cross, safe_clamp, which swapped them instead. Neither gives the
old result.

- safe_clamp is the old clamp again, min(max(value, lo), hi). This restores
  26.05 at every place it is used, among them the AI's dynamic brake test
  (its demand was fAccThreshold x1.21, the swap made it x1.01), the
  generator voltage, the heavy cargo acceleration of the AI and the EP
  correction of the brake.
- The cab camera is kept inside the cab with safe_clamp. The bounds come
  from the .mmd as written and some cabs have them reversed (the B cars of
  SA134 and 21xM, ET40, 754); with std::clamp the camera jumped between
  the two bounds every frame on MSVC, as its result is fed back.

* fix: every call of the old clamp gives what it gave up to 26.05.1

d1f16411 (#99) made every call of the project's clamp() std::clamp. Where the bounds come from the data or
are computed at runtime they can cross, and then std::clamp gives another result (undefined behaviour;
MSVC gives the lower bound unless the value is above the upper one) where the old clamp gave the upper
bound. These calls use safe_clamp, the old clamp, too:

- Mover: the pantograph pressure (MaxPress), the compressor switch (CompressorListPosNo), the coupler
  distance (DmaxB, DmaxC), the engine revolutions, the eimic ramp (CtrlDelay), the eimic limit
  (eimic_max), the speed control ramp (PowerUpSpeed, PowerDownSpeed), the load (MaxLoad), the magnet of
  the security system (Dim.L);
- DynObj: the coupler distance of the buffers (DmaxB), the axle distance (Dim.L);
- Train: the brake handle positions (BrakeCtrlPosNo, the range of the handle);
- the legacy renderer: the mouse pick (the window size).

With the bounds in order nothing changes. Calls whose bounds the code keeps in order (constants,
SplineFidelity 1-4, the season table, the guarded output calibration) give the same result with
std::clamp and stay as they are.

The load offset takes its arguments in the 26.05.1 order again; fa2ed089 swapped them, which with the
old clamp differs only for a negative load.

The bump at a rail joint gives the old result again. Up to 26.05.1 its clamps had 0 in place of the
value (since 96f43e11 and 4d72d352), and the old clamp made that the headroom Vmax - (Vel + 0.32 Vmax),
negative above 68% of the top speed, capped from above only; d464628a and 03bfbb13 kept it at 0 or
above. Only damaged track has the bump: a damage flag in the .scn, a derailer set by an event, a track
made on a derailment.

The interior light of the cab in the 3.3 renderer is computed in double again, as before d1f16411.

The call added since (stepped_uc_value, 00955513) keeps what master does: bounds given the other way
round are put in order.

* fix: the alpha of a particle in the legacy renderer as up to 26.05.1, the NaN cases of the clamp tested

Up to 26.05.1 the alpha was clamp<std::uint8_t>( particle.opacity * 255, 0, 255 ): the float was
made a byte first, so the clamp did nothing and an opacity over 1 (a smoke max_opacity over 1)
wrapped round, 1.2 giving 50. The move to std::clamp made it 255. It's made a byte as then again,
through int: the byte the x86-64 compilers gave, without the undefined behaviour of that conversion
(MSVC makes the same two instructions of both). openglparticles.cpp goes with feat/gl46-migration;
its opengl33 counterpart, std::clamp( opacity, 0, 1 ), already gives what 26.05.1 gave.

The tests pin what the old clamp gave with NaN: a NaN value stays NaN, a NaN bound doesn't clamp.
The checks named after the AI braking test and the bump at a rail joint say they test the helper with
the arguments of those calls, not the calls.

* test: the includes of the clamp tests before the project's headers

<cmath> and <limits> go up, after the test headers, so the change no longer touches the lines
#416 adds its includes after. With both merged <cmath> is included twice, which is harmless.

---------

Co-authored-by: maj00r <maj00r@host>
2026-11-20 03:39:29 +01:00
maj00r
f9b7e9174c fix(files): terrain files named in another case are found on Linux
The terrain directive names .txtf/.btf files in lowercase, as the parser
gives every token. The name is now taken as it is on disk, from the text
file first, so the binary file is made next to the text and the editor's
references and layers keep one name.
2026-11-13 16:34:06 +01:00
maj00r
afbc84c6bc fix(files): the banks keep the names asked for, only the opening takes the case of the disk
The textures, materials and sounds are kept by the names they're asked for.
Given back as named on the disk, a file in another case missed the bank and
was loaded again on every request.

- FileExists with names and extensions finds the file in any case but gives
  back the name asked for; FileOnDisk gives the file to open, used where
  textures, sounds and scripts are opened
- FileExists of a single name is a plain check again, the places checking
  it and opening the same name stay as they were
- the texture format is told by the extension asked for again
- a folder changed shortly before it was read is read again for a name
  missing from it, the time of a change being as coarse as the clock of the
  file system; a listing cut short isn't kept
2026-11-13 15:47:52 +01:00
maj00r
d0a3694657 fix(files): data named in another case is found on Linux, folders included
The parser and the loaders lowercase every name they read, while the data
made on Windows has files and folders named in any case (scenery/Braniewo,
textures/siec_trakcyjna_ph/.../STS_*.tga, sounds/sip/Gorki.wav). FileCased
matched the file name only, so a folder in another case wasn't found.

- FileCased walks every part of the path on Linux, the folder listings kept
  by their lowercase and read again once the folder changed; Windows as it was
- FileExists finds the file in any case on Linux, and the variant with names
  and extensions gives back the name as it's on the disk, so textures,
  materials, sounds, station announcements and scripts open that name
- models, sound captions, timetables and nodebank previews open the file
  as it's named on the disk; the texture format is told by the extension in
  any case
2026-11-13 15:41:40 +01:00
jerrrrycho
5764692e89 test: characterize the helpers of utilities
The texts, numbers, random numbers, file names and times of utilities.cpp and utilities.h as they behave now. The table of Bezogonkow() is checked as the build has it: one byte for its plus-minus sign with MSVC, two with GCC and Clang, which give other letters.
2026-11-11 22:40:02 +01:00