mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 19:57:06 +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.
94 lines
4.1 KiB
C++
94 lines
4.1 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
|
|
#include "vehicle/lightsprogrammer.h"
|
|
|
|
// the lights the light preset selector (programmer) of the occupied cab gives the vehicles of the consist,
|
|
// TDynamicObject::SetLights(): the cab's front lights at the end the cab faces, its back lights at the other
|
|
// end, and no lights at an end with another vehicle coupled
|
|
|
|
namespace {
|
|
|
|
int const pc1{light::headlight_left | light::headlight_upper | light::headlight_right};
|
|
int const tailmarkers{light::redmarker_left | light::redmarker_right};
|
|
ByEnd<int> const cablights{pc1, tailmarkers}; // Lights[VehicleEnd::front], Lights[VehicleEnd::rear]
|
|
|
|
// the lights at the vehicle's own end, placed the way TDynamicObject::RaLightsSet() places them
|
|
int lights_at(lights_programmer::consist_lights const &Lights, int const Direction, VehicleEnd const Side) {
|
|
auto const headend{Direction > 0 ? VehicleEnd::front : VehicleEnd::rear};
|
|
return Side == headend ? Lights.head : Lights.rear;
|
|
}
|
|
|
|
struct setup {
|
|
int cab; // CabOccupied of the vehicle with the programmer
|
|
int direction; // its iDirection
|
|
ByEnd<bool> coupled; // vehicle coupled at its VehicleEnd::front / VehicleEnd::rear
|
|
};
|
|
|
|
lights_programmer::consist_lights lights_for(setup const &Setup) {
|
|
// TDynamicObject::SetLights(): the cab faces the head of the consist when CabOccupied * DirectionGet() >= 0
|
|
auto const cabfacinghead{Setup.cab * (Setup.direction > 0 ? 1 : -1) >= 0};
|
|
return lights_programmer::vehicle_lights(cablights, cabfacinghead, Setup.direction, Setup.coupled);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("lights programmer: a lone vehicle gets the cab's front lights ahead of the cab and its back lights behind it") {
|
|
for (auto const direction : {0, 1}) {
|
|
CAPTURE(direction);
|
|
// cab 1 faces VehicleEnd::front
|
|
auto const fromcab1{lights_for({1, direction, {false, false}})};
|
|
CHECK(lights_at(fromcab1, direction, VehicleEnd::front) == pc1);
|
|
CHECK(lights_at(fromcab1, direction, VehicleEnd::rear) == tailmarkers);
|
|
// cab -1 faces VehicleEnd::rear
|
|
auto const fromcab2{lights_for({-1, direction, {false, false}})};
|
|
CHECK(lights_at(fromcab2, direction, VehicleEnd::rear) == pc1);
|
|
CHECK(lights_at(fromcab2, direction, VehicleEnd::front) == tailmarkers);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("lights programmer: the end with the train coupled goes dark, not the other one (eu07/maszyna#395)") {
|
|
// a locomotive driven from either cab, with the train coupled at either end, either way round in the consist.
|
|
// the end with the train goes dark, the free end shows the lights meant for it
|
|
for (auto const direction : {0, 1}) {
|
|
for (auto const cab : {1, -1}) {
|
|
for (auto const trainend : VehicleEnds) {
|
|
CAPTURE(direction);
|
|
CAPTURE(cab);
|
|
CAPTURE(trainend);
|
|
ByEnd<bool> coupled{false, false};
|
|
coupled[trainend] = true;
|
|
auto const freeend{trainend == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front};
|
|
auto const cabfront{cab > 0 ? VehicleEnd::front : VehicleEnd::rear};
|
|
|
|
auto const lights{lights_for({cab, direction, coupled})};
|
|
|
|
CHECK(lights_at(lights, direction, trainend) == 0);
|
|
CHECK(lights_at(lights, direction, freeend) == (freeend == cabfront ? pc1 : tailmarkers));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_CASE("lights programmer: 6Dg driven backwards from its second cab position pulls the train with its head lights lit (eu07/maszyna#395)") {
|
|
// the reported case: the train coupled behind the driver (VehicleEnd::front, which cab -1 has at its back), the
|
|
// locomotive running towards VehicleEnd::rear, the train in tow. the head lights stay lit, the end with the train goes dark;
|
|
// before the fix the couplings were looked up at the swapped ends and it was the other way round
|
|
auto const lights{lights_for({-1, 1, {true, false}})};
|
|
|
|
CHECK(lights_at(lights, 1, VehicleEnd::rear) == pc1);
|
|
CHECK(lights_at(lights, 1, VehicleEnd::front) == 0);
|
|
}
|
|
|
|
TEST_CASE("lights programmer: a vehicle coupled at both ends stays dark") {
|
|
for (auto const direction : {0, 1}) {
|
|
for (auto const cab : {1, -1}) {
|
|
CAPTURE(direction);
|
|
CAPTURE(cab);
|
|
auto const lights{lights_for({cab, direction, {true, true}})};
|
|
CHECK(lights.head == 0);
|
|
CHECK(lights.rear == 0);
|
|
}
|
|
}
|
|
}
|