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

switches for local converter and compressor, motor connector fix for multi-unit engines, crossroad generation fixes for vbo render path

This commit is contained in:
tmj-fstate
2017-05-23 02:25:56 +02:00
parent e805533f54
commit 9f07e2b504
16 changed files with 425 additions and 249 deletions

247
Train.cpp
View File

@@ -175,8 +175,10 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::pantographlowerall, &TTrain::OnCommand_pantographlowerall },
{ user_command::linebreakertoggle, &TTrain::OnCommand_linebreakertoggle },
{ user_command::convertertoggle, &TTrain::OnCommand_convertertoggle },
{ user_command::convertertogglelocal, &TTrain::OnCommand_convertertogglelocal },
{ user_command::converteroverloadrelayreset, &TTrain::OnCommand_converteroverloadrelayreset },
{ user_command::compressortoggle, &TTrain::OnCommand_compressortoggle },
{ user_command::compressortogglelocal, &TTrain::OnCommand_compressortogglelocal },
{ user_command::motorconnectorsopen, &TTrain::OnCommand_motorconnectorsopen },
{ user_command::motordisconnect, &TTrain::OnCommand_motordisconnect },
{ user_command::motoroverloadrelaythresholdtoggle, &TTrain::OnCommand_motoroverloadrelaythresholdtoggle },
@@ -1727,6 +1729,69 @@ void TTrain::OnCommand_convertertoggle( TTrain *Train, command_data const &Comma
}
}
void TTrain::OnCommand_convertertogglelocal( TTrain *Train, command_data const &Command ) {
if( Train->mvOccupied->ConverterStart == start::automatic ) {
// let the automatic thing do its automatic thing...
return;
}
if( Train->ggConverterLocalButton.SubModel == nullptr ) {
return;
}
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( ( false == Train->mvOccupied->ConverterAllowLocal )
&& ( Train->ggConverterLocalButton.GetValue() < 0.5 ) ) {
// turn on
// sound feedback
if( Train->ggConverterLocalButton.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggConverterLocalButton.UpdateValue( 1.0 );
// effect
Train->mvOccupied->ConverterAllowLocal = true;
/*
if( true == Train->mvControlled->ConverterSwitch( true, range::local ) ) {
// side effects
// control the compressor, if it's paired with the converter
if( Train->mvControlled->CompressorPower == 2 ) {
// hunter-091012: tak jest poprawnie
Train->mvControlled->CompressorSwitch( true, range::local );
}
}
*/
}
else {
//turn off
// sound feedback
if( Train->ggConverterLocalButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggConverterLocalButton.UpdateValue( 0.0 );
// effect
Train->mvOccupied->ConverterAllowLocal = false;
/*
if( true == Train->mvControlled->ConverterSwitch( false, range::local ) ) {
// side effects
// control the compressor, if it's paired with the converter
if( Train->mvControlled->CompressorPower == 2 ) {
// hunter-091012: tak jest poprawnie
Train->mvControlled->CompressorSwitch( false, range::local );
}
// if there's no (low voltage) power source left, drop pantographs
if( false == Train->mvControlled->Battery ) {
Train->mvControlled->PantFront( false, range::local );
Train->mvControlled->PantRear( false, range::local );
}
}
*/
}
}
}
void TTrain::OnCommand_converteroverloadrelayreset( TTrain *Train, command_data const &Command ) {
if( Train->ggConverterFuseButton.SubModel == nullptr ) {
@@ -1824,6 +1889,42 @@ void TTrain::OnCommand_compressortoggle( TTrain *Train, command_data const &Comm
*/
}
void TTrain::OnCommand_compressortogglelocal( TTrain *Train, command_data const &Command ) {
if( Train->mvOccupied->CompressorPower >= 2 ) {
return;
}
if( Train->ggCompressorLocalButton.SubModel == nullptr ) {
return;
}
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == Train->mvOccupied->CompressorAllowLocal ) {
// turn on
// sound feedback
if( Train->ggCompressorLocalButton.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggCompressorLocalButton.UpdateValue( 1.0 );
// effect
Train->mvOccupied->CompressorAllowLocal = true;
}
else {
//turn off
// sound feedback
if( Train->ggCompressorLocalButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggCompressorLocalButton.UpdateValue( 0.0 );
// effect
Train->mvOccupied->CompressorAllowLocal = false;
}
}
}
void TTrain::OnCommand_motorconnectorsopen( TTrain *Train, command_data const &Command ) {
// TODO: don't rely on presense of 3d model to determine presence of the switch
@@ -1833,31 +1934,111 @@ void TTrain::OnCommand_motorconnectorsopen( TTrain *Train, command_data const &C
}
return;
}
if( Command.action != GLFW_RELEASE ) {
// button works while it's held down
if( true == Train->mvControlled->StLinFlag ) {
// NOTE: because we don't have modeled actual circuits this is a simplification of the real mechanics
// namely, pressing the button will flip it in the entire unit, which isn't exactly physically possible
if( Command.action == GLFW_PRESS ) {
// button works while it's held down but we can only pay attention to initial press
if( false == Train->mvControlled->StLinSwitchOff ) {
// open the connectors
Train->mvControlled->StLinSwitchOff = true;
if( ( Train->mvControlled->TrainType == dt_ET41 )
|| ( Train->mvControlled->TrainType == dt_ET42 ) ) {
// crude implementation of the butto affecting entire unit for multi-unit engines
// TODO: rework it into part of standard command propagation system
if( ( Train->mvControlled->Couplers[ 0 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 0 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 0 ].Connected->StLinSwitchOff = true;
}
if( ( Train->mvControlled->Couplers[ 1 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 1 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 1 ].Connected->StLinSwitchOff = true;
}
}
// sound feedback
if( Train->ggStLinOffButton.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggStLinOffButton.UpdateValue( 1.0 );
// effect
if( true == Train->mvControlled->StLinFlag ) {
Train->play_sound( Train->dsbRelay );
}
// yBARC - zmienione na przeciwne, bo true to zalaczone
Train->mvControlled->StLinFlag = false;
Train->play_sound( Train->dsbRelay );
if( ( Train->mvControlled->TrainType == dt_ET41 )
|| ( Train->mvControlled->TrainType == dt_ET42 ) ) {
// crude implementation of the butto affecting entire unit for multi-unit engines
// TODO: rework it into part of standard command propagation system
if( ( Train->mvControlled->Couplers[ 0 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 0 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 0 ].Connected->StLinFlag = false;
}
if( ( Train->mvControlled->Couplers[ 1 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 1 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 1 ].Connected->StLinFlag = false;
}
}
}
Train->mvControlled->StLinSwitchOff = true;
// sound feedback
if( Train->ggStLinOffButton.GetValue() < 0.05 ) {
Train->play_sound( Train->dsbSwitch );
else {
if( Train->mvControlled->StLinSwitchType == "toggle" ) {
// default type of button (impulse) has only one effect on press, but the toggle type can toggle the state
Train->mvControlled->StLinSwitchOff = false;
if( ( Train->mvControlled->TrainType == dt_ET41 )
|| ( Train->mvControlled->TrainType == dt_ET42 ) ) {
// crude implementation of the butto affecting entire unit for multi-unit engines
// TODO: rework it into part of standard command propagation system
if( ( Train->mvControlled->Couplers[ 0 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 0 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 0 ].Connected->StLinSwitchOff = false;
}
if( ( Train->mvControlled->Couplers[ 1 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 1 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 1 ].Connected->StLinSwitchOff = false;
}
}
// sound feedback
if( Train->ggStLinOffButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggStLinOffButton.UpdateValue( 0.0 );
}
}
// visual feedback
Train->ggStLinOffButton.UpdateValue( 1.0 );
}
else {
else if( Command.action == GLFW_RELEASE ) {
// button released
Train->mvControlled->StLinSwitchOff = false;
// sound feedback
if( Train->ggStLinOffButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
if( Train->mvControlled->StLinSwitchType != "toggle" ) {
// default button type (impulse) works on button release
Train->mvControlled->StLinSwitchOff = false;
if( ( Train->mvControlled->TrainType == dt_ET41 )
|| ( Train->mvControlled->TrainType == dt_ET42 ) ) {
// crude implementation of the butto affecting entire unit for multi-unit engines
// TODO: rework it into part of standard command propagation system
if( ( Train->mvControlled->Couplers[ 0 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 0 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 0 ].Connected->StLinSwitchOff = false;
}
if( ( Train->mvControlled->Couplers[ 1 ].Connected != nullptr )
&& ( true == TestFlag( Train->mvControlled->Couplers[ 1 ].CouplingFlag, coupling::permanent ) ) ) {
// the first unit isn't allowed to start its compressor until second unit can start its own as well
Train->mvControlled->Couplers[ 1 ].Connected->StLinSwitchOff = false;
}
}
// sound feedback
if( Train->ggStLinOffButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggStLinOffButton.UpdateValue( 0.0 );
}
// visual feedback
Train->ggStLinOffButton.UpdateValue( 0.0 );
}
}
@@ -4674,9 +4855,11 @@ bool TTrain::Update( double const Deltatime )
ggDepartureSignalButton.Update();
// NBMX dzwignia sprezarki
ggCompressorButton.Update();
ggCompressorLocalButton.Update();
ggMainButton.Update();
ggRadioButton.Update();
ggConverterButton.Update();
ggConverterLocalButton.Update();
ggConverterOffButton.Update();
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
@@ -6604,6 +6787,11 @@ void TTrain::set_cab_controls() {
if( true == mvOccupied->Battery ) {
ggBatteryButton.PutValue( 1.0 );
}
// motor connectors
ggStLinOffButton.PutValue(
( mvControlled->StLinSwitchOff ?
1.0 :
0.0 ) );
// radio
if( true == mvOccupied->Radio ) {
ggRadioButton.PutValue( 1.0 );
@@ -6636,10 +6824,19 @@ void TTrain::set_cab_controls() {
1.0 :
0.0 );
}
ggConverterLocalButton.PutValue(
mvControlled->ConverterAllowLocal ?
1.0 :
0.0 );
// compressor
if( true == mvControlled->CompressorAllow ) {
ggCompressorButton.PutValue( 1.0 );
}
ggCompressorButton.PutValue(
mvControlled->CompressorAllow ?
1.0 :
0.0 );
ggCompressorLocalButton.PutValue(
mvControlled->CompressorAllowLocal ?
1.0 :
0.0 );
// motor overload relay threshold / shunt mode
if( mvControlled->Imax == mvControlled->ImaxHi ) {
ggMaxCurrentCtrl.PutValue( 1.0 );
@@ -7175,11 +7372,19 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
// sprezarka
ggCompressorButton.Load(Parser, DynamicObject->mdKabina);
}
else if( Label == "compressorlocal_sw:" ) {
// sprezarka
ggCompressorLocalButton.Load( Parser, DynamicObject->mdKabina );
}
else if (Label == "converter_sw:")
{
// przetwornica
ggConverterButton.Load(Parser, DynamicObject->mdKabina);
}
else if( Label == "converterlocal_sw:" ) {
// przetwornica
ggConverterLocalButton.Load( Parser, DynamicObject->mdKabina );
}
else if (Label == "converteroff_sw:")
{
// przetwornica wyl