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

audio subsystem: completed base functionality of the renderer, external and engine sounds moved from cab to vehicle, minor fixes to various sound-related methods

This commit is contained in:
tmj-fstate
2017-11-29 01:50:57 +01:00
parent bc43c21174
commit 3afff7c3ab
27 changed files with 2488 additions and 1929 deletions

View File

@@ -197,14 +197,15 @@ static int const s_SHPebrake = 64; //hamuje
static int const s_CAtest = 128;
/*dzwieki*/
static int const sound_none = 0;
static int const sound_loud = 1;
static int const sound_couplerstretch = 2;
static int const sound_bufferclamp = 4;
static int const sound_bufferbump = 8;
static int const sound_relay = 16;
static int const sound_manyrelay = 32;
static int const sound_brakeacc = 64;
enum sound {
none,
loud = 0x1,
couplerstretch = 0x2,
bufferclash = 0x4,
relay = 0x10,
parallel = 0x20,
pneumatic = 0x40
};
//szczególne typy pojazdów (inna obsługa) dla zmiennej TrainType
//zamienione na flagi bitowe, aby szybko wybierać grupę (np. EZT+SZT)
@@ -602,6 +603,8 @@ struct TCoupling {
power_coupling power_high;
power_coupling power_low; // TODO: implement this
int sounds { 0 }; // sounds emitted by the coupling devices
};
class TMoverParameters
@@ -1167,6 +1170,7 @@ public:
bool DoorLeft(bool State); //obsluga drzwi lewych
bool DoorRight(bool State); //obsluga drzwi prawych
bool DoorBlockedFlag(void); //sprawdzenie blokady drzwi
bool signal_departure( bool const State, int const Notify = range::consist ); // toggles departure warning
/* funkcje dla samochodow*/
bool ChangeOffsetH(double DeltaOffset);

View File

