build 210408. door opening logic enhancements, door permit sound, door permit indicator cab control

This commit is contained in:
tmj-fstate
2021-04-09 13:36:43 +02:00
parent 716aefc2ed
commit 66bd63336b
7 changed files with 124 additions and 40 deletions

View File

@@ -4347,13 +4347,15 @@ void TDynamicObject::RenderSounds() {
if( true == door.is_opening ) {
// door sounds
// due to potential wait for the doorstep we play the sound only during actual animation
if( door.position > 0.f ) {
for( auto &doorsounds : m_doorsounds ) {
if( doorsounds.placement == side ) {
// determine left side doors from their offset
doorsounds.rsDoorOpen.play( sound_flags::exclusive );
doorsounds.rsDoorClose.stop();
if( ( false == door.step_unfolding ) // no wait if no doorstep
|| ( MoverParameters->Doors.step_type == 2 ) ) { // no wait for rotating doorstep
if( door.position < 0.5f ) { // safety measure, to keep slightly too short sounds from repeating
for( auto &doorsounds : m_doorsounds ) {
if( doorsounds.placement == side ) {
// determine left side doors from their offset
doorsounds.rsDoorOpen.play( sound_flags::exclusive );
doorsounds.rsDoorClose.stop();
}
}
}
}
@@ -4579,10 +4581,9 @@ void TDynamicObject::RenderSounds() {
}
}
// McZapkie! - to wazne - SoundFlag wystawiane jest przez moje moduly
// gdy zachodza pewne wydarzenia komentowane dzwiekiem.
// McZapkie! - to wazne - SoundFlag wystawiane jest przez moje moduly gdy zachodza pewne wydarzenia komentowane dzwiekiem.
// pneumatic relay
if( TestFlag( MoverParameters->SoundFlag, sound::pneumatic ) ) {
// pneumatic relay
dsbPneumaticRelay
.gain(
true == TestFlag( MoverParameters->SoundFlag, sound::loud ) ?
@@ -4590,6 +4591,16 @@ void TDynamicObject::RenderSounds() {
0.8f )
.play();
}
// door permit
if( TestFlag( MoverParameters->SoundFlag, sound::doorpermit ) ) {
// NOTE: current implementation doesn't discern between permit for left/right side,
// which may be undesired in weird setups with doors only on one side
// TBD, TODO: rework into dedicated sound event flag for each door location instance?
for( auto &door : m_doorsounds ) {
door.permit_granted.play( sound_flags::exclusive );
}
}
// couplers
int couplerindex { 0 };
for( auto &couplersounds : m_couplersounds ) {
@@ -5848,6 +5859,18 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
}
}
else if( token == "doorpermit:" ) {
sound_source soundtemplate { sound_placement::general };
soundtemplate.deserialize( parser, sound_type::single );
soundtemplate.owner( this );
for( auto &door : m_doorsounds ) {
// apply configuration to all defined doors, but preserve their individual offsets
auto const dooroffset { door.permit_granted.offset() };
door.permit_granted = soundtemplate;
door.permit_granted.offset( dooroffset );
}
}
else if( token == "unloading:" ) {
m_exchangesounds.unloading.range( MoverParameters->Dim.L * 0.5f * -1 );
m_exchangesounds.unloading.deserialize( parser, sound_type::single );
@@ -5982,6 +6005,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
door.unlock.offset( location );
door.step_close.offset( location );
door.step_open.offset( location );
door.permit_granted.offset( location );
m_doorsounds.emplace_back( door );
}
if( ( sides == "both" )
@@ -5995,6 +6019,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
door.unlock.offset( location );
door.step_close.offset( location );
door.step_open.offset( location );
door.permit_granted.offset( location );
m_doorsounds.emplace_back( door );
}
m_doorspeakers.emplace_back(

View File

@@ -356,6 +356,7 @@ private:
sound_source unlock { sound_placement::general };
sound_source step_open { sound_placement::general };
sound_source step_close { sound_placement::general };
sound_source permit_granted { sound_placement::general };
side placement {};
};

View File

@@ -252,6 +252,7 @@ enum sound {
attachheating = 1 << 13,
attachadapter = 1 << 14,
removeadapter = 1 << 15,
doorpermit = 1 << 16,
};
// customizable reset button
@@ -882,6 +883,7 @@ private:
// internal data
float auto_timer { -1.f }; // delay between activation of open state and closing state for automatic doors
float close_delay { 0.f }; // delay between activation of closing state and actual closing
float open_delay { 0.f }; // delay between activation of opening state and actual opening
float position { 0.f }; // current shift of the door from the closed position
float step_position { 0.f }; // current shift of the movable step from the retracted position
// ld outputs
@@ -897,6 +899,7 @@ private:
// config
control_t open_control { control_t::passenger };
float open_rate { 1.f };
float open_delay { 0.f };
control_t close_control { control_t::passenger };
float close_rate { 1.f };
float close_delay { 0.f };
@@ -1432,6 +1435,7 @@ public:
heat_data dizel_heat;
std::array<cooling_fan, 2> MotorBlowers;
door_data Doors;
float DoorsOpenWithPermitAfter { -1.f }; // remote open if permit button is held for specified time. NOTE: separate from door data as its cab control thing
int BrakeCtrlPos = -2; /*nastawa hamulca zespolonego*/
double BrakeCtrlPosR = 0.0; /*nastawa hamulca zespolonego - plynna dla FV4a*/
@@ -1868,6 +1872,7 @@ public:
bool AssignLoad( std::string const &Name, float const Amount = 0.f );
bool LoadingDone(double LSpeed, std::string const &Loadname);
bool PermitDoors( side const Door, bool const State = true, range_t const Notify = range_t::consist );
void PermitDoors_( side const Door, bool const State = true );
bool ChangeDoorPermitPreset( int const Change, range_t const Notify = range_t::consist );
bool PermitDoorStep( bool const State, range_t const Notify = range_t::consist );
bool ChangeDoorControlMode( bool const State, range_t const Notify = range_t::consist );

View File

@@ -8236,7 +8236,7 @@ bool TMoverParameters::PermitDoors( side const Door, bool const State, range_t c
bool const initialstate { Doors.instances[Door].open_permit };
Doors.instances[ Door ].open_permit = State;
PermitDoors_( Door, State );
if( Notify != range_t::local ) {
@@ -8255,6 +8255,14 @@ bool TMoverParameters::PermitDoors( side const Door, bool const State, range_t c
return ( Doors.instances[ Door ].open_permit != initialstate );
}
void TMoverParameters::PermitDoors_( side const Door, bool const State ) {
if( ( State ) && ( State != Doors.instances[ Door ].open_permit ) ) {
SetFlag( SoundFlag, sound::doorpermit );
}
Doors.instances[ Door ].open_permit = State;
}
bool TMoverParameters::ChangeDoorControlMode( bool const State, range_t const Notify ) {
auto const initialstate { Doors.remote_only };
@@ -8483,21 +8491,15 @@ TMoverParameters::update_doors( double const Deltatime ) {
// doors
if( true == door.is_opening ) {
// open door
if( ( TrainType == dt_EZT )
|| ( TrainType == dt_DMU ) ) {
// multi-unit vehicles typically open door only after unfolding the doorstep
if( ( false == door.step_unfolding ) // no wait if no doorstep
|| ( Doors.step_type == 2 ) ) { // no wait for rotating doorstep
if( ( false == door.step_unfolding ) // no wait if no doorstep
|| ( Doors.step_type == 2 ) ) { // no wait for rotating doorstep
door.open_delay += Deltatime;
if( door.open_delay > Doors.open_delay ) {
door.position = std::min<float>(
Doors.range,
door.position + Doors.open_rate * Deltatime );
}
}
else {
door.position = std::min<float>(
Doors.range,
door.position + Doors.open_rate * Deltatime );
}
door.close_delay = 0.f;
}
if( true == door.is_closing ) {
@@ -8508,6 +8510,7 @@ TMoverParameters::update_doors( double const Deltatime ) {
0.f,
door.position - Doors.close_rate * Deltatime );
}
door.open_delay = 0.f;
}
// doorsteps
if( door.step_unfolding ) {
@@ -9973,6 +9976,7 @@ void TMoverParameters::LoadFIZ_Doors( std::string const &line ) {
}
extract_value( Doors.open_rate, "OpenSpeed", line, "" );
extract_value( Doors.open_delay, "DoorOpenDelay", line, "" );
extract_value( Doors.close_rate, "CloseSpeed", line, "" );
extract_value( Doors.close_delay, "DoorCloseDelay", line, "" );
extract_value( Doors.range, "DoorMaxShiftL", line, "" );
@@ -10016,6 +10020,7 @@ void TMoverParameters::LoadFIZ_Doors( std::string const &line ) {
extract_value( MirrorMaxShift, "MirrorMaxShift", line, "" );
extract_value( MirrorVelClose, "MirrorVelClose", line, "");
extract_value( DoorsOpenWithPermitAfter, "DoorOpenWithPermit", line, "" );
}
void TMoverParameters::LoadFIZ_BuffCoupl( std::string const &line, int const Index ) {
@@ -11841,10 +11846,10 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
auto const right { 3 - left };
if( std::abs( static_cast<int>( CValue1 ) ) & right ) {
Doors.instances[ side::right ].open_permit = (CValue1 > 0);
PermitDoors_( side::right, ( CValue1 > 0 ) );
}
if( std::abs( static_cast<int>( CValue1 ) ) & left ) {
Doors.instances[ side::left ].open_permit = (CValue1 > 0);
PermitDoors_( side::left, ( CValue1 > 0 ) );
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );

View File

@@ -1100,7 +1100,7 @@ void TTrain::OnCommand_secondcontrollerincrease( TTrain *Train, command_data con
}
}
else {
if( Train->ggScndCtrl.type() == TGaugeType::push ) {
if( Train->ggScndCtrl.is_push() ) {
// two-state control, active while the button is down
if( Command.action == GLFW_PRESS ) {
// activate on press
@@ -1118,6 +1118,13 @@ void TTrain::OnCommand_secondcontrollerincrease( TTrain *Train, command_data con
Train->mvControlled->IncScndCtrl( 1 );
}
}
// potentially animate tempomat button
if( ( Train->ggScndCtrlButton.is_push() )
&& ( Train->mvControlled->ScndCtrlPos <= 1 ) ) {
Train->ggScndCtrlButton.UpdateValue(
( ( Command.action == GLFW_RELEASE ) ? 0.f : 1.f ),
Train->dsbSwitch );
}
}
}
@@ -1252,6 +1259,20 @@ void TTrain::OnCommand_secondcontrollerdecrease( TTrain *Train, command_data con
Train->mvControlled->DecScndCtrl( 1 );
}
}
// potentially animate tempomat button
if( ( Train->ggScndCtrlButton.is_push() )
&& ( Train->mvControlled->ScndCtrlPos <= 1 ) ) {
if( Train->m_controlmapper.contains( "tempomatoff_sw:" ) ) {
Train->ggScndCtrlOffButton.UpdateValue(
( ( Command.action == GLFW_RELEASE ) ? 0.f : 1.f ),
Train->dsbSwitch );
}
else {
Train->ggScndCtrlButton.UpdateValue(
( ( Command.action == GLFW_RELEASE ) ? 0.f : 1.f ),
Train->dsbSwitch );
}
}
}
void TTrain::OnCommand_secondcontrollerdecreasefast( TTrain *Train, command_data const &Command ) {
@@ -5168,18 +5189,20 @@ void TTrain::OnCommand_doorpermitleft( TTrain *Train, command_data const &Comman
if( Command.action == GLFW_REPEAT ) { return; }
if( false == Train->mvOccupied->Doors.permit_presets.empty() ) { return; }
auto const side { (
Train->cab_to_end() == end::front ?
side::left :
side::right ) };
if( Command.action == GLFW_PRESS ) {
auto const side { (
Train->cab_to_end() == end::front ?
side::left :
side::right ) };
if( Train->ggDoorLeftPermitButton.type() == TGaugeType::push ) {
if( Train->ggDoorLeftPermitButton.is_push() ) {
// impulse switch
Train->mvOccupied->PermitDoors( side );
// visual feedback
Train->ggDoorLeftPermitButton.UpdateValue( 1.0, Train->dsbSwitch );
// start potential timer for remote door control
Train->m_doorpermittimers[ side ] = Train->mvOccupied->DoorsOpenWithPermitAfter;
}
else {
// two-state switch
@@ -5192,10 +5215,12 @@ void TTrain::OnCommand_doorpermitleft( TTrain *Train, command_data const &Comman
}
else if( Command.action == GLFW_RELEASE ) {
if( Train->ggDoorLeftPermitButton.type() == TGaugeType::push ) {
if( Train->ggDoorLeftPermitButton.is_push() ) {
// impulse switch
// visual feedback
Train->ggDoorLeftPermitButton.UpdateValue( 0.0, Train->dsbSwitch );
// reset potential remote door control timer
Train->m_doorpermittimers[ side ] = -1.f;
}
}
}
@@ -5205,18 +5230,20 @@ void TTrain::OnCommand_doorpermitright( TTrain *Train, command_data const &Comma
if( Command.action == GLFW_REPEAT ) { return; }
if( false == Train->mvOccupied->Doors.permit_presets.empty() ) { return; }
if( Command.action == GLFW_PRESS ) {
auto const side { (
Train->cab_to_end() == end::front ?
side::right :
side::left ) };
auto const side { (
Train->cab_to_end() == end::front ?
side::right :
side::left ) };
if( Command.action == GLFW_PRESS ) {
if( Train->ggDoorRightPermitButton.type() == TGaugeType::push ) {
// impulse switch
Train->mvOccupied->PermitDoors( side );
// visual feedback
Train->ggDoorRightPermitButton.UpdateValue( 1.0, Train->dsbSwitch );
// start potential timer for remote door control
Train->m_doorpermittimers[ side ] = Train->mvOccupied->DoorsOpenWithPermitAfter;
}
else {
// two-state switch
@@ -5233,6 +5260,8 @@ void TTrain::OnCommand_doorpermitright( TTrain *Train, command_data const &Comma
// impulse switch
// visual feedback
Train->ggDoorRightPermitButton.UpdateValue( 0.0, Train->dsbSwitch );
// reset potential remote door control timer
Train->m_doorpermittimers[ side ] = -1.f;
}
}
}
@@ -6118,7 +6147,7 @@ void TTrain::UpdateCab() {
bool TTrain::Update( double const Deltatime )
{
// train state verification
// train state update
// line breaker:
if( m_linebreakerstate == 0 ) {
if( true == mvControlled->Mains ) {
@@ -6169,13 +6198,29 @@ bool TTrain::Update( double const Deltatime )
0 );
}
}
// door permits
for( auto idx = 0; idx < 2; ++idx ) {
auto &doorpermittimer { m_doorpermittimers[ idx ] };
if( doorpermittimer < 0.f ) {
continue;
}
doorpermittimer -= Deltatime;
if( doorpermittimer < 0.f ) {
mvOccupied->OperateDoors( static_cast<side>( idx ), true );
}
}
// helper variables
if( DynamicObject->Mechanik != nullptr ) {
m_doors = ( DynamicObject->Mechanik->IsAnyDoorOpen[ side::right ] || DynamicObject->Mechanik->IsAnyDoorOpen[ side::left ] );
m_doors = (
DynamicObject->Mechanik->IsAnyDoorOpen[ side::right ]
|| DynamicObject->Mechanik->IsAnyDoorOpen[ side::left ] );
m_doorpermits = (
DynamicObject->Mechanik->IsAnyDoorPermitActive[ side::right ]
|| DynamicObject->Mechanik->IsAnyDoorPermitActive[ side::left ] );
}
m_dirforward = ( mvControlled->DirActive > 0 );
m_dirneutral = ( mvControlled->DirActive == 0 );
m_dirbackward = ( mvControlled->DirActive <0 );
m_dirbackward = ( mvControlled->DirActive < 0 );
// check for received user commands
// NOTE: this is a temporary arrangement, for the transition period from old command setup to the new one
@@ -9213,6 +9258,7 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co
{ "i-doors:", &m_doors },
{ "i-doorpermit_left:", &mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::left : side::right ) ].open_permit },
{ "i-doorpermit_right:", &mvOccupied->Doors.instances[ ( cab_to_end() == end::front ? side::right : side::left ) ].open_permit },
{ "i-doorpermit_any:", &m_doorpermits },
{ "i-doorstep:", &mvOccupied->Doors.step_enabled },
{ "i-mainpipelock:", &mvOccupied->LockPipe },
{ "i-battery:", &mvOccupied->Power24vIsAvailable },

View File

@@ -818,6 +818,8 @@ private:
bool m_dirforward{ false }; // helper, true if direction set to forward
bool m_dirneutral{ false }; // helper, true if direction set to neutral
bool m_dirbackward{ false }; // helper, true if direction set to backward
bool m_doorpermits{ false }; // helper, true if any door permit is active
float m_doorpermittimers[2] = { -1.f, -1.f };
// ld substitute
bool m_couplingdisconnect { false };

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 21
#define VERSION_MINOR 331
#define VERSION_MINOR 408
#define VERSION_REVISION 0