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

overload relay control, generic brake handles sound fix

This commit is contained in:
tmj-fstate
2017-04-14 15:17:32 +02:00
parent fafb7a63c3
commit 57c213fd1d
8 changed files with 189 additions and 71 deletions

View File

@@ -676,10 +676,23 @@ bool TMoverParameters::CurrentSwitch(int direction)
if (TrainType != dt_EZT) if (TrainType != dt_EZT)
return (MinCurrentSwitch(direction != 0)); return (MinCurrentSwitch(direction != 0));
} }
if (EngineType == DieselEngine) // dla 2Ls150 // TBD, TODO: split off shunt mode toggle into a separate command? It doesn't make much sense to have these two together like that
if (ShuntModeAllow) // dla 2Ls150
if (ActiveDir == 0) // przed ustawieniem kierunku if( ( EngineType == DieselEngine )
ShuntMode = ( direction != 0 ); && ( true == ShuntModeAllow )
&& ( ActiveDir == 0 ) ) {
// przed ustawieniem kierunku
ShuntMode = ( direction != 0 );
return true;
}
// for SM42/SP42
if( ( EngineType == DieselElectric )
&& ( true == ShuntModeAllow )
&& ( MainCtrlPos == 0 ) ) {
ShuntMode = ( direction != 0 );
return true;
}
return false; return false;
}; };

View File

@@ -48,6 +48,7 @@ class TRealSound
int GetStatus(); int GetStatus();
void ResetPosition(); void ResetPosition();
// void FreqReset(float f=22050.0) {fFrequency=f;}; // void FreqReset(float f=22050.0) {fFrequency=f;};
bool Empty() { return ( pSound == nullptr ); }
}; };
class TTextSound : public TRealSound class TTextSound : public TRealSound

154
Train.cpp
View File

