From 45fc26c59641a7bc847ad27d0d527b3cdd601d35 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Mon, 4 Jun 2018 00:05:36 +0200 Subject: [PATCH] brake delay command propagation, vehicle controller state command fixes --- McZapkie/Mover.cpp | 1 + Train.cpp | 32 +++++++++++++++++++++++--------- uilayer.cpp | 12 +++++++++--- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 0034732f..47368df9 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -9574,6 +9574,7 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C else { OK = false; } + SendCtrlToNext( Command, CValue1, CValue2, Couplertype ); } else if (Command == "Sandbox") { diff --git a/Train.cpp b/Train.cpp index e72dc35b..1d830d27 100644 --- a/Train.cpp +++ b/Train.cpp @@ -740,12 +740,22 @@ void TTrain::OnCommand_mastercontrollerdecreasefast( TTrain *Train, command_data void TTrain::OnCommand_mastercontrollerset( TTrain *Train, command_data const &Command ) { - auto const targetposition { std::min( Command.param1, Train->mvControlled->MainCtrlPosNo ) }; - while( targetposition < Train->mvControlled->MainCtrlPos ) { - Train->mvControlled->DecMainCtrl( 1 ); + auto positionchange { + std::min( + Command.param1, + ( Train->mvControlled->CoupledCtrl ? + Train->mvControlled->MainCtrlPosNo + Train->mvControlled->ScndCtrlPosNo : + Train->mvControlled->MainCtrlPosNo ) ) + - ( Train->mvControlled->CoupledCtrl ? + Train->mvControlled->MainCtrlPos + Train->mvControlled->ScndCtrlPos : + Train->mvControlled->MainCtrlPos ) }; + while( ( positionchange < 0 ) + && ( true == Train->mvControlled->DecMainCtrl( 1 ) ) ) { + ++positionchange; } - while( targetposition > Train->mvControlled->MainCtrlPos ) { - Train->mvControlled->IncMainCtrl( 1 ); + while( ( positionchange > 0 ) + && ( true == Train->mvControlled->IncMainCtrl( 1 ) ) ) { + --positionchange; } } @@ -850,11 +860,15 @@ void TTrain::OnCommand_secondcontrollerdecreasefast( TTrain *Train, command_data void TTrain::OnCommand_secondcontrollerset( TTrain *Train, command_data const &Command ) { auto const targetposition { std::min( Command.param1, Train->mvControlled->ScndCtrlPosNo ) }; - while( targetposition < Train->mvControlled->ScndCtrlPos ) { - Train->mvControlled->DecScndCtrl( 1 ); + while( ( targetposition < Train->mvControlled->ScndCtrlPos ) + && ( true == Train->mvControlled->DecScndCtrl( 1 ) ) ) { + // all work is done in the header + ; } - while( targetposition > Train->mvControlled->ScndCtrlPos ) { - Train->mvControlled->IncScndCtrl( 1 ); + while( ( targetposition > Train->mvControlled->ScndCtrlPos ) + && ( true == Train->mvControlled->IncScndCtrl( 1 ) ) ) { + // all work is done in the header + ; } } diff --git a/uilayer.cpp b/uilayer.cpp index 40a08c22..b31d716e 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -283,11 +283,17 @@ ui_layer::update() { if( Global.iScreenMode[ Global.iTextMode - GLFW_KEY_F1 ] == 1 ) { // detail mode on second key press + auto const speedlimit { static_cast( std::floor( driver->VelDesired ) ) }; uitextline2 += " Speed: " + std::to_string( static_cast( std::floor( mover->Vel ) ) ) + " km/h" - + " (limit: " + std::to_string( static_cast( std::floor( driver->VelDesired ) ) ) + " km/h" - + ", next limit: " + std::to_string( static_cast( std::floor( controlled->Mechanik->VelNext ) ) ) + " km/h" - + " in " + to_string( controlled->Mechanik->ActualProximityDist * 0.001, 1 ) + " km)"; + + " (limit: " + std::to_string( speedlimit ) + " km/h"; + auto const nextspeedlimit { static_cast( std::floor( controlled->Mechanik->VelNext ) ) }; + if( nextspeedlimit != speedlimit ) { + uitextline2 += + ", new limit: " + std::to_string( nextspeedlimit ) + " km/h" + + " in " + to_string( controlled->Mechanik->ActualProximityDist * 0.001, 1 ) + " km"; + } + uitextline2 += ")"; uitextline3 += " Pressure: " + to_string( mover->BrakePress * 100.0, 2 ) + " kPa" + " (train pipe: " + to_string( mover->PipePress * 100.0, 2 ) + " kPa)";