18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 00:45:29 +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:
2026-11-28 18:32:58 +01:00
parent 4679201cb9
commit fbb9dc1e89
96 changed files with 1395 additions and 1304 deletions
+9 -9
View File
@@ -288,7 +288,7 @@ bool scene_walk::Render_lowpoly( TDynamicObject *Dynamic, float const Squaredist
return true;
}
bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Squaredistance, int const End, bool const Alpha ) {
bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Squaredistance, VehicleEnd const End, bool const Alpha ) {
if( Dynamic->m_coupleradapters[ End ] == nullptr ) { return false; }
gfx::walk_sync::vehicle_hold hold;
@@ -296,11 +296,11 @@ bool scene_walk::Render_coupler_adapter( TDynamicObject *Dynamic, float const Sq
auto const position { glm::dvec3 {
0.f,
Dynamic->MoverParameters->Couplers[ End ].adapter_height,
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == end::front ? 1 : -1 ) } };
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == VehicleEnd::front ? 1 : -1 ) } };
auto const angle { glm::vec3{
0,
( End == end::front ? 0 : 180 ),
( End == VehicleEnd::front ? 0 : 180 ),
0 } };
if( Alpha ) {
@@ -1931,8 +1931,8 @@ bool scene_walk::Render(TDynamicObject *Dynamic)
Render( attachment, Dynamic->Material(), squaredistance );
}
// optional coupling adapters
Render_coupler_adapter( Dynamic, squaredistance, end::front );
Render_coupler_adapter( Dynamic, squaredistance, end::rear );
Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::front );
Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::rear );
// post-render cleanup
if (gfx::vehicle_shade(Dynamic) > 0.0f)
@@ -1957,8 +1957,8 @@ bool scene_walk::Render(TDynamicObject *Dynamic)
Render( attachment, Dynamic->Material(), squaredistance );
}
// optional coupling adapters
Render_coupler_adapter( Dynamic, squaredistance, end::front );
Render_coupler_adapter( Dynamic, squaredistance, end::rear );
Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::front );
Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::rear );
if( Dynamic->mdLoad ) {
// renderowanie nieprzezroczystego ładunku
Render( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
@@ -3099,8 +3099,8 @@ bool scene_walk::Render_Alpha(TDynamicObject *Dynamic)
Render_Alpha( attachment, Dynamic->Material(), squaredistance );
}
// optional coupling adapters
Render_coupler_adapter( Dynamic, squaredistance, end::front, true );
Render_coupler_adapter( Dynamic, squaredistance, end::rear, true );
Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::front, true );
Render_coupler_adapter( Dynamic, squaredistance, VehicleEnd::rear, true );
if( Dynamic->mdLoad ) {
// renderowanie nieprzezroczystego ładunku
Render_Alpha( Dynamic->mdLoad, Dynamic->Material(), squaredistance, { 0.f, Dynamic->LoadOffset, 0.f }, {} );
+2 -1
View File
@@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include "physics/vehicletypes.h"
#include "rendering/geometrybank.h"
#include "rendering/openglcamera.h"
#include "scene/scene.h"
@@ -178,7 +179,7 @@ class scene_walk
bool Render_cab(TDynamicObject const *Dynamic, float const Lightlevel, bool const Alpha = false);
bool Render_interior(bool const Alpha = false);
bool Render_lowpoly(TDynamicObject *Dynamic, float const Squaredistance, bool const Setup, bool const Alpha = false);
bool Render_coupler_adapter(TDynamicObject *Dynamic, float const Squaredistance, int const End, bool const Alpha = false);
bool Render_coupler_adapter(TDynamicObject *Dynamic, float const Squaredistance, VehicleEnd const End, bool const Alpha = false);
void Render(TMemCell *Memcell);
void Render_Alpha(scene::basic_region *Region);
void Render_Alpha(cell_sequence::reverse_iterator First, cell_sequence::reverse_iterator Last);
+5 -5
View File
@@ -23,8 +23,8 @@ light_array::insert( TDynamicObject const *Owner ) {
// we're only storing lights for locos, which have two sets of lights, front and rear
// for a more generic role this function would have to be tweaked to add vehicle type-specific light combinations
data.emplace_back( Owner, end::front );
data.emplace_back( Owner, end::rear );
data.emplace_back( Owner, NumberOf( VehicleEnd::front ) );
data.emplace_back( Owner, NumberOf( VehicleEnd::rear ) );
}
void
@@ -39,7 +39,7 @@ light_array::update() {
for( auto &light : data ) {
// update light parameters to match current data of the owner
if( light.index == end::front ) {
if( EndOf( light.index ) == VehicleEnd::front ) {
// front light set
light.position = light.owner->GetPosition() + ( light.owner->VectorFront() * ( std::max( 0.0, light.owner->GetLength() * 0.5 - 2.0 ) ) );// +( light.owner->VectorUp() * 0.25 );
light.direction = glm::make_vec3( glm::value_ptr(light.owner->VectorFront()) ); // TODO: It is needed to get value_ptr and then make_vec3?
@@ -56,7 +56,7 @@ light_array::update() {
|| ( true == light.owner->MoverParameters->Power110vIsAvailable ) ) {
// with power on, the intensity depends on the state of activated switches
// first we cross-check the list of enabled lights with the lights installed in the vehicle...
auto const lights { light.owner->MoverParameters->iLights[ light.index ] & light.owner->LightList( static_cast<end>( light.index ) ) };
auto const lights { light.owner->MoverParameters->iLights[ light.index ] & light.owner->LightList( static_cast<VehicleEnd>( light.index ) ) };
// ...then check their individual state
light.count = 0
+ ( ( lights & light::headlight_left ) ? 1 : 0 )
@@ -67,7 +67,7 @@ light_array::update() {
// set intensity
if( light.count > 0 ) {
bool isEnabled = light.index == end::front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff;
bool isEnabled = EndOf( light.index ) == VehicleEnd::front ? !light.owner->HeadlightsAoff : !light.owner->HeadlightsBoff;
light.intensity = std::max(0.0f, std::log((float)light.count + 1.0f));
if (light.owner->DimHeadlights && !light.owner->HighBeamLights && isEnabled) // tylko przyciemnione