mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 03:37:09 +01:00
refactor(physics): the ends and the sides of a vehicle as scoped enums
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.
This commit is contained in:
+47
-47
@@ -279,48 +279,48 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
}
|
||||
case driver_hint::frontpantographvalveon: {
|
||||
if( AIControllFlag ) {
|
||||
mvOccupied->OperatePantographValve( end::front, operation_t::enable );
|
||||
mvOccupied->OperatePantographValve( VehicleEnd::front, operation_t::enable );
|
||||
}
|
||||
remove_hint( driver_hint::frontpantographvalveoff );
|
||||
hint(
|
||||
Action,
|
||||
[ this ]( float const Parameter ) {
|
||||
return mvPantographUnit->Pantographs[end::front].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); },
|
||||
return mvPantographUnit->Pantographs[VehicleEnd::front].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); },
|
||||
Actionparameter );
|
||||
break;
|
||||
}
|
||||
case driver_hint::frontpantographvalveoff: {
|
||||
if( AIControllFlag ) {
|
||||
mvOccupied->OperatePantographValve( end::front, operation_t::disable );
|
||||
mvOccupied->OperatePantographValve( VehicleEnd::front, operation_t::disable );
|
||||
}
|
||||
remove_hint( driver_hint::frontpantographvalveon );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return mvPantographUnit->Pantographs[end::front].valve.is_active == false; } );
|
||||
return mvPantographUnit->Pantographs[VehicleEnd::front].valve.is_active == false; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::rearpantographvalveon: {
|
||||
if( AIControllFlag ) {
|
||||
mvOccupied->OperatePantographValve( end::rear, operation_t::enable );
|
||||
mvOccupied->OperatePantographValve( VehicleEnd::rear, operation_t::enable );
|
||||
}
|
||||
remove_hint( driver_hint::rearpantographvalveoff );
|
||||
hint(
|
||||
Action,
|
||||
[ this ]( float const Parameter ) {
|
||||
return mvPantographUnit->Pantographs[end::rear].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); },
|
||||
return mvPantographUnit->Pantographs[VehicleEnd::rear].valve.is_active == true || (Parameter > 0 && mvOccupied->Vel > Parameter); },
|
||||
Actionparameter );
|
||||
break;
|
||||
}
|
||||
case driver_hint::rearpantographvalveoff: {
|
||||
if( AIControllFlag ) {
|
||||
mvOccupied->OperatePantographValve( end::rear, operation_t::disable );
|
||||
mvOccupied->OperatePantographValve( VehicleEnd::rear, operation_t::disable );
|
||||
}
|
||||
remove_hint( driver_hint::rearpantographvalveon );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return mvPantographUnit->Pantographs[end::rear].valve.is_active == false; } );
|
||||
return mvPantographUnit->Pantographs[VehicleEnd::rear].valve.is_active == false; } );
|
||||
break;
|
||||
}
|
||||
// converter
|
||||
@@ -434,27 +434,27 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
}
|
||||
case driver_hint::frontmotorblowerson: {
|
||||
if( AIControllFlag ) {
|
||||
mvOccupied->MotorBlowersSwitchOff( false, end::front );
|
||||
mvOccupied->MotorBlowersSwitch( true, end::front );
|
||||
mvOccupied->MotorBlowersSwitchOff( false, VehicleEnd::front );
|
||||
mvOccupied->MotorBlowersSwitch( true, VehicleEnd::front );
|
||||
}
|
||||
remove_hint( driver_hint::frontmotorblowersoff );
|
||||
hint(
|
||||
Action,
|
||||
[this]( float const /*Parameter*/ ) {
|
||||
auto const &device { mvOccupied->MotorBlowers[ end::front ] };
|
||||
auto const &device { mvOccupied->MotorBlowers[ VehicleEnd::front ] };
|
||||
return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false); } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::rearmotorblowerson: {
|
||||
if( AIControllFlag ) {
|
||||
mvOccupied->MotorBlowersSwitchOff( false, end::rear );
|
||||
mvOccupied->MotorBlowersSwitch( true, end::rear );
|
||||
mvOccupied->MotorBlowersSwitchOff( false, VehicleEnd::rear );
|
||||
mvOccupied->MotorBlowersSwitch( true, VehicleEnd::rear );
|
||||
}
|
||||
remove_hint( driver_hint::rearmotorblowersoff );
|
||||
hint(
|
||||
Action,
|
||||
[this]( float const /*Parameter*/ ) {
|
||||
auto const &device { mvOccupied->MotorBlowers[ end::rear ] };
|
||||
auto const &device { mvOccupied->MotorBlowers[ VehicleEnd::rear ] };
|
||||
return device.start_type != start_t::manual || (device.is_enabled == true && device.is_disabled == false); } );
|
||||
break;
|
||||
}
|
||||
@@ -1070,93 +1070,93 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
case driver_hint::doorrightopen: {
|
||||
if( AIControllFlag
|
||||
|| pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) {
|
||||
pVehicle->MoverParameters->OperateDoors( side::right, true );
|
||||
pVehicle->MoverParameters->OperateDoors( VehicleSide::right, true );
|
||||
}
|
||||
remove_hint( driver_hint::doorrightclose );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorOpen[side::right] == true; } );
|
||||
return IsAnyDoorOpen[VehicleSide::right] == true; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorrightclose: {
|
||||
if( AIControllFlag
|
||||
|| pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) {
|
||||
pVehicle->MoverParameters->OperateDoors( side::right, false );
|
||||
pVehicle->MoverParameters->OperateDoors( VehicleSide::right, false );
|
||||
}
|
||||
remove_hint( driver_hint::doorrightopen );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorOpen[side::right] == false; } );
|
||||
return IsAnyDoorOpen[VehicleSide::right] == false; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorleftopen: {
|
||||
if( AIControllFlag
|
||||
|| pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) {
|
||||
pVehicle->MoverParameters->OperateDoors( side::left, true );
|
||||
pVehicle->MoverParameters->OperateDoors( VehicleSide::left, true );
|
||||
}
|
||||
remove_hint( driver_hint::doorleftclose );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorOpen[side::left] == true; } );
|
||||
return IsAnyDoorOpen[VehicleSide::left] == true; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorleftclose: {
|
||||
if( AIControllFlag
|
||||
|| pVehicle->MoverParameters->Doors.open_control == control_t::conductor ) {
|
||||
pVehicle->MoverParameters->OperateDoors( side::left, false );
|
||||
pVehicle->MoverParameters->OperateDoors( VehicleSide::left, false );
|
||||
}
|
||||
remove_hint( driver_hint::doorleftopen );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorOpen[side::left] == false; } );
|
||||
return IsAnyDoorOpen[VehicleSide::left] == false; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorrightpermiton: {
|
||||
if( AIControllFlag ) {
|
||||
pVehicle->MoverParameters->PermitDoors( side::right, true );
|
||||
pVehicle->MoverParameters->PermitDoors( VehicleSide::right, true );
|
||||
}
|
||||
remove_hint( driver_hint::doorrightpermitoff );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorPermitActive[side::right] == true; } );
|
||||
return IsAnyDoorPermitActive[VehicleSide::right] == true; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorrightpermitoff: {
|
||||
if( AIControllFlag ) {
|
||||
pVehicle->MoverParameters->PermitDoors( side::right, false );
|
||||
pVehicle->MoverParameters->PermitDoors( VehicleSide::right, false );
|
||||
}
|
||||
remove_hint( driver_hint::doorrightpermiton );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorPermitActive[side::right] == false; } );
|
||||
return IsAnyDoorPermitActive[VehicleSide::right] == false; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorleftpermiton: {
|
||||
if( AIControllFlag ) {
|
||||
pVehicle->MoverParameters->PermitDoors( side::left, true );
|
||||
pVehicle->MoverParameters->PermitDoors( VehicleSide::left, true );
|
||||
}
|
||||
remove_hint( driver_hint::doorleftpermitoff );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorPermitActive[side::left] == true; } );
|
||||
return IsAnyDoorPermitActive[VehicleSide::left] == true; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::doorleftpermitoff: {
|
||||
if( AIControllFlag ) {
|
||||
pVehicle->MoverParameters->PermitDoors( side::left, false );
|
||||
pVehicle->MoverParameters->PermitDoors( VehicleSide::left, false );
|
||||
}
|
||||
remove_hint( driver_hint::doorleftpermiton );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return IsAnyDoorPermitActive[side::left] == false; } );
|
||||
return IsAnyDoorPermitActive[VehicleSide::left] == false; } );
|
||||
break;
|
||||
}
|
||||
// doorsteps, as the timetable asks (eu07/maszyna#95)
|
||||
@@ -1254,30 +1254,30 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
case driver_hint::couplingadapterattach: {
|
||||
// TODO: run also for potential settings-based virtual assistant
|
||||
if( AIControllFlag ) {
|
||||
pVehicles[ end::front ]->attach_coupler_adapter( static_cast<int>(Actionparameter) );
|
||||
pVehicles[ VehicleEnd::front ]->attach_coupler_adapter( EndOf( static_cast<int>(Actionparameter) ) );
|
||||
}
|
||||
hint(
|
||||
Action,
|
||||
[this](float const Parameter) {
|
||||
auto const &device { pVehicles[ end::front ]->MoverParameters->Couplers[ static_cast<int>( Parameter ) ] };
|
||||
auto const &device { pVehicles[ VehicleEnd::front ]->MoverParameters->Couplers[ static_cast<int>( Parameter ) ] };
|
||||
return device.type() == TCouplerType::Automatic; } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::couplingadapterremove: {
|
||||
if( AIControllFlag || Global.AITrainman ) {
|
||||
pVehicles[ end::front ]->remove_coupler_adapter( static_cast<int>(Actionparameter) );
|
||||
pVehicles[ VehicleEnd::front ]->remove_coupler_adapter( EndOf( static_cast<int>(Actionparameter) ) );
|
||||
}
|
||||
hint(
|
||||
Action,
|
||||
[this](float const Parameter) {
|
||||
auto const &device { pVehicles[ end::front ]->MoverParameters->Couplers[ static_cast<int>( Parameter ) ] };
|
||||
auto const &device { pVehicles[ VehicleEnd::front ]->MoverParameters->Couplers[ static_cast<int>( Parameter ) ] };
|
||||
return false == device.has_adapter(); } );
|
||||
break;
|
||||
}
|
||||
// lights
|
||||
case driver_hint::headcodepc1: {
|
||||
if( AIControllFlag ) {
|
||||
pVehicles[ end::front ]->RaLightsSet( light::headlight_left | light::headlight_right | light::headlight_upper, -1 );
|
||||
pVehicles[ VehicleEnd::front ]->RaLightsSet( light::headlight_left | light::headlight_right | light::headlight_upper, -1 );
|
||||
}
|
||||
remove_hint( driver_hint::headcodepc2 );
|
||||
remove_hint( driver_hint::headcodetb1 );
|
||||
@@ -1285,12 +1285,12 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return pVehicles[end::front]->has_signal_pc1_on(); } );
|
||||
return pVehicles[VehicleEnd::front]->has_signal_pc1_on(); } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::headcodepc2: {
|
||||
if( AIControllFlag ) {
|
||||
pVehicles[ end::front ]->RaLightsSet( light::redmarker_left | light::headlight_right | light::headlight_upper, -1 );
|
||||
pVehicles[ VehicleEnd::front ]->RaLightsSet( light::redmarker_left | light::headlight_right | light::headlight_upper, -1 );
|
||||
}
|
||||
remove_hint( driver_hint::headcodepc1 );
|
||||
remove_hint( driver_hint::headcodetb1 );
|
||||
@@ -1298,7 +1298,7 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return pVehicles[end::front]->has_signal_pc2_on(); } );
|
||||
return pVehicles[VehicleEnd::front]->has_signal_pc2_on(); } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::headcodetb1: {
|
||||
@@ -1315,22 +1315,22 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
auto const activeend { mvOccupied->CabActive >= 0 ? end::front : end::rear };
|
||||
auto const consistfront { mvOccupied->DirActive >= 0 ? end::front : end::rear };
|
||||
return pVehicles[consistfront]->has_signal_on(activeend, light::headlight_right) && pVehicles[1 - consistfront]->has_signal_on(1 - activeend, light::headlight_left); } );
|
||||
auto const activeend { mvOccupied->CabActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
|
||||
auto const consistfront { mvOccupied->DirActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
|
||||
return pVehicles[consistfront]->has_signal_on(activeend, light::headlight_right) && pVehicles[Opposite(consistfront)]->has_signal_on(Opposite(activeend), light::headlight_left); } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::headcodepc5: {
|
||||
if( AIControllFlag
|
||||
|| ( Global.AITrainman && false == pVehicles[end::rear]->is_connected(pVehicle, Coupling::control) ) ) {
|
||||
pVehicles[ end::rear ]->RaLightsSet( -1, light::redmarker_left | light::redmarker_right | light::rearendsignals );
|
||||
|| ( Global.AITrainman && false == pVehicles[VehicleEnd::rear]->is_connected(pVehicle, Coupling::control) ) ) {
|
||||
pVehicles[ VehicleEnd::rear ]->RaLightsSet( -1, light::redmarker_left | light::redmarker_right | light::rearendsignals );
|
||||
}
|
||||
remove_hint( driver_hint::headcodetb1 );
|
||||
remove_hint( driver_hint::lightsoff );
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
return pVehicles[end::rear]->has_signal_pc5_on(); } );
|
||||
return pVehicles[VehicleEnd::rear]->has_signal_pc5_on(); } );
|
||||
break;
|
||||
}
|
||||
case driver_hint::lightsoff: {
|
||||
@@ -1344,9 +1344,9 @@ TController::cue_action( driver_hint const Action, float const Actionparameter )
|
||||
hint(
|
||||
Action,
|
||||
[this](float const /*Parameter*/) {
|
||||
auto const activeend { mvOccupied->CabActive >= 0 ? end::front : end::rear };
|
||||
auto const consistfront { mvOccupied->DirActive >= 0 ? end::front : end::rear };
|
||||
return pVehicles[consistfront]->has_signal_on(activeend, 0) && pVehicles[1 - consistfront]->has_signal_on(1 - activeend, 0); } );
|
||||
auto const activeend { mvOccupied->CabActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
|
||||
auto const consistfront { mvOccupied->DirActive >= 0 ? VehicleEnd::front : VehicleEnd::rear };
|
||||
return pVehicles[consistfront]->has_signal_on(activeend, 0) && pVehicles[Opposite(consistfront)]->has_signal_on(Opposite(activeend), 0); } );
|
||||
break;
|
||||
}
|
||||
// releaser
|
||||
|
||||
Reference in New Issue
Block a user