18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 19:57:06 +01:00
Files
maszyna/tests/unit/figures.h
T
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

71 lines
2.3 KiB
C++

#pragma once
#include <string>
#include <vector>
#include "physics/vehicle.h"
namespace test {
// the key figures of a vehicle's run, for each part of it between two events of the test: the speeds, the
// distance, the time to stop, the brake pipe's lowest pressure and the time it took to get back, the brake
// cylinders', the motor current's and the tractive force's peaks. a golden trace keeps them next to its
// samples, in data/golden/<Name>.figures, which a person reads:
//
// [emergency]
// duration = 40.00 s
// speed at the start = 80.0 km/h
// speed at the end = 0.0 km/h
// distance = 412.3 m
// stopped after = 38.21 s
// brake cylinders peak = 3.800 bar
//
// a figure the vehicle doesn't have (no speed, no current) is left out of all the parts. they're compared
// within 0.5%, loose enough for any compiler, so a change which alters the behaviour on purpose shows in their
// diff in a few readable lines, where the samples change in thousands
class figures {
public:
// called on every step of the vehicle
void sample(double Time, physics::Vehicle const &Vehicle);
// a part of the run starts with the event
void mark(std::string const &Event);
// the figures as the lines of the file
std::vector<std::string> lines() const;
// the differences of the lines from the recorded ones, beyond the tolerance, each told in a line
static std::vector<std::string> compare(std::vector<std::string> const &Recorded, std::vector<std::string> const &Now);
private:
struct part {
std::string event;
bool sampled{false};
double start{0.0};
double end{0.0};
double speed_start{0.0};
double speed_end{0.0};
double speed_peak{0.0};
double distance_start{0.0};
double distance_end{0.0};
double stopped{-1.0}; // after the start, if it started moving and stopped
double pipe_lowest{0.0};
double pipe_end{0.0};
double pipe_back{-1.0}; // after the start, at 4.9 bar again after a drop under 4.8
double cylinders_peak{0.0};
double current_peak{0.0};
double force_peak{0.0};
};
std::vector<part> m_parts{part{"start"}};
double m_last_time{-1.0};
double m_last_speed{0.0};
double m_last_distance{0.0};
// the figures the vehicle has, shown in every part
bool m_moved{false};
bool m_piped{false};
bool m_braked{false};
bool m_current{false};
bool m_force{false};
};
} // namespace test