18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 20:05:23 +01:00

refactor(physics): the controllers and the switches of the cab are private to the vehicle

The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.

The .fiz keys are untouched.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 12:26:21 +01:00
parent 7387e36df5
commit 84f1aa2515
87 changed files with 798 additions and 769 deletions
+13 -13
View File
@@ -787,7 +787,7 @@ void driver_mode::update_camera(double const Deltatime)
{
// jeśli jazda w kabinie, przeliczyć trzeba parametry kamery
/*
auto tempangle = controlled->VectorFront() * ( controlled->physics->CabOccupied == -1 ? -1 : 1 );
auto tempangle = controlled->VectorFront() * ( controlled->physics->CabOccupied() == -1 ? -1 : 1 );
double modelrotate = atan2( -tempangle.x, tempangle.z );
*/
if (false == FreeFlyModeFlag && true == Global.ctrlState && (m_input.keyboard.key(GLFW_KEY_LEFT) != GLFW_RELEASE || m_input.keyboard.key(GLFW_KEY_RIGHT) != GLFW_RELEASE))
@@ -799,7 +799,7 @@ void driver_mode::update_camera(double const Deltatime)
// Camera.Yaw powinno być wyzerowane, aby po powrocie patrzeć do przodu
Camera.Pos = controlled->GetPosition() + simulation::Train->MirrorPosition(lr); // pozycja lusterka // NOSONAR
Camera.Angle.y = 0; // odchylenie na bok od Camera.LookAt
if (simulation::Train->Occupied()->CabOccupied == 0)
if (simulation::Train->Occupied()->CabOccupied() == 0)
{
// gdy w korytarzu
Camera.LookAt = Camera.Pos - simulation::Train->GetDirection();
@@ -807,12 +807,12 @@ void driver_mode::update_camera(double const Deltatime)
else if (Global.shiftState)
{
// patrzenie w bok przez szybę
Camera.LookAt = Camera.Pos - (lr ? -1.0 : 1.0) * controlled->VectorLeft() * (double)simulation::Train->Occupied()->CabOccupied;
Camera.LookAt = Camera.Pos - (lr ? -1.0 : 1.0) * controlled->VectorLeft() * (double)simulation::Train->Occupied()->CabOccupied();
}
else
{ // patrzenie w kierunku osi pojazdu, z uwzględnieniem kabiny - jakby z lusterka,
// ale bez odbicia
Camera.LookAt = Camera.Pos - simulation::Train->GetDirection() * (double)simulation::Train->Occupied()->CabOccupied; //-1 albo 1
Camera.LookAt = Camera.Pos - simulation::Train->GetDirection() * (double)simulation::Train->Occupied()->CabOccupied(); //-1 albo 1
}
auto const *dynamic{simulation::Train->Dynamic()};
auto const shakeangles{dynamic->shake_angles(dynamic->shake_between(shake_fraction()))};
@@ -867,7 +867,7 @@ void driver_mode::update_camera(double const Deltatime)
Controlled->ABuSetModelShake( temp );
// ABu: koniec rzucania
*/
if (simulation::Train->Occupied()->CabOccupied == 0)
if (simulation::Train->Occupied()->CabOccupied() == 0)
{
// gdy w korytarzu
Camera.LookAt = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset) + Camera.m_owner->VectorFront() * 5.0;
@@ -875,7 +875,7 @@ void driver_mode::update_camera(double const Deltatime)
else
{
// patrzenie w kierunku osi pojazdu, z uwzględnieniem kabiny
Camera.LookAt = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset) + Camera.m_owner->VectorFront() * 5.0 * (double)simulation::Train->Occupied()->CabOccupied; //-1 albo 1
Camera.LookAt = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset) + Camera.m_owner->VectorFront() * 5.0 * (double)simulation::Train->Occupied()->CabOccupied(); //-1 albo 1
}
Camera.vUp = simulation::Train->GetUp();
}
@@ -1192,7 +1192,7 @@ void driver_mode::DistantView(bool const Near)
return;
}
auto const cab = vehicle->physics->CabOccupied == 0 ? 1 : vehicle->physics->CabOccupied;
auto const cab = vehicle->physics->CabOccupied() == 0 ? 1 : vehicle->physics->CabOccupied();
auto const left = vehicle->VectorLeft() * (double)cab;
if (true == Near)
@@ -1203,7 +1203,7 @@ void driver_mode::DistantView(bool const Near)
else
{
Camera.Pos = vehicle->GetPosition() + vehicle->VectorFront() * (double)vehicle->physics->CabOccupied * 50.0 + glm::dvec3(-10.0 * left.x, 1.6, -10.0 * left.z);
Camera.Pos = vehicle->GetPosition() + vehicle->VectorFront() * (double)vehicle->physics->CabOccupied() * 50.0 + glm::dvec3(-10.0 * left.x, 1.6, -10.0 * left.z);
}
Camera.m_owner = nullptr;
@@ -1256,7 +1256,7 @@ void driver_mode::ExternalView()
else
{
// default view setup
auto const offsetflip{(vehicle->physics->CabOccupied == 0 ? 1 : vehicle->physics->CabOccupied) *
auto const offsetflip{(vehicle->physics->CabOccupied() == 0 ? 1 : vehicle->physics->CabOccupied()) *
(vehicle->physics->DirActive == 0 ? 1 : vehicle->physics->DirActive)};
Camera.m_owneroffset = {1.5 * owner->physics->Dim.W * offsetflip, std::max(5.0, 1.25 * owner->physics->Dim.H), -0.4 * owner->physics->Dim.L * offsetflip};
@@ -1286,7 +1286,7 @@ void driver_mode::ExternalView()
else
{
// default view setup
auto const offsetflip{(vehicle->physics->CabOccupied == 0 ? 1 : vehicle->physics->CabOccupied) *
auto const offsetflip{(vehicle->physics->CabOccupied() == 0 ? 1 : vehicle->physics->CabOccupied()) *
(vehicle->physics->DirActive == 0 ? 1 : vehicle->physics->DirActive) * -1};
Camera.m_owneroffset = {1.5 * owner->physics->Dim.W * offsetflip, std::max(5.0, 1.25 * owner->physics->Dim.H), 0.2 * owner->physics->Dim.L * offsetflip};
@@ -1314,7 +1314,7 @@ void driver_mode::ExternalView()
else
{
// default view setup
auto const offsetflip{(vehicle->physics->CabOccupied == 0 ? 1 : vehicle->physics->CabOccupied) *
auto const offsetflip{(vehicle->physics->CabOccupied() == 0 ? 1 : vehicle->physics->CabOccupied()) *
(vehicle->physics->DirActive == 0 ? 1 : vehicle->physics->DirActive)};
Camera.m_owneroffset = {-0.65 * owner->physics->Dim.W * offsetflip, 0.90, 0.15 * owner->physics->Dim.L * offsetflip};
@@ -1382,14 +1382,14 @@ void driver_mode::CabView()
Camera.Angle.x -= 0.5 * shakeangles.second; // hustanie kamery przod tyl
Camera.Angle.z = shakeangles.first; // hustanie kamery na boki
if (train->Occupied()->CabOccupied == 0)
if (train->Occupied()->CabOccupied() == 0)
{
Camera.LookAt = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset) + Camera.m_owner->VectorFront() * 5.0;
}
else
{
// patrz w strone wlasciwej kabiny
Camera.LookAt = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset) + Camera.m_owner->VectorFront() * 5.0 * (double)Camera.m_owner->physics->CabOccupied;
Camera.LookAt = Camera.m_owner->GetWorldPosition(Camera.m_owneroffset) + Camera.m_owner->VectorFront() * 5.0 * (double)Camera.m_owner->physics->CabOccupied();
}
train->pMechOffset = Camera.m_owneroffset;
}