mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 08:17:09 +01:00
d0387753f8
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.
58 lines
2.4 KiB
C++
58 lines
2.4 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "vehicle.h"
|
|
|
|
#include <fstream>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using test::definition;
|
|
using test::vehicle;
|
|
|
|
// the field shunting step a position of the master controller selects (RList, its sixth column ScndAct) indexes the
|
|
// motor parameter table, MotorParam, which has MotorParametersArraySize + 1 entries. The loader takes ScndAct from the
|
|
// .fiz as it is, so the readers of the table (physics::Vehicle::Momentum(), MomentumF(), TController::ESMVelocity())
|
|
// go through motor_param(), which keeps the index inside the table
|
|
|
|
namespace {
|
|
|
|
// the RList rows of the EP09 with the ScndAct of the first position replaced
|
|
nlohmann::ordered_json ep09_rlist_with_scndact(std::string const &Scndact) {
|
|
std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/fiz/ep09_v2/104e.json"};
|
|
REQUIRE(file.good());
|
|
// '=' rather than braces: GCC takes a json in braces for an initializer list, an array holding it
|
|
auto const ep09 = nlohmann::ordered_json::parse(file);
|
|
auto rows = ep09.at("RList").at("rows");
|
|
REQUIRE(rows.size() > 1);
|
|
rows[1][5] = Scndact;
|
|
return rows;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("motor parameters: the ScndAct of an RList row is read from the .fiz as it is") {
|
|
vehicle ep09{definition::fiz("ep09_v2/104e")};
|
|
// the first position of the EP09 runs on field shunting step 2
|
|
CHECK(ep09->RList[1].ScndAct == 2);
|
|
CHECK(&ep09->motor_param(ep09->RList[1].ScndAct) == &ep09->MotorParam[2]);
|
|
|
|
// a .fiz giving a step beyond the table: nothing checks it on loading
|
|
vehicle broken{definition::fiz("ep09_v2/104e").set("RList", "rows", ep09_rlist_with_scndact("20"))};
|
|
CHECK(broken->RList[1].ScndAct == 20);
|
|
CHECK(broken->RList[1].ScndAct > MotorParametersArraySize);
|
|
}
|
|
|
|
TEST_CASE("motor parameters: motor_param() keeps a step from the .fiz inside the table") {
|
|
vehicle broken{definition::fiz("ep09_v2/104e").set("RList", "rows", ep09_rlist_with_scndact("20"))};
|
|
auto const &table{broken->MotorParam};
|
|
// past the end: the last entry, rather than memory beyond the table
|
|
CHECK(&broken->motor_param(broken->RList[1].ScndAct) == &table[MotorParametersArraySize]);
|
|
CHECK(&broken->motor_param(MotorParametersArraySize + 1) == &table[MotorParametersArraySize]);
|
|
// below the start: the first entry
|
|
CHECK(&broken->motor_param(-1) == &table[0]);
|
|
// inside the table: the entry itself
|
|
for (int step = 0; step <= MotorParametersArraySize; ++step) {
|
|
CHECK(&broken->motor_param(step) == &table[step]);
|
|
}
|
|
}
|