1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

Merge pull request #275 from zrax/file-utils

Unify filesystem utilities
This commit is contained in:
2013-01-22 16:27:26 -08:00
148 changed files with 1545 additions and 4225 deletions

View File

@ -868,14 +868,14 @@ plSoundBuffer::ELoadReturnVal plSound::IPreLoadBuffer( bool playWhenLoaded, bool
}
}
const char *plSound::GetFileName( void ) const
plFileName plSound::GetFileName( void ) const
{
if(fDataBufferKey->ObjectIsLoaded())
if (fDataBufferKey->ObjectIsLoaded())
{
return ((plSoundBuffer *)fDataBufferKey->ObjectIsLoaded())->GetFileName();
}
return nil;
return "";
}
/////////////////////////////////////////////////////////////////////////

View File

@ -211,9 +211,9 @@ public:
virtual void Update();
plSoundBuffer * GetDataBuffer( void ) const { return (plSoundBuffer *)fDataBufferKey->ObjectIsLoaded(); }
float QueryCurrVolume( void ) const; // Returns the current volume, attenuated
float QueryCurrVolume( void ) const; // Returns the current volume, attenuated
const char * GetFileName( void ) const;
plFileName GetFileName( void ) const;
virtual double GetLength();
void SetProperty( Property prop, bool on ) { if( on ) fProperties |= prop; else fProperties &= ~prop; }

View File

@ -228,14 +228,14 @@ bool plWin32GroupedSound::LoadSound( bool is3D )
IFillCurrentSound( 0 );
// Logging
plString str = plString::Format(" Grouped %s %s allocated (%d msec).", buffer->GetFileName() != nil ? "file" : "buffer",
buffer->GetFileName() != nil ? buffer->GetFileName() : buffer->GetKey()->GetUoid().GetObjectName().c_str(),
//fDSoundBuffer->IsHardwareAccelerated() ? "hardware" : "software",
//fDSoundBuffer->IsStaticVoice() ? "static" : "dynamic",
plString str = plString::Format(" Grouped %s %s allocated (%d msec).", buffer->GetFileName().IsValid() ? "file" : "buffer",
buffer->GetFileName().IsValid() ? buffer->GetFileName().AsString().c_str() : buffer->GetKey()->GetUoid().GetObjectName().c_str(),
//fDSoundBuffer->IsHardwareAccelerated() ? "hardware" : "software",
//fDSoundBuffer->IsStaticVoice() ? "static" : "dynamic",
#ifdef PL_PROFILE_ENABLED
gProfileVarStaticSndShoveTime.GetValue() );
gProfileVarStaticSndShoveTime.GetValue() );
#else
0 );
0 );
#endif
IPrintDbgMessage( str.c_str() );
if( GetKey() != nil && GetKeyName().Find( "Footstep" ) >= 0 )

View File