@@ -165,6 +165,7 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::linebreakertoggle, &TTrain::OnCommand_linebreakertoggle }, { user_command::linebreakertoggle, &TTrain::OnCommand_linebreakertoggle },
{ user_command::convertertoggle, &TTrain::OnCommand_convertertoggle }, { user_command::convertertoggle, &TTrain::OnCommand_convertertoggle },
{ user_command::compressortoggle, &TTrain::OnCommand_compressortoggle }, { user_command::compressortoggle, &TTrain::OnCommand_compressortoggle },
{ user_command::motoroverloadrelaythresholdtoggle, &TTrain::OnCommand_motoroverloadrelaythresholdtoggle },
{ user_command::headlighttoggleleft, &TTrain::OnCommand_headlighttoggleleft }, { user_command::headlighttoggleleft, &TTrain::OnCommand_headlighttoggleleft },
{ user_command::headlighttoggleright, &TTrain::OnCommand_headlighttoggleright }, { user_command::headlighttoggleright, &TTrain::OnCommand_headlighttoggleright },
{ user_command::headlighttoggleupper, &TTrain::OnCommand_headlighttoggleupper }, { user_command::headlighttoggleupper, &TTrain::OnCommand_headlighttoggleupper },
@@ -639,14 +640,14 @@ void TTrain::OnCommand_trainbrakeincrease( TTrain *Train, command_data const &Co
void TTrain::OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Command ) {
if( Command.action != GLFW_RELEASE ) { if( Command.action != GLFW_RELEASE ) {
// press or hold
if( Train->mvOccupied->BrakeHandle == FV4a ) { if( Train->mvOccupied->BrakeHandle == FV4a ) {
Train->mvOccupied->BrakeLevelAdd( -0.1 /*-15.0 * Command.time_delta*/ ); Train->mvOccupied->BrakeLevelAdd( -0.1 /*-15.0 * Command.time_delta*/ );
} }
else { else {
// nową wersję dostarczył ZiomalCl ("fixed looped sound in ezt when using NUM_9 key") // nową wersję dostarczył ZiomalCl ("fixed looped sound in ezt when using NUM_9 key")
if( ( Train->mvOccupied->BrakeCtrlPos > -1 ) if( ( Train->mvOccupied->BrakeCtrlPos > -1 )
|| ( Train->keybrakecount > 1 ) ) { || ( Train->keybrakecount > 1 ) ) {
if( ( Train->is_eztoer() ) if( ( Train->is_eztoer() )
&& ( Train->mvControlled->Mains ) && ( Train->mvControlled->Mains )
@@ -661,12 +662,29 @@ void TTrain::OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Co
// koniec wersji dostarczonej przez ZiomalCl // koniec wersji dostarczonej przez ZiomalCl
} }
} }
else {
// release
if( ( Train->mvOccupied->BrakeCtrlPos == -1 )
&& ( Train->mvOccupied->BrakeHandle == FVel6 )
&& ( Train->DynamicObject->Controller != AIdriver )
&& ( Global::iFeedbackMode != 4 )
&& ( !( Global::bMWDmasterEnable && Global::bMWDBreakEnable ) ) ) {
// Odskakiwanie hamulce EP
Train->mvOccupied->BrakeLevelSet( Train->mvOccupied->BrakeCtrlPos + 1 );
Train->keybrakecount = 0;
if( ( Train->mvOccupied->TrainType == dt_EZT )
&& ( Train->mvControlled->Mains )
&& ( Train->mvControlled->ActiveDir != 0 ) ) {
Train->play_sound( Train->dsbPneumaticSwitch );
}
}
}
} }
void TTrain::OnCommand_trainbrakecharging( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_trainbrakecharging( TTrain *Train, command_data const &Command ) {
if( Command.action != GLFW_RELEASE ) { if( Command.action != GLFW_RELEASE ) {
// press or hold
// sound feedback // sound feedback
if( ( Train->is_eztoer() ) if( ( Train->is_eztoer() )
&& ( Train->mvControlled->Mains ) && ( Train->mvControlled->Mains )
@@ -676,6 +694,23 @@ void TTrain::OnCommand_trainbrakecharging( TTrain *Train, command_data const &Co
Train->mvOccupied->BrakeLevelSet( -1 ); Train->mvOccupied->BrakeLevelSet( -1 );
} }
else {
// release
if( ( Train->mvOccupied->BrakeCtrlPos == -1 )
&& ( Train->mvOccupied->BrakeHandle == FVel6 )
&& ( Train->DynamicObject->Controller != AIdriver )
&& ( Global::iFeedbackMode != 4 )
&& ( !( Global::bMWDmasterEnable && Global::bMWDBreakEnable ) ) ) {
// Odskakiwanie hamulce EP
Train->mvOccupied->BrakeLevelSet( Train->mvOccupied->BrakeCtrlPos + 1 );
Train->keybrakecount = 0;
if( ( Train->mvOccupied->TrainType == dt_EZT )
&& ( Train->mvControlled->Mains )
&& ( Train->mvControlled->ActiveDir != 0 ) ) {
Train->play_sound( Train->dsbPneumaticSwitch );
}
}
}
} }
void TTrain::OnCommand_trainbrakerelease( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_trainbrakerelease( TTrain *Train, command_data const &Command ) {
@@ -1330,6 +1365,35 @@ void TTrain::OnCommand_compressortoggle( TTrain *Train, command_data const &Comm
*/ */
} }
void TTrain::OnCommand_motoroverloadrelaythresholdtoggle( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( Train->mvControlled->Imax < Train->mvControlled->ImaxHi ) {
// turn on
if( true == Train->mvControlled->CurrentSwitch( true ) ) {
// visual feedback
Train->ggMaxCurrentCtrl.UpdateValue( 1.0 );
// sound feedback
if( Train->ggMaxCurrentCtrl.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
}
}
else {
//turn off
if( true == Train->mvControlled->CurrentSwitch( false ) ) {
// visual feedback
Train->ggMaxCurrentCtrl.UpdateValue( 0.0 );
// sound feedback
if( Train->ggMaxCurrentCtrl.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
}
}
}
}
void TTrain::OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ) { void TTrain::OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ) {
if( Train->mvOccupied->LightsPosNo > 0 ) { if( Train->mvOccupied->LightsPosNo > 0 ) {
@@ -2084,9 +2148,9 @@ void TTrain::OnKeyDown(int cKey)
DynamicObject->Mechanik->TakeControl(true); DynamicObject->Mechanik->TakeControl(true);
} }
} }
else if (cKey == Global::Keys[k_MaxCurrent]) // McZapkie-160502: F - #ifdef EU07_USE_OLD_COMMAND_SYSTEM
// wysoki rozruch else if (cKey == Global::Keys[k_MaxCurrent]) {
{ // McZapkie-160502: F - wysoki rozruch
if ((mvControlled->EngineType == DieselElectric) && (mvControlled->ShuntModeAllow) && if ((mvControlled->EngineType == DieselElectric) && (mvControlled->ShuntModeAllow) &&
(mvControlled->MainCtrlPos == 0)) (mvControlled->MainCtrlPos == 0))
{ {
@@ -2096,28 +2160,17 @@ void TTrain::OnKeyDown(int cKey)
{ {
play_sound( dsbSwitch ); play_sound( dsbSwitch );
} }
/* Ra: przeniesione do Mover.cpp
if (mvControlled->TrainType!=dt_EZT) //to powinno być w fizyce, a
nie w kabinie!
if (mvControlled->MinCurrentSwitch(true))
{
dsbSwitch->SetVolume(DSBVOLUME_MAX);
dsbSwitch->Play(0,0,0);
}
*/
} }
else if (cKey == Global::Keys[k_CurrentAutoRelay]) // McZapkie-241002: G - #endif
// wlaczanie PSR else if (cKey == Global::Keys[k_CurrentAutoRelay]) {
{ // McZapkie-241002: G - wlaczanie PSR
if (mvControlled->AutoRelaySwitch(true)) if (mvControlled->AutoRelaySwitch(true))
{ {
play_sound( dsbSwitch ); play_sound( dsbSwitch );
} }
} }
else if (cKey == Global::Keys[k_FailedEngineCutOff]) // McZapkie-060103: E else if (cKey == Global::Keys[k_FailedEngineCutOff]) {
// - wylaczanie // McZapkie-060103: E - wylaczanie sekcji silnikow
// sekcji silnikow
{
if (mvControlled->CutOffEngine()) if (mvControlled->CutOffEngine())
{ {
play_sound( dsbSwitch ); play_sound( dsbSwitch );
@@ -3084,7 +3137,8 @@ void TTrain::OnKeyDown(int cKey)
if (DynamicObject->Mechanik) if (DynamicObject->Mechanik)
DynamicObject->Mechanik->TakeControl(false); DynamicObject->Mechanik->TakeControl(false);
} }
else if (cKey == Global::Keys[k_MaxCurrent]) // McZapkie-160502: f - niski rozruch #ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if( cKey == Global::Keys[ k_MaxCurrent ] ) // McZapkie-160502: f - niski rozruch
{ {
if ((mvControlled->EngineType == DieselElectric) && (mvControlled->ShuntModeAllow) && if ((mvControlled->EngineType == DieselElectric) && (mvControlled->ShuntModeAllow) &&
(mvControlled->MainCtrlPos == 0)) (mvControlled->MainCtrlPos == 0))
@@ -3095,15 +3149,8 @@ void TTrain::OnKeyDown(int cKey)
{ {
play_sound( dsbSwitch ); play_sound( dsbSwitch );
} }
/* Ra: przeniesione do Mover.cpp
if (mvControlled->TrainType!=dt_EZT)
if (mvControlled->MinCurrentSwitch(false))
{
dsbSwitch->SetVolume(DSBVOLUME_MAX);
dsbSwitch->Play(0,0,0);
}
*/
} }
#endif
else if (cKey == Global::Keys[k_CurrentAutoRelay]) // McZapkie-241002: g - else if (cKey == Global::Keys[k_CurrentAutoRelay]) // McZapkie-241002: g -
// wylaczanie PSR // wylaczanie PSR
{ {
@@ -4351,7 +4398,7 @@ bool TTrain::Update( double const Deltatime )
fPPress = (1 * fPPress + mvOccupied->Handle->GetSound(s_fv4a_b)) / (2); fPPress = (1 * fPPress + mvOccupied->Handle->GetSound(s_fv4a_b)) / (2);
if (fPPress > 0) if (fPPress > 0)
{ {
vol = 2 * rsHiss.AM * fPPress; vol = 2.0 * rsHiss.AM * fPPress;
} }
if (vol > 0.001) if (vol > 0.001)
{ {
@@ -4418,13 +4465,12 @@ bool TTrain::Update( double const Deltatime )
} // koniec FV4a } // koniec FV4a
else // jesli nie FV4a else // jesli nie FV4a
{ {
if (rsHiss.AM != 0) // upuszczanie z PG if (rsHiss.AM != 0.0) // upuszczanie z PG
{ {
fPPress = (4 * fPPress + Max0R(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) / fPPress = (4.0f * fPPress + std::max(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) / (4.0f + 1.0f);
(4 + 1); if (fPPress > 0.0f)
if (fPPress > 0)
{ {
vol = 2 * rsHiss.AM * fPPress * 0.01; vol = 2.0 * rsHiss.AM * fPPress;
} }
if (vol > 0.01) if (vol > 0.01)
{ {
@@ -4435,13 +4481,12 @@ bool TTrain::Update( double const Deltatime )
rsHiss.Stop(); rsHiss.Stop();
} }
} }
if (rsHissU.AM != 0) // napelnianie PG if (rsHissU.AM != 0.0) // napelnianie PG
{ {
fNPress = (4 * fNPress + Min0R(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) / fNPress = (4.0f * fNPress + Min0R(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) / (4.0f + 1.0f);
(4 + 1); if (fNPress < 0.0f)
if (fNPress < 0)
{ {
vol = -2 * rsHissU.AM * fNPress * 0.004; vol = -1.0 * rsHissU.AM * fNPress;
} }
if (vol > 0.01) if (vol > 0.01)
{ {
@@ -4956,7 +5001,8 @@ bool TTrain::Update( double const Deltatime )
mvControlled->ResistorsFlagCheck()); mvControlled->ResistorsFlagCheck());
//------- //-------
btLampkaWysRozr.Turn(mvControlled->Imax == mvControlled->ImaxHi); btLampkaWysRozr.Turn(!(mvControlled->Imax < mvControlled->ImaxHi));
if (((mvControlled->ScndCtrlActualPos > 0) || if (((mvControlled->ScndCtrlActualPos > 0) ||
((mvControlled->RList[mvControlled->MainCtrlActualPos].ScndAct != 0) && ((mvControlled->RList[mvControlled->MainCtrlActualPos].ScndAct != 0) &&
(mvControlled->RList[mvControlled->MainCtrlActualPos].ScndAct != 255))) && (mvControlled->RList[mvControlled->MainCtrlActualPos].ScndAct != 255))) &&
@@ -5283,7 +5329,9 @@ bool TTrain::Update( double const Deltatime )
if (ggMaxCurrentCtrl.SubModel) if (ggMaxCurrentCtrl.SubModel)
{ {
ggMaxCurrentCtrl.UpdateValue(double(mvControlled->Imax == mvControlled->ImaxHi)); #ifdef EU07_USE_OLD_COMMAND_SYSTEM
ggMaxCurrentCtrl.UpdateValue( double( mvControlled->Imax == mvControlled->ImaxHi ) );
#endif
ggMaxCurrentCtrl.Update(); ggMaxCurrentCtrl.Update();
} }
@@ -6101,6 +6149,7 @@ bool TTrain::Update( double const Deltatime )
} }
} }
} }
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// Odskakiwanie hamulce EP // Odskakiwanie hamulce EP
if ((!Console::Pressed(Global::Keys[k_DecBrakeLevel])) && if ((!Console::Pressed(Global::Keys[k_DecBrakeLevel])) &&
(!Console::Pressed(Global::Keys[k_WaveBrake])) && (mvOccupied->BrakeCtrlPos == -1) && (!Console::Pressed(Global::Keys[k_WaveBrake])) && (mvOccupied->BrakeCtrlPos == -1) &&
@@ -6117,7 +6166,10 @@ bool TTrain::Update( double const Deltatime )
play_sound( dsbPneumaticSwitch ); play_sound( dsbPneumaticSwitch );
} }
} }
#endif
/*
// NOTE: disabled, as it doesn't seem to be used.
// TODO: get rid of it altogether when we're cleaninng
// Ra: przeklejka z SPKS - płynne poruszanie hamulcem // Ra: przeklejka z SPKS - płynne poruszanie hamulcem
// if // if
// ((mvOccupied->BrakeHandle==FV4a)&&(Console::Pressed(Global::Keys[k_IncBrakeLevel]))) // ((mvOccupied->BrakeHandle==FV4a)&&(Console::Pressed(Global::Keys[k_IncBrakeLevel])))
@@ -6151,7 +6203,7 @@ bool TTrain::Update( double const Deltatime )
// mvOccupied->BrakeLevelAdd(mvOccupied->fBrakeCtrlPos<-1?0:-dt*2); // mvOccupied->BrakeLevelAdd(mvOccupied->fBrakeCtrlPos<-1?0:-dt*2);
} }
} }
*/
if ((mvOccupied->BrakeHandle == FV4a) && (Console::Pressed(Global::Keys[k_IncBrakeLevel]))) if ((mvOccupied->BrakeHandle == FV4a) && (Console::Pressed(Global::Keys[k_IncBrakeLevel])))
{ {
if (Global::ctrlState) if (Global::ctrlState)
@@ -7287,6 +7339,11 @@ void TTrain::clear_cab_controls()
void TTrain::set_cab_controls() { void TTrain::set_cab_controls() {
// switches // switches
// battery
if( true == mvOccupied->Battery ) {
ggBatteryButton.PutValue( 1.0 );
}
// pantographs // pantographs
if( mvOccupied->PantSwitchType != "impulse" ) { if( mvOccupied->PantSwitchType != "impulse" ) {
ggPantFrontButton.PutValue( ggPantFrontButton.PutValue(
@@ -7319,6 +7376,11 @@ void TTrain::set_cab_controls() {
ggCompressorButton.PutValue( 1.0 ); ggCompressorButton.PutValue( 1.0 );
} }
// motor overload relay threshold / shunt mode
if( mvControlled->Imax == mvControlled->ImaxHi ) {
ggMaxCurrentCtrl.PutValue( 1.0 );
}
// lights // lights
int const lightsindex = int const lightsindex =
( mvOccupied->ActiveCab == 1 ? ( mvOccupied->ActiveCab == 1 ?

View File

@@ -141,6 +141,7 @@ class TTrain
static void OnCommand_linebreakertoggle( TTrain *Train, command_data const &Command ); static void OnCommand_linebreakertoggle( TTrain *Train, command_data const &Command );
static void OnCommand_convertertoggle( TTrain *Train, command_data const &Command ); static void OnCommand_convertertoggle( TTrain *Train, command_data const &Command );
static void OnCommand_compressortoggle( TTrain *Train, command_data const &Command ); static void OnCommand_compressortoggle( TTrain *Train, command_data const &Command );
static void OnCommand_motoroverloadrelaythresholdtoggle( TTrain *Train, command_data const &Command );
static void OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ); static void OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command );
static void OnCommand_headlighttoggleright( TTrain *Train, command_data const &Command ); static void OnCommand_headlighttoggleright( TTrain *Train, command_data const &Command );
static void OnCommand_headlighttoggleupper( TTrain *Train, command_data const &Command ); static void OnCommand_headlighttoggleupper( TTrain *Train, command_data const &Command );

View File

@@ -79,16 +79,16 @@ command_relay::command_relay() {
const int k_AntiSlipping = 21; const int k_AntiSlipping = 21;
const int k_Sand = 22; const int k_Sand = 22;
*/ */
{ user_command::linebreakertoggle, command_target::vehicle },
{ user_command::reverserincrease, command_target::vehicle }, { user_command::reverserincrease, command_target::vehicle },
{ user_command::reverserdecrease, command_target::vehicle }, { user_command::reverserdecrease, command_target::vehicle },
{ user_command::linebreakertoggle, command_target::vehicle },
/* /*
const int k_Fuse = 26; const int k_Fuse = 26;
*/ */
{ user_command::compressortoggle, command_target::vehicle },
{ user_command::convertertoggle, command_target::vehicle }, { user_command::convertertoggle, command_target::vehicle },
{ user_command::compressortoggle, command_target::vehicle },
{ user_command::motoroverloadrelaythresholdtoggle, command_target::vehicle },
/* /*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30; const int k_CurrentAutoRelay = 30;
const int k_BrakeProfile = 31; const int k_BrakeProfile = 31;
*/ */
@@ -189,14 +189,15 @@ int const k_DimHeadlights = 74;
const int k_AntiSlipping = 21; const int k_AntiSlipping = 21;
const int k_Sand = 22; const int k_Sand = 22;
*/ */
"linebreakertoggle",
"reverserincrease", "reverserincrease",
"reverserdecrease", "reverserdecrease",
"linebreakertoggle",
/* /*
const int k_Fuse = 26; const int k_Fuse = 26;
*/ */
"compressortoggle",
"convertertoggle", "convertertoggle",
"compressortoggle",
"motoroverloadrelaythresholdtoggle",
/* /*
const int k_MaxCurrent = 29; const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30; const int k_CurrentAutoRelay = 30;

View File

@@ -39,14 +39,15 @@ enum class user_command {
const int k_AntiSlipping = 21; const int k_AntiSlipping = 21;
const int k_Sand = 22; const int k_Sand = 22;
*/ */
linebreakertoggle,
reverserincrease, reverserincrease,
reverserdecrease, reverserdecrease,
linebreakertoggle,
/* /*
const int k_Fuse = 26; const int k_Fuse = 26;
*/ */
compressortoggle,
convertertoggle, convertertoggle,
compressortoggle,
motoroverloadrelaythresholdtoggle,
/* /*
const int k_MaxCurrent = 29; const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30; const int k_CurrentAutoRelay = 30;
@@ -54,7 +55,6 @@ const int k_BrakeProfile = 31;
*/ */
alerteracknowledge, alerteracknowledge,
/* /*
const int k_Czuwak = 32;
const int k_Horn = 33; const int k_Horn = 33;
const int k_Horn2 = 34; const int k_Horn2 = 34;
const int k_FailedEngineCutOff = 35; const int k_FailedEngineCutOff = 35;

View File

@@ -87,6 +87,11 @@ gamepad_input::init() {
void void
gamepad_input::poll() { gamepad_input::poll() {
if( m_deviceid == -1 ) {
// if there's no gamepad we can skip the rest
return;
}
int count; std::size_t idx = 0; int count; std::size_t idx = 0;
// poll button state // poll button state
auto const buttons = glfwGetJoystickButtons( m_deviceid, &count ); auto const buttons = glfwGetJoystickButtons( m_deviceid, &count );
@@ -98,8 +103,8 @@ gamepad_input::poll() {
on_button( on_button(
static_cast<gamepad_button>( idx ), static_cast<gamepad_button>( idx ),
( buttons[ idx ] == 1 ? ( buttons[ idx ] == 1 ?
GLFW_PRESS : GLFW_PRESS :
GLFW_RELEASE ) ); GLFW_RELEASE ) );
} }
else { else {
// otherwise we only pass info about button being held down // otherwise we only pass info about button being held down
@@ -115,10 +120,6 @@ gamepad_input::poll() {
} }
} }
if( m_deviceid == -1 ) {
// if there's no gamepad we can skip the rest
return;
}
// poll axes state // poll axes state
idx = 0; idx = 0;
glm::vec2 leftstick, rightstick, triggers; glm::vec2 leftstick, rightstick, triggers;
@@ -167,7 +168,8 @@ gamepad_input::on_button( gamepad_button const Button, int const Action ) {
case gamepad_button::y: { case gamepad_button::y: {
if( Action == GLFW_RELEASE ) { if( Action == GLFW_RELEASE ) {
// if the button was released the stick controls movement // TODO: send GLFW_RELEASE for whatever command could be issued by the mode active until now
// if the button was released the stick switches to control the movement
m_mode = control_mode::entity; m_mode = control_mode::entity;
// zero the stick and the accumulator so the input won't bleed between modes // zero the stick and the accumulator so the input won't bleed between modes
m_leftstick = glm::vec2(); m_leftstick = glm::vec2();
@@ -275,11 +277,20 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
if( Value >= 0.0f ) { if( Value >= 0.0f ) {
if( m_modeaccumulator < 0.0f ) { if( m_modeaccumulator < 0.0f ) {
// reset accumulator if we're going in the other direction i.e. issuing opposite control // reset accumulator if we're going in the other direction i.e. issuing opposite control
// this also means we should indicate the previous command no longer applies
// (normally it's handled when the stick enters dead zone, but it's possible there's no actual dead zone)
m_relay.post(
lookup.second,
0, 0,
GLFW_RELEASE,
Recipient );
m_modeaccumulator = 0.0f; m_modeaccumulator = 0.0f;
} }
if( Value > m_deadzone ) { if( Value > m_deadzone ) {
m_modeaccumulator += ( Value - m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime; m_modeaccumulator += ( Value - m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime;
while( m_modeaccumulator >= 1.0f ) { // we're making sure there's always a positive charge left in the accumulator,
// to more reliably decect when the stick goes from active to dead zone, below
while( m_modeaccumulator > 1.0f ) {
// send commands if the accumulator(s) was filled // send commands if the accumulator(s) was filled
m_relay.post( m_relay.post(
lookup.first, lookup.first,
@@ -289,15 +300,34 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
m_modeaccumulator -= 1.0f; m_modeaccumulator -= 1.0f;
} }
} }
else {
// if the accumulator isn't empty it's an indicator the stick moved from active to neutral zone
// indicate it with proper RELEASE command
m_relay.post(
lookup.first,
0, 0,
GLFW_RELEASE,
Recipient );
m_modeaccumulator = 0.0f;
}
} }
else { else {
if( m_modeaccumulator > 0.0f ) { if( m_modeaccumulator > 0.0f ) {
// reset accumulator if we're going in the other direction i.e. issuing opposite control // reset accumulator if we're going in the other direction i.e. issuing opposite control
// this also means we should indicate the previous command no longer applies
// (normally it's handled when the stick enters dead zone, but it's possible there's no actual dead zone)
m_relay.post(
lookup.first,
0, 0,
GLFW_RELEASE,
Recipient );
m_modeaccumulator = 0.0f; m_modeaccumulator = 0.0f;
} }
if( Value < m_deadzone ) { if( Value < m_deadzone ) {
m_modeaccumulator += ( Value + m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime; m_modeaccumulator += ( Value + m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime;
while( m_modeaccumulator <= -1.0f ) { // we're making sure there's always a negative charge left in the accumulator,
// to more reliably decect when the stick goes from active to dead zone, below
while( m_modeaccumulator < -1.0f ) {
// send commands if the accumulator(s) was filled // send commands if the accumulator(s) was filled
m_relay.post( m_relay.post(
lookup.second, lookup.second,
@@ -307,6 +337,16 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
m_modeaccumulator += 1.0f; m_modeaccumulator += 1.0f;
} }
} }
else {
// if the accumulator isn't empty it's an indicator the stick moved from active to neutral zone
// indicate it with proper RELEASE command
m_relay.post(
lookup.second,
0, 0,
GLFW_RELEASE,
Recipient );
m_modeaccumulator = 0.0f;
}
} }
} }

View File

@@ -118,16 +118,16 @@ keyboard_input::default_bindings() {
const int k_AntiSlipping = 21; const int k_AntiSlipping = 21;
const int k_Sand = 22; const int k_Sand = 22;
*/ */
{ "linebreakertoggle", command_target::vehicle, GLFW_KEY_M },
{ "reverserincrease", command_target::vehicle, GLFW_KEY_D }, { "reverserincrease", command_target::vehicle, GLFW_KEY_D },
{ "reverserdecrease", command_target::vehicle, GLFW_KEY_R }, { "reverserdecrease", command_target::vehicle, GLFW_KEY_R },
{ "linebreakertoggle", command_target::vehicle, GLFW_KEY_M },
/* /*
const int k_Fuse = 26; const int k_Fuse = 26;
*/ */
{ "compressortoggle", command_target::vehicle, GLFW_KEY_C },
{ "convertertoggle", command_target::vehicle, GLFW_KEY_X }, { "convertertoggle", command_target::vehicle, GLFW_KEY_X },
{ "compressortoggle", command_target::vehicle, GLFW_KEY_C },
{ "motoroverloadrelaythresholdtoggle", command_target::vehicle, GLFW_KEY_F },
/* /*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30; const int k_CurrentAutoRelay = 30;
const int k_BrakeProfile = 31; const int k_BrakeProfile = 31;
*/ */