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

control for battery, pantographs, line breaker, converter and compressor

This commit is contained in:
tmj-fstate
2017-04-10 15:18:08 +02:00
parent e6f488ed6f
commit 1034fb8aa9
15 changed files with 830 additions and 350 deletions

View File

@@ -295,97 +295,6 @@ TCamera::OnCommand( command_data const &Command ) {
}
break;
}
/*
case user_command::moveforwardfastest: {
if( Command.action != GLFW_RELEASE ) {
m_keys.forward = true;
m_moverate.z =
( Type == tp_Free ?
8.0 :
0.8 );
}
else {
m_keys.forward = false;
}
break;
}
case user_command::movebackfastest: {
if( Command.action != GLFW_RELEASE ) {
m_keys.back = true;
m_moverate.z =
( Type == tp_Free ?
8.0 :
0.8 );
}
else {
m_keys.back = false;
}
break;
}
case user_command::moveleftfastest: {
if( Command.action != GLFW_RELEASE ) {
m_keys.left = true;
m_moverate.x =
( Type == tp_Free ?
8.0 :
0.8 );
}
else {
m_keys.left = false;
}
break;
}
case user_command::moverightfastest: {
if( Command.action != GLFW_RELEASE ) {
m_keys.right = true;
m_moverate.x =
( Type == tp_Free ?
8.0 :
0.8 );
}
else {
m_keys.right = false;
}
break;
}
case user_command::moveupfastest: {
if( Command.action != GLFW_RELEASE ) {
m_keys.up = true;
m_moverate.y =
( Type == tp_Free ?
8.0 :
0.8 );
}
else {
m_keys.up = false;
}
break;
}
case user_command::movedownfastest: {
if( Command.action != GLFW_RELEASE ) {
m_keys.down = true;
m_moverate.y =
( Type == tp_Free ?
8.0 :
0.8 );
}
else {
m_keys.down = false;
}
break;
}
*/
}
}
@@ -463,32 +372,11 @@ void TCamera::Update()
#endif
if( Type == tp_Free ) {
// free movement position update is handled here, movement while in vehicle is handled by train update
vector3 Vec = Velocity;
Vec.RotateY( Yaw );
Pos += Vec * 5.0 * deltatime;
}
else {
}
/*
if( deltatime < 1.0 / 20.0 ) {
// płynne hamowanie ruchu
Velocity -= Velocity * 20.0 * deltatime;
}
else {
// instant stop
Velocity.Zero();
}
if( std::abs( Velocity.x ) < 0.01 ) { Velocity.x = 0.0; }
if( std::abs( Velocity.y ) < 0.01 ) { Velocity.y = 0.0; }
if( std::abs( Velocity.z ) < 0.01 ) { Velocity.z = 0.0; }
*/
/*
Velocity *= 0.5;
if( std::abs( Velocity.x ) < 0.01 ) { Velocity.x = 0.0; }
if( std::abs( Velocity.y ) < 0.01 ) { Velocity.y = 0.0; }
if( std::abs( Velocity.z ) < 0.01 ) { Velocity.z = 0.0; }
*/
}
vector3 TCamera::GetDirection()

View File

@@ -3291,8 +3291,7 @@ bool TDynamicObject::Update(double dt, double dt1)
if (tmpTraction.TractionVoltage == 0)
{ // to coś wyłączało dźwięk silnika w ST43!
MoverParameters->ConverterFlag = false;
MoverParameters->CompressorFlag = false; // Ra: to jest wątpliwe - wyłączenie
// sprężarki powinno być w jednym miejscu!
MoverParameters->CompressorFlag = false; // Ra: to jest wątpliwe - wyłączenie sprężarki powinno być w jednym miejscu!
}
}
}

View File

@@ -66,7 +66,7 @@ inline float3 operator/( float3 const &v, float const k )
};
inline float3 SafeNormalize(const float3 &v)
{ // bezpieczna normalizacja (wektor długości 1.0)
double l = v.Length();
auto const l = v.Length();
float3 retVal;
if (l == 0)
retVal.x = retVal.y = retVal.z = 0;
@@ -104,11 +104,11 @@ class float4
z = c;
w = d;
};
double inline float4::LengthSquared() const
float inline float4::LengthSquared() const
{
return x * x + y * y + z * z + w * w;
};
double inline float4::Length() const
float inline float4::Length() const
{
return sqrt(x * x + y * y + z * z + w * w);
};
@@ -132,26 +132,26 @@ inline float4 operator+(const float4 &v1, const float4 &v2)
{
return float4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
};
inline float4 operator/(const float4 &v, double k)
inline float4 operator/(const float4 &v, float const k)
{
return float4(v.x / k, v.y / k, v.z / k, v.w / k);
};
inline float4 Normalize(const float4 &v)
{ // bezpieczna normalizacja (wektor długości 1.0)
double l = v.LengthSquared();
if (l == 1.0)
auto const lengthsquared = v.LengthSquared();
if (lengthsquared == 1.0)
return v;
if (l == 0.0)
if (lengthsquared == 0.0)
return float4(); // wektor zerowy, w=1
else
return v / sqrt(l); // pierwiastek liczony tylko jeśli trzeba wykonać dzielenia
return v / std::sqrt(lengthsquared); // pierwiastek liczony tylko jeśli trzeba wykonać dzielenia
};
inline
float Dot(const float4 &q1, const float4 &q2)
{ // iloczyn skalarny
return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
}
inline float4 &operator*=(float4 &v1, double d)
inline float4 &operator*=(float4 &v1, float const d)
{ // mnożenie przez skalar, jaki ma sens?
v1.x *= d;
v1.y *= d;
@@ -172,7 +172,7 @@ inline float4 Slerp(const float4 &q0, const float4 &q1, float t)
new_q1.w = -new_q1.w;
cosOmega = -cosOmega;
}
double k0, k1;
float k0, k1;
if (cosOmega > 0.9999f)
{ // jeśli jesteśmy z (t) na maksimum kosinusa, to tam prawie liniowo jest
k0 = 1.0f - t;
@@ -180,9 +180,9 @@ inline float4 Slerp(const float4 &q0, const float4 &q1, float t)
}
else
{ // a w ogólnym przypadku trzeba liczyć na trygonometrię
double sinOmega = sqrt(1.0f - cosOmega * cosOmega); // sinus z jedynki tryg.
double omega = atan2(sinOmega, cosOmega); // wyznaczenie kąta
double oneOverSinOmega = 1.0f / sinOmega; // odwrotność sinusa, bo sinus w mianowniku
auto const sinOmega = std::sqrt(1.0f - cosOmega * cosOmega); // sinus z jedynki tryg.
auto const omega = std::atan2(sinOmega, cosOmega); // wyznaczenie kąta
auto const oneOverSinOmega = 1.0f / sinOmega; // odwrotność sinusa, bo sinus w mianowniku
k0 = sin((1.0f - t) * omega) * oneOverSinOmega;
k1 = sin(t * omega) * oneOverSinOmega;
}

View File

