unified simulation sound sources, gfx namespace for gfx code and structures

This commit is contained in:
tmj-fstate
2017-11-12 00:23:21 +01:00
parent 492c1342b1
commit 5226fca281
36 changed files with 1487 additions and 1433 deletions

View File

@@ -46,10 +46,7 @@ void TButton::Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2) {
else {
// new, block type config
// TODO: rework the base part into yaml-compatible flow style mapping
cParser mappingparser( Parser.getToken<std::string>( false, "}" ) );
submodelname = mappingparser.getToken<std::string>( false );
// new, variable length section
while( true == Load_mapping( mappingparser ) ) {
while( true == Load_mapping( Parser ) ) {
; // all work done by while()
}
}
@@ -77,27 +74,13 @@ void TButton::Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2) {
bool
TButton::Load_mapping( cParser &Input ) {
if( false == Input.getTokens( 2, true, " ,\n\r\t" ) ) {
return false;
}
// token can be a key or block end
std::string const key { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
if( key == "}" ) { return false; }
// if not block end then the key is followed by assigned value or sub-block
if( key == "soundinc:" ) { m_soundfxincrease.deserialize( Input, sound_type::single ); }
else if( key == "sounddec:" ) { m_soundfxdecrease.deserialize( Input, sound_type::single ); }
std::string key, value;
Input
>> key
>> value;
if( key == "soundinc:" ) {
m_soundfxincrease = (
value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr );
}
else if( key == "sounddec:" ) {
m_soundfxdecrease = (
value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr );
}
return true; // return value marks a key: value pair was extracted, nothing about whether it's recognized
}
@@ -141,19 +124,6 @@ void TButton::AssignBool(bool const *bValue) {
void
TButton::play() {
play(
m_state == true ?
m_soundfxincrease :
m_soundfxdecrease );
}
void
TButton::play( PSound Sound ) {
if( Sound == nullptr ) { return; }
Sound->SetCurrentPosition( 0 );
Sound->SetVolume( DSBVOLUME_MAX );
Sound->Play( 0, 0, 0 );
return;
if( m_state == true ) { m_soundfxincrease.play(); }
else { m_soundfxdecrease.play(); }
}

View File

@@ -22,8 +22,8 @@ class TButton
bool m_state { false };
bool const *bData { nullptr };
int iFeedbackBit { 0 }; // Ra: bit informacji zwrotnej, do wyprowadzenia na pulpit
PSound m_soundfxincrease { nullptr }; // sound associated with increasing control's value
PSound m_soundfxdecrease { nullptr }; // sound associated with decreasing control's value
sound_source m_soundfxincrease; // sound associated with increasing control's value
sound_source m_soundfxdecrease; // sound associated with decreasing control's value
// methods
// imports member data pair from the config file
bool
@@ -31,10 +31,6 @@ class TButton
// plays the sound associated with current state
void
play();
// plays specified sound
static
void
play( PSound Sound );
public:
TButton() = default;
@@ -42,14 +38,10 @@ class TButton
inline void FeedbackBitSet(int const i) {
iFeedbackBit = 1 << i; };
void Turn( bool const State );
inline void TurnOn() {
Turn( true ); };
inline void TurnOff() {
Turn( false ); };
inline void Switch() {
Turn( !m_state ); };
inline bool Active() {
return (pModelOn) || (pModelOff); };
inline
bool Active() {
return ( ( pModelOn != nullptr )
|| ( pModelOff != nullptr ) ); }
void Update();
void Init(std::string const &asName, TModel3d *pModel, bool bNewOn = false);
void Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2 = NULL);

View File

@@ -23,8 +23,12 @@ class TModel3d; //siatka modelu wspólna dla egzemplarzy
class TSubModel; // fragment modelu (tu do wyświetlania terenu)
class TMemCell; // komórka pamięci
class cParser;
#ifdef EU07_USE_OLD_SOUNDCODE
class TRealSound; // dźwięk ze współrzędnymi XYZ
class TTextSound; // dźwięk ze stenogramem
#else
class sound_source;
#endif
class TEventLauncher;
class TTraction; // drut
class TTractionPowerSource; // zasilanie drutów

View File

@@ -998,7 +998,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
if (go == cm_Unknown) // jeśli nie było komendy wcześniej
go = cm_Ready; // gotów do odjazdu z W4 (semafor może
// zatrzymać)
if (tsGuardSignal) // jeśli mamy głos kierownika, to odegrać
if (false == tsGuardSignal->empty()) // jeśli mamy głos kierownika, to odegrać
iDrivigFlags |= moveGuardSignal;
continue; // nie analizować prędkości
} // koniec startu z zatrzymania
@@ -2572,9 +2572,12 @@ bool TController::DecBrake()
bool TController::IncSpeed()
{ // zwiększenie prędkości; zwraca false, jeśli dalej się nie da zwiększać
#ifdef EU07_USE_OLD_SOUNDCODE
if (tsGuardSignal) // jeśli jest dźwięk kierownika
if (tsGuardSignal->GetStatus() & DSBSTATUS_PLAYING) // jeśli gada, to nie jedziemy
return false;
#else
#endif
bool OK = true;
if( ( iDrivigFlags & moveDoorOpened )
&& ( VelDesired > 0.0 ) ) { // to prevent door shuffle on stop
@@ -3084,10 +3087,14 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
NewCommand = Global::asCurrentSceneryPath + NewCommand + ".wav"; // na razie jeden
if (FileExists(NewCommand))
{ // wczytanie dźwięku odjazdu podawanego bezpośrenido
tsGuardSignal = new TTextSound(NewCommand, 30, pVehicle->GetPosition().x,
pVehicle->GetPosition().y, pVehicle->GetPosition().z,
false);
// rsGuardSignal->Stop();
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal =
new TTextSound(
NewCommand, 30,
pVehicle->GetPosition().x, pVehicle->GetPosition().y, pVehicle->GetPosition().z,
false);
#else
#endif
iGuardRadio = 0; // nie przez radio
}
else
@@ -3095,9 +3102,14 @@ bool TController::PutCommand( std::string NewCommand, double NewValue1, double N
NewCommand = NewCommand.insert(NewCommand.find_last_of("."),"radio"); // wstawienie przed kropkč
if (FileExists(NewCommand))
{ // wczytanie dźwięku odjazdu w wersji radiowej (słychać tylko w kabinie)
tsGuardSignal = new TTextSound(NewCommand, -1, pVehicle->GetPosition().x,
pVehicle->GetPosition().y, pVehicle->GetPosition().z,
false);
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal =
new TTextSound(
NewCommand, -1,
pVehicle->GetPosition().x, pVehicle->GetPosition().y, pVehicle->GetPosition().z,
false);
#else
#endif
iGuardRadio = iRadioChannel;
}
}
@@ -4472,7 +4484,10 @@ TController::UpdateSituation(double dt) {
->DoorOpenCtrl ) // jeśli drzwi niesterowane przez maszynistę
Doors( false ); // a EZT zamknie dopiero po odegraniu komunikatu kierownika
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal->Stop();
#else
#endif
// w zasadzie to powinien mieć flagę, czy jest dźwiękiem radiowym, czy
// bezpośrednim
// albo trzeba zrobić dwa dźwięki, jeden bezpośredni, słyszalny w
@@ -4481,7 +4496,10 @@ TController::UpdateSituation(double dt) {
// obsługę kanałów radiowych itd.
if( !iGuardRadio ) {
// jeśli nie przez radio
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal->Play( 1.0, 0, !FreeFlyModeFlag, pVehicle->GetPosition() ); // dla true jest głośniej
#else
#endif
}
else {
// if (iGuardRadio==iRadioChannel) //zgodność kanału
@@ -4490,7 +4508,10 @@ TController::UpdateSituation(double dt) {
// przy braku reakcji
if( SquareMagnitude( pVehicle->GetPosition() - Global::pCameraPosition ) < 2000 * 2000 ) {
// w odległości mniejszej niż 2km
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal->Play( 1.0, 0, true, pVehicle->GetPosition() ); // dźwięk niby przez radio
#else
#endif
}
}
}

View File

@@ -242,7 +242,10 @@ private:
TTrainParameters *TrainParams = nullptr; // rozkład jazdy zawsze jest, nawet jeśli pusty
int iRadioChannel = 1; // numer aktualnego kanału radiowego
int iGuardRadio = 0; // numer kanału radiowego kierownika (0, gdy nie używa radia)
/*
TTextSound *tsGuardSignal = nullptr; // komunikat od kierownika
*/
sound_source *tsGuardSignal { nullptr };
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

@@ -612,14 +612,14 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
if ((TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_coupler)) &&
(MoverParameters->Couplers[0].Render))
{
btCoupler1.TurnOn();
btCoupler1.Turn( true );
btnOn = true;
}
// else btCoupler1.TurnOff();
if ((TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_coupler)) &&
(MoverParameters->Couplers[1].Render))
{
btCoupler2.TurnOn();
btCoupler2.Turn( true );
btnOn = true;
}
// else btCoupler2.TurnOff();
@@ -820,26 +820,26 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
// przewody sterowania ukrotnionego
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_controll))
{
btCCtrl1.TurnOn();
btCCtrl1.Turn( true );
btnOn = true;
}
// else btCCtrl1.TurnOff();
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_controll))
{
btCCtrl2.TurnOn();
btCCtrl2.Turn( true );
btnOn = true;
}
// else btCCtrl2.TurnOff();
// McZapkie-181103: mostki przejsciowe
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_passenger))
{
btCPass1.TurnOn();
btCPass1.Turn( true );
btnOn = true;
}
// else btCPass1.TurnOff();
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_passenger))
{
btCPass2.TurnOn();
btCPass2.Turn( true );
btnOn = true;
}
// else btCPass2.TurnOff();
@@ -849,7 +849,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{
if (TestFlag(iLights[0], 2) || TestFlag(iLights[0], 32))
{
btEndSignals1.TurnOn();
btEndSignals1.Turn( true );
btnOn = true;
}
// else btEndSignals1.TurnOff();
@@ -858,13 +858,13 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{
if (TestFlag(iLights[0], 2))
{
btEndSignals11.TurnOn();
btEndSignals11.Turn( true );
btnOn = true;
}
// else btEndSignals11.TurnOff();
if (TestFlag(iLights[0], 32))
{
btEndSignals13.TurnOn();
btEndSignals13.Turn( true );
btnOn = true;
}
// else btEndSignals13.TurnOff();
@@ -873,7 +873,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{
if (TestFlag(iLights[1], 2) || TestFlag(iLights[1], 32))
{
btEndSignals2.TurnOn();
btEndSignals2.Turn( true );
btnOn = true;
}
// else btEndSignals2.TurnOff();
@@ -882,28 +882,28 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{
if (TestFlag(iLights[1], 2))
{
btEndSignals21.TurnOn();
btEndSignals21.Turn( true );
btnOn = true;
}
// else btEndSignals21.TurnOff();
if (TestFlag(iLights[1], 32))
{
btEndSignals23.TurnOn();
btEndSignals23.Turn( true );
btnOn = true;
}
// else btEndSignals23.TurnOff();
}
}
// tablice blaszane:
if (TestFlag(iLights[0], 64))
if (TestFlag(iLights[side::front], light::rearendsignals))
{
btEndSignalsTab1.TurnOn();
btEndSignalsTab1.Turn( true );
btnOn = true;
}
// else btEndSignalsTab1.TurnOff();
if (TestFlag(iLights[1], 64))
if (TestFlag(iLights[side::rear], light::rearendsignals))
{
btEndSignalsTab2.TurnOn();
btEndSignalsTab2.Turn( true );
btnOn = true;
}
// else btEndSignalsTab2.TurnOff();
@@ -914,36 +914,17 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
smWahacze[i]->SetRotate(float3(1, 0, 0),
fWahaczeAmp * cos(MoverParameters->eAngle));
if (Mechanik)
{ // rysowanie figurki mechanika
/*
if (smMechanik0) // mechanik od strony sprzęgu 0
if (smMechanik1) // jak jest drugi, to pierwszego jedynie pokazujemy
smMechanik0->iVisible = MoverParameters->ActiveCab > 0;
else
{ // jak jest tylko jeden, to do drugiej kabiny go obracamy
smMechanik0->iVisible = (MoverParameters->ActiveCab != 0);
smMechanik0->SetRotate(
float3(0, 0, 1),
MoverParameters->ActiveCab >= 0 ? 0 : 180); // obrót względem osi Z
}
if (smMechanik1) // mechanik od strony sprzęgu 1
smMechanik1->iVisible = MoverParameters->ActiveCab < 0;
*/
if (MoverParameters->ActiveCab > 0)
{
btMechanik1.TurnOn();
btnOn = true;
}
if (MoverParameters->ActiveCab < 0)
{
btMechanik2.TurnOn();
btnOn = true;
}
if (Mechanik) {
// rysowanie figurki mechanika
if( MoverParameters->ActiveCab > 0 ) {
btMechanik1.Turn( true );
btnOn = true;
}
if( MoverParameters->ActiveCab < 0 ) {
btMechanik2.Turn( true );
btnOn = true;
}
}
// ABu: Przechyly na zakretach
// Ra: przechyłkę załatwiamy na etapie przesuwania modelu
// if (ObjSqrDist<80000) ABuModelRoll(); //przechyłki od 400m
}
if( MoverParameters->Battery || MoverParameters->ConverterFlag )
{ // sygnały czoła pociagu //Ra: wyświetlamy bez
@@ -951,37 +932,37 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
// daleka
if (TestFlag(iLights[0], 1))
{
btHeadSignals11.TurnOn();
btHeadSignals11.Turn( true );
btnOn = true;
}
// else btHeadSignals11.TurnOff();
if (TestFlag(iLights[0], 4))
{
btHeadSignals12.TurnOn();
btHeadSignals12.Turn( true );
btnOn = true;
}
// else btHeadSignals12.TurnOff();
if (TestFlag(iLights[0], 16))
{
btHeadSignals13.TurnOn();
btHeadSignals13.Turn( true );
btnOn = true;
}
// else btHeadSignals13.TurnOff();
if (TestFlag(iLights[1], 1))
{
btHeadSignals21.TurnOn();
btHeadSignals21.Turn( true );
btnOn = true;
}
// else btHeadSignals21.TurnOff();
if (TestFlag(iLights[1], 4))
{
btHeadSignals22.TurnOn();
btHeadSignals22.Turn( true );
btnOn = true;
}
// else btHeadSignals22.TurnOff();
if (TestFlag(iLights[1], 16))
{
btHeadSignals23.TurnOn();
btHeadSignals23.Turn( true );
btnOn = true;
}
// else btHeadSignals23.TurnOff();
@@ -2926,12 +2907,13 @@ bool TDynamicObject::Update(double dt, double dt1)
}
Global::ABuDebug = dDOMoveLen / dt1;
ResetdMoveLen();
#ifdef EU07_USE_OLD_SOUNDCODE
// McZapkie-260202
// tupot mew, tfu, stukot kol:
// taka prowizorka zeby sciszyc stukot dalekiej lokomotywy
double ObjectDist;
double vol = 0;
// double freq; //Ra: nie używane
ObjectDist = SquareMagnitude(Global::pCameraPosition - vPosition);
// McZapkie-270202
if (MyTrack->fSoundDistance != -1)
@@ -2979,8 +2961,7 @@ bool TDynamicObject::Update(double dt, double dt1)
{
rsStukot[i + 1].Stop();
}
rsStukot[i].Play(vol, 0, MechInside,
vPosition); // poprawic pozycje o uklad osi
rsStukot[i].Play(vol, 0, MechInside, vPosition); // poprawic pozycje o uklad osi
if (i == 1)
MoverParameters->AccV -=
0.5 * GetVelocity() / (1 + MoverParameters->Vmax);
@@ -3018,7 +2999,7 @@ bool TDynamicObject::Update(double dt, double dt1)
else
rsUnbrake.Stop();
}
#endif
// fragment z EXE Kursa
/* if (MoverParameters->TrainType==dt_ET42)
{
@@ -3128,13 +3109,16 @@ bool TDynamicObject::Update(double dt, double dt1)
else if( ( true == MoverParameters->PantFrontUp )
&& ( PantDiff < 0.01 ) ) // tolerancja niedolegania
{
if ((MoverParameters->PantFrontVolt == 0.0) &&
(MoverParameters->PantRearVolt == 0.0))
sPantUp.Play(vol, 0, MechInside, vPosition);
if (p->hvPowerWire) // TODO: wyliczyć trzeba prąd przypadający na
// pantograf i
// wstawić do GetVoltage()
{
if( ( MoverParameters->PantFrontVolt == 0.0 )
&& ( MoverParameters->PantRearVolt == 0.0 ) ) {
#ifdef EU07_USE_OLD_SOUNDCODE
sPantUp.Play( vol, 0, MechInside, vPosition );
#else
sPantUp.play();
#endif
}
if (p->hvPowerWire) {
// TODO: wyliczyć trzeba prąd przypadający na pantograf i wstawić do GetVoltage()
MoverParameters->PantFrontVolt =
p->hvPowerWire->VoltageGet(MoverParameters->Voltage, fPantCurrent);
fCurrent -= fPantCurrent; // taki prąd płynie przez powyższy pantograf
@@ -3159,7 +3143,11 @@ bool TDynamicObject::Update(double dt, double dt1)
{
if( ( MoverParameters->PantRearVolt == 0.0 )
&& ( MoverParameters->PantFrontVolt == 0.0 ) ) {
#ifdef EU07_USE_OLD_SOUNDCODE
sPantUp.Play( vol, 0, MechInside, vPosition );
#else
sPantUp.play();
#endif
}
if (p->hvPowerWire) {
// TODO: wyliczyć trzeba prąd przypadający na pantograf i wstawić do GetVoltage()
@@ -3246,12 +3234,20 @@ bool TDynamicObject::Update(double dt, double dt1)
} // koniec pętli po pantografach
if ((MoverParameters->PantFrontSP == false) && (MoverParameters->PantFrontUp == false))
{
#ifdef EU07_USE_OLD_SOUNDCODE
sPantDown.Play(vol, 0, MechInside, vPosition);
#else
sPantDown.play();
#endif
MoverParameters->PantFrontSP = true;
}
if ((MoverParameters->PantRearSP == false) && (MoverParameters->PantRearUp == false))
{
#ifdef EU07_USE_OLD_SOUNDCODE
sPantDown.Play(vol, 0, MechInside, vPosition);
#else
sPantDown.play();
#endif
MoverParameters->PantRearSP = true;
}
/*
@@ -3354,24 +3350,40 @@ bool TDynamicObject::Update(double dt, double dt1)
// NBMX Obsluga drzwi, MC: zuniwersalnione
if ((dDoorMoveL < MoverParameters->DoorMaxShiftL) && (MoverParameters->DoorLeftOpened))
{
rsDoorOpen.Play(1, 0, MechInside, vPosition);
#ifdef EU07_USE_OLD_SOUNDCODE
rsDoorOpen.Play(1, 0, MechInside, vPosition);
#else
rsDoorOpen.play();
#endif
dDoorMoveL += dt1 * 0.5 * MoverParameters->DoorOpenSpeed;
}
if ((dDoorMoveL > 0) && (!MoverParameters->DoorLeftOpened))
{
rsDoorClose.Play(1, 0, MechInside, vPosition);
#ifdef EU07_USE_OLD_SOUNDCODE
rsDoorClose.Play(1, 0, MechInside, vPosition);
#else
rsDoorClose.play();
#endif
dDoorMoveL -= dt1 * MoverParameters->DoorCloseSpeed;
if (dDoorMoveL < 0)
dDoorMoveL = 0;
}
if ((dDoorMoveR < MoverParameters->DoorMaxShiftR) && (MoverParameters->DoorRightOpened))
{
rsDoorOpen.Play(1, 0, MechInside, vPosition);
#ifdef EU07_USE_OLD_SOUNDCODE
rsDoorOpen.Play(1, 0, MechInside, vPosition);
#else
rsDoorOpen.play();
#endif
dDoorMoveR += dt1 * 0.5 * MoverParameters->DoorOpenSpeed;
}
if ((dDoorMoveR > 0) && (!MoverParameters->DoorRightOpened))
{
rsDoorClose.Play(1, 0, MechInside, vPosition);
#ifdef EU07_USE_OLD_SOUNDCODE
rsDoorClose.Play(1, 0, MechInside, vPosition);
#else
rsDoorClose.play();
#endif
dDoorMoveR -= dt1 * MoverParameters->DoorCloseSpeed;
if (dDoorMoveR < 0)
dDoorMoveR = 0;
@@ -3465,8 +3477,8 @@ void TDynamicObject::TurnOff()
{ // wyłączenie rysowania submodeli zmiennych dla
// egemplarza pojazdu
btnOn = false;
btCoupler1.TurnOff();
btCoupler2.TurnOff();
btCoupler1.Turn( false );
btCoupler2.Turn( false );
btCPneumatic1.TurnOff();
btCPneumatic1r.TurnOff();
btCPneumatic2.TurnOff();
@@ -3475,45 +3487,41 @@ void TDynamicObject::TurnOff()
btPneumatic1r.TurnOff();
btPneumatic2.TurnOff();
btPneumatic2r.TurnOff();
btCCtrl1.TurnOff();
btCCtrl2.TurnOff();
btCPass1.TurnOff();
btCPass2.TurnOff();
btEndSignals11.TurnOff();
btEndSignals13.TurnOff();
btEndSignals21.TurnOff();
btEndSignals23.TurnOff();
btEndSignals1.TurnOff();
btEndSignals2.TurnOff();
btEndSignalsTab1.TurnOff();
btEndSignalsTab2.TurnOff();
btHeadSignals11.TurnOff();
btHeadSignals12.TurnOff();
btHeadSignals13.TurnOff();
btHeadSignals21.TurnOff();
btHeadSignals22.TurnOff();
btHeadSignals23.TurnOff();
btMechanik1.TurnOff();
btMechanik2.TurnOff();
btCCtrl1.Turn( false );
btCCtrl2.Turn( false );
btCPass1.Turn( false );
btCPass2.Turn( false );
btEndSignals11.Turn( false );
btEndSignals13.Turn( false );
btEndSignals21.Turn( false );
btEndSignals23.Turn( false );
btEndSignals1.Turn( false );
btEndSignals2.Turn( false );
btEndSignalsTab1.Turn( false );
btEndSignalsTab2.Turn( false );
btHeadSignals11.Turn( false );
btHeadSignals12.Turn( false );
btHeadSignals13.Turn( false );
btHeadSignals21.Turn( false );
btHeadSignals22.Turn( false );
btHeadSignals23.Turn( false );
btMechanik1.Turn( false );
btMechanik2.Turn( false );
};
void TDynamicObject::RenderSounds()
{ // przeliczanie dźwięków, bo będzie słychać bez wyświetlania sektora z pojazdem
// if( Global::iPause > 0 ) { return; }
// przeliczanie dźwięków, bo będzie słychać bez wyświetlania sektora z pojazdem
void TDynamicObject::RenderSounds() {
#ifdef EU07_USE_OLD_SOUNDCODE
// McZapkie-010302: ulepszony dzwiek silnika
double freq;
double vol = 0;
double dt = Timer::GetDeltaRenderTime();
// double sounddist;
// sounddist=SquareMagnitude(Global::pCameraPosition-vPosition);
if (MoverParameters->Power > 0)
{
if ((rsSilnik.AM != 0)
&& ((MoverParameters->Mains)
// McZapkie-280503: zeby dla dumb dzialal silnik na jalowych obrotach
// McZapkie-280503: zeby dla dumb dzialal silnik na jalowych obrotach
|| (MoverParameters->EngineType == DieselEngine)))
{
if ((fabs(MoverParameters->enrot) > 0.01) ||
@@ -3521,8 +3529,7 @@ void TDynamicObject::RenderSounds()
{
freq = rsSilnik.FM * fabs(MoverParameters->enrot) + rsSilnik.FA;
if (MoverParameters->EngineType == Dumb)
freq = freq -
0.2 * MoverParameters->EnginePower / (1 + MoverParameters->Power * 1000);
freq = freq - 0.2 * MoverParameters->EnginePower / (1 + MoverParameters->Power * 1000);
rsSilnik.AdjFreq(freq, dt);
if (MoverParameters->EngineType == DieselEngine)
{
@@ -3561,24 +3568,23 @@ void TDynamicObject::RenderSounds()
if (volrnd < 2)
vol = vol + volrnd / 200.0;
}
switch (MyTrack->eEnvironment)
{
case e_tunnel:
{
vol += 0.1;
switch( MyTrack->eEnvironment ) {
case e_tunnel: {
vol += 0.1;
break;
}
case e_canyon: {
vol += 0.05;
break;
}
default: {
break;
}
}
break;
case e_canyon:
{
vol += 0.05;
}
break;
}
if ((MoverParameters->DynamicBrakeFlag) && (MoverParameters->EnginePower > 0.1) &&
(MoverParameters->EngineType ==
ElectricSeriesMotor)) // Szociu - 29012012 - jeżeli uruchomiony
// jest hamulec
// elektrodynamiczny, odtwarzany jest dźwięk silnika
if( ( MoverParameters->DynamicBrakeFlag )
&& ( MoverParameters->EnginePower > 0.1 )
&& ( MoverParameters->EngineType == ElectricSeriesMotor ) )
// Szociu - 29012012 - jeżeli uruchomiony jest hamulec elektrodynamiczny, odtwarzany jest dźwięk silnika
vol += 0.8;
if (enginevolume > 0.0001)
@@ -3693,15 +3699,6 @@ void TDynamicObject::RenderSounds()
if (MoverParameters->BrakePress < 0.1)
releaser_vol = MoverParameters->BrakePress * 10;
sReleaser.UpdateAF(releaser_vol, 1, MechInside, GetPosition());
// if ((MoverParameters->ConverterFlag==false) &&
// (MoverParameters->TrainType!=dt_ET22))
// if
// ((MoverParameters->ConverterFlag==false)&&(MoverParameters->CompressorPower!=0))
// MoverParameters->CompressorFlag=false; //Ra: wywalić to stąd, tu tylko dla
// wyświetlanych!
// Ra: no to już wiemy, dlaczego pociągi jeżdżą lepiej, gdy się na nie patrzy!
// if (MoverParameters->CompressorPower==2)
// MoverParameters->CompressorAllow=MoverParameters->ConverterFlag;
// McZapkie! - dzwiek compressor.wav tylko gdy dziala sprezarka
if (MoverParameters->VeselVolume != 0)
@@ -3851,15 +3848,7 @@ void TDynamicObject::RenderSounds()
if (GetVelocity() == 0)
rsDerailment.Stop();
}
/* //Ra: dwa razy?
if (MoverParameters->EventFlag)
{
if (TestFlag(MoverParameters->DamageFlag,dtrain_out) && GetVelocity()>0)
rsDerailment.Play(1,0,true,GetPosition());
if (GetVelocity()==0)
rsDerailment.Stop();
}
*/
#endif
};
// McZapkie-250202
@@ -4560,10 +4549,16 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
parser.getTokens();
parser >> token;
if( token != "end" ) {
rsStukot[ i ].Init( token, dSDist, GetPosition().x,
GetPosition().y + dWheelsPosition[ i ], GetPosition().z,
#ifdef EU07_USE_OLD_SOUNDCODE
rsStukot[ i ].Init(
token, dSDist,
GetPosition().x, GetPosition().y + dWheelsPosition[ i ], GetPosition().z,
true );
}
#else
rsStukot[ i ].deserialize( token + " " + std::to_string( dSDist ), sound_type::single, sound_parameters::range );
// TODO: set per-wheel offset
#endif
}
}
if( token != "end" ) {
// TODO: double-check if this if() and/or retrieval makes sense here
@@ -4574,6 +4569,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
else if( ( token == "engine:" )
&& ( MoverParameters->Power > 0 ) ) {
// plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest.
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
@@ -4585,7 +4581,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
true, true );
if( rsSilnik.GetWaveTime() == 0 ) {
ErrorLog( "Missed sound: \"" + token + "\" for " + asFileName );
}
}
parser.getTokens( 1, false );
parser >> rsSilnik.AM;
if( MoverParameters->EngineType == DieselEngine ) {
@@ -4605,13 +4601,17 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
>> rsSilnik.AA
>> rsSilnik.FM // MoverParameters->nmax;
>> rsSilnik.FA;
#else
rsSilnik.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
#endif
}
else if( ( token == "ventilator:" )
&& ( ( MoverParameters->EngineType == ElectricSeriesMotor )
|| ( MoverParameters->EngineType == ElectricInductionMotor ) ) ) {
// plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest.
double attenuation;
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
>> token
@@ -4628,12 +4628,16 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
>> rsWentylator.FA;
rsWentylator.AM /= MoverParameters->RVentnmax;
rsWentylator.FM /= MoverParameters->RVentnmax;
#else
rsWentylator.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
#endif
}
else if( ( token == "transmission:" )
&& ( MoverParameters->EngineType == ElectricSeriesMotor ) ) {
// plik z dzwiekiem, mnozniki i ofsety amp. i czest.
double attenuation;
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
>> token
@@ -4646,11 +4650,15 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsPrzekladnia.AA = 0.1;
rsPrzekladnia.FM = 0.005;
rsPrzekladnia.FA = 1.0;
#else
rsPrzekladnia.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
#endif
}
else if( token == "brake:" ){
// plik z piskiem hamulca, mnozniki i ofsety amplitudy.
double attenuation;
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
>> token
@@ -4663,23 +4671,26 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsPisk.AA = parser.getToken<double>() * ( 105 - Random( 10 ) ) / 100;
rsPisk.FM = 1.0;
rsPisk.FA = 0.0;
#else
rsPisk.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude );
#endif
}
else if( token == "brakeacc:" ) {
// plik z przyspieszaczem (upust po zlapaniu hamowania)
// sBrakeAcc.Init(str.c_str(),Parser->GetNextSymbol().ToDouble(),GetPosition().x,GetPosition().y,GetPosition().z,true);
parser.getTokens( 1, false ); parser >> token;
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
sBrakeAcc = TSoundsManager::GetFromName( token, true );
#else
sBrakeAcc.deserialize( parser, sound_type::single );
#endif
bBrakeAcc = true;
// sBrakeAcc.AM=1.0;
// sBrakeAcc.AA=0.0;
// sBrakeAcc.FM=1.0;
// sBrakeAcc.FA=0.0;
}
else if( token == "unbrake:" ) {
// plik z piskiem hamulca, mnozniki i ofsety amplitudy.
double attenuation;
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
>> token
@@ -4692,11 +4703,15 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsUnbrake.AA = 0.0;
rsUnbrake.FM = 1.0;
rsUnbrake.FA = 0.0;
#else
rsUnbrake.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
}
else if( token == "derail:" ) {
// dzwiek przy wykolejeniu
double attenuation;
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
>> token
@@ -4709,11 +4724,15 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsDerailment.AA = 0.0;
rsDerailment.FM = 1.0;
rsDerailment.FA = 0.0;
#else
rsDerailment.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
}
else if( token == "dieselinc:" ) {
// dzwiek przy wlazeniu na obroty woodwarda
double attenuation;
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false );
parser
>> token
@@ -4726,12 +4745,16 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsDiesielInc.AA = 0.0;
rsDiesielInc.FM = 1.0;
rsDiesielInc.FA = 0.0;
#else
rsDiesielInc.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
}
else if( token == "curve:" ) {
double attenuation;
parser.getTokens( 2, false );
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 2, false );
parser
>> token
>> attenuation;
@@ -4743,91 +4766,143 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rscurve.AA = 0.0;
rscurve.FM = 1.0;
rscurve.FA = 0.0;
#else
rscurve.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
}
else if( token == "horn1:" ) {
// pliki z trabieniem
sHorn1.Load( parser, GetPosition() );
#ifdef EU07_USE_OLD_SOUNDCODE
sHorn1.Load( parser, GetPosition() );
#else
sHorn1.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "horn2:" ) {
// pliki z trabieniem wysokoton.
sHorn2.Load( parser, GetPosition() );
if( iHornWarning ) {
#ifdef EU07_USE_OLD_SOUNDCODE
sHorn2.Load( parser, GetPosition() );
#else
sHorn2.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
if( iHornWarning ) {
iHornWarning = 2; // numer syreny do użycia po otrzymaniu sygnału do jazdy
}
}
}
else if( token == "departuresignal:" ) {
// pliki z sygnalem odjazdu
sDepartureSignal.Load( parser, GetPosition() );
#ifdef EU07_USE_OLD_SOUNDCODE
sDepartureSignal.Load( parser, GetPosition() );
#else
sDepartureSignal.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "pantographup:" ) {
// pliki dzwiekow pantografow
parser.getTokens( 1, false ); parser >> token;
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
sPantUp.Init(
token, 50,
GetPosition().x, GetPosition().y, GetPosition().z,
true );
#else
sPantUp.deserialize( parser, sound_type::single );
#endif
}
else if( token == "pantographdown:" ) {
// pliki dzwiekow pantografow
parser.getTokens( 1, false ); parser >> token;
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
sPantDown.Init(
token, 50,
GetPosition().x, GetPosition().y, GetPosition().z,
true );
#else
sPantDown.deserialize( parser, sound_type::single );
#endif
}
else if( token == "compressor:" ) {
// pliki ze sprezarka
#ifdef EU07_USE_OLD_SOUNDCODE
sCompressor.Load( parser, GetPosition() );
#else
sCompressor.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "converter:" ) {
// pliki z przetwornica
// if (MoverParameters->EngineType==DieselElectric) //będzie modulowany?
sConverter.Load( parser, GetPosition() );
#ifdef EU07_USE_OLD_SOUNDCODE
sConverter.Load( parser, GetPosition() );
#else
sConverter.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "turbo:" ) {
// pliki z turbogeneratorem
sTurbo.Load( parser, GetPosition() );
#ifdef EU07_USE_OLD_SOUNDCODE
sTurbo.Load( parser, GetPosition() );
#else
sTurbo.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "small-compressor:" ) {
// pliki z przetwornica
sSmallCompressor.Load( parser, GetPosition() );
#ifdef EU07_USE_OLD_SOUNDCODE
sSmallCompressor.Load( parser, GetPosition() );
#else
sSmallCompressor.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "dooropen:" ) {
parser.getTokens( 1, false ); parser >> token;
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
rsDoorOpen.Init(
token, 50,
GetPosition().x, GetPosition().y, GetPosition().z,
true );
#else
rsDoorOpen.deserialize( parser, sound_type::single );
#endif
}
else if( token == "doorclose:" ) {
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
rsDoorClose.Init(
token, 50,
GetPosition().x, GetPosition().y, GetPosition().z,
true );
#else
rsDoorClose.deserialize( parser, sound_type::single );
#endif
}
else if( token == "sand:" ) {
// pliki z piasecznica
#ifdef EU07_USE_OLD_SOUNDCODE
// pliki z piasecznica
sSand.Load( parser, GetPosition() );
#else
sSand.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
else if( token == "releaser:" ) {
// pliki z odluzniaczem
sReleaser.Load( parser, GetPosition() );
#ifdef EU07_USE_OLD_SOUNDCODE
sReleaser.Load( parser, GetPosition() );
#else
sReleaser.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
}
} while( ( token != "" )

View File

@@ -14,10 +14,9 @@ http://mozilla.org/MPL/2.0/.
#include "TrkFoll.h"
// McZapkie:
#include "RealSound.h"
#include "AdvSound.h"
#include "Button.h"
#include "AirCoupler.h"
#include "sound.h"
#include "texture.h"
//---------------------------------------------------------------------------
@@ -304,27 +303,27 @@ private:
double dRailLength;
double dRailPosition[MaxAxles]; // licznik pozycji osi w/m szyny
double dWheelsPosition[MaxAxles]; // pozycja osi w/m srodka pojazdu
TRealSound rsStukot[MaxAxles]; // dzwieki poszczegolnych osi //McZapkie-270202
TRealSound rsSilnik; // McZapkie-010302 - silnik
TRealSound rsWentylator; // McZapkie-030302
TRealSound rsPisk; // McZapkie-260302
TRealSound rsDerailment; // McZapkie-051202
TRealSound rsPrzekladnia;
TAdvancedSound sHorn1;
TAdvancedSound sHorn2;
TAdvancedSound sCompressor; // NBMX wrzesien 2003
TAdvancedSound sConverter;
TAdvancedSound sSmallCompressor;
TAdvancedSound sDepartureSignal;
TAdvancedSound sTurbo;
TAdvancedSound sSand;
TAdvancedSound sReleaser;
sound_source rsStukot[MaxAxles]; // dzwieki poszczegolnych osi //McZapkie-270202
sound_source rsSilnik; // McZapkie-010302 - silnik
sound_source rsWentylator; // McZapkie-030302
sound_source rsPisk; // McZapkie-260302
sound_source rsDerailment; // McZapkie-051202
sound_source rsPrzekladnia;
sound_source sHorn1;
sound_source sHorn2;
sound_source sCompressor; // NBMX wrzesien 2003
sound_source sConverter;
sound_source sSmallCompressor;
sound_source sDepartureSignal;
sound_source sTurbo;
sound_source sSand;
sound_source sReleaser;
// Winger 010304
TRealSound sPantUp;
TRealSound sPantDown;
TRealSound rsDoorOpen; // Ra: przeniesione z kabiny
TRealSound rsDoorClose;
sound_source sPantUp;
sound_source sPantDown;
sound_source rsDoorOpen; // Ra: przeniesione z kabiny
sound_source rsDoorClose;
double eng_vol_act;
double eng_frq_act;
@@ -336,9 +335,9 @@ private:
bool renderme; // yB - czy renderowac
// TRealSound sBrakeAcc; //dźwięk przyspieszacza
PSound sBrakeAcc;
sound_source sBrakeAcc;
bool bBrakeAcc;
TRealSound rsUnbrake; // yB - odglos luzowania
sound_source rsUnbrake; // yB - odglos luzowania
float ModCamRot;
int iInventory[ 2 ] { 0, 0 }; // flagi bitowe posiadanych submodeli (np. świateł)
void TurnOff();
@@ -379,8 +378,8 @@ private:
std::string name() const {
return this ? asName : std::string(); };
TRealSound rsDiesielInc; // youBy
TRealSound rscurve; // youBy
sound_source rsDiesielInc; // youBy
sound_source rscurve; // youBy
// std::ofstream PneuLogFile; //zapis parametrow pneumatycznych
// youBy - dym
// TSmoke Smog;

View File

@@ -1022,6 +1022,7 @@ event_manager::CheckQuery() {
return false;
}
case tp_Sound: {
#ifdef EU07_USE_OLD_SOUNDCODE
switch( m_workevent->Params[ 0 ].asInt ) {
// trzy możliwe przypadki:
case 0: {
@@ -1048,6 +1049,7 @@ event_manager::CheckQuery() {
break;
}
}
#endif
break;
}
case tp_Disable:

View File

@@ -74,7 +74,11 @@ union TParam
bool asBool;
double asdouble;
int asInt;
#ifdef EU07_USE_OLD_SOUNDCODE
TTextSound *tsTextSound;
#else
sound_source *tsTextSound;
#endif
char *asText;
TCommandType asCommand;
TTractionPowerSource *psPower;

View File

@@ -70,16 +70,15 @@ bool TGauge::Load(cParser &Parser, TModel3d *md1, TModel3d *md2, double mul) {
else {
// new, block type config
// TODO: rework the base part into yaml-compatible flow style mapping
cParser mappingparser( Parser.getToken<std::string>( false, "}" ) );
submodelname = mappingparser.getToken<std::string>( false );
gaugetypename = mappingparser.getToken<std::string>( true );
mappingparser.getTokens( 3, false );
mappingparser
submodelname = Parser.getToken<std::string>( false );
gaugetypename = Parser.getToken<std::string>( true );
Parser.getTokens( 3, false );
Parser
>> scale
>> offset
>> friction;
// new, variable length section
while( true == Load_mapping( mappingparser ) ) {
while( true == Load_mapping( Parser ) ) {
; // all work done by while()
}
}
@@ -116,26 +115,15 @@ bool TGauge::Load(cParser &Parser, TModel3d *md1, TModel3d *md2, double mul) {
bool
TGauge::Load_mapping( cParser &Input ) {
if( false == Input.getTokens( 2, true, ", \n\r\t" ) ) {
return false;
}
std::string key, value;
Input
>> key
>> value;
// token can be a key or block end
std::string const key { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
if( ( true == key.empty() ) || ( key == "}" ) ) { return false; }
// if not block end then the key is followed by assigned value or sub-block
if( key == "soundinc:" ) {
m_soundfxincrease = (
value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr );
m_soundfxincrease.deserialize( Input, sound_type::single );
}
else if( key == "sounddec:" ) {
m_soundfxdecrease = (
value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr );
m_soundfxdecrease.deserialize( Input, sound_type::single );
}
else if( key.compare( 0, std::min<std::size_t>( key.size(), 5 ), "sound" ) == 0 ) {
// sounds assigned to specific gauge values, defined by key soundFoo: where Foo = value
@@ -144,9 +132,7 @@ TGauge::Load_mapping( cParser &Input ) {
if( indexstart != std::string::npos ) {
m_soundfxvalues.emplace(
std::stoi( key.substr( indexstart, indexend - indexstart ) ),
( value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr ) );
sound_source().deserialize( Input, sound_type::single ) );
}
}
return true; // return value marks a key: value pair was extracted, nothing about whether it's recognized
@@ -176,9 +162,21 @@ void TGauge::DecValue(double fNewDesired)
fDesiredValue = 0;
};
void
TGauge::UpdateValue( double fNewDesired ) {
return UpdateValue( fNewDesired, nullptr );
}
void
TGauge::UpdateValue( double fNewDesired, sound_source &Fallbacksound ) {
return UpdateValue( fNewDesired, &Fallbacksound );
}
// ustawienie wartości docelowej. plays provided fallback sound, if no sound was defined in the control itself
void
TGauge::UpdateValue( double fNewDesired, PSound Fallbacksound ) {
TGauge::UpdateValue( double fNewDesired, sound_source *Fallbacksound ) {
auto const desiredtimes100 = static_cast<int>( std::round( 100.0 * fNewDesired ) );
if( static_cast<int>( std::round( 100.0 * ( fDesiredValue - fOffset ) / fScale ) ) == desiredtimes100 ) {
@@ -191,21 +189,25 @@ TGauge::UpdateValue( double fNewDesired, PSound Fallbacksound ) {
// filter out values other than full integers
auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 );
if( lookup != m_soundfxvalues.end() ) {
play( lookup->second );
lookup->second.play();
return;
}
}
// ...and if there isn't any, fall back on the basic set...
auto const currentvalue = GetValue();
if( ( currentvalue < fNewDesired ) && ( m_soundfxincrease != nullptr ) ) {
play( m_soundfxincrease );
if( ( currentvalue < fNewDesired )
&& ( false == m_soundfxincrease.empty() ) ) {
// shift up
m_soundfxincrease.play();
}
else if( ( currentvalue > fNewDesired ) && ( m_soundfxdecrease != nullptr ) ) {
play( m_soundfxdecrease );
else if( ( currentvalue > fNewDesired )
&& ( false == m_soundfxdecrease.empty() ) ) {
// shift down
m_soundfxdecrease.play();
}
else if( Fallbacksound != nullptr ) {
// ...and if that fails too, try the provided fallback sound from legacy system
play( Fallbacksound );
Fallbacksound->play();
}
};
@@ -315,15 +317,4 @@ void TGauge::UpdateValue()
}
};
void
TGauge::play( PSound Sound ) {
if( Sound == nullptr ) { return; }
Sound->SetCurrentPosition( 0 );
Sound->SetVolume( DSBVOLUME_MAX );
Sound->Play( 0, 0, 0 );
return;
}
//---------------------------------------------------------------------------

28
Gauge.h
View File

@@ -24,7 +24,13 @@ enum TGaugeType {
// animowany wskaźnik, mogący przyjmować wiele stanów pośrednich
class TGauge {
private:
private:
// methods
// imports member data pair from the config file
bool
Load_mapping( cParser &Input );
void UpdateValue( double fNewDesired, sound_source *Fallbacksound );
// members
TGaugeType eType { gt_Unknown }; // typ ruchu
double fFriction { 0.0 }; // hamowanie przy zliżaniu się do zadanej wartości
double fDesiredValue { 0.0 }; // wartość docelowa
@@ -38,18 +44,12 @@ class TGauge {
double *dData { nullptr };
int *iData;
};
PSound m_soundfxincrease { nullptr }; // sound associated with increasing control's value
PSound m_soundfxdecrease { nullptr }; // sound associated with decreasing control's value
std::map<int, PSound> m_soundfxvalues; // sounds associated with specific values
// methods
// imports member data pair from the config file
bool
Load_mapping( cParser &Input );
// plays specified sound
void
play( PSound Sound );
sound_source m_soundfxincrease; // sound associated with increasing control's value
sound_source m_soundfxdecrease; // sound associated with decreasing control's value
std::map<int, sound_source> m_soundfxvalues; // sounds associated with specific values
public:
public:
// methods
TGauge() = default;
inline
void Clear() { *this = TGauge(); }
@@ -58,7 +58,8 @@ class TGauge {
void PermIncValue(double fNewDesired);
void IncValue(double fNewDesired);
void DecValue(double fNewDesired);
void UpdateValue(double fNewDesired, PSound Fallbacksound = nullptr );
void UpdateValue( double fNewDesired );
void UpdateValue( double fNewDesired, sound_source &Fallbacksound );
void PutValue(double fNewDesired);
double GetValue() const;
void Update();
@@ -67,6 +68,7 @@ class TGauge {
void AssignDouble(double *dValue);
void AssignInt(int *iValue);
void UpdateValue();
// members
TSubModel *SubModel; // McZapkie-310302: zeby mozna bylo sprawdzac czy zainicjowany poprawnie
};

View File

@@ -114,6 +114,7 @@ int const k_DimHeadlights = 74;
const int MaxKeys = 75;
// klasy dla wskaźników globalnych
/*
class TGround;
class TWorld;
class TCamera;
@@ -121,8 +122,7 @@ class TDynamicObject;
class TAnimModel; // obiekt terenu
class cParser; // nowy (powolny!) parser
class TEvent;
class TTextSound;
*/
class TTranscript
{ // klasa obsługująca linijkę napisu do dźwięku
public:
@@ -293,7 +293,9 @@ public:
static float4 UITextColor; // base color of UI text
static std::string asLang; // domyślny język - http://tools.ietf.org/html/bcp47
static int iHiddenEvents; // czy łączyć eventy z torami poprzez nazwę toru
/*
static TTextSound *tsRadioBusy[10]; // zajętość kanałów radiowych (wskaźnik na odgrywany dźwięk)
*/
static int iPoKeysPWM[7]; // numery wejść dla PWM
//randomizacja

View File

@@ -95,7 +95,7 @@ TSubModel::SetLightLevel( float const Level, bool const Includechildren, bool co
}
}
int TSubModel::SeekFaceNormal(std::vector<unsigned int> const &Masks, int const Startface, unsigned int const Mask, glm::vec3 const &Position, vertex_array const &Vertices)
int TSubModel::SeekFaceNormal(std::vector<unsigned int> const &Masks, int const Startface, unsigned int const Mask, glm::vec3 const &Position, gfx::vertex_array const &Vertices)
{ // szukanie punktu stycznego do (pt), zwraca numer wierzchołka, a nie trójkąta
int facecount = iNumVerts / 3; // bo maska powierzchni jest jedna na trójkąt
for( int faceidx = Startface; faceidx < facecount; ++faceidx ) {
@@ -983,7 +983,7 @@ void TSubModel::serialize_geometry( std::ostream &Output ) const {
};
void
TSubModel::create_geometry( std::size_t &Dataoffset, geometrybank_handle const &Bank ) {
TSubModel::create_geometry( std::size_t &Dataoffset, gfx::geometrybank_handle const &Bank ) {
// data offset is used to determine data offset of each submodel into single shared geometry bank
// (the offsets are part of legacy system which we now need to work around for backward compatibility)
@@ -1472,7 +1472,7 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
// once sorted we can grab geometry as it comes, and assign it to the chunks it belongs to
for( auto const &submodeloffset : submodeloffsets ) {
auto &submodel = Root[ submodeloffset.second ];
vertex_array vertices; vertices.resize( submodel.iNumVerts );
gfx::vertex_array vertices; vertices.resize( submodel.iNumVerts );
iNumVerts += submodel.iNumVerts;
for( auto &vertex : vertices ) {
vertex.deserialize( s );

View File

@@ -124,7 +124,7 @@ private:
TSubModel *Next { nullptr };
TSubModel *Child { nullptr };
geometry_handle m_geometry { 0, 0 }; // geometry of the submodel
gfx::geometry_handle m_geometry { 0, 0 }; // geometry of the submodel
material_handle m_material { null_handle }; // numer tekstury, -1 wymienna, 0 brak
bool bWire { false }; // nie używane, ale wczytywane
float Opacity { 1.0f };
@@ -134,7 +134,7 @@ private:
public: // chwilowo
float3 v_TransVector { 0.0f, 0.0f, 0.0f };
vertex_array Vertices;
gfx::vertex_array Vertices;
float m_boundingradius { 0 };
size_t iAnimOwner{ 0 }; // roboczy numer egzemplarza, który ustawił animację
TAnimType b_aAnim{ at_None }; // kody animacji oddzielnie, bo zerowane
@@ -147,7 +147,7 @@ public:
std::string m_materialname; // robocza nazwa tekstury do zapisania w pliku binarnym
std::string pName; // robocza nazwa
private:
int SeekFaceNormal( std::vector<unsigned int> const &Masks, int const Startface, unsigned int const Mask, glm::vec3 const &Position, vertex_array const &Vertices );
int SeekFaceNormal( std::vector<unsigned int> const &Masks, int const Startface, unsigned int const Mask, glm::vec3 const &Position, gfx::vertex_array const &Vertices );
void RaAnimation(TAnimType a);
public:
@@ -174,7 +174,7 @@ public:
inline float4x4 * GetMatrix() { return fMatrix; };
inline void Hide() { iVisible = 0; };
void create_geometry( std::size_t &Dataoffset, geometrybank_handle const &Bank );
void create_geometry( std::size_t &Dataoffset, gfx::geometrybank_handle const &Bank );
int FlagsCheck();
void WillBeAnimated()
{
@@ -222,7 +222,7 @@ private:
int iFlags; // Ra: czy submodele mają przezroczyste tekstury
public: // Ra: tymczasowo
int iNumVerts; // ilość wierzchołków (gdy nie ma VBO, to m_nVertexCount=0)
geometrybank_handle m_geometrybank;
gfx::geometrybank_handle m_geometrybank;
bool m_geometrycreated { false };
private:
std::vector<std::string> Textures; // nazwy tekstur

View File

@@ -359,7 +359,7 @@ Math3D::vector3 TSegment::FastGetPoint(double const t) const
interpolate( Point1, Point2, t ) );
}
bool TSegment::RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin, const basic_vertex *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale, int iSkip, int iEnd, float fOffsetX, glm::vec3 **p, bool bRender)
bool TSegment::RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Origin, const gfx::basic_vertex *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale, int iSkip, int iEnd, float fOffsetX, glm::vec3 **p, bool bRender)
{ // generowanie trójkątów dla odcinka trajektorii ruchu
// standardowo tworzy triangle_strip dla prostego albo ich zestaw dla łuku
// po modyfikacji - dla ujemnego (iNumShapePoints) w dodatkowych polach tabeli

View File

@@ -97,7 +97,7 @@ public:
r2 = fRoll2; }
bool
RenderLoft( vertex_array &Output, Math3D::vector3 const &Origin, basic_vertex const *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, float fOffsetX = 0.f, glm::vec3 **p = nullptr, bool bRender = true);
RenderLoft( gfx::vertex_array &Output, Math3D::vector3 const &Origin, gfx::basic_vertex const *ShapePoints, int iNumShapePoints, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, float fOffsetX = 0.f, glm::vec3 **p = nullptr, bool bRender = true);
void
Render();
inline

View File

@@ -940,7 +940,7 @@ const int nnumPts = 12;
// szyna - vextor6(x,y,mapowanie tekstury,xn,yn,zn)
// tę wersję opracował Tolein (bez pochylenia)
// TODO: profile definitions in external files
basic_vertex const szyna[ nnumPts ] = {
gfx::basic_vertex const szyna[ nnumPts ] = {
{{ 0.111f, -0.180f, 0.f}, { 1.000f, 0.000f, 0.f}, {0.00f, 0.f}},
{{ 0.046f, -0.150f, 0.f}, { 0.707f, 0.707f, 0.f}, {0.15f, 0.f}},
{{ 0.044f, -0.050f, 0.f}, { 0.707f, -0.707f, 0.f}, {0.25f, 0.f}},
@@ -957,7 +957,7 @@ basic_vertex const szyna[ nnumPts ] = {
// iglica - vextor3(x,y,mapowanie tekstury)
// 1 mm więcej, żeby nie nachodziły tekstury?
// TODO: automatic generation from base profile TBD: reuse base profile?
basic_vertex const iglica[ nnumPts ] = {
gfx::basic_vertex const iglica[ nnumPts ] = {
{{ 0.010f, -0.180f, 0.f}, { 1.000f, 0.000f, 0.f}, {0.00f, 0.f}},
{{ 0.010f, -0.155f, 0.f}, { 1.000f, 0.000f, 0.f}, {0.15f, 0.f}},
{{ 0.010f, -0.070f, 0.f}, { 1.000f, 0.000f, 0.f}, {0.25f, 0.f}},
@@ -1062,7 +1062,7 @@ void TTrack::RaAssign( TAnimModel *am, TEvent *done, TEvent *joined )
};
// wypełnianie tablic VBO
void TTrack::create_geometry( geometrybank_handle const &Bank ) {
void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
// Ra: trzeba rozdzielić szyny od podsypki, aby móc grupować wg tekstur
auto const fHTW = 0.5f * std::abs(fTrackWidth);
auto const side = std::abs(fTexWidth); // szerokść podsypki na zewnątrz szyny albo pobocza
@@ -1122,7 +1122,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
sin2 = std::sin(roll2),
cos2 = std::cos(roll2);
// zwykla szyna: //Ra: czemu główki są asymetryczne na wysokości 0.140?
basic_vertex rpts1[24], rpts2[24], rpts3[24], rpts4[24];
gfx::basic_vertex rpts1[24], rpts2[24], rpts3[24], rpts4[24];
for( int i = 0; i < 12; ++i ) {
rpts1[ i ] = {
@@ -1186,7 +1186,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
case tt_Normal:
if (m_material2)
{ // podsypka z podkładami jest tylko dla zwykłego toru
basic_vertex bpts1[ 8 ]; // punkty głównej płaszczyzny nie przydają się do robienia boków
gfx::basic_vertex bpts1[ 8 ]; // punkty głównej płaszczyzny nie przydają się do robienia boków
if( fTexLength == 4.f ) {
// stare mapowanie z różną gęstością pikseli i oddzielnymi teksturami na każdy profil
auto const normalx = std::cos( glm::radians( 75.f ) );
@@ -1314,7 +1314,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
{0.5f + map12, 0.f} }; // prawy skos
}
}
vertex_array vertices;
gfx::vertex_array vertices;
Segment->RenderLoft(vertices, m_origin, bpts1, iTrapezoid ? -4 : 4, fTexLength);
if( ( Bank != 0 ) && ( true == Geometry2.empty() ) ) {
Geometry2.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
@@ -1326,7 +1326,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
if (m_material1)
{ // szyny - generujemy dwie, najwyżej rysować się będzie jedną
vertex_array vertices;
gfx::vertex_array vertices;
if( ( Bank != 0 ) && ( true == Geometry1.empty() ) ) {
Segment->RenderLoft( vertices, m_origin, rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength );
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
@@ -1347,7 +1347,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
case tt_Switch: // dla zwrotnicy dwa razy szyny
if( m_material1 || m_material2 ) {
// iglice liczone tylko dla zwrotnic
basic_vertex rpts3[24], rpts4[24];
gfx::basic_vertex rpts3[24], rpts4[24];
for( int i = 0; i < 12; ++i ) {
rpts3[ i ] = {
@@ -1378,7 +1378,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
// TODO, TBD: change all track geometry to triangles, to allow packing data in less, larger buffers
if (SwitchExtension->RightSwitch)
{ // nowa wersja z SPKS, ale odwrotnie lewa/prawa
vertex_array vertices;
gfx::vertex_array vertices;
if( m_material1 ) {
// fixed parts
SwitchExtension->Segments[ 0 ]->RenderLoft( vertices, m_origin, rpts2, nnumPts, fTexLength );
@@ -1408,7 +1408,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
else
{ // lewa działa lepiej niż prawa
vertex_array vertices;
gfx::vertex_array vertices;
if( m_material1 ) {
// fixed parts
SwitchExtension->Segments[ 0 ]->RenderLoft( vertices, m_origin, rpts1, nnumPts, fTexLength ); // lewa szyna normalna cała
@@ -1446,7 +1446,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
{
case tt_Normal: // drogi proste, bo skrzyżowania osobno
{
basic_vertex bpts1[4]; // punkty głównej płaszczyzny przydają się do robienia boków
gfx::basic_vertex bpts1[4]; // punkty głównej płaszczyzny przydają się do robienia boków
if (m_material1 || m_material2) {
// punkty się przydadzą, nawet jeśli nawierzchni nie ma
/*
@@ -1489,13 +1489,13 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
if (m_material1) // jeśli podana była tekstura, generujemy trójkąty
{ // tworzenie trójkątów nawierzchni szosy
vertex_array vertices;
gfx::vertex_array vertices;
Segment->RenderLoft(vertices, m_origin, bpts1, iTrapezoid ? -2 : 2, fTexLength);
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
}
if (m_material2)
{ // pobocze drogi - poziome przy przechyłce (a może krawężnik i chodnik zrobić jak w Midtown Madness 2?)
basic_vertex
gfx::basic_vertex
rpts1[6],
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
if (fTexHeight1 >= 0.f)
@@ -1649,7 +1649,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
{0.484375f - map2l, 0.f} }; // lewy brzeg lewego chodnika
}
}
vertex_array vertices;
gfx::vertex_array vertices;
if( iTrapezoid ) // trapez albo przechyłki
{ // pobocza do trapezowatej nawierzchni - dodatkowe punkty z drugiej strony
// odcinka
@@ -1728,7 +1728,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
SwitchExtension->bPoints ?
nullptr :
SwitchExtension->vPoints; // zmienna robocza, NULL gdy tablica punktów już jest wypełniona
basic_vertex bpts1[4]; // punkty głównej płaszczyzny przydają się do robienia boków
gfx::basic_vertex bpts1[4]; // punkty głównej płaszczyzny przydają się do robienia boków
if (m_material1 || m_material2) // punkty się przydadzą, nawet jeśli nawierzchni nie ma
{ // double max=2.0*(fHTW>fHTW2?fHTW:fHTW2); //z szerszej strony jest 100%
auto const max = fTexRatio1 * fTexLength; // test: szerokość proporcjonalna do długości
@@ -1761,7 +1761,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
// ale pobocza renderują się później, więc nawierzchnia nie załapuje się na renderowanie w swoim czasie
if( m_material2 )
{ // pobocze drogi - poziome przy przechyłce (a może krawężnik i chodnik zrobić jak w Midtown Madness 2?)
basic_vertex
gfx::basic_vertex
rpts1[6],
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
// Ra 2014-07: trzeba to przerobić na pętlę i pobierać profile (przynajmniej 2..4) z sąsiednich dróg
@@ -1900,7 +1900,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
}
bool render = ( m_material2 != 0 ); // renderować nie trzeba, ale trzeba wyznaczyć punkty brzegowe nawierzchni
vertex_array vertices;
gfx::vertex_array vertices;
if (SwitchExtension->iRoads == 4)
{ // pobocza do trapezowatej nawierzchni - dodatkowe punkty z drugiej strony odcinka
if( ( fTexHeight1 >= 0.0 ) || ( side != 0.0 ) ) {
@@ -1956,7 +1956,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
if( m_material1 ) {
vertex_array vertices;
gfx::vertex_array vertices;
// jeśli podana tekstura nawierzchni
// we start with a vertex in the middle...
vertices.emplace_back(
@@ -2006,7 +2006,7 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
{
case tt_Normal: // drogi proste, bo skrzyżowania osobno
{
basic_vertex bpts1[4]; // punkty głównej płaszczyzny przydają się do robienia boków
gfx::basic_vertex bpts1[4]; // punkty głównej płaszczyzny przydają się do robienia boków
if (m_material1 || m_material2) // punkty się przydadzą, nawet jeśli nawierzchni nie ma
{ // double max=2.0*(fHTW>fHTW2?fHTW:fHTW2); //z szerszej strony jest 100%
auto const max = (
@@ -2056,14 +2056,14 @@ void TTrack::create_geometry( geometrybank_handle const &Bank ) {
}
if (m_material1) // jeśli podana była tekstura, generujemy trójkąty
{ // tworzenie trójkątów nawierzchni szosy
vertex_array vertices;
gfx::vertex_array vertices;
Segment->RenderLoft(vertices, m_origin, bpts1, iTrapezoid ? -2 : 2, fTexLength);
Geometry1.emplace_back( GfxRenderer.Insert( vertices, Bank, GL_TRIANGLE_STRIP ) );
}
if (m_material2)
{ // pobocze drogi - poziome przy przechyłce (a może krawężnik i chodnik zrobić jak w Midtown Madness 2?)
vertex_array vertices;
basic_vertex
gfx::vertex_array vertices;
gfx::basic_vertex
rpts1[6],
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
@@ -2425,7 +2425,7 @@ TTrack * TTrack::RaAnimate()
auto const fHTW2 = fHTW; // Ra: na razie niech tak będzie
auto const cos1 = 1.0f, sin1 = 0.0f, cos2 = 1.0f, sin2 = 0.0f; // Ra: ...
basic_vertex
gfx::basic_vertex
rpts3[ 24 ],
rpts4[ 24 ];
for (int i = 0; i < 12; ++i) {
@@ -2456,7 +2456,7 @@ TTrack * TTrack::RaAnimate()
{szyna[ i ].texture.x, 0.f} };
}
vertex_array vertices;
gfx::vertex_array vertices;
if (SwitchExtension->RightSwitch)
{ // nowa wersja z SPKS, ale odwrotnie lewa/prawa
@@ -2520,7 +2520,7 @@ TTrack * TTrack::RaAnimate()
dynamic->Move( 0.000001 );
}
// NOTE: passing empty handle is a bit of a hack here. could be refactored into something more elegant
create_geometry( geometrybank_handle() );
create_geometry( {} );
} // animacja trwa nadal
}
else

View File

@@ -147,7 +147,7 @@ private:
glm::dvec3 m_origin;
material_handle m_material1 = 0; // tekstura szyn albo nawierzchni
material_handle m_material2 = 0; // tekstura automatycznej podsypki albo pobocza
typedef std::vector<geometry_handle> geometryhandle_sequence;
typedef std::vector<gfx::geometry_handle> geometryhandle_sequence;
geometryhandle_sequence Geometry1; // geometry chunks textured with texture 1
geometryhandle_sequence Geometry2; // geometry chunks textured with texture 2
@@ -245,7 +245,7 @@ public:
std::vector<glm::dvec3>
endpoints() const;
void create_geometry( geometrybank_handle const &Bank ); // wypełnianie VBO
void create_geometry( gfx::geometrybank_handle const &Bank ); // wypełnianie VBO
void RenderDynSounds(); // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania
void RaOwnerSet( scene::basic_cell *o ) {

View File

@@ -175,18 +175,18 @@ TTraction::endpoints() const {
}
std::size_t
TTraction::create_geometry( geometrybank_handle const &Bank ) {
TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
if( m_geometry != null_handle ) {
return GfxRenderer.Vertices( m_geometry ).size() / 2;
}
vertex_array vertices;
gfx::vertex_array vertices;
double ddp = std::hypot( pPoint2.x - pPoint1.x, pPoint2.z - pPoint1.z );
if( Wires == 2 )
WireOffset = 0;
// jezdny
basic_vertex startvertex, endvertex;
gfx::basic_vertex startvertex, endvertex;
startvertex.position =
glm::vec3(
pPoint1.x - ( pPoint2.z / ddp - pPoint1.z / ddp ) * WireOffset - m_origin.x,

View File

@@ -50,7 +50,7 @@ class TTraction : public editor::basic_node {
int PowerState { 0 }; // type of incoming power, if any
// visualization data
glm::dvec3 m_origin;
geometry_handle m_geometry;
gfx::geometry_handle m_geometry;
explicit TTraction( scene::node_data const &Nodedata );
@@ -64,7 +64,7 @@ class TTraction : public editor::basic_node {
endpoints() const;
// creates geometry data in specified geometry bank. returns: number of created elements, or NULL
// NOTE: deleting nodes doesn't currently release geometry data owned by the node. TODO: implement erasing individual geometry chunks and banks
std::size_t create_geometry( geometrybank_handle const &Bank );
std::size_t create_geometry( gfx::geometrybank_handle const &Bank );
int TestPoint(glm::dvec3 const &Point);
void Connect(int my, TTraction *with, int to);
void Init();

1609
Train.cpp

File diff suppressed because it is too large Load Diff

81
Train.h
View File

@@ -14,7 +14,7 @@ http://mozilla.org/MPL/2.0/.
#include "Button.h"
#include "Gauge.h"
#include "Spring.h"
#include "AdvSound.h"
#include "sound.h"
#include "PyInt.h"
#include "command.h"
@@ -90,6 +90,7 @@ class TTrain
void UpdateMechPosition(double dt);
vector3 GetWorldMechPosition();
bool Update( double const Deltatime );
void update_sounds( double const Deltatime );
bool m_updated = false;
void MechStop();
void SetLights();
@@ -110,10 +111,6 @@ class TTrain
bool initialize_gauge(cParser &Parser, std::string const &Label, int const Cabindex);
// initializes a button matching provided label. returns: true if the label was found, false otherwise
bool initialize_button(cParser &Parser, std::string const &Label, int const Cabindex);
// plays specified sound, or fallback sound if the primary sound isn't presend
// NOTE: temporary routine until sound system is sorted out and paired with switches
void play_sound( PSound Sound, int const Volume = DSBVOLUME_MAX, DWORD const Flags = 0 );
void play_sound( PSound Sound, PSound Fallbacksound, int const Volume, DWORD const Flags );
// helper, returns true for EMU with oerlikon brake
bool is_eztoer() const;
// command handlers
@@ -308,8 +305,6 @@ public: // reszta może by?publiczna
TGauge ggTrainHeatingButton;
TGauge ggSignallingButton;
TGauge ggDoorSignallingButton;
// TGauge ggDistCounter; //Ra 2014-07: licznik kilometrów
// TGauge ggVelocityDgt; //i od razu prędkościomierz
TButton btLampkaPoslizg;
TButton btLampkaStyczn;
@@ -356,7 +351,6 @@ public: // reszta może by?publiczna
TButton btLampkaRadiotelefon;
TButton btLampkaHamienie;
TButton btLampkaED; // Stele 161228 hamowanie elektrodynamiczne
TButton btLampkaJazda; // Ra: nie używane
// KURS90
TButton btLampkaBoczniki;
TButton btLampkaMaxSila;
@@ -384,8 +378,9 @@ public: // reszta może by?publiczna
// Ra 2013-12: wirtualne "lampki" do odbijania na haslerze w PoKeys
TButton btHaslerBrakes; // ciśnienie w cylindrach
TButton btHaslerCurrent; // prąd na silnikach
/*
vector3 pPosition;
*/
vector3 pMechOffset; // driverNpos
vector3 vMechMovement;
vector3 pMechPosition;
@@ -403,48 +398,42 @@ public: // reszta może by?publiczna
double fMechRoll;
double fMechPitch;
PSound dsbNastawnikJazdy;
PSound dsbNastawnikBocz; // hunter-081211
PSound dsbRelay;
PSound dsbPneumaticRelay;
PSound dsbSwitch;
PSound dsbPneumaticSwitch;
PSound dsbReverserKey; // hunter-121211
sound_source dsbNastawnikJazdy;
sound_source dsbNastawnikBocz; // hunter-081211
sound_source dsbRelay;
sound_source dsbPneumaticRelay;
sound_source dsbSwitch;
sound_source dsbPneumaticSwitch;
sound_source dsbReverserKey; // hunter-121211
PSound dsbCouplerAttach; // Ra: w kabinie????
PSound dsbCouplerDetach; // Ra: w kabinie???
sound_source dsbCouplerAttach; // Ra: w kabinie????
sound_source dsbCouplerDetach; // Ra: w kabinie???
PSound dsbDieselIgnition; // Ra: w kabinie???
PSound dsbDoorClose; // Ra: w kabinie???
PSound dsbDoorOpen; // Ra: w kabinie???
sound_source dsbDieselIgnition; // Ra: w kabinie???
// Winger 010304
PSound dsbPantUp;
PSound dsbPantDown;
PSound dsbWejscie_na_bezoporow;
PSound dsbWejscie_na_drugi_uklad; // hunter-081211: poprawka literowki
sound_source dsbWejscie_na_bezoporow;
sound_source dsbWejscie_na_drugi_uklad; // hunter-081211: poprawka literowki
// PSound dsbHiss1;
// PSound dsbHiss2;
// McZapkie-280302
TRealSound rsBrake;
TRealSound rsSlippery;
TRealSound rsHiss; // upuszczanie
TRealSound rsHissU; // napelnianie
TRealSound rsHissE; // nagle
TRealSound rsHissX; // fala
TRealSound rsHissT; // czasowy
TRealSound rsSBHiss;
TRealSound rsRunningNoise;
TRealSound rsEngageSlippery;
TRealSound rsFadeSound;
sound_source rsBrake;
sound_source rsSlippery;
sound_source rsHiss; // upuszczanie
sound_source rsHissU; // napelnianie
sound_source rsHissE; // nagle
sound_source rsHissX; // fala
sound_source rsHissT; // czasowy
sound_source rsSBHiss;
sound_source rsRunningNoise;
sound_source rsEngageSlippery;
sound_source rsFadeSound;
PSound dsbHasler;
PSound dsbBuzzer;
PSound dsbSlipAlarm; // Bombardier 011010: alarm przy poslizgu dla 181/182
sound_source dsbHasler;
sound_source dsbBuzzer;
sound_source dsbSlipAlarm; // Bombardier 011010: alarm przy poslizgu dla 181/182
int iCabLightFlag; // McZapkie:120503: oswietlenie kabiny (0: wyl, 1: przyciemnione, 2: pelne)
bool bCabLight; // hunter-091012: czy swiatlo jest zapalone?
@@ -453,11 +442,10 @@ public: // reszta może by?publiczna
vector3 pMechSittingPosition; // ABu 180404
vector3 MirrorPosition(bool lewe);
private:
// PSound dsbBuzzer;
PSound dsbCouplerStretch;
PSound dsbEN57_CouplerStretch;
PSound dsbBufferClamp;
private:
sound_source dsbCouplerStretch;
sound_source dsbEN57_CouplerStretch;
sound_source dsbBufferClamp;
double fBlinkTimer;
float fHaslerTimer;
float fConverterTimer; // hunter-261211: dla przekaznika
@@ -509,5 +497,6 @@ public: // reszta może by?publiczna
inline TMoverParameters *Controlled() { return mvControlled; };
void DynamicSet(TDynamicObject *d);
void Silence();
};
//---------------------------------------------------------------------------

View File

@@ -196,8 +196,6 @@ TWorld::TWorld()
TWorld::~TWorld()
{
TrainDelete();
// Ground.Free(); //Ra: usunięcie obiektów przed usunięciem dźwięków - sypie się
TSoundsManager::Free();
}
void TWorld::TrainDelete(TDynamicObject *d)
@@ -234,7 +232,7 @@ bool TWorld::Init( GLFWwindow *Window ) {
"ShaXbee, Oli_EU, youBy, KURS90, Ra, hunter, szociu, Stele, Q, firleju and others\n" );
UILayer.set_background( "logo" );
#ifdef EU07_USE_OLD_SOUNDCODE
if( true == TSoundsManager::Init( glfwGetWin32Window( window ) ) ) {
WriteLog( "Sound subsystem setup complete" );
}
@@ -242,7 +240,7 @@ bool TWorld::Init( GLFWwindow *Window ) {
ErrorLog( "Sound subsystem setup failed" );
return false;
}
#endif
glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii
UILayer.set_progress(0.01);
UILayer.set_progress( "Loading scenery / Wczytywanie scenerii" );
@@ -689,7 +687,7 @@ void TWorld::OnKeyDown(int cKey)
vehicle->MoverParameters->DecBrakeMult())
if (Train)
{ // dźwięk oczywiście jest w kabinie
Train->play_sound( Train->dsbSwitch );
Train->dsbSwitch.play();
}
}
}
@@ -717,7 +715,7 @@ void TWorld::OnKeyDown(int cKey)
vehicle->iLights[CouplNr] = (vehicle->iLights[CouplNr] & ~mask) | set;
if (Train)
{ // Ra: ten dźwięk z kabiny to przegięcie, ale na razie zostawiam
Train->play_sound( Train->dsbSwitch );
Train->dsbSwitch.play();
}
}
}
@@ -737,7 +735,7 @@ void TWorld::OnKeyDown(int cKey)
if (vehicle->MoverParameters->IncLocalBrakeLevelFAST())
if (Train)
{ // dźwięk oczywiście jest w kabinie
Train->play_sound( Train->dsbPneumaticRelay );
Train->dsbPneumaticRelay.play();
}
}
}
@@ -756,7 +754,7 @@ void TWorld::OnKeyDown(int cKey)
if (vehicle->MoverParameters->DecLocalBrakeLevelFAST())
if (Train)
{ // dźwięk oczywiście jest w kabinie
Train->play_sound( Train->dsbPneumaticRelay );
Train->dsbPneumaticRelay.play();
}
}
}

View File

@@ -231,6 +231,9 @@
<ClCompile Include="audio.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="sound.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Globals.h">
@@ -452,6 +455,9 @@
<ClInclude Include="audio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="sound.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="maszyna.rc">

View File

@@ -14,6 +14,8 @@ http://mozilla.org/MPL/2.0/.
#include "logs.h"
#include "globals.h"
namespace gfx {
void
basic_vertex::serialize( std::ostream &s ) const {
@@ -47,14 +49,14 @@ basic_vertex::deserialize( std::istream &s ) {
// generic geometry bank class, allows storage, update and drawing of geometry chunks
// creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk
geometry_handle
geometry_bank::create( vertex_array &Vertices, unsigned int const Type ) {
gfx::geometry_handle
geometry_bank::create( gfx::vertex_array &Vertices, unsigned int const Type ) {
if( true == Vertices.empty() ) { return geometry_handle( 0, 0 ); }
if( true == Vertices.empty() ) { return { 0, 0 }; }
m_chunks.emplace_back( Vertices, Type );
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
gfx::geometry_handle chunkhandle { 0, static_cast<std::uint32_t>(m_chunks.size()) };
// template method implementation
create_( chunkhandle );
// all done
@@ -63,11 +65,11 @@ geometry_bank::create( vertex_array &Vertices, unsigned int const Type ) {
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool
geometry_bank::replace( vertex_array &Vertices, geometry_handle const &Geometry, std::size_t const Offset ) {
geometry_bank::replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
auto &chunk = geometry_bank::chunk( Geometry );
auto &chunk = gfx::geometry_bank::chunk( Geometry );
if( ( Offset == 0 )
&& ( Vertices.size() == chunk.vertices.size() ) ) {
@@ -78,7 +80,7 @@ geometry_bank::replace( vertex_array &Vertices, geometry_handle const &Geometry,
// ...otherwise we need to do some legwork
// NOTE: if the offset is larger than existing size of the chunk, it'll bridge the gap with 'blank' vertices
// TBD: we could bail out with an error instead if such request occurs
chunk.vertices.resize( Offset + Vertices.size(), basic_vertex() );
chunk.vertices.resize( Offset + Vertices.size(), gfx::basic_vertex() );
chunk.vertices.insert( std::end( chunk.vertices ), std::begin( Vertices ), std::end( Vertices ) );
}
// template method implementation
@@ -89,16 +91,16 @@ geometry_bank::replace( vertex_array &Vertices, geometry_handle const &Geometry,
// adds supplied vertex data at the end of specified chunk
bool
geometry_bank::append( vertex_array &Vertices, geometry_handle const &Geometry ) {
geometry_bank::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
if( ( Geometry.chunk == 0 ) || ( Geometry.chunk > m_chunks.size() ) ) { return false; }
return replace( Vertices, Geometry, geometry_bank::chunk( Geometry ).vertices.size() );
return replace( Vertices, Geometry, gfx::geometry_bank::chunk( Geometry ).vertices.size() );
}
// draws geometry stored in specified chunk
void
geometry_bank::draw( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
geometry_bank::draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
// template method implementation
draw_( Geometry, Units, Streams );
}
@@ -111,7 +113,7 @@ geometry_bank::release() {
}
vertex_array const &
geometry_bank::vertices( geometry_handle const &Geometry ) const {
geometry_bank::vertices( gfx::geometry_handle const &Geometry ) const {
return geometry_bank::chunk( Geometry ).vertices;
}
@@ -119,12 +121,12 @@ geometry_bank::vertices( geometry_handle const &Geometry ) const {
// opengl vbo-based variant of the geometry bank
GLuint opengl_vbogeometrybank::m_activebuffer { 0 }; // buffer bound currently on the opengl end, if any
unsigned int opengl_vbogeometrybank::m_activestreams { stream::none }; // currently enabled data type pointers
unsigned int opengl_vbogeometrybank::m_activestreams { gfx::stream::none }; // currently enabled data type pointers
std::vector<GLint> opengl_vbogeometrybank::m_activetexturearrays; // currently enabled texture coord arrays
// create() subclass details
void
opengl_vbogeometrybank::create_( geometry_handle const &Geometry ) {
opengl_vbogeometrybank::create_( gfx::geometry_handle const &Geometry ) {
// adding a chunk means we'll be (re)building the buffer, which will fill the chunk records, amongst other things.
// thus we don't need to initialize the values here
m_chunkrecords.emplace_back( chunk_record() );
@@ -134,7 +136,7 @@ opengl_vbogeometrybank::create_( geometry_handle const &Geometry ) {
// replace() subclass details
void
opengl_vbogeometrybank::replace_( geometry_handle const &Geometry ) {
opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
chunkrecord.is_good = false;
@@ -149,7 +151,7 @@ opengl_vbogeometrybank::replace_( geometry_handle const &Geometry ) {
// draw() subclass details
void
opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
opengl_vbogeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
if( m_buffer == 0 ) {
// if there's no buffer, we'll have to make one
@@ -176,7 +178,7 @@ opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, stream_units con
// TODO: allow to specify usage hint at the object creation, and pass it here
::glBufferData(
GL_ARRAY_BUFFER,
datasize * sizeof( basic_vertex ),
datasize * sizeof( gfx::basic_vertex ),
nullptr,
GL_STATIC_DRAW );
if( ::glGetError() == GL_OUT_OF_MEMORY ) {
@@ -193,13 +195,13 @@ opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, stream_units con
bind_buffer();
}
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
auto const &chunk = geometry_bank::chunk( Geometry );
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
if( false == chunkrecord.is_good ) {
// we may potentially need to upload new buffer data before we can draw it
::glBufferSubData(
GL_ARRAY_BUFFER,
chunkrecord.offset * sizeof( basic_vertex ),
chunkrecord.size * sizeof( basic_vertex ),
chunkrecord.offset * sizeof( gfx::basic_vertex ),
chunkrecord.size * sizeof( gfx::basic_vertex ),
chunk.vertices.data() );
chunkrecord.is_good = true;
}
@@ -229,7 +231,7 @@ opengl_vbogeometrybank::bind_buffer() {
::glBindBuffer( GL_ARRAY_BUFFER, m_buffer );
m_activebuffer = m_buffer;
m_activestreams = stream::none;
m_activestreams = gfx::stream::none;
}
void
@@ -250,34 +252,34 @@ opengl_vbogeometrybank::delete_buffer() {
}
void
opengl_vbogeometrybank::bind_streams( stream_units const &Units, unsigned int const Streams ) {
opengl_vbogeometrybank::bind_streams( gfx::stream_units const &Units, unsigned int const Streams ) {
if( Streams & stream::position ) {
::glVertexPointer( 3, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) );
if( Streams & gfx::stream::position ) {
::glVertexPointer( 3, GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) );
::glEnableClientState( GL_VERTEX_ARRAY );
}
else {
::glDisableClientState( GL_VERTEX_ARRAY );
}
// NOTE: normal and color streams share the data, making them effectively mutually exclusive
if( Streams & stream::normal ) {
::glNormalPointer( GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
if( Streams & gfx::stream::normal ) {
::glNormalPointer( GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
::glEnableClientState( GL_NORMAL_ARRAY );
}
else {
::glDisableClientState( GL_NORMAL_ARRAY );
}
if( Streams & stream::color ) {
::glColorPointer( 3, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
if( Streams & gfx::stream::color ) {
::glColorPointer( 3, GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
::glEnableClientState( GL_COLOR_ARRAY );
}
else {
::glDisableClientState( GL_COLOR_ARRAY );
}
if( Streams & stream::texture ) {
if( Streams & gfx::stream::texture ) {
for( auto unit : Units.texture ) {
::glClientActiveTexture( unit );
::glTexCoordPointer( 2, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) + 24 );
::glTexCoordPointer( 2, GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) + 24 );
::glEnableClientState( GL_TEXTURE_COORD_ARRAY );
}
m_activetexturearrays = Units.texture;
@@ -304,7 +306,7 @@ opengl_vbogeometrybank::release_streams() {
::glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
m_activestreams = stream::none;
m_activestreams = gfx::stream::none;
m_activetexturearrays.clear();
}
@@ -312,21 +314,21 @@ opengl_vbogeometrybank::release_streams() {
// create() subclass details
void
opengl_dlgeometrybank::create_( geometry_handle const &Geometry ) {
opengl_dlgeometrybank::create_( gfx::geometry_handle const &Geometry ) {
m_chunkrecords.emplace_back( chunk_record() );
}
// replace() subclass details
void
opengl_dlgeometrybank::replace_( geometry_handle const &Geometry ) {
opengl_dlgeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
delete_list( Geometry );
}
// draw() subclass details
void
opengl_dlgeometrybank::draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) {
opengl_dlgeometrybank::draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) {
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
if( chunkrecord.streams != Streams ) {
@@ -336,15 +338,15 @@ opengl_dlgeometrybank::draw_( geometry_handle const &Geometry, stream_units cons
// we don't have a list ready, so compile one
chunkrecord.streams = Streams;
chunkrecord.list = ::glGenLists( 1 );
auto const &chunk = geometry_bank::chunk( Geometry );
auto const &chunk = gfx::geometry_bank::chunk( Geometry );
::glNewList( chunkrecord.list, GL_COMPILE );
::glBegin( chunk.type );
for( auto const &vertex : chunk.vertices ) {
if( Streams & stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
else if( Streams & stream::color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
if( Streams & stream::texture ) { for( auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
if( Streams & stream::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
else if( Streams & gfx::stream::color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); }
if( Streams & gfx::stream::texture ) { for( auto unit : Units.texture ) { ::glMultiTexCoord2fv( unit, glm::value_ptr( vertex.texture ) ); } }
if( Streams & gfx::stream::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
}
::glEnd();
::glEndList();
@@ -362,19 +364,19 @@ opengl_dlgeometrybank::release_() {
::glDeleteLists( chunkrecord.list, 1 );
chunkrecord.list = 0;
}
chunkrecord.streams = stream::none;
chunkrecord.streams = gfx::stream::none;
}
}
void
opengl_dlgeometrybank::delete_list( geometry_handle const &Geometry ) {
opengl_dlgeometrybank::delete_list( gfx::geometry_handle const &Geometry ) {
// NOTE: given it's our own internal method we trust it to be called with valid parameters
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
if( chunkrecord.list != 0 ) {
::glDeleteLists( chunkrecord.list, 1 );
chunkrecord.list = 0;
}
chunkrecord.streams = stream::none;
chunkrecord.streams = gfx::stream::none;
}
// geometry bank manager, holds collection of geometry banks
@@ -387,41 +389,41 @@ geometrybank_manager::update() {
}
// creates a new geometry bank. returns: handle to the bank or NULL
geometrybank_handle
gfx::geometrybank_handle
geometrybank_manager::create_bank() {
if( true == Global::bUseVBO ) { m_geometrybanks.emplace_back( std::make_shared<opengl_vbogeometrybank>(), std::chrono::steady_clock::time_point() ); }
else { m_geometrybanks.emplace_back( std::make_shared<opengl_dlgeometrybank>(), std::chrono::steady_clock::time_point() ); }
// NOTE: handle is effectively (index into chunk array + 1) this leaves value of 0 to serve as error/empty handle indication
return geometrybank_handle( m_geometrybanks.size(), 0 );
return { m_geometrybanks.size(), 0 };
}
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
geometry_handle
geometrybank_manager::create_chunk( vertex_array &Vertices, geometrybank_handle const &Geometry, int const Type ) {
gfx::geometry_handle
geometrybank_manager::create_chunk( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) {
auto const newchunkhandle = bank( Geometry ).first->create( Vertices, Type );
if( newchunkhandle.chunk != 0 ) { return geometry_handle( Geometry.bank, newchunkhandle.chunk ); }
else { return geometry_handle( 0, 0 ); }
if( newchunkhandle.chunk != 0 ) { return { Geometry.bank, newchunkhandle.chunk }; }
else { return { 0, 0 }; }
}
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool
geometrybank_manager::replace( vertex_array &Vertices, geometry_handle const &Geometry, std::size_t const Offset ) {
geometrybank_manager::replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
return bank( Geometry ).first->replace( Vertices, Geometry, Offset );
}
// adds supplied vertex data at the end of specified chunk
bool
geometrybank_manager::append( vertex_array &Vertices, geometry_handle const &Geometry ) {
geometrybank_manager::append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
return bank( Geometry ).first->append( Vertices, Geometry );
}
// draws geometry stored in specified chunk
void
geometrybank_manager::draw( geometry_handle const &Geometry, unsigned int const Streams ) {
geometrybank_manager::draw( gfx::geometry_handle const &Geometry, unsigned int const Streams ) {
if( Geometry == null_handle ) { return; }
@@ -432,8 +434,10 @@ geometrybank_manager::draw( geometry_handle const &Geometry, unsigned int const
}
// provides direct access to vertex data of specfied chunk
vertex_array const &
geometrybank_manager::vertices( geometry_handle const &Geometry ) const {
gfx::vertex_array const &
geometrybank_manager::vertices( gfx::geometry_handle const &Geometry ) const {
return bank( Geometry ).first->vertices( Geometry );
}
} // namespace gfx

View File

@@ -18,6 +18,8 @@ http://mozilla.org/MPL/2.0/.
#endif
#include "ResourceManager.h"
namespace gfx {
struct basic_vertex {
glm::vec3 position; // 3d space
@@ -93,36 +95,36 @@ public:
// methods:
// creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk or NULL
geometry_handle
create( vertex_array &Vertices, unsigned int const Type );
gfx::geometry_handle
create( gfx::vertex_array &Vertices, unsigned int const Type );
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool
replace( vertex_array &Vertices, geometry_handle const &Geometry, std::size_t const Offset = 0 );
replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 );
// adds supplied vertex data at the end of specified chunk
bool
append( vertex_array &Vertices, geometry_handle const &Geometry );
append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
// draws geometry stored in specified chunk
void
draw( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams = basic_streams );
draw( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams = basic_streams );
// draws geometry stored in supplied list of chunks
template <typename Iterator_>
void
draw( Iterator_ First, Iterator_ Last, stream_units const &Units, unsigned int const Streams = basic_streams ) { while( First != Last ) { draw( *First, Units, Streams ); ++First; } }
draw( Iterator_ First, Iterator_ Last, gfx::stream_units const &Units, unsigned int const Streams = basic_streams ) { while( First != Last ) { draw( *First, Units, Streams ); ++First; } }
// frees subclass-specific resources associated with the bank, typically called when the bank wasn't in use for a period of time
void
release();
// provides direct access to vertex data of specfied chunk
vertex_array const &
vertices( geometry_handle const &Geometry ) const;
gfx::vertex_array const &
vertices( gfx::geometry_handle const &Geometry ) const;
protected:
// types:
struct geometry_chunk {
unsigned int type; // kind of geometry used by the chunk
vertex_array vertices; // geometry data
gfx::vertex_array vertices; // geometry data
// NOTE: constructor doesn't copy provided vertex data, but moves it
geometry_chunk( vertex_array &Vertices, unsigned int Type ) :
type( Type )
geometry_chunk( gfx::vertex_array &Vertices, unsigned int Type ) :
type( Type )
{
vertices.swap( Vertices );
}
@@ -133,11 +135,11 @@ protected:
// methods
inline
geometry_chunk &
chunk( geometry_handle const Geometry ) {
chunk( gfx::geometry_handle const Geometry ) {
return m_chunks[ Geometry.chunk - 1 ]; }
inline
geometry_chunk const &
chunk( geometry_handle const Geometry ) const {
chunk( gfx::geometry_handle const Geometry ) const {
return m_chunks[ Geometry.chunk - 1 ]; }
// members:
@@ -146,11 +148,11 @@ protected:
private:
// methods:
// create() subclass details
virtual void create_( geometry_handle const &Geometry ) = 0;
virtual void create_( gfx::geometry_handle const &Geometry ) = 0;
// replace() subclass details
virtual void replace_( geometry_handle const &Geometry ) = 0;
virtual void replace_( gfx::geometry_handle const &Geometry ) = 0;
// draw() subclass details
virtual void draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams ) = 0;
virtual void draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams ) = 0;
// resource release subclass details
virtual void release_() = 0;
};
@@ -170,7 +172,7 @@ public:
void
reset() {
m_activebuffer = 0;
m_activestreams = stream::none; }
m_activestreams = gfx::stream::none; }
private:
// types:
@@ -185,13 +187,13 @@ private:
// methods:
// create() subclass details
void
create_( geometry_handle const &Geometry );
create_( gfx::geometry_handle const &Geometry );
// replace() subclass details
void
replace_( geometry_handle const &Geometry );
replace_( gfx::geometry_handle const &Geometry );
// draw() subclass details
void
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams );
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams );
// release() subclass details
void
release_();
@@ -201,7 +203,7 @@ private:
delete_buffer();
static
void
bind_streams( stream_units const &Units, unsigned int const Streams );
bind_streams( gfx::stream_units const &Units, unsigned int const Streams );
static
void
release_streams();
@@ -240,18 +242,18 @@ private:
// methods:
// create() subclass details
void
create_( geometry_handle const &Geometry );
create_( gfx::geometry_handle const &Geometry );
// replace() subclass details
void
replace_( geometry_handle const &Geometry );
replace_( gfx::geometry_handle const &Geometry );
// draw() subclass details
void
draw_( geometry_handle const &Geometry, stream_units const &Units, unsigned int const Streams );
draw_( gfx::geometry_handle const &Geometry, gfx::stream_units const &Units, unsigned int const Streams );
// release () subclass details
void
release_();
void
delete_list( geometry_handle const &Geometry );
delete_list( gfx::geometry_handle const &Geometry );
// members:
chunkrecord_sequence m_chunkrecords; // helper data for all stored geometry chunks, in matching order
@@ -269,20 +271,20 @@ public:
// performs a resource sweep
void update();
// creates a new geometry bank. returns: handle to the bank or NULL
geometrybank_handle
gfx::geometrybank_handle
create_bank();
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
geometry_handle
create_chunk( vertex_array &Vertices, geometrybank_handle const &Geometry, int const Type );
gfx::geometry_handle
create_chunk( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type );
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool
replace( vertex_array &Vertices, geometry_handle const &Geometry, std::size_t const Offset = 0 );
replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 );
// adds supplied vertex data at the end of specified chunk
bool
append( vertex_array &Vertices, geometry_handle const &Geometry );
append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
// draws geometry stored in specified chunk
void
draw( geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
draw( gfx::geometry_handle const &Geometry, unsigned int const Streams = basic_streams );
template <typename Iterator_>
void
draw( Iterator_ First, Iterator_ Last, unsigned int const Streams = basic_streams ) {
@@ -290,10 +292,10 @@ public:
draw( *First, Streams );
++First; } }
// provides direct access to vertex data of specfied chunk
vertex_array const &
vertices( geometry_handle const &Geometry ) const;
gfx::vertex_array const &
vertices( gfx::geometry_handle const &Geometry ) const;
// sets target texture unit for the texture data stream
stream_units &
gfx::stream_units &
units() { return m_units; }
private:
@@ -307,21 +309,23 @@ private:
// members:
geometrybanktimepointpair_sequence m_geometrybanks;
garbage_collector<geometrybanktimepointpair_sequence> m_garbagecollector { m_geometrybanks, 60, 120, "geometry buffer" };
stream_units m_units;
gfx::stream_units m_units;
// methods
inline
bool
valid( geometry_handle const &Geometry ) const {
valid( gfx::geometry_handle const &Geometry ) const {
return ( ( Geometry.bank != 0 )
&& ( Geometry.bank <= m_geometrybanks.size() ) ); }
inline
geometrybanktimepointpair_sequence::value_type &
bank( geometry_handle const Geometry ) {
bank( gfx::geometry_handle const Geometry ) {
return m_geometrybanks[ Geometry.bank - 1 ]; }
inline
geometrybanktimepointpair_sequence::value_type const &
bank( geometry_handle const Geometry ) const {
bank( gfx::geometry_handle const Geometry ) const {
return m_geometrybanks[ Geometry.bank - 1 ]; }
};
};
} // namespace gfx

View File

@@ -298,7 +298,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
auto const geometrybank = m_geometry.create_bank();
float const size = 2.5f;
m_billboardgeometry = m_geometry.create_chunk(
vertex_array{
gfx::vertex_array{
{ { -size, size, 0.f }, glm::vec3(), { 1.f, 1.f } },
{ { size, size, 0.f }, glm::vec3(), { 0.f, 1.f } },
{ { -size, -size, 0.f }, glm::vec3(), { 1.f, 0.f } },
@@ -1129,7 +1129,7 @@ opengl_renderer::Render( world_environment *Environment ) {
Environment->m_skydome.Render();
if( true == Global::bUseVBO ) {
// skydome uses a custom vbo which could potentially confuse the main geometry system. hardly elegant but, eh
opengl_vbogeometrybank::reset();
gfx::opengl_vbogeometrybank::reset();
}
// stars
if( Environment->m_stars.m_stars != nullptr ) {
@@ -1263,36 +1263,36 @@ opengl_renderer::Render( world_environment *Environment ) {
// geometry methods
// creates a new geometry bank. returns: handle to the bank or NULL
geometrybank_handle
gfx::geometrybank_handle
opengl_renderer::Create_Bank() {
return m_geometry.create_bank();
}
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
geometry_handle
opengl_renderer::Insert( vertex_array &Vertices, geometrybank_handle const &Geometry, int const Type ) {
gfx::geometry_handle
opengl_renderer::Insert( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type ) {
return m_geometry.create_chunk( Vertices, Geometry, Type );
}
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool
opengl_renderer::Replace( vertex_array &Vertices, geometry_handle const &Geometry, std::size_t const Offset ) {
opengl_renderer::Replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset ) {
return m_geometry.replace( Vertices, Geometry, Offset );
}
// adds supplied vertex data at the end of specified chunk
bool
opengl_renderer::Append( vertex_array &Vertices, geometry_handle const &Geometry ) {
opengl_renderer::Append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry ) {
return m_geometry.append( Vertices, Geometry );
}
// provides direct access to vertex data of specfied chunk
vertex_array const &
opengl_renderer::Vertices( geometry_handle const &Geometry ) const {
gfx::vertex_array const &
opengl_renderer::Vertices( gfx::geometry_handle const &Geometry ) const {
return m_geometry.vertices( Geometry );
}
@@ -2262,7 +2262,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
::glDisable( GL_LIGHTING );
// main draw call
m_geometry.draw( Submodel->m_geometry, color_streams );
m_geometry.draw( Submodel->m_geometry, gfx::color_streams );
// post-draw reset
::glPopAttrib();

View File

@@ -156,20 +156,20 @@ public:
// geometry methods
// NOTE: hands-on geometry management is exposed as a temporary measure; ultimately all visualization data should be generated/handled automatically by the renderer itself
// creates a new geometry bank. returns: handle to the bank or NULL
geometrybank_handle
gfx::geometrybank_handle
Create_Bank();
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
geometry_handle
Insert( vertex_array &Vertices, geometrybank_handle const &Geometry, int const Type );
gfx::geometry_handle
Insert( gfx::vertex_array &Vertices, gfx::geometrybank_handle const &Geometry, int const Type );
// replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool
Replace( vertex_array &Vertices, geometry_handle const &Geometry, std::size_t const Offset = 0 );
Replace( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry, std::size_t const Offset = 0 );
// adds supplied vertex data at the end of specified chunk
bool
Append( vertex_array &Vertices, geometry_handle const &Geometry );
Append( gfx::vertex_array &Vertices, gfx::geometry_handle const &Geometry );
// provides direct access to vertex data of specfied chunk
vertex_array const &
Vertices( geometry_handle const &Geometry ) const;
gfx::vertex_array const &
Vertices( gfx::geometry_handle const &Geometry ) const;
// material methods
material_handle
Fetch_Material( std::string const &Filename, bool const Loadnow = true );
@@ -337,12 +337,12 @@ private:
// members
GLFWwindow *m_window { nullptr };
geometrybank_manager m_geometry;
gfx::geometrybank_manager m_geometry;
material_manager m_materials;
texture_manager m_textures;
opengllight_array m_lights;
geometry_handle m_billboardgeometry { 0, 0 };
gfx::geometry_handle m_billboardgeometry { 0, 0 };
texture_handle m_glaretexture { -1 };
texture_handle m_suntexture { -1 };
texture_handle m_moontexture { -1 };

View File

@@ -125,11 +125,13 @@ basic_cell::update_sounds() {
// sounds
auto const deltatime = Timer::GetDeltaRenderTime();
for( auto *sound : m_sounds ) {
#ifdef EU07_USE_OLD_SOUNDCODE
if( ( sound->GetStatus() & DSBSTATUS_PLAYING ) == DSBPLAY_LOOPING ) {
sound->Play( 1, DSBPLAY_LOOPING, true, sound->vSoundPosition );
sound->AdjFreq( 1.0, deltatime );
}
#else
#endif
}
// TBD, TODO: move to sound renderer
for( auto *path : m_paths ) {
@@ -348,7 +350,11 @@ basic_cell::insert( TAnimModel *Instance ) {
// adds provided sound instance to the cell
void
#ifdef EU07_USE_OLD_SOUNDCODE
basic_cell::insert( TTextSound *Sound ) {
#else
basic_cell::insert( sound_source *Sound ) {
#endif
m_active = true;
@@ -514,7 +520,7 @@ basic_cell::center( glm::dvec3 Center ) {
// generates renderable version of held non-instanced geometry
void
basic_cell::create_geometry( geometrybank_handle const &Bank ) {
basic_cell::create_geometry( gfx::geometrybank_handle const &Bank ) {
if( false == m_active ) { return; } // nothing to do here
@@ -1171,8 +1177,13 @@ basic_region::insert_instance( TAnimModel *Instance, scratch_data &Scratchpad )
// inserts provided sound in the region
void
#ifdef EU07_USE_OLD_SOUNDCODE
basic_region::insert_sound( TTextSound *Sound, scratch_data &Scratchpad ) {
#else
basic_region::insert_sound( sound_source *Sound, scratch_data &Scratchpad ) {
#endif
#ifdef EU07_USE_OLD_SOUNDCODE
// NOTE: bounding area isn't present/filled until track class and wrapper refactoring is done
auto location = Sound->location();
@@ -1184,6 +1195,8 @@ basic_region::insert_sound( TTextSound *Sound, scratch_data &Scratchpad ) {
// tracks are guaranteed to hava a name so we can skip the check
ErrorLog( "Bad scenario: sound node \"" + Sound->name() + "\" placed in location outside region bounds (" + to_string( location ) + ")" );
}
#else
#endif
}
// inserts provided event launcher in the region

17
scene.h
View File

@@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
#include "scenenode.h"
#include "track.h"
#include "traction.h"
#include "sound.h"
namespace scene {
@@ -104,7 +105,11 @@ public:
insert( TAnimModel *Instance );
// adds provided sound instance to the cell
void
#ifdef EU07_USE_OLD_SOUNDCODE
insert( TTextSound *Sound );
#else
insert( sound_source *Sound );
#endif
// adds provided event launcher to the cell
void
insert( TEventLauncher *Launcher );
@@ -131,7 +136,7 @@ public:
center( glm::dvec3 Center );
// generates renderable version of held non-instanced geometry in specified geometry bank
void
create_geometry( geometrybank_handle const &Bank );
create_geometry( gfx::geometrybank_handle const &Bank );
// provides access to bounding area data
bounding_area const &
area() const {
@@ -144,7 +149,11 @@ private:
using path_sequence = std::vector<TTrack *>;
using traction_sequence = std::vector<TTraction *>;
using instance_sequence = std::vector<TAnimModel *>;
#ifdef EU07_USE_OLD_SOUNDCODE
using sound_sequence = std::vector<TTextSound *>;
#else
using sound_sequence = std::vector<sound_source *>;
#endif
using eventlauncher_sequence = std::vector<TEventLauncher *>;
// methods
void
@@ -258,7 +267,7 @@ private:
shapenode_sequence m_shapes; // large pieces of opaque geometry and (legacy) terrain
// TODO: implement dedicated, higher fidelity, fixed resolution terrain mesh item
// gfx renderer data
geometrybank_handle m_geometrybank;
gfx::geometrybank_handle m_geometrybank;
bool m_geometrycreated { false };
};
@@ -311,7 +320,11 @@ public:
insert_instance( TAnimModel *Instance, scratch_data &Scratchpad );
// inserts provided sound in the region
void
#ifdef EU07_USE_OLD_SOUNDCODE
insert_sound( TTextSound *Sound, scratch_data &Scratchpad );
#else
insert_sound( sound_source *Sound, scratch_data &Scratchpad );
#endif
// inserts provided event launcher in the region
void
insert_launcher( TEventLauncher *Launcher, scratch_data &Scratchpad );

View File

@@ -80,7 +80,7 @@ shape_node::shapenode_data::serialize( std::ostream &Output ) const {
// vertex count, followed by vertex data
sn_utils::ls_uint32( Output, vertices.size() );
for( auto const &vertex : vertices ) {
basic_vertex(
gfx::basic_vertex(
glm::vec3{ vertex.position - origin },
vertex.normal,
vertex.texture )
@@ -109,7 +109,7 @@ shape_node::shapenode_data::deserialize( std::istream &Input ) {
// NOTE: geometry handle is acquired during geometry creation
// vertex data
vertices.resize( sn_utils::ld_uint32( Input ) );
basic_vertex localvertex;
gfx::basic_vertex localvertex;
for( auto &vertex : vertices ) {
localvertex.deserialize( Input );
vertex.position = origin + glm::dvec3{ localvertex.position };
@@ -417,9 +417,9 @@ shape_node::merge( shape_node &Shape ) {
// generates renderable version of held non-instanced geometry in specified geometry bank
void
shape_node::create_geometry( geometrybank_handle const &Bank ) {
shape_node::create_geometry( gfx::geometrybank_handle const &Bank ) {
vertex_array vertices; vertices.reserve( m_data.vertices.size() );
gfx::vertex_array vertices; vertices.reserve( m_data.vertices.size() );
for( auto const &vertex : m_data.vertices ) {
vertices.emplace_back(
@@ -464,7 +464,7 @@ lines_node::linesnode_data::serialize( std::ostream &Output ) const {
// vertex count, followed by vertex data
sn_utils::ls_uint32( Output, vertices.size() );
for( auto const &vertex : vertices ) {
basic_vertex(
gfx::basic_vertex(
glm::vec3{ vertex.position - origin },
vertex.normal,
vertex.texture )
@@ -489,7 +489,7 @@ lines_node::linesnode_data::deserialize( std::istream &Input ) {
// NOTE: geometry handle is acquired during geometry creation
// vertex data
vertices.resize( sn_utils::ld_uint32( Input ) );
basic_vertex localvertex;
gfx::basic_vertex localvertex;
for( auto &vertex : vertices ) {
localvertex.deserialize( Input );
vertex.position = origin + glm::dvec3{ localvertex.position };
@@ -637,9 +637,9 @@ lines_node::merge( lines_node &Lines ) {
// generates renderable version of held non-instanced geometry in specified geometry bank
void
lines_node::create_geometry( geometrybank_handle const &Bank ) {
lines_node::create_geometry( gfx::geometrybank_handle const &Bank ) {
vertex_array vertices; vertices.reserve( m_data.vertices.size() );
gfx::vertex_array vertices; vertices.reserve( m_data.vertices.size() );
for( auto const &vertex : m_data.vertices ) {
vertices.emplace_back(

View File

@@ -93,7 +93,7 @@ public:
lighting_data lighting;
// geometry data
glm::dvec3 origin; // world position of the relative coordinate system origin
geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer
gfx::geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer
std::vector<world_vertex> vertices; // world space source data of the geometry
// methods:
// sends content of the struct to provided stream
@@ -122,7 +122,7 @@ public:
merge( shape_node &Shape );
// generates renderable version of held non-instanced geometry in specified geometry bank
void
create_geometry( geometrybank_handle const &Bank );
create_geometry( gfx::geometrybank_handle const &Bank );
// calculates shape's bounding radius
void
compute_radius();
@@ -182,7 +182,7 @@ public:
lighting_data lighting;
// geometry data
glm::dvec3 origin; // world position of the relative coordinate system origin
geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer
gfx::geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer
std::vector<world_vertex> vertices; // world space source data of the geometry
// methods:
// sends content of the struct to provided stream
@@ -208,7 +208,7 @@ public:
merge( lines_node &Lines );
// generates renderable version of held non-instanced geometry in specified geometry bank
void
create_geometry( geometrybank_handle const &Bank );
create_geometry( gfx::geometrybank_handle const &Bank );
// calculates shape's bounding radius
void
compute_radius();

View File

@@ -460,7 +460,10 @@ state_manager::deserialize_node( cParser &Input, scene::scratch_data &Scratchpad
auto *sound { deserialize_sound( Input, Scratchpad, nodedata ) };
if( false == simulation::Sounds.insert( sound ) ) {
#ifdef EU07_USE_OLD_SOUNDCODE
ErrorLog( "Bad scenario: sound node with duplicate name \"" + sound->m_name + "\" encountered in file \"" + Input.Name() + "\" (line " + std::to_string( inputline ) + ")" );
#else
#endif
}
simulation::Region->insert_sound( sound, Scratchpad );
}
@@ -830,7 +833,11 @@ state_manager::deserialize_dynamic( cParser &Input, scene::scratch_data &Scratch
return vehicle;
}
#ifdef EU07_USE_OLD_SOUNDCODE
TTextSound *
#else
sound_source *
#endif
state_manager::deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata ) {
glm::dvec3 location;
@@ -842,9 +849,14 @@ state_manager::deserialize_sound( cParser &Input, scene::scratch_data &Scratchpa
// adjust location
location = transform( location, Scratchpad );
#ifdef EU07_USE_OLD_SOUNDCODE
auto const soundname { Input.getToken<std::string>() };
auto *sound = new TTextSound( soundname, Nodedata.range_max, location.x, location.y, location.z, false, false, Nodedata.range_min );
sound->name( Nodedata.name );
#else
auto *sound = new sound_source();
sound->deserialize( Input.getToken<std::string>(), sound_type::single );
#endif
skip_until( Input, "endsound" );

View File

@@ -17,7 +17,7 @@ http://mozilla.org/MPL/2.0/.
#include "track.h"
#include "traction.h"
#include "tractionpower.h"
#include "realsound.h"
#include "sound.h"
#include "animmodel.h"
#include "dynobj.h"
#include "driver.h"
@@ -64,7 +64,11 @@ private:
TEventLauncher * deserialize_eventlauncher( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
TAnimModel * deserialize_model( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
TDynamicObject * deserialize_dynamic( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
#ifdef EU07_USE_OLD_SOUNDCODE
TTextSound * deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
#else
sound_source * deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata );
#endif
// skips content of stream until specified token
void skip_until( cParser &Input, std::string const &Token );
// transforms provided location by specifed rotation and offset

66
sound.cpp Normal file
View File

@@ -0,0 +1,66 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "sound.h"
// restores state of the class from provided data stream
sound_source &
sound_source::deserialize( std::string const &Input, sound_type const Legacytype, int const Legacyparameters ) {
return deserialize( cParser{ Input }, Legacytype, Legacyparameters );
}
sound_source &
sound_source::deserialize( cParser &Input, sound_type const Legacytype, int const Legacyparameters ) {
// TODO: implement block type config parsing
switch( Legacytype ) {
case sound_type::single: {
// single sample only
Input.getTokens( 1, true, "\n\r\t ,;" );
break;
}
case sound_type::multipart: {
// three samples: start, middle, stop
Input.getTokens( 3, true, "\n\r\t ,;" );
break;
}
default: {
break;
}
}
if( Legacyparameters & sound_parameters::range ) {
Input.getTokens( 1, false );
}
if( Legacyparameters & sound_parameters::amplitude ) {
Input.getTokens( 2, false );
}
if( Legacyparameters & sound_parameters::frequency ) {
Input.getTokens( 2, false );
}
return *this;
}
// issues contextual play commands for the audio renderer
void
sound_source::play() {
}
bool
sound_source::empty() const {
return true;
}
//---------------------------------------------------------------------------

69
sound.h Normal file
View File

@@ -0,0 +1,69 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "audiorenderer.h"
#include "parser.h"
#include "names.h"
enum sound_type {
single,
multipart
};
enum sound_parameters {
none,
range = 0x1,
amplitude = 0x2,
frequency = 0x4
};
// mini controller and audio dispatcher; issues play commands for the audio renderer,
// updates parameters of assigned audio sources for the playback duration
// TODO: move to simulation namespace after clean up of owner classes
class sound_source {
public:
// methods
// restores state of the class from provided data stream
sound_source &
deserialize( cParser &Input, sound_type const Legacytype, int const Legacyparameters = sound_parameters::none );
sound_source &
deserialize( std::string const &Input, sound_type const Legacytype, int const Legacyparameters = sound_parameters::none );
// issues contextual play commands for the audio renderer
void
play();
// sets volume of audio streams associated with this source
sound_source &
volume( float const Volume );
// sound source name setter/getter
void
name( std::string Name );
std::string const &
name() const;
// returns true if there isn't any sound buffer associated with the object, false otherwise
bool
empty() const;
private:
// members
std::string m_name;
};
// sound source name setter/getter
inline void sound_source::name( std::string Name ) { m_name = Name; }
inline std::string const & sound_source::name() const { return m_name; }
// collection of generators for power grid present in the scene
class sound_table : public basic_table<sound_source> {
};
//---------------------------------------------------------------------------