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

additional door cab controls, light configuration ai command, line breaker state change sounds, texture scaling crash fix

This commit is contained in:
tmj-fstate
2018-08-06 17:01:20 +02:00
parent 47d8944d17
commit e2fdf16fdc
17 changed files with 510 additions and 99 deletions

View File

@@ -27,6 +27,7 @@ http://mozilla.org/MPL/2.0/.
#include "simulationtime.h"
#include "track.h"
#include "station.h"
#include "keyboardinput.h"
#include "utilities.h"
#define LOGVELOCITY 0
@@ -603,6 +604,17 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
if (pTrack->eType == tt_Cross) {
// na skrzyżowaniach trzeba wybrać segment, po którym pojedzie pojazd
// dopiero tutaj jest ustalany kierunek segmentu na skrzyżowaniu
int routewanted;
if( false == AIControllFlag ) {
routewanted = (
input::keys[ GLFW_KEY_LEFT ] != GLFW_RELEASE ? 1 :
input::keys[ GLFW_KEY_RIGHT ] != GLFW_RELEASE ? 2 :
3 );
}
else {
routewanted = 1 + std::floor( Random( static_cast<double>( pTrack->RouteCount() ) - 0.001 ) );
}
sSpeedTable[iLast].iFlags |=
( ( pTrack->CrossSegment(
(fLastDir < 0 ?
@@ -611,7 +623,7 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
/*
iRouteWanted )
*/
1 + std::floor( Random( static_cast<double>(pTrack->RouteCount()) - 0.001 ) ) )
routewanted )
& 0xf ) << 28 ); // ostatnie 4 bity pola flag
sSpeedTable[iLast].iFlags &= ~spReverse; // usunięcie flagi kierunku, bo może być błędna
if (sSpeedTable[iLast].iFlags < 0) {
@@ -1969,8 +1981,7 @@ bool TController::CheckVehicles(TOrders user)
fVelMax = -1; // ustalenie prędkości dla składu
bool main = true; // czy jest głównym sterującym
iDrivigFlags |= moveOerlikons; // zakładamy, że są same Oerlikony
// Ra 2014-09: ustawić moveMultiControl, jeśli wszystkie są w ukrotnieniu (i skrajne mają
// kabinę?)
// Ra 2014-09: ustawić moveMultiControl, jeśli wszystkie są w ukrotnieniu (i skrajne mają kabinę?)
while (p)
{ // sprawdzanie, czy jest głównym sterującym, żeby nie było konfliktu
if (p->Mechanik) // jeśli ma obsadę
@@ -2016,9 +2027,20 @@ bool TController::CheckVehicles(TOrders user)
}
if (AIControllFlag)
{ // jeśli prowadzi komputer
if (OrderCurrentGet() == Obey_train) // jeśli jazda pociągowa
{
Lights(1 + 4 + 16, 2 + 32 + 64); //światła pociągowe (Pc1) i końcówki (Pc5)
if (OrderCurrentGet() == Obey_train) {
// jeśli jazda pociągowa
// światła pociągowe (Pc1) i końcówki (Pc5)
auto const frontlights { (
( m_lighthints[ side::front ] != -1 ) ?
m_lighthints[ side::front ] :
light::headlight_left | light::headlight_right | light::headlight_upper ) };
auto const rearlights { (
( m_lighthints[ side::rear ] != -1 ) ?
m_lighthints[ side::rear ] :
light::redmarker_left | light::redmarker_right | light::rearendsignals ) };
Lights(
frontlights,
rearlights );
#if LOGPRESS == 0
AutoRewident(); // nastawianie hamulca do jazdy pociągowej
#endif
@@ -2090,6 +2112,9 @@ bool TController::CheckVehicles(TOrders user)
JumpToNextOrder(); // zmianę kierunku też można olać, ale zmienić kierunek
// skanowania!
}
break;
default:
break;
}
// Ra 2014-09: tymczasowo prymitywne ustawienie warunku pod kątem SN61
if( ( mvOccupied->TrainType == dt_EZT )
@@ -3249,6 +3274,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
mvOccupied->RunInternalCommand(); // rozpoznaj komende bo lokomotywa jej nie rozpoznaje
return true; // załatwione
}
if (NewCommand == "Overhead")
{ // informacja o stanie sieci trakcyjnej
fOverhead1 =
@@ -3257,13 +3283,15 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
// opuszczonym i ograniczeniem prędkości)
return true; // załatwione
}
else if (NewCommand == "Emergency_brake") // wymuszenie zatrzymania, niezależnie kto prowadzi
if (NewCommand == "Emergency_brake") // wymuszenie zatrzymania, niezależnie kto prowadzi
{ // Ra: no nadal nie jest zbyt pięknie
SetVelocity(0, 0, reason);
mvOccupied->PutCommand("Emergency_brake", 1.0, 1.0, mvOccupied->Loc);
return true; // załatwione
}
else if (NewCommand.compare(0, 10, "Timetable:") == 0)
if (NewCommand.compare(0, 10, "Timetable:") == 0)
{ // przypisanie nowego rozkładu jazdy, również prowadzonemu przez użytkownika
NewCommand.erase(0, 10); // zostanie nazwa pliku z rozkładem
#if LOGSTOPS
@@ -3374,6 +3402,7 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
// TrainNumber=floor(NewValue1); //i co potem ???
return true; // załatwione
}
if (NewCommand == "SetVelocity")
{
if (NewLocation)
@@ -3393,16 +3422,20 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
iDrivigFlags |= moveStopHere; // stać do momentu podania komendy jazdy
SetVelocity(NewValue1, NewValue2, reason); // bylo: nic nie rob bo SetVelocity zewnetrznie
// jest wywolywane przez dynobj.cpp
return true;
}
else if (NewCommand == "SetProximityVelocity")
if (NewCommand == "SetProximityVelocity")
{
/*
if (SetProximityVelocity(NewValue1,NewValue2))
if (NewLocation)
vCommandLocation=*NewLocation;
*/
return true;
}
else if (NewCommand == "ShuntVelocity")
if (NewCommand == "ShuntVelocity")
{ // uruchomienie jazdy manewrowej bądź zmiana prędkości
if (NewLocation)
vCommandLocation = *NewLocation;
@@ -3426,15 +3459,21 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
iDrivigFlags |= moveStopHere; // ma stać w miejscu
if (fabs(NewValue1) > 2.0) // o ile wartość jest sensowna (-1 nie jest konkretną wartością)
fShuntVelocity = fabs(NewValue1); // zapamiętanie obowiązującej prędkości dla manewrów
return true;
}
else if (NewCommand == "Wait_for_orders")
if (NewCommand == "Wait_for_orders")
{ // oczekiwanie; NewValue1 - czas oczekiwania, -1 = na inną komendę
if (NewValue1 > 0.0 ? NewValue1 > fStopTime : false)
fStopTime = NewValue1; // Ra: włączenie czekania bez zmiany komendy
else
OrderList[OrderPos] = Wait_for_orders; // czekanie na komendę (albo dać OrderPos=0)
return true;
}
else if (NewCommand == "Prepare_engine")
if (NewCommand == "Prepare_engine")
{ // włączenie albo wyłączenie silnika (w szerokim sensie)
OrdersClear(); // czyszczenie tabelki rozkazów, aby nic dalej nie robił
if (NewValue1 == 0.0)
@@ -3442,8 +3481,10 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
else if (NewValue1 > 0.0)
OrderNext(Prepare_engine); // odpalić silnik (wyłączyć wszystko, co się da)
// po załączeniu przejdzie do kolejnej komendy, po wyłączeniu na Wait_for_orders
return true;
}
else if (NewCommand == "Change_direction")
if (NewCommand == "Change_direction")
{
TOrders o = OrderList[OrderPos]; // co robił przed zmianą kierunku
if (!iEngineActive)
@@ -3469,16 +3510,21 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
if (mvOccupied->Vel >= 1.0) // jeśli jedzie
iDrivigFlags &= ~moveStartHorn; // to bez trąbienia po ruszeniu z zatrzymania
// Change_direction wykona się samo i następnie przejdzie do kolejnej komendy
return true;
}
else if (NewCommand == "Obey_train")
if (NewCommand == "Obey_train")
{
if (!iEngineActive)
OrderNext(Prepare_engine); // trzeba odpalić silnik najpierw
OrderNext(Obey_train);
// if (NewValue1>0) TrainNumber=floor(NewValue1); //i co potem ???
OrderCheck(); // jeśli jazda pociągowa teraz, to wykonać niezbędne operacje
return true;
}
else if (NewCommand == "Shunt")
if (NewCommand == "Shunt")
{ // NewValue1 - ilość wagonów (-1=wszystkie); NewValue2: 0=odczep, 1..63=dołącz, -1=bez zmian
//-3,-y - podłączyć do całego stojącego składu (sprzęgiem y>=1), zmienić kierunek i czekać w
// trybie pociągowym
@@ -3552,70 +3598,73 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
if (VelDesired==0)
SetVelocity(20,0); //to niech jedzie
*/
return true;
}
else if (NewCommand == "Jump_to_first_order")
if( NewCommand == "Jump_to_first_order" ) {
JumpToFirstOrder();
else if (NewCommand == "Jump_to_order")
return true;
}
if (NewCommand == "Jump_to_order")
{
if (NewValue1 == -1.0)
if( NewValue1 == -1.0 ) {
JumpToNextOrder();
}
else if ((NewValue1 >= 0) && (NewValue1 < maxorders))
{
OrderPos = floor(NewValue1);
if (!OrderPos)
OrderPos = 1; // zgodność wstecz: dopiero pierwsza uruchamia
if( !OrderPos ) {
// zgodność wstecz: dopiero pierwsza uruchamia
OrderPos = 1;
}
#if LOGORDERS
WriteLog("--> Jump_to_order");
OrdersDump();
#endif
}
/*
if (WriteLogFlag)
{
append(AIlogFile);
writeln(AILogFile,ElapsedTime:5:2," - new order: ",Order2Str( OrderList[OrderPos])," @
",OrderPos);
close(AILogFile);
return true;
}
*/
}
/* //ta komenda jest teraz skanowana, więc wysyłanie jej eventem nie ma sensu
else if (NewCommand=="OutsideStation") //wskaznik W5
{
if (OrderList[OrderPos]==Obey_train)
SetVelocity(NewValue1,NewValue2,stopOut); //koniec stacji - predkosc szlakowa
else //manewry - zawracaj
{
iDirectionOrder=-iDirection; //zmiana na przeciwny niż obecny
OrderNext(Change_direction); //zmiana kierunku
OrderNext(Shunt); //a dalej manewry
iDrivigFlags&=~moveStartHorn; //bez trąbienia po zatrzymaniu
}
}
*/
else if (NewCommand == "Warning_signal")
{
if (AIControllFlag) // poniższa komenda nie jest wykonywana przez użytkownika
if (NewValue1 > 0)
if (NewCommand == "Warning_signal")
{
if( AIControllFlag ) {
// poniższa komenda nie jest wykonywana przez użytkownika
if( NewValue1 > 0 ) {
fWarningDuration = NewValue1; // czas trąbienia
mvOccupied->WarningSignal = NewValue2; // horn combination flag
}
}
else if (NewCommand == "Radio_channel")
{ // wybór kanału radiowego (którego powinien używać AI, ręczny maszynista musi go ustawić sam)
if (NewValue1 >= 0) // wartości ujemne są zarezerwowane, -1 = nie zmieniać kanału
{
return true;
}
if (NewCommand == "Radio_channel") {
// wybór kanału radiowego (którego powinien używać AI, ręczny maszynista musi go ustawić sam)
if (NewValue1 >= 0) {
// wartości ujemne są zarezerwowane, -1 = nie zmieniać kanału
iRadioChannel = NewValue1;
if (iGuardRadio)
iGuardRadio = iRadioChannel; // kierownikowi też zmienić
if( iGuardRadio ) {
// kierownikowi też zmienić
iGuardRadio = iRadioChannel;
}
}
// NewValue2 może zawierać dodatkowo oczekiwany kod odpowiedzi, np. dla W29 "nawiązać
// łączność radiową z dyżurnym ruchu odcinkowym"
return true;
}
else
if( NewCommand == "SetLights" ) {
// set consist lights pattern hints
m_lighthints[ side::front ] = static_cast<int>( NewValue1 );
m_lighthints[ side::rear ] = static_cast<int>( NewValue2 );
if( OrderCurrentGet() == Obey_train ) {
// light hints only apply in the obey_train mode
CheckVehicles();
}
return true;
}
return false; // nierozpoznana - wysłać bezpośrednio do pojazdu
return true; // komenda została przetworzona
};
void TController::PhysicsLog()
@@ -5465,6 +5514,11 @@ void TController::JumpToFirstOrder()
void TController::OrderCheck()
{ // reakcja na zmianę rozkazu
if( OrderList[ OrderPos ] != Obey_train ) {
// reset light hints
m_lighthints[ side::front ] = m_lighthints[ side::rear ] = -1;
}
if( OrderList[ OrderPos ] & ( Shunt | Connect | Obey_train ) ) {
CheckVehicles(); // sprawdzić światła
}

View File

@@ -241,6 +241,7 @@ private:
int iRadioChannel = 1; // numer aktualnego kanału radiowego
int iGuardRadio = 0; // numer kanału radiowego kierownika (0, gdy nie używa radia)
sound_source tsGuardSignal { sound_placement::internal };
std::array<int, 2> m_lighthints { -1 }; // suggested light patterns
public:
double AccPreferred = 0.0; // preferowane przyspieszenie (wg psychiki kierującego, zmniejszana przy wykryciu kolizji)
double AccDesired = AccPreferred; // przyspieszenie, jakie ma utrzymywać (<0:nie przyspieszaj,<-0.1:hamuj)

View File

@@ -5690,6 +5690,14 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
m_powertrainsounds.rsEngageSlippery.m_frequencyfactor /= ( 1 + MoverParameters->nmax );
}
else if( token == "linebreakerclose:" ) {
m_powertrainsounds.linebreaker_close.deserialize( parser, sound_type::single );
m_powertrainsounds.linebreaker_close.owner( this );
}
else if( token == "linebreakeropen:" ) {
m_powertrainsounds.linebreaker_open.deserialize( parser, sound_type::single );
m_powertrainsounds.linebreaker_open.owner( this );
}
else if( token == "relay:" ) {
// styczniki itp:
m_powertrainsounds.motor_relay.deserialize( parser, sound_type::single );
@@ -6421,16 +6429,26 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub
if( engine_state_last != Vehicle.Mains ) {
if( true == Vehicle.Mains ) {
// main circuit/engine activation
// TODO: separate engine and main circuit
// engine activation
engine_ignition
.pitch( engine_ignition.m_frequencyoffset + engine_ignition.m_frequencyfactor * 1.f )
.gain( engine_ignition.m_amplitudeoffset + engine_ignition.m_amplitudefactor * 1.f )
.play( sound_flags::exclusive );
// main circuit activation
linebreaker_close
.pitch( linebreaker_close.m_frequencyoffset + linebreaker_close.m_frequencyfactor * 1.f )
.gain( linebreaker_close.m_amplitudeoffset + linebreaker_close.m_amplitudefactor * 1.f )
.play();
}
else {
// main circuit/engine deactivation
// engine deactivation
engine_ignition.stop();
// main circuit
linebreaker_open
.pitch( linebreaker_open.m_frequencyoffset + linebreaker_open.m_frequencyfactor * 1.f )
.gain( linebreaker_open.m_amplitudeoffset + linebreaker_open.m_amplitudefactor * 1.f )
.play();
}
engine_state_last = Vehicle.Mains;
}

View File

@@ -331,6 +331,8 @@ private:
sound_source dsbWejscie_na_bezoporow { sound_placement::engine }; // moved from cab
sound_source motor_parallel { sound_placement::engine }; // moved from cab
sound_source motor_shuntfield { sound_placement::engine };
sound_source linebreaker_close { sound_placement::engine };
sound_source linebreaker_open { sound_placement::engine };
sound_source rsWentylator { sound_placement::engine }; // McZapkie-030302
sound_source engine { sound_placement::engine }; // generally diesel engine
sound_source engine_ignition { sound_placement::engine }; // moved from cab

View File

@@ -215,7 +215,8 @@ TGauge::UpdateValue( float fNewDesired, sound_source *Fallbacksound ) {
m_targetvalue = fNewDesired;
// if there's any sound associated with new requested value, play it
// check value-specific table first...
if( desiredtimes100 % 100 == 0 ) {
auto const fullinteger { desiredtimes100 % 100 == 0 };
if( fullinteger ) {
// filter out values other than full integers
auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 );
if( lookup != m_soundfxvalues.end() ) {
@@ -223,21 +224,26 @@ TGauge::UpdateValue( float fNewDesired, sound_source *Fallbacksound ) {
return;
}
}
else {
// toggle the control to continous range/exclusive sound mode from now on
m_soundtype = sound_flags::exclusive;
}
// ...and if there isn't any, fall back on the basic set...
auto const currentvalue = GetValue();
// HACK: crude way to discern controls with continuous and quantized value range
if( ( currentvalue < fNewDesired )
&& ( false == m_soundfxincrease.empty() ) ) {
// shift up
m_soundfxincrease.play( sound_flags::exclusive );
m_soundfxincrease.play( m_soundtype );
}
else if( ( currentvalue > fNewDesired )
&& ( false == m_soundfxdecrease.empty() ) ) {
// shift down
m_soundfxdecrease.play( sound_flags::exclusive );
m_soundfxdecrease.play( m_soundtype );
}
else if( Fallbacksound != nullptr ) {
// ...and if that fails too, try the provided fallback sound from legacy system
Fallbacksound->play( sound_flags::exclusive );
Fallbacksound->play( m_soundtype );
}
};

View File

@@ -76,6 +76,7 @@ private:
double *dData { nullptr };
int *iData;
};
int m_soundtype { 0 }; // toggle between exclusive and multiple sound generation
sound_source m_soundtemplate { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; // shared properties for control's sounds
sound_source m_soundfxincrease { m_soundtemplate }; // sound associated with increasing control's value
sound_source m_soundfxdecrease { m_soundtemplate }; // sound associated with decreasing control's value

View File

@@ -951,6 +951,7 @@ public:
int DoorOpenCtrl = 0; int DoorCloseCtrl = 0; /*0: przez pasazera, 1: przez maszyniste, 2: samoczynne (zamykanie)*/
double DoorStayOpen = 0.0; /*jak dlugo otwarte w przypadku DoorCloseCtrl=2*/
bool DoorClosureWarning = false; /*czy jest ostrzeganie przed zamknieciem*/
bool DoorClosureWarningAuto = false; // departure signal plays automatically while door closing button is held down
double DoorOpenSpeed = 1.0; double DoorCloseSpeed = 1.0; /*predkosc otwierania i zamykania w j.u. */
double DoorMaxShiftL = 0.5; double DoorMaxShiftR = 0.5; double DoorMaxPlugShift = 0.1;/*szerokosc otwarcia lub kat*/
int DoorOpenMethod = 2; /*sposob otwarcia - 1: przesuwne, 2: obrotowe, 3: trójelementowe*/

View File

@@ -7853,11 +7853,9 @@ void TMoverParameters::LoadFIZ_Doors( std::string const &line ) {
else if( openmethod == "Fold" ) { DoorOpenMethod = 3; } //3 submodele się obracają
else if( openmethod == "Plug" ) { DoorOpenMethod = 4; } //odskokowo-przesuwne
std::string closurewarning; extract_value( closurewarning, "DoorClosureWarning", line, "" );
DoorClosureWarning = ( closurewarning == "Yes" );
std::string doorblocked; extract_value( doorblocked, "DoorBlocked", line, "" );
DoorBlocked = ( doorblocked == "Yes" );
extract_value( DoorClosureWarning, "DoorClosureWarning", line, "" );
extract_value( DoorClosureWarningAuto, "DoorClosureWarningAuto", line, "" );
extract_value( DoorBlocked, "DoorBlocked", line, "" );
extract_value( PlatformSpeed, "PlatformSpeed", line, "" );
extract_value( PlatformMaxShift, "PlatformMaxShift", line, "" );

View File

@@ -698,6 +698,9 @@ opengl_texture::downsize( GLuint const Format ) {
}
WriteLog( "Texture size exceeds specified limits, downsampling data" );
// trim potential odd texture sizes
data_width -= ( data_width % 2 );
data_height -= ( data_height % 2 );
switch( Format ) {
case GL_RGB: { downsample< glm::tvec3<std::uint8_t> >( data_width, data_height, data.data() ); break; }

View File

@@ -2372,18 +2372,18 @@ int TTrack::CrossSegment(int from, int into)
switch (into)
{
case 0: // stop
// WriteLog( "Stopping in P" + to_string( from + 1 ) + " on " + pMyNode->asName );
// WriteLog( "Stopping in P" + to_string( from + 1 ) + " on " + name() );
break;
case 1: // left
// WriteLog( "Turning left from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
// WriteLog( "Turning left from P" + to_string( from + 1 ) + " on " + name() );
i = (SwitchExtension->iRoads == 4) ? iLewo4[from] : iLewo3[from];
break;
case 2: // right
// WriteLog( "Turning right from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
// WriteLog( "Turning right from P" + to_string( from + 1 ) + " on " + name() );
i = (SwitchExtension->iRoads == 4) ? iPrawo4[from] : iPrawo3[from];
break;
case 3: // stright
// WriteLog( "Going straight from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
// WriteLog( "Going straight from P" + to_string( from + 1 ) + " on " + name() );
i = (SwitchExtension->iRoads == 4) ? iProsto4[from] : iProsto3[from];
break;
}

290
Train.cpp
View File

@@ -313,6 +313,11 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::doorlocktoggle, &TTrain::OnCommand_doorlocktoggle },
{ user_command::doortoggleleft, &TTrain::OnCommand_doortoggleleft },
{ user_command::doortoggleright, &TTrain::OnCommand_doortoggleright },
{ user_command::dooropenleft, &TTrain::OnCommand_dooropenleft },
{ user_command::dooropenright, &TTrain::OnCommand_dooropenright },
{ user_command::doorcloseleft, &TTrain::OnCommand_doorcloseleft },
{ user_command::doorcloseright, &TTrain::OnCommand_doorcloseright },
{ user_command::doorcloseall, &TTrain::OnCommand_doorcloseall },
{ user_command::carcouplingincrease, &TTrain::OnCommand_carcouplingincrease },
{ user_command::carcouplingdisconnect, &TTrain::OnCommand_carcouplingdisconnect },
{ user_command::departureannounce, &TTrain::OnCommand_departureannounce },
@@ -3725,6 +3730,64 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
Train->mvOccupied->DoorLeftOpened :
Train->mvOccupied->DoorRightOpened ) ) {
// open
OnCommand_dooropenleft( Train, Command );
}
else {
// close
if( ( Train->ggDoorAllOffButton.SubModel != nullptr )
&& ( Train->ggDoorLeftOffButton.SubModel == nullptr ) ) {
// OnCommand_doorcloseall( Train, Command );
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
return;
}
else {
OnCommand_doorcloseleft( Train, Command );
}
}
}
else if( Command.action == GLFW_RELEASE ) {
if( true == (
Train->mvOccupied->ActiveCab == 1 ?
Train->mvOccupied->DoorLeftOpened :
Train->mvOccupied->DoorRightOpened ) ) {
// open
if( ( Train->mvOccupied->DoorClosureWarningAuto )
&& ( Train->mvOccupied->DepartureSignal ) ) {
// complete closing the doors
if( ( Train->ggDoorAllOffButton.SubModel != nullptr )
&& ( Train->ggDoorLeftOffButton.SubModel == nullptr ) ) {
// OnCommand_doorcloseall( Train, Command );
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
return;
}
else {
OnCommand_doorcloseleft( Train, Command );
}
}
else {
OnCommand_dooropenleft( Train, Command );
}
}
else {
// close
if( ( Train->ggDoorAllOffButton.SubModel != nullptr )
&& ( Train->ggDoorLeftOffButton.SubModel == nullptr ) ) {
// OnCommand_doorcloseall( Train, Command );
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
return;
}
else {
OnCommand_doorcloseleft( Train, Command );
}
}
}
}
void TTrain::OnCommand_dooropenleft( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) {
// NOTE: test how the door state check works with consists where the occupied vehicle doesn't have opening doors
if( Train->mvOccupied->DoorOpenCtrl != control_t::driver ) {
return;
}
@@ -3736,13 +3799,37 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
Train->mvOccupied->DoorRight( true );
}
// visual feedback
Train->ggDoorLeftButton.UpdateValue( 1.0, Train->dsbSwitch );
if( Train->ggDoorLeftOnButton.SubModel != nullptr ) {
// two separate impulse switches
Train->ggDoorLeftOnButton.UpdateValue( 1.0, Train->dsbSwitch );
}
else {
// close
// single two-state switch
Train->ggDoorLeftButton.UpdateValue( 1.0, Train->dsbSwitch );
}
}
else if( Command.action == GLFW_RELEASE ) {
// visual feedback
if( Train->ggDoorLeftOnButton.SubModel != nullptr ) {
// two separate impulse switches
Train->ggDoorLeftOnButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
}
void TTrain::OnCommand_doorcloseleft( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) {
if( Train->mvOccupied->DoorCloseCtrl != control_t::driver ) {
return;
}
if( Train->mvOccupied->DoorClosureWarningAuto ) {
// automatic departure signal delays actual door closing until the button is released
Train->mvOccupied->signal_departure( true );
}
else {
// TODO: move door opening/closing to the update, so the switch animation doesn't hinge on door working
if( Train->mvOccupied->ActiveCab == 1 ) {
Train->mvOccupied->DoorLeft( false );
@@ -3751,10 +3838,36 @@ void TTrain::OnCommand_doortoggleleft( TTrain *Train, command_data const &Comman
// in the rear cab sides are reversed...
Train->mvOccupied->DoorRight( false );
}
}
// visual feedback
if( Train->ggDoorLeftOffButton.SubModel != nullptr ) {
// two separate switches to open and close the door
Train->ggDoorLeftOffButton.UpdateValue( 1.0, Train->dsbSwitch );
}
else {
// single two-state switch
Train->ggDoorLeftButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
else if( Command.action == GLFW_RELEASE ) {
if( Train->mvOccupied->DoorClosureWarningAuto ) {
// automatic departure signal delays actual door closing until the button is released
Train->mvOccupied->signal_departure( false );
// now we can actually close the door
if( Train->mvOccupied->ActiveCab == 1 ) {
Train->mvOccupied->DoorLeft( false );
}
else {
// in the rear cab sides are reversed...
Train->mvOccupied->DoorRight( false );
}
}
// visual feedback
// dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position
if( Train->ggDoorLeftOffButton.SubModel )
Train->ggDoorLeftOffButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
void TTrain::OnCommand_doortoggleright( TTrain *Train, command_data const &Command ) {
@@ -3766,6 +3879,64 @@ void TTrain::OnCommand_doortoggleright( TTrain *Train, command_data const &Comma
Train->mvOccupied->DoorRightOpened :
Train->mvOccupied->DoorLeftOpened ) ) {
// open
OnCommand_dooropenright( Train, Command );
}
else {
// close
if( ( Train->ggDoorAllOffButton.SubModel != nullptr )
&& ( Train->ggDoorRightOffButton.SubModel == nullptr ) ) {
// OnCommand_doorcloseall( Train, Command );
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
return;
}
else {
OnCommand_doorcloseright( Train, Command );
}
}
}
else if( Command.action == GLFW_RELEASE ) {
if( true == (
Train->mvOccupied->ActiveCab == 1 ?
Train->mvOccupied->DoorRightOpened :
Train->mvOccupied->DoorLeftOpened ) ) {
// open
if( ( Train->mvOccupied->DoorClosureWarningAuto )
&& ( Train->mvOccupied->DepartureSignal ) ) {
// complete closing the doors
if( ( Train->ggDoorAllOffButton.SubModel != nullptr )
&& ( Train->ggDoorRightOffButton.SubModel == nullptr ) ) {
// OnCommand_doorcloseall( Train, Command );
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
return;
}
else {
OnCommand_doorcloseright( Train, Command );
}
}
else {
OnCommand_dooropenright( Train, Command );
}
}
else {
// close
if( ( Train->ggDoorAllOffButton.SubModel != nullptr )
&& ( Train->ggDoorRightOffButton.SubModel == nullptr ) ) {
// OnCommand_doorcloseall( Train, Command );
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
return;
}
else {
OnCommand_doorcloseright( Train, Command );
}
}
}
}
void TTrain::OnCommand_dooropenright( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) {
// NOTE: test how the door state check works with consists where the occupied vehicle doesn't have opening doors
if( Train->mvOccupied->DoorOpenCtrl != control_t::driver ) {
return;
}
@@ -3777,13 +3948,38 @@ void TTrain::OnCommand_doortoggleright( TTrain *Train, command_data const &Comma
Train->mvOccupied->DoorLeft( true );
}
// visual feedback
Train->ggDoorRightButton.UpdateValue( 1.0, Train->dsbSwitch );
if( Train->ggDoorRightOnButton.SubModel != nullptr ) {
// two separate impulse switches
Train->ggDoorRightOnButton.UpdateValue( 1.0, Train->dsbSwitch );
}
else {
// close
// single two-state switch
Train->ggDoorRightButton.UpdateValue( 1.0, Train->dsbSwitch );
}
}
else if( Command.action == GLFW_RELEASE ) {
// visual feedback
if( Train->ggDoorRightOnButton.SubModel != nullptr ) {
// two separate impulse switches
Train->ggDoorRightOnButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
}
void TTrain::OnCommand_doorcloseright( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) {
if( Train->mvOccupied->DoorCloseCtrl != control_t::driver ) {
return;
}
if( Train->mvOccupied->DoorClosureWarningAuto ) {
// automatic departure signal delays actual door closing until the button is released
Train->mvOccupied->signal_departure( true );
}
else {
// TODO: move door opening/closing to the update, so the switch animation doesn't hinge on door working
if( Train->mvOccupied->ActiveCab == 1 ) {
Train->mvOccupied->DoorRight( false );
}
@@ -3791,10 +3987,81 @@ void TTrain::OnCommand_doortoggleright( TTrain *Train, command_data const &Comma
// in the rear cab sides are reversed...
Train->mvOccupied->DoorLeft( false );
}
}
// visual feedback
if( Train->ggDoorRightOffButton.SubModel != nullptr ) {
// two separate switches to open and close the door
Train->ggDoorRightOffButton.UpdateValue( 1.0, Train->dsbSwitch );
}
else {
// single two-state switch
Train->ggDoorRightButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
else if( Command.action == GLFW_RELEASE ) {
if( Train->mvOccupied->DoorClosureWarningAuto ) {
// automatic departure signal delays actual door closing until the button is released
Train->mvOccupied->signal_departure( false );
// now we can actually close the door
if( Train->mvOccupied->ActiveCab == 1 ) {
Train->mvOccupied->DoorRight( false );
}
else {
// in the rear cab sides are reversed...
Train->mvOccupied->DoorLeft( false );
}
}
// visual feedback
// dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position
if( Train->ggDoorRightOffButton.SubModel )
Train->ggDoorRightOffButton.UpdateValue( 0.0, Train->dsbSwitch );
}
}
void TTrain::OnCommand_doorcloseall( TTrain *Train, command_data const &Command ) {
if( Train->ggDoorAllOffButton.SubModel == nullptr ) {
// TODO: expand definition of cab controls so we can know if the control is present without testing for presence of 3d switch
if( Command.action == GLFW_PRESS ) {
WriteLog( "Close All Doors switch is missing, or wasn't defined" );
}
return;
}
if( Command.action == GLFW_PRESS ) {
if( Train->mvOccupied->DoorCloseCtrl != control_t::driver ) {
return;
}
if( Train->mvOccupied->DoorClosureWarningAuto ) {
// automatic departure signal delays actual door closing until the button is released
Train->mvOccupied->signal_departure( true );
}
else {
Train->mvOccupied->DoorRight( false );
Train->mvOccupied->DoorLeft( false );
}
// visual feedback
Train->ggDoorLeftButton.UpdateValue( 0.0, Train->dsbSwitch );
Train->ggDoorRightButton.UpdateValue( 0.0, Train->dsbSwitch );
if( Train->ggDoorAllOffButton.SubModel )
Train->ggDoorAllOffButton.UpdateValue( 1.0, Train->dsbSwitch );
}
else if( Command.action == GLFW_RELEASE ) {
// release the button
if( Train->mvOccupied->DoorClosureWarningAuto ) {
// automatic departure signal delays actual door closing until the button is released
Train->mvOccupied->signal_departure( false );
// now we can actually close the door
Train->mvOccupied->DoorRight( false );
Train->mvOccupied->DoorLeft( false );
}
// visual feedback
if( Train->ggDoorAllOffButton.SubModel )
Train->ggDoorAllOffButton.UpdateValue( 0.0 );
}
}
void TTrain::OnCommand_carcouplingincrease( TTrain *Train, command_data const &Command ) {
@@ -5231,6 +5498,11 @@ bool TTrain::Update( double const Deltatime )
// NBMX wrzesien 2003 - drzwi
ggDoorLeftButton.Update();
ggDoorRightButton.Update();
ggDoorLeftOnButton.Update();
ggDoorRightOnButton.Update();
ggDoorLeftOffButton.Update();
ggDoorRightOffButton.Update();
ggDoorAllOffButton.Update();
ggDoorSignallingButton.Update();
// NBMX dzwignia sprezarki
ggCompressorButton.Update();
@@ -6391,6 +6663,11 @@ void TTrain::clear_cab_controls()
ggRadioTest.Clear();
ggDoorLeftButton.Clear();
ggDoorRightButton.Clear();
ggDoorLeftOnButton.Clear();
ggDoorRightOnButton.Clear();
ggDoorLeftOffButton.Clear();
ggDoorRightOffButton.Clear();
ggDoorAllOffButton.Clear();
ggTrainHeatingButton.Clear();
ggSignallingButton.Clear();
ggDoorSignallingButton.Clear();
@@ -6908,6 +7185,11 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
{ "stlinoff_bt:", ggStLinOffButton },
{ "door_left_sw:", ggDoorLeftButton },
{ "door_right_sw:", ggDoorRightButton },
{ "doorlefton_sw:", ggDoorLeftOnButton },
{ "doorrighton_sw:", ggDoorRightOnButton },
{ "doorleftoff_sw:", ggDoorLeftOffButton },
{ "doorrightoff_sw:", ggDoorRightOffButton },
{ "dooralloff_sw:", ggDoorAllOffButton },
{ "departure_signal_bt:", ggDepartureSignalButton },
{ "upperlight_sw:", ggUpperLightButton },
{ "leftlight_sw:", ggLeftLightButton },

10
Train.h
View File

@@ -297,6 +297,11 @@ class TTrain
static void OnCommand_doorlocktoggle( TTrain *Train, command_data const &Command );
static void OnCommand_doortoggleleft( TTrain *Train, command_data const &Command );
static void OnCommand_doortoggleright( TTrain *Train, command_data const &Command );
static void OnCommand_dooropenleft( TTrain *Train, command_data const &Command );
static void OnCommand_dooropenright( TTrain *Train, command_data const &Command );
static void OnCommand_doorcloseleft( TTrain *Train, command_data const &Command );
static void OnCommand_doorcloseright( TTrain *Train, command_data const &Command );
static void OnCommand_doorcloseall( TTrain *Train, command_data const &Command );
static void OnCommand_carcouplingincrease( TTrain *Train, command_data const &Command );
static void OnCommand_carcouplingdisconnect( TTrain *Train, command_data const &Command );
static void OnCommand_departureannounce( TTrain *Train, command_data const &Command );
@@ -416,6 +421,11 @@ public: // reszta może by?publiczna
// NBMX wrzesien 2003 - obsluga drzwi
TGauge ggDoorLeftButton;
TGauge ggDoorRightButton;
TGauge ggDoorLeftOnButton;
TGauge ggDoorRightOnButton;
TGauge ggDoorLeftOffButton;
TGauge ggDoorRightOffButton;
TGauge ggDoorAllOffButton;
TGauge ggDepartureSignalButton;
// Winger 160204 - obsluga pantografow - ZROBIC

View File

@@ -142,6 +142,11 @@ commanddescription_sequence Commands_descriptions = {
{ "carcouplingdisconnect", command_target::vehicle },
{ "doortoggleleft", command_target::vehicle },
{ "doortoggleright", command_target::vehicle },
{ "dooropenleft", command_target::vehicle },
{ "dooropenright", command_target::vehicle },
{ "doorlcloseleft", command_target::vehicle },
{ "doorcloseright", command_target::vehicle },
{ "doorcloseall", command_target::vehicle },
{ "departureannounce", command_target::vehicle },
{ "doorlocktoggle", command_target::vehicle },
{ "pantographcompressorvalvetoggle", command_target::vehicle },

View File

@@ -135,6 +135,11 @@ enum class user_command {
carcouplingdisconnect,
doortoggleleft,
doortoggleright,
dooropenleft,
dooropenright,
doorcloseleft,
doorcloseright,
doorcloseall,
departureannounce,
doorlocktoggle,
pantographcompressorvalvetoggle,

View File

@@ -144,6 +144,11 @@ driverkeyboard_input::default_bindings() {
{ user_command::carcouplingdisconnect, GLFW_KEY_DELETE },
{ user_command::doortoggleleft, GLFW_KEY_COMMA },
{ user_command::doortoggleright, GLFW_KEY_PERIOD },
// dooropenleft,
// dooropenright,
// doorcloseleft,
// doorcloseright,
{ user_command::doorcloseall, GLFW_KEY_SLASH | keymodifier::control },
{ user_command::departureannounce, GLFW_KEY_SLASH },
{ user_command::doorlocktoggle, GLFW_KEY_S | keymodifier::control },
{ user_command::pantographcompressorvalvetoggle, GLFW_KEY_V | keymodifier::control },

View File

@@ -544,6 +544,21 @@ drivermouse_input::default_bindings() {
{ "door_right_sw:", {
user_command::doortoggleright,
user_command::none } },
{ "doorlefton_sw:", {
user_command::dooropenleft,
user_command::none } },
{ "doorrighton_sw:", {
user_command::dooropenright,
user_command::none } },
{ "doorleftoff_sw:", {
user_command::doorcloseleft,
user_command::none } },
{ "doorrightoff_sw:", {
user_command::doorcloseright,
user_command::none } },
{ "dooralloff_sw:", {
user_command::doorcloseall,
user_command::none } },
{ "departure_signal_bt:", {
user_command::departureannounce,
user_command::none } },

View File

@@ -52,6 +52,11 @@ static std::unordered_map<std::string, std::string> m_cabcontrols = {
{ "stlinoff_bt:", "motor connectors" },
{ "door_left_sw:", "left door" },
{ "door_right_sw:", "right door" },
{ "doorlefton_sw:", "left door" },
{ "doorrighton_sw:", "right door" },
{ "doorleftoff_sw:", "left door" },
{ "doorrightoff_sw:", "right door" },
{ "dooralloff_sw:", "all doors" },
{ "departure_signal_bt:", "departure signal" },
{ "upperlight_sw:", "upper headlight" },
{ "leftlight_sw:", "left headlight" },