From 00bb44a7898fa22bcd8e31f39647e57036a2d0db Mon Sep 17 00:00:00 2001 From: combolek <4743344+combolek@users.noreply.github.com> Date: Sun, 26 Jul 2026 17:56:44 -0700 Subject: [PATCH 1/3] state_manager: Optimize computation of pressure flow for Oerlikon ESt valves TNESt3::GetPF() is a *major* hotspot in simulation state update. The leading cause is the use of typeid (RTTI) which is implemented in the C++ runtime essentially as a string compare. This change eliminates the use of typeid and instead caches statically typed pointers for the few TPrzekladnik subclass objects that need their parameters adjusted in TNESt3::GetPF(). As a bonus some virtual methods on TPrzekladnik can now be removed. Overall this change reduces the TNESt3::GetPF() contribution from about 25% to 16%. --- McZapkie/Oerlikon_ESt.cpp | 64 ++++++++++++++++++++++----------------- McZapkie/Oerlikon_ESt.h | 14 ++++----- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/McZapkie/Oerlikon_ESt.cpp b/McZapkie/Oerlikon_ESt.cpp index 1df5fe81..a787a09d 100644 --- a/McZapkie/Oerlikon_ESt.cpp +++ b/McZapkie/Oerlikon_ESt.cpp @@ -237,26 +237,24 @@ double TNESt3::GetPF( double const PP, double const dt, double const Vel ) // pr BrakeRes->Flow(dV); for (int i = 1; i < 4; ++i) - { Przekladniki[i]->Update(dt); - if (typeid(*Przekladniki[i]) == typeid(TRapid)) - { - RapidStatus = (BrakeDelayFlag & bdelay_R) == bdelay_R && (std::abs(Vel) > 70.0 || (std::abs(Vel) > 50.0 && RapidStatus) || RapidStaly); - Przekladniki[i]->SetRapidStatus(RapidStatus); - } - else if( typeid( *Przekladniki[i] ) == typeid( TPrzeciwposlizg ) ) - Przekladniki[i]->SetPoslizg((BrakeStatus & b_asb) == b_asb); - else if( typeid( *Przekladniki[ i ] ) == typeid( TPrzekED ) ) { - if( Vel < -15.0 ) - Przekladniki[ i ]->SetP( 0.0 ); - else - Przekladniki[ i ]->SetP( MaxBP * 3.0 ); - } - else if( typeid( *Przekladniki[i] ) == typeid( TPrzekCiagly ) ) - Przekladniki[i]->SetMult(LoadC); - else if( typeid( *Przekladniki[i] ) == typeid( TPrzek_PZZ ) ) - Przekladniki[i]->SetLBP(LBP); + + if( PrzekRapid != nullptr ) { + RapidStatus = (BrakeDelayFlag & bdelay_R) == bdelay_R && (std::abs(Vel) > 70.0 || (std::abs(Vel) > 50.0 && RapidStatus) || RapidStaly); + PrzekRapid->SetRapidStatus(RapidStatus); } + if( PrzekPoslizg != nullptr ) + PrzekPoslizg->SetPoslizg((BrakeStatus & b_asb) == b_asb); + if( PrzekED != nullptr ) { + if( Vel < -15.0 ) + PrzekED->SetP( 0.0 ); + else + PrzekED->SetP( MaxBP * 3.0 ); + } + if( PrzekCiagly != nullptr ) + PrzekCiagly->SetMult(LoadC); + if( PrzekPZZ != nullptr ) + PrzekPZZ->SetLBP(LBP); // przeplyw testowy miedzypojemnosci dV = PF(MPP, VVP, BVs(BCP)) + PF(MPP, CVP, CVs(BCP)); @@ -458,6 +456,12 @@ void TNESt3::SetSize( int const size, std::string const ¶ms ) // ustawianie static double const dOO1l = 0.907; static double const dOT1l = 0.524; + PrzekRapid.reset(); + PrzekPoslizg.reset(); + PrzekED.reset(); + PrzekCiagly.reset(); + PrzekPZZ.reset(); + if (contains( params, "ESt3" ) ) { Podskok = 0.7; @@ -467,23 +471,27 @@ void TNESt3::SetSize( int const size, std::string const ¶ms ) // ustawianie else { Podskok = -1.0; - Przekladniki[1] = std::make_shared(); - if (contains( params, "-s216" ) ) - Przekladniki[1]->SetRapidParams(2, 16); - else - Przekladniki[1]->SetRapidParams(2, 0); - Przekladniki[3] = std::make_shared(); + Przekladniki[1] = PrzekRapid = std::make_shared(); + if (contains( params,"-ED") ) { - Przekladniki[1]->SetRapidParams(2, 18); - Przekladniki[3] = std::make_shared(); + PrzekRapid->SetRapidParams(2, 18); + Przekladniki[3] = PrzekED = std::make_shared(); + } + else + { + if (contains( params, "-s216" ) ) + PrzekRapid->SetRapidParams(2, 16); + else + PrzekRapid->SetRapidParams(2, 0); + Przekladniki[3] = PrzekPoslizg = std::make_shared(); } } if (contains(params,"AL2") ) - Przekladniki[2] = std::make_shared(); + Przekladniki[2] = PrzekCiagly = std::make_shared(); else if (contains(params,"PZZ") ) - Przekladniki[2] = std::make_shared(); + Przekladniki[2] = PrzekPZZ = std::make_shared(); else Przekladniki[2] = std::make_shared(); diff --git a/McZapkie/Oerlikon_ESt.h b/McZapkie/Oerlikon_ESt.h index a6b6f3d0..51d787be 100644 --- a/McZapkie/Oerlikon_ESt.h +++ b/McZapkie/Oerlikon_ESt.h @@ -76,12 +76,6 @@ class TPrzekladnik : public TReservoir // przekladnik (powtarzacz) TPrzekladnik() : TReservoir() {}; virtual void Update(double dt); - virtual void SetPoslizg(bool flag) {}; - virtual void SetP(double P) {}; - virtual void SetMult(double m) {}; - virtual void SetLBP(double P) {}; - virtual void SetRapidParams(double mult, double size) {}; - virtual void SetRapidStatus(bool rs) {}; }; class TRura : public TPrzekladnik // nieprzekladnik, rura laczaca @@ -185,7 +179,13 @@ class TNESt3 : public TBrake { private: std::shared_ptr CntrlRes; // zbiornik sterujacy std::shared_ptr Miedzypoj; // pojemnosc posrednia (urojona) do napelniania ZP i ZS - std::shared_ptr Przekladniki[ 4 ]; + std::shared_ptr Przekladniki[ 4 ]; // indeksowane od 1, indeks jest zarazem pojemnoscia + // bezposrednie wskazniki do przekladnikow dostrajanych w GetPF, inicjowane przy tworzeniu + std::shared_ptr PrzekRapid; + std::shared_ptr PrzekPoslizg; + std::shared_ptr PrzekED; + std::shared_ptr PrzekCiagly; + std::shared_ptr PrzekPZZ; double Nozzles[ dMAX ]; // dysze double BVM = 0.0; // przelozenie PG-CH // ValveFlag: byte; //polozenie roznych zaworkow From 12c583f41894bec2a680dea2f1063205a362591e Mon Sep 17 00:00:00 2001 From: combolek <4743344+combolek@users.noreply.github.com> Date: Tue, 28 Jul 2026 08:54:33 -0700 Subject: [PATCH 2/3] Fix some SonarQube warnings --- McZapkie/Oerlikon_ESt.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/McZapkie/Oerlikon_ESt.cpp b/McZapkie/Oerlikon_ESt.cpp index a787a09d..9559d305 100644 --- a/McZapkie/Oerlikon_ESt.cpp +++ b/McZapkie/Oerlikon_ESt.cpp @@ -471,12 +471,14 @@ void TNESt3::SetSize( int const size, std::string const ¶ms ) // ustawianie else { Podskok = -1.0; - Przekladniki[1] = PrzekRapid = std::make_shared(); + PrzekRapid = std::make_shared(); + Przekladniki[1] = PrzekRapid; if (contains( params,"-ED") ) { PrzekRapid->SetRapidParams(2, 18); - Przekladniki[3] = PrzekED = std::make_shared(); + PrzekED = std::make_shared(); + Przekladniki[3] = PrzekED; } else { @@ -484,14 +486,21 @@ void TNESt3::SetSize( int const size, std::string const ¶ms ) // ustawianie PrzekRapid->SetRapidParams(2, 16); else PrzekRapid->SetRapidParams(2, 0); - Przekladniki[3] = PrzekPoslizg = std::make_shared(); + PrzekPoslizg = std::make_shared(); + Przekladniki[3] = PrzekPoslizg; } } if (contains(params,"AL2") ) - Przekladniki[2] = PrzekCiagly = std::make_shared(); + { + PrzekCiagly = std::make_shared(); + Przekladniki[2] = PrzekCiagly; + } else if (contains(params,"PZZ") ) - Przekladniki[2] = PrzekPZZ = std::make_shared(); + { + PrzekPZZ = std::make_shared(); + Przekladniki[2] = PrzekPZZ; + } else Przekladniki[2] = std::make_shared(); From 19441b5e91331b0441a577d7e2db4498f709b339 Mon Sep 17 00:00:00 2001 From: combolek <4743344+combolek@users.noreply.github.com> Date: Tue, 28 Jul 2026 09:01:21 -0700 Subject: [PATCH 3/3] Convert Przekladniki to std::array --- McZapkie/Oerlikon_ESt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/McZapkie/Oerlikon_ESt.h b/McZapkie/Oerlikon_ESt.h index 51d787be..c1269185 100644 --- a/McZapkie/Oerlikon_ESt.h +++ b/McZapkie/Oerlikon_ESt.h @@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/. Copyright (C) 2007-2014 Maciej Cierniak */ +#include #include #include "hamulce.h" // Pascal unit #include "friction.h" // Pascal unit @@ -179,7 +180,7 @@ class TNESt3 : public TBrake { private: std::shared_ptr CntrlRes; // zbiornik sterujacy std::shared_ptr Miedzypoj; // pojemnosc posrednia (urojona) do napelniania ZP i ZS - std::shared_ptr Przekladniki[ 4 ]; // indeksowane od 1, indeks jest zarazem pojemnoscia + std::array, 4> Przekladniki; // indeksowane od 1, indeks jest zarazem pojemnoscia // bezposrednie wskazniki do przekladnikow dostrajanych w GetPF, inicjowane przy tworzeniu std::shared_ptr PrzekRapid; std::shared_ptr PrzekPoslizg;