mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 14:16:48 +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:
@@ -55,13 +55,13 @@ namespace {
|
||||
constexpr float coupler_repair_radius { 5.f };
|
||||
|
||||
// the broken coupler nearest to the camera, within reach: the vehicle and its end, or no vehicle
|
||||
std::pair<TDynamicObject const *, int> broken_coupler_nearby( glm::dvec3 const &Camera ) {
|
||||
std::pair<TDynamicObject const *, VehicleEnd> broken_coupler_nearby( glm::dvec3 const &Camera ) {
|
||||
auto const *vehicle { std::get<TDynamicObject *>( simulation::Region->find_vehicle( Camera, coupler_repair_radius, false, true ) ) };
|
||||
if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) { return { nullptr, end::front }; }
|
||||
auto const front { glm::distance( vehicle->CouplerPosition( end::front ), Camera ) };
|
||||
auto const rear { glm::distance( vehicle->CouplerPosition( end::rear ), Camera ) };
|
||||
auto const nearest { front <= rear ? end::front : end::rear };
|
||||
if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->MoverParameters->Couplers[ nearest ].broken ) { return { nullptr, end::front }; }
|
||||
if( vehicle == nullptr || vehicle->MoverParameters == nullptr ) { return { nullptr, VehicleEnd::front }; }
|
||||
auto const front { glm::distance( vehicle->CouplerPosition( VehicleEnd::front ), Camera ) };
|
||||
auto const rear { glm::distance( vehicle->CouplerPosition( VehicleEnd::rear ), Camera ) };
|
||||
auto const nearest { front <= rear ? VehicleEnd::front : VehicleEnd::rear };
|
||||
if( std::min( front, rear ) > coupler_repair_radius || false == vehicle->MoverParameters->Couplers[ nearest ].broken ) { return { nullptr, VehicleEnd::front }; }
|
||||
return { vehicle, nearest };
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ drivingaid_panel::render_contents() {
|
||||
// only the coupler the camera is next to, and the one of the vehicle it was coupled with
|
||||
if( m_brokenvehicle != nullptr && ImGui::Button( STR_C( "Repair coupler" ) ) ) {
|
||||
command_relay commandrelay;
|
||||
commandrelay.post( user_command::repaircoupler, m_brokenend, 0.0, GLFW_PRESS, 0, glm::vec3( 0.0f ), &m_brokenvehicle->name() );
|
||||
commandrelay.post( user_command::repaircoupler, NumberOf( m_brokenend ), 0.0, GLFW_PRESS, 0, glm::vec3( 0.0f ), &m_brokenvehicle->name() );
|
||||
}
|
||||
|
||||
ui_panel::render_contents();
|
||||
@@ -807,8 +807,8 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
mover.EngineDescription( 0 ).c_str(),
|
||||
// TODO: put wheel flat reporting in the enginedescription()
|
||||
std::string( mover.WheelFlat > 0.01 ? " Flat: " + to_string( mover.WheelFlat, 1 ) + " mm" : "" ).c_str(),
|
||||
update_vehicle_coupler( end::front ).c_str(),
|
||||
update_vehicle_coupler( end::rear ).c_str() );
|
||||
update_vehicle_coupler( VehicleEnd::front ).c_str(),
|
||||
update_vehicle_coupler( VehicleEnd::rear ).c_str() );
|
||||
|
||||
Output.emplace_back( std::string{ m_buffer.data() }, Global.UITextColor );
|
||||
|
||||
@@ -818,11 +818,11 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
// devices
|
||||
mover.Battery ? 'B' : '.',
|
||||
mover.PantsValve.is_active ? '+' : '.',
|
||||
mover.Pantographs[end::rear].valve.is_active ? 'O' :
|
||||
mover.Pantographs[end::rear].valve.is_enabled ? 'o' :
|
||||
mover.Pantographs[VehicleEnd::rear].valve.is_active ? 'O' :
|
||||
mover.Pantographs[VehicleEnd::rear].valve.is_enabled ? 'o' :
|
||||
'.',
|
||||
mover.Pantographs[end::front].valve.is_active ? 'P' :
|
||||
mover.Pantographs[end::front].valve.is_enabled ? 'p' :
|
||||
mover.Pantographs[VehicleEnd::front].valve.is_active ? 'P' :
|
||||
mover.Pantographs[VehicleEnd::front].valve.is_enabled ? 'p' :
|
||||
'.',
|
||||
mover.PantPressLockActive ? '!' :
|
||||
mover.PantPressSwitchActive ? '*' :
|
||||
@@ -866,21 +866,21 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
std::string( isdieselenginepowered ? STR(" oil pressure: ") + to_string( mover.OilPump.pressure, 2 ) : "" ).c_str(),
|
||||
// power transfers
|
||||
// 3000v
|
||||
mover.Couplers[ end::front ].power_high.voltage,
|
||||
mover.Couplers[ end::front ].power_high.current,
|
||||
std::string( mover.Couplers[ end::front ].power_high.is_local ? ":" : ":=" ).c_str(),
|
||||
mover.Couplers[ VehicleEnd::front ].power_high.voltage,
|
||||
mover.Couplers[ VehicleEnd::front ].power_high.current,
|
||||
std::string( mover.Couplers[ VehicleEnd::front ].power_high.is_local ? ":" : ":=" ).c_str(),
|
||||
mover.EngineVoltage,
|
||||
std::string( mover.Couplers[ end::rear ].power_high.is_local ? ":" : "=:" ).c_str(),
|
||||
mover.Couplers[ end::rear ].power_high.voltage,
|
||||
mover.Couplers[ end::rear ].power_high.current,
|
||||
std::string( mover.Couplers[ VehicleEnd::rear ].power_high.is_local ? ":" : "=:" ).c_str(),
|
||||
mover.Couplers[ VehicleEnd::rear ].power_high.voltage,
|
||||
mover.Couplers[ VehicleEnd::rear ].power_high.current,
|
||||
// 110v
|
||||
mover.Couplers[ end::front ].power_110v.voltage,
|
||||
mover.Couplers[ end::front ].power_110v.current,
|
||||
std::string( mover.Couplers[ end::front ].power_110v.is_local ? ":" : ":=" ).c_str(),
|
||||
mover.Couplers[ VehicleEnd::front ].power_110v.voltage,
|
||||
mover.Couplers[ VehicleEnd::front ].power_110v.current,
|
||||
std::string( mover.Couplers[ VehicleEnd::front ].power_110v.is_local ? ":" : ":=" ).c_str(),
|
||||
mover.PowerCircuits[ 1 ].first,
|
||||
std::string( mover.Couplers[ end::rear ].power_110v.is_local ? ":" : "=:" ).c_str(),
|
||||
mover.Couplers[ end::rear ].power_110v.voltage,
|
||||
mover.Couplers[ end::rear ].power_110v.current );
|
||||
std::string( mover.Couplers[ VehicleEnd::rear ].power_110v.is_local ? ":" : "=:" ).c_str(),
|
||||
mover.Couplers[ VehicleEnd::rear ].power_110v.voltage,
|
||||
mover.Couplers[ VehicleEnd::rear ].power_110v.current );
|
||||
|
||||
Output.emplace_back( m_buffer.data(), Global.UITextColor );
|
||||
|
||||
@@ -898,8 +898,8 @@ debug_panel::update_section_vehicle( std::vector<text_line> &Output ) {
|
||||
std::abs( mover.enrot ) * 60,
|
||||
std::abs( mover.nrot ) * mover.Transmision.Ratio * 60,
|
||||
mover.RventRot * 60,
|
||||
std::abs( mover.MotorBlowers[end::front].revolutions ),
|
||||
std::abs( mover.MotorBlowers[end::rear].revolutions ),
|
||||
std::abs( mover.MotorBlowers[VehicleEnd::front].revolutions ),
|
||||
std::abs( mover.MotorBlowers[VehicleEnd::rear].revolutions ),
|
||||
mover.diesel.heat.rpmw,
|
||||
mover.diesel.heat.rpmw2 );
|
||||
|
||||
@@ -1033,7 +1033,7 @@ void debug_panel::graph_data::render() {
|
||||
}
|
||||
|
||||
std::string
|
||||
debug_panel::update_vehicle_coupler( int const Side ) {
|
||||
debug_panel::update_vehicle_coupler( VehicleEnd const Side ) {
|
||||
// NOTE: mover and vehicle are guaranteed to be valid by the caller
|
||||
auto const &mover { *m_input.mover };
|
||||
|
||||
@@ -1613,8 +1613,8 @@ debug_panel::update_section_coupler( std::vector<text_line> &Output ) {
|
||||
Output.emplace_back( std::format( "No coupler within {:.0f} m of the camera", coupler_pick_radius ), Global.UITextColor );
|
||||
return;
|
||||
}
|
||||
auto const nearerfront { glm::distance( vehicle->CouplerPosition( end::front ), camera ) <= glm::distance( vehicle->CouplerPosition( end::rear ), camera ) };
|
||||
m_coupler = { vehicle, nearerfront ? end::front : end::rear };
|
||||
auto const nearerfront { glm::distance( vehicle->CouplerPosition( VehicleEnd::front ), camera ) <= glm::distance( vehicle->CouplerPosition( VehicleEnd::rear ), camera ) };
|
||||
m_coupler = { vehicle, nearerfront ? VehicleEnd::front : VehicleEnd::rear };
|
||||
|
||||
auto const &mover { *vehicle->MoverParameters };
|
||||
auto const &coupler { mover.Couplers[ m_coupler.end ] };
|
||||
@@ -1634,7 +1634,7 @@ debug_panel::update_section_coupler( std::vector<text_line> &Output ) {
|
||||
Global.UITextColor );
|
||||
if( neighbour.vehicle != nullptr ) {
|
||||
Output.emplace_back(
|
||||
std::format( "Neighbour: {} ({} end), coupling [{}], gap {:.1f} mm", neighbour.vehicle->name(), neighbour.vehicle_end == end::front ? "front" : "rear", coupler.CouplingFlag.Bits(), neighbour.distance * 1000.0 ),
|
||||
std::format( "Neighbour: {} ({} end), coupling [{}], gap {:.1f} mm", neighbour.vehicle->name(), neighbour.FacingEnd() == VehicleEnd::front ? "front" : "rear", coupler.CouplingFlag.Bits(), neighbour.distance * 1000.0 ),
|
||||
Global.UITextColor );
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user