diff --git a/ee.linux.cbp b/ee.linux.cbp
index 194ce59d1..3e9abc251 100644
--- a/ee.linux.cbp
+++ b/ee.linux.cbp
@@ -13,6 +13,7 @@
+
@@ -63,6 +64,7 @@
+
diff --git a/src/audio/csound.cpp b/src/audio/csound.cpp
index ae9264f12..035aa4426 100755
--- a/src/audio/csound.cpp
+++ b/src/audio/csound.cpp
@@ -75,7 +75,7 @@ void cSound::Position( const eeFloat& X, const eeFloat& Y, const eeFloat& Z ) {
}
void cSound::Position( const Vector3AL& Position ) {
- this->Position(Position.x, Position.y, Position.z);
+ this->Position( Position.x, Position.y, Position.z );
}
void cSound::MinDistance( const eeFloat& MinDistance ) {
diff --git a/src/audio/csoundbuffer.cpp b/src/audio/csoundbuffer.cpp
index e41975cf6..10502ec77 100755
--- a/src/audio/csoundbuffer.cpp
+++ b/src/audio/csoundbuffer.cpp
@@ -85,7 +85,7 @@ bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
cLog::instance()->Write( "Failed to read audio data from file in memory" );
return false;
}
- }else {
+ } else {
cLog::instance()->Write( "Failed to load sound buffer from file in memory" );
return false;
}
diff --git a/src/audio/tsoundloader.hpp b/src/audio/tsoundloader.hpp
new file mode 100644
index 000000000..9dd44b635
--- /dev/null
+++ b/src/audio/tsoundloader.hpp
@@ -0,0 +1,166 @@
+#ifndef EE_AUDIOTSOUNDLOADER_HPP
+#define EE_AUDIOTSOUNDLOADER_HPP
+
+#include "base.hpp"
+#include "tsoundmanager.hpp"
+#include "../system/cobjectloader.hpp"
+
+namespace EE { namespace Audio {
+
+#define SND_LT_PATH (1)
+#define SND_LT_MEM (2)
+#define SND_LT_PACK (3)
+#define SND_LT_SAMPLES (4)
+
+template
+class EE_API tSoundLoader : public cObjectLoader {
+ public:
+ tSoundLoader( tSoundManager * SndMngr, const T& id, const std::string& filepath );
+
+ tSoundLoader( tSoundManager * SndMngr, const T& id, const char* Data, std::size_t SizeInBytes );
+
+ tSoundLoader( tSoundManager * SndMngr, const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate );
+
+ tSoundLoader( tSoundManager * SndMngr, const T& id, cPack* Pack, const std::string& FilePackPath );
+
+ ~tSoundLoader();
+
+ void Update();
+
+ const T& Id() const;
+ protected:
+ Uint32 mLoadType;
+ tSoundManager * mSndMngr;
+ T mId;
+ std::string mFilepath;
+ const char * mData;
+ Uint32 mDataSize;
+ const Int16 * mSamples;
+ Uint32 mSamplesCount;
+ Uint32 mChannelsCount;
+ Uint32 mSampleRate;
+ cPack * mPack;
+
+ void Start();
+ private:
+ void LoadFromPath();
+ void LoadFromMemory();
+ void LoadFromPack();
+ void LoadFromSamples();
+};
+
+template
+tSoundLoader::tSoundLoader( tSoundManager * SndMngr,
+ const T& id,
+ const std::string& filepath
+) : cObjectLoader( cObjectLoader::SoundLoader ),
+ mLoadType(SND_LT_PATH),
+ mSndMngr(SndMngr),
+ mId(id),
+ mFilepath(filepath)
+{
+}
+
+template
+tSoundLoader::tSoundLoader( tSoundManager * SndMngr,
+ const T& id,
+ const char * Data,
+ std::size_t SizeInBytes
+) : cObjectLoader( cObjectLoader::SoundLoader ),
+ mLoadType(SND_LT_MEM),
+ mSndMngr(SndMngr),
+ mId(id),
+ mData(Data),
+ mDataSize(SizeInBytes)
+{
+}
+
+template
+tSoundLoader::tSoundLoader( tSoundManager * SndMngr,
+ const T& id,
+ const Int16* Samples,
+ std::size_t SamplesCount,
+ unsigned int ChannelsCount,
+ unsigned int SampleRate
+) : cObjectLoader( cObjectLoader::SoundLoader ),
+ mLoadType(SND_LT_SAMPLES),
+ mSndMngr(SndMngr),
+ mId(id),
+ mSamples(Samples),
+ mSamplesCount(SamplesCount),
+ mChannelsCount(ChannelsCount),
+ mSampleRate(SampleRate)
+{
+}
+
+template
+tSoundLoader::tSoundLoader( tSoundManager * SndMngr,
+ const T& id, cPack* Pack,
+ const std::string& FilePackPath
+) : cObjectLoader( cObjectLoader::SoundLoader ),
+ mLoadType(SND_LT_PACK),
+ mSndMngr(SndMngr),
+ mId(id),
+ mFilepath(FilePackPath),
+ mPack(Pack)
+{
+}
+
+template
+tSoundLoader::~tSoundLoader() {
+
+}
+
+template
+void tSoundLoader::Update() {
+
+}
+
+template
+void tSoundLoader::Start() {
+ if ( NULL != mSndMngr ) {
+ cObjectLoader::Start();
+
+ if ( SND_LT_PATH == mLoadType )
+ LoadFromPath();
+ else if ( SND_LT_MEM == mLoadType )
+ LoadFromMemory();
+ else if ( SND_LT_PACK == mLoadType )
+ LoadFromPack();
+ else if ( SND_LT_SAMPLES == mLoadType )
+ LoadFromSamples();
+
+ SetLoaded();
+ }
+}
+
+template
+void tSoundLoader::LoadFromPath() {
+ mSndMngr->LoadFromFile( mId, mFilepath );
+}
+
+template
+void tSoundLoader::LoadFromMemory() {
+ mSndMngr->LoadFromMemory( mId, mData, mDataSize );
+}
+
+template
+void tSoundLoader::LoadFromPack() {
+ mSndMngr->LoadFromPack( mId, mPack, mFilepath );
+}
+
+template
+void tSoundLoader::LoadFromSamples() {
+ mSndMngr->LoadFromSamples( mId, mSamples, mSamplesCount, mChannelsCount, mSampleRate );
+}
+
+template
+const T& tSoundLoader::Id() const {
+ return mId;
+}
+
+typedef tSoundLoader cSoundLoader;
+
+}}
+
+#endif
diff --git a/src/audio/tsoundmanager.hpp b/src/audio/tsoundmanager.hpp
index 8090d1544..944753f4c 100755
--- a/src/audio/tsoundmanager.hpp
+++ b/src/audio/tsoundmanager.hpp
@@ -15,7 +15,7 @@ class EE_API tSoundManager{
bool LoadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes );
bool LoadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate );
bool LoadFromPack( const T& id, cPack* Pack, const std::string& FilePackPath );
-
+
cSoundBuffer& GetBuffer( const T& id );
/** This method will open a new channel if the channel seted for the sound is playing. */
@@ -37,44 +37,56 @@ class EE_API tSoundManager{
template
bool tSoundManager::LoadFromPack( const T& id, cPack* Pack, const std::string& FilePackPath ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
- if ( tSounds[id].Buf.LoadFromPack( Pack, FilePackPath ) ) {
- tSounds[id].Snd.push_back( cSound( tSounds[id].Buf ) );
+ sSound * tSound = &tSounds[id];
+
+ if ( tSound->Buf.LoadFromPack( Pack, FilePackPath ) ) {
+ tSound->Snd.push_back( cSound( tSound->Buf ) );
return true;
}
}
+
return false;
}
template
bool tSoundManager::LoadFromFile( const T& id, const std::string& filepath ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
- if ( tSounds[id].Buf.LoadFromFile( filepath ) ) {
- tSounds[id].Snd.push_back( cSound( tSounds[id].Buf ) );
+ sSound * tSound = &tSounds[id];
+
+ if ( tSound->Buf.LoadFromFile( filepath ) ) {
+ tSound->Snd.push_back( cSound( tSound->Buf ) );
return true;
}
}
+
return false;
}
template
bool tSoundManager::LoadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
- if ( tSounds[id].Buf.LoadFromMemory( Data, SizeInBytes ) ) {
- tSounds[id].Snd.push_back( cSound( tSounds[id].Buf ) );
+ sSound * tSound = &tSounds[id];
+
+ if ( tSound->Buf.LoadFromMemory( Data, SizeInBytes ) ) {
+ tSound->Snd.push_back( cSound( tSound->Buf ) );
return true;
}
}
+
return false;
}
template
bool tSoundManager::LoadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
- if ( tSounds[id].Buf.LoadFromSamples( Samples, SamplesCount, ChannelsCount, SampleRate ) ) {
- tSounds[id].Snd.push_back( cSound( tSounds[id].Buf ) );
+ sSound * tSound = &tSounds[id];
+
+ if ( tSound->Buf.LoadFromSamples( Samples, SamplesCount, ChannelsCount, SampleRate ) ) {
+ tSound->Snd.push_back( cSound( tSound->Buf ) );
return true;
}
}
+
return false;
}
@@ -94,24 +106,30 @@ cSound& tSoundManager::operator[] ( const T& id ) {
template
void tSoundManager::Play( const T& id ) {
- if ( tSounds.find( id ) != tSounds.end() ) {
- for ( Uint32 i = 0; i < tSounds[id].Snd.size(); i++ ) {
+ typename std::map::iterator it = tSounds.find( id );
+
+ if ( it != tSounds.end() ) {
+ sSound * tSound = &it->second;
+ Uint32 tSize = tSound->Snd.size();
+
+ for ( Uint32 i = 0; i < tSize; i++ ) {
// If there is a free slot, use it.
- if ( tSounds[id].Snd[i].GetState() != SOUND_PLAYING ) {
- tSounds[id].Snd[i].Play();
+ if ( tSound->Snd[i].GetState() != SOUND_PLAYING ) {
+ tSound->Snd[i].Play();
return;
}
}
// Otherwise create a new one and play it.
- tSounds[id].Snd.push_back( cSound( tSounds[id].Buf ) );
- tSounds[id].Snd[ tSounds[id].Snd.size() - 1 ].Play();
+ tSound->Snd.push_back( cSound( tSound->Buf ) );
+ tSound->Snd[ tSize ].Play();
}
}
template
tSoundManager::~tSoundManager() {
typename std::map::iterator itr;
+
for (itr = tSounds.begin(); itr != tSounds.end(); itr++)
itr->second.Snd.clear();
@@ -124,10 +142,12 @@ bool tSoundManager::Remove( const T& id ) {
tSounds.erase( id );
return true;
}
+
return false;
}
typedef tSoundManager cSoundManager;
+
}}
#endif
diff --git a/src/ee.h b/src/ee.h
index 3a1514940..91fdb82ed 100755
--- a/src/ee.h
+++ b/src/ee.h
@@ -72,6 +72,7 @@
#include "audio/csoundbuffer.hpp"
#include "audio/csoundstream.hpp"
#include "audio/cmusic.hpp"
+ #include "audio/tsoundloader.hpp"
#include "audio/tsoundmanager.hpp"
using namespace EE::Audio;
diff --git a/src/graphics/cconsole.cpp b/src/graphics/cconsole.cpp
index 6b99a43ea..dfe110024 100755
--- a/src/graphics/cconsole.cpp
+++ b/src/graphics/cconsole.cpp
@@ -203,44 +203,38 @@ void cConsole::PushText( const std::string& str ) {
PrivPushText( toWStr( str ) );
}
-void cConsole::PushText( const char* format, ... ) {
- char buf[256];
+void cConsole::PushText( const char * format, ... ) {
+ int n, size = 256;
+ std::string tstr( size, '\0' );
- va_list( args );
+ va_list args;
- va_start( args, format );
+ while (1) {
+ va_start( args, format );
- #ifdef EE_COMPILER_MSVC
- int nb = _vsnprintf_s( buf, 256, 256, format, args );
- #else
- int nb = vsnprintf(buf, 256, format, args);
- #endif
+ #ifdef EE_COMPILER_MSVC
+ n = _vsnprintf_s( &tstr[0], size, size, format, args );
+ #else
+ n = vsnprintf( &tstr[0], size, format, args );
+ #endif
- va_end( args );
+ va_end( args );
- if ( nb < 256 ) {
- PrivPushText( toWStr( std::string( buf ) ) );
- return;
+ if ( n > -1 && n < size ) {
+ tstr.resize( n );
+
+ PushText( tstr );
+
+ return;
+ }
+
+ if ( n > -1 ) // glibc 2.1
+ size = n+1; // precisely what is needed
+ else // glibc 2.0
+ size *= 2; // twice the old size
+
+ tstr.resize( size, '\0' );
}
-
- // The static size was not big enough, try again with a dynamic allocation.
- ++nb;
-
- char * buf2 = new char[nb];
-
- va_start( args, format );
-
- #ifdef EE_COMPILER_MSVC
- _vsnprintf_s( buf2, nb, nb, format, args );
- #else
- vsnprintf( buf2, nb, format, args );
- #endif
-
- va_end( args );
-
- PrivPushText( toWStr( std::string( buf2 ) ) );
-
- delete [] buf2;
}
void cConsole::Toggle() {
diff --git a/src/graphics/cshader.cpp b/src/graphics/cshader.cpp
index d2b07bea2..9b398e06b 100644
--- a/src/graphics/cshader.cpp
+++ b/src/graphics/cshader.cpp
@@ -28,21 +28,28 @@ cShader::cShader( const Uint32& Type, const std::string& Filename ) {
Compile();
}
+cShader::cShader( const Uint32& Type, const Uint8 * Data, const Uint32& DataSize ) {
+ Init( Type );
+
+ SetSource( Data, DataSize );
+
+ Compile();
+}
+
cShader::~cShader() {
- glDeleteShader( GetId() );
+ if ( 0 != mGLId )
+ glDeleteShader( mGLId );
}
void cShader::Init( const Uint32& Type ) {
- mType = Type;
- mValid = false;
- mCompiled = false;
- mGLId = glCreateShader( mType );
+ mType = Type;
+ mValid = false;
+ mCompiled = false;
+ mGLId = glCreateShader( mType );
}
void cShader::Reload() {
- mValid = false;
- mCompiled = false;
- mGLId = glCreateShader( mType );
+ Init( mType );
SetSource( mSource );
@@ -51,12 +58,18 @@ void cShader::Reload() {
void cShader::SetSource( const std::string& Source ) {
std::vector _dst( Source.size(), 0 );
- std::string _src( Source.size(), 0 );
- _src = Source;
- memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &_src[0] ), Source.size() );
+ memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Source[0] ), Source.size() );
- SetSource( _src );
+ SetSource( _dst );
+}
+
+void cShader::SetSource( const Uint8 * Data, const Uint32& DataSize ) {
+ std::vector _dst( DataSize, 0 );
+
+ memcpy( reinterpret_cast( &_dst[0] ), reinterpret_cast( &Data[0] ), DataSize );
+
+ SetSource( _dst );
}
void cShader::SetSource( const std::vector& Source ) {
@@ -67,9 +80,9 @@ void cShader::SetSource( const std::vector& Source ) {
mSource = Source;
- const char* src = &Source[0];
+ const char * src = &Source[0];
- glShaderSource( GetId(), 1, &src, NULL );
+ glShaderSource( mGLId, 1, &src, NULL );
}
bool cShader::Compile() {
@@ -102,9 +115,34 @@ bool cShader::Compile() {
return mValid;
}
-cVertexShader::cVertexShader() : cShader( GL_VERTEX_SHADER ) {}
-cVertexShader::cVertexShader( const std::string& Filename ) : cShader( GL_VERTEX_SHADER, Filename ) {}
-cFragmentShader::cFragmentShader() : cShader(GL_FRAGMENT_SHADER) {}
-cFragmentShader::cFragmentShader( const std::string& Filename ) : cShader( GL_FRAGMENT_SHADER, Filename ) {}
+cVertexShader::cVertexShader() :
+ cShader( GL_VERTEX_SHADER )
+{
+}
+
+cVertexShader::cVertexShader( const std::string& Filename ) :
+ cShader( GL_VERTEX_SHADER, Filename )
+{
+}
+
+cVertexShader::cVertexShader( const Uint8 * Data, const Uint32& DataSize ) :
+ cShader( GL_VERTEX_SHADER, Data, DataSize )
+{
+}
+
+cFragmentShader::cFragmentShader() :
+ cShader(GL_FRAGMENT_SHADER)
+{
+}
+
+cFragmentShader::cFragmentShader( const std::string& Filename ) :
+ cShader( GL_FRAGMENT_SHADER, Filename )
+{
+}
+
+cFragmentShader::cFragmentShader( const Uint8 * Data, const Uint32& DataSize ) :
+ cShader( GL_FRAGMENT_SHADER, Data, DataSize )
+{
+}
}}
diff --git a/src/graphics/cshader.hpp b/src/graphics/cshader.hpp
index 83b029c1b..d4b18886a 100644
--- a/src/graphics/cshader.hpp
+++ b/src/graphics/cshader.hpp
@@ -14,6 +14,9 @@ class EE_API cShader {
/** Create a type of shader and load the shader from a file, and compile it. */
cShader( const Uint32& Type, const std::string& Filename );
+ /** Create a type of shader from memory, and compile it. */
+ cShader( const Uint32& Type, const Uint8 * Data, const Uint32& DataSize );
+
virtual ~cShader();
/** Set the shader source */
@@ -22,6 +25,9 @@ class EE_API cShader {
/** Set the shader source */
void SetSource( const std::vector& Source );
+ /** Set the shader source */
+ void SetSource( const Uint8 * Data, const Uint32& DataSize );
+
/** Compile the shader */
bool Compile();
@@ -43,12 +49,12 @@ class EE_API cShader {
/** Reloads the Shader. */
void Reload();
protected:
- GLuint mGLId;
- GLenum mType;
- bool mValid;
- bool mCompiled;
- std::string mCompileLog;
- std::vector mSource;
+ GLuint mGLId;
+ GLenum mType;
+ bool mValid;
+ bool mCompiled;
+ std::string mCompileLog;
+ std::vector mSource;
void Init( const Uint32& Type );
};
@@ -58,6 +64,7 @@ class EE_API cVertexShader : public cShader {
public:
cVertexShader();
cVertexShader( const std::string& Filename );
+ cVertexShader( const Uint8 * Data, const Uint32& DataSize );
};
/** @brief Prebuild Fragment Shader class */
@@ -65,6 +72,7 @@ class EE_API cFragmentShader : public cShader {
public:
cFragmentShader();
cFragmentShader( const std::string& Filename );
+ cFragmentShader( const Uint8 * Data, const Uint32& DataSize );
};
}}
diff --git a/src/graphics/cshaderprogram.cpp b/src/graphics/cshaderprogram.cpp
index 450c749bc..9eb0c1316 100644
--- a/src/graphics/cshaderprogram.cpp
+++ b/src/graphics/cshaderprogram.cpp
@@ -34,8 +34,29 @@ cShaderProgram::cShaderProgram( const std::string& VertexShaderFile, const std::
cFragmentShader * fs = new cFragmentShader( FragmentShaderFile );
if ( !vs->IsValid() || !fs->IsValid() ) {
- delete vs;
- delete fs;
+ eeSAFE_DELETE( vs );
+ eeSAFE_DELETE( fs );
+ return;
+ }
+
+ AddShader( vs );
+ AddShader( fs );
+
+ Link();
+}
+
+cShaderProgram::cShaderProgram( const Uint8 * VertexShaderData, const Uint32& VertexShaderDataSize, const Uint8 * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name ) :
+ mGLId(0)
+{
+ AddToManager( name );
+ Init();
+
+ cVertexShader * vs = new cVertexShader( VertexShaderData, VertexShaderDataSize );
+ cFragmentShader * fs = new cFragmentShader( FragmentShaderData, FragmentShaderDataSize );
+
+ if ( !vs->IsValid() || !fs->IsValid() ) {
+ eeSAFE_DELETE( vs );
+ eeSAFE_DELETE( fs );
return;
}
@@ -53,7 +74,7 @@ cShaderProgram::~cShaderProgram() {
mAttributeLocations.clear();
for ( eeUint i = 0; i < mShaders.size(); i++ )
- delete mShaders[i];
+ eeSAFE_DELETE( mShaders[i] );
}
void cShaderProgram::AddToManager( const std::string& name ) {
diff --git a/src/graphics/cshaderprogram.hpp b/src/graphics/cshaderprogram.hpp
index 127561ae4..17ebf3b73 100644
--- a/src/graphics/cshaderprogram.hpp
+++ b/src/graphics/cshaderprogram.hpp
@@ -17,9 +17,12 @@ class EE_API cShaderProgram {
/** Construct a program shader with a vector of shaders and link them. */
cShaderProgram( const std::vector& Shaders, const std::string& name = "" );
- /** Constructor that creates a VertexShader from file and a Fragment Shader from file, and Link them. */
+ /** Constructor that creates a VertexShader from file and a Fragment Shader from file, and link them. */
cShaderProgram( const std::string& VertexShaderFile, const std::string& FragmentShaderFile, const std::string& name = "" );
+ /** Constructor that creates a VertexShader from memory and a Fragment Shader from memory, and link them. */
+ cShaderProgram( const Uint8 * VertexShaderData, const Uint32& VertexShaderDataSize, const Uint8 * FragmentShaderData, const Uint32& FragmentShaderDataSize, const std::string& name = "" );
+
virtual ~cShaderProgram();
/** Add a new shader */
diff --git a/src/graphics/cshapemanager.cpp b/src/graphics/cshapemanager.cpp
index 3a366d38d..bd89d6ccf 100644
--- a/src/graphics/cshapemanager.cpp
+++ b/src/graphics/cshapemanager.cpp
@@ -78,14 +78,14 @@ bool cShapeManager::Remove( const std::string& Name ) {
}
cShape * cShapeManager::Add( cShape * Shape ) {
- //assert null shape
-
- if ( mCount < mShapes.size() ) {
- mShapes[ mCount ] = Shape;
- mCount++;
- } else {
- mShapes.push_back( Shape );
- mCount++;
+ if ( NULL != Shape ) {
+ if ( mCount < mShapes.size() ) {
+ mShapes[ mCount ] = Shape;
+ mCount++;
+ } else {
+ mShapes.push_back( Shape );
+ mCount++;
+ }
}
return Shape;
diff --git a/src/graphics/cshapemanager.hpp b/src/graphics/cshapemanager.hpp
index 0596603cf..bc4496c43 100644
--- a/src/graphics/cshapemanager.hpp
+++ b/src/graphics/cshapemanager.hpp
@@ -32,7 +32,7 @@ class EE_API cShapeManager : public cSingleton {
bool Remove( const std::string& Name );
cShape * Add( cShape * Shape );
-
+
cShape * Add( const Uint32& TexId, const std::string& Name = "" );
cShape * Add( const Uint32& TexId, const eeRecti& SrcRect, const std::string& Name = "" );
@@ -46,6 +46,7 @@ class EE_API cShapeManager : public cSingleton {
Uint32 Count();
protected:
std::vector mShapes;
+
Uint32 mCount;
};
diff --git a/src/graphics/ctexturefactory.cpp b/src/graphics/ctexturefactory.cpp
index ab36c901e..c51714c7c 100755
--- a/src/graphics/ctexturefactory.cpp
+++ b/src/graphics/ctexturefactory.cpp
@@ -29,25 +29,25 @@ Uint32 cTextureFactory::CreateEmptyTexture( const eeUint& Width, const eeUint& H
Uint32 cTextureFactory::LoadFromPixels( const unsigned char * Pixels, const eeUint& Width, const eeUint& Height, const eeUint& Channels, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy, const std::string& FileName ) {
cTextureLoader myTex( Pixels, Width, Height, Channels, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy, FileName );
myTex.Load();
- return myTex.TexId();
+ return myTex.Id();
}
Uint32 cTextureFactory::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
cTextureLoader myTex( Pack, FilePackPath, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
myTex.Load();
- return myTex.TexId();
+ return myTex.Id();
}
Uint32 cTextureFactory::LoadFromMemory( const unsigned char * ImagePtr, const eeUint& Size, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
cTextureLoader myTex( ImagePtr, Size, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
myTex.Load();
- return myTex.TexId();
+ return myTex.Id();
}
Uint32 cTextureFactory::Load( const std::string& Filepath, const bool& Mipmap, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) {
cTextureLoader myTex( Filepath, Mipmap, ColorKey, ClampMode, CompressTexture, KeepLocalCopy );
myTex.Load();
- return myTex.TexId();
+ return myTex.Id();
}
Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& TexId, const eeUint& Width, const eeUint& Height, const eeUint& ImgWidth, const eeUint& ImgHeight, const bool& Mipmap, const eeUint& Channels, const eeRGB& ColorKey, const EE_CLAMP_MODE& ClampMode, const bool& CompressTexture, const bool& LocalCopy ) {
diff --git a/src/graphics/ctextureloader.cpp b/src/graphics/ctextureloader.cpp
index 952ad51e7..d84cd2cca 100644
--- a/src/graphics/ctextureloader.cpp
+++ b/src/graphics/ctextureloader.cpp
@@ -208,7 +208,7 @@ void cTextureLoader::Update() {
LoadFromPixels();
}
-const Uint32& cTextureLoader::TexId() const {
+const Uint32& cTextureLoader::Id() const {
return mTexId;
}
diff --git a/src/graphics/ctextureloader.hpp b/src/graphics/ctextureloader.hpp
index 77aaab872..9add6e7d4 100644
--- a/src/graphics/ctextureloader.hpp
+++ b/src/graphics/ctextureloader.hpp
@@ -25,7 +25,7 @@ class cTextureLoader : public cObjectLoader {
void Update();
- const Uint32& TexId() const;
+ const Uint32& Id() const;
protected:
Uint32 mLoadType; // From memory, from path, from pack
Uint8 * mPixels; // Texture Info
diff --git a/src/system/cobjectloader.hpp b/src/system/cobjectloader.hpp
index a65605513..cda389cbb 100644
--- a/src/system/cobjectloader.hpp
+++ b/src/system/cobjectloader.hpp
@@ -12,6 +12,7 @@ class cObjectLoader : cThread {
enum ObjLoaderType {
TextureLoader = 1,
+ SoundLoader = 2,
UserObjLoader
};
diff --git a/src/system/cpack.hpp b/src/system/cpack.hpp
index f259c8185..660f67268 100755
--- a/src/system/cpack.hpp
+++ b/src/system/cpack.hpp
@@ -29,6 +29,12 @@ class EE_API cPack : protected cMutex {
*/
virtual bool AddFile( const std::string& path, const std::string& inpack ) = 0;
+ /** Add a new file from memory */
+ virtual bool AddFile( std::vector& data, const std::string& inpack ) = 0;
+
+ /** Add a new file from memory */
+ virtual bool AddFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack ) = 0;
+
/** Add a map of files to the pack file ( myMap[ myFilepath ] = myInPackFilepath ) */
virtual bool AddFiles( std::map paths ) = 0;
@@ -44,6 +50,9 @@ class EE_API cPack : protected cMutex {
/** Extract a file to memory from the pack file */
virtual bool ExtractFileToMemory( const std::string& path, std::vector& data ) = 0;
+ /** Extract a file to memory from the pack file */
+ virtual bool ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* dataSize ) = 0;
+
/** Check if a file exists in the pack file and return the number of the file, otherwise return -1. */
virtual Int32 Exists( const std::string& path ) = 0;
@@ -55,9 +64,6 @@ class EE_API cPack : protected cMutex {
/** @return If the pack file is open */
virtual bool IsOpen() const;
-
- /** Add a new file from memory */
- virtual bool AddFile( std::vector& data, const std::string& inpack ) = 0;
protected:
bool mIsOpen;
};
diff --git a/src/system/cpak.cpp b/src/system/cpak.cpp
index f15da3afc..8c2fa0092 100755
--- a/src/system/cpak.cpp
+++ b/src/system/cpak.cpp
@@ -141,11 +141,33 @@ bool cPak::ExtractFileToMemory( const std::string& path, std::vector& dat
return Ret;
}
-bool cPak::AddFile( std::vector& data, const std::string& inpack ) {
- if ( data.size() < 1 )
+bool cPak::ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* dataSize ) {
+ Lock();
+
+ bool Ret = false;
+
+ Int32 Pos = Exists( path );
+
+ if ( Pos != -1 ) {
+ *dataSize = pakFiles[Pos].file_length;
+ *data = new Uint8[ (*dataSize) ];
+
+ myPak.fs.seekg( pakFiles[Pos].file_position, ios::beg );
+ myPak.fs.read( reinterpret_cast ( *data ), pakFiles[Pos].file_length );
+
+ Ret = true;
+ }
+
+ Unlock();
+
+ return Ret;
+}
+
+bool cPak::AddFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack ) {
+ if ( dataSize < 1 )
return false;
- Uint32 fsize = data.size();
+ Uint32 fsize = dataSize;
if ( myPak.fs.is_open() ) {
if ( myPak.header.dir_length == 1 ) {
@@ -168,8 +190,6 @@ bool cPak::AddFile( std::vector& data, const std::string& inpack ) {
pakFiles.push_back( newFile );
- data.clear();
-
return true;
} else {
if ( Exists( inpack ) != -1 ) // If the file already exists exit
@@ -206,15 +226,19 @@ bool cPak::AddFile( std::vector& data, const std::string& inpack ) {
pakFiles.push_back( pakE[ myPak.pakFilesNum ] );
myPak.pakFilesNum += 1;
- data.clear();
pakE.clear();
return true;
}
}
+
return false;
}
+bool cPak::AddFile( std::vector& data, const std::string& inpack ) {
+ return AddFile( reinterpret_cast ( &data[0] ), (Uint32)data.size(), inpack );
+}
+
bool cPak::AddFile( const std::string& path, const std::string& inpack ) {
if ( path.size() > 56 )
return false;
diff --git a/src/system/cpak.hpp b/src/system/cpak.hpp
index 09c56246d..aee9978b5 100755
--- a/src/system/cpak.hpp
+++ b/src/system/cpak.hpp
@@ -32,6 +32,9 @@ class EE_API cPak : public cPack {
/** Add a new file from memory */
bool AddFile( std::vector& data, const std::string& inpack );
+ /** Add a new file from memory */
+ bool AddFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack );
+
/** Add a map of files to the pakFile ( myMap[ myFilepath ] = myInPakFilepath ) */
bool AddFiles( std::map paths );
@@ -47,6 +50,9 @@ class EE_API cPak : public cPack {
/** Extract a file to memory from the pakFile */
bool ExtractFileToMemory( const std::string& path, std::vector& data );
+ /** Extract a file to memory from the pakFile */
+ bool ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* dataSize );
+
/** Check if a file exists in the pakFile and return the number of the file, otherwise return -1. */
Int32 Exists( const std::string& path );
diff --git a/src/system/czip.cpp b/src/system/czip.cpp
index 2bcc87aa7..c2356ecbf 100644
--- a/src/system/czip.cpp
+++ b/src/system/czip.cpp
@@ -87,10 +87,10 @@ bool cZip::AddFile( const std::string& path, const std::string& inpack ) {
return AddFile( file, inpack );
}
-bool cZip::AddFile( std::vector& data, const std::string& inpack ) {
+bool cZip::AddFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack ) {
if ( 0 == CheckPack() ) {
if ( ZIP_CREATED == mState ) {
- Int32 Result = ZipAdd( mZip , inpack.c_str(), reinterpret_cast (&data[0]), (unsigned int)data.size() );
+ Int32 Result = ZipAdd( mZip , inpack.c_str(), const_cast( data ), (unsigned int)dataSize );
if ( ZR_OK == Result )
return true;
@@ -107,7 +107,7 @@ bool cZip::AddFile( std::vector& data, const std::string& inpack ) {
Zip.AddFile( tdata, zipFiles[i].name );
}
- Zip.AddFile( data, inpack );
+ Zip.AddFile( data, dataSize, inpack );
Zip.Close();
@@ -130,6 +130,10 @@ bool cZip::AddFile( std::vector& data, const std::string& inpack ) {
return false;
}
+bool cZip::AddFile( std::vector& data, const std::string& inpack ) {
+ return AddFile( reinterpret_cast ( &data[0] ), (Uint32)data.size(), inpack );
+}
+
bool cZip::AddFiles( std::map paths ) {
for( std::map::iterator itr = paths.begin(); itr != paths.end(); itr++)
if ( !AddFile( itr->first, itr->second ) )
@@ -246,6 +250,29 @@ bool cZip::ExtractFileToMemory( const std::string& path, std::vector& dat
return Ret;
}
+bool cZip::ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* dataSize ) {
+ Lock();
+
+ bool Ret = false;
+ Int32 Pos = Exists( path );
+ Uint32 Result = 0;
+
+ if ( 0 == CheckPack() && -1 != Pos ) {
+ *dataSize = zipFiles[Pos].unc_size;
+ *data = new Uint8[ (*dataSize) ];
+
+ Result = UnzipItem( mZip, Pos, reinterpret_cast ( *data ), (unsigned int)zipFiles[Pos].unc_size );
+
+ if ( ZR_OK == Result ) {
+ Ret = true;
+ }
+ }
+
+ Unlock();
+
+ return Ret;
+}
+
Int32 cZip::Exists( const std::string& path ) {
for ( Uint32 i = 0; i < zipFiles.size(); i++ )
if ( strcmp( path.c_str(), zipFiles[i].name ) == 0 )
diff --git a/src/system/czip.hpp b/src/system/czip.hpp
index 7571de0b7..ec0ca6ad8 100644
--- a/src/system/czip.hpp
+++ b/src/system/czip.hpp
@@ -31,6 +31,9 @@ class EE_API cZip : public cPack {
*/
bool AddFile( const std::string& path, const std::string& inpack );
+ /** Add a new file from memory */
+ bool AddFile( const Uint8 * data, const Uint32& dataSize, const std::string& inpack );
+
/** Add a map of files to the pack file ( myMap[ myFilepath ] = myInPackFilepath ) */
bool AddFiles( std::map paths );
@@ -46,6 +49,9 @@ class EE_API cZip : public cPack {
/** Extract a file to memory from the pack file */
bool ExtractFileToMemory( const std::string& path, std::vector& data );
+ /** Extract a file to memory from the pakFile */
+ bool ExtractFileToMemory( const std::string& path, Uint8** data, Uint32* dataSize );
+
/** Check if a file exists in the pack file and return the number of the file, otherwise return -1. */
Int32 Exists( const std::string& path );
diff --git a/src/test/ee.cpp b/src/test/ee.cpp
index c5b921e77..6fbd57aee 100644
--- a/src/test/ee.cpp
+++ b/src/test/ee.cpp
@@ -1,7 +1,8 @@
#include "../ee.h"
/**
-@TODO Create a asynchronous resource loader ( at least for textures ).
+@TODO Add async loader for fonts.
+@TODO Create a Global Shape Manager containing one default shape manager and with the possibility to add new shape managers.
@TODO Add support for Joysticks.
@TODO Create a Vertex Buffer Object class ( with and without GL_ARB_vertex_buffer_object ).
@TODO Add support for Frame Buffer Object and to switch rendering to FBO and Screen.
@@ -11,6 +12,8 @@
@TODO Encapsulate SDL and OpenGL ( and remove unnecessary dependencies ).
@TODO Add some Surface Grid class, to create special effects ( waved texture, and stuff like that ).
@TODO Support color cursors ( not only black and white cursors, that really sucks ) - Imposible with SDL 1.2
+@TODO Add Scripting support.
+@TODO Add 2D physics support ( Box2D or Chipmunk wrapper ).
*/
class cUITest : public cUIControlAnim {
@@ -237,10 +240,6 @@ void cEETest::Init() {
LoadTextures();
- if ( SndMng.LoadFromPack( "mysound", &PAK, "sound.ogg" ) )
- SndMng["mysound"].Play();
-
-
if ( Mus.OpenFromPack( &PAK, "music.ogg" ) ) {
Mus.Loop(true);
Mus.Play();
@@ -373,6 +372,7 @@ void cEETest::CmdSetPartsNum ( const std::vector < std::wstring >& params ) {
void cEETest::OnTextureLoaded( cResourceLoader * ResLoaded ) {
mTextureLoaded = true;
+ SndMng.Play( "mysound" );
}
void cEETest::LoadTextures() {
@@ -386,8 +386,12 @@ void cEETest::LoadTextures() {
std::vector files = PakTest.GetFileList();
- for ( i = 0; i < files.size(); i++ )
- mResLoad.Add( new cTextureLoader( &PakTest, files[i] ) );
+ for ( i = 0; i < files.size(); i++ ) {
+ if ( "jpg" == FileExtension( files[i] ) )
+ mResLoad.Add( new cTextureLoader( &PakTest, files[i] ) );
+ }
+
+ mResLoad.Add( new cSoundLoader( &SndMng, "mysound", &PAK, "sound.ogg" ) );
mResLoad.Load( boost::bind( &cEETest::OnTextureLoaded, this, _1 ) );
diff --git a/src/utils/string.cpp b/src/utils/string.cpp
index 4ee77fa9a..ca2db7eac 100644
--- a/src/utils/string.cpp
+++ b/src/utils/string.cpp
@@ -70,7 +70,11 @@ std::vector < std::wstring > SplitString ( const std::wstring& str, const Uint32
std::wstring tmpstr;
for ( eeUint i = 0; i < str.size(); i++ ) {
+ #ifdef EE_COMPILER_MSVC
if ( str[i] == splitchar ) {
+ #else
+ if ( str[i] == (Int32)splitchar ) {
+ #endif
tmp.push_back(tmpstr);
tmpstr = L"";
} else {
diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp
index b73c2f9f3..c33b300c7 100755
--- a/src/utils/utils.cpp
+++ b/src/utils/utils.cpp
@@ -328,6 +328,12 @@ bool FileCopy( const std::string& src, const std::string& dst ) {
return false;
}
+std::string FileExtension( const std::string& filepath ) {
+ std::string tstr( filepath.substr( filepath.find_last_of(".") + 1 ) );
+ toLower( tstr );
+ return tstr;
+}
+
eeInt GetNumCPUs() {
eeInt nprocs = -1;
diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp
index dd9069431..e5f895807 100755
--- a/src/utils/utils.hpp
+++ b/src/utils/utils.hpp
@@ -57,6 +57,9 @@ namespace EE { namespace Utils {
*/
bool FileCopy( const std::string& src, const std::string& dst );
+ /** @return The file extension */
+ std::string FileExtension( const std::string& filepath );
+
/** @return The Number of CPUs of the system. */
eeInt GetNumCPUs();
}