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

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 { else {
// new, block type config // new, block type config
// TODO: rework the base part into yaml-compatible flow style mapping // TODO: rework the base part into yaml-compatible flow style mapping
cParser mappingparser( Parser.getToken<std::string>( false, "}" ) ); while( true == Load_mapping( Parser ) ) {
submodelname = mappingparser.getToken<std::string>( false );
// new, variable length section
while( true == Load_mapping( mappingparser ) ) {
; // all work done by while() ; // all work done by while()
} }
} }
@@ -77,27 +74,13 @@ void TButton::Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2) {
bool bool
TButton::Load_mapping( cParser &Input ) { TButton::Load_mapping( cParser &Input ) {
if( false == Input.getTokens( 2, true, " ,\n\r\t" ) ) { // token can be a key or block end
return false; 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 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 void
TButton::play() { TButton::play() {
play( if( m_state == true ) { m_soundfxincrease.play(); }
m_state == true ? else { m_soundfxdecrease.play(); }
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;
} }

View File

@@ -22,8 +22,8 @@ class TButton
bool m_state { false }; bool m_state { false };
bool const *bData { nullptr }; bool const *bData { nullptr };
int iFeedbackBit { 0 }; // Ra: bit informacji zwrotnej, do wyprowadzenia na pulpit int iFeedbackBit { 0 }; // Ra: bit informacji zwrotnej, do wyprowadzenia na pulpit
PSound m_soundfxincrease { nullptr }; // sound associated with increasing control's value sound_source m_soundfxincrease; // sound associated with increasing control's value
PSound m_soundfxdecrease { nullptr }; // sound associated with decreasing control's value sound_source m_soundfxdecrease; // sound associated with decreasing control's value
// methods // methods
// imports member data pair from the config file // imports member data pair from the config file
bool bool
@@ -31,10 +31,6 @@ class TButton
// plays the sound associated with current state // plays the sound associated with current state
void void
play(); play();
// plays specified sound
static
void
play( PSound Sound );
public: public:
TButton() = default; TButton() = default;
@@ -42,14 +38,10 @@ class TButton
inline void FeedbackBitSet(int const i) { inline void FeedbackBitSet(int const i) {
iFeedbackBit = 1 << i; }; iFeedbackBit = 1 << i; };
void Turn( bool const State ); void Turn( bool const State );
inline void TurnOn() { inline
Turn( true ); }; bool Active() {
inline void TurnOff() { return ( ( pModelOn != nullptr )
Turn( false ); }; || ( pModelOff != nullptr ) ); }
inline void Switch() {
Turn( !m_state ); };
inline bool Active() {
return (pModelOn) || (pModelOff); };
void Update(); void Update();
void Init(std::string const &asName, TModel3d *pModel, bool bNewOn = false); void Init(std::string const &asName, TModel3d *pModel, bool bNewOn = false);
void Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2 = NULL); 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 TSubModel; // fragment modelu (tu do wyświetlania terenu)
class TMemCell; // komórka pamięci class TMemCell; // komórka pamięci
class cParser; class cParser;
#ifdef EU07_USE_OLD_SOUNDCODE
class TRealSound; // dźwięk ze współrzędnymi XYZ class TRealSound; // dźwięk ze współrzędnymi XYZ
class TTextSound; // dźwięk ze stenogramem class TTextSound; // dźwięk ze stenogramem
#else
class sound_source;
#endif
class TEventLauncher; class TEventLauncher;
class TTraction; // drut class TTraction; // drut
class TTractionPowerSource; // zasilanie drutów 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 if (go == cm_Unknown) // jeśli nie było komendy wcześniej
go = cm_Ready; // gotów do odjazdu z W4 (semafor może go = cm_Ready; // gotów do odjazdu z W4 (semafor może
// zatrzymać) // 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; iDrivigFlags |= moveGuardSignal;
continue; // nie analizować prędkości continue; // nie analizować prędkości
} // koniec startu z zatrzymania } // koniec startu z zatrzymania
@@ -2572,9 +2572,12 @@ bool TController::DecBrake()
bool TController::IncSpeed() bool TController::IncSpeed()
{ // zwiększenie prędkości; zwraca false, jeśli dalej się nie da zwiększać { // 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) // jeśli jest dźwięk kierownika
if (tsGuardSignal->GetStatus() & DSBSTATUS_PLAYING) // jeśli gada, to nie jedziemy if (tsGuardSignal->GetStatus() & DSBSTATUS_PLAYING) // jeśli gada, to nie jedziemy
return false; return false;
#else
#endif
bool OK = true; bool OK = true;
if( ( iDrivigFlags & moveDoorOpened ) if( ( iDrivigFlags & moveDoorOpened )
&& ( VelDesired > 0.0 ) ) { // to prevent door shuffle on stop && ( 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 NewCommand = Global::asCurrentSceneryPath + NewCommand + ".wav"; // na razie jeden
if (FileExists(NewCommand)) if (FileExists(NewCommand))
{ // wczytanie dźwięku odjazdu podawanego bezpośrenido { // wczytanie dźwięku odjazdu podawanego bezpośrenido
tsGuardSignal = new TTextSound(NewCommand, 30, pVehicle->GetPosition().x, #ifdef EU07_USE_OLD_SOUNDCODE
pVehicle->GetPosition().y, pVehicle->GetPosition().z, tsGuardSignal =
false); new TTextSound(
// rsGuardSignal->Stop(); NewCommand, 30,
pVehicle->GetPosition().x, pVehicle->GetPosition().y, pVehicle->GetPosition().z,
false);
#else
#endif
iGuardRadio = 0; // nie przez radio iGuardRadio = 0; // nie przez radio
} }
else 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č NewCommand = NewCommand.insert(NewCommand.find_last_of("."),"radio"); // wstawienie przed kropkč
if (FileExists(NewCommand)) if (FileExists(NewCommand))
{ // wczytanie dźwięku odjazdu w wersji radiowej (słychać tylko w kabinie) { // wczytanie dźwięku odjazdu w wersji radiowej (słychać tylko w kabinie)
tsGuardSignal = new TTextSound(NewCommand, -1, pVehicle->GetPosition().x, #ifdef EU07_USE_OLD_SOUNDCODE
pVehicle->GetPosition().y, pVehicle->GetPosition().z, tsGuardSignal =
false); new TTextSound(
NewCommand, -1,
pVehicle->GetPosition().x, pVehicle->GetPosition().y, pVehicle->GetPosition().z,
false);
#else
#endif
iGuardRadio = iRadioChannel; iGuardRadio = iRadioChannel;
} }
} }
@@ -4472,7 +4484,10 @@ TController::UpdateSituation(double dt) {
->DoorOpenCtrl ) // jeśli drzwi niesterowane przez maszynistę ->DoorOpenCtrl ) // jeśli drzwi niesterowane przez maszynistę
Doors( false ); // a EZT zamknie dopiero po odegraniu komunikatu kierownika Doors( false ); // a EZT zamknie dopiero po odegraniu komunikatu kierownika
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal->Stop(); tsGuardSignal->Stop();
#else
#endif
// w zasadzie to powinien mieć flagę, czy jest dźwiękiem radiowym, czy // w zasadzie to powinien mieć flagę, czy jest dźwiękiem radiowym, czy
// bezpośrednim // bezpośrednim
// albo trzeba zrobić dwa dźwięki, jeden bezpośredni, słyszalny w // 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. // obsługę kanałów radiowych itd.
if( !iGuardRadio ) { if( !iGuardRadio ) {
// jeśli nie przez radio // jeśli nie przez radio
#ifdef EU07_USE_OLD_SOUNDCODE
tsGuardSignal->Play( 1.0, 0, !FreeFlyModeFlag, pVehicle->GetPosition() ); // dla true jest głośniej tsGuardSignal->Play( 1.0, 0, !FreeFlyModeFlag, pVehicle->GetPosition() ); // dla true jest głośniej
#else
#endif
} }
else { else {
// if (iGuardRadio==iRadioChannel) //zgodność kanału // if (iGuardRadio==iRadioChannel) //zgodność kanału
@@ -4490,7 +4508,10 @@ TController::UpdateSituation(double dt) {
// przy braku reakcji // przy braku reakcji
if( SquareMagnitude( pVehicle->GetPosition() - Global::pCameraPosition ) < 2000 * 2000 ) { if( SquareMagnitude( pVehicle->GetPosition() - Global::pCameraPosition ) < 2000 * 2000 ) {
// w odległości mniejszej niż 2km // 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 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 TTrainParameters *TrainParams = nullptr; // rozkład jazdy zawsze jest, nawet jeśli pusty
int iRadioChannel = 1; // numer aktualnego kanału radiowego int iRadioChannel = 1; // numer aktualnego kanału radiowego
int iGuardRadio = 0; // numer kanału radiowego kierownika (0, gdy nie używa radia) int iGuardRadio = 0; // numer kanału radiowego kierownika (0, gdy nie używa radia)
/*
TTextSound *tsGuardSignal = nullptr; // komunikat od kierownika TTextSound *tsGuardSignal = nullptr; // komunikat od kierownika
*/
sound_source *tsGuardSignal { nullptr };
public: public:
double AccPreferred = 0.0; // preferowane przyspieszenie (wg psychiki kierującego, zmniejszana przy wykryciu kolizji) 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) 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)) && if ((TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_coupler)) &&
(MoverParameters->Couplers[0].Render)) (MoverParameters->Couplers[0].Render))
{ {
btCoupler1.TurnOn(); btCoupler1.Turn( true );
btnOn = true; btnOn = true;
} }
// else btCoupler1.TurnOff(); // else btCoupler1.TurnOff();
if ((TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_coupler)) && if ((TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_coupler)) &&
(MoverParameters->Couplers[1].Render)) (MoverParameters->Couplers[1].Render))
{ {
btCoupler2.TurnOn(); btCoupler2.Turn( true );
btnOn = true; btnOn = true;
} }
// else btCoupler2.TurnOff(); // else btCoupler2.TurnOff();
@@ -820,26 +820,26 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
// przewody sterowania ukrotnionego // przewody sterowania ukrotnionego
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_controll)) if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_controll))
{ {
btCCtrl1.TurnOn(); btCCtrl1.Turn( true );
btnOn = true; btnOn = true;
} }
// else btCCtrl1.TurnOff(); // else btCCtrl1.TurnOff();
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_controll)) if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_controll))
{ {
btCCtrl2.TurnOn(); btCCtrl2.Turn( true );
btnOn = true; btnOn = true;
} }
// else btCCtrl2.TurnOff(); // else btCCtrl2.TurnOff();
// McZapkie-181103: mostki przejsciowe // McZapkie-181103: mostki przejsciowe
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_passenger)) if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_passenger))
{ {
btCPass1.TurnOn(); btCPass1.Turn( true );
btnOn = true; btnOn = true;
} }
// else btCPass1.TurnOff(); // else btCPass1.TurnOff();
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_passenger)) if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_passenger))
{ {
btCPass2.TurnOn(); btCPass2.Turn( true );
btnOn = true; btnOn = true;
} }
// else btCPass2.TurnOff(); // else btCPass2.TurnOff();
@@ -849,7 +849,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{ {
if (TestFlag(iLights[0], 2) || TestFlag(iLights[0], 32)) if (TestFlag(iLights[0], 2) || TestFlag(iLights[0], 32))
{ {
btEndSignals1.TurnOn(); btEndSignals1.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignals1.TurnOff(); // else btEndSignals1.TurnOff();
@@ -858,13 +858,13 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{ {
if (TestFlag(iLights[0], 2)) if (TestFlag(iLights[0], 2))
{ {
btEndSignals11.TurnOn(); btEndSignals11.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignals11.TurnOff(); // else btEndSignals11.TurnOff();
if (TestFlag(iLights[0], 32)) if (TestFlag(iLights[0], 32))
{ {
btEndSignals13.TurnOn(); btEndSignals13.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignals13.TurnOff(); // else btEndSignals13.TurnOff();
@@ -873,7 +873,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{ {
if (TestFlag(iLights[1], 2) || TestFlag(iLights[1], 32)) if (TestFlag(iLights[1], 2) || TestFlag(iLights[1], 32))
{ {
btEndSignals2.TurnOn(); btEndSignals2.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignals2.TurnOff(); // else btEndSignals2.TurnOff();
@@ -882,28 +882,28 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
{ {
if (TestFlag(iLights[1], 2)) if (TestFlag(iLights[1], 2))
{ {
btEndSignals21.TurnOn(); btEndSignals21.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignals21.TurnOff(); // else btEndSignals21.TurnOff();
if (TestFlag(iLights[1], 32)) if (TestFlag(iLights[1], 32))
{ {
btEndSignals23.TurnOn(); btEndSignals23.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignals23.TurnOff(); // else btEndSignals23.TurnOff();
} }
} }
// tablice blaszane: // tablice blaszane:
if (TestFlag(iLights[0], 64)) if (TestFlag(iLights[side::front], light::rearendsignals))
{ {
btEndSignalsTab1.TurnOn(); btEndSignalsTab1.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignalsTab1.TurnOff(); // else btEndSignalsTab1.TurnOff();
if (TestFlag(iLights[1], 64)) if (TestFlag(iLights[side::rear], light::rearendsignals))
{ {
btEndSignalsTab2.TurnOn(); btEndSignalsTab2.Turn( true );
btnOn = true; btnOn = true;
} }
// else btEndSignalsTab2.TurnOff(); // else btEndSignalsTab2.TurnOff();
@@ -914,36 +914,17 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
smWahacze[i]->SetRotate(float3(1, 0, 0), smWahacze[i]->SetRotate(float3(1, 0, 0),
fWahaczeAmp * cos(MoverParameters->eAngle)); fWahaczeAmp * cos(MoverParameters->eAngle));
if (Mechanik) if (Mechanik) {
{ // rysowanie figurki mechanika // rysowanie figurki mechanika
/* if( MoverParameters->ActiveCab > 0 ) {
if (smMechanik0) // mechanik od strony sprzęgu 0 btMechanik1.Turn( true );
if (smMechanik1) // jak jest drugi, to pierwszego jedynie pokazujemy btnOn = true;
smMechanik0->iVisible = MoverParameters->ActiveCab > 0; }
else if( MoverParameters->ActiveCab < 0 ) {
{ // jak jest tylko jeden, to do drugiej kabiny go obracamy btMechanik2.Turn( true );
smMechanik0->iVisible = (MoverParameters->ActiveCab != 0); btnOn = true;
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;
}
} }
// 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 ) if( MoverParameters->Battery || MoverParameters->ConverterFlag )
{ // sygnały czoła pociagu //Ra: wyświetlamy bez { // sygnały czoła pociagu //Ra: wyświetlamy bez
@@ -951,37 +932,37 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
// daleka // daleka
if (TestFlag(iLights[0], 1)) if (TestFlag(iLights[0], 1))
{ {
btHeadSignals11.TurnOn(); btHeadSignals11.Turn( true );
btnOn = true; btnOn = true;
} }
// else btHeadSignals11.TurnOff(); // else btHeadSignals11.TurnOff();
if (TestFlag(iLights[0], 4)) if (TestFlag(iLights[0], 4))
{ {
btHeadSignals12.TurnOn(); btHeadSignals12.Turn( true );
btnOn = true; btnOn = true;
} }
// else btHeadSignals12.TurnOff(); // else btHeadSignals12.TurnOff();
if (TestFlag(iLights[0], 16)) if (TestFlag(iLights[0], 16))
{ {
btHeadSignals13.TurnOn(); btHeadSignals13.Turn( true );
btnOn = true; btnOn = true;
} }
// else btHeadSignals13.TurnOff(); // else btHeadSignals13.TurnOff();
if (TestFlag(iLights[1], 1)) if (TestFlag(iLights[1], 1))
{ {
btHeadSignals21.TurnOn(); btHeadSignals21.Turn( true );
btnOn = true; btnOn = true;
} }
// else btHeadSignals21.TurnOff(); // else btHeadSignals21.TurnOff();
if (TestFlag(iLights[1], 4)) if (TestFlag(iLights[1], 4))
{ {
btHeadSignals22.TurnOn(); btHeadSignals22.Turn( true );
btnOn = true; btnOn = true;
} }
// else btHeadSignals22.TurnOff(); // else btHeadSignals22.TurnOff();
if (TestFlag(iLights[1], 16)) if (TestFlag(iLights[1], 16))
{ {
btHeadSignals23.TurnOn(); btHeadSignals23.Turn( true );
btnOn = true; btnOn = true;
} }
// else btHeadSignals23.TurnOff(); // else btHeadSignals23.TurnOff();
@@ -2926,12 +2907,13 @@ bool TDynamicObject::Update(double dt, double dt1)
} }
Global::ABuDebug = dDOMoveLen / dt1; Global::ABuDebug = dDOMoveLen / dt1;
ResetdMoveLen(); ResetdMoveLen();
#ifdef EU07_USE_OLD_SOUNDCODE
// McZapkie-260202 // McZapkie-260202
// tupot mew, tfu, stukot kol: // tupot mew, tfu, stukot kol:
// taka prowizorka zeby sciszyc stukot dalekiej lokomotywy // taka prowizorka zeby sciszyc stukot dalekiej lokomotywy
double ObjectDist; double ObjectDist;
double vol = 0; double vol = 0;
// double freq; //Ra: nie używane
ObjectDist = SquareMagnitude(Global::pCameraPosition - vPosition); ObjectDist = SquareMagnitude(Global::pCameraPosition - vPosition);
// McZapkie-270202 // McZapkie-270202
if (MyTrack->fSoundDistance != -1) if (MyTrack->fSoundDistance != -1)
@@ -2979,8 +2961,7 @@ bool TDynamicObject::Update(double dt, double dt1)
{ {
rsStukot[i + 1].Stop(); rsStukot[i + 1].Stop();
} }
rsStukot[i].Play(vol, 0, MechInside, rsStukot[i].Play(vol, 0, MechInside, vPosition); // poprawic pozycje o uklad osi
vPosition); // poprawic pozycje o uklad osi
if (i == 1) if (i == 1)
MoverParameters->AccV -= MoverParameters->AccV -=
0.5 * GetVelocity() / (1 + MoverParameters->Vmax); 0.5 * GetVelocity() / (1 + MoverParameters->Vmax);
@@ -3018,7 +2999,7 @@ bool TDynamicObject::Update(double dt, double dt1)
else else
rsUnbrake.Stop(); rsUnbrake.Stop();
} }
#endif
// fragment z EXE Kursa // fragment z EXE Kursa
/* if (MoverParameters->TrainType==dt_ET42) /* if (MoverParameters->TrainType==dt_ET42)
{ {
@@ -3128,13 +3109,16 @@ bool TDynamicObject::Update(double dt, double dt1)
else if( ( true == MoverParameters->PantFrontUp ) else if( ( true == MoverParameters->PantFrontUp )
&& ( PantDiff < 0.01 ) ) // tolerancja niedolegania && ( PantDiff < 0.01 ) ) // tolerancja niedolegania
{ {
if ((MoverParameters->PantFrontVolt == 0.0) && if( ( MoverParameters->PantFrontVolt == 0.0 )
(MoverParameters->PantRearVolt == 0.0)) && ( MoverParameters->PantRearVolt == 0.0 ) ) {
sPantUp.Play(vol, 0, MechInside, vPosition); #ifdef EU07_USE_OLD_SOUNDCODE
if (p->hvPowerWire) // TODO: wyliczyć trzeba prąd przypadający na sPantUp.Play( vol, 0, MechInside, vPosition );
// pantograf i #else
// wstawić do GetVoltage() sPantUp.play();
{ #endif
}
if (p->hvPowerWire) {
// TODO: wyliczyć trzeba prąd przypadający na pantograf i wstawić do GetVoltage()
MoverParameters->PantFrontVolt = MoverParameters->PantFrontVolt =
p->hvPowerWire->VoltageGet(MoverParameters->Voltage, fPantCurrent); p->hvPowerWire->VoltageGet(MoverParameters->Voltage, fPantCurrent);
fCurrent -= fPantCurrent; // taki prąd płynie przez powyższy pantograf 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 ) if( ( MoverParameters->PantRearVolt == 0.0 )
&& ( MoverParameters->PantFrontVolt == 0.0 ) ) { && ( MoverParameters->PantFrontVolt == 0.0 ) ) {
#ifdef EU07_USE_OLD_SOUNDCODE
sPantUp.Play( vol, 0, MechInside, vPosition ); sPantUp.Play( vol, 0, MechInside, vPosition );
#else
sPantUp.play();
#endif
} }
if (p->hvPowerWire) { if (p->hvPowerWire) {
// TODO: wyliczyć trzeba prąd przypadający na pantograf i wstawić do GetVoltage() // 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 } // koniec pętli po pantografach
if ((MoverParameters->PantFrontSP == false) && (MoverParameters->PantFrontUp == false)) if ((MoverParameters->PantFrontSP == false) && (MoverParameters->PantFrontUp == false))
{ {
#ifdef EU07_USE_OLD_SOUNDCODE
sPantDown.Play(vol, 0, MechInside, vPosition); sPantDown.Play(vol, 0, MechInside, vPosition);
#else
sPantDown.play();
#endif
MoverParameters->PantFrontSP = true; MoverParameters->PantFrontSP = true;
} }
if ((MoverParameters->PantRearSP == false) && (MoverParameters->PantRearUp == false)) if ((MoverParameters->PantRearSP == false) && (MoverParameters->PantRearUp == false))
{ {
#ifdef EU07_USE_OLD_SOUNDCODE
sPantDown.Play(vol, 0, MechInside, vPosition); sPantDown.Play(vol, 0, MechInside, vPosition);
#else
sPantDown.play();
#endif
MoverParameters->PantRearSP = true; MoverParameters->PantRearSP = true;
} }
/* /*
@@ -3354,24 +3350,40 @@ bool TDynamicObject::Update(double dt, double dt1)
// NBMX Obsluga drzwi, MC: zuniwersalnione // NBMX Obsluga drzwi, MC: zuniwersalnione
if ((dDoorMoveL < MoverParameters->DoorMaxShiftL) && (MoverParameters->DoorLeftOpened)) 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; dDoorMoveL += dt1 * 0.5 * MoverParameters->DoorOpenSpeed;
} }
if ((dDoorMoveL > 0) && (!MoverParameters->DoorLeftOpened)) 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; dDoorMoveL -= dt1 * MoverParameters->DoorCloseSpeed;
if (dDoorMoveL < 0) if (dDoorMoveL < 0)
dDoorMoveL = 0; dDoorMoveL = 0;
} }
if ((dDoorMoveR < MoverParameters->DoorMaxShiftR) && (MoverParameters->DoorRightOpened)) 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; dDoorMoveR += dt1 * 0.5 * MoverParameters->DoorOpenSpeed;
} }
if ((dDoorMoveR > 0) && (!MoverParameters->DoorRightOpened)) 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; dDoorMoveR -= dt1 * MoverParameters->DoorCloseSpeed;
if (dDoorMoveR < 0) if (dDoorMoveR < 0)
dDoorMoveR = 0; dDoorMoveR = 0;
@@ -3465,8 +3477,8 @@ void TDynamicObject::TurnOff()
{ // wyłączenie rysowania submodeli zmiennych dla { // wyłączenie rysowania submodeli zmiennych dla
// egemplarza pojazdu // egemplarza pojazdu
btnOn = false; btnOn = false;
btCoupler1.TurnOff(); btCoupler1.Turn( false );
btCoupler2.TurnOff(); btCoupler2.Turn( false );
btCPneumatic1.TurnOff(); btCPneumatic1.TurnOff();
btCPneumatic1r.TurnOff(); btCPneumatic1r.TurnOff();
btCPneumatic2.TurnOff(); btCPneumatic2.TurnOff();
@@ -3475,45 +3487,41 @@ void TDynamicObject::TurnOff()
btPneumatic1r.TurnOff(); btPneumatic1r.TurnOff();
btPneumatic2.TurnOff(); btPneumatic2.TurnOff();
btPneumatic2r.TurnOff(); btPneumatic2r.TurnOff();
btCCtrl1.TurnOff(); btCCtrl1.Turn( false );
btCCtrl2.TurnOff(); btCCtrl2.Turn( false );
btCPass1.TurnOff(); btCPass1.Turn( false );
btCPass2.TurnOff(); btCPass2.Turn( false );
btEndSignals11.TurnOff(); btEndSignals11.Turn( false );
btEndSignals13.TurnOff(); btEndSignals13.Turn( false );
btEndSignals21.TurnOff(); btEndSignals21.Turn( false );
btEndSignals23.TurnOff(); btEndSignals23.Turn( false );
btEndSignals1.TurnOff(); btEndSignals1.Turn( false );
btEndSignals2.TurnOff(); btEndSignals2.Turn( false );
btEndSignalsTab1.TurnOff(); btEndSignalsTab1.Turn( false );
btEndSignalsTab2.TurnOff(); btEndSignalsTab2.Turn( false );
btHeadSignals11.TurnOff(); btHeadSignals11.Turn( false );
btHeadSignals12.TurnOff(); btHeadSignals12.Turn( false );
btHeadSignals13.TurnOff(); btHeadSignals13.Turn( false );
btHeadSignals21.TurnOff(); btHeadSignals21.Turn( false );
btHeadSignals22.TurnOff(); btHeadSignals22.Turn( false );
btHeadSignals23.TurnOff(); btHeadSignals23.Turn( false );
btMechanik1.TurnOff(); btMechanik1.Turn( false );
btMechanik2.TurnOff(); btMechanik2.Turn( false );
}; };
void TDynamicObject::RenderSounds() // przeliczanie dźwięków, bo będzie słychać bez wyświetlania sektora z pojazdem
{ // przeliczanie dźwięków, bo będzie słychać bez wyświetlania sektora z pojazdem void TDynamicObject::RenderSounds() {
// if( Global::iPause > 0 ) { return; } #ifdef EU07_USE_OLD_SOUNDCODE
// McZapkie-010302: ulepszony dzwiek silnika // McZapkie-010302: ulepszony dzwiek silnika
double freq; double freq;
double vol = 0; double vol = 0;
double dt = Timer::GetDeltaRenderTime(); double dt = Timer::GetDeltaRenderTime();
// double sounddist;
// sounddist=SquareMagnitude(Global::pCameraPosition-vPosition);
if (MoverParameters->Power > 0) if (MoverParameters->Power > 0)
{ {
if ((rsSilnik.AM != 0) if ((rsSilnik.AM != 0)
&& ((MoverParameters->Mains) && ((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))) || (MoverParameters->EngineType == DieselEngine)))
{ {
if ((fabs(MoverParameters->enrot) > 0.01) || if ((fabs(MoverParameters->enrot) > 0.01) ||
@@ -3521,8 +3529,7 @@ void TDynamicObject::RenderSounds()
{ {
freq = rsSilnik.FM * fabs(MoverParameters->enrot) + rsSilnik.FA; freq = rsSilnik.FM * fabs(MoverParameters->enrot) + rsSilnik.FA;
if (MoverParameters->EngineType == Dumb) if (MoverParameters->EngineType == Dumb)
freq = freq - freq = freq - 0.2 * MoverParameters->EnginePower / (1 + MoverParameters->Power * 1000);
0.2 * MoverParameters->EnginePower / (1 + MoverParameters->Power * 1000);
rsSilnik.AdjFreq(freq, dt); rsSilnik.AdjFreq(freq, dt);
if (MoverParameters->EngineType == DieselEngine) if (MoverParameters->EngineType == DieselEngine)
{ {
@@ -3561,24 +3568,23 @@ void TDynamicObject::RenderSounds()
if (volrnd < 2) if (volrnd < 2)
vol = vol + volrnd / 200.0; vol = vol + volrnd / 200.0;
} }
switch (MyTrack->eEnvironment) switch( MyTrack->eEnvironment ) {
{ case e_tunnel: {
case e_tunnel: vol += 0.1;
{ break;
vol += 0.1; }
case e_canyon: {
vol += 0.05;
break;
}
default: {
break;
}
} }
break; if( ( MoverParameters->DynamicBrakeFlag )
case e_canyon: && ( MoverParameters->EnginePower > 0.1 )
{ && ( MoverParameters->EngineType == ElectricSeriesMotor ) )
vol += 0.05; // Szociu - 29012012 - jeżeli uruchomiony jest hamulec elektrodynamiczny, odtwarzany jest dźwięk silnika
}
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
vol += 0.8; vol += 0.8;
if (enginevolume > 0.0001) if (enginevolume > 0.0001)
@@ -3693,15 +3699,6 @@ void TDynamicObject::RenderSounds()
if (MoverParameters->BrakePress < 0.1) if (MoverParameters->BrakePress < 0.1)
releaser_vol = MoverParameters->BrakePress * 10; releaser_vol = MoverParameters->BrakePress * 10;
sReleaser.UpdateAF(releaser_vol, 1, MechInside, GetPosition()); 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 // McZapkie! - dzwiek compressor.wav tylko gdy dziala sprezarka
if (MoverParameters->VeselVolume != 0) if (MoverParameters->VeselVolume != 0)
@@ -3851,15 +3848,7 @@ void TDynamicObject::RenderSounds()
if (GetVelocity() == 0) if (GetVelocity() == 0)
rsDerailment.Stop(); rsDerailment.Stop();
} }
/* //Ra: dwa razy? #endif
if (MoverParameters->EventFlag)
{
if (TestFlag(MoverParameters->DamageFlag,dtrain_out) && GetVelocity()>0)
rsDerailment.Play(1,0,true,GetPosition());
if (GetVelocity()==0)
rsDerailment.Stop();
}
*/
}; };
// McZapkie-250202 // McZapkie-250202
@@ -4560,10 +4549,16 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
parser.getTokens(); parser.getTokens();
parser >> token; parser >> token;
if( token != "end" ) { if( token != "end" ) {
rsStukot[ i ].Init( token, dSDist, GetPosition().x, #ifdef EU07_USE_OLD_SOUNDCODE
GetPosition().y + dWheelsPosition[ i ], GetPosition().z, rsStukot[ i ].Init(
token, dSDist,
GetPosition().x, GetPosition().y + dWheelsPosition[ i ], GetPosition().z,
true ); 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" ) { if( token != "end" ) {
// TODO: double-check if this if() and/or retrieval makes sense here // 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:" ) else if( ( token == "engine:" )
&& ( MoverParameters->Power > 0 ) ) { && ( MoverParameters->Power > 0 ) ) {
// plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest. // plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest.
#ifdef EU07_USE_OLD_SOUNDCODE
double attenuation; double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
@@ -4585,7 +4581,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
true, true ); true, true );
if( rsSilnik.GetWaveTime() == 0 ) { if( rsSilnik.GetWaveTime() == 0 ) {
ErrorLog( "Missed sound: \"" + token + "\" for " + asFileName ); ErrorLog( "Missed sound: \"" + token + "\" for " + asFileName );
} }
parser.getTokens( 1, false ); parser.getTokens( 1, false );
parser >> rsSilnik.AM; parser >> rsSilnik.AM;
if( MoverParameters->EngineType == DieselEngine ) { if( MoverParameters->EngineType == DieselEngine ) {
@@ -4605,13 +4601,17 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
>> rsSilnik.AA >> rsSilnik.AA
>> rsSilnik.FM // MoverParameters->nmax; >> rsSilnik.FM // MoverParameters->nmax;
>> rsSilnik.FA; >> rsSilnik.FA;
#else
rsSilnik.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
#endif
} }
else if( ( token == "ventilator:" ) else if( ( token == "ventilator:" )
&& ( ( MoverParameters->EngineType == ElectricSeriesMotor ) && ( ( MoverParameters->EngineType == ElectricSeriesMotor )
|| ( MoverParameters->EngineType == ElectricInductionMotor ) ) ) { || ( MoverParameters->EngineType == ElectricInductionMotor ) ) ) {
// plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest. // plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest.
double attenuation; #ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
>> token >> token
@@ -4628,12 +4628,16 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
>> rsWentylator.FA; >> rsWentylator.FA;
rsWentylator.AM /= MoverParameters->RVentnmax; rsWentylator.AM /= MoverParameters->RVentnmax;
rsWentylator.FM /= 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:" ) else if( ( token == "transmission:" )
&& ( MoverParameters->EngineType == ElectricSeriesMotor ) ) { && ( MoverParameters->EngineType == ElectricSeriesMotor ) ) {
// plik z dzwiekiem, mnozniki i ofsety amp. i czest. // plik z dzwiekiem, mnozniki i ofsety amp. i czest.
double attenuation; #ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
>> token >> token
@@ -4646,11 +4650,15 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsPrzekladnia.AA = 0.1; rsPrzekladnia.AA = 0.1;
rsPrzekladnia.FM = 0.005; rsPrzekladnia.FM = 0.005;
rsPrzekladnia.FA = 1.0; 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:" ){ else if( token == "brake:" ){
// plik z piskiem hamulca, mnozniki i ofsety amplitudy. // plik z piskiem hamulca, mnozniki i ofsety amplitudy.
double attenuation; #ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
>> token >> token
@@ -4663,23 +4671,26 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsPisk.AA = parser.getToken<double>() * ( 105 - Random( 10 ) ) / 100; rsPisk.AA = parser.getToken<double>() * ( 105 - Random( 10 ) ) / 100;
rsPisk.FM = 1.0; rsPisk.FM = 1.0;
rsPisk.FA = 0.0; rsPisk.FA = 0.0;
#else
rsPisk.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude );
#endif
} }
else if( token == "brakeacc:" ) { else if( token == "brakeacc:" ) {
// plik z przyspieszaczem (upust po zlapaniu hamowania) // plik z przyspieszaczem (upust po zlapaniu hamowania)
// sBrakeAcc.Init(str.c_str(),Parser->GetNextSymbol().ToDouble(),GetPosition().x,GetPosition().y,GetPosition().z,true); #ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token; parser.getTokens( 1, false ); parser >> token;
sBrakeAcc = TSoundsManager::GetFromName( token, true ); sBrakeAcc = TSoundsManager::GetFromName( token, true );
#else
sBrakeAcc.deserialize( parser, sound_type::single );
#endif
bBrakeAcc = true; bBrakeAcc = true;
// sBrakeAcc.AM=1.0;
// sBrakeAcc.AA=0.0;
// sBrakeAcc.FM=1.0;
// sBrakeAcc.FA=0.0;
} }
else if( token == "unbrake:" ) { else if( token == "unbrake:" ) {
// plik z piskiem hamulca, mnozniki i ofsety amplitudy. // plik z piskiem hamulca, mnozniki i ofsety amplitudy.
double attenuation; #ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
>> token >> token
@@ -4692,11 +4703,15 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsUnbrake.AA = 0.0; rsUnbrake.AA = 0.0;
rsUnbrake.FM = 1.0; rsUnbrake.FM = 1.0;
rsUnbrake.FA = 0.0; rsUnbrake.FA = 0.0;
#else
rsUnbrake.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
} }
else if( token == "derail:" ) { else if( token == "derail:" ) {
// dzwiek przy wykolejeniu // dzwiek przy wykolejeniu
double attenuation; #ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
>> token >> token
@@ -4709,11 +4724,15 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsDerailment.AA = 0.0; rsDerailment.AA = 0.0;
rsDerailment.FM = 1.0; rsDerailment.FM = 1.0;
rsDerailment.FA = 0.0; rsDerailment.FA = 0.0;
#else
rsDerailment.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
} }
else if( token == "dieselinc:" ) { else if( token == "dieselinc:" ) {
// dzwiek przy wlazeniu na obroty woodwarda // dzwiek przy wlazeniu na obroty woodwarda
double attenuation; #ifdef EU07_USE_OLD_SOUNDCODE
double attenuation;
parser.getTokens( 2, false ); parser.getTokens( 2, false );
parser parser
>> token >> token
@@ -4726,12 +4745,16 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rsDiesielInc.AA = 0.0; rsDiesielInc.AA = 0.0;
rsDiesielInc.FM = 1.0; rsDiesielInc.FM = 1.0;
rsDiesielInc.FA = 0.0; rsDiesielInc.FA = 0.0;
#else
rsDiesielInc.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
} }
else if( token == "curve:" ) { else if( token == "curve:" ) {
double attenuation; double attenuation;
parser.getTokens( 2, false ); #ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 2, false );
parser parser
>> token >> token
>> attenuation; >> attenuation;
@@ -4743,91 +4766,143 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
rscurve.AA = 0.0; rscurve.AA = 0.0;
rscurve.FM = 1.0; rscurve.FM = 1.0;
rscurve.FA = 0.0; rscurve.FA = 0.0;
#else
rscurve.deserialize( parser, sound_type::single, sound_parameters::range );
#endif
} }
else if( token == "horn1:" ) { else if( token == "horn1:" ) {
// pliki z trabieniem // 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:" ) { else if( token == "horn2:" ) {
// pliki z trabieniem wysokoton. // pliki z trabieniem wysokoton.
sHorn2.Load( parser, GetPosition() ); #ifdef EU07_USE_OLD_SOUNDCODE
if( iHornWarning ) { 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 iHornWarning = 2; // numer syreny do użycia po otrzymaniu sygnału do jazdy
} }
} }
else if( token == "departuresignal:" ) { else if( token == "departuresignal:" ) {
// pliki z sygnalem odjazdu // 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:" ) { else if( token == "pantographup:" ) {
// pliki dzwiekow pantografow // pliki dzwiekow pantografow
parser.getTokens( 1, false ); parser >> token; #ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
sPantUp.Init( sPantUp.Init(
token, 50, token, 50,
GetPosition().x, GetPosition().y, GetPosition().z, GetPosition().x, GetPosition().y, GetPosition().z,
true ); true );
#else
sPantUp.deserialize( parser, sound_type::single );
#endif
} }
else if( token == "pantographdown:" ) { else if( token == "pantographdown:" ) {
// pliki dzwiekow pantografow // pliki dzwiekow pantografow
parser.getTokens( 1, false ); parser >> token; #ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token;
sPantDown.Init( sPantDown.Init(
token, 50, token, 50,
GetPosition().x, GetPosition().y, GetPosition().z, GetPosition().x, GetPosition().y, GetPosition().z,
true ); true );
#else
sPantDown.deserialize( parser, sound_type::single );
#endif
} }
else if( token == "compressor:" ) { else if( token == "compressor:" ) {
// pliki ze sprezarka // pliki ze sprezarka
#ifdef EU07_USE_OLD_SOUNDCODE
sCompressor.Load( parser, GetPosition() ); sCompressor.Load( parser, GetPosition() );
#else
sCompressor.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
} }
else if( token == "converter:" ) { else if( token == "converter:" ) {
// pliki z przetwornica // pliki z przetwornica
// if (MoverParameters->EngineType==DieselElectric) //będzie modulowany? #ifdef EU07_USE_OLD_SOUNDCODE
sConverter.Load( parser, GetPosition() ); sConverter.Load( parser, GetPosition() );
#else
sConverter.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
} }
else if( token == "turbo:" ) { else if( token == "turbo:" ) {
// pliki z turbogeneratorem // 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:" ) { else if( token == "small-compressor:" ) {
// pliki z przetwornica // 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:" ) { else if( token == "dooropen:" ) {
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token; parser.getTokens( 1, false ); parser >> token;
rsDoorOpen.Init( rsDoorOpen.Init(
token, 50, token, 50,
GetPosition().x, GetPosition().y, GetPosition().z, GetPosition().x, GetPosition().y, GetPosition().z,
true ); true );
#else
rsDoorOpen.deserialize( parser, sound_type::single );
#endif
} }
else if( token == "doorclose:" ) { else if( token == "doorclose:" ) {
#ifdef EU07_USE_OLD_SOUNDCODE
parser.getTokens( 1, false ); parser >> token; parser.getTokens( 1, false ); parser >> token;
rsDoorClose.Init( rsDoorClose.Init(
token, 50, token, 50,
GetPosition().x, GetPosition().y, GetPosition().z, GetPosition().x, GetPosition().y, GetPosition().z,
true ); true );
#else
rsDoorClose.deserialize( parser, sound_type::single );
#endif
} }
else if( token == "sand:" ) { else if( token == "sand:" ) {
// pliki z piasecznica #ifdef EU07_USE_OLD_SOUNDCODE
// pliki z piasecznica
sSand.Load( parser, GetPosition() ); sSand.Load( parser, GetPosition() );
#else
sSand.deserialize( parser, sound_type::multipart, sound_parameters::range );
#endif
} }
else if( token == "releaser:" ) { else if( token == "releaser:" ) {
// pliki z odluzniaczem // 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 != "" ) } while( ( token != "" )

View File

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

View File

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

View File

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

View File

@@ -70,16 +70,15 @@ bool TGauge::Load(cParser &Parser, TModel3d *md1, TModel3d *md2, double mul) {
else { else {
// new, block type config // new, block type config
// TODO: rework the base part into yaml-compatible flow style mapping // TODO: rework the base part into yaml-compatible flow style mapping
cParser mappingparser( Parser.getToken<std::string>( false, "}" ) ); submodelname = Parser.getToken<std::string>( false );
submodelname = mappingparser.getToken<std::string>( false ); gaugetypename = Parser.getToken<std::string>( true );
gaugetypename = mappingparser.getToken<std::string>( true ); Parser.getTokens( 3, false );
mappingparser.getTokens( 3, false ); Parser
mappingparser
>> scale >> scale
>> offset >> offset
>> friction; >> friction;
// new, variable length section // new, variable length section
while( true == Load_mapping( mappingparser ) ) { while( true == Load_mapping( Parser ) ) {
; // all work done by while() ; // all work done by while()
} }
} }
@@ -116,26 +115,15 @@ bool TGauge::Load(cParser &Parser, TModel3d *md1, TModel3d *md2, double mul) {
bool bool
TGauge::Load_mapping( cParser &Input ) { TGauge::Load_mapping( cParser &Input ) {
if( false == Input.getTokens( 2, true, ", \n\r\t" ) ) { // token can be a key or block end
return false; 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
std::string key, value;
Input
>> key
>> value;
if( key == "soundinc:" ) { if( key == "soundinc:" ) {
m_soundfxincrease = ( m_soundfxincrease.deserialize( Input, sound_type::single );
value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr );
} }
else if( key == "sounddec:" ) { else if( key == "sounddec:" ) {
m_soundfxdecrease = ( m_soundfxdecrease.deserialize( Input, sound_type::single );
value != "none" ?
TSoundsManager::GetFromName( value, true ) :
nullptr );
} }
else if( key.compare( 0, std::min<std::size_t>( key.size(), 5 ), "sound" ) == 0 ) { 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 // 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 ) { if( indexstart != std::string::npos ) {
m_soundfxvalues.emplace( m_soundfxvalues.emplace(
std::stoi( key.substr( indexstart, indexend - indexstart ) ), std::stoi( key.substr( indexstart, indexend - indexstart ) ),
( value != "none" ? sound_source().deserialize( Input, sound_type::single ) );
TSoundsManager::GetFromName( value, true ) :
nullptr ) );
} }
} }
return true; // return value marks a key: value pair was extracted, nothing about whether it's recognized 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; 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 // ustawienie wartości docelowej. plays provided fallback sound, if no sound was defined in the control itself
void 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 ) ); auto const desiredtimes100 = static_cast<int>( std::round( 100.0 * fNewDesired ) );
if( static_cast<int>( std::round( 100.0 * ( fDesiredValue - fOffset ) / fScale ) ) == desiredtimes100 ) { 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 // filter out values other than full integers
auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 ); auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 );
if( lookup != m_soundfxvalues.end() ) { if( lookup != m_soundfxvalues.end() ) {
play( lookup->second ); lookup->second.play();
return; return;
} }
} }
// ...and if there isn't any, fall back on the basic set... // ...and if there isn't any, fall back on the basic set...
auto const currentvalue = GetValue(); auto const currentvalue = GetValue();
if( ( currentvalue < fNewDesired ) && ( m_soundfxincrease != nullptr ) ) { if( ( currentvalue < fNewDesired )
play( m_soundfxincrease ); && ( false == m_soundfxincrease.empty() ) ) {
// shift up
m_soundfxincrease.play();
} }
else if( ( currentvalue > fNewDesired ) && ( m_soundfxdecrease != nullptr ) ) { else if( ( currentvalue > fNewDesired )
play( m_soundfxdecrease ); && ( false == m_soundfxdecrease.empty() ) ) {
// shift down
m_soundfxdecrease.play();
} }
else if( Fallbacksound != nullptr ) { else if( Fallbacksound != nullptr ) {
// ...and if that fails too, try the provided fallback sound from legacy system // ...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 // animowany wskaźnik, mogący przyjmować wiele stanów pośrednich
class TGauge { 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 TGaugeType eType { gt_Unknown }; // typ ruchu
double fFriction { 0.0 }; // hamowanie przy zliżaniu się do zadanej wartości double fFriction { 0.0 }; // hamowanie przy zliżaniu się do zadanej wartości
double fDesiredValue { 0.0 }; // wartość docelowa double fDesiredValue { 0.0 }; // wartość docelowa
@@ -38,18 +44,12 @@ class TGauge {
double *dData { nullptr }; double *dData { nullptr };
int *iData; int *iData;
}; };
PSound m_soundfxincrease { nullptr }; // sound associated with increasing control's value sound_source m_soundfxincrease; // sound associated with increasing control's value
PSound m_soundfxdecrease { nullptr }; // sound associated with decreasing control's value sound_source m_soundfxdecrease; // sound associated with decreasing control's value
std::map<int, PSound> m_soundfxvalues; // sounds associated with specific values std::map<int, sound_source> 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 );
public: public:
// methods
TGauge() = default; TGauge() = default;
inline inline
void Clear() { *this = TGauge(); } void Clear() { *this = TGauge(); }
@@ -58,7 +58,8 @@ class TGauge {
void PermIncValue(double fNewDesired); void PermIncValue(double fNewDesired);
void IncValue(double fNewDesired); void IncValue(double fNewDesired);
void DecValue(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); void PutValue(double fNewDesired);
double GetValue() const; double GetValue() const;
void Update(); void Update();
@@ -67,6 +68,7 @@ class TGauge {
void AssignDouble(double *dValue); void AssignDouble(double *dValue);
void AssignInt(int *iValue); void AssignInt(int *iValue);
void UpdateValue(); void UpdateValue();
// members
TSubModel *SubModel; // McZapkie-310302: zeby mozna bylo sprawdzac czy zainicjowany poprawnie 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; const int MaxKeys = 75;
// klasy dla wskaźników globalnych // klasy dla wskaźników globalnych
/*
class TGround; class TGround;
class TWorld; class TWorld;
class TCamera; class TCamera;
@@ -121,8 +122,7 @@ class TDynamicObject;
class TAnimModel; // obiekt terenu class TAnimModel; // obiekt terenu
class cParser; // nowy (powolny!) parser class cParser; // nowy (powolny!) parser
class TEvent; class TEvent;
class TTextSound; */
class TTranscript class TTranscript
{ // klasa obsługująca linijkę napisu do dźwięku { // klasa obsługująca linijkę napisu do dźwięku
public: public:
@@ -293,7 +293,9 @@ public:
static float4 UITextColor; // base color of UI text static float4 UITextColor; // base color of UI text
static std::string asLang; // domyślny język - http://tools.ietf.org/html/bcp47 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 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 TTextSound *tsRadioBusy[10]; // zajętość kanałów radiowych (wskaźnik na odgrywany dźwięk)
*/
static int iPoKeysPWM[7]; // numery wejść dla PWM static int iPoKeysPWM[7]; // numery wejść dla PWM
//randomizacja //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 { // 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 int facecount = iNumVerts / 3; // bo maska powierzchni jest jedna na trójkąt
for( int faceidx = Startface; faceidx < facecount; ++faceidx ) { for( int faceidx = Startface; faceidx < facecount; ++faceidx ) {
@@ -983,7 +983,7 @@ void TSubModel::serialize_geometry( std::ostream &Output ) const {
}; };
void 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 // 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) // (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 // once sorted we can grab geometry as it comes, and assign it to the chunks it belongs to
for( auto const &submodeloffset : submodeloffsets ) { for( auto const &submodeloffset : submodeloffsets ) {
auto &submodel = Root[ submodeloffset.second ]; auto &submodel = Root[ submodeloffset.second ];
vertex_array vertices; vertices.resize( submodel.iNumVerts ); gfx::vertex_array vertices; vertices.resize( submodel.iNumVerts );
iNumVerts += submodel.iNumVerts; iNumVerts += submodel.iNumVerts;
for( auto &vertex : vertices ) { for( auto &vertex : vertices ) {
vertex.deserialize( s ); vertex.deserialize( s );

View File

@@ -124,7 +124,7 @@ private:
TSubModel *Next { nullptr }; TSubModel *Next { nullptr };
TSubModel *Child { 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 material_handle m_material { null_handle }; // numer tekstury, -1 wymienna, 0 brak
bool bWire { false }; // nie używane, ale wczytywane bool bWire { false }; // nie używane, ale wczytywane
float Opacity { 1.0f }; float Opacity { 1.0f };
@@ -134,7 +134,7 @@ private:
public: // chwilowo public: // chwilowo
float3 v_TransVector { 0.0f, 0.0f, 0.0f }; float3 v_TransVector { 0.0f, 0.0f, 0.0f };
vertex_array Vertices; gfx::vertex_array Vertices;
float m_boundingradius { 0 }; float m_boundingradius { 0 };
size_t iAnimOwner{ 0 }; // roboczy numer egzemplarza, który ustawił animację size_t iAnimOwner{ 0 }; // roboczy numer egzemplarza, który ustawił animację
TAnimType b_aAnim{ at_None }; // kody animacji oddzielnie, bo zerowane 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 m_materialname; // robocza nazwa tekstury do zapisania w pliku binarnym
std::string pName; // robocza nazwa std::string pName; // robocza nazwa
private: 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); void RaAnimation(TAnimType a);
public: public:
@@ -174,7 +174,7 @@ public:
inline float4x4 * GetMatrix() { return fMatrix; }; inline float4x4 * GetMatrix() { return fMatrix; };
inline void Hide() { iVisible = 0; }; 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(); int FlagsCheck();
void WillBeAnimated() void WillBeAnimated()
{ {
@@ -222,7 +222,7 @@ private:
int iFlags; // Ra: czy submodele mają przezroczyste tekstury int iFlags; // Ra: czy submodele mają przezroczyste tekstury
public: // Ra: tymczasowo public: // Ra: tymczasowo
int iNumVerts; // ilość wierzchołków (gdy nie ma VBO, to m_nVertexCount=0) 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 }; bool m_geometrycreated { false };
private: private:
std::vector<std::string> Textures; // nazwy tekstur 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 ) ); 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 { // generowanie trójkątów dla odcinka trajektorii ruchu
// standardowo tworzy triangle_strip dla prostego albo ich zestaw dla łuku // standardowo tworzy triangle_strip dla prostego albo ich zestaw dla łuku
// po modyfikacji - dla ujemnego (iNumShapePoints) w dodatkowych polach tabeli // po modyfikacji - dla ujemnego (iNumShapePoints) w dodatkowych polach tabeli

View File

@@ -97,7 +97,7 @@ public:
r2 = fRoll2; } r2 = fRoll2; }
bool 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 void
Render(); Render();
inline inline

View File

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

View File

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

View File

@@ -175,18 +175,18 @@ TTraction::endpoints() const {
} }
std::size_t std::size_t
TTraction::create_geometry( geometrybank_handle const &Bank ) { TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
if( m_geometry != null_handle ) { if( m_geometry != null_handle ) {
return GfxRenderer.Vertices( m_geometry ).size() / 2; 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 ); double ddp = std::hypot( pPoint2.x - pPoint1.x, pPoint2.z - pPoint1.z );
if( Wires == 2 ) if( Wires == 2 )
WireOffset = 0; WireOffset = 0;
// jezdny // jezdny
basic_vertex startvertex, endvertex; gfx::basic_vertex startvertex, endvertex;
startvertex.position = startvertex.position =
glm::vec3( glm::vec3(
pPoint1.x - ( pPoint2.z / ddp - pPoint1.z / ddp ) * WireOffset - m_origin.x, 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 int PowerState { 0 }; // type of incoming power, if any
// visualization data // visualization data
glm::dvec3 m_origin; glm::dvec3 m_origin;
geometry_handle m_geometry; gfx::geometry_handle m_geometry;
explicit TTraction( scene::node_data const &Nodedata ); explicit TTraction( scene::node_data const &Nodedata );
@@ -64,7 +64,7 @@ class TTraction : public editor::basic_node {
endpoints() const; endpoints() const;
// creates geometry data in specified geometry bank. returns: number of created elements, or NULL // 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 // 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); int TestPoint(glm::dvec3 const &Point);
void Connect(int my, TTraction *with, int to); void Connect(int my, TTraction *with, int to);
void Init(); 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 "Button.h"
#include "Gauge.h" #include "Gauge.h"
#include "Spring.h" #include "Spring.h"
#include "AdvSound.h" #include "sound.h"
#include "PyInt.h" #include "PyInt.h"
#include "command.h" #include "command.h"
@@ -90,6 +90,7 @@ class TTrain
void UpdateMechPosition(double dt); void UpdateMechPosition(double dt);
vector3 GetWorldMechPosition(); vector3 GetWorldMechPosition();
bool Update( double const Deltatime ); bool Update( double const Deltatime );
void update_sounds( double const Deltatime );
bool m_updated = false; bool m_updated = false;
void MechStop(); void MechStop();
void SetLights(); void SetLights();
@@ -110,10 +111,6 @@ class TTrain
bool initialize_gauge(cParser &Parser, std::string const &Label, int const Cabindex); 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 // 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); 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 // helper, returns true for EMU with oerlikon brake
bool is_eztoer() const; bool is_eztoer() const;
// command handlers // command handlers
@@ -308,8 +305,6 @@ public: // reszta może by?publiczna
TGauge ggTrainHeatingButton; TGauge ggTrainHeatingButton;
TGauge ggSignallingButton; TGauge ggSignallingButton;
TGauge ggDoorSignallingButton; TGauge ggDoorSignallingButton;
// TGauge ggDistCounter; //Ra 2014-07: licznik kilometrów
// TGauge ggVelocityDgt; //i od razu prędkościomierz
TButton btLampkaPoslizg; TButton btLampkaPoslizg;
TButton btLampkaStyczn; TButton btLampkaStyczn;
@@ -356,7 +351,6 @@ public: // reszta może by?publiczna
TButton btLampkaRadiotelefon; TButton btLampkaRadiotelefon;
TButton btLampkaHamienie; TButton btLampkaHamienie;
TButton btLampkaED; // Stele 161228 hamowanie elektrodynamiczne TButton btLampkaED; // Stele 161228 hamowanie elektrodynamiczne
TButton btLampkaJazda; // Ra: nie używane
// KURS90 // KURS90
TButton btLampkaBoczniki; TButton btLampkaBoczniki;
TButton btLampkaMaxSila; TButton btLampkaMaxSila;
@@ -384,8 +378,9 @@ public: // reszta może by?publiczna
// Ra 2013-12: wirtualne "lampki" do odbijania na haslerze w PoKeys // Ra 2013-12: wirtualne "lampki" do odbijania na haslerze w PoKeys
TButton btHaslerBrakes; // ciśnienie w cylindrach TButton btHaslerBrakes; // ciśnienie w cylindrach
TButton btHaslerCurrent; // prąd na silnikach TButton btHaslerCurrent; // prąd na silnikach
/*
vector3 pPosition; vector3 pPosition;
*/
vector3 pMechOffset; // driverNpos vector3 pMechOffset; // driverNpos
vector3 vMechMovement; vector3 vMechMovement;
vector3 pMechPosition; vector3 pMechPosition;
@@ -403,48 +398,42 @@ public: // reszta może by?publiczna
double fMechRoll; double fMechRoll;
double fMechPitch; double fMechPitch;
PSound dsbNastawnikJazdy; sound_source dsbNastawnikJazdy;
PSound dsbNastawnikBocz; // hunter-081211 sound_source dsbNastawnikBocz; // hunter-081211
PSound dsbRelay; sound_source dsbRelay;
PSound dsbPneumaticRelay; sound_source dsbPneumaticRelay;
PSound dsbSwitch; sound_source dsbSwitch;
PSound dsbPneumaticSwitch; sound_source dsbPneumaticSwitch;
PSound dsbReverserKey; // hunter-121211 sound_source dsbReverserKey; // hunter-121211
PSound dsbCouplerAttach; // Ra: w kabinie???? sound_source dsbCouplerAttach; // Ra: w kabinie????
PSound dsbCouplerDetach; // Ra: w kabinie??? sound_source dsbCouplerDetach; // Ra: w kabinie???
PSound dsbDieselIgnition; // Ra: w kabinie??? sound_source dsbDieselIgnition; // Ra: w kabinie???
PSound dsbDoorClose; // Ra: w kabinie???
PSound dsbDoorOpen; // Ra: w kabinie???
// Winger 010304 // Winger 010304
PSound dsbPantUp; sound_source dsbWejscie_na_bezoporow;
PSound dsbPantDown; sound_source dsbWejscie_na_drugi_uklad; // hunter-081211: poprawka literowki
PSound dsbWejscie_na_bezoporow;
PSound dsbWejscie_na_drugi_uklad; // hunter-081211: poprawka literowki
// PSound dsbHiss1; // PSound dsbHiss1;
// PSound dsbHiss2; // PSound dsbHiss2;
// McZapkie-280302 // McZapkie-280302
TRealSound rsBrake; sound_source rsBrake;
TRealSound rsSlippery; sound_source rsSlippery;
TRealSound rsHiss; // upuszczanie sound_source rsHiss; // upuszczanie
TRealSound rsHissU; // napelnianie sound_source rsHissU; // napelnianie
TRealSound rsHissE; // nagle sound_source rsHissE; // nagle
TRealSound rsHissX; // fala sound_source rsHissX; // fala
TRealSound rsHissT; // czasowy sound_source rsHissT; // czasowy
TRealSound rsSBHiss; sound_source rsSBHiss;
TRealSound rsRunningNoise; sound_source rsRunningNoise;
TRealSound rsEngageSlippery; sound_source rsEngageSlippery;
TRealSound rsFadeSound; sound_source rsFadeSound;
PSound dsbHasler; sound_source dsbHasler;
PSound dsbBuzzer; sound_source dsbBuzzer;
PSound dsbSlipAlarm; // Bombardier 011010: alarm przy poslizgu dla 181/182 sound_source dsbSlipAlarm; // Bombardier 011010: alarm przy poslizgu dla 181/182
int iCabLightFlag; // McZapkie:120503: oswietlenie kabiny (0: wyl, 1: przyciemnione, 2: pelne) int iCabLightFlag; // McZapkie:120503: oswietlenie kabiny (0: wyl, 1: przyciemnione, 2: pelne)
bool bCabLight; // hunter-091012: czy swiatlo jest zapalone? bool bCabLight; // hunter-091012: czy swiatlo jest zapalone?
@@ -453,11 +442,10 @@ public: // reszta może by?publiczna
vector3 pMechSittingPosition; // ABu 180404 vector3 pMechSittingPosition; // ABu 180404
vector3 MirrorPosition(bool lewe); vector3 MirrorPosition(bool lewe);
private: private:
// PSound dsbBuzzer; sound_source dsbCouplerStretch;
PSound dsbCouplerStretch; sound_source dsbEN57_CouplerStretch;
PSound dsbEN57_CouplerStretch; sound_source dsbBufferClamp;
PSound dsbBufferClamp;
double fBlinkTimer; double fBlinkTimer;
float fHaslerTimer; float fHaslerTimer;
float fConverterTimer; // hunter-261211: dla przekaznika float fConverterTimer; // hunter-261211: dla przekaznika
@@ -509,5 +497,6 @@ public: // reszta może by?publiczna
inline TMoverParameters *Controlled() { return mvControlled; }; inline TMoverParameters *Controlled() { return mvControlled; };
void DynamicSet(TDynamicObject *d); void DynamicSet(TDynamicObject *d);
void Silence(); void Silence();
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -196,8 +196,6 @@ TWorld::TWorld()
TWorld::~TWorld() TWorld::~TWorld()
{ {
TrainDelete(); TrainDelete();
// Ground.Free(); //Ra: usunięcie obiektów przed usunięciem dźwięków - sypie się
TSoundsManager::Free();
} }
void TWorld::TrainDelete(TDynamicObject *d) 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" ); "ShaXbee, Oli_EU, youBy, KURS90, Ra, hunter, szociu, Stele, Q, firleju and others\n" );
UILayer.set_background( "logo" ); UILayer.set_background( "logo" );
#ifdef EU07_USE_OLD_SOUNDCODE
if( true == TSoundsManager::Init( glfwGetWin32Window( window ) ) ) { if( true == TSoundsManager::Init( glfwGetWin32Window( window ) ) ) {
WriteLog( "Sound subsystem setup complete" ); WriteLog( "Sound subsystem setup complete" );
} }
@@ -242,7 +240,7 @@ bool TWorld::Init( GLFWwindow *Window ) {
ErrorLog( "Sound subsystem setup failed" ); ErrorLog( "Sound subsystem setup failed" );
return false; return false;
} }
#endif
glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii
UILayer.set_progress(0.01); UILayer.set_progress(0.01);
UILayer.set_progress( "Loading scenery / Wczytywanie scenerii" ); UILayer.set_progress( "Loading scenery / Wczytywanie scenerii" );
@@ -689,7 +687,7 @@ void TWorld::OnKeyDown(int cKey)
vehicle->MoverParameters->DecBrakeMult()) vehicle->MoverParameters->DecBrakeMult())
if (Train) if (Train)
{ // dźwięk oczywiście jest w kabinie { // 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; vehicle->iLights[CouplNr] = (vehicle->iLights[CouplNr] & ~mask) | set;
if (Train) if (Train)
{ // Ra: ten dźwięk z kabiny to przegięcie, ale na razie zostawiam { // 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 (vehicle->MoverParameters->IncLocalBrakeLevelFAST())
if (Train) if (Train)
{ // dźwięk oczywiście jest w kabinie { // 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 (vehicle->MoverParameters->DecLocalBrakeLevelFAST())
if (Train) if (Train)
{ // dźwięk oczywiście jest w kabinie { // 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"> <ClCompile Include="audio.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="sound.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Globals.h"> <ClInclude Include="Globals.h">
@@ -452,6 +455,9 @@
<ClInclude Include="audio.h"> <ClInclude Include="audio.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="sound.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="maszyna.rc"> <ResourceCompile Include="maszyna.rc">

View File

@@ -14,6 +14,8 @@ http://mozilla.org/MPL/2.0/.
#include "logs.h" #include "logs.h"
#include "globals.h" #include "globals.h"
namespace gfx {
void void
basic_vertex::serialize( std::ostream &s ) const { 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 // 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 // creates a new geometry chunk of specified type from supplied vertex data. returns: handle to the chunk
geometry_handle gfx::geometry_handle
geometry_bank::create( vertex_array &Vertices, unsigned int const Type ) { 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 ); 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 // 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 // template method implementation
create_( chunkhandle ); create_( chunkhandle );
// all done // 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 // replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool 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; } 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 ) if( ( Offset == 0 )
&& ( Vertices.size() == chunk.vertices.size() ) ) { && ( 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 // ...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 // 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 // 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 ) ); chunk.vertices.insert( std::end( chunk.vertices ), std::begin( Vertices ), std::end( Vertices ) );
} }
// template method implementation // 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 // adds supplied vertex data at the end of specified chunk
bool 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; } 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 // draws geometry stored in specified chunk
void 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 // template method implementation
draw_( Geometry, Units, Streams ); draw_( Geometry, Units, Streams );
} }
@@ -111,7 +113,7 @@ geometry_bank::release() {
} }
vertex_array const & 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; 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 // opengl vbo-based variant of the geometry bank
GLuint opengl_vbogeometrybank::m_activebuffer { 0 }; // buffer bound currently on the opengl end, if any 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 std::vector<GLint> opengl_vbogeometrybank::m_activetexturearrays; // currently enabled texture coord arrays
// create() subclass details // create() subclass details
void 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. // 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 // thus we don't need to initialize the values here
m_chunkrecords.emplace_back( chunk_record() ); m_chunkrecords.emplace_back( chunk_record() );
@@ -134,7 +136,7 @@ opengl_vbogeometrybank::create_( geometry_handle const &Geometry ) {
// replace() subclass details // replace() subclass details
void void
opengl_vbogeometrybank::replace_( geometry_handle const &Geometry ) { opengl_vbogeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ]; auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
chunkrecord.is_good = false; chunkrecord.is_good = false;
@@ -149,7 +151,7 @@ opengl_vbogeometrybank::replace_( geometry_handle const &Geometry ) {
// draw() subclass details // draw() subclass details
void 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( m_buffer == 0 ) {
// if there's no buffer, we'll have to make one // 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 // TODO: allow to specify usage hint at the object creation, and pass it here
::glBufferData( ::glBufferData(
GL_ARRAY_BUFFER, GL_ARRAY_BUFFER,
datasize * sizeof( basic_vertex ), datasize * sizeof( gfx::basic_vertex ),
nullptr, nullptr,
GL_STATIC_DRAW ); GL_STATIC_DRAW );
if( ::glGetError() == GL_OUT_OF_MEMORY ) { if( ::glGetError() == GL_OUT_OF_MEMORY ) {
@@ -193,13 +195,13 @@ opengl_vbogeometrybank::draw_( geometry_handle const &Geometry, stream_units con
bind_buffer(); bind_buffer();
} }
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ]; 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 ) { if( false == chunkrecord.is_good ) {
// we may potentially need to upload new buffer data before we can draw it // we may potentially need to upload new buffer data before we can draw it
::glBufferSubData( ::glBufferSubData(
GL_ARRAY_BUFFER, GL_ARRAY_BUFFER,
chunkrecord.offset * sizeof( basic_vertex ), chunkrecord.offset * sizeof( gfx::basic_vertex ),
chunkrecord.size * sizeof( basic_vertex ), chunkrecord.size * sizeof( gfx::basic_vertex ),
chunk.vertices.data() ); chunk.vertices.data() );
chunkrecord.is_good = true; chunkrecord.is_good = true;
} }
@@ -229,7 +231,7 @@ opengl_vbogeometrybank::bind_buffer() {
::glBindBuffer( GL_ARRAY_BUFFER, m_buffer ); ::glBindBuffer( GL_ARRAY_BUFFER, m_buffer );
m_activebuffer = m_buffer; m_activebuffer = m_buffer;
m_activestreams = stream::none; m_activestreams = gfx::stream::none;
} }
void void
@@ -250,34 +252,34 @@ opengl_vbogeometrybank::delete_buffer() {
} }
void 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 ) { if( Streams & gfx::stream::position ) {
::glVertexPointer( 3, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) ); ::glVertexPointer( 3, GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) );
::glEnableClientState( GL_VERTEX_ARRAY ); ::glEnableClientState( GL_VERTEX_ARRAY );
} }
else { else {
::glDisableClientState( GL_VERTEX_ARRAY ); ::glDisableClientState( GL_VERTEX_ARRAY );
} }
// NOTE: normal and color streams share the data, making them effectively mutually exclusive // NOTE: normal and color streams share the data, making them effectively mutually exclusive
if( Streams & stream::normal ) { if( Streams & gfx::stream::normal ) {
::glNormalPointer( GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 ); ::glNormalPointer( GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
::glEnableClientState( GL_NORMAL_ARRAY ); ::glEnableClientState( GL_NORMAL_ARRAY );
} }
else { else {
::glDisableClientState( GL_NORMAL_ARRAY ); ::glDisableClientState( GL_NORMAL_ARRAY );
} }
if( Streams & stream::color ) { if( Streams & gfx::stream::color ) {
::glColorPointer( 3, GL_FLOAT, sizeof( basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 ); ::glColorPointer( 3, GL_FLOAT, sizeof( gfx::basic_vertex ), static_cast<char *>( nullptr ) + sizeof( float ) * 3 );
::glEnableClientState( GL_COLOR_ARRAY ); ::glEnableClientState( GL_COLOR_ARRAY );
} }
else { else {
::glDisableClientState( GL_COLOR_ARRAY ); ::glDisableClientState( GL_COLOR_ARRAY );
} }
if( Streams & stream::texture ) { if( Streams & gfx::stream::texture ) {
for( auto unit : Units.texture ) { for( auto unit : Units.texture ) {
::glClientActiveTexture( unit ); ::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 ); ::glEnableClientState( GL_TEXTURE_COORD_ARRAY );
} }
m_activetexturearrays = Units.texture; m_activetexturearrays = Units.texture;
@@ -304,7 +306,7 @@ opengl_vbogeometrybank::release_streams() {
::glDisableClientState( GL_TEXTURE_COORD_ARRAY ); ::glDisableClientState( GL_TEXTURE_COORD_ARRAY );
} }
m_activestreams = stream::none; m_activestreams = gfx::stream::none;
m_activetexturearrays.clear(); m_activetexturearrays.clear();
} }
@@ -312,21 +314,21 @@ opengl_vbogeometrybank::release_streams() {
// create() subclass details // create() subclass details
void void
opengl_dlgeometrybank::create_( geometry_handle const &Geometry ) { opengl_dlgeometrybank::create_( gfx::geometry_handle const &Geometry ) {
m_chunkrecords.emplace_back( chunk_record() ); m_chunkrecords.emplace_back( chunk_record() );
} }
// replace() subclass details // replace() subclass details
void void
opengl_dlgeometrybank::replace_( geometry_handle const &Geometry ) { opengl_dlgeometrybank::replace_( gfx::geometry_handle const &Geometry ) {
delete_list( Geometry ); delete_list( Geometry );
} }
// draw() subclass details // draw() subclass details
void 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 ]; auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
if( chunkrecord.streams != Streams ) { 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 // we don't have a list ready, so compile one
chunkrecord.streams = Streams; chunkrecord.streams = Streams;
chunkrecord.list = ::glGenLists( 1 ); chunkrecord.list = ::glGenLists( 1 );
auto const &chunk = geometry_bank::chunk( Geometry ); auto const &chunk = gfx::geometry_bank::chunk( Geometry );
::glNewList( chunkrecord.list, GL_COMPILE ); ::glNewList( chunkrecord.list, GL_COMPILE );
::glBegin( chunk.type ); ::glBegin( chunk.type );
for( auto const &vertex : chunk.vertices ) { for( auto const &vertex : chunk.vertices ) {
if( Streams & stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); } if( Streams & gfx::stream::normal ) { ::glNormal3fv( glm::value_ptr( vertex.normal ) ); }
else if( Streams & stream::color ) { ::glColor3fv( glm::value_ptr( vertex.normal ) ); } else if( Streams & gfx::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 & gfx::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::position ) { ::glVertex3fv( glm::value_ptr( vertex.position ) ); }
} }
::glEnd(); ::glEnd();
::glEndList(); ::glEndList();
@@ -362,19 +364,19 @@ opengl_dlgeometrybank::release_() {
::glDeleteLists( chunkrecord.list, 1 ); ::glDeleteLists( chunkrecord.list, 1 );
chunkrecord.list = 0; chunkrecord.list = 0;
} }
chunkrecord.streams = stream::none; chunkrecord.streams = gfx::stream::none;
} }
} }
void 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 // NOTE: given it's our own internal method we trust it to be called with valid parameters
auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ]; auto &chunkrecord = m_chunkrecords[ Geometry.chunk - 1 ];
if( chunkrecord.list != 0 ) { if( chunkrecord.list != 0 ) {
::glDeleteLists( chunkrecord.list, 1 ); ::glDeleteLists( chunkrecord.list, 1 );
chunkrecord.list = 0; chunkrecord.list = 0;
} }
chunkrecord.streams = stream::none; chunkrecord.streams = gfx::stream::none;
} }
// geometry bank manager, holds collection of geometry banks // 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 // creates a new geometry bank. returns: handle to the bank or NULL
geometrybank_handle gfx::geometrybank_handle
geometrybank_manager::create_bank() { geometrybank_manager::create_bank() {
if( true == Global::bUseVBO ) { m_geometrybanks.emplace_back( std::make_shared<opengl_vbogeometrybank>(), std::chrono::steady_clock::time_point() ); } 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() ); } 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 // 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 // creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
geometry_handle gfx::geometry_handle
geometrybank_manager::create_chunk( vertex_array &Vertices, geometrybank_handle const &Geometry, int const Type ) { 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 ); auto const newchunkhandle = bank( Geometry ).first->create( Vertices, Type );
if( newchunkhandle.chunk != 0 ) { return geometry_handle( Geometry.bank, newchunkhandle.chunk ); } if( newchunkhandle.chunk != 0 ) { return { Geometry.bank, newchunkhandle.chunk }; }
else { return geometry_handle( 0, 0 ); } else { return { 0, 0 }; }
} }
// replaces data of specified chunk with the supplied vertex data, starting from specified offset // replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool 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 ); return bank( Geometry ).first->replace( Vertices, Geometry, Offset );
} }
// adds supplied vertex data at the end of specified chunk // adds supplied vertex data at the end of specified chunk
bool 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 ); return bank( Geometry ).first->append( Vertices, Geometry );
} }
// draws geometry stored in specified chunk // draws geometry stored in specified chunk
void 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; } 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 // provides direct access to vertex data of specfied chunk
vertex_array const & gfx::vertex_array const &
geometrybank_manager::vertices( geometry_handle const &Geometry ) const { geometrybank_manager::vertices( gfx::geometry_handle const &Geometry ) const {
return bank( Geometry ).first->vertices( Geometry ); return bank( Geometry ).first->vertices( Geometry );
} }
} // namespace gfx

View File

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

View File

@@ -156,20 +156,20 @@ public:
// geometry methods // 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 // 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 // creates a new geometry bank. returns: handle to the bank or NULL
geometrybank_handle gfx::geometrybank_handle
Create_Bank(); Create_Bank();
// creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL // creates a new geometry chunk of specified type from supplied vertex data, in specified bank. returns: handle to the chunk or NULL
geometry_handle gfx::geometry_handle
Insert( vertex_array &Vertices, geometrybank_handle const &Geometry, int const Type ); 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 // replaces data of specified chunk with the supplied vertex data, starting from specified offset
bool 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 // adds supplied vertex data at the end of specified chunk
bool 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 // provides direct access to vertex data of specfied chunk
vertex_array const & gfx::vertex_array const &
Vertices( geometry_handle const &Geometry ) const; Vertices( gfx::geometry_handle const &Geometry ) const;
// material methods // material methods
material_handle material_handle
Fetch_Material( std::string const &Filename, bool const Loadnow = true ); Fetch_Material( std::string const &Filename, bool const Loadnow = true );
@@ -337,12 +337,12 @@ private:
// members // members
GLFWwindow *m_window { nullptr }; GLFWwindow *m_window { nullptr };
geometrybank_manager m_geometry; gfx::geometrybank_manager m_geometry;
material_manager m_materials; material_manager m_materials;
texture_manager m_textures; texture_manager m_textures;
opengllight_array m_lights; 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_glaretexture { -1 };
texture_handle m_suntexture { -1 }; texture_handle m_suntexture { -1 };
texture_handle m_moontexture { -1 }; texture_handle m_moontexture { -1 };

View File

@@ -125,11 +125,13 @@ basic_cell::update_sounds() {
// sounds // sounds
auto const deltatime = Timer::GetDeltaRenderTime(); auto const deltatime = Timer::GetDeltaRenderTime();
for( auto *sound : m_sounds ) { for( auto *sound : m_sounds ) {
#ifdef EU07_USE_OLD_SOUNDCODE
if( ( sound->GetStatus() & DSBSTATUS_PLAYING ) == DSBPLAY_LOOPING ) { if( ( sound->GetStatus() & DSBSTATUS_PLAYING ) == DSBPLAY_LOOPING ) {
sound->Play( 1, DSBPLAY_LOOPING, true, sound->vSoundPosition ); sound->Play( 1, DSBPLAY_LOOPING, true, sound->vSoundPosition );
sound->AdjFreq( 1.0, deltatime ); sound->AdjFreq( 1.0, deltatime );
} }
#else
#endif
} }
// TBD, TODO: move to sound renderer // TBD, TODO: move to sound renderer
for( auto *path : m_paths ) { for( auto *path : m_paths ) {
@@ -348,7 +350,11 @@ basic_cell::insert( TAnimModel *Instance ) {
// adds provided sound instance to the cell // adds provided sound instance to the cell
void void
#ifdef EU07_USE_OLD_SOUNDCODE
basic_cell::insert( TTextSound *Sound ) { basic_cell::insert( TTextSound *Sound ) {
#else
basic_cell::insert( sound_source *Sound ) {
#endif
m_active = true; m_active = true;
@@ -514,7 +520,7 @@ basic_cell::center( glm::dvec3 Center ) {
// generates renderable version of held non-instanced geometry // generates renderable version of held non-instanced geometry
void 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 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 // inserts provided sound in the region
void void
#ifdef EU07_USE_OLD_SOUNDCODE
basic_region::insert_sound( TTextSound *Sound, scratch_data &Scratchpad ) { 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 // NOTE: bounding area isn't present/filled until track class and wrapper refactoring is done
auto location = Sound->location(); 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 // 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 ) + ")" ); 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 // 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 "scenenode.h"
#include "track.h" #include "track.h"
#include "traction.h" #include "traction.h"
#include "sound.h"
namespace scene { namespace scene {
@@ -104,7 +105,11 @@ public:
insert( TAnimModel *Instance ); insert( TAnimModel *Instance );
// adds provided sound instance to the cell // adds provided sound instance to the cell
void void
#ifdef EU07_USE_OLD_SOUNDCODE
insert( TTextSound *Sound ); insert( TTextSound *Sound );
#else
insert( sound_source *Sound );
#endif
// adds provided event launcher to the cell // adds provided event launcher to the cell
void void
insert( TEventLauncher *Launcher ); insert( TEventLauncher *Launcher );
@@ -131,7 +136,7 @@ public:
center( glm::dvec3 Center ); center( glm::dvec3 Center );
// generates renderable version of held non-instanced geometry in specified geometry bank // generates renderable version of held non-instanced geometry in specified geometry bank
void void
create_geometry( geometrybank_handle const &Bank ); create_geometry( gfx::geometrybank_handle const &Bank );
// provides access to bounding area data // provides access to bounding area data
bounding_area const & bounding_area const &
area() const { area() const {
@@ -144,7 +149,11 @@ private:
using path_sequence = std::vector<TTrack *>; using path_sequence = std::vector<TTrack *>;
using traction_sequence = std::vector<TTraction *>; using traction_sequence = std::vector<TTraction *>;
using instance_sequence = std::vector<TAnimModel *>; using instance_sequence = std::vector<TAnimModel *>;
#ifdef EU07_USE_OLD_SOUNDCODE
using sound_sequence = std::vector<TTextSound *>; using sound_sequence = std::vector<TTextSound *>;
#else
using sound_sequence = std::vector<sound_source *>;
#endif
using eventlauncher_sequence = std::vector<TEventLauncher *>; using eventlauncher_sequence = std::vector<TEventLauncher *>;
// methods // methods
void void
@@ -258,7 +267,7 @@ private:
shapenode_sequence m_shapes; // large pieces of opaque geometry and (legacy) terrain shapenode_sequence m_shapes; // large pieces of opaque geometry and (legacy) terrain
// TODO: implement dedicated, higher fidelity, fixed resolution terrain mesh item // TODO: implement dedicated, higher fidelity, fixed resolution terrain mesh item
// gfx renderer data // gfx renderer data
geometrybank_handle m_geometrybank; gfx::geometrybank_handle m_geometrybank;
bool m_geometrycreated { false }; bool m_geometrycreated { false };
}; };
@@ -311,7 +320,11 @@ public:
insert_instance( TAnimModel *Instance, scratch_data &Scratchpad ); insert_instance( TAnimModel *Instance, scratch_data &Scratchpad );
// inserts provided sound in the region // inserts provided sound in the region
void void
#ifdef EU07_USE_OLD_SOUNDCODE
insert_sound( TTextSound *Sound, scratch_data &Scratchpad ); insert_sound( TTextSound *Sound, scratch_data &Scratchpad );
#else
insert_sound( sound_source *Sound, scratch_data &Scratchpad );
#endif
// inserts provided event launcher in the region // inserts provided event launcher in the region
void void
insert_launcher( TEventLauncher *Launcher, scratch_data &Scratchpad ); 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 // vertex count, followed by vertex data
sn_utils::ls_uint32( Output, vertices.size() ); sn_utils::ls_uint32( Output, vertices.size() );
for( auto const &vertex : vertices ) { for( auto const &vertex : vertices ) {
basic_vertex( gfx::basic_vertex(
glm::vec3{ vertex.position - origin }, glm::vec3{ vertex.position - origin },
vertex.normal, vertex.normal,
vertex.texture ) vertex.texture )
@@ -109,7 +109,7 @@ shape_node::shapenode_data::deserialize( std::istream &Input ) {
// NOTE: geometry handle is acquired during geometry creation // NOTE: geometry handle is acquired during geometry creation
// vertex data // vertex data
vertices.resize( sn_utils::ld_uint32( Input ) ); vertices.resize( sn_utils::ld_uint32( Input ) );
basic_vertex localvertex; gfx::basic_vertex localvertex;
for( auto &vertex : vertices ) { for( auto &vertex : vertices ) {
localvertex.deserialize( Input ); localvertex.deserialize( Input );
vertex.position = origin + glm::dvec3{ localvertex.position }; 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 // generates renderable version of held non-instanced geometry in specified geometry bank
void 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 ) { for( auto const &vertex : m_data.vertices ) {
vertices.emplace_back( vertices.emplace_back(
@@ -464,7 +464,7 @@ lines_node::linesnode_data::serialize( std::ostream &Output ) const {
// vertex count, followed by vertex data // vertex count, followed by vertex data
sn_utils::ls_uint32( Output, vertices.size() ); sn_utils::ls_uint32( Output, vertices.size() );
for( auto const &vertex : vertices ) { for( auto const &vertex : vertices ) {
basic_vertex( gfx::basic_vertex(
glm::vec3{ vertex.position - origin }, glm::vec3{ vertex.position - origin },
vertex.normal, vertex.normal,
vertex.texture ) vertex.texture )
@@ -489,7 +489,7 @@ lines_node::linesnode_data::deserialize( std::istream &Input ) {
// NOTE: geometry handle is acquired during geometry creation // NOTE: geometry handle is acquired during geometry creation
// vertex data // vertex data
vertices.resize( sn_utils::ld_uint32( Input ) ); vertices.resize( sn_utils::ld_uint32( Input ) );
basic_vertex localvertex; gfx::basic_vertex localvertex;
for( auto &vertex : vertices ) { for( auto &vertex : vertices ) {
localvertex.deserialize( Input ); localvertex.deserialize( Input );
vertex.position = origin + glm::dvec3{ localvertex.position }; 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 // generates renderable version of held non-instanced geometry in specified geometry bank
void 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 ) { for( auto const &vertex : m_data.vertices ) {
vertices.emplace_back( vertices.emplace_back(

View File

@@ -93,7 +93,7 @@ public:
lighting_data lighting; lighting_data lighting;
// geometry data // geometry data
glm::dvec3 origin; // world position of the relative coordinate system origin 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 std::vector<world_vertex> vertices; // world space source data of the geometry
// methods: // methods:
// sends content of the struct to provided stream // sends content of the struct to provided stream
@@ -122,7 +122,7 @@ public:
merge( shape_node &Shape ); merge( shape_node &Shape );
// generates renderable version of held non-instanced geometry in specified geometry bank // generates renderable version of held non-instanced geometry in specified geometry bank
void void
create_geometry( geometrybank_handle const &Bank ); create_geometry( gfx::geometrybank_handle const &Bank );
// calculates shape's bounding radius // calculates shape's bounding radius
void void
compute_radius(); compute_radius();
@@ -182,7 +182,7 @@ public:
lighting_data lighting; lighting_data lighting;
// geometry data // geometry data
glm::dvec3 origin; // world position of the relative coordinate system origin 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 std::vector<world_vertex> vertices; // world space source data of the geometry
// methods: // methods:
// sends content of the struct to provided stream // sends content of the struct to provided stream
@@ -208,7 +208,7 @@ public:
merge( lines_node &Lines ); merge( lines_node &Lines );
// generates renderable version of held non-instanced geometry in specified geometry bank // generates renderable version of held non-instanced geometry in specified geometry bank
void void
create_geometry( geometrybank_handle const &Bank ); create_geometry( gfx::geometrybank_handle const &Bank );
// calculates shape's bounding radius // calculates shape's bounding radius
void void
compute_radius(); 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 ) }; auto *sound { deserialize_sound( Input, Scratchpad, nodedata ) };
if( false == simulation::Sounds.insert( sound ) ) { 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 ) + ")" ); 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 ); simulation::Region->insert_sound( sound, Scratchpad );
} }
@@ -830,7 +833,11 @@ state_manager::deserialize_dynamic( cParser &Input, scene::scratch_data &Scratch
return vehicle; return vehicle;
} }
#ifdef EU07_USE_OLD_SOUNDCODE
TTextSound * TTextSound *
#else
sound_source *
#endif
state_manager::deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata ) { state_manager::deserialize_sound( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata ) {
glm::dvec3 location; glm::dvec3 location;
@@ -842,9 +849,14 @@ state_manager::deserialize_sound( cParser &Input, scene::scratch_data &Scratchpa
// adjust location // adjust location
location = transform( location, Scratchpad ); location = transform( location, Scratchpad );
#ifdef EU07_USE_OLD_SOUNDCODE
auto const soundname { Input.getToken<std::string>() }; 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 ); auto *sound = new TTextSound( soundname, Nodedata.range_max, location.x, location.y, location.z, false, false, Nodedata.range_min );
sound->name( Nodedata.name ); sound->name( Nodedata.name );
#else
auto *sound = new sound_source();
sound->deserialize( Input.getToken<std::string>(), sound_type::single );
#endif
skip_until( Input, "endsound" ); skip_until( Input, "endsound" );

View File

@@ -17,7 +17,7 @@ http://mozilla.org/MPL/2.0/.
#include "track.h" #include "track.h"
#include "traction.h" #include "traction.h"
#include "tractionpower.h" #include "tractionpower.h"
#include "realsound.h" #include "sound.h"
#include "animmodel.h" #include "animmodel.h"
#include "dynobj.h" #include "dynobj.h"
#include "driver.h" #include "driver.h"
@@ -64,7 +64,11 @@ private:
TEventLauncher * deserialize_eventlauncher( cParser &Input, scene::scratch_data &Scratchpad, scene::node_data const &Nodedata ); 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 ); 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 ); 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 ); 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 // skips content of stream until specified token
void skip_until( cParser &Input, std::string const &Token ); void skip_until( cParser &Input, std::string const &Token );
// transforms provided location by specifed rotation and offset // 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> {
};
//---------------------------------------------------------------------------