Fixes unnecessary use of VfsPath pointers in sound system. Refs #1223

This was SVN commit r12444.
This commit is contained in:
historic_bruno 2012-08-16 01:41:45 +00:00
parent 78e9fecf92
commit 714426f761
11 changed files with 21 additions and 37 deletions

View File

@ -138,7 +138,7 @@ void CSoundManager::SetActionGain(float gain)
}
ISoundItem* CSoundManager::LoadItem(const VfsPath* itemPath)
ISoundItem* CSoundManager::LoadItem(const VfsPath& itemPath)
{
CSoundData* itemData = CSoundData::SoundDataFromFile(itemPath);
ISoundItem* answer = NULL;

View File

@ -50,7 +50,7 @@ public:
CSoundManager();
virtual ~CSoundManager();
ISoundItem* LoadItem(const VfsPath* itemPath);
ISoundItem* LoadItem(const VfsPath& itemPath);
static void ScriptingInit();

View File

@ -59,17 +59,17 @@ void CSoundData::ReleaseSoundData(CSoundData* theData)
}
}
CSoundData* CSoundData::SoundDataFromFile(const VfsPath* itemPath)
CSoundData* CSoundData::SoundDataFromFile(const VfsPath& itemPath)
{
if (CSoundData::sSoundData == NULL)
CSoundData::sSoundData = new DataMap;
Path fExt = itemPath->Extension();
Path fExt = itemPath.Extension();
DataMap::iterator itemFind;
CSoundData* answer = NULL;
if ((itemFind = CSoundData::sSoundData->find(itemPath->string())) != sSoundData->end())
if ((itemFind = CSoundData::sSoundData->find(itemPath.string())) != sSoundData->end())
{
answer = itemFind->second;
}
@ -79,7 +79,7 @@ CSoundData* CSoundData::SoundDataFromFile(const VfsPath* itemPath)
answer = SoundDataFromOgg(itemPath);
if (answer && answer->IsOneShot())
(*CSoundData::sSoundData)[itemPath->string()] = answer;
(*CSoundData::sSoundData)[itemPath.string()] = answer;
}
return answer;
@ -91,13 +91,13 @@ bool CSoundData::IsOneShot()
}
CSoundData* CSoundData::SoundDataFromOgg(const VfsPath* itemPath)
CSoundData* CSoundData::SoundDataFromOgg(const VfsPath& itemPath)
{
CSoundData* answer = NULL;
COggData* oggAnswer = new COggData();
OsPath realPath;
Status ret = g_VFS->GetRealPath(*itemPath, realPath);
Status ret = g_VFS->GetRealPath(itemPath, realPath);
if (ret == INFO::OK)
{
if (oggAnswer->InitOggFile(realPath.string().c_str()))

View File

@ -32,8 +32,8 @@ typedef std::map<std::wstring, CSoundData*> DataMap;
class CSoundData
{
public:
static CSoundData* SoundDataFromFile(const VfsPath* itemPath);
static CSoundData* SoundDataFromOgg(const VfsPath* itemPath);
static CSoundData* SoundDataFromFile(const VfsPath& itemPath);
static CSoundData* SoundDataFromOgg(const VfsPath& itemPath);
static void ReleaseSoundData(CSoundData* theData);

View File

@ -25,17 +25,10 @@
#include "soundmanager/SoundManager.h"
JAmbientSound::JAmbientSound(const VfsPath& pathname)
JAmbientSound::JAmbientSound(const VfsPath& pathname) : m_FileName(pathname)
{
m_FileName = new VfsPath(pathname.string().c_str());
}
JAmbientSound::~JAmbientSound()
{
delete m_FileName;
}
// start playing the sound, all ambient sounds loop
bool JAmbientSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
@ -44,7 +37,7 @@ bool JAmbientSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSE
if (aSnd)
aSnd->PlayAsAmbient();
else
debug_printf(L"sound item could not be loaded to play at: %hs\n", m_FileName);
debug_printf(L"sound item could not be loaded to play: %ls\n", m_FileName.string().c_str());
return true;
}
@ -57,7 +50,7 @@ bool JAmbientSound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSE
if (aSnd)
aSnd->PlayAsAmbient();
else
debug_printf(L"sound item could not be loaded to loop at: %hs\n", m_FileName);
debug_printf(L"sound item could not be loaded to loop: %ls\n", m_FileName.string().c_str());
return true;
}
@ -85,7 +78,7 @@ CStr JAmbientSound::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* U
{
std::ostringstream stringStream;
stringStream << "[object AmbientSound: ";
stringStream << m_FileName->string().c_str();
stringStream << m_FileName.string().c_str();
return stringStream.str();
}

View File

@ -25,8 +25,6 @@ class JAmbientSound : public CJSObject<JAmbientSound>
{
public:
JAmbientSound(const VfsPath& pathname);
virtual ~JAmbientSound();
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
@ -44,7 +42,7 @@ public:
static void ScriptingInit();
protected:
VfsPath* m_FileName;
VfsPath m_FileName;
};

View File

@ -25,14 +25,8 @@
#include "soundmanager/SoundManager.h"
JMusicSound::JMusicSound(const VfsPath& pathname)
JMusicSound::JMusicSound(const VfsPath& pathname) : m_FileName(pathname)
{
m_FileName = new VfsPath(pathname.string().c_str());
}
JMusicSound::~JMusicSound()
{
delete m_FileName;
}
bool JMusicSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
@ -67,7 +61,7 @@ CStr JMusicSound::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNU
{
std::ostringstream stringStream;
stringStream << "[object MusicSound: ";
stringStream << m_FileName->string().c_str();
stringStream << m_FileName.string().c_str();
return stringStream.str();
}

View File

@ -39,7 +39,6 @@ class JMusicSound : public CJSObject<JMusicSound>
{
public:
JMusicSound(const VfsPath& pathname);
virtual ~JMusicSound();
// Script-bound functions
@ -53,7 +52,7 @@ public:
static void ScriptingInit();
protected:
VfsPath* m_FileName;
VfsPath m_FileName;
};
#endif // #ifndef INCLUDED_MUSICSOUND_H

View File

@ -27,7 +27,7 @@
JSound::JSound(const VfsPath& pathname)
{
m_SndItem = g_SoundManager->LoadItem(&pathname);
m_SndItem = g_SoundManager->LoadItem(pathname);
}
JSound::~JSound()

View File

@ -221,7 +221,7 @@ void CSoundGroup::Reload()
for (size_t i = 0; i < filenames.size(); i++)
{
VfsPath thePath = m_filepath/filenames[i];
ISoundItem* temp = g_SoundManager->LoadItem(&thePath);
ISoundItem* temp = g_SoundManager->LoadItem(thePath);
if (temp == NULL)
HandleError(L"error loading sound", thePath, NULL);

View File

@ -52,7 +52,7 @@ public:
static void ScriptingInit();
protected:
VfsPath* m_FileName;
VfsPath m_FileName;
};
#endif // #ifndef INCLUDED_JSOUNDPLAYER