18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 06:35:21 +01:00
Files
maszyna/tests/unit/consist.h
jerrrrycho a1a988d753 test: the trains of the hose exchange kept from one step to the next against ones worked out in every step
One train, a locomotive with five freight wagons on a gradient, stepped twice from the same seed: as the game
steps it, the trains of the hoses kept in the cache, and with them worked out again in every step
(test::consist::keep_hose_trains(false)). Charged, braked, the last two wagons uncoupled, released: with
Global.physics_sleepheld the wagons held by their brakes fall asleep and wake on the way, so the trains change
with the uncoupling and with the vehicles going to sleep and waking. The pipes, the reservoirs of the hoses and
the brake cylinders of the two are bitwise the same after every step. A cache which is never laid out again
after its first step fails it (10203 differences).
2026-12-01 17:28:55 +01:00

67 lines
3.0 KiB
C++

#pragma once
#include <cstddef>
#include <memory>
#include <vector>
#include "vehicle.h"
#include "physics/components/hosetrains.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;
// whether the trains of the hose exchange are kept from one step to the next, as the game keeps them (the default), or
// worked out again in every step
void keep_hose_trains(bool Keep) { m_keephosetrains = Keep; }
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;
// the trains of the hoses kept from one step to the next, as vehicle_table::update_brake_pipes() keeps them
mutable physics::hose_trains_cache m_hosetrains;
bool m_keephosetrains{true};
};
} // namespace test