16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-20 06:49:19 +02:00

refactoring: radio channel variable unification

This commit is contained in:
tmj-fstate
2019-10-24 17:38:08 +02:00
parent f26c2315e3
commit 27d5b55ca6
2 changed files with 11 additions and 10 deletions

View File

@@ -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 ) {

View File

@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
#include <string>
#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<std::pair<std::string, texture_handle>> 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<std::string> 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; };