@@ -136,19 +136,22 @@ void TGauge::PutValue(double fNewDesired)
fValue = fDesiredValue;
};
double TGauge::GetValue() const {
// we feed value in range 0-1 so we should be getting it reported in the same range
return ( fValue - fOffset ) / fScale;
}
void TGauge::Update()
{
float dt = Timer::GetDeltaTime();
if ((fFriction > 0) && (dt < 0.5 * fFriction)) // McZapkie-281102:
// zabezpieczenie przed
// oscylacjami dla dlugich
// czasow
fValue += dt * (fDesiredValue - fValue) / fFriction;
if( ( fFriction > 0 ) && ( dt < 0.5 * fFriction ) ) {
// McZapkie-281102: zabezpieczenie przed oscylacjami dla dlugich czasow
fValue += dt * ( fDesiredValue - fValue ) / fFriction;
}
else
fValue = fDesiredValue;
if (SubModel)
{ // warunek na wszelki wypadek, gdyby się submodel nie
// podłączył
{ // warunek na wszelki wypadek, gdyby się submodel nie podłączył
TSubModel *sm;
switch (eType)
{

15
Gauge.h
View File

@@ -25,11 +25,11 @@ class TGauge // zmienne "gg"
{ // animowany wskaźnik, mogący przyjmować wiele stanów pośrednich
private:
TGaugeType eType; // typ ruchu
double fFriction; // hamowanie przy zliżaniu się do zadanej wartości
double fDesiredValue; // wartość docelowa
double fValue; // wartość obecna
double fOffset; // wartość początkowa ("0")
double fScale; // wartość końcowa ("1")
double fFriction{ 0.0 }; // hamowanie przy zliżaniu się do zadanej wartości
double fDesiredValue{ 0.0 }; // wartość docelowa
double fValue{ 0.0 }; // wartość obecna
double fOffset{ 0.0 }; // wartość początkowa ("0")
double fScale{ 1.0 }; // wartość końcowa ("1")
double fStepSize; // nie używane
char cDataType; // typ zmiennej parametru: f-float, d-double, i-int
union
@@ -51,10 +51,7 @@ class TGauge // zmienne "gg"
void DecValue(double fNewDesired);
void UpdateValue(double fNewDesired);
void PutValue(double fNewDesired);
float GetValue()
{
return fValue;
};
double GetValue() const;
void Update();
void Render();
void AssignFloat(float *fValue);

View File

@@ -6891,6 +6891,9 @@ void TMoverParameters::LoadFIZ_Switches( std::string const &Input ) {
extract_value( PantSwitchType, "Pantograph", Input, "" );
extract_value( ConvSwitchType, "Converter", Input, "" );
// because people can't make up their minds whether it's "impulse" or "Impulse"...
PantSwitchType = ToLower( PantSwitchType );
ConvSwitchType = ToLower( ConvSwitchType );
}
void TMoverParameters::LoadFIZ_MotorParamTable( std::string const &Input ) {

View File

@@ -321,8 +321,13 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
>> discard >> fFarDecayRadius
>> discard >> fCosFalloffAngle // kąt liczony dla średnicy, a nie promienia
>> discard >> fCosHotspotAngle; // kąt liczony dla średnicy, a nie promienia
fCosFalloffAngle = std::cos( DegToRad( 0.5f * fCosFalloffAngle ) );
fCosHotspotAngle = std::cos( DegToRad( 0.5f * fCosHotspotAngle ) );
// convert conve parameters if specified in degrees
if( fCosFalloffAngle > 1.0 ) {
fCosFalloffAngle = std::cos( DegToRad( 0.5f * fCosFalloffAngle ) );
}
if( fCosHotspotAngle > 1.0 ) {
fCosHotspotAngle = std::cos( DegToRad( 0.5f * fCosHotspotAngle ) );
}
iNumVerts = 1;
/*
iFlags |= 0x4010; // rysowane w cyklu nieprzezroczystych, macierz musi zostać bez zmiany
@@ -2023,6 +2028,14 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, float8 *v,
// so as a workaround we're doing it here manually
iFlags |= 0x20;
}
// intercept and fix hotspot values if specified in degrees and not directly
if( fCosFalloffAngle > 1.0 ) {
fCosFalloffAngle = std::cos( DegToRad( 0.5f * fCosFalloffAngle ) );
}
if( fCosHotspotAngle > 1.0 ) {
fCosHotspotAngle = std::cos( DegToRad( 0.5f * fCosHotspotAngle ) );
}
iFlags &= ~0x0200; // wczytano z pliku binarnego (nie jest właścicielem tablic)
iVboPtr = tVboPtr;

659
Train.cpp
View File

@@ -761,6 +761,525 @@ TTrain::OnCommand( command_data const &Command ) {
break;
}
case user_command::batterytoggle: {
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == mvOccupied->Battery ) {
// turn on
// wyłącznik jest też w SN61, ewentualnie załączać prąd na stałe z poziomu FIZ
if( mvOccupied->BatterySwitch( true ) ) {
// bateria potrzebna np. do zapalenia świateł
if( ggBatteryButton.SubModel ) {
ggBatteryButton.UpdateValue( 1 );
}
// audio feedback
play_sound( dsbSwitch );
// side-effects
if( mvOccupied->LightsPosNo > 0 ) {
SetLights();
}
if( TestFlag( mvOccupied->SecuritySystem.SystemType, 2 ) ) {
// Ra: znowu w kabinie jest coś, co być nie powinno!
SetFlag( mvOccupied->SecuritySystem.Status, s_active );
SetFlag( mvOccupied->SecuritySystem.Status, s_SHPalarm );
}
}
}
else {
//turn off
if( mvOccupied->BatterySwitch( false ) ) {
// ewentualnie zablokować z FIZ, np. w samochodach się nie odłącza akumulatora
if( ggBatteryButton.SubModel ) {
ggBatteryButton.UpdateValue( 0 );
}
// audio feedback
play_sound( dsbSwitch );
// side-effects
mvControlled->PantFront( false );
mvControlled->PantRear( false );
}
}
}
break;
}
case user_command::pantographtogglefront: {
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == ( mvOccupied->ActiveCab == 1 ? mvControlled->PantFrontUp : mvControlled->PantRearUp ) ) {
// turn on...
if( mvOccupied->ActiveCab == 1 ) {
// przedni gdy w kabinie 1
mvControlled->PantFrontSP = false;
if( mvControlled->PantFront( true ) ) {
if( mvControlled->PantFrontStart != 1 ) {
if( ggPantFrontButton.SubModel ) {
ggPantFrontButton.UpdateValue( 1.0 );
}
play_sound( dsbSwitch );
}
}
}
else {
// rear otherwise
mvControlled->PantRearSP = false;
if( mvControlled->PantRear( true ) ) {
if( mvControlled->PantRearStart != 1 ) {
if( ggPantRearButton.SubModel ) {
ggPantRearButton.UpdateValue( 1.0 );
}
play_sound( dsbSwitch );
}
}
}
}
else {
// ...or turn off
if( mvOccupied->ActiveCab == 1 ) {
// przedni gdy w kabinie 1
mvControlled->PantFrontSP = false;
if( false == mvControlled->PantFront( false ) ) {
if( mvControlled->PantFrontStart != 0 ) {
if( ggPantFrontButton.SubModel ) {
ggPantFrontButton.UpdateValue(
( mvOccupied->PantSwitchType != "impulse" ?
0.0 :
1.0 ) );
}
play_sound( dsbSwitch );
}
}
}
else {
// rear otherwise
mvControlled->PantRearSP = false;
if( false == mvControlled->PantRear( false ) ) {
if( mvControlled->PantRearStart != 0 ) {
if( ggPantRearButton.SubModel ) {
ggPantRearButton.UpdateValue(
( mvOccupied->PantSwitchType != "impulse" ?
0.0 :
1.0 ) );
}
play_sound( dsbSwitch );
}
}
}
}
}
else if( Command.action == GLFW_RELEASE ) {
// impulse switches return automatically to neutral position
if( mvOccupied->PantSwitchType == "impulse" ) {
if( mvOccupied->ActiveCab == 1 ) {
// przedni gdy w kabinie 1
if( ggPantFrontButton.GetValue() > 0.1 ) {
play_sound( dsbSwitch );
}
if( ggPantFrontButton.SubModel ) {
ggPantFrontButton.UpdateValue( 0.0 );
}
}
else {
// rear otherwise
if( ggPantRearButton.GetValue() > 0.1 ) {
play_sound( dsbSwitch );
}
if( ggPantRearButton.SubModel ) {
ggPantRearButton.UpdateValue( 0.0 );
}
}
}
}
break;
}
case user_command::pantographtogglerear: {
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == ( mvOccupied->ActiveCab == 1 ? mvControlled->PantRearUp : mvControlled->PantFrontUp ) ) {
// turn on...
if( mvOccupied->ActiveCab == 1 ) {
// rear if in front cab
mvControlled->PantRearSP = false;
if( mvControlled->PantRear( true ) ) {
if( mvControlled->PantRearStart != 1 ) {
if( ggPantRearButton.SubModel ) {
ggPantRearButton.UpdateValue( 1.0 );
}
play_sound( dsbSwitch );
}
}
}
else {
// front otherwise
mvControlled->PantFrontSP = false;
if( mvControlled->PantFront( true ) ) {
if( mvControlled->PantFrontStart != 1 ) {
if( ggPantFrontButton.SubModel ) {
ggPantFrontButton.UpdateValue( 1.0 );
}
play_sound( dsbSwitch );
}
}
}
}
else {
// ...or turn off
if( mvOccupied->ActiveCab == 1 ) {
// rear if in front cab
mvControlled->PantRearSP = false;
if( false == mvControlled->PantRear( false ) ) {
if( mvControlled->PantRearStart != 0 ) {
if( ggPantRearButton.SubModel ) {
ggPantRearButton.UpdateValue(
( mvOccupied->PantSwitchType != "impulse" ?
0.0 :
1.0 ) );
}
play_sound( dsbSwitch );
}
}
}
else {
// front otherwise
mvControlled->PantFrontSP = false;
if( false == mvControlled->PantFront( false ) ) {
if( mvControlled->PantFrontStart != 0 ) {
if( ggPantFrontButton.SubModel ) {
ggPantFrontButton.UpdateValue(
( mvOccupied->PantSwitchType != "impulse" ?
0.0 :
1.0 ) );
}
play_sound( dsbSwitch );
}
}
}
}
}
else if( Command.action == GLFW_RELEASE ) {
// impulse switches return automatically to neutral position
if( mvOccupied->PantSwitchType == "impulse" ) {
if( mvOccupied->ActiveCab == 1 ) {
// tylny gdy w kabinie 1
if( ggPantRearButton.GetValue() > 0.1 ) {
play_sound( dsbSwitch );
}
if( ggPantRearButton.SubModel ) {
ggPantRearButton.UpdateValue( 0.0 );
}
}
else {
// front otherwise
if( ggPantFrontButton.GetValue() > 0.1 ) {
play_sound( dsbSwitch );
}
if( ggPantFrontButton.SubModel ) {
ggPantFrontButton.UpdateValue( 0.0 );
}
play_sound( dsbSwitch );
}
}
}
break;
}
case user_command::linebreakertoggle: {
if( Command.action != GLFW_RELEASE ) {
// press or hold...
if( false == mvControlled->Mains ) {
// ...to close the circuit
if( false == m_linebreakerclosed ) {
// safety check so we don't close the circuit right after opening
if( ggMainOnButton.SubModel != nullptr ) {
// two separate switches to close and break the circuit
// audio feedback
if( Command.action == GLFW_PRESS ) {
play_sound( dsbSwitch );
}
// visual feedback
ggMainOnButton.UpdateValue( 1.0 );
}
else if( ggMainButton.SubModel != nullptr ) {
// single two-state switch
// audio feedback
if( Command.action == GLFW_PRESS ) {
play_sound( dsbSwitch );
}
// visual feedback
ggMainButton.UpdateValue( 1.0 );
}
// keep track of period the button is held down, to determine when/if circuit closes
fMainRelayTimer += 0.33; // Command.time_delta * 5.0;
// NOTE: this shouldn't be necessary, what exactly does it fix?
if( mvControlled->Mains != true ) {
// hunter-080812: poprawka
// adjusted further to take into account state of the switch
mvControlled->ConverterSwitch( ggConverterButton.GetValue() > 0.5 );
mvControlled->CompressorSwitch( ggCompressorButton.GetValue() > 0.5 );
}
if( fMainRelayTimer > mvControlled->InitialCtrlDelay ) {
// wlaczanie WSa z opoznieniem
if( mvControlled->MainSwitch( true ) ) {
// sound feedback, engine start for diesel vehicle
if( mvControlled->EngineType == DieselEngine ) {
play_sound( dsbDieselIgnition );
}
}
}
}
}
else {
// ...to open the circuit
if( true == m_linebreakerclosed ) {
// safety check so we don't open the circuit right after closing
if( mvControlled->MainSwitch( false ) ) {
if( ggMainOffButton.SubModel != nullptr ) {
// two separate switches to close and break the circuit
// audio feedback
if( Command.action == GLFW_PRESS ) {
play_sound( dsbSwitch );
}
// visual feedback
ggMainOffButton.UpdateValue( 1.0 );
}
else if( ggMainButton.SubModel != nullptr ) {
// single two-state switch
// NOTE: we don't have switch type definition for the line breaker switch
// so for the time being we have hard coded "impulse" switches for all EMUs
// TODO: have proper switch type config for all switches, and put it in the cab switch descriptions, not in the .fiz
if( mvControlled->TrainType == dt_EZT ) {
// audio feedback
if( Command.action == GLFW_PRESS ) {
play_sound( dsbSwitch );
}
// visual feedback
ggMainButton.UpdateValue( 1.0 );
}
else {
// audio feedback
if( Command.action == GLFW_PRESS ) {
play_sound( dsbSwitch );
}
// visual feedback
ggMainButton.UpdateValue( 0.0 );
}
}
// side-effects
mvControlled->ConverterSwitch( ggConverterButton.GetValue() > 0.5 );
mvControlled->CompressorSwitch( ggCompressorButton.GetValue() > 0.5 );
}
// play sound immediately when the switch is hit, not after release
if( fMainRelayTimer > 0.0f ) {
play_sound( dsbRelay );
fMainRelayTimer = 0.0f;
}
}
}
}
else {
// release...
if( false == mvControlled->Mains ) {
// ...after opening circuit, or holding for too short time to close it
/*
if( mvControlled->ConverterAllow ) {
// po puszczeniu przycisku od WSa odpalanie potwora
mvControlled->ConverterSwitch( true );
}
*/
// hunter-091012: przeniesione z mover.pas, zeby dzwiek sie nie zapetlal,
if( fMainRelayTimer > 0.0f ) {
play_sound( dsbRelay );
fMainRelayTimer = 0.0f;
}
// we don't exactly know which of the two buttons was used, so reset both
if( ggMainOnButton.SubModel != nullptr ) {
// setup with two separate swiches
ggMainOnButton.UpdateValue( 0.0 );
}
if( ggMainOffButton.SubModel != nullptr ) {
// setup with two separate swiches
ggMainOffButton.UpdateValue( 0.0 );
}
// and the two-state switch too, for good measure
if( ggMainButton.SubModel != nullptr ) {
ggMainButton.UpdateValue( 0.0 );
// NOTE: we don't have switch type definition for the line breaker switch
// so for the time being we have hard coded "impulse" switches for all EMUs
// TODO: have proper switch type config for all switches, and put it in the cab switch descriptions, not in the .fiz
if( mvControlled->TrainType == dt_EZT ) {
// audio feedback
play_sound( dsbSwitch );
}
}
m_linebreakerclosed = false;
}
else {
// ...after closing the circuit
if( ggMainOnButton.SubModel != nullptr ) {
// setup with two separate switches
ggMainOnButton.UpdateValue( 0.0 );
}
// NOTE: we don't have switch type definition for the line breaker switch
// so for the time being we have hard coded "impulse" switches for all EMUs
// TODO: have proper switch type config for all switches, and put it in the cab switch descriptions, not in the .fiz
if( mvControlled->TrainType == dt_EZT ) {
if( ggMainButton.SubModel != nullptr ) {
ggMainButton.UpdateValue( 0.0 );
// audio feedback
play_sound( dsbSwitch );
}
}
m_linebreakerclosed = true;
}
}
break;
}
case user_command::convertertoggle: {
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == mvControlled->ConverterAllow ) {
// turn on
if( ( mvControlled->EnginePowerSource.SourceType != CurrentCollector )
|| ( mvControlled->PantRearVolt != 0.0 )
|| ( mvControlled->PantFrontVolt != 0.0 ) ) {
// visual feedback
ggConverterButton.UpdateValue( 1.0 );
// sound feedback
if( ggConverterButton.GetValue() < 0.5 ) {
play_sound( dsbSwitch );
}
// impulse type switch has no effect if there's no power
// NOTE: this is most likely setup wrong, but the whole thing is smoke and mirrors anyway
if( ( mvOccupied->ConvSwitchType != "impulse" )
|| ( mvControlled->Mains ) ) {
if( true == mvControlled->ConverterSwitch( true ) ) {
// side effects
// control the compressor, if it's paired with the converter
if( mvControlled->CompressorPower == 2 ) {
// hunter-091012: tak jest poprawnie
mvControlled->CompressorSwitch( true );
}
}
}
}
}
else {
//turn off
if( true == mvControlled->ConverterSwitch( false ) ) {
// sound feedback
play_sound( dsbSwitch );
// visual feedback
ggConverterButton.UpdateValue( 0.0 );
if( ggConverterOffButton.SubModel != nullptr ) {
ggConverterOffButton.UpdateValue( 1.0 );
}
// side effects
// control the compressor, if it's paired with the converter
if( mvControlled->CompressorPower == 2 ) {
// hunter-091012: tak jest poprawnie
mvControlled->CompressorSwitch( false );
}
if( ( mvControlled->TrainType == dt_EZT )
&& ( !TestFlag( mvControlled->EngDmgFlag, 4 ) ) ) {
mvControlled->ConvOvldFlag = false;
}
}
}
}
else if( Command.action == GLFW_RELEASE ){
// on button release...
if( mvOccupied->ConvSwitchType == "impulse" ) {
// ...return switches to start position if applicable
if( ( ggConverterButton.GetValue() > 0.0 )
|| ( ggConverterOffButton.GetValue() > 0.0 ) ) {
// sound feedback
play_sound( dsbSwitch );
}
ggConverterButton.UpdateValue( 0.0 );
ggConverterOffButton.UpdateValue( 0.0 );
}
}
break;
}
case user_command::compressortoggle: {
if( mvControlled->CompressorPower < 2 ) {
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == mvControlled->CompressorAllow ) {
// turn on
// visual feedback
ggCompressorButton.UpdateValue( 1.0 );
// sound feedback
if( ggCompressorButton.GetValue() < 0.5 ) {
play_sound( dsbSwitch );
}
// impulse type switch has no effect if there's no power
// NOTE: this is most likely setup wrong, but the whole thing is smoke and mirrors anyway
// (we're presuming impulse type switch for all EMUs for the time being)
/*
if( ( mvControlled->TrainType != dt_EZT )
|| ( mvControlled->Mains ) ) {
*/
mvControlled->CompressorSwitch( true );
/*
}
*/
}
else {
//turn off
if( true == mvControlled->CompressorSwitch( false ) ) {
// sound feedback
play_sound( dsbSwitch );
// NOTE: we don't have switch type definition for the compresor switch
// so for the time being we have hard coded "impulse" switches for all EMUs
// TODO: have proper switch type config for all switches, and put it in the cab switch descriptions, not in the .fiz
/*
if( mvControlled->TrainType == dt_EZT ) {
// visual feedback
ggCompressorButton.UpdateValue( 1.0 );
}
else {
*/
// visual feedback
ggCompressorButton.UpdateValue( 0.0 );
/*
}
*/
}
}
}
else if( Command.action == GLFW_RELEASE ) {
// on button release...
/*
// TODO: check if compressor switch is two-state or impulse type
// NOTE: we don't have switch type definition for the compresor switch
// so for the time being we have hard coded "impulse" switches for all EMUs
// TODO: have proper switch type config for all switches, and put it in the cab switch descriptions, not in the .fiz
if( mvControlled->TrainType == dt_EZT ) {
if( ggCompressorButton.SubModel != nullptr ) {
ggCompressorButton.UpdateValue( 0.0 );
// audio feedback
play_sound( dsbSwitch );
}
}
*/
}
}
break;
}
default: {
break;
@@ -852,23 +1371,7 @@ void TTrain::OnKeyDown(int cKey)
;
else
;
#endif
// McZapkie-240302 - wlaczanie glownego obwodu klawiszem M+shift
//-----------
// hunter-141211: wyl. szybki zalaczony przeniesiony do TTrain::Update()
/* if (cKey==Global::Keys[k_Main])
{
ggMainOnButton.PutValue(1);
if (mvControlled->MainSwitch(true))
{
if (mvControlled->EngineType==DieselEngine)
dsbDieselIgnition->Play(0,0,0);
else
dsbNastawnikJazdy->Play(0,0,0);
}
}
else */
if (cKey == Global::Keys[k_Battery])
if( cKey == Global::Keys[ k_Battery ] )
{
// if
// (((mvControlled->TrainType==dt_EZT)||(mvControlled->EngineType==ElectricSeriesMotor)||(mvControlled->EngineType==DieselElectric))&&(!mvControlled->Battery))
@@ -895,7 +1398,8 @@ void TTrain::OnKeyDown(int cKey)
}
}
}
else if ((cKey == Global::Keys[k_StLinOff]) && (!Global::shiftState) && (!Global::ctrlState)) // shift&ctrl are used for light dimming
#endif
if ((cKey == Global::Keys[k_StLinOff]) && (!Global::shiftState) && (!Global::ctrlState)) // shift&ctrl are used for light dimming
{
if (mvControlled->TrainType == dt_EZT)
{
@@ -930,7 +1434,8 @@ void TTrain::OnKeyDown(int cKey)
}
}
}
if (cKey == Global::Keys[k_Main])
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
if( cKey == Global::Keys[ k_Main ] )
{
if (fabs(ggMainOnButton.GetValue()) < 0.001)
if (dsbSwitch)
@@ -939,6 +1444,7 @@ void TTrain::OnKeyDown(int cKey)
dsbSwitch->Play(0, 0, 0);
}
}
#endif
else if (cKey == Global::Keys[k_BrakeProfile]) // McZapkie-240302-B:
//-----------
@@ -991,34 +1497,7 @@ void TTrain::OnKeyDown(int cKey)
}
}
}
//-----------
// hunter-261211: przetwornica i sprzezarka przeniesione do
// TTrain::Update()
/* if (cKey==Global::Keys[k_Converter]) //NBMX 14-09-2003:
przetwornica wl
{
if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
(mvControlled->EnginePowerSource.SourceType!=CurrentCollector) ||
(!Global::bLiveTraction))
if (mvControlled->ConverterSwitch(true))
{
dsbSwitch->SetVolume(DSBVOLUME_MAX);
dsbSwitch->Play(0,0,0);
}
}
else
if (cKey==Global::Keys[k_Compressor]) //NBMX 14-09-2003: sprezarka wl
{
if ((mvControlled->ConverterFlag) ||
(mvControlled->CompressorPower<2))
if (mvControlled->CompressorSwitch(true))
{
dsbSwitch->SetVolume(DSBVOLUME_MAX);
dsbSwitch->Play(0,0,0);
}
}
else */
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if (cKey == Global::Keys[k_Converter])
{
if (ggConverterButton.GetValue() == 0)
@@ -1040,7 +1519,8 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
dsbSwitch->Play(0, 0, 0);
}
}
else if (cKey == Global::Keys[k_SmallCompressor]) // Winger 160404: mala
#endif
else if( cKey == Global::Keys[ k_SmallCompressor ] ) // Winger 160404: mala
// sprezarka wl
{ // Ra: dźwięk, gdy razem z [Shift]
if ((mvControlled->TrainType & dt_EZT) ? mvControlled == mvOccupied :
@@ -1184,7 +1664,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
}
}
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
//-----------
else if (cKey == Global::Keys[k_PantFrontUp])
{ // Winger 160204: podn.
@@ -1243,7 +1723,8 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
}
}
}
else if (cKey == Global::Keys[k_Active]) // yB 300407: przelacznik rozrzadu
#endif
else if( cKey == Global::Keys[ k_Active ] ) // yB 300407: przelacznik rozrzadu
{ // Ra 2014-06: uruchomiłem to, aby aktywować czuwak w zajmowanym członie,
// a wyłączyć w innych
// Ra 2014-03: aktywacja czuwaka przepięta na ustawienie kierunku w
@@ -1839,7 +2320,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
if (Global::ctrlState) // z controlem
{
ggConverterFuseButton.PutValue(1); // hunter-261211
if ((mvControlled->Mains == false) && (ggConverterButton.GetValue() == 0) &&
if ((mvControlled->Mains == false) && (ggConverterButton.GetValue() < 0.01) &&
(mvControlled->TrainType != dt_EZT))
mvControlled->ConvOvldFlag = false;
}
@@ -1913,7 +2394,8 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
}
#endif
}
else if (cKey == Global::Keys[k_Main])
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if( cKey == Global::Keys[ k_Main ] )
// McZapkie-240302 - wylaczanie glownego obwodu
//-----------
// hunter-141211: wyl. szybki wylaczony przeniesiony do TTrain::Update()
@@ -1925,7 +2407,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
dsbSwitch->Play(0, 0, 0);
}
}
else if (cKey == Global::Keys[k_Battery])
else if( cKey == Global::Keys[ k_Battery ] )
{
// if ((mvControlled->TrainType==dt_EZT) ||
// (mvControlled->EngineType==ElectricSeriesMotor)||
@@ -1944,7 +2426,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
mvControlled->PantRear(false);
}
}
#endif
//-----------
// if (cKey==Global::Keys[k_Active]) //yB 300407: przelacznik
// rozrzadu
@@ -2006,6 +2488,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
}
}
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if (cKey == Global::Keys[k_Converter])
//-----------
// hunter-261211: przetwornica i sprzezarka przeniesione do
@@ -2030,7 +2513,6 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
}
}
//-----------
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if( cKey == Global::Keys[ k_Releaser ] ) // odluzniacz
{
if (!FreeFlyModeFlag)
@@ -2052,8 +2534,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
}
}
#endif
else if (cKey == Global::Keys[k_SmallCompressor]) // Winger 160404: mala
// sprezarka wl
else if (cKey == Global::Keys[k_SmallCompressor]) // Winger 160404: mala sprezarka wl
{ // Ra: bez [Shift] też dać dźwięk
if ((mvControlled->TrainType & dt_EZT) ? mvControlled == mvOccupied :
!mvOccupied->ActiveCab) // tylko w maszynowym
@@ -2164,9 +2645,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) ||
false; // wyjście z maszynowego wyłącza sprężarkę pomocniczą
}
else if (cKey == Global::Keys[k_Couple])
{ // ABu051104: male zmiany, zeby
// mozna bylo laczyc odlegle
// wagony
{ // ABu051104: male zmiany, zeby mozna bylo laczyc odlegle wagony
// da sie zoptymalizowac, ale nie ma na to czasu :(
if (iCabn > 0)
{
@@ -2409,6 +2888,7 @@ if
}
}
//-----------
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
else if (cKey == Global::Keys[k_PantFrontDown]) // Winger 160204:
// opuszczanie prz. patyka
{
@@ -2462,7 +2942,8 @@ if
}
}
}
else if (cKey == Global::Keys[k_Heating]) // Winger 020304: ogrzewanie -
#endif
else if( cKey == Global::Keys[ k_Heating ] ) // Winger 020304: ogrzewanie -
// wylaczenie
{ // Ra 2014-09: w trybie latania obsługa jest w World.cpp
if (!FreeFlyModeFlag)
@@ -3061,6 +3542,7 @@ bool TTrain::Update( double const Deltatime )
DWORD stat;
double dt = Deltatime; // Timer::GetDeltaTime();
if (DynamicObject->mdKabina)
{ // Ra: TODO: odczyty klawiatury/pulpitu nie
// powinny być uzależnione od istnienia modelu
@@ -3327,8 +3809,10 @@ bool TTrain::Update( double const Deltatime )
if (mvControlled->TrainType != dt_EZT)
mvControlled->MainSwitch(false);
}
else if (fConverterTimer >= fConverterPrzekaznik)
mvControlled->CompressorSwitch(true);
else if( fConverterTimer >= fConverterPrzekaznik ) {
// changed switch from always true to take into account state of the compressor switch
mvControlled->CompressorSwitch( mvControlled->CompressorAllow );
}
}
}
else
@@ -4473,17 +4957,29 @@ bool TTrain::Update( double const Deltatime )
//---------
// Winger 010304 - pantografy
if (ggPantFrontButton.SubModel)
// NOTE: shouldn't the pantograph updates check whether it's front or rear cabin?
if (ggPantFrontButton.SubModel )
{
if (mvControlled->PantFrontUp)
ggPantFrontButton.PutValue(1);
else
ggPantFrontButton.PutValue(0);
if( mvOccupied->PantSwitchType != "impulse" ) {
ggPantFrontButton.UpdateValue(
( mvOccupied->ActiveCab == 1 ?
mvControlled->PantFrontUp :
mvControlled->PantRearUp ) ?
1.0 :
0.0 );
}
ggPantFrontButton.Update();
}
if (ggPantRearButton.SubModel)
{
ggPantRearButton.PutValue(mvControlled->PantRearUp ? 1 : 0);
if( mvOccupied->PantSwitchType != "impulse" ) {
ggPantRearButton.UpdateValue(
( mvOccupied->ActiveCab == 1 ?
mvControlled->PantRearUp :
mvControlled->PantFrontUp ) ?
1.0 :
0.0 );
}
ggPantRearButton.Update();
}
if (ggPantFrontButtonOff.SubModel)
@@ -4492,8 +4988,7 @@ bool TTrain::Update( double const Deltatime )
}
// Winger 020304 - ogrzewanie
//----------
// hunter-080812: poprawka na ogrzewanie w elektrykach - usuniete
// uzaleznienie od przetwornicy
// hunter-080812: poprawka na ogrzewanie w elektrykach - usuniete uzaleznienie od przetwornicy
if (ggTrainHeatingButton.SubModel)
{
if (mvControlled->Heating)
@@ -4633,8 +5128,8 @@ bool TTrain::Update( double const Deltatime )
{
SetFlag(mvOccupied->WarningSignal, 2);
}
//----------------
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// hunter-141211: wyl. szybki zalaczony i wylaczony przeniesiony z
// OnKeyPress()
if (Global::shiftState && Console::Pressed(Global::Keys[k_Main]))
@@ -4670,7 +5165,6 @@ bool TTrain::Update( double const Deltatime )
ggMainOnButton.UpdateValue(0);
}
//---
if (!Global::shiftState && Console::Pressed(Global::Keys[k_Main]))
{
ggMainOffButton.PutValue(1);
@@ -4679,7 +5173,7 @@ bool TTrain::Update( double const Deltatime )
}
else
ggMainOffButton.UpdateValue(0);
#endif
/* if (cKey==Global::Keys[k_Main]) //z shiftem
{
ggMainOnButton.PutValue(1);
@@ -4809,6 +5303,7 @@ bool TTrain::Update( double const Deltatime )
else
ggAntiSlipButton.UpdateValue(0);
//-----------------
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// hunter-261211: przetwornica i sprezarka
if (Global::shiftState &&
Console::Pressed(Global::Keys[k_Converter])) // NBMX 14-09-2003: przetwornica wl
@@ -4832,7 +5327,6 @@ bool TTrain::Update( double const Deltatime )
ggConverterOffButton.PutValue(0);
}
}
// if (
// Global::shiftState&&Console::Pressed(Global::Keys[k_Compressor])&&((mvControlled->EngineType==ElectricSeriesMotor)||(mvControlled->TrainType==dt_EZT))
// ) //NBMX 14-09-2003: sprezarka wl
@@ -4842,7 +5336,6 @@ bool TTrain::Update( double const Deltatime )
ggCompressorButton.PutValue(1);
mvControlled->CompressorSwitch(true);
}
if (!Global::shiftState &&
Console::Pressed(Global::Keys[k_Converter])) // NBMX 14-09-2003: przetwornica wl
{
@@ -4852,7 +5345,6 @@ bool TTrain::Update( double const Deltatime )
if ((mvControlled->TrainType == dt_EZT) && (!TestFlag(mvControlled->EngDmgFlag, 4)))
mvControlled->ConvOvldFlag = false;
}
// if (
// !Global::shiftState&&Console::Pressed(Global::Keys[k_Compressor])&&((mvControlled->EngineType==ElectricSeriesMotor)||(mvControlled->TrainType==dt_EZT))
// ) //NBMX 14-09-2003: sprezarka wl
@@ -4862,7 +5354,7 @@ bool TTrain::Update( double const Deltatime )
ggCompressorButton.PutValue(0);
mvControlled->CompressorSwitch(false);
}
#endif
/*
bez szifta
if (cKey==Global::Keys[k_Converter]) //NBMX wyl przetwornicy
@@ -5231,7 +5723,7 @@ bool TTrain::Update( double const Deltatime )
if (!DynamicObject->Mechanik->AIControllFlag) // tylko jeśli nie prowadzi AI
mvControlled->DepartureSignal = false;
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
if (Console::Pressed(Global::Keys[k_Main])) //[]
{
if (Global::shiftState)
@@ -5241,7 +5733,7 @@ bool TTrain::Update( double const Deltatime )
}
else
ggMainButton.PutValue(0);
#endif
if (Console::Pressed(Global::Keys[k_CurrentNext]))
{
if (mvControlled->TrainType != dt_EZT)
@@ -5299,7 +5791,7 @@ bool TTrain::Update( double const Deltatime )
}
}
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// Winger 010304 PantAllDownButton
if (Console::Pressed(Global::Keys[k_PantFrontUp]))
{
@@ -5313,7 +5805,6 @@ bool TTrain::Update( double const Deltatime )
ggPantFrontButton.PutValue(0);
ggPantAllDownButton.PutValue(0);
}
if (Console::Pressed(Global::Keys[k_PantRearUp]))
{
if (Global::shiftState)
@@ -5326,7 +5817,7 @@ bool TTrain::Update( double const Deltatime )
ggPantRearButton.PutValue(0);
ggPantFrontButtonOff.PutValue(0);
}
#endif
/* if ((mvControlled->Mains) &&
(mvControlled->EngineType==ElectricSeriesMotor))
{
@@ -5428,8 +5919,10 @@ bool TTrain::Update( double const Deltatime )
ggUniversal4Button.PermIncValue(dt);
ggUniversal4Button.Update();
/*
ggMainOffButton.UpdateValue(0);
ggMainOnButton.UpdateValue(0);
*/
ggSecurityResetButton.UpdateValue(0);
/*
ggReleaserButton.UpdateValue(0);

View File

@@ -111,6 +111,9 @@ class TTrain
// NOTE: temporary routine until sound system is sorted out and paired with switches
void play_sound( PSound Sound, PSound Fallbacksound = nullptr );
// helper variable, to prevent immediate switch between closing and opening line breaker circuit
bool m_linebreakerclosed{ false };
private: //żeby go nic z zewnątrz nie przestawiało
TDynamicObject *DynamicObject; // przestawia zmiana pojazdu [F5]
private: //żeby go nic z zewnątrz nie przestawiało

View File

@@ -78,14 +78,16 @@ command_relay::command_relay() {
/*
const int k_AntiSlipping = 21;
const int k_Sand = 22;
const int k_Main = 23;
*/
{ user_command::linebreakertoggle, command_target::vehicle },
{ user_command::reverserincrease, command_target::vehicle },
{ user_command::reverserdecrease, command_target::vehicle },
/*
const int k_Fuse = 26;
const int k_Compressor = 27;
const int k_Converter = 28;
*/
{ user_command::compressortoggle, command_target::vehicle },
{ user_command::convertertoggle, command_target::vehicle },
/*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30;
const int k_BrakeProfile = 31;
@@ -107,15 +109,7 @@ const int k_FailedEngineCutOff = 35;
{ user_command::moveforwardfast, command_target::entity },
{ user_command::movebackfast, command_target::entity },
{ user_command::moveupfast, command_target::entity },
{ user_command::movedownfast, command_target::entity }
/*
{ user_command::moveleftfastest, command_target::entity },
{ user_command::moverightfastest, command_target::entity },
{ user_command::moveforwardfastest, command_target::entity },
{ user_command::movebackfastest, command_target::entity },
{ user_command::moveupfastest, command_target::entity },
{ user_command::movedownfastest, command_target::entity }
*/
{ user_command::movedownfast, command_target::entity },
/*
const int k_CabForward = 42;
const int k_CabBackward = 43;
@@ -129,10 +123,10 @@ const int k_OpenRight = 50;
const int k_CloseLeft = 51;
const int k_CloseRight = 52;
const int k_DepartureSignal = 53;
const int k_PantFrontUp = 54;
const int k_PantRearUp = 55;
const int k_PantFrontDown = 56;
const int k_PantRearDown = 57;
*/
{ user_command::pantographtogglefront, command_target::vehicle },
{ user_command::pantographtogglerear, command_target::vehicle },
/*
const int k_Heating = 58;
// const int k_FreeFlyMode= 59;
const int k_LeftSign = 60;
@@ -147,7 +141,9 @@ const int k_Univ3 = 68;
const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
const int k_Battery = 72;
*/
{ user_command::batterytoggle, command_target::vehicle }
/*
const int k_WalkMode = 73;
int const k_DimHeadlights = 74;
*/
@@ -180,14 +176,16 @@ int const k_DimHeadlights = 74;
/*
const int k_AntiSlipping = 21;
const int k_Sand = 22;
const int k_Main = 23;
*/
"linebreakertoggle",
"reverserincrease",
"reverserdecrease",
/*
const int k_Fuse = 26;
const int k_Compressor = 27;
const int k_Converter = 28;
*/
"compressortoggle",
"convertertoggle",
/*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30;
const int k_BrakeProfile = 31;
@@ -209,15 +207,7 @@ const int k_FailedEngineCutOff = 35;
"", //"moveforwardfast",
"", //"movebackfast",
"", //"moveupfast",
"" //"movedownfast"
/*
"moveleftfastest",
"moverightfastest",
"moveforwardfastest",
"movebackfastest",
"moveupfastest",
"movedownfastest"
*/
"", //"movedownfast"
/*
const int k_CabForward = 42;
const int k_CabBackward = 43;
@@ -231,10 +221,10 @@ const int k_OpenRight = 50;
const int k_CloseLeft = 51;
const int k_CloseRight = 52;
const int k_DepartureSignal = 53;
const int k_PantFrontUp = 54;
const int k_PantRearUp = 55;
const int k_PantFrontDown = 56;
const int k_PantRearDown = 57;
*/
"pantographtogglefront",
"pantographtogglerear",
/*
const int k_Heating = 58;
// const int k_FreeFlyMode= 59;
const int k_LeftSign = 60;
@@ -249,7 +239,9 @@ const int k_Univ3 = 68;
const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
const int k_Battery = 72;
*/
"batterytoggle"
/*
const int k_WalkMode = 73;
int const k_DimHeadlights = 74;
*/

View File

@@ -38,14 +38,16 @@ enum class user_command {
/*
const int k_AntiSlipping = 21;
const int k_Sand = 22;
const int k_Main = 23;
*/
linebreakertoggle,
reverserincrease,
reverserdecrease,
/*
const int k_Fuse = 26;
const int k_Compressor = 27;
const int k_Converter = 28;
*/
compressortoggle,
convertertoggle,
/*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30;
const int k_BrakeProfile = 31;
@@ -67,15 +69,7 @@ const int k_FailedEngineCutOff = 35;
moveforwardfast,
movebackfast,
moveupfast,
movedownfast
/*
moveleftfastest,
moverightfastest,
moveforwardfastest,
movebackfastest,
moveupfastest,
movedownfastest
*/
movedownfast,
/*
const int k_CabForward = 42;
const int k_CabBackward = 43;
@@ -89,10 +83,10 @@ const int k_OpenRight = 50;
const int k_CloseLeft = 51;
const int k_CloseRight = 52;
const int k_DepartureSignal = 53;
const int k_PantFrontUp = 54;
const int k_PantRearUp = 55;
const int k_PantFrontDown = 56;
const int k_PantRearDown = 57;
*/
pantographtogglefront,
pantographtogglerear,
/*
const int k_Heating = 58;
// const int k_FreeFlyMode= 59;
const int k_LeftSign = 60;
@@ -107,11 +101,12 @@ const int k_Univ3 = 68;
const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
const int k_Battery = 72;
*/
batterytoggle
/*
const int k_WalkMode = 73;
int const k_DimHeadlights = 74;
*/
};
enum class command_target {

View File

@@ -188,7 +188,7 @@ gamepad_input::on_button( gamepad_button const Button, int const Action ) {
void
gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, glm::vec2 const &Triggers ) {
// left stick, look around
// right stick, look around
if( ( Rightstick.x != 0.0f ) || ( Rightstick.y != 0.0f ) ) {
// TODO: make toggles for the axis flip
auto const deltatime = Timer::GetDeltaRenderTime() * 60.0;
@@ -204,7 +204,7 @@ gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, g
0 );
}
// right stick, either movement or controls, depending on currently active mode
// left stick, either movement or controls, depending on currently active mode
if( m_mode == control_mode::entity ) {
if( ( Leftstick.x != 0.0 || Leftstick.y != 0.0 )
@@ -218,45 +218,6 @@ gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, g
GLFW_PRESS,
0 );
}
/*
Leftstick = circle_to_square( Leftstick );
if( Leftstick.y >= 0.0f ) {
// forward
process_axis(
Leftstick.y, m_leftstick.y,
1.0,
user_command::moveforward,
user_command::moveforwardfast,
0 );
}
if( Leftstick.y <= 0.0f ) {
// back
process_axis(
Leftstick.y, m_leftstick.y,
-1.0,
user_command::moveback,
user_command::movebackfast,
0 );
}
if( Leftstick.x >= 0.0f ) {
// right
process_axis(
Leftstick.x, m_leftstick.x,
1.0,
user_command::moveright,
user_command::moverightfast,
0 );
}
if( Leftstick.x <= 0.0f ) {
// left
process_axis(
Leftstick.x, m_leftstick.x,
-1.0,
user_command::moveleft,
user_command::moveleftfast,
0 );
}
*/
}
else {
// vehicle control modes
@@ -317,7 +278,7 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
m_modeaccumulator = 0.0f;
}
if( Value > m_deadzone ) {
m_modeaccumulator += Value * deltatime;
m_modeaccumulator += ( Value - m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime;
while( m_modeaccumulator >= 1.0f ) {
// send commands if the accumulator(s) was filled
m_relay.post(
@@ -335,7 +296,7 @@ gamepad_input::process_mode( float const Value, std::uint16_t const Recipient )
m_modeaccumulator = 0.0f;
}
if( Value < m_deadzone ) {
m_modeaccumulator += Value * deltatime;
m_modeaccumulator += ( Value + m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime;
while( m_modeaccumulator <= -1.0f ) {
// send commands if the accumulator(s) was filled
m_relay.post(

View File

@@ -31,6 +31,7 @@ keyboard_input::key( int const Key, int const Action ) {
false :
true );
modifier = true;
// whenever shift key is used it may affect currently pressed movement keys, so check and update these
}
if( ( Key == GLFW_KEY_LEFT_CONTROL ) || ( Key == GLFW_KEY_RIGHT_CONTROL ) ) {
// update internal state, but don't bother passing these
@@ -45,6 +46,16 @@ keyboard_input::key( int const Key, int const Action ) {
return false;
}
if( true == update_movement( Key, Action ) ) {
// if the received key was one of movement keys, it's been handled and we don't need to bother further
return true;
}
// store key state
if( Key != -1 ) {
m_keys[ Key ] = Action;
}
// include active modifiers for currently pressed key, except if the key is a modifier itself
auto const key =
Key
@@ -106,14 +117,16 @@ keyboard_input::default_bindings() {
/*
const int k_AntiSlipping = 21;
const int k_Sand = 22;
const int k_Main = 23;
*/
{ "linebreakertoggle", command_target::vehicle, GLFW_KEY_M },
{ "reverserincrease", command_target::vehicle, GLFW_KEY_D },
{ "reverserdecrease", command_target::vehicle, GLFW_KEY_R },
/*
const int k_Fuse = 26;
const int k_Compressor = 27;
const int k_Converter = 28;
*/
{ "compressortoggle", command_target::vehicle, GLFW_KEY_C },
{ "convertertoggle", command_target::vehicle, GLFW_KEY_X },
/*
const int k_MaxCurrent = 29;
const int k_CurrentAutoRelay = 30;
const int k_BrakeProfile = 31;
@@ -130,20 +143,12 @@ const int k_FailedEngineCutOff = 35;
{ "moveback", command_target::entity, GLFW_KEY_DOWN },
{ "moveup", command_target::entity, GLFW_KEY_PAGE_UP },
{ "movedown", command_target::entity, GLFW_KEY_PAGE_DOWN },
{ "moveleftfast", command_target::entity, GLFW_KEY_LEFT | keymodifier::shift },
{ "moverightfast", command_target::entity, GLFW_KEY_RIGHT | keymodifier::shift },
{ "moveforwardfast", command_target::entity, GLFW_KEY_UP | keymodifier::shift },
{ "movebackfast", command_target::entity, GLFW_KEY_DOWN | keymodifier::shift },
{ "moveupfast", command_target::entity, GLFW_KEY_PAGE_UP | keymodifier::shift },
{ "movedownfast", command_target::entity, GLFW_KEY_PAGE_DOWN | keymodifier::shift }
/*
{ "moveleftfastest", command_target::entity, GLFW_KEY_LEFT | keymodifier::control },
{ "moverightfastest", command_target::entity, GLFW_KEY_RIGHT | keymodifier::control },
{ "moveforwardfastest", command_target::entity, GLFW_KEY_UP | keymodifier::control },
{ "movebackfastest", command_target::entity, GLFW_KEY_DOWN | keymodifier::control },
{ "moveupfastest", command_target::entity, GLFW_KEY_PAGE_UP | keymodifier::control },
{ "movedownfastest", command_target::entity, GLFW_KEY_PAGE_DOWN | keymodifier::control }
*/
{ "moveleftfast", command_target::entity, -1 },
{ "moverightfast", command_target::entity, -1 },
{ "moveforwardfast", command_target::entity, -1 },
{ "movebackfast", command_target::entity, -1 },
{ "moveupfast", command_target::entity, -1 },
{ "movedownfast", command_target::entity, -1 },
/*
const int k_CabForward = 42;
const int k_CabBackward = 43;
@@ -157,10 +162,10 @@ const int k_OpenRight = 50;
const int k_CloseLeft = 51;
const int k_CloseRight = 52;
const int k_DepartureSignal = 53;
const int k_PantFrontUp = 54;
const int k_PantRearUp = 55;
const int k_PantFrontDown = 56;
const int k_PantRearDown = 57;
*/
{ "pantographtogglefront", command_target::vehicle, GLFW_KEY_P },
{ "pantographtogglerear", command_target::vehicle, GLFW_KEY_O },
/*
const int k_Heating = 58;
// const int k_FreeFlyMode= 59;
const int k_LeftSign = 60;
@@ -175,7 +180,9 @@ const int k_Univ3 = 68;
const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
const int k_Battery = 72;
*/
{ "batterytoggle", command_target::vehicle, GLFW_KEY_J }
/*
const int k_WalkMode = 73;
int const k_DimHeadlights = 74;
*/
@@ -199,6 +206,117 @@ keyboard_input::bind() {
}
++commandcode;
}
// cache movement key bindings, so we can test them faster in the input loop
m_bindingscache.forward = m_commands[ static_cast<std::size_t>( user_command::moveforward ) ].binding;
m_bindingscache.back = m_commands[ static_cast<std::size_t>( user_command::moveback ) ].binding;
m_bindingscache.left = m_commands[ static_cast<std::size_t>( user_command::moveleft ) ].binding;
m_bindingscache.right = m_commands[ static_cast<std::size_t>( user_command::moveright ) ].binding;
m_bindingscache.up = m_commands[ static_cast<std::size_t>( user_command::moveup ) ].binding;
m_bindingscache.down = m_commands[ static_cast<std::size_t>( user_command::movedown ) ].binding;
}
// NOTE: ugliest code ever, gg
bool
keyboard_input::update_movement( int const Key, int const Action ) {
bool shift =
( ( Key == GLFW_KEY_LEFT_SHIFT )
|| ( Key == GLFW_KEY_RIGHT_SHIFT ) );
bool movementkey =
( ( Key == m_bindingscache.forward )
|| ( Key == m_bindingscache.back )
|| ( Key == m_bindingscache.left )
|| ( Key == m_bindingscache.right )
|| ( Key == m_bindingscache.up )
|| ( Key == m_bindingscache.down ) );
if( false == ( shift || movementkey ) ) { return false; }
if( false == shift ) {
// TODO: pass correct entity id once the missing systems are in place
if( Key == m_bindingscache.forward ) {
m_keys[ Key ] = Action;
m_relay.post(
( m_shift ?
user_command::moveforwardfast :
user_command::moveforward ),
0, 0,
m_keys[ m_bindingscache.forward ],
0 );
return true;
}
else if( Key == m_bindingscache.back ) {
m_keys[ Key ] = Action;
m_relay.post(
( m_shift ?
user_command::movebackfast :
user_command::moveback ),
0, 0,
m_keys[ m_bindingscache.back ],
0 );
return true;
}
else if( Key == m_bindingscache.left ) {
m_keys[ Key ] = Action;
m_relay.post(
( m_shift ?
user_command::moveleftfast :
user_command::moveleft ),
0, 0,
m_keys[ m_bindingscache.left ],
0 );
return true;
}
else if( Key == m_bindingscache.right ) {
m_keys[ Key ] = Action;
m_relay.post(
( m_shift ?
user_command::moverightfast :
user_command::moveright ),
0, 0,
m_keys[ m_bindingscache.right ],
0 );
return true;
}
else if( Key == m_bindingscache.up ) {
m_keys[ Key ] = Action;
m_relay.post(
( m_shift ?
user_command::moveupfast :
user_command::moveup ),
0, 0,
m_keys[ m_bindingscache.up ],
0 );
return true;
}
else if( Key == m_bindingscache.down ) {
m_keys[ Key ] = Action;
m_relay.post(
( m_shift ?
user_command::movedownfast :
user_command::movedown ),
0, 0,
m_keys[ m_bindingscache.down ],
0 );
return true;
}
}
else {
// if it's not the movement keys but one of shift keys, we might potentially need to update movement state
if( m_keys[ Key ] == Action ) {
// but not if it's just repeat
return false;
}
// bit of recursion voodoo here, we fake relevant key presses so we don't have to duplicate the code from above
if( m_keys[ m_bindingscache.forward ] != GLFW_RELEASE ) { update_movement( m_bindingscache.forward, m_keys[ m_bindingscache.forward ] ); }
if( m_keys[ m_bindingscache.back ] != GLFW_RELEASE ) { update_movement( m_bindingscache.back, m_keys[ m_bindingscache.back ] ); }
if( m_keys[ m_bindingscache.left ] != GLFW_RELEASE ) { update_movement( m_bindingscache.left, m_keys[ m_bindingscache.left ] ); }
if( m_keys[ m_bindingscache.right ] != GLFW_RELEASE ) { update_movement( m_bindingscache.right, m_keys[ m_bindingscache.right ] ); }
if( m_keys[ m_bindingscache.up ] != GLFW_RELEASE ) { update_movement( m_bindingscache.up, m_keys[ m_bindingscache.up ] ); }
if( m_keys[ m_bindingscache.down ] != GLFW_RELEASE ) { update_movement( m_bindingscache.down, m_keys[ m_bindingscache.down ] ); }
}
return false;
}
//---------------------------------------------------------------------------

View File

@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include <unordered_map>
#include <array>
#include "command.h"
class keyboard_input {
@@ -44,11 +45,23 @@ private:
typedef std::vector<command_setup> commandsetup_sequence;
typedef std::unordered_map<int, user_command> usercommand_map;
struct bindings_cache {
int forward{ -1 };
int back{ -1 };
int left{ -1 };
int right{ -1 };
int up{ -1 };
int down{ -1 };
};
// methods
void
default_bindings();
void
bind();
bool
update_movement( int const Key, int const Action );
// members
commandsetup_sequence m_commands;
@@ -56,6 +69,8 @@ private:
command_relay m_relay;
bool m_shift{ false };
bool m_ctrl{ false };
bindings_cache m_bindingscache;
std::array<char, GLFW_KEY_LAST> m_keys;
};
//---------------------------------------------------------------------------

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>..\..\Projects\maszyna</LocalDebuggerWorkingDirectory>
<LocalDebuggerWorkingDirectory>..\..\..\development\maszyna</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -9,11 +9,11 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\..\Projects\maszyna</LocalDebuggerWorkingDirectory>
<LocalDebuggerWorkingDirectory>..\..\..\development\maszyna</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>..\..\Projects\maszyna</LocalDebuggerWorkingDirectory>
<LocalDebuggerWorkingDirectory>..\..\..\development\maszyna</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerEnvironment>_NO_DEBUG_HEAP=1</LocalDebuggerEnvironment>
</PropertyGroup>
@@ -23,7 +23,7 @@
<LocalDebuggerEnvironment>_NO_DEBUG_HEAP=1</LocalDebuggerEnvironment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>..\..\Projects\maszyna</LocalDebuggerWorkingDirectory>
<LocalDebuggerWorkingDirectory>..\..\..\development\maszyna</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerEnvironment>_NO_DEBUG_HEAP=1</LocalDebuggerEnvironment>
</PropertyGroup>