mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 22:09:19 +02:00
replaced char parameters in sound system with stl string
This commit is contained in:
@@ -5072,7 +5072,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
|||||||
// 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);
|
// sBrakeAcc.Init(str.c_str(),Parser->GetNextSymbol().ToDouble(),GetPosition().x,GetPosition().y,GetPosition().z,true);
|
||||||
parser.getTokens( 1, false ); parser >> token;
|
parser.getTokens( 1, false ); parser >> token;
|
||||||
sBrakeAcc = TSoundsManager::GetFromName( token.c_str(), true );
|
sBrakeAcc = TSoundsManager::GetFromName( token, true );
|
||||||
bBrakeAcc = true;
|
bBrakeAcc = true;
|
||||||
// sBrakeAcc.AM=1.0;
|
// sBrakeAcc.AM=1.0;
|
||||||
// sBrakeAcc.AA=0.0;
|
// sBrakeAcc.AA=0.0;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void TFadeSound::Free()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TFadeSound::Init(char *Name, float fNewFade)
|
void TFadeSound::Init(std::string const &Name, float fNewFade)
|
||||||
{
|
{
|
||||||
Sound = TSoundsManager::GetFromName(Name, false);
|
Sound = TSoundsManager::GetFromName(Name, false);
|
||||||
if (Sound)
|
if (Sound)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class TFadeSound
|
|||||||
public:
|
public:
|
||||||
TFadeSound();
|
TFadeSound();
|
||||||
~TFadeSound();
|
~TFadeSound();
|
||||||
void Init(char *Name, float fNewFade);
|
void Init(std::string const &Name, float fNewFade);
|
||||||
void TurnOn();
|
void TurnOn();
|
||||||
void TurnOff();
|
void TurnOff();
|
||||||
bool Playing()
|
bool Playing()
|
||||||
|
|||||||
@@ -823,11 +823,19 @@ void TSubRect::LoadNodes()
|
|||||||
break;
|
break;
|
||||||
case TP_TRACK:
|
case TP_TRACK:
|
||||||
if (n->iNumVerts) // bo tory zabezpieczające są niewidoczne
|
if (n->iNumVerts) // bo tory zabezpieczające są niewidoczne
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
n->pTrack->RaArrayFill( m_pVNT + n->iVboPtr, m_pVNT );
|
n->pTrack->RaArrayFill( m_pVNT + n->iVboPtr, m_pVNT );
|
||||||
|
#else
|
||||||
|
n->pTrack->RaArrayFill(m_pVNT.data() + n->iVboPtr, m_pVNT.data());
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case TP_TRACTION:
|
case TP_TRACTION:
|
||||||
if (n->iNumVerts) // druty mogą być niewidoczne...?
|
if (n->iNumVerts) // druty mogą być niewidoczne...?
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
n->hvTraction->RaArrayFill( m_pVNT + n->iVboPtr );
|
n->hvTraction->RaArrayFill( m_pVNT + n->iVboPtr );
|
||||||
|
#else
|
||||||
|
n->hvTraction->RaArrayFill(m_pVNT.data() + n->iVboPtr);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
n = n->nNext2; // następny z sektora
|
n = n->nNext2; // następny z sektora
|
||||||
|
|||||||
@@ -144,98 +144,6 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ReadWord(std::ifstream &infile)
|
|
||||||
{
|
|
||||||
std::string s = "";
|
|
||||||
char c;
|
|
||||||
bool nextword = false;
|
|
||||||
|
|
||||||
while ((!infile.eof()) && (!nextword))
|
|
||||||
{
|
|
||||||
infile.get(c);
|
|
||||||
if (_spacesigns.find(c) != std::string::npos)
|
|
||||||
if (s != "")
|
|
||||||
nextword = true;
|
|
||||||
if (_spacesigns.find(c) == std::string::npos)
|
|
||||||
s += c;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string TrimSpace(std::string &s)
|
|
||||||
{
|
|
||||||
/*int ii;
|
|
||||||
|
|
||||||
switch (Just)
|
|
||||||
{
|
|
||||||
case CutLeft:
|
|
||||||
{
|
|
||||||
ii = 0;
|
|
||||||
while ((ii < s.length()) && (s[ii + 1] == (char)" "))
|
|
||||||
++ii;
|
|
||||||
s = s.substr(ii + 1, s.length() - ii);
|
|
||||||
}
|
|
||||||
case CutRight:
|
|
||||||
{
|
|
||||||
ii = s.length();
|
|
||||||
while ((ii > 0) && (s[ii] == (char)" "))
|
|
||||||
--ii;
|
|
||||||
s = s.substr(0, ii);
|
|
||||||
}
|
|
||||||
case CutBoth:
|
|
||||||
{
|
|
||||||
s = TrimSpace(s, CutLeft);
|
|
||||||
s = TrimSpace(s, CutRight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s;*/
|
|
||||||
|
|
||||||
if (s.empty())
|
|
||||||
return "";
|
|
||||||
size_t first = s.find_first_not_of(' ');
|
|
||||||
if (first == std::string::npos)
|
|
||||||
return "";
|
|
||||||
size_t last = s.find_last_not_of(' ');
|
|
||||||
return s.substr(first, (last - first + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
char* TrimAndReduceSpaces(const char* s)
|
|
||||||
{ // redukuje spacje pomiedzy znakami do jednej
|
|
||||||
char* tmp = nullptr;
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
|
|
||||||
tmp = _strdup(s);
|
|
||||||
char* from = tmp + strspn(tmp, " ");
|
|
||||||
char* to = tmp;
|
|
||||||
|
|
||||||
do if ((*to = *from++) == ' ')
|
|
||||||
from += strspn(from, " ");
|
|
||||||
while (*to++);
|
|
||||||
|
|
||||||
while (*--to == ' ')
|
|
||||||
*to = '\0';
|
|
||||||
}
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ExtractKeyWord(std::string InS, std::string KeyWord)
|
|
||||||
{
|
|
||||||
std::string s;
|
|
||||||
InS = InS + " ";
|
|
||||||
std::size_t kwp = InS.find(KeyWord);
|
|
||||||
if (kwp != std::string::npos)
|
|
||||||
{
|
|
||||||
s = InS.substr(kwp, InS.length());
|
|
||||||
//s = Copy(InS, kwp, length(InS));
|
|
||||||
s = s.substr(0, s.find_first_of(" "));
|
|
||||||
//s = Copy(s, 1, Pos(" ", s) - 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s = "";
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string DUE(std::string s) /*Delete Before Equal sign*/
|
std::string DUE(std::string s) /*Delete Before Equal sign*/
|
||||||
{
|
{
|
||||||
//DUE = Copy(s, Pos("=", s) + 1, length(s));
|
//DUE = Copy(s, Pos("=", s) + 1, length(s));
|
||||||
@@ -473,8 +381,7 @@ void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R
|
|||||||
bool FileExists( std::string const &Filename ) {
|
bool FileExists( std::string const &Filename ) {
|
||||||
|
|
||||||
std::ifstream file( Filename );
|
std::ifstream file( Filename );
|
||||||
if( file.is_open() == false ) { return false; }
|
return( true == file.is_open() );
|
||||||
else { return true; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -105,11 +105,6 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability);
|
|||||||
/*to samo ale zawsze niezaleznie od DebugFlag*/
|
/*to samo ale zawsze niezaleznie od DebugFlag*/
|
||||||
|
|
||||||
/*operacje na stringach*/
|
/*operacje na stringach*/
|
||||||
std::string ReadWord( std::ifstream& infile); /*czyta slowo z wiersza pliku tekstowego*/
|
|
||||||
//std::string Ups(std::string s);
|
|
||||||
//std::string TrimSpace(std::string &s);
|
|
||||||
//char* TrimAndReduceSpaces(const char* s);
|
|
||||||
//std::string ExtractKeyWord(std::string InS, std::string KeyWord); /*wyciaga slowo kluczowe i lancuch do pierwszej spacji*/
|
|
||||||
std::string DUE(std::string s); /*Delete Until Equal sign*/
|
std::string DUE(std::string s); /*Delete Until Equal sign*/
|
||||||
std::string DWE(std::string s); /*Delete While Equal sign*/
|
std::string DWE(std::string s); /*Delete While Equal sign*/
|
||||||
std::string ExchangeCharInString(std::string const &s, const char &aim, const char &target); // zamienia jeden znak na drugi
|
std::string ExchangeCharInString(std::string const &s, const char &aim, const char &target); // zamienia jeden znak na drugi
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ void TModelsManager::Init()
|
|||||||
*/
|
*/
|
||||||
void TModelsManager::Free()
|
void TModelsManager::Free()
|
||||||
{
|
{
|
||||||
SafeDeleteArray(Models);
|
delete[] Models;
|
||||||
|
Models = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TModel3d * TModelsManager::LoadModel(std::string const &Name, bool dynamic)
|
TModel3d * TModelsManager::LoadModel(std::string const &Name, bool dynamic)
|
||||||
|
|||||||
@@ -14,16 +14,12 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
class TMdlContainer
|
class TMdlContainer
|
||||||
{
|
{
|
||||||
friend class TModelsManager;
|
friend class TModelsManager;
|
||||||
TMdlContainer()
|
|
||||||
{
|
|
||||||
Model = NULL;
|
|
||||||
};
|
|
||||||
~TMdlContainer()
|
~TMdlContainer()
|
||||||
{
|
{
|
||||||
SafeDelete(Model);
|
delete Model;
|
||||||
};
|
};
|
||||||
TModel3d * LoadModel(std::string const &NewName, bool dynamic);
|
TModel3d * LoadModel(std::string const &NewName, bool dynamic);
|
||||||
TModel3d *Model;
|
TModel3d *Model{ nullptr };
|
||||||
std::string Name;
|
std::string Name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
44
Model3d.cpp
44
Model3d.cpp
@@ -1577,8 +1577,12 @@ TModel3d::~TModel3d()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // wczytano z pliku binarnego (jest właścicielem tablic)
|
{ // wczytano z pliku binarnego (jest właścicielem tablic)
|
||||||
m_pVNT = NULL; // nie usuwać tego, bo wskazuje na iModel
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
Root = NULL;
|
m_pVNT = nullptr; // nie usuwać tego, bo wskazuje na iModel
|
||||||
|
#else
|
||||||
|
m_pVNT.clear();
|
||||||
|
#endif
|
||||||
|
Root = nullptr;
|
||||||
delete[] iModel; // usuwamy cały wczytany plik i to wystarczy
|
delete[] iModel; // usuwamy cały wczytany plik i to wystarczy
|
||||||
}
|
}
|
||||||
// później się jeszcze usuwa obiekt z którego dziedziczymy tabelę VBO
|
// później się jeszcze usuwa obiekt z którego dziedziczymy tabelę VBO
|
||||||
@@ -1801,7 +1805,11 @@ void TModel3d::SaveToBinFile(char const *FileName)
|
|||||||
transforms[i].serialize_float32(s);
|
transforms[i].serialize_float32(s);
|
||||||
|
|
||||||
MakeArray(iNumVerts);
|
MakeArray(iNumVerts);
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
Root->RaArrayFill(m_pVNT);
|
Root->RaArrayFill(m_pVNT);
|
||||||
|
#else
|
||||||
|
Root->RaArrayFill( m_pVNT.data() );
|
||||||
|
#endif
|
||||||
sn_utils::ls_uint32(s, MAKE_ID4('V', 'N', 'T', '0'));
|
sn_utils::ls_uint32(s, MAKE_ID4('V', 'N', 'T', '0'));
|
||||||
sn_utils::ls_uint32(s, 8 + iNumVerts * 32);
|
sn_utils::ls_uint32(s, 8 + iNumVerts * 32);
|
||||||
for (size_t i = 0; i < (size_t)iNumVerts; i++)
|
for (size_t i = 0; i < (size_t)iNumVerts; i++)
|
||||||
@@ -1886,7 +1894,11 @@ void TSubModel::deserialize(std::istream &s)
|
|||||||
|
|
||||||
void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
||||||
{
|
{
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
m_pVNT = nullptr;
|
m_pVNT = nullptr;
|
||||||
|
#else
|
||||||
|
m_pVNT.clear();
|
||||||
|
#endif
|
||||||
Root = nullptr;
|
Root = nullptr;
|
||||||
float4x4 *tm = nullptr;
|
float4x4 *tm = nullptr;
|
||||||
|
|
||||||
@@ -1900,13 +1912,22 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
|
|
||||||
if (type == MAKE_ID4('V', 'N', 'T', '0'))
|
if (type == MAKE_ID4('V', 'N', 'T', '0'))
|
||||||
{
|
{
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
if (m_pVNT != nullptr)
|
if (m_pVNT != nullptr)
|
||||||
|
#else
|
||||||
|
if( false == m_pVNT.empty() )
|
||||||
|
#endif
|
||||||
throw std::runtime_error("e3d: duplicated VNT chunk");
|
throw std::runtime_error("e3d: duplicated VNT chunk");
|
||||||
|
|
||||||
size_t vt_cnt = size / 32;
|
size_t vt_cnt = size / 32;
|
||||||
iNumVerts = (int)vt_cnt;
|
iNumVerts = (int)vt_cnt;
|
||||||
m_nVertexCount = (int)vt_cnt;
|
m_nVertexCount = (int)vt_cnt;
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
|
assert( m_pVNT == nullptr );
|
||||||
m_pVNT = new CVertNormTex[vt_cnt];
|
m_pVNT = new CVertNormTex[vt_cnt];
|
||||||
|
#else
|
||||||
|
m_pVNT.resize( vt_cnt );
|
||||||
|
#endif
|
||||||
for (size_t i = 0; i < vt_cnt; i++)
|
for (size_t i = 0; i < vt_cnt; i++)
|
||||||
m_pVNT[i].deserialize(s);
|
m_pVNT[i].deserialize(s);
|
||||||
}
|
}
|
||||||
@@ -1967,12 +1988,20 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
|||||||
if (!Root)
|
if (!Root)
|
||||||
throw std::runtime_error("e3d: no submodels");
|
throw std::runtime_error("e3d: no submodels");
|
||||||
|
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
if (!m_pVNT)
|
if (!m_pVNT)
|
||||||
|
#else
|
||||||
|
if(m_pVNT.empty() )
|
||||||
|
#endif
|
||||||
throw std::runtime_error("e3d: no vertices");
|
throw std::runtime_error("e3d: no vertices");
|
||||||
|
|
||||||
for (size_t i = 0; (int)i < iSubModelsCount; i++)
|
for (size_t i = 0; (int)i < iSubModelsCount; i++)
|
||||||
{
|
{
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
Root[i].BinInit(Root, tm, (float8*)m_pVNT, &Textures, &Names, dynamic);
|
Root[i].BinInit(Root, tm, (float8*)m_pVNT, &Textures, &Names, dynamic);
|
||||||
|
#else
|
||||||
|
Root[ i ].BinInit( Root, tm, (float8*)m_pVNT.data(), &Textures, &Names, dynamic );
|
||||||
|
#endif
|
||||||
|
|
||||||
if (Root[i].ChildGet())
|
if (Root[i].ChildGet())
|
||||||
Root[i].ChildGet()->Parent = &Root[i];
|
Root[i].ChildGet()->Parent = &Root[i];
|
||||||
@@ -2151,11 +2180,18 @@ void TModel3d::Init()
|
|||||||
*/
|
*/
|
||||||
if (Global::bUseVBO)
|
if (Global::bUseVBO)
|
||||||
{
|
{
|
||||||
if (!m_pVNT) // jeśli nie ma jeszcze tablicy (wczytano z pliku
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
// tekstowego)
|
if (!m_pVNT) // jeśli nie ma jeszcze tablicy (wczytano z pliku tekstowego)
|
||||||
|
#else
|
||||||
|
if( m_pVNT.empty() )
|
||||||
|
#endif
|
||||||
{ // tworzenie tymczasowej tablicy z wierzchołkami całego modelu
|
{ // tworzenie tymczasowej tablicy z wierzchołkami całego modelu
|
||||||
MakeArray(iNumVerts); // tworzenie tablic dla VBO
|
MakeArray(iNumVerts); // tworzenie tablic dla VBO
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
Root->RaArrayFill(m_pVNT); // wypełnianie tablicy
|
Root->RaArrayFill(m_pVNT); // wypełnianie tablicy
|
||||||
|
#else
|
||||||
|
Root->RaArrayFill( m_pVNT.data() ); // wypełnianie tablicy
|
||||||
|
#endif
|
||||||
BuildVBOs(); // tworzenie VBO i usuwanie tablicy z pamięci
|
BuildVBOs(); // tworzenie VBO i usuwanie tablicy z pamięci
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void TRealSound::Init(std::string const &SoundName, double DistanceAttenuation,
|
|||||||
bool Dynamic, bool freqmod, double rmin)
|
bool Dynamic, bool freqmod, double rmin)
|
||||||
{
|
{
|
||||||
// Nazwa=SoundName; //to tak raczej nie zadziała, (SoundName) jest tymczasowe
|
// Nazwa=SoundName; //to tak raczej nie zadziała, (SoundName) jest tymczasowe
|
||||||
pSound = TSoundsManager::GetFromName(SoundName.c_str(), Dynamic, &fFrequency);
|
pSound = TSoundsManager::GetFromName(SoundName, Dynamic, &fFrequency);
|
||||||
if (pSound)
|
if (pSound)
|
||||||
{
|
{
|
||||||
if (freqmod)
|
if (freqmod)
|
||||||
@@ -48,8 +48,7 @@ void TRealSound::Init(std::string const &SoundName, double DistanceAttenuation,
|
|||||||
{ // dla modulowanych nie może być zmiany mnożnika, bo częstotliwość w nagłówku byłą
|
{ // dla modulowanych nie może być zmiany mnożnika, bo częstotliwość w nagłówku byłą
|
||||||
// ignorowana, a mogła być inna niż 22050
|
// ignorowana, a mogła być inna niż 22050
|
||||||
fFrequency = 22050.0;
|
fFrequency = 22050.0;
|
||||||
ErrorLog("Bad sound: " + std::string(SoundName) +
|
ErrorLog("Bad sound: " + SoundName + ", as modulated, should have 22.05kHz in header");
|
||||||
", as modulated, should have 22.05kHz in header");
|
|
||||||
}
|
}
|
||||||
AM = 1.0;
|
AM = 1.0;
|
||||||
pSound->SetVolume(DSBVOLUME_MIN);
|
pSound->SetVolume(DSBVOLUME_MIN);
|
||||||
@@ -57,7 +56,7 @@ void TRealSound::Init(std::string const &SoundName, double DistanceAttenuation,
|
|||||||
else
|
else
|
||||||
{ // nie ma dźwięku, to jest wysyp
|
{ // nie ma dźwięku, to jest wysyp
|
||||||
AM = 0;
|
AM = 0;
|
||||||
ErrorLog("Missed sound: " + std::string(SoundName));
|
ErrorLog("Missed sound: " + SoundName);
|
||||||
}
|
}
|
||||||
if (DistanceAttenuation > 0.0)
|
if (DistanceAttenuation > 0.0)
|
||||||
{
|
{
|
||||||
@@ -268,26 +267,8 @@ void TTextSound::Play(double Volume, int Looping, bool ListenerInside, vector3 N
|
|||||||
{ // jeśli ma powiązany tekst
|
{ // jeśli ma powiązany tekst
|
||||||
DWORD stat;
|
DWORD stat;
|
||||||
pSound->GetStatus(&stat);
|
pSound->GetStatus(&stat);
|
||||||
if (!(stat & DSBSTATUS_PLAYING)) // jeśli nie jest aktualnie odgrywany
|
if (!(stat & DSBSTATUS_PLAYING)) {
|
||||||
{
|
// jeśli nie jest aktualnie odgrywany
|
||||||
/*
|
|
||||||
std::string t( asText );
|
|
||||||
size_t i;
|
|
||||||
do
|
|
||||||
{ // na razie zrobione jakkolwiek, docelowo przenieść teksty do tablicy nazw
|
|
||||||
i = t.find('\r'); // znak nowej linii
|
|
||||||
if( i == std::string::npos ) {
|
|
||||||
Global::tranTexts.Add( t, fTime, true );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Global::tranTexts.Add(t.substr(0, i), fTime, true);
|
|
||||||
t.erase(0, i + 1);
|
|
||||||
while (t.empty() ? false : (unsigned char)(t[1]) < 33)
|
|
||||||
t.erase(0, 1);
|
|
||||||
}
|
|
||||||
} while (i != std::string::npos);
|
|
||||||
*/
|
|
||||||
Global::tranTexts.Add( asText, fTime, true );
|
Global::tranTexts.Add( asText, fTime, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
112
Sound.cpp
112
Sound.cpp
@@ -14,7 +14,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Usefull.h"
|
#include "Usefull.h"
|
||||||
#include "mczapkie/mctools.h"
|
#include "mczapkie/mctools.h"
|
||||||
#include "WavRead.h"
|
#include "WavRead.h"
|
||||||
//#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
|
|
||||||
#define SAFE_RELEASE(p) \
|
#define SAFE_RELEASE(p) \
|
||||||
{ \
|
{ \
|
||||||
if (p) \
|
if (p) \
|
||||||
@@ -24,43 +24,31 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
char Directory[] = "sounds\\";
|
|
||||||
|
|
||||||
LPDIRECTSOUND TSoundsManager::pDS;
|
LPDIRECTSOUND TSoundsManager::pDS;
|
||||||
LPDIRECTSOUNDNOTIFY TSoundsManager::pDSNotify;
|
LPDIRECTSOUNDNOTIFY TSoundsManager::pDSNotify;
|
||||||
|
|
||||||
int TSoundsManager::Count = 0;
|
int TSoundsManager::Count = 0;
|
||||||
TSoundContainer *TSoundsManager::First = NULL;
|
TSoundContainer *TSoundsManager::First = NULL;
|
||||||
|
|
||||||
TSoundContainer::TSoundContainer(LPDIRECTSOUND pDS, const char *Directory, const char *strFileName,
|
TSoundContainer::TSoundContainer(LPDIRECTSOUND pDS, std::string const &Directory, std::string const &Filename, int NConcurrent)
|
||||||
int NConcurrent)
|
|
||||||
{ // wczytanie pliku dźwiękowego
|
{ // wczytanie pliku dźwiękowego
|
||||||
int hr = 111;
|
int hr = 111;
|
||||||
DSBuffer = NULL; // na początek, gdyby uruchomić dźwięków się nie udało
|
DSBuffer = nullptr; // na początek, gdyby uruchomić dźwięków się nie udało
|
||||||
|
|
||||||
Concurrent = NConcurrent;
|
Concurrent = NConcurrent;
|
||||||
|
|
||||||
Oldest = 0;
|
Oldest = 0;
|
||||||
// strcpy(Name, strFileName);
|
m_name = Directory + Filename;
|
||||||
|
|
||||||
strcpy(Name, Directory);
|
|
||||||
strcat(Name, strFileName);
|
|
||||||
|
|
||||||
CWaveSoundRead *pWaveSoundRead;
|
|
||||||
|
|
||||||
// Create a new wave file class
|
// Create a new wave file class
|
||||||
pWaveSoundRead = new CWaveSoundRead();
|
std::shared_ptr<CWaveSoundRead> pWaveSoundRead = std::make_shared<CWaveSoundRead>();
|
||||||
|
|
||||||
// Load the wave file
|
// Load the wave file
|
||||||
if (FAILED(pWaveSoundRead->Open(Name)))
|
if( ( FAILED( pWaveSoundRead->Open( m_name ) ) )
|
||||||
if (FAILED(pWaveSoundRead->Open(strdup(strFileName))))
|
&& ( FAILED( pWaveSoundRead->Open( Filename ) ) ) ) {
|
||||||
{
|
ErrorLog( "Missed sound: " + Filename );
|
||||||
// SetFileUI( hDlg, TEXT("Bad wave file.") );
|
|
||||||
ErrorLog( "Missed sound: " + std::string( strFileName ) );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(Name, ToLower(strFileName).c_str());
|
m_name = ToLower( Filename );
|
||||||
|
|
||||||
// Set up the direct sound buffer, and only request the flags needed
|
// Set up the direct sound buffer, and only request the flags needed
|
||||||
// since each requires some overhead and limits if the buffer can
|
// since each requires some overhead and limits if the buffer can
|
||||||
@@ -133,27 +121,10 @@ TSoundContainer::TSoundContainer(LPDIRECTSOUND pDS, const char *Directory, const
|
|||||||
// We dont need the wav file data buffer anymore, so delete it
|
// We dont need the wav file data buffer anymore, so delete it
|
||||||
delete[] pbWavData;
|
delete[] pbWavData;
|
||||||
|
|
||||||
delete pWaveSoundRead;
|
|
||||||
|
|
||||||
DSBuffers.push(DSBuffer);
|
DSBuffers.push(DSBuffer);
|
||||||
|
|
||||||
/*
|
|
||||||
for (int i=1; i<Concurrent; i++)
|
|
||||||
{
|
|
||||||
if( FAILED( hr= pDS->DuplicateSoundBuffer(pDSBuffer[0],&(pDSBuffer[i]))))
|
|
||||||
{
|
|
||||||
Concurrent= i;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
};*/
|
|
||||||
};
|
};
|
||||||
TSoundContainer::~TSoundContainer()
|
TSoundContainer::~TSoundContainer()
|
||||||
{
|
{
|
||||||
// for (int i=Concurrent-1; i>=0; i--)
|
|
||||||
// SAFE_RELEASE( pDSBuffer[i] );
|
|
||||||
// free(pDSBuffer);
|
|
||||||
while (!DSBuffers.empty())
|
while (!DSBuffers.empty())
|
||||||
{
|
{
|
||||||
SAFE_RELEASE(DSBuffers.top());
|
SAFE_RELEASE(DSBuffers.top());
|
||||||
@@ -185,84 +156,51 @@ void TSoundsManager::Free()
|
|||||||
SAFE_RELEASE(pDS);
|
SAFE_RELEASE(pDS);
|
||||||
};
|
};
|
||||||
|
|
||||||
TSoundContainer * TSoundsManager::LoadFromFile(const char *Dir, const char *Name, int Concurrent)
|
TSoundContainer * TSoundsManager::LoadFromFile( std::string const &Dir, std::string const &Filename, int Concurrent)
|
||||||
{
|
{
|
||||||
TSoundContainer *Tmp = First;
|
TSoundContainer *tmp = First;
|
||||||
First = new TSoundContainer(pDS, Dir, Name, Concurrent);
|
First = new TSoundContainer(pDS, Dir, Filename, Concurrent);
|
||||||
First->Next = Tmp;
|
First->Next = tmp;
|
||||||
Count++;
|
Count++;
|
||||||
return First; // albo NULL, jak nie wyjdzie (na razie zawsze wychodzi)
|
return First; // albo NULL, jak nie wyjdzie (na razie zawsze wychodzi)
|
||||||
};
|
};
|
||||||
|
|
||||||
void TSoundsManager::LoadSounds(char *Directory)
|
LPDIRECTSOUNDBUFFER TSoundsManager::GetFromName(std::string const &Name, bool Dynamic, float *fSamplingRate)
|
||||||
{ // wczytanie wszystkich plików z katalogu - mało elastyczne
|
|
||||||
WIN32_FIND_DATA FindFileData;
|
|
||||||
HANDLE handle = FindFirstFile("sounds\\*.wav", &FindFileData);
|
|
||||||
if (handle != INVALID_HANDLE_VALUE)
|
|
||||||
do
|
|
||||||
{
|
|
||||||
LoadFromFile(Directory, FindFileData.cFileName, 1);
|
|
||||||
} while (FindNextFile(handle, &FindFileData));
|
|
||||||
FindClose(handle);
|
|
||||||
};
|
|
||||||
|
|
||||||
LPDIRECTSOUNDBUFFER TSoundsManager::GetFromName(const char *Name, bool Dynamic, float *fSamplingRate)
|
|
||||||
{ // wyszukanie dźwięku w pamięci albo wczytanie z pliku
|
{ // wyszukanie dźwięku w pamięci albo wczytanie z pliku
|
||||||
|
std::string name{ ToLower(Name) };
|
||||||
std::string file;
|
std::string file;
|
||||||
if (Dynamic)
|
if (Dynamic)
|
||||||
{ // próba wczytania z katalogu pojazdu
|
{ // próba wczytania z katalogu pojazdu
|
||||||
file = Global::asCurrentDynamicPath + Name;
|
file = Global::asCurrentDynamicPath + name;
|
||||||
if (FileExists(file))
|
if (FileExists(file))
|
||||||
Name = file.c_str(); // nowa nazwa
|
name = file; // nowa nazwa
|
||||||
else
|
else
|
||||||
Dynamic = false; // wczytanie z "sounds/"
|
Dynamic = false; // wczytanie z "sounds/"
|
||||||
}
|
}
|
||||||
TSoundContainer *Next = First;
|
TSoundContainer *Next = First;
|
||||||
for (int i = 0; i < Count; i++)
|
for (int i = 0; i < Count; i++)
|
||||||
{
|
{
|
||||||
if (strcmp(Name, Next->Name) == 0)
|
if( name == Next->m_name ) {
|
||||||
{
|
|
||||||
if (fSamplingRate)
|
if (fSamplingRate)
|
||||||
*fSamplingRate = Next->fSamplingRate; // częstotliwość
|
*fSamplingRate = Next->fSamplingRate; // częstotliwość
|
||||||
return (Next->GetUnique(pDS));
|
return (Next->GetUnique(pDS));
|
||||||
// DSBuffers.
|
|
||||||
/*
|
|
||||||
Next->pDSBuffer[Next->Oldest]->Stop();
|
|
||||||
Next->pDSBuffer[Next->Oldest]->SetCurrentPosition(0);
|
|
||||||
if (Next->Oldest<Next->Concurrent-1)
|
|
||||||
{
|
|
||||||
Next->Oldest++;
|
|
||||||
return (Next->pDSBuffer[Next->Oldest-1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Next->Oldest= 0;
|
|
||||||
return (Next->pDSBuffer[Next->Concurrent-1]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* for (int j=0; j<Next->Concurrent; j++)
|
|
||||||
{
|
|
||||||
|
|
||||||
Next->pDSBuffer[j]->GetStatus(&dwStatus);
|
|
||||||
if ((dwStatus & DSBSTATUS_PLAYING) != DSBSTATUS_PLAYING)
|
|
||||||
return (Next->pDSBuffer[j]);
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Next = Next->Next;
|
Next = Next->Next;
|
||||||
};
|
};
|
||||||
if (Dynamic) // wczytanie z katalogu pojazdu
|
if (Dynamic) // wczytanie z katalogu pojazdu
|
||||||
Next = LoadFromFile("", Name, 1);
|
Next = LoadFromFile("", name, 1);
|
||||||
else
|
else
|
||||||
Next = LoadFromFile(Directory, Name, 1);
|
Next = LoadFromFile(szSoundPath, name, 1);
|
||||||
if (Next)
|
if (Next)
|
||||||
{ //
|
{ //
|
||||||
if (fSamplingRate)
|
if (fSamplingRate)
|
||||||
*fSamplingRate = Next->fSamplingRate; // częstotliwość
|
*fSamplingRate = Next->fSamplingRate; // częstotliwość
|
||||||
return Next->GetUnique(pDS);
|
return Next->GetUnique(pDS);
|
||||||
}
|
}
|
||||||
ErrorLog("Missed sound: " + std::string(Name) );
|
ErrorLog("Missed sound: " + Name );
|
||||||
return (NULL);
|
return (nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
void TSoundsManager::RestoreAll()
|
void TSoundsManager::RestoreAll()
|
||||||
@@ -299,10 +237,6 @@ void TSoundsManager::RestoreAll()
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// void TSoundsManager::Init(char *Name, int Concurrent)
|
|
||||||
// TSoundsManager::TSoundsManager(HWND hWnd)
|
|
||||||
// void TSoundsManager::Init(HWND hWnd, char *NDirectory)
|
|
||||||
|
|
||||||
void TSoundsManager::Init(HWND hWnd)
|
void TSoundsManager::Init(HWND hWnd)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
32
Sound.h
32
Sound.h
@@ -7,33 +7,28 @@ obtain one at
|
|||||||
http://mozilla.org/MPL/2.0/.
|
http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SoundH
|
#pragma once
|
||||||
#define SoundH
|
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <dsound.h>
|
#include <dsound.h>
|
||||||
|
|
||||||
typedef LPDIRECTSOUNDBUFFER PSound;
|
typedef LPDIRECTSOUNDBUFFER PSound;
|
||||||
|
|
||||||
// inline Playing(PSound Sound)
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
class TSoundContainer
|
class TSoundContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int Concurrent;
|
int Concurrent;
|
||||||
int Oldest;
|
int Oldest;
|
||||||
char Name[80];
|
std::string m_name;
|
||||||
LPDIRECTSOUNDBUFFER DSBuffer;
|
LPDIRECTSOUNDBUFFER DSBuffer;
|
||||||
float fSamplingRate; // częstotliwość odczytana z pliku
|
float fSamplingRate; // częstotliwość odczytana z pliku
|
||||||
int iBitsPerSample; // ile bitów na próbkę
|
int iBitsPerSample; // ile bitów na próbkę
|
||||||
TSoundContainer *Next;
|
TSoundContainer *Next;
|
||||||
std::stack<LPDIRECTSOUNDBUFFER> DSBuffers;
|
std::stack<LPDIRECTSOUNDBUFFER> DSBuffers;
|
||||||
LPDIRECTSOUNDBUFFER GetUnique(LPDIRECTSOUND pDS);
|
|
||||||
TSoundContainer(LPDIRECTSOUND pDS, const char *Directory, const char *strFileName, int NConcurrent);
|
TSoundContainer(LPDIRECTSOUND pDS, std::string const &Directory, std::string const &Filename, int NConcurrent);
|
||||||
~TSoundContainer();
|
~TSoundContainer();
|
||||||
|
LPDIRECTSOUNDBUFFER GetUnique( LPDIRECTSOUND pDS );
|
||||||
};
|
};
|
||||||
|
|
||||||
class TSoundsManager
|
class TSoundsManager
|
||||||
@@ -41,22 +36,15 @@ class TSoundsManager
|
|||||||
private:
|
private:
|
||||||
static LPDIRECTSOUND pDS;
|
static LPDIRECTSOUND pDS;
|
||||||
static LPDIRECTSOUNDNOTIFY pDSNotify;
|
static LPDIRECTSOUNDNOTIFY pDSNotify;
|
||||||
// static char Directory[80];
|
|
||||||
static int Count;
|
|
||||||
static TSoundContainer *First;
|
static TSoundContainer *First;
|
||||||
static TSoundContainer * LoadFromFile(const char *Dir, const char *Name, int Concurrent);
|
static int Count;
|
||||||
|
|
||||||
|
static TSoundContainer * LoadFromFile( std::string const &Directory, std::string const &FileName, int Concurrent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// TSoundsManager(HWND hWnd);
|
|
||||||
// static void Init(HWND hWnd, char *NDirectory);
|
|
||||||
static void Init(HWND hWnd);
|
|
||||||
~TSoundsManager();
|
~TSoundsManager();
|
||||||
|
static void Init( HWND hWnd );
|
||||||
static void Free();
|
static void Free();
|
||||||
static void Init(char *Name, int Concurrent);
|
static LPDIRECTSOUNDBUFFER GetFromName( std::string const &Name, bool Dynamic, float *fSamplingRate = NULL );
|
||||||
static void LoadSounds(char *Directory);
|
|
||||||
static LPDIRECTSOUNDBUFFER GetFromName(const char *Name, bool Dynamic, float *fSamplingRate = NULL);
|
|
||||||
static void RestoreAll();
|
static void RestoreAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
#endif
|
|
||||||
|
|||||||
50
Train.cpp
50
Train.cpp
@@ -5820,6 +5820,8 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||||
// parser.addCommentStyle( "#", "\n" );
|
// parser.addCommentStyle( "#", "\n" );
|
||||||
//Wartości domyślne by nie wysypywało przy wybrakowanych mmd @240816 Stele
|
//Wartości domyślne by nie wysypywało przy wybrakowanych mmd @240816 Stele
|
||||||
|
// NOTE: should be no longer needed as safety checks were added,
|
||||||
|
// but leaving the defaults for the sake of incomplete mmd files
|
||||||
dsbPneumaticSwitch = TSoundsManager::GetFromName("silence1.wav", true);
|
dsbPneumaticSwitch = TSoundsManager::GetFromName("silence1.wav", true);
|
||||||
dsbBufferClamp = TSoundsManager::GetFromName("en57_bufferclamp.wav", true);
|
dsbBufferClamp = TSoundsManager::GetFromName("en57_bufferclamp.wav", true);
|
||||||
dsbCouplerDetach = TSoundsManager::GetFromName("couplerdetach.wav", true);
|
dsbCouplerDetach = TSoundsManager::GetFromName("couplerdetach.wav", true);
|
||||||
@@ -5847,67 +5849,67 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
{
|
{
|
||||||
// nastawnik:
|
// nastawnik:
|
||||||
dsbNastawnikJazdy =
|
dsbNastawnikJazdy =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "ctrlscnd:")
|
else if (token == "ctrlscnd:")
|
||||||
{
|
{
|
||||||
// hunter-081211: nastawnik bocznikowania
|
// hunter-081211: nastawnik bocznikowania
|
||||||
dsbNastawnikBocz =
|
dsbNastawnikBocz =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "reverserkey:")
|
else if (token == "reverserkey:")
|
||||||
{
|
{
|
||||||
// hunter-131211: dzwiek kierunkowego
|
// hunter-131211: dzwiek kierunkowego
|
||||||
dsbReverserKey =
|
dsbReverserKey =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "buzzer:")
|
else if (token == "buzzer:")
|
||||||
{
|
{
|
||||||
// bzyczek shp:
|
// bzyczek shp:
|
||||||
dsbBuzzer =
|
dsbBuzzer =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "slipalarm:")
|
else if (token == "slipalarm:")
|
||||||
{
|
{
|
||||||
// Bombardier 011010: alarm przy poslizgu:
|
// Bombardier 011010: alarm przy poslizgu:
|
||||||
dsbSlipAlarm =
|
dsbSlipAlarm =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "tachoclock:")
|
else if (token == "tachoclock:")
|
||||||
{
|
{
|
||||||
// cykanie rejestratora:
|
// cykanie rejestratora:
|
||||||
dsbHasler =
|
dsbHasler =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "switch:")
|
else if (token == "switch:")
|
||||||
{
|
{
|
||||||
// przelaczniki:
|
// przelaczniki:
|
||||||
dsbSwitch =
|
dsbSwitch =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "pneumaticswitch:")
|
else if (token == "pneumaticswitch:")
|
||||||
{
|
{
|
||||||
// stycznik EP:
|
// stycznik EP:
|
||||||
dsbPneumaticSwitch =
|
dsbPneumaticSwitch =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "wejscie_na_bezoporow:")
|
else if (token == "wejscie_na_bezoporow:")
|
||||||
{
|
{
|
||||||
// hunter-111211: wydzielenie wejscia na bezoporowa i na drugi uklad do pliku
|
// hunter-111211: wydzielenie wejscia na bezoporowa i na drugi uklad do pliku
|
||||||
dsbWejscie_na_bezoporow =
|
dsbWejscie_na_bezoporow =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "wejscie_na_drugi_uklad:")
|
else if (token == "wejscie_na_drugi_uklad:")
|
||||||
{
|
{
|
||||||
|
|
||||||
dsbWejscie_na_drugi_uklad =
|
dsbWejscie_na_drugi_uklad =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "relay:")
|
else if (token == "relay:")
|
||||||
{
|
{
|
||||||
// styczniki itp:
|
// styczniki itp:
|
||||||
dsbRelay =
|
dsbRelay =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
if (!dsbWejscie_na_bezoporow)
|
if (!dsbWejscie_na_bezoporow)
|
||||||
{ // hunter-111211: domyslne, gdy brak
|
{ // hunter-111211: domyslne, gdy brak
|
||||||
dsbWejscie_na_bezoporow =
|
dsbWejscie_na_bezoporow =
|
||||||
@@ -5923,39 +5925,37 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
{
|
{
|
||||||
// wylaczniki pneumatyczne:
|
// wylaczniki pneumatyczne:
|
||||||
dsbPneumaticRelay =
|
dsbPneumaticRelay =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "couplerattach:")
|
else if (token == "couplerattach:")
|
||||||
{
|
{
|
||||||
// laczenie:
|
// laczenie:
|
||||||
dsbCouplerAttach =
|
dsbCouplerAttach =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "couplerstretch:")
|
else if (token == "couplerstretch:")
|
||||||
{
|
{
|
||||||
// laczenie:
|
// laczenie:
|
||||||
dsbCouplerStretch = TSoundsManager::GetFromName(
|
dsbCouplerStretch =
|
||||||
parser.getToken<std::string>().c_str(),
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
true); // McZapkie-090503: PROWIZORKA!!! "en57_couplerstretch.wav"
|
|
||||||
}
|
}
|
||||||
else if (token == "couplerdetach:")
|
else if (token == "couplerdetach:")
|
||||||
{
|
{
|
||||||
// rozlaczanie:
|
// rozlaczanie:
|
||||||
dsbCouplerDetach =
|
dsbCouplerDetach =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "bufferclamp:")
|
else if (token == "bufferclamp:")
|
||||||
{
|
{
|
||||||
// laczenie:
|
// laczenie:
|
||||||
dsbBufferClamp = TSoundsManager::GetFromName(
|
dsbBufferClamp =
|
||||||
parser.getToken<std::string>().c_str(),
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
true); // McZapkie-090503: PROWIZORKA!!! "en57_bufferclamp.wav"
|
|
||||||
}
|
}
|
||||||
else if (token == "ignition:")
|
else if (token == "ignition:")
|
||||||
{
|
{
|
||||||
// odpalanie silnika
|
// odpalanie silnika
|
||||||
dsbDieselIgnition =
|
dsbDieselIgnition =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "brakesound:")
|
else if (token == "brakesound:")
|
||||||
{
|
{
|
||||||
@@ -6073,25 +6073,25 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
{
|
{
|
||||||
// podniesienie patyka:
|
// podniesienie patyka:
|
||||||
dsbPantUp =
|
dsbPantUp =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "pantographdown:")
|
else if (token == "pantographdown:")
|
||||||
{
|
{
|
||||||
// podniesienie patyka:
|
// podniesienie patyka:
|
||||||
dsbPantDown =
|
dsbPantDown =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "doorclose:")
|
else if (token == "doorclose:")
|
||||||
{
|
{
|
||||||
// zamkniecie drzwi:
|
// zamkniecie drzwi:
|
||||||
dsbDoorClose =
|
dsbDoorClose =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
else if (token == "dooropen:")
|
else if (token == "dooropen:")
|
||||||
{
|
{
|
||||||
// otwarcie drzwi:
|
// otwarcie drzwi:
|
||||||
dsbDoorOpen =
|
dsbDoorOpen =
|
||||||
TSoundsManager::GetFromName(parser.getToken<std::string>().c_str(), true);
|
TSoundsManager::GetFromName(parser.getToken<std::string>(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (token != "");
|
} while (token != "");
|
||||||
|
|||||||
20
VBO.cpp
20
VBO.cpp
@@ -44,7 +44,9 @@ void CVertNormTex::serialize(std::ostream &s)
|
|||||||
|
|
||||||
CMesh::CMesh()
|
CMesh::CMesh()
|
||||||
{ // utworzenie pustego obiektu
|
{ // utworzenie pustego obiektu
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
m_pVNT = nullptr;
|
m_pVNT = nullptr;
|
||||||
|
#endif
|
||||||
m_nVertexCount = -1;
|
m_nVertexCount = -1;
|
||||||
m_nVBOVertices = 0; // nie zarezerwowane
|
m_nVBOVertices = 0; // nie zarezerwowane
|
||||||
};
|
};
|
||||||
@@ -57,7 +59,13 @@ CMesh::~CMesh()
|
|||||||
void CMesh::MakeArray(int n)
|
void CMesh::MakeArray(int n)
|
||||||
{ // tworzenie tablic
|
{ // tworzenie tablic
|
||||||
m_nVertexCount = n;
|
m_nVertexCount = n;
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
|
assert( m_pVNT == nullptr );
|
||||||
m_pVNT = new CVertNormTex[m_nVertexCount]; // przydzielenie pamięci dla tablicy
|
m_pVNT = new CVertNormTex[m_nVertexCount]; // przydzielenie pamięci dla tablicy
|
||||||
|
#else
|
||||||
|
m_pVNT.clear();
|
||||||
|
m_pVNT.resize( m_nVertexCount );
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void CMesh::BuildVBOs(bool del)
|
void CMesh::BuildVBOs(bool del)
|
||||||
@@ -65,11 +73,19 @@ void CMesh::BuildVBOs(bool del)
|
|||||||
// pobierz numer VBO oraz ustaw go jako aktywny
|
// pobierz numer VBO oraz ustaw go jako aktywny
|
||||||
glGenBuffers(1, &m_nVBOVertices); // pobierz numer
|
glGenBuffers(1, &m_nVBOVertices); // pobierz numer
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_nVBOVertices); // ustaw bufor jako aktualny
|
glBindBuffer(GL_ARRAY_BUFFER, m_nVBOVertices); // ustaw bufor jako aktualny
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
glBufferData(GL_ARRAY_BUFFER, m_nVertexCount * sizeof(CVertNormTex), m_pVNT, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, m_nVertexCount * sizeof(CVertNormTex), m_pVNT, GL_STATIC_DRAW);
|
||||||
|
#else
|
||||||
|
glBufferData( GL_ARRAY_BUFFER, m_nVertexCount * sizeof( CVertNormTex ), m_pVNT.data(), GL_STATIC_DRAW );
|
||||||
|
#endif
|
||||||
// WriteLog("Assigned VBO number "+AnsiString(m_nVBOVertices)+", vertices:
|
// WriteLog("Assigned VBO number "+AnsiString(m_nVBOVertices)+", vertices:
|
||||||
// "+AnsiString(m_nVertexCount));
|
// "+AnsiString(m_nVertexCount));
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
if (del)
|
if (del)
|
||||||
SafeDeleteArray(m_pVNT); // wierzchołki już się nie przydadzą
|
SafeDeleteArray(m_pVNT); // wierzchołki już się nie przydadzą
|
||||||
|
#else
|
||||||
|
m_pVNT.clear();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void CMesh::Clear()
|
void CMesh::Clear()
|
||||||
@@ -82,7 +98,11 @@ void CMesh::Clear()
|
|||||||
}
|
}
|
||||||
m_nVBOVertices = 0;
|
m_nVBOVertices = 0;
|
||||||
m_nVertexCount = -1; // do ponownego zliczenia
|
m_nVertexCount = -1; // do ponownego zliczenia
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
SafeDeleteArray(m_pVNT); // usuwanie tablic, gdy były użyte do Vertex Array
|
SafeDeleteArray(m_pVNT); // usuwanie tablic, gdy były użyte do Vertex Array
|
||||||
|
#else
|
||||||
|
m_pVNT.clear();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
bool CMesh::StartVBO()
|
bool CMesh::StartVBO()
|
||||||
|
|||||||
7
VBO.h
7
VBO.h
@@ -9,6 +9,9 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#ifndef VBOH
|
#ifndef VBOH
|
||||||
#define VBOH
|
#define VBOH
|
||||||
|
|
||||||
|
#define EU07_USE_OLD_VERTEXBUFFER
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
class CVertNormTex
|
class CVertNormTex
|
||||||
{
|
{
|
||||||
@@ -30,7 +33,11 @@ class CMesh
|
|||||||
{ // wsparcie dla VBO
|
{ // wsparcie dla VBO
|
||||||
public:
|
public:
|
||||||
int m_nVertexCount; // liczba wierzchołków
|
int m_nVertexCount; // liczba wierzchołków
|
||||||
|
#ifdef EU07_USE_OLD_VERTEXBUFFER
|
||||||
CVertNormTex *m_pVNT;
|
CVertNormTex *m_pVNT;
|
||||||
|
#else
|
||||||
|
std::vector<CVertNormTex> m_pVNT;
|
||||||
|
#endif
|
||||||
unsigned int m_nVBOVertices; // numer VBO z wierzchołkami
|
unsigned int m_nVBOVertices; // numer VBO z wierzchołkami
|
||||||
CMesh();
|
CMesh();
|
||||||
~CMesh();
|
~CMesh();
|
||||||
|
|||||||
24
usefull.h
24
usefull.h
@@ -11,17 +11,6 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#define SafeDelete(a) \
|
|
||||||
{ \
|
|
||||||
delete (a); \
|
|
||||||
a = nullptr; \
|
|
||||||
}
|
|
||||||
#define SafeDeleteArray(a) \
|
|
||||||
{ \
|
|
||||||
delete[](a); \
|
|
||||||
a = nullptr; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
|
#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
|
||||||
|
|
||||||
#define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem
|
#define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem
|
||||||
@@ -31,9 +20,22 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#define asSceneryPath std::string("scenery\\")
|
#define asSceneryPath std::string("scenery\\")
|
||||||
#define szSceneryPath "scenery\\"
|
#define szSceneryPath "scenery\\"
|
||||||
#define szTexturePath "textures\\"
|
#define szTexturePath "textures\\"
|
||||||
|
#define szSoundPath "sounds\\"
|
||||||
|
|
||||||
#define MAKE_ID4(a,b,c,d) (((std::uint32_t)(d)<<24)|((std::uint32_t)(c)<<16)|((std::uint32_t)(b)<<8)|(std::uint32_t)(a))
|
#define MAKE_ID4(a,b,c,d) (((std::uint32_t)(d)<<24)|((std::uint32_t)(c)<<16)|((std::uint32_t)(b)<<8)|(std::uint32_t)(a))
|
||||||
|
|
||||||
|
template <typename _Type>
|
||||||
|
void SafeDelete( _Type &Pointer ) {
|
||||||
|
delete Pointer;
|
||||||
|
Pointer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename _Type>
|
||||||
|
void SafeDeleteArray( _Type &Pointer ) {
|
||||||
|
delete[] Pointer;
|
||||||
|
Pointer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename _Type>
|
template <typename _Type>
|
||||||
_Type
|
_Type
|
||||||
clamp( _Type const Value, _Type const Min, _Type const Max ) {
|
clamp( _Type const Value, _Type const Min, _Type const Max ) {
|
||||||
|
|||||||
33
wavread.cpp
33
wavread.cpp
@@ -17,26 +17,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "WavRead.h"
|
#include "WavRead.h"
|
||||||
|
#include "usefull.h"
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Defines, constants, and global variables
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
#define SAFE_DELETE(p) \
|
|
||||||
{ \
|
|
||||||
if (p) \
|
|
||||||
{ \
|
|
||||||
delete (p); \
|
|
||||||
(p) = NULL; \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
#define SAFE_RELEASE(p) \
|
|
||||||
{ \
|
|
||||||
if (p) \
|
|
||||||
{ \
|
|
||||||
(p)->Release(); \
|
|
||||||
(p) = NULL; \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Name: ReadMMIO()
|
// Name: ReadMMIO()
|
||||||
@@ -122,13 +103,13 @@ HRESULT ReadMMIO(HMMIO hmmioIn, MMCKINFO *pckInRIFF, WAVEFORMATEX **ppwfxInfo)
|
|||||||
// so the data can be easily read with WaveReadFile. Returns 0 if
|
// so the data can be easily read with WaveReadFile. Returns 0 if
|
||||||
// successful, the error code if not.
|
// successful, the error code if not.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
HRESULT WaveOpenFile(CHAR *strFileName, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,
|
HRESULT WaveOpenFile( std::string const &Filename, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,
|
||||||
MMCKINFO *pckInRIFF)
|
MMCKINFO *pckInRIFF)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
HMMIO hmmioIn = NULL;
|
HMMIO hmmioIn = NULL;
|
||||||
|
|
||||||
if (NULL == (hmmioIn = mmioOpen(strFileName, NULL, MMIO_ALLOCBUF | MMIO_READ)))
|
if (NULL == (hmmioIn = mmioOpen(const_cast<char*>(Filename.c_str()), NULL, MMIO_ALLOCBUF | MMIO_READ)))
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
|
||||||
if (FAILED(hr = ReadMMIO(hmmioIn, pckInRIFF, ppwfxInfo)))
|
if (FAILED(hr = ReadMMIO(hmmioIn, pckInRIFF, ppwfxInfo)))
|
||||||
@@ -228,20 +209,20 @@ CWaveSoundRead::CWaveSoundRead()
|
|||||||
CWaveSoundRead::~CWaveSoundRead()
|
CWaveSoundRead::~CWaveSoundRead()
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
SAFE_DELETE(m_pwfx);
|
SafeDelete(m_pwfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Name: Open()
|
// Name: Open()
|
||||||
// Desc: Opens a wave file for reading
|
// Desc: Opens a wave file for reading
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
HRESULT CWaveSoundRead::Open(CHAR *strFilename)
|
HRESULT CWaveSoundRead::Open(std::string const &Filename)
|
||||||
{
|
{
|
||||||
SAFE_DELETE(m_pwfx);
|
SafeDelete(m_pwfx);
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
if (FAILED(hr = WaveOpenFile(strFilename, &m_hmmioIn, &m_pwfx, &m_ckInRiff)))
|
if (FAILED(hr = WaveOpenFile(Filename, &m_hmmioIn, &m_pwfx, &m_ckInRiff)))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
if (FAILED(hr = Reset()))
|
if (FAILED(hr = Reset()))
|
||||||
|
|||||||
10
wavread.h
10
wavread.h
@@ -15,12 +15,12 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
//
|
//
|
||||||
// Copyright (c) 1999 Microsoft Corp. All rights reserved.
|
// Copyright (c) 1999 Microsoft Corp. All rights reserved.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#ifndef WAVE_READ_H
|
#pragma once
|
||||||
#define WAVE_READ_H
|
|
||||||
|
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
HRESULT WaveOpenFile(CHAR *strFileName, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,
|
HRESULT WaveOpenFile(std::string const &Filename, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,
|
||||||
MMCKINFO *pckInRIFF);
|
MMCKINFO *pckInRIFF);
|
||||||
HRESULT WaveStartDataRead(HMMIO *phmmioIn, MMCKINFO *pckIn, MMCKINFO *pckInRIFF);
|
HRESULT WaveStartDataRead(HMMIO *phmmioIn, MMCKINFO *pckIn, MMCKINFO *pckInRIFF);
|
||||||
HRESULT WaveReadFile(HMMIO hmmioIn, UINT cbRead, BYTE *pbDest, MMCKINFO *pckIn, UINT *cbActualRead);
|
HRESULT WaveReadFile(HMMIO hmmioIn, UINT cbRead, BYTE *pbDest, MMCKINFO *pckIn, UINT *cbActualRead);
|
||||||
@@ -41,10 +41,8 @@ class CWaveSoundRead
|
|||||||
CWaveSoundRead();
|
CWaveSoundRead();
|
||||||
~CWaveSoundRead();
|
~CWaveSoundRead();
|
||||||
|
|
||||||
HRESULT Open(CHAR *strFilename);
|
HRESULT Open(std::string const &Filename);
|
||||||
HRESULT Reset();
|
HRESULT Reset();
|
||||||
HRESULT Read(UINT nSizeToRead, BYTE *pbData, UINT *pnSizeRead);
|
HRESULT Read(UINT nSizeToRead, BYTE *pbData, UINT *pnSizeRead);
|
||||||
HRESULT Close();
|
HRESULT Close();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif WAVE_READ_H
|
|
||||||
|
|||||||
Reference in New Issue
Block a user