From 27d5b55ca6b33ed0f62781f278710d8d0dbec3dd Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Thu, 24 Oct 2019 17:38:08 +0200 Subject: [PATCH] refactoring: radio channel variable unification --- Train.cpp | 16 ++++++++-------- Train.h | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Train.cpp b/Train.cpp index 660550dd..27bec525 100644 --- a/Train.cpp +++ b/Train.cpp @@ -524,7 +524,7 @@ dictionary_source *TTrain::GetTrainState() { dict->insert( "distance_counter", m_distancecounter ); dict->insert( "pantpress", std::abs( mvControlled->PantPress ) ); dict->insert( "universal3", InstrumentLightActive ); - dict->insert( "radio_channel", iRadioChannel ); + dict->insert( "radio_channel", RadioChannel() ); dict->insert( "door_lock", mvOccupied->Doors.lock_enabled ); // movement data dict->insert( "velocity", std::abs( mvOccupied->Vel ) ); @@ -5353,9 +5353,9 @@ void TTrain::OnCommand_radiotoggle( TTrain *Train, command_data const &Command ) void TTrain::OnCommand_radiochannelincrease( TTrain *Train, command_data const &Command ) { if( Command.action == GLFW_PRESS ) { - Train->iRadioChannel = clamp( Train->iRadioChannel + 1, 1, 10 ); + Train->RadioChannel() = clamp( Train->RadioChannel() + 1, 1, 10 ); // visual feedback - Train->ggRadioChannelSelector.UpdateValue( Train->iRadioChannel - 1 ); + Train->ggRadioChannelSelector.UpdateValue( Train->RadioChannel() - 1 ); Train->ggRadioChannelNext.UpdateValue( 1.0 ); } else if( Command.action == GLFW_RELEASE ) { @@ -5367,9 +5367,9 @@ void TTrain::OnCommand_radiochannelincrease( TTrain *Train, command_data const & void TTrain::OnCommand_radiochanneldecrease( TTrain *Train, command_data const &Command ) { if( Command.action == GLFW_PRESS ) { - Train->iRadioChannel = clamp( Train->iRadioChannel - 1, 1, 10 ); + Train->RadioChannel() = clamp( Train->RadioChannel() - 1, 1, 10 ); // visual feedback - Train->ggRadioChannelSelector.UpdateValue( Train->iRadioChannel - 1 ); + Train->ggRadioChannelSelector.UpdateValue( Train->RadioChannel() - 1 ); Train->ggRadioChannelPrevious.UpdateValue( 1.0 ); } else if( Command.action == GLFW_RELEASE ) { @@ -7085,7 +7085,7 @@ void TTrain::update_sounds_radio() { for( auto &message : m_radiomessages ) { auto const volume { ( true == radioenabled ) - && ( message.first == iRadioChannel ) ? + && ( message.first == RadioChannel() ) ? Global.RadioVolume : 0.0 }; message.second->gain( volume ); @@ -7743,7 +7743,7 @@ TTrain::radio_message( sound_source *Message, int const Channel ) { auto const radioenabled { ( true == mvOccupied->Radio ) && ( mvControlled->Battery || mvControlled->ConverterFlag ) }; auto const volume { ( true == radioenabled ) - && ( Channel == iRadioChannel ) ? + && ( Channel == RadioChannel() ) ? 1.0 : 0.0 }; message @@ -8038,7 +8038,7 @@ void TTrain::set_cab_controls( int const Cab ) { if( true == mvOccupied->Radio ) { ggRadioButton.PutValue( 1.f ); } - ggRadioChannelSelector.PutValue( iRadioChannel - 1 ); + ggRadioChannelSelector.PutValue( RadioChannel() - 1 ); // pantographs if( mvOccupied->PantSwitchType != "impulse" ) { if( ggPantFrontButton.SubModel ) { diff --git a/Train.h b/Train.h index e4a20388..08a43e01 100644 --- a/Train.h +++ b/Train.h @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include #include "DynObj.h" +#include "Driver.h" #include "Button.h" #include "Gauge.h" #include "sound.h" @@ -729,7 +730,6 @@ private: float fPPress, fNPress; bool m_mastercontrollerinuse { false }; float m_mastercontrollerreturndelay { 0.f }; - int iRadioChannel { 1 }; // numer aktualnego kana?u radiowego std::vector> m_screens; float m_distancecounter { -1.f }; // distance traveled since meter was activated or -1 if inactive @@ -739,9 +739,10 @@ private: static std::vector const fPress_labels; float fEIMParams[9][10]; // parametry dla silnikow asynchronicznych float fDieselParams[9][10]; // parametry dla silnikow asynchronicznych - int RadioChannel() const { return iRadioChannel; }; // plays provided sound from position of the radio void radio_message( sound_source *Message, int const Channel ); + inline auto const &RadioChannel() const { return Dynamic()->Mechanik->iRadioChannel; } + inline auto &RadioChannel() { return Dynamic()->Mechanik->iRadioChannel; } inline TDynamicObject *Dynamic() { return DynamicObject; }; inline TDynamicObject const *Dynamic() const { return DynamicObject; }; inline TMoverParameters *Controlled() { return mvControlled; };