diff --git a/src/audio/cmusic.cpp b/src/audio/cmusic.cpp index 62f7d63da..5dab8bd24 100755 --- a/src/audio/cmusic.cpp +++ b/src/audio/cmusic.cpp @@ -1,11 +1,12 @@ #include "cmusic.hpp" +#include "../system/cpackmanager.hpp" namespace EE { namespace Audio { -cMusic::cMusic(std::size_t BufferSize) : - mFile (NULL), - mDuration(0.f), - mSamples (BufferSize) +cMusic::cMusic( std::size_t BufferSize ) : + mFile ( NULL ), + mDuration( 0.f ), + mSamples( BufferSize ) { } @@ -16,12 +17,26 @@ cMusic::~cMusic() { bool cMusic::OpenFromPack( cPack* Pack, const std::string& FilePackPath ) { if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, mData ) ) - return OpenFromMemory( reinterpret_cast (&mData[0]), mData.size() ); + return OpenFromMemory( reinterpret_cast ( mData.Data ), mData.DataSize ); return false; } -bool cMusic::OpenFromFile(const std::string& Filename) { +bool cMusic::OpenFromFile( const std::string& Filename ) { + if ( !FileExists( Filename ) ) { + if ( cPackManager::instance()->FallbackToPacks() ) { + std::string tPath( Filename ); + + cPack * tPack = cPackManager::instance()->Exists( tPath ); + + if ( NULL != tPack ) { + return OpenFromPack( tPack, tPath ); + } + } + + return false; + } + // Create the sound file implementation, and open it in read mode Stop(); eeSAFE_DELETE( mFile ); @@ -34,7 +49,7 @@ bool cMusic::OpenFromFile(const std::string& Filename) { } // Compute the duration - mDuration = static_cast(mFile->GetSamplesCount()) / mFile->GetSampleRate() / mFile->GetChannelsCount(); + mDuration = static_cast( mFile->GetSamplesCount() ) / mFile->GetSampleRate() / mFile->GetChannelsCount(); // Initialize the stream Initialize(mFile->GetChannelsCount(), mFile->GetSampleRate()); @@ -43,7 +58,7 @@ bool cMusic::OpenFromFile(const std::string& Filename) { return true; } -bool cMusic::OpenFromMemory(const char* Data, std::size_t SizeInBytes) { +bool cMusic::OpenFromMemory( const char * Data, std::size_t SizeInBytes ) { Stop(); eeSAFE_DELETE( mFile ); @@ -55,9 +70,9 @@ bool cMusic::OpenFromMemory(const char* Data, std::size_t SizeInBytes) { return false; } - mDuration = static_cast(mFile->GetSamplesCount()) / mFile->GetSampleRate(); // Compute the duration + mDuration = static_cast( mFile->GetSamplesCount() ) / mFile->GetSampleRate(); // Compute the duration - Initialize(mFile->GetChannelsCount(), mFile->GetSampleRate()); // Initialize the stream + Initialize( mFile->GetChannelsCount(), mFile->GetSampleRate() ); // Initialize the stream cLog::instance()->Write( "Music file loaded from memory." ); return true; diff --git a/src/audio/cmusic.hpp b/src/audio/cmusic.hpp index 6f5cb3ec9..364214379 100755 --- a/src/audio/cmusic.hpp +++ b/src/audio/cmusic.hpp @@ -34,7 +34,7 @@ class EE_API cMusic : public cSoundStream { cSoundFile * mFile; ///< Sound file eeFloat mDuration; ///< Music duration, in seconds std::vector mSamples; ///< Temporary buffer of samples - std::vector mData; + SafeDataPointer mData; }; }} diff --git a/src/audio/csoundbuffer.cpp b/src/audio/csoundbuffer.cpp index d923fe459..e71f39710 100755 --- a/src/audio/csoundbuffer.cpp +++ b/src/audio/csoundbuffer.cpp @@ -1,5 +1,6 @@ #include "csoundbuffer.hpp" #include "csound.hpp" +#include "../system/cpackmanager.hpp" namespace EE { namespace Audio { @@ -30,6 +31,21 @@ cSoundBuffer::~cSoundBuffer() { } bool cSoundBuffer::LoadFromFile(const std::string& Filename) { + if ( !FileExists( Filename ) ) { + if ( cPackManager::instance()->FallbackToPacks() ) { + std::string tPath( Filename ); + + cPack * tPack = cPackManager::instance()->Exists( tPath ); + + if ( NULL != tPack ) { + return LoadFromPack( tPack, tPath ); + } + } + + cLog::instance()->Write( "Failed to load sound buffer from file \"" + Filename + "\"" ); + return false; + } + // Create the sound file std::auto_ptr File( cSoundFile::CreateRead( Filename ) ); diff --git a/src/audio/csoundfile.cpp b/src/audio/csoundfile.cpp index b23d6c581..8ab227bfd 100755 --- a/src/audio/csoundfile.cpp +++ b/src/audio/csoundfile.cpp @@ -21,9 +21,9 @@ cSoundFile * cSoundFile::CreateRead( const std::string& Filename ) { // Create the file according to its type cSoundFile * File = NULL; - if ( cSoundFileOgg::IsFileSupported(Filename, true) ) File = eeNew( cSoundFileOgg, () ); + if ( cSoundFileOgg::IsFileSupported( Filename, true ) ) File = eeNew( cSoundFileOgg, () ); #ifndef EE_NO_SNDFILE - else if ( cSoundFileDefault::IsFileSupported(Filename, true) ) File = eeNew( cSoundFileDefault, () ); + else if ( cSoundFileDefault::IsFileSupported( Filename, true ) ) File = eeNew( cSoundFileDefault, () ); #endif // Open it for reading @@ -52,9 +52,9 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory // Create the file according to its type cSoundFile * File = NULL; - if ( cSoundFileOgg::IsFileSupported(Data, SizeInMemory)) File = eeNew( cSoundFileOgg, () ); + if ( cSoundFileOgg::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( cSoundFileOgg, () ); #ifndef EE_NO_SNDFILE - else if ( cSoundFileDefault::IsFileSupported(Data, SizeInMemory) ) File = eeNew( cSoundFileDefault, () ); + else if ( cSoundFileDefault::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( cSoundFileDefault, () ); #endif // Open it for reading @@ -63,13 +63,13 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory unsigned int ChannelsCount; unsigned int SampleRate; - if ( File->OpenRead(Data, SizeInMemory, SamplesCount, ChannelsCount, SampleRate) ) { - File->mFilename = ""; - File->mData = Data; - File->mSize = SizeInMemory; - File->mNbSamples = SamplesCount; - File->mChannelsCount = ChannelsCount; - File->mSampleRate = SampleRate; + if ( File->OpenRead( Data, SizeInMemory, SamplesCount, ChannelsCount, SampleRate ) ) { + File->mFilename = ""; + File->mData = Data; + File->mSize = SizeInMemory; + File->mNbSamples = SamplesCount; + File->mChannelsCount = ChannelsCount; + File->mSampleRate = SampleRate; } else { eeDelete( File ); File = NULL; @@ -83,20 +83,20 @@ cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int // Create the file according to its type cSoundFile * File = NULL; - if ( cSoundFileOgg::IsFileSupported(Filename, false) ) File = eeNew( cSoundFileOgg, () ); + if ( cSoundFileOgg::IsFileSupported( Filename, false ) ) File = eeNew( cSoundFileOgg, () ); #ifndef EE_NO_SNDFILE - else if ( cSoundFileDefault::IsFileSupported(Filename, false) ) File = eeNew( cSoundFileDefault, () ); + else if ( cSoundFileDefault::IsFileSupported( Filename, false ) ) File = eeNew( cSoundFileDefault, () ); #endif // Open it for writing if ( NULL != File ) { - if ( File->OpenWrite(Filename, ChannelsCount, SampleRate) ) { - File->mFilename = ""; - File->mData = NULL; - File->mSize = 0; - File->mNbSamples = 0; - File->mChannelsCount = ChannelsCount; - File->mSampleRate = SampleRate; + if ( File->OpenWrite( Filename, ChannelsCount, SampleRate ) ) { + File->mFilename = ""; + File->mData = NULL; + File->mSize = 0; + File->mNbSamples = 0; + File->mChannelsCount = ChannelsCount; + File->mSampleRate = SampleRate; } else { eeDelete( File ); File = NULL; @@ -122,10 +122,10 @@ unsigned int cSoundFile::GetSampleRate() const { bool cSoundFile::Restart() { if ( mData ) { // Reopen from memory - return OpenRead(mData, mSize, mNbSamples, mChannelsCount, mSampleRate); + return OpenRead( mData, mSize, mNbSamples, mChannelsCount, mSampleRate ); } else if ( mFilename != "" ) { // Reopen from file - return OpenRead(mFilename, mNbSamples, mChannelsCount, mSampleRate); + return OpenRead( mFilename, mNbSamples, mChannelsCount, mSampleRate ); } else { cLog::instance()->Write( "Warning : trying to restart a sound opened in write mode, which is not allowed" ); return false; diff --git a/src/audio/csoundfile.hpp b/src/audio/csoundfile.hpp index 1ab4e0141..c788e890d 100755 --- a/src/audio/csoundfile.hpp +++ b/src/audio/csoundfile.hpp @@ -30,12 +30,12 @@ class EE_API cSoundFile { virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate); virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate); - std::size_t mNbSamples; + std::size_t mNbSamples; unsigned int mChannelsCount; unsigned int mSampleRate; std::string mFilename; const char * mData; - std::size_t mSize; + std::size_t mSize; }; }} diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp index ff8fc5c28..312b71815 100644 --- a/src/gaming/cmap.cpp +++ b/src/gaming/cmap.cpp @@ -858,6 +858,14 @@ bool cMap::Load( const std::string& path ) { cIOStreamFile IOS( mPath, std::ios::in | std::ios::binary ); return LoadFromStream( IOS ); + } else if ( cPackManager::instance()->FallbackToPacks() ) { + std::string tPath( path ); + cPack * tPack = cPackManager::instance()->Exists( tPath ) ; + + if ( NULL != tPack ) { + mPath = tPath; + return LoadFromPack( tPack, tPath ); + } } return false; diff --git a/src/graphics/base.hpp b/src/graphics/base.hpp index 386246b91..5d37a4978 100644 --- a/src/graphics/base.hpp +++ b/src/graphics/base.hpp @@ -108,7 +108,6 @@ typedef char GLchar; #include "../utils/string.hpp" #include "../utils/utils.hpp" #include "../utils/polygon2.hpp" -#include "../utils/vector3.hpp" using namespace EE::Utils; #include "../math/math.hpp" @@ -120,6 +119,7 @@ using namespace EE::Math; #include "../system/cpack.hpp" #include "../system/tresourcemanager.hpp" #include "../system/tcontainer.hpp" +#include "../system/cpackmanager.hpp" using namespace EE::System; #include "renders.hpp" diff --git a/src/graphics/cfont.hpp b/src/graphics/cfont.hpp index fbf14caf8..8ea631abe 100755 --- a/src/graphics/cfont.hpp +++ b/src/graphics/cfont.hpp @@ -14,8 +14,6 @@ namespace EE { namespace Graphics { /** @brief Font interface class. */ class EE_API cFont { public: - cFont( const Uint32& Type, const std::string& Name ); - virtual ~cFont(); /** Set a text to render @@ -146,6 +144,8 @@ class EE_API cFont { std::vector mRenderCoords; std::vector mColors; + cFont( const Uint32& Type, const std::string& Name ); + void CacheWidth(); void CacheNumLines(); void SubDraw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_PRE_BLEND_FUNC& Effect ); diff --git a/src/graphics/cimage.cpp b/src/graphics/cimage.cpp index 6ee805c5e..c95a6dc24 100644 --- a/src/graphics/cimage.cpp +++ b/src/graphics/cimage.cpp @@ -46,7 +46,7 @@ cImage::cImage( Uint8* data, const eeUint& Width, const eeUint& Height, const ee { } -cImage::cImage( const std::string& Path ) : +cImage::cImage( std::string Path ) : mPixels(NULL), mWidth(0), mHeight(0), @@ -55,6 +55,7 @@ cImage::cImage( const std::string& Path ) : mAvoidFree(false) { int w, h, c; + cPack * tPack = NULL; Uint8 * data = stbi_load( Path.c_str(), &w, &h, &c, 0 ); if ( NULL != data ) { @@ -69,16 +70,58 @@ cImage::cImage( const std::string& Path ) : #ifdef EE_MEMORY_MANAGER MemoryManager::AddPointer( cAllocatedPointer( (void*)data, __FILE__, __LINE__, mSize ) ); #endif + } else if ( cPackManager::instance()->FallbackToPacks() && NULL != ( tPack = cPackManager::instance()->Exists( Path ) ) ) { + LoadFromPack( tPack, Path ); } else { cLog::instance()->Write( "Failed to load image, reason: " + std::string( stbi_failure_reason() ) ); } } +cImage::cImage( cPack * Pack, std::string FilePackPath ) : + mPixels(NULL), + mWidth(0), + mHeight(0), + mChannels(0), + mSize(0), + mAvoidFree(false) +{ + LoadFromPack( Pack, FilePackPath ); +} + cImage::~cImage() { if ( !mAvoidFree ) ClearCache(); } +void cImage::LoadFromPack( cPack * Pack, const std::string& FilePackPath ) { + if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( FilePackPath ) ) { + SafeDataPointer PData; + + Pack->ExtractFileToMemory( FilePackPath, PData ); + + int w, h, c; + Uint8 * data = stbi_load_from_memory( PData.Data, PData.DataSize, &w, &h, &c, 0 ); + + if ( NULL != data ) { + mPixels = data; + mWidth = (eeUint)w; + mHeight = (eeUint)h; + mChannels = (eeUint)c; + + mSize = mWidth * mHeight * mChannels; + + //! HACK: This is a hack to make the memory manager recognize the allocated data + #ifdef EE_MEMORY_MANAGER + MemoryManager::AddPointer( cAllocatedPointer( (void*)data, __FILE__, __LINE__, mSize ) ); + #endif + } else { + cLog::instance()->Write( "Failed to load image, reason: " + std::string( stbi_failure_reason() ) ); + } + } else { + cLog::instance()->Write( "Failed to load image " + FilePackPath + " from pack." ); + } +} + void cImage::SetPixels( const Uint8* data ) { if ( data != NULL ) { eeUint size = (eeUint)mWidth * (eeUint)mHeight * mChannels; diff --git a/src/graphics/cimage.hpp b/src/graphics/cimage.hpp index a83bd1a1a..0ea9e8783 100644 --- a/src/graphics/cimage.hpp +++ b/src/graphics/cimage.hpp @@ -19,7 +19,10 @@ class EE_API cImage { cImage( const Uint32& Width, const Uint32& Height, const Uint32& Channels ); /** Load an image from path */ - cImage( const std::string& Path ); + cImage( std::string Path ); + + /** Load an image from pack */ + cImage( cPack * Pack, std::string FilePackPath ); virtual ~cImage(); @@ -106,6 +109,8 @@ class EE_API cImage { bool mAvoidFree; void Allocate( const Uint32& size ); + + void LoadFromPack( cPack * Pack, const std::string& FilePackPath ); }; }} diff --git a/src/graphics/cshader.cpp b/src/graphics/cshader.cpp index f9adfefdf..177d7567e 100644 --- a/src/graphics/cshader.cpp +++ b/src/graphics/cshader.cpp @@ -20,10 +20,21 @@ cShader::cShader( const Uint32& Type, const std::string& Filename ) { SetSource( (const char*)PData.Data, PData.DataSize ); } else { - cLog::instance()->Write( std::string( "Couldn't open shader object: " ) + Filename ); + std::string tPath = Filename; + cPack * tPack = NULL; + + if ( cPackManager::instance()->FallbackToPacks() && NULL != ( tPack = cPackManager::instance()->Exists( tPath ) ) ) { + SafeDataPointer PData; + + tPack->ExtractFileToMemory( tPath, PData ); + + SetSource( reinterpret_cast ( PData.Data ), PData.DataSize ); + } else { + cLog::instance()->Write( std::string( "Couldn't open shader object: " ) + Filename ); + } } - Compile(); + Compile(); } cShader::cShader( const Uint32& Type, const char * Data, const Uint32& DataSize ) { diff --git a/src/graphics/cshaderprogram.hpp b/src/graphics/cshaderprogram.hpp index da4426d6e..610d46d0e 100644 --- a/src/graphics/cshaderprogram.hpp +++ b/src/graphics/cshaderprogram.hpp @@ -2,6 +2,7 @@ #define EE_GRAPHICSCSHADERPROGRAM_H #include "base.hpp" +#include "../utils/vector3.hpp" #include "cshader.hpp" namespace EE { namespace Graphics { diff --git a/src/graphics/cshape.hpp b/src/graphics/cshape.hpp index da67c8e33..5c584f3cf 100644 --- a/src/graphics/cshape.hpp +++ b/src/graphics/cshape.hpp @@ -19,7 +19,7 @@ class EE_API cShape { cShape( const Uint32& TexId, const eeRecti& SrcRect, const eeFloat& DestWidth, const eeFloat& DestHeight, const Int32& OffsetX, const Int32& OffsetY, const std::string& Name = "" ); - ~cShape(); + virtual ~cShape(); const Uint32& Id() const; diff --git a/src/graphics/ctexturefont.cpp b/src/graphics/ctexturefont.cpp index 58ec77a77..238013bb7 100755 --- a/src/graphics/ctexturefont.cpp +++ b/src/graphics/ctexturefont.cpp @@ -126,24 +126,32 @@ void cTextureFont::BuildFontFromDat() { bool cTextureFont::Load( const Uint32& TexId, const std::string& CoordinatesDatPath, const bool& VerticalDraw ) { if ( FileExists( CoordinatesDatPath ) ) { - std::vector TmpData; + SafeDataPointer PData; - FileGet( CoordinatesDatPath, TmpData ); + FileGet( CoordinatesDatPath, PData ); - return LoadFromMemory( TexId, reinterpret_cast ( &TmpData[0] ), (Uint32)TmpData.size(), VerticalDraw ); + return LoadFromMemory( TexId, reinterpret_cast ( PData.Data ), PData.DataSize, VerticalDraw ); + } else if ( cPackManager::instance()->FallbackToPacks() ) { + std::string tPath( CoordinatesDatPath ); + + cPack * tPack = cPackManager::instance()->Exists( tPath ); + + if ( NULL != tPack ) { + return LoadFromPack( TexId, tPack, tPath, VerticalDraw ); + } } return false; } bool cTextureFont::LoadFromPack( const Uint32& TexId, cPack* Pack, const std::string& FilePackPath, const bool& VerticalDraw ) { - bool Ret = false; SafeDataPointer PData; - if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, PData ) ) - Ret = LoadFromMemory( TexId, reinterpret_cast ( PData.Data ), PData.DataSize, VerticalDraw ); + if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, PData ) ) { + return LoadFromMemory( TexId, reinterpret_cast ( PData.Data ), PData.DataSize, VerticalDraw ); + } - return Ret; + return false; } bool cTextureFont::LoadFromMemory( const Uint32& TexId, const Uint8* CoordData, const Uint32& CoordDataSize, const bool& VerticalDraw ) { @@ -170,6 +178,7 @@ bool cTextureFont::LoadFromMemory( const Uint32& TexId, const Uint8* CoordData, BuildFontFromDat(); mLoadedCoords = true; + return true; } } diff --git a/src/graphics/ctexturefont.hpp b/src/graphics/ctexturefont.hpp index 961832095..7b4abc0ab 100755 --- a/src/graphics/ctexturefont.hpp +++ b/src/graphics/ctexturefont.hpp @@ -11,7 +11,8 @@ namespace EE { namespace Graphics { class EE_API cTextureFont : public cFont { public: cTextureFont( const std::string FontName ); - ~cTextureFont(); + + virtual ~cTextureFont(); /** Load's a texture font * @param TexId The texture id returned by cTextureFactory diff --git a/src/graphics/ctexturegrouploader.cpp b/src/graphics/ctexturegrouploader.cpp index 350e07428..eb631797c 100644 --- a/src/graphics/ctexturegrouploader.cpp +++ b/src/graphics/ctexturegrouploader.cpp @@ -123,6 +123,14 @@ void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { cIOStreamFile IOS( mTextureGroupPath, std::ios::in | std::ios::binary ); LoadFromStream( IOS ); + } else if ( cPackManager::instance()->FallbackToPacks() ) { + std::string tgPath( mTextureGroupPath ); + + cPack * tPack = cPackManager::instance()->Exists( tgPath ); + + if ( NULL != tPack ) { + LoadFromPack( tPack, tgPath ); + } } } diff --git a/src/graphics/ctextureloader.cpp b/src/graphics/ctextureloader.cpp index 0b3833686..88da1f33d 100644 --- a/src/graphics/ctextureloader.cpp +++ b/src/graphics/ctextureloader.cpp @@ -168,6 +168,14 @@ void cTextureLoader::LoadFromPath() { if ( NULL == mPixels ) cLog::instance()->Write( stbi_failure_reason() ); + } else if ( cPackManager::instance()->FallbackToPacks() ) { + mPack = cPackManager::instance()->Exists( mFilepath ); + + if ( NULL != mPack ) { + mLoadType = TEX_LT_PACK; + + LoadFromPack(); + } } } diff --git a/src/graphics/cttffont.cpp b/src/graphics/cttffont.cpp index f2bf8bc4c..e5df4ae96 100755 --- a/src/graphics/cttffont.cpp +++ b/src/graphics/cttffont.cpp @@ -40,12 +40,23 @@ bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const } bool cTTFFont::Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { - mFilepath = Filepath; - mLoadedFromMemory = false; + mFilepath = Filepath; - mFont = hkFontManager::instance()->OpenFromFile( Filepath.c_str(), Size, 0, NumCharsToGen ); + if ( FileExists( Filepath ) ) { + mLoadedFromMemory = false; - return iLoad( Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + mFont = hkFontManager::instance()->OpenFromFile( Filepath.c_str(), Size, 0, NumCharsToGen ); + + return iLoad( Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + } else if ( cPackManager::instance()->FallbackToPacks() ) { + cPack * tPack = cPackManager::instance()->Exists( mFilepath ); + + if ( NULL != tPack ) { + return LoadFromPack( tPack, mFilepath, Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + } + } + + return false; } bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONTSTYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, Uint8 OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { diff --git a/src/graphics/cttffont.hpp b/src/graphics/cttffont.hpp index 58806b469..af1e58349 100755 --- a/src/graphics/cttffont.hpp +++ b/src/graphics/cttffont.hpp @@ -14,7 +14,8 @@ namespace EE { namespace Graphics { class EE_API cTTFFont : public cFont { public: cTTFFont( const std::string FontName ); - ~cTTFFont(); + + virtual ~cTTFFont(); /** Load a True Type Font from path * @param Filepath The TTF file path diff --git a/src/system/cinifile.cpp b/src/system/cinifile.cpp index 0132f6321..c20579aab 100755 --- a/src/system/cinifile.cpp +++ b/src/system/cinifile.cpp @@ -1,4 +1,5 @@ #include "cinifile.hpp" +#include "cpackmanager.hpp" namespace EE { namespace System { @@ -8,16 +9,36 @@ namespace EE { namespace System { #define iniEOL '\r' << std::endl #endif -cIniFile::cIniFile ( std::string const iniPath ) { - mCaseInsensitive = true; +cIniFile::cIniFile ( std::string const iniPath ) : + mCaseInsensitive( true ) +{ LoadFromFile( iniPath ); } -cIniFile::cIniFile ( const Uint8* RAWData, const Uint32& size ) { - mCaseInsensitive = true; +cIniFile::cIniFile ( const Uint8* RAWData, const Uint32& size ) : + mCaseInsensitive( true ) +{ LoadFromMemory( RAWData, size ); } +cIniFile::cIniFile( cPack * Pack, std::string iniPackPath ) : + mCaseInsensitive( true ) +{ + LoadFromPack( Pack, iniPackPath ); +} + +bool cIniFile::LoadFromPack( cPack * Pack, std::string iniPackPath ) { + if ( NULL != Pack && Pack->IsOpen() && Pack->Exists( iniPackPath ) ) { + SafeDataPointer PData; + + Pack->ExtractFileToMemory( iniPackPath, PData ); + + return LoadFromMemory( PData.Data, PData.DataSize ); + } + + return false; +} + bool cIniFile::LoadFromMemory( const Uint8* RAWData, const Uint32& size ) { std::string myfile; myfile.assign( reinterpret_cast (RAWData), size ); @@ -28,26 +49,38 @@ bool cIniFile::LoadFromMemory( const Uint8* RAWData, const Uint32& size ) { } bool cIniFile::LoadFromFile( const std::string& iniPath ) { - // Normally you would use ifstream, but the SGI CC compiler has - // a few bugs with ifstream. So ... fstream used. - std::fstream f; - std::string line; + if ( FileExists( iniPath ) ) { + // Normally you would use ifstream, but the SGI CC compiler has + // a few bugs with ifstream. So ... fstream used. + std::fstream f; + std::string line; - Path ( iniPath ); + Path ( iniPath ); - f.open ( mPath.c_str(), std::ios::in ); + f.open ( mPath.c_str(), std::ios::in ); - if ( f.fail() ) - return false; + if ( f.fail() ) + return false; - mLines.clear(); + mLines.clear(); - while ( getline ( f, line ) ) - mLines.push_back( line ); + while ( getline ( f, line ) ) + mLines.push_back( line ); - f.close(); + f.close(); - return true; + return true; + } else if ( cPackManager::instance()->FallbackToPacks() ) { + std::string tPath( iniPath ); + + cPack * tPack = cPackManager::instance()->Exists( tPath ); + + if ( NULL != tPack ) { + return LoadFromPack( tPack, tPath ); + } + } + + return false; } bool cIniFile::ReadFile() { diff --git a/src/system/cinifile.hpp b/src/system/cinifile.hpp index ceadbb7c2..9250b2432 100755 --- a/src/system/cinifile.hpp +++ b/src/system/cinifile.hpp @@ -24,6 +24,8 @@ namespace EE { namespace System { +class cPack; + class EE_API cIniFile { private: bool mCaseInsensitive; @@ -43,9 +45,11 @@ class EE_API cIniFile { enum errors { noID = -1}; cIniFile ( std::string const iniPath = "" ); cIniFile ( const Uint8* RAWData, const Uint32& size ); + cIniFile ( cPack * Pack, std::string iniPackPath ); bool LoadFromFile( const std::string& iniPath ); bool LoadFromMemory( const Uint8* RAWData, const Uint32& size ); + bool LoadFromPack( cPack * Pack, std::string iniPackPath ); virtual ~cIniFile() {} diff --git a/src/system/cpackmanager.cpp b/src/system/cpackmanager.cpp index d96c9d881..97015be45 100644 --- a/src/system/cpackmanager.cpp +++ b/src/system/cpackmanager.cpp @@ -2,7 +2,8 @@ namespace EE { namespace System { -cPackManager::cPackManager() +cPackManager::cPackManager() : + mFallback( true ) { } @@ -10,12 +11,18 @@ cPackManager::~cPackManager() { } cPack * cPackManager::Exists( std::string& path ) { - FilePathRemoveProcessPath( path ); + std::string tpath( path ); + + FilePathRemoveProcessPath( tpath ); std::list::iterator it; for ( it = mResources.begin(); it != mResources.end(); it++ ) { - if ( -1 != (*it)->Exists( path ) ) { + if ( -1 != (*it)->Exists( tpath ) ) { + if ( path.size() != tpath.size() ) { + path = tpath; + } + return (*it); } } @@ -23,4 +30,12 @@ cPack * cPackManager::Exists( std::string& path ) { return NULL; } +const bool& cPackManager::FallbackToPacks() const { + return mFallback; +} + +void cPackManager::FallbackToPacks( const bool& fallback ) { + mFallback = fallback; +} + }} diff --git a/src/system/cpackmanager.hpp b/src/system/cpackmanager.hpp index 3edf784ad..216b3495b 100644 --- a/src/system/cpackmanager.hpp +++ b/src/system/cpackmanager.hpp @@ -15,6 +15,12 @@ class EE_API cPackManager : public tContainer, public tSingletonCreateWindow( WindowSettings( mWidth, mHeight, BitColor, Style, MyPath + "data/ee.png" ), ContextSettings( VSync, GLVer ) ); - PAK = eeNew( cZip, () ); PAK->Open( MyPath + "data/ee.zip" ); + mWindow = EE->CreateWindow( WindowSettings( mWidth, mHeight, BitColor, Style, "ee.png" ), ContextSettings( VSync, GLVer ) ); + run = ( mWindow->Created() && PAK->IsOpen() ); if ( run ) { @@ -738,7 +738,6 @@ void cEETest::LoadTextures() { Uint32 i; - PakTest = eeNew( cZip, () ); PakTest->Open( MyPath + "data/test.zip" ); diff --git a/src/window/backend/SDL/cwindowsdl.cpp b/src/window/backend/SDL/cwindowsdl.cpp index 3d2a8fe9e..d16908df2 100644 --- a/src/window/backend/SDL/cwindowsdl.cpp +++ b/src/window/backend/SDL/cwindowsdl.cpp @@ -186,10 +186,6 @@ void cWindowSDL::Caption( const std::string& Caption ) { bool cWindowSDL::Icon( const std::string& Path ) { int x, y, c; - if ( !FileExists( Path ) ) { - return false; - } - if ( !mWindow.Created ) { if ( stbi_info( Path.c_str(), &x, &y, &c ) ) { mWindow.WindowConfig.Icon = Path; @@ -200,13 +196,15 @@ bool cWindowSDL::Icon( const std::string& Path ) { return false; } - unsigned char * Ptr = stbi_load( Path.c_str(), &x, &y, &c, 0 ); + cImage Img( Path ); - if ( NULL != Ptr ) { - Int32 W = x; - Int32 H = y; + if ( NULL != Img.GetPixelsPtr() ) { + const Uint8 * Ptr = Img.GetPixelsPtr(); + x = Img.Width(); + y = Img.Height(); + c = Img.Channels(); - if ( ( W % 8 ) == 0 && ( H % 8 ) == 0 ) { + if ( ( x % 8 ) == 0 && ( y % 8 ) == 0 ) { Uint32 rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; @@ -219,7 +217,7 @@ bool cWindowSDL::Icon( const std::string& Path ) { bmask = 0x00ff0000; amask = 0xff000000; #endif - SDL_Surface * TempGlyphSheet = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, c * 8, rmask, gmask, bmask, amask); + SDL_Surface * TempGlyphSheet = SDL_CreateRGBSurface( SDL_SWSURFACE, x, y, c * 8, rmask, gmask, bmask, amask ); SDL_LockSurface( TempGlyphSheet ); @@ -235,12 +233,8 @@ bool cWindowSDL::Icon( const std::string& Path ) { SDL_FreeSurface( TempGlyphSheet ); - free( Ptr ); - return true; } - - free( Ptr ); } return false; @@ -357,9 +351,9 @@ std::vector< std::pair > cWindowSDL::GetPossibleReso } void cWindowSDL::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) { - eeclamp( &Red , 0.1f, 10.0f ); - eeclamp( &Green , 0.1f, 10.0f ); - eeclamp( &Blue , 0.1f, 10.0f ); + eeclamp( &Red , 0.1f, 10.0f ); + eeclamp( &Green , 0.1f, 10.0f ); + eeclamp( &Blue , 0.1f, 10.0f ); SDL_SetGamma( Red, Green, Blue ); } diff --git a/src/window/backend/SDL13/cwindowsdl.cpp b/src/window/backend/SDL13/cwindowsdl.cpp index 571c1e159..bfaa0ea4a 100644 --- a/src/window/backend/SDL13/cwindowsdl.cpp +++ b/src/window/backend/SDL13/cwindowsdl.cpp @@ -318,18 +318,20 @@ void cWindowSDL::SetGamma( eeFloat Red, eeFloat Green, eeFloat Blue ) { Uint16 green_ramp[256]; Uint16 blue_ramp[256]; - SDL_CalculateGammaRamp(Red, red_ramp); + SDL_CalculateGammaRamp( Red, red_ramp ); - if (Green == Red) { + if ( Green == Red ) { SDL_memcpy(green_ramp, red_ramp, sizeof(red_ramp)); } else { - SDL_CalculateGammaRamp(Green, green_ramp); + SDL_CalculateGammaRamp( Green, green_ramp ); } - if (Blue == Red) { - SDL_memcpy(blue_ramp, red_ramp, sizeof(red_ramp)); + if ( Blue == Red ) { + SDL_memcpy( blue_ramp, red_ramp, sizeof(red_ramp) ); + } else if ( Blue == Green ) { + SDL_memcpy( blue_ramp, green_ramp, sizeof(green_ramp) ); } else { - SDL_CalculateGammaRamp(Blue, blue_ramp); + SDL_CalculateGammaRamp( Blue, blue_ramp ); } SDL_SetWindowGammaRamp( mSDLWindow, red_ramp, green_ramp, blue_ramp ); @@ -350,10 +352,6 @@ eeWindowHandler cWindowSDL::GetWindowHandler() { bool cWindowSDL::Icon( const std::string& Path ) { int x, y, c; - if ( !FileExists( Path ) ) { - return false; - } - if ( !mWindow.Created ) { if ( stbi_info( Path.c_str(), &x, &y, &c ) ) { mWindow.WindowConfig.Icon = Path; @@ -364,13 +362,15 @@ bool cWindowSDL::Icon( const std::string& Path ) { return false; } - unsigned char * Ptr = stbi_load( Path.c_str(), &x, &y, &c, 0 ); + cImage Img( Path ); - if ( NULL != Ptr ) { - Int32 W = x; - Int32 H = y; + if ( NULL != Img.GetPixelsPtr() ) { + const Uint8 * Ptr = Img.GetPixelsPtr(); + x = Img.Width(); + y = Img.Height(); + c = Img.Channels(); - if ( ( W % 8 ) == 0 && ( H % 8 ) == 0 ) { + if ( ( x % 8 ) == 0 && ( y % 8 ) == 0 ) { Uint32 rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; @@ -383,7 +383,7 @@ bool cWindowSDL::Icon( const std::string& Path ) { bmask = 0x00ff0000; amask = 0xff000000; #endif - SDL_Surface * TempGlyphSheet = SDL_CreateRGBSurface(SDL_SWSURFACE, W, H, c * 8, rmask, gmask, bmask, amask); + SDL_Surface * TempGlyphSheet = SDL_CreateRGBSurface( SDL_SWSURFACE, x, y, c * 8, rmask, gmask, bmask, amask ); SDL_LockSurface( TempGlyphSheet ); @@ -399,12 +399,8 @@ bool cWindowSDL::Icon( const std::string& Path ) { SDL_FreeSurface( TempGlyphSheet ); - free( Ptr ); - return true; } - - free( Ptr ); } return false; diff --git a/src/window/backend/allegro5/cwindowal.cpp b/src/window/backend/allegro5/cwindowal.cpp index bf331dd84..c743efc19 100644 --- a/src/window/backend/allegro5/cwindowal.cpp +++ b/src/window/backend/allegro5/cwindowal.cpp @@ -413,15 +413,13 @@ bool cWindowAl::Icon( const std::string& Path ) { return false; } - if ( !FileExists( Path ) ) { - return false; - } + cImage Img( Path ); - unsigned char * Ptr = stbi_load( Path.c_str(), &x, &y, &c, 0 ); - - if ( NULL != Ptr ) { - Int32 W = x; - Int32 H = y; + if ( NULL != Img.GetPixelsPtr() ) { + const Uint8 * Ptr = Img.GetPixelsPtr(); + Int32 W = Img.Width(); + Int32 H = Img.Height(); + c = Img.Channels(); if ( ( W % 8 ) == 0 && ( H % 8 ) == 0 ) { int nbfl = al_get_new_bitmap_flags(); @@ -459,14 +457,10 @@ bool cWindowAl::Icon( const std::string& Path ) { al_set_new_bitmap_flags( nbfl ); al_set_target_backbuffer( mDisplay ); - free( Ptr ); - mWindow.WindowConfig.Icon = Path; return true; } - - free( Ptr ); } return false;