@@ -1369,11 +1369,11 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap
if (EngineType == ElectricSeriesMotor)
if (AutoRelayCheck())
SetFlag(SoundFlag, sound_relay);
SetFlag(SoundFlag, sound::relay);
if (EngineType == DieselEngine)
if (dizel_Update(dt))
SetFlag(SoundFlag, sound_relay);
SetFlag(SoundFlag, sound::relay);
// uklady hamulcowe:
if (VeselVolume > 0)
Compressor = CompressedVolume / VeselVolume;
@@ -1530,7 +1530,7 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape &Shape
if (EngineType == DieselEngine)
if (dizel_Update(dt))
SetFlag(SoundFlag, sound_relay);
SetFlag(SoundFlag, sound::relay);
// uklady hamulcowe:
if (VeselVolume > 0)
Compressor = CompressedVolume / VeselVolume;
@@ -1703,7 +1703,7 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
if( RList[ MainCtrlPos ].Bn > 1 ) {
if( true == MaxCurrentSwitch( false )) {
// wylaczanie wysokiego rozruchu
SetFlag( SoundFlag, sound_relay );
SetFlag( SoundFlag, sound::relay );
} // Q TODO:
// if (EngineType=ElectricSeriesMotor) and (MainCtrlPos=1)
// then
@@ -2988,6 +2988,10 @@ bool TMoverParameters::BrakeDelaySwitch(int BDS)
}
else
rBDS = false;
if( true == rBDS ) {
// if setting was changed emit the sound of pneumatic relay
SetFlag( SoundFlag, sound::pneumatic );
}
return rBDS;
}
@@ -3086,8 +3090,8 @@ void TMoverParameters::CompressorCheck(double dt)
else
{
CompressedVolume = CompressedVolume * 0.8;
SetFlag(SoundFlag, sound_relay | sound_loud);
// SetFlag(SoundFlag, sound_loud);
SetFlag(SoundFlag, sound::relay | sound::loud);
// SetFlag(SoundFlag, sound::loud);
}
}
}
@@ -4078,6 +4082,31 @@ double TMoverParameters::CouplerForce(int CouplerN, double dt)
// tempdist:=tempdist+CoupleDist; //ABu: proby szybkiego naprawienia bledu
}
dV = V - (double)DirPatch( CouplerN, CNext ) * Couplers[ CouplerN ].Connected->V;
absdV = abs( dV );
// potentially generate sounds on clash or stretch
if( ( newdist < 0.0 )
&& ( Couplers[ CouplerN ].Dist > newdist )
&& ( dV < -0.5 ) ) {
// 090503: dzwieki pracy zderzakow
SetFlag(
Couplers[ CouplerN ].sounds,
( absdV > 5.0 ?
( sound::bufferclash | sound::loud ) :
sound::bufferclash ) );
}
else if( ( Couplers[ CouplerN ].CouplingFlag != coupling::faux )
&& ( newdist > 0.001 )
&& ( Couplers[ CouplerN ].Dist <= 0.001 )
&& ( absdV > 0.005 ) ) {
// 090503: dzwieki pracy sprzegu
SetFlag(
Couplers[ CouplerN ].sounds,
( absdV > 0.1 ?
( sound::couplerstretch | sound::loud ) :
sound::couplerstretch ) );
}
// blablabla
// ABu: proby znalezienia problemu ze zle odbijajacymi sie skladami
//if (Couplers[CouplerN].CouplingFlag=ctrain_virtual) and (newdist>0) then
@@ -4099,23 +4128,6 @@ double TMoverParameters::CouplerForce(int CouplerN, double dt)
Couplers[CouplerN].Connected->Couplers[CNext].FmaxB) *
CouplerTune / 2.0;
}
dV = V - (double)DirPatch(CouplerN, CNext) * Couplers[CouplerN].Connected->V;
absdV = abs(dV);
if ((newdist < -0.001) && (Couplers[CouplerN].Dist >= -0.001) &&
(absdV > 0.010)) // 090503: dzwieki pracy zderzakow
{
if (SetFlag(SoundFlag, sound_bufferclamp))
if (absdV > 0.5)
SetFlag(SoundFlag, sound_loud);
}
else if ((newdist > 0.002) && (Couplers[CouplerN].Dist <= 0.002) &&
(absdV > 0.005)) // 090503: dzwieki pracy sprzegu
{
if (Couplers[CouplerN].CouplingFlag > 0)
if (SetFlag(SoundFlag, sound_couplerstretch))
if (absdV > 0.1)
SetFlag(SoundFlag, sound_loud);
}
distDelta =
abs(newdist) - abs(Couplers[CouplerN].Dist); // McZapkie-191103: poprawka na histereze
Couplers[CouplerN].Dist = newdist;
@@ -4919,7 +4931,7 @@ bool TMoverParameters::FuseOn(void)
{
FuseFlag = false; // wlaczenie ponowne obwodu
FO = true;
SetFlag(SoundFlag, sound_relay | sound_loud);
SetFlag(SoundFlag, sound::relay | sound::loud);
}
}
return FO;
@@ -4935,7 +4947,7 @@ void TMoverParameters::FuseOff(void)
{
FuseFlag = true;
EventFlag = true;
SetFlag(SoundFlag, sound_relay | sound_loud);
SetFlag(SoundFlag, sound::relay | sound::loud);
}
}
@@ -5206,7 +5218,7 @@ bool TMoverParameters::AutoRelayCheck(void)
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// szybkie wchodzenie na bezoporowa (303E)
OK = true;
SetFlag(SoundFlag, sound_manyrelay | sound_loud);
SetFlag(SoundFlag, sound::parallel | sound::loud);
}
else if ((LastRelayTime > CtrlDelay) && (ARFASI))
{
@@ -5240,13 +5252,13 @@ bool TMoverParameters::AutoRelayCheck(void)
if ((RList[MainCtrlActualPos].R == 0) &&
(!(MainCtrlActualPos == MainCtrlPosNo))) // wejscie na bezoporowa
{
SetFlag(SoundFlag, sound_manyrelay | sound_loud);
SetFlag(SoundFlag, sound::parallel | sound::loud);
}
else if ((RList[MainCtrlActualPos].R > 0) &&
(RList[MainCtrlActualPos - 1].R ==
0)) // wejscie na drugi uklad
{
SetFlag(SoundFlag, sound_manyrelay);
SetFlag(SoundFlag, sound::parallel);
}
}
}
@@ -5259,7 +5271,7 @@ bool TMoverParameters::AutoRelayCheck(void)
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// szybkie wchodzenie na bezoporowa (303E)
OK = true;
SetFlag(SoundFlag, sound_manyrelay);
SetFlag(SoundFlag, sound::parallel);
}
else if (LastRelayTime > CtrlDownDelay)
{
@@ -5272,7 +5284,7 @@ bool TMoverParameters::AutoRelayCheck(void)
if (RList[MainCtrlActualPos].R ==
0) // dzwieki schodzenia z bezoporowej}
{
SetFlag(SoundFlag, sound_manyrelay);
SetFlag(SoundFlag, sound::parallel);
}
}
}
@@ -5304,7 +5316,7 @@ bool TMoverParameters::AutoRelayCheck(void)
StLinFlag = true; // ybARC - zalaczenie stycznikow liniowych
MainCtrlActualPos = 1;
DelayCtrlFlag = false;
SetFlag(SoundFlag, sound_relay | sound_loud);
SetFlag(SoundFlag, sound::relay | sound::loud);
OK = true;
}
}
@@ -5858,6 +5870,32 @@ bool TMoverParameters::DoorRight(bool State)
return DR;
}
// toggles departure warning
bool
TMoverParameters::signal_departure( bool const State, int const Notify ) {
if( DepartureSignal == State ) {
// TBD: should the command be passed to other vehicles regardless of whether it affected the primary target?
return false;
}
DepartureSignal = State;
if( Notify != range::local ) {
// wysłanie wyłączenia do pozostałych?
SendCtrlToNext(
"DepartureSignal",
( State == true ?
1 :
0 ),
CabNo,
( Notify == range::unit ?
ctrain_controll | ctrain_depot :
ctrain_controll ) );
}
return true;
}
// *************************************************************************************************
// Q: 20160713
// Przesuwa pojazd o podaną wartość w bok względem toru (dla samochodów)
@@ -8227,6 +8265,13 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
}
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if( Command == "DepartureSignal" ) {
DepartureSignal = (
CValue1 == 1 ?
true :
false );
OK = SendCtrlToNext( Command, CValue1, CValue2, Couplertype );
}
else if (Command == "PantFront") /*Winger 160204*/
{ // Ra: uwzględnić trzeba jeszcze zgodność sprzęgów
// Czemu EZT ma być traktowane inaczej? Ukrotnienie ma, a człon może być odwrócony
@@ -8346,6 +8391,8 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
if( true == Hamulec->SetBDF( brakesetting ) ) {
BrakeDelayFlag = brakesetting;
OK = true;
// if setting was changed emit the sound of pneumatic relay
SetFlag( SoundFlag, sound::pneumatic );
}
else {
OK = false;

View File

@@ -578,47 +578,58 @@ void TESt::CheckReleaser( double const dt )
}
}
void TESt::CheckState( double const BCP, double &dV1 )
{
double VVP;
double BVP;
double CVP;
void TESt::CheckState( double const BCP, double &dV1 ) {
BVP = BrakeRes->P();
VVP = ValveRes->P();
// if (BVP<VVP) then
// VVP:=(BVP+VVP)/2;
CVP = CntrlRes->P() - 0.0;
double const VVP { ValveRes->P() };
double const BVP { BrakeRes->P() };
double const CVP { CntrlRes->P() };
// sprawdzanie stanu
if (((BrakeStatus & b_hld) == b_hld) && (BCP > 0.25))
if ((VVP + 0.003 + BCP / BVM < CVP))
BrakeStatus |= b_on; // hamowanie stopniowe
else if ((VVP - 0.003 + (BCP - 0.1) / BVM > CVP))
BrakeStatus &= ~( b_on | b_hld ); // luzowanie
else if ((VVP + BCP / BVM > CVP))
BrakeStatus &= ~b_on; // zatrzymanie napelaniania
else
;
else if ((VVP + 0.10 < CVP) && (BCP < 0.25)) // poczatek hamowania
{
if ((BrakeStatus & b_hld) == b_off)
{
ValveRes->CreatePress(0.02 * VVP);
SoundFlag |= sf_Acc;
ValveRes->Act();
if( BCP > 0.25 ) {
if( ( BrakeStatus & b_hld ) == b_hld ) {
if( ( VVP + 0.003 + BCP / BVM ) < CVP ) {
// hamowanie stopniowe
BrakeStatus |= b_on;
}
else {
if( ( VVP + BCP / BVM ) > CVP ) {
// zatrzymanie napelaniania
BrakeStatus &= ~b_on;
}
if( ( VVP - 0.003 + ( BCP - 0.1 ) / BVM ) > CVP ) {
// luzowanie
BrakeStatus &= ~( b_on | b_hld );
}
}
}
BrakeStatus |= (b_on | b_hld);
else {
// ValveRes.CreatePress(0);
// dV1:=1;
if( ( VVP + BCP / BVM < CVP )
&& ( ( CVP - VVP ) * BVM > 0.25 ) ) {
// zatrzymanie luzowanie
BrakeStatus |= b_hld;
}
}
}
else if ((VVP + (BCP - 0.1) / BVM < CVP) && ((CVP - VVP) * BVM > 0.25) &&
(BCP > 0.25)) // zatrzymanie luzowanie
BrakeStatus |= b_hld;
else {
if ((BrakeStatus & b_hld) == b_off)
if( VVP + 0.1 < CVP ) {
// poczatek hamowania
if( ( BrakeStatus & b_hld ) == 0 ) {
// przyspieszacz
ValveRes->CreatePress( 0.02 * VVP );
SoundFlag |= sf_Acc;
ValveRes->Act();
}
BrakeStatus |= ( b_on | b_hld );
}
}
if( ( BrakeStatus & b_hld ) == 0 ) {
SoundFlag |= sf_CylU;
}
}
double TESt::CVs( double const BP )
@@ -828,6 +839,10 @@ double TEStEP2::GetPF( double const PP, double const dt, double const Vel )
else if ((VVP + BCP / BVM < CVP - 0.12) && (BCP > 0.25)) // zatrzymanie luzowanie
BrakeStatus |= b_hld;
if( ( BrakeStatus & b_hld ) == 0 ) {
SoundFlag |= sf_CylU;
}
// przeplyw ZS <-> PG
if ((BVP < CVP - 0.2) || (BrakeStatus != b_off) || (BCP > 0.25))
temp = 0;
@@ -1211,6 +1226,40 @@ double TLSt::GetPF( double const PP, double const dt, double const Vel )
double dV1{ 0.0 };
// sprawdzanie stanu
// NOTE: partial copypaste from checkstate() of base class
// TODO: clean inheritance for checkstate() and checkreleaser() and reuse these instead of manual copypaste
if( ( ( BrakeStatus & b_hld ) == b_hld ) && ( BCP > 0.25 ) ) {
if( ( VVP + 0.003 + BCP / BVM < CVP ) ) {
// hamowanie stopniowe
BrakeStatus |= b_on;
}
else if( ( VVP - 0.003 + ( BCP - 0.1 ) / BVM > CVP ) ) {
// luzowanie
BrakeStatus &= ~( b_on | b_hld );
}
else if( ( VVP + BCP / BVM > CVP ) ) {
// zatrzymanie napelaniania
BrakeStatus &= ~b_on;
}
}
else if ((VVP + 0.10 < CVP) && (BCP < 0.25)) {
// poczatek hamowania
if ((BrakeStatus & b_hld) == b_off)
{
SoundFlag |= sf_Acc;
}
BrakeStatus |= (b_on | b_hld);
}
else if( ( VVP + ( BCP - 0.1 ) / BVM < CVP )
&& ( ( CVP - VVP ) * BVM > 0.25 )
&& ( BCP > 0.25 ) ) {
// zatrzymanie luzowanie
BrakeStatus |= b_hld;
}
if( ( BrakeStatus & b_hld ) == 0 ) {
SoundFlag |= sf_CylU;
}
// equivalent of checkreleaser() in the base class?
if( ( BrakeStatus & b_rls ) == b_rls ) {
if( CVP < 0.0 ) {
BrakeStatus &= ~b_rls;
@@ -1219,18 +1268,11 @@ double TLSt::GetPF( double const PP, double const dt, double const Vel )
{ // 008
dV = PF1( CVP, BCP, 0.024 ) * dt;
CntrlRes->Flow( dV );
/*
// NOTE: attempted fix, disabled because it breaks when releaser is used while releasing breakes
dV = PF1(CVP, VVP, 0.024) * dt;
CntrlRes->Flow( dV );
dV1 = dV; //minus potem jest
ImplsRes->Flow( -dV1 );
*/
}
}
double temp;
// przeplyw ZS <-> PG
double temp;
if (((CVP - BCP) * BVM > 0.5))
temp = 0.0;
else if ((VVP > CVP + 0.4))
@@ -1888,22 +1930,51 @@ void TKE::CheckState( double const BCP, double &dV1 )
CVP = CntrlRes->P();
// sprawdzanie stanu
if ((BrakeStatus & b_hld) == b_hld)
if ((VVP + 0.003 + BCP / BVM < CVP))
BrakeStatus |= b_on; // hamowanie stopniowe;
else if ((VVP - 0.003 + BCP / BVM > CVP))
BrakeStatus &= ~( b_on | b_hld ); // luzowanie;
else if ((VVP + BCP / BVM > CVP))
BrakeStatus &= ~b_on; // zatrzymanie napelaniania;
else
;
else if ((VVP + 0.10 < CVP) && (BCP < 0.1)) // poczatek hamowania
{
BrakeStatus |= (b_on | b_hld);
ValveRes->CreatePress(0.8 * VVP); // przyspieszacz
if( BCP > 0.1 ) {
if( ( BrakeStatus & b_hld ) == b_hld ) {
if( ( VVP + 0.003 + BCP / BVM ) < CVP ) {
// hamowanie stopniowe;
BrakeStatus |= b_on;
}
else {
if( ( VVP + BCP / BVM ) > CVP ) {
// zatrzymanie napelaniania;
BrakeStatus &= ~b_on;
}
if( ( VVP - 0.003 + BCP / BVM ) > CVP ) {
// luzowanie;
BrakeStatus &= ~( b_on | b_hld );
}
}
}
else {
if( ( VVP + BCP / BVM < CVP )
&& ( ( CVP - VVP ) * BVM > 0.25 ) ) {
// zatrzymanie luzowanie
BrakeStatus |= b_hld;
}
}
}
else {
if( VVP + 0.1 < CVP ) {
// poczatek hamowania
if( ( BrakeStatus & b_hld ) == 0 ) {
// przyspieszacz
ValveRes->CreatePress( 0.8 * VVP );
SoundFlag |= sf_Acc;
ValveRes->Act();
}
BrakeStatus |= ( b_on | b_hld );
}
}
if( ( BrakeStatus & b_hld ) == 0 ) {
SoundFlag |= sf_CylU;
}
else if ((VVP + BCP / BVM < CVP) && ((CVP - VVP) * BVM > 0.25)) // zatrzymanie luzowanie
BrakeStatus |= b_hld;
}
double TKE::CVs( double const BP )