18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 17:37:09 +01:00
Files
maszyna/tests/unit/consist.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

59 lines
2.6 KiB
C++

#pragma once
#include <cstddef>
#include <memory>
#include <vector>
#include "vehicle.h"
class TDynamicObject;
namespace test {
// vehicles coupled into a train on a straight track, all facing forward, from the front one back, stepped the
// way vehicle_table::update() steps the vehicles of the game: the constants and neighbours of all of them,
// their forces, then their movement. couplers carry the forces, the air, the control and the power between
// the vehicles as in the game:
// test::consist en57;
// en57.add(definition::fiz("en57_v1/5bgb"), 1); // driven from the front cab
// en57.add(definition::fiz("en57_v1/6ba_840"));
// en57.add(definition::fiz("en57_v1/5bgb"));
class consist {
public:
// everything a coupler can join, as two vehicles of a train coupled by a crew
static constexpr CouplingSet full_coupling{Coupling::coupler | Coupling::brakeHose | Coupling::mainHose | Coupling::control | Coupling::gangway | Coupling::heating |
Coupling::permanent | Coupling::power110v | Coupling::power24v | Coupling::highVoltage};
consist();
~consist();
consist(consist const &) = delete;
consist &operator=(consist const &) = delete;
// a vehicle at the back of the train, its front coupler joined to the rear one of the last vehicle with
// the given coupling (coupling flags), Gap [m] between their buffers. Cab as for a vehicle. a vehicle
// with no coupling (Coupling::none) is free on the same track, as one about to be coupled or hit
vehicle &add(definition const &Definition, int Cab = 0, CouplingSet couplings = full_coupling, double Velocity = 0.0, double Gap = 0.0);
vehicle &operator[](std::size_t Index) { return *m_vehicles[Index]; }
std::size_t size() const { return m_vehicles.size(); }
void step(track const &Track = {}, double Dt = 0.01);
void run(double Seconds, track const &Track = {}, double Dt = 0.01);
// distance between the couplers of the vehicle and the one behind it [m], negative when the buffers press
double gap(std::size_t Index) const;
private:
void update_neighbours();
void update_brake_pipes(double Dt) const;
std::vector<std::unique_ptr<vehicle>> m_vehicles;
std::vector<double> m_positions; // of the vehicles' middles along the track
// the physics reaches a neighbouring vehicle through its TDynamicObject, for its physics alone.
// the game's object can't be made without the rest of the game, so it's a stand-in: storage of its size
// with that one member set, never constructed, which only the physics ever looks into
std::vector<std::vector<std::byte>> m_objects;
};
} // namespace test