From 9a7ff372f776a28fd88f6cc586ee0cf40f960a59 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Fri, 23 Oct 2026 19:08:09 +0200 Subject: [PATCH] perf(debug): count what wakes the physics of the vehicles (brake pipe, main reservoir pipe, command, speed, acceleration, neighbour, other) in the debug panel --- McZapkie/MOVER.h | 14 +++++++++++++- McZapkie/Mover.cpp | 19 +++++++++++-------- rendering/opengl46/opengl46renderer.cpp | 10 +++++++++- utilities/Timer.h | 10 +++++++++- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 5c2c0532..e0e38eac 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2324,7 +2324,19 @@ class TMoverParameters // Q ******************************************************************************************* double GetTrainsetVoltage(int const Coupling = coupling::heating | coupling::highvoltage) const; double GetTrainsetHighVoltage() const; - bool switch_physics(bool const State); + // what turns the physics on, counted for the debug panel (Timer::switching_counter) + enum class wake_cause + { + other, + mainpipe, // air flowing in from a neighbour along the brake pipe + scndpipe, // along the main reservoir pipe + command, + speed, // the test of ComputeTotalForce(): the vehicle moves + acceleration, // accelerates + neighbour, // a neighbour moves or accelerates + rest // active cab, switching, ezt/dmu + }; + bool switch_physics(bool const State, wake_cause const Cause = wake_cause::other); // whether the vehicle accelerates, for the test which turns the physics off in vehicles standing still (ComputeTotalForce()). // standing still, its acceleration is the pull of the slope and of the couplers, as the brakes and the resistance count only // against a speed (FTotal); with Global.physics_sleepheld one held by them, the way ComputeMovement() keeps it standing, doesn't diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 1f89c8c2..59e1aa0a 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -4745,7 +4745,7 @@ void TMoverParameters::UpdateScndPipePressure(double dt) c = Couplers[0].Connected; // skrot dv1 = 0.5 * dt * PF(ScndPipePress, c->ScndPipePress, Spz * 0.75); if (dv1 * dv1 > 0.00000000000001) - c->switch_physics(true); + c->switch_physics(true, wake_cause::scndpipe); c->Pipe2->Flow(-dv1); } // sprzeg 2 @@ -4754,7 +4754,7 @@ void TMoverParameters::UpdateScndPipePressure(double dt) c = Couplers[1].Connected; // skrot dv2 = 0.5 * dt * PF(ScndPipePress, c->ScndPipePress, Spz * 0.75); if (dv2 * dv2 > 0.00000000000001) - c->switch_physics(true); + c->switch_physics(true, wake_cause::scndpipe); c->Pipe2->Flow(-dv2); } if (Couplers[1].Connected != nullptr && Couplers[0].Connected != nullptr && TestFlag(Couplers[0].CouplingFlag, ctrain_scndpneumatic) && TestFlag(Couplers[1].CouplingFlag, ctrain_scndpneumatic)) @@ -4833,7 +4833,7 @@ double TMoverParameters::GetDVc(double dt) c = Couplers[0].Connected; // skrot //0.08 //e/D * L/D = e/D^2 * L dv1 = 0.5 * dt * PF(PipePress, c->PipePress, Spg / (1.0 + 0.015 / Spg * Dim.L)); if (dv1 * dv1 > 0.00000000000001) - c->switch_physics(true); + c->switch_physics(true, wake_cause::mainpipe); c->Pipe->Flow(-dv1); } // sprzeg 2 @@ -4842,7 +4842,7 @@ double TMoverParameters::GetDVc(double dt) c = Couplers[1].Connected; // skrot dv2 = 0.5 * dt * PF(PipePress, c->PipePress, Spg / (1.0 + 0.015 / Spg * Dim.L)); if (dv2 * dv2 > 0.00000000000001) - c->switch_physics(true); + c->switch_physics(true, wake_cause::mainpipe); c->Pipe->Flow(-dv2); } // if ((Couplers[1].Connected != NULL) && (Couplers[0].Connected != NULL)) @@ -4974,7 +4974,10 @@ void TMoverParameters::ComputeTotalForce(double dt) auto const calculatephysics{vehicleisactive || movingvehicleahead || movingvehiclebehind}; - switch_physics(calculatephysics); + switch_physics(calculatephysics, Vel > 0.0001 ? wake_cause::speed : + accelerating() ? wake_cause::acceleration : + vehicleisactive ? wake_cause::rest : + wake_cause::neighbour); } if (false == PhysicActivation) @@ -8941,7 +8944,7 @@ bool TMoverParameters::accelerating() const // ************************************************************************************************* // Kasowanie zmiennych pracy fizyki // ************************************************************************************************* -bool TMoverParameters::switch_physics(bool const State) // DO PRZETLUMACZENIA NA KONCU +bool TMoverParameters::switch_physics(bool const State, wake_cause const Cause) // DO PRZETLUMACZENIA NA KONCU { if (PhysicActivation == State) { @@ -8952,7 +8955,7 @@ bool TMoverParameters::switch_physics(bool const State) // DO PRZETLUMACZENIA NA if (true == State) { LastSwitchingTime = 0; - Timer::subsystem.switching.note(Timer::switching_counter::wake, this, &TypeName, &Name); + Timer::subsystem.switching.note(static_cast(Timer::switching_counter::wake + static_cast(Cause)), this, &TypeName, &Name); } return true; @@ -12720,7 +12723,7 @@ bool TMoverParameters::RunInternalCommand() CommandIn.Location.X = 0; CommandIn.Location.Y = 0; CommandIn.Location.Z = 0; - switch_physics(true); + switch_physics(true, wake_cause::command); } } else diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp index ebfb66ef..092fe894 100644 --- a/rendering/opengl46/opengl46renderer.cpp +++ b/rendering/opengl46/opengl46renderer.cpp @@ -883,7 +883,15 @@ void opengl46_renderer::SwapBuffers() 3, "switching per second: compressor on " + std::to_string( switching.events[ source::compressor_on ] ) + ", off " + std::to_string( switching.events[ source::compressor_off ] ) + ", mains " + std::to_string( switching.events[ source::mains ] ) + ", diesel " - + std::to_string( switching.events[ source::diesel ] ) + ", physics woken " + std::to_string( switching.events[ source::wake ] ), + + std::to_string( switching.events[ source::diesel ] ), + "" ); + text += timeline( + 3, + "physics woken per second: brake pipe " + std::to_string( switching.events[ source::wake_mainpipe ] ) + ", main reservoir pipe " + + std::to_string( switching.events[ source::wake_scndpipe ] ) + ", command " + std::to_string( switching.events[ source::wake_command ] ) + + ", speed " + std::to_string( switching.events[ source::wake_speed ] ) + ", acceleration " + + std::to_string( switching.events[ source::wake_acceleration ] ) + ", neighbour " + std::to_string( switching.events[ source::wake_neighbour ] ) + + ", cab/ezt " + std::to_string( switching.events[ source::wake_rest ] ) + ", other " + std::to_string( switching.events[ source::wake ] ), "" ); if( switching.busiestevents > 0 ) { text += timeline( 3, "most often: " + switching.busiest + " (" + std::to_string( switching.busiestevents ) + ")", "" ); diff --git a/utilities/Timer.h b/utilities/Timer.h index b9dd2018..07326a76 100644 --- a/utilities/Timer.h +++ b/utilities/Timer.h @@ -94,7 +94,15 @@ public: compressor_off, mains, diesel, - wake, // switch_physics( true ) of a vehicle whose physics was off + // switch_physics( true ) of a vehicle whose physics was off, by TMoverParameters::wake_cause, in its order + wake, + wake_mainpipe, + wake_scndpipe, + wake_command, + wake_speed, + wake_acceleration, + wake_neighbour, + wake_rest, count }; struct result {