@ -44,7 +44,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsGeometry3.h"
#include "plgDispatch.h"
#include "plProfile.h"
#include "plFile/hsFiles.h"
#include "plWin32Sound.h"
#include "plWin32StreamingSound.h"
@ -91,9 +90,6 @@ plWin32StreamingSound::~plWin32StreamingSound()
IUnloadDataBuffer();
delete fDataStream;
fDataStream = nil;
fSrcFilename[ 0 ] = 0;
delete fDeswizzler;
}
@ -117,11 +113,11 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
{
if(fPlayWhenStopped)
return plSoundBuffer::kPending;
bool sfxPath = fNewFilename.size() ? false : true;
if( fDataStream != nil && fNewFilename.size() == 0)
bool sfxPath = fNewFilename.IsValid() ? false : true;
if (fDataStream != nil && !fNewFilename.IsValid())
return plSoundBuffer::kSuccess; // Already loaded
if(!ILoadDataBuffer())
{
return plSoundBuffer::kError;
@ -131,11 +127,11 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
return plSoundBuffer::kError;
// The databuffer also needs to know if the source is compressed or not
if(fNewFilename.length())
if (fNewFilename.IsValid())
{
buffer->SetFileName(fNewFilename.c_str());
buffer->SetFileName(fNewFilename);
buffer->SetFlag(plSoundBuffer::kStreamCompressed, fIsCompressed);
fNewFilename.clear();
fNewFilename = "";
if(fReallyPlaying)
{
fPlayWhenStopped = true;
@ -172,8 +168,7 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
}
}
char str[ 256 ];
strncpy( fSrcFilename, buffer->GetFileName(), sizeof( fSrcFilename ) );
fSrcFilename = buffer->GetFileName();
bool streamCompressed = (buffer->HasFlag(plSoundBuffer::kStreamCompressed) != 0);
delete fDataStream;
@ -185,20 +180,14 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
bool streamCompressed = (buffer->HasFlag(plSoundBuffer::kStreamCompressed) != 0);
/// Open da file
char strPath[ kFolderIterator_MaxPath ];
getcwd(strPath, kFolderIterator_MaxPath);
if(sfxPath)
strcat( strPath, "\\sfx\\" );
else
{
// if we've changing the filename don't append 'sfx', just append a '\' since a path to the folder is expected
strcat( strPath, "\\");
}
strcat( strPath, fSrcFilename );
plFileName strPath = plFileSystem::GetCWD();
if (sfxPath)
strPath = plFileName::Join(strPath, "sfx");
strPath = plFileName::Join(strPath, fSrcFilename);
fDataStream = plAudioFileReader::CreateReader(strPath, select,type);
}
}
if( fDataStream == nil || !fDataStream->IsValid() )
{
delete fDataStream;
@ -206,8 +195,7 @@ plSoundBuffer::ELoadReturnVal plWin32StreamingSound::IPreLoadBuffer( bool playWh
return plSoundBuffer::kError;
}
sprintf( str, " Readied file %s for streaming", fSrcFilename );
IPrintDbgMessage( str );
IPrintDbgMessage(plString::Format(" Readied file %s for streaming", fSrcFilename.AsString().c_str()).c_str());
// dont free sound data until we have a chance to use it in load sound
@ -227,11 +215,11 @@ void plWin32StreamingSound::IFreeBuffers( void )
if(!plgAudioSys::IsRestarting())
{
// we are deleting the stream, we must release the sound data.
FreeSoundData();
FreeSoundData();
delete fDataStream;
fDataStream = nil;
}
fSrcFilename[ 0 ] = 0;
fSrcFilename = "";
}
}
@ -303,9 +291,10 @@ bool plWin32StreamingSound::LoadSound( bool is3D )
delete fDSoundBuffer;
fDSoundBuffer = nil;
char str[256];
sprintf(str, "Can't create sound buffer for %s.wav. This could happen if the wav file is a stereo file. Stereo files are not supported on 3D sounds. If the file is not stereo then please report this error.", GetFileName());
IPrintDbgMessage( str, true );
plString str = plString::Format("Can't create sound buffer for %s.wav. This could happen if the wav file is a stereo file."
" Stereo files are not supported on 3D sounds. If the file is not stereo then please report this error.",
GetFileName().AsString().c_str());
IPrintDbgMessage(str.c_str(), true);
fFailed = true;
return false;
}

View File

@ -70,15 +70,15 @@ public:
virtual bool MsgReceive( plMessage *pMsg );
protected:
float fTimeAtBufferStart;
plAudioFileReader *fDataStream;
float fBufferLengthInSecs;
uint8_t fBlankBufferFillCounter;
plSoundDeswizzler *fDeswizzler;
char fSrcFilename[ 256 ];
float fTimeAtBufferStart;
plAudioFileReader *fDataStream;
float fBufferLengthInSecs;
uint8_t fBlankBufferFillCounter;
plSoundDeswizzler *fDeswizzler;
plFileName fSrcFilename;
StreamType fStreamType;
bool fIsCompressed; // this applies only to the new sound file specified in fNewFilename, so we can play both ogg's and wav's
std::string fNewFilename; // allow the filename to be changed so we can play from a different source.
plFileName fNewFilename; // allow the filename to be changed so we can play from a different source.
// ultimately this filename will be given to fDataBuffer, but since it's not always around we'll store it here
bool fStopping;
@ -86,7 +86,7 @@ protected:
bool fPlayWhenStopped;
unsigned fStartPos;
float IGetTimeAtBufferStart( void ) { return fTimeAtBufferStart; }
float IGetTimeAtBufferStart( void ) { return fTimeAtBufferStart; }
virtual void SetStartPos(unsigned bytes);
virtual void IDerivedActuallyPlay( void );