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)
return (MinCurrentSwitch(direction != 0));
}
if (EngineType == DieselEngine) // dla 2Ls150
if (ShuntModeAllow)
if (ActiveDir == 0) // przed ustawieniem kierunku
ShuntMode = ( direction != 0 );
// TBD, TODO: split off shunt mode toggle into a separate command? It doesn't make much sense to have these two together like that
// dla 2Ls150
if( ( EngineType == DieselEngine )
&& ( 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;
};

View File

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

156
Train.cpp
View File

@@ -165,6 +165,7 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::linebreakertoggle, &TTrain::OnCommand_linebreakertoggle },
{ user_command::convertertoggle, &TTrain::OnCommand_convertertoggle },
{ user_command::compressortoggle, &TTrain::OnCommand_compressortoggle },
{ user_command::motoroverloadrelaythresholdtoggle, &TTrain::OnCommand_motoroverloadrelaythresholdtoggle },
{ user_command::headlighttoggleleft, &TTrain::OnCommand_headlighttoggleleft },
{ user_command::headlighttoggleright, &TTrain::OnCommand_headlighttoggleright },
{ 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 ) {
if( Command.action != GLFW_RELEASE ) {
// press or hold
if( Train->mvOccupied->BrakeHandle == FV4a ) {
Train->mvOccupied->BrakeLevelAdd( -0.1 /*-15.0 * Command.time_delta*/ );
}
else {
// nową wersję dostarczył ZiomalCl ("fixed looped sound in ezt when using NUM_9 key")
if( ( Train->mvOccupied->BrakeCtrlPos > -1 )
|| ( Train->keybrakecount > 1 ) ) {
|| ( Train->keybrakecount > 1 ) ) {
if( ( Train->is_eztoer() )
&& ( Train->mvControlled->Mains )
@@ -661,12 +662,29 @@ void TTrain::OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Co
// 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 ) {
if( Command.action != GLFW_RELEASE ) {
// press or hold
// sound feedback
if( ( Train->is_eztoer() )
&& ( Train->mvControlled->Mains )
@@ -676,6 +694,23 @@ void TTrain::OnCommand_trainbrakecharging( TTrain *Train, command_data const &Co
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 ) {
@@ -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 ) {
if( Train->mvOccupied->LightsPosNo > 0 ) {
@@ -2084,9 +2148,9 @@ void TTrain::OnKeyDown(int cKey)
DynamicObject->Mechanik->TakeControl(true);
}
}
else if (cKey == Global::Keys[k_MaxCurrent]) // McZapkie-160502: F -
// wysoki rozruch
{
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if (cKey == Global::Keys[k_MaxCurrent]) {
// McZapkie-160502: F - wysoki rozruch
if ((mvControlled->EngineType == DieselElectric) && (mvControlled->ShuntModeAllow) &&
(mvControlled->MainCtrlPos == 0))
{
@@ -2096,28 +2160,17 @@ void TTrain::OnKeyDown(int cKey)
{
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 -
// wlaczanie PSR
{
#endif
else if (cKey == Global::Keys[k_CurrentAutoRelay]) {
// McZapkie-241002: G - wlaczanie PSR
if (mvControlled->AutoRelaySwitch(true))
{
play_sound( dsbSwitch );
}
}
else if (cKey == Global::Keys[k_FailedEngineCutOff]) // McZapkie-060103: E
// - wylaczanie
// sekcji silnikow
{
else if (cKey == Global::Keys[k_FailedEngineCutOff]) {
// McZapkie-060103: E - wylaczanie sekcji silnikow
if (mvControlled->CutOffEngine())
{
play_sound( dsbSwitch );
@@ -3084,7 +3137,8 @@ void TTrain::OnKeyDown(int cKey)
if (DynamicObject->Mechanik)
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) &&
(mvControlled->MainCtrlPos == 0))
@@ -3095,15 +3149,8 @@ void TTrain::OnKeyDown(int cKey)
{
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 -
// wylaczanie PSR
{
@@ -4351,7 +4398,7 @@ bool TTrain::Update( double const Deltatime )
fPPress = (1 * fPPress + mvOccupied->Handle->GetSound(s_fv4a_b)) / (2);
if (fPPress > 0)
{
vol = 2 * rsHiss.AM * fPPress;
vol = 2.0 * rsHiss.AM * fPPress;
}
if (vol > 0.001)
{
@@ -4402,7 +4449,7 @@ bool TTrain::Update( double const Deltatime )
rsHissX.Stop();
}
}
if (rsHissT.AM != 0) // upuszczanie z czasowego
if (rsHissT.AM != 0) // upuszczanie z czasowego
{
vol = mvOccupied->Handle->GetSound(s_fv4a_t) * rsHissT.AM;
if (vol > 0.001)
@@ -4418,13 +4465,12 @@ bool TTrain::Update( double const Deltatime )
} // koniec 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)) /
(4 + 1);
if (fPPress > 0)
fPPress = (4.0f * fPPress + std::max(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) / (4.0f + 1.0f);
if (fPPress > 0.0f)
{
vol = 2 * rsHiss.AM * fPPress * 0.01;
vol = 2.0 * rsHiss.AM * fPPress;
}
if (vol > 0.01)
{
@@ -4435,13 +4481,12 @@ bool TTrain::Update( double const Deltatime )
rsHiss.Stop();
}
}
if (rsHissU.AM != 0) // napelnianie PG
if (rsHissU.AM != 0.0) // napelnianie PG
{
fNPress = (4 * fNPress + Min0R(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) /
(4 + 1);
if (fNPress < 0)
fNPress = (4.0f * fNPress + Min0R(mvOccupied->dpLocalValve, mvOccupied->dpMainValve)) / (4.0f + 1.0f);
if (fNPress < 0.0f)
{
vol = -2 * rsHissU.AM * fNPress * 0.004;
vol = -1.0 * rsHissU.AM * fNPress;
}
if (vol > 0.01)
{
@@ -4956,7 +5001,8 @@ bool TTrain::Update( double const Deltatime )
mvControlled->ResistorsFlagCheck());
//-------
btLampkaWysRozr.Turn(mvControlled->Imax == mvControlled->ImaxHi);
btLampkaWysRozr.Turn(!(mvControlled->Imax < mvControlled->ImaxHi));
if (((mvControlled->ScndCtrlActualPos > 0) ||
((mvControlled->RList[mvControlled->MainCtrlActualPos].ScndAct != 0) &&
(mvControlled->RList[mvControlled->MainCtrlActualPos].ScndAct != 255))) &&
@@ -5283,7 +5329,9 @@ bool TTrain::Update( double const Deltatime )
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();
}
@@ -6101,6 +6149,7 @@ bool TTrain::Update( double const Deltatime )
}
}
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// Odskakiwanie hamulce EP
if ((!Console::Pressed(Global::Keys[k_DecBrakeLevel])) &&
(!Console::Pressed(Global::Keys[k_WaveBrake])) && (mvOccupied->BrakeCtrlPos == -1) &&
@@ -6117,7 +6166,10 @@ bool TTrain::Update( double const Deltatime )
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
// if
// ((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);
}
}
*/
if ((mvOccupied->BrakeHandle == FV4a) && (Console::Pressed(Global::Keys[k_IncBrakeLevel])))
{
if (Global::ctrlState)
@@ -7287,6 +7339,11 @@ void TTrain::clear_cab_controls()
void TTrain::set_cab_controls() {
// switches
// battery
if( true == mvOccupied->Battery ) {
ggBatteryButton.PutValue( 1.0 );
}
// pantographs
if( mvOccupied->PantSwitchType != "impulse" ) {
ggPantFrontButton.PutValue(
@@ -7319,6 +7376,11 @@ void TTrain::set_cab_controls() {
ggCompressorButton.PutValue( 1.0 );
}
// motor overload relay threshold / shunt mode
if( mvControlled->Imax == mvControlled->ImaxHi ) {
ggMaxCurrentCtrl.PutValue( 1.0 );
}
// lights
int const lightsindex =
( mvOccupied->ActiveCab == 1 ?

View File

@@ -141,6 +141,7 @@ class TTrain
static void OnCommand_linebreakertoggle( 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_motoroverloadrelaythresholdtoggle( 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_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_Sand = 22;
*/
{ user_command::linebreakertoggle, command_target::vehicle },
{ user_command::reverserincrease, command_target::vehicle },
{ user_command::reverserdecrease, command_target::vehicle },
{ user_command::linebreakertoggle, command_target::vehicle },
/*
const int k_Fuse = 26;
*/
{ user_command::compressortoggle, 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_BrakeProfile = 31;
*/
@@ -189,14 +189,15 @@ int const k_DimHeadlights = 74;
const int k_AntiSlipping = 21;
const int k_Sand = 22;
*/
"linebreakertoggle",
"reverserincrease",
"reverserdecrease",
"linebreakertoggle",
/*
const int k_Fuse = 26;
*/
"compressortoggle",
"convertertoggle",
"compressortoggle",
"motoroverloadrelaythresholdtoggle",
/*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30;

View File

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

View File

@@ -87,6 +87,11 @@ gamepad_input::init() {
void
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;
// poll button state
auto const buttons = glfwGetJoystickButtons( m_deviceid, &count );
@@ -98,8 +103,8 @@ gamepad_input::poll() {
on_button(
static_cast<gamepad_button>( idx ),
( buttons[ idx ] == 1 ?
GLFW_PRESS :
GLFW_RELEASE ) );
GLFW_PRESS :
GLFW_RELEASE ) );
}
else {
// 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
idx = 0;
glm::vec2 leftstick, rightstick, triggers;
@@ -167,7 +168,8 @@ gamepad_input::on_button( gamepad_button const Button, int const Action ) {
case gamepad_button::y: {
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;
// zero the stick and the accumulator so the input won't bleed between modes
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( m_modeaccumulator < 0.0f ) {
// 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;
}
if( Value > m_deadzone ) {
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
m_relay.post(
lookup.first,
@@ -289,15 +300,34 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
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 {
if( m_modeaccumulator > 0.0f ) {
// 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;
}
if( Value < m_deadzone ) {
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
m_relay.post(
lookup.second,
@@ -307,6 +337,16 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
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_Sand = 22;
*/
{ "linebreakertoggle", command_target::vehicle, GLFW_KEY_M },
{ "reverserincrease", command_target::vehicle, GLFW_KEY_D },
{ "reverserdecrease", command_target::vehicle, GLFW_KEY_R },
{ "linebreakertoggle", command_target::vehicle, GLFW_KEY_M },
/*
const int k_Fuse = 26;
*/
{ "compressortoggle", command_target::vehicle, GLFW_KEY_C },
{ "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_BrakeProfile = 31;
*/