mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 08:17:09 +01:00
fbb9dc1e89
end and side were unscoped enums: front, rear, left and right sat in the
global namespace (the test PCH had to leave mover.h out for it), and an end
went into any int, a side into an end, without a word from the compiler. They
become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the
names follow the rule for types, and leave "end" and "side" to the many
locals of that name. The numbers stay: front 0, rear 1, right 0, left 1.
- ByEnd<T> / BySide<T>: two values indexed by the enum, and by a number
where a loop or a format counts them. The arrays of the ends and the sides
are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights,
iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler,
m_couplersounds, m_mirrormotion, iInventory, and the voltages of the
couplers
- VehicleEnds / VehicleSides to go through them, Opposite() in place of
1 - end, NumberOf() where a number is needed
- the couplers and the collisions take the ends they work on as VehicleEnd:
CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit,
CompatibleCoupling and the rest of their family, DirF, DirPatch, and of
the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on;
Attach, Dettach and DettachStatus have overloads by the ends
- neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of
the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1
and 2 for "none" in places
The walks along the consist (FirstFind, Neighbour, the AI's coupling and
uncoupling) still carry the ends as numbers; where one of them meets a typed
end, NumberOf() and EndOf() say so, and keep the number as it was.
Kept as it was, and worth a look: TDynamicObject::SetLights() switches the
headlights A/B off by CabActive with the cases end::front and end::rear, that
is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are
NumberOf(VehicleEnd::front / rear) now, the same numbers.
No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed.
97 lines
3.7 KiB
C++
97 lines
3.7 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "vehicle.h"
|
|
|
|
// the cab interior light set by the positions of the light preset selector: an optional third column of LightsList,
|
|
// 1 the cab light on, 2 dimmed, 0 off; a row without it leaves the cab light to its own switch (eu07/maszyna#529)
|
|
|
|
using test::definition;
|
|
using test::vehicle;
|
|
|
|
namespace {
|
|
|
|
auto const shunting{light::headlight_left | light::headlight_right};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("lights preset cab light: a table without the column sets no position's cab light") {
|
|
vehicle wagon{definition::load("wagon")
|
|
.set("LightsList", "Size", 2)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{0, 0}, {shunting, shunting}})};
|
|
|
|
REQUIRE(wagon->LightsPosNo == 2);
|
|
CHECK(wagon->Lights[VehicleEnd::front][1] == shunting);
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(1).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value());
|
|
}
|
|
|
|
TEST_CASE("lights preset cab light: the third column turns the cab light off, on, or on dimmed") {
|
|
// off - shunting - shunting with the cab lit - shunting with the cab lit dimmed - shunting leaving the cab light
|
|
vehicle wagon{definition::load("wagon")
|
|
.set("LightsList", "Size", 5)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{0, 0, 0}, {shunting, shunting}, {shunting, shunting, 1}, {shunting, shunting, 3}, {shunting, 0, -1}})};
|
|
|
|
REQUIRE(wagon->LightsPosNo == 5);
|
|
// the light columns read as before
|
|
CHECK(wagon->Lights[VehicleEnd::front][2] == shunting);
|
|
CHECK(wagon->Lights[VehicleEnd::rear][2] == shunting);
|
|
CHECK(wagon->Lights[VehicleEnd::rear][4] == 0);
|
|
|
|
auto const off{wagon->LightsPresetCabLight(1)};
|
|
REQUIRE(off.has_value());
|
|
CHECK_FALSE(off->light);
|
|
CHECK_FALSE(off->dim);
|
|
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value());
|
|
|
|
auto const lit{wagon->LightsPresetCabLight(3)};
|
|
REQUIRE(lit.has_value());
|
|
CHECK(lit->light);
|
|
CHECK_FALSE(lit->dim);
|
|
|
|
auto const dimmed{wagon->LightsPresetCabLight(4)};
|
|
REQUIRE(dimmed.has_value());
|
|
CHECK(dimmed->light);
|
|
CHECK(dimmed->dim);
|
|
|
|
// a negative value is the same as no value
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(5).has_value());
|
|
}
|
|
|
|
TEST_CASE("lights preset cab light: positions outside the table, and the lightsset custom one, set nothing") {
|
|
vehicle wagon{definition::load("wagon")
|
|
.set("LightsList", "Size", 1)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{shunting, shunting, 1}})};
|
|
|
|
CHECK(wagon->LightsPresetCabLight(1).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(0).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(2).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(18).has_value());
|
|
CHECK_FALSE(wagon->LightsPresetCabLight(19).has_value());
|
|
}
|
|
|
|
TEST_CASE("lights preset cab light: a stray note after the two columns is not read as the cab light") {
|
|
// some vehicles of the game carry rows like "38 38 / A"
|
|
auto text{definition::load("wagon")
|
|
.set("LightsList", "Size", 2)
|
|
.set("LightsList", "Default", 1)
|
|
.set("LightsList", "rows", {{0, 0}, {38, 38}})
|
|
.text()};
|
|
auto const list{text.find("LightsList")};
|
|
REQUIRE(list != std::string::npos);
|
|
auto const row{text.find("38", list)};
|
|
REQUIRE(row != std::string::npos);
|
|
auto const rowend{text.find('\n', row)};
|
|
REQUIRE(rowend != std::string::npos);
|
|
text.insert(rowend, " / A");
|
|
TMoverParameters wagon(0.0, "wagon", "test", 0);
|
|
REQUIRE(wagon.LoadFIZ_Text(text));
|
|
REQUIRE(wagon.LightsPosNo == 2);
|
|
CHECK(wagon.Lights[VehicleEnd::front][1] == 38);
|
|
CHECK(wagon.Lights[VehicleEnd::rear][1] == 38);
|
|
CHECK_FALSE(wagon.LightsPresetCabLight(2).has_value());
|
|
}
|