diff --git a/ee.files b/ee.files index aafbdd00d..57faa3af0 100644 --- a/ee.files +++ b/ee.files @@ -725,3 +725,8 @@ src/gaming/cgameobjectvirtual.hpp src/gaming/cgameobjectvirtual.cpp src/utils/safedatapointer.hpp src/utils/safedatapointer.cpp +src/system/ciostream.hpp +src/system/ciostreamfile.hpp +src/system/ciostreamfile.cpp +src/system/ciostreammemory.hpp +src/system/ciostreammemory.cpp diff --git a/src/gaming/base.hpp b/src/gaming/base.hpp index 2325e0ca4..13028bacc 100644 --- a/src/gaming/base.hpp +++ b/src/gaming/base.hpp @@ -12,4 +12,9 @@ using namespace EE::Utils; #include "../math/math.hpp" using namespace EE::Math; +#include "../system/ciostream.hpp" +#include "../system/ciostreamfile.hpp" +#include "../system/ciostreammemory.hpp" +using namespace EE::System; + #endif diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp index af66da723..143b16d40 100644 --- a/src/gaming/cmap.cpp +++ b/src/gaming/cmap.cpp @@ -633,148 +633,160 @@ typedef struct sMapObjGOHdrS { Int32 PosY; } sMapObjGOHdr; -bool cMap::Load( const std::string& path ) { - if ( FileExists( path ) ) { - sMapHdr MapHdr; - Uint32 i, z; +bool cMap::LoadFromStream( cIOStream& IOS ) { + sMapHdr MapHdr; + Uint32 i, z; - std::fstream fs ( path.c_str() , std::ios::in | std::ios::binary ); + if ( IOS.IsOpen() ) { + IOS.Read( (char*)&MapHdr, sizeof(sMapHdr) ); - if ( fs.is_open() ) { - fs.read( reinterpret_cast (&MapHdr), sizeof(sMapHdr) ); + if ( MapHdr.Magic == ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'M' << 16 ) | ( 'P' << 24 ) ) ) { + Create( eeSize( MapHdr.SizeX, MapHdr.SizeY ), MapHdr.MaxLayers, eeSize( MapHdr.TileSizeX, MapHdr.TileSizeY ), MapHdr.Flags ); - if ( MapHdr.Magic == ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'M' << 16 ) | ( 'P' << 24 ) ) ) { - Create( eeSize( MapHdr.SizeX, MapHdr.SizeY ), MapHdr.MaxLayers, eeSize( MapHdr.TileSizeX, MapHdr.TileSizeY ), MapHdr.Flags ); + //! Load Properties + if ( MapHdr.PropertyCount ) { + sPropertyHdr tProp[ MapHdr.PropertyCount ]; - //! Load Properties - if ( MapHdr.PropertyCount ) { - sPropertyHdr tProp[ MapHdr.PropertyCount ]; - fs.read( reinterpret_cast( &tProp[0] ), sizeof(sPropertyHdr) * MapHdr.PropertyCount ); + IOS.Read( (char*)&tProp[0], sizeof(sPropertyHdr) * MapHdr.PropertyCount ); - for ( i = 0; i < MapHdr.PropertyCount; i++ ) { - AddProperty( std::string( tProp[i].Name ), std::string( tProp[i].Value ) ); + for ( i = 0; i < MapHdr.PropertyCount; i++ ) { + AddProperty( std::string( tProp[i].Name ), std::string( tProp[i].Value ) ); + } + } + + //! Load Shape Groups + if ( MapHdr.ShapeGroupCount ) { + sMapShapeGroup tSG[ MapHdr.ShapeGroupCount ]; + + IOS.Read( (char*)&tSG[0], sizeof(sMapShapeGroup) * MapHdr.ShapeGroupCount ); + + std::vector ShapeGroups; + + for ( i = 0; i < MapHdr.ShapeGroupCount; i++ ) { + ShapeGroups.push_back( std::string( tSG[i].Path ) ); + } + + //! Load the Texture groups if needed + //! @TODO: Load TGPs + } + + //! Load Virtual Object Types + if ( MapHdr.VirtualObjectTypesCount ) { + sVirtualObj tVObj[ MapHdr.VirtualObjectTypesCount ]; + + IOS.Read( (char*)&tVObj[0], sizeof(sVirtualObj) * MapHdr.VirtualObjectTypesCount ); + + for ( i = 0; i < MapHdr.VirtualObjectTypesCount; i++ ) { + AddVirtualObjectType( std::string( tVObj[i].Name ) ); + } + } + + //! Load Layers + if ( MapHdr.LayerCount ) { + sLayerHdr tLayersHdr[ MapHdr.LayerCount ]; + sLayerHdr * tLayerHdr; + + IOS.Read( (char*)&tLayersHdr[0], sizeof(sLayerHdr) * MapHdr.LayerCount ); + + for ( i = 0; i < MapHdr.LayerCount; i++ ) { + tLayerHdr = &(tLayersHdr[i]); + + cLayer * tLayer = AddLayer( tLayerHdr->Type, tLayerHdr->Flags, std::string( tLayerHdr->Name ) ); + + tLayer->Offset( eeVector2f( (eeFloat)tLayerHdr->OffsetX, (eeFloat)tLayerHdr->OffsetY ) ); + + sPropertyHdr tProps[ tLayerHdr->PropertyCount ]; + + IOS.Read( (char*)&tProps[0], sizeof(sPropertyHdr) * tLayerHdr->PropertyCount ); + + for ( z = 0; z < tLayerHdr->PropertyCount; z++ ) { + tLayer->AddProperty( std::string( tProps[z].Name ), std::string( tProps[z].Value ) ); } } - //! Load Shape Groups - if ( MapHdr.ShapeGroupCount ) { - sMapShapeGroup tSG[ MapHdr.ShapeGroupCount ]; - fs.read( reinterpret_cast( &tSG[0] ), sizeof(sMapShapeGroup) * MapHdr.ShapeGroupCount ); + bool ThereIsTiled = false; - std::vector ShapeGroups; - - for ( i = 0; i < MapHdr.ShapeGroupCount; i++ ) { - ShapeGroups.push_back( std::string( tSG[i].Path ) ); - } - - //! Load the Texture groups if needed - } - - //! Load Virtual Object Types - if ( MapHdr.VirtualObjectTypesCount ) { - sVirtualObj tVObj[ MapHdr.VirtualObjectTypesCount ]; - fs.read( reinterpret_cast( &tVObj[0] ), sizeof(sVirtualObj) * MapHdr.VirtualObjectTypesCount ); - - for ( i = 0; i < MapHdr.VirtualObjectTypesCount; i++ ) { - AddVirtualObjectType( std::string( tVObj[i].Name ) ); + for ( i = 0; i < mLayerCount; i++ ) { + if ( NULL != mLayers[i] && mLayers[i]->Type() == MAP_LAYER_TILED ) { + ThereIsTiled = true; } } - //! Load Layers - if ( MapHdr.LayerCount ) { - sLayerHdr tLayersHdr[ MapHdr.LayerCount ]; - sLayerHdr * tLayerHdr; + Int32 x, y; + Uint32 tReadFlag = 0; + cTileLayer * tTLayer; + cGameObject * tGO; - fs.read( reinterpret_cast( &tLayersHdr[0] ), sizeof(sLayerHdr) * MapHdr.LayerCount ); + if ( ThereIsTiled ) { + //! First we read the tiled layers. + for ( y = 0; y < mSize.y; y++ ) { + for ( x = 0; x < mSize.x; x++ ) { - for ( i = 0; i < MapHdr.LayerCount; i++ ) { - tLayerHdr = &(tLayersHdr[i]); + //! Read the current tile flags + IOS.Read( (char*)&tReadFlag, sizeof(Uint32) ); - cLayer * tLayer = AddLayer( tLayerHdr->Type, tLayerHdr->Flags, std::string( tLayerHdr->Name ) ); + //! Read every game object header corresponding to this tile + for ( i = 0; i < mLayerCount; i++ ) { + if ( tReadFlag & ( 1 << i ) ) { + tTLayer = reinterpret_cast ( mLayers[i] ); - tLayer->Offset( eeVector2f( (eeFloat)tLayerHdr->OffsetX, (eeFloat)tLayerHdr->OffsetY ) ); + sMapTileGOHdr tTGOHdr; - sPropertyHdr tProps[ tLayerHdr->PropertyCount ]; - fs.read( reinterpret_cast( &tProps[0] ), sizeof(sPropertyHdr) * tLayerHdr->PropertyCount ); + IOS.Read( (char*)&tTGOHdr, sizeof(sMapTileGOHdr) ); - for ( z = 0; z < tLayerHdr->PropertyCount; z++ ) { - tLayer->AddProperty( std::string( tProps[z].Name ), std::string( tProps[z].Value ) ); - } - } + tGO = CreateGameObject( tTGOHdr.Type, tTGOHdr.Flags, tTGOHdr.Id ); - bool ThereIsTiled = false; - - for ( i = 0; i < mLayerCount; i++ ) { - if ( NULL != mLayers[i] && mLayers[i]->Type() == MAP_LAYER_TILED ) { - ThereIsTiled = true; - } - } - - Int32 x, y; - Uint32 tReadFlag = 0; - cTileLayer * tTLayer; - cGameObject * tGO; - - if ( ThereIsTiled ) { - //! First we read the tiled layers. - for ( y = 0; y < mSize.y; y++ ) { - for ( x = 0; x < mSize.x; x++ ) { - - //! Read the current tile flags - fs.read( reinterpret_cast ( &tReadFlag ), sizeof(Uint32) ); - - //! Read every game object header corresponding to this tile - for ( i = 0; i < mLayerCount; i++ ) { - if ( tReadFlag & ( 1 << i ) ) { - tTLayer = reinterpret_cast ( mLayers[i] ); - - sMapTileGOHdr tTGOHdr; - fs.read( reinterpret_cast ( &tTGOHdr ), sizeof(sMapTileGOHdr) ); - - tGO = CreateGameObject( tTGOHdr.Type, tTGOHdr.Flags, tTGOHdr.Id ); - - tTLayer->AddGameObject( tGO, eeVector2i( x, y ) ); - } + tTLayer->AddGameObject( tGO, eeVector2i( x, y ) ); } } } } + } - //! Load the game objects from the object layers - cObjectLayer * tOLayer; + //! Load the game objects from the object layers + cObjectLayer * tOLayer; - for ( i = 0; i < mLayerCount; i++ ) { - if ( NULL != mLayers[i] && mLayers[i]->Type() == MAP_LAYER_OBJECT ) { - tLayerHdr = &( tLayersHdr[i] ); - tOLayer = reinterpret_cast ( mLayers[i] ); + for ( i = 0; i < mLayerCount; i++ ) { + if ( NULL != mLayers[i] && mLayers[i]->Type() == MAP_LAYER_OBJECT ) { + tLayerHdr = &( tLayersHdr[i] ); + tOLayer = reinterpret_cast ( mLayers[i] ); - sMapObjGOHdr tOGOsHdr[ tLayerHdr->ObjectCount ]; - sMapObjGOHdr * tOGOHdr; + sMapObjGOHdr tOGOsHdr[ tLayerHdr->ObjectCount ]; + sMapObjGOHdr * tOGOHdr; - fs.read( reinterpret_cast ( &tOGOsHdr ), sizeof(sMapObjGOHdr) * tLayerHdr->ObjectCount ); + IOS.Read( (char*)&tOGOsHdr, sizeof(sMapObjGOHdr) * tLayerHdr->ObjectCount ); - for ( z = 0; z < tLayerHdr->ObjectCount; z++ ) { - tOGOHdr = &( tOGOsHdr[z] ); + for ( z = 0; z < tLayerHdr->ObjectCount; z++ ) { + tOGOHdr = &( tOGOsHdr[z] ); - tGO = CreateGameObject( tOGOHdr->Type, tOGOHdr->Flags, tOGOHdr->Id ); + tGO = CreateGameObject( tOGOHdr->Type, tOGOHdr->Flags, tOGOHdr->Id ); - tGO->Pos( eeVector2f( tOGOHdr->PosX, tOGOHdr->PosY ) ); + tGO->Pos( eeVector2f( tOGOHdr->PosX, tOGOHdr->PosY ) ); - tOLayer->AddGameObject( tGO ); - } + tOLayer->AddGameObject( tGO ); } } } - - return true; } + + return true; } } return false; } -void cMap::Save( const std::string& path ) { +bool cMap::Load( const std::string& path ) { + if ( FileExists( path ) ) { + cIOStreamFile IOS( path, std::ios::in | std::ios::binary ); + + return LoadFromStream( IOS ); + } + + return false; +} + +void cMap::SaveToStream( cIOStream& IOS ) { Uint32 i; sMapHdr MapHdr; cLayer * tLayer; @@ -793,11 +805,9 @@ void cMap::Save( const std::string& path ) { MapHdr.ShapeGroupCount = ShapeGroups.size(); MapHdr.VirtualObjectTypesCount = mObjTypes.size(); //! This is only usefull for the Map Editor, to auto add on the load the virtual object types that where used to create the map. - std::fstream fs ( path.c_str() , std::ios::out | std::ios::binary ); - - if ( fs.is_open() ) { + if ( IOS.IsOpen() ) { //! Writes the map header - fs.write( reinterpret_cast ( &MapHdr ), sizeof(sMapHdr) ); + IOS.Write( (const char*)&MapHdr, sizeof(sMapHdr) ); //! Writes the properties of the map for ( cMap::PropertiesMap::iterator it = mProperties.begin(); it != mProperties.end(); it++ ) { @@ -809,7 +819,7 @@ void cMap::Save( const std::string& path ) { StrCopy( tProp.Name, (*it).first.c_str(), MAP_PROPERTY_SIZE ); StrCopy( tProp.Value, (*it).second.c_str(), MAP_PROPERTY_SIZE ); - fs.write( reinterpret_cast ( &tProp ), sizeof(sPropertyHdr) ); + IOS.Write( (const char*)&tProp, sizeof(sPropertyHdr) ); } //! Writes the shape groups that the map will need and load @@ -820,7 +830,7 @@ void cMap::Save( const std::string& path ) { StrCopy( tSG.Path, ShapeGroups[i].c_str(), MAP_SHAPEGROUP_PATH_SIZE ); - fs.write( reinterpret_cast ( &tSG ), sizeof(sMapShapeGroup) ); + IOS.Write( (const char*)&tSG, sizeof(sMapShapeGroup) ); } //! Writes the names of the virtual object types created in the map editor @@ -831,7 +841,7 @@ void cMap::Save( const std::string& path ) { StrCopy( tVObjH.Name, (*votit).c_str(), MAP_PROPERTY_SIZE ); - fs.write( reinterpret_cast ( &tVObjH ), sizeof(sVirtualObj) ); + IOS.Write( (const char*)&tVObjH, sizeof(sVirtualObj) ); } //! Writes every layer header @@ -858,7 +868,7 @@ void cMap::Save( const std::string& path ) { tLayerH.PropertyCount = tLayerProp.size(); //! Writes the layer header - fs.write( reinterpret_cast ( &tLayerH ), sizeof(sLayerHdr) ); + IOS.Write( (const char*)&tLayerH, sizeof(sLayerHdr) ); //! Writes the properties of the current layer for ( cLayer::PropertiesMap::iterator lit = tLayerProp.begin(); lit != tLayerProp.end(); lit++ ) { @@ -869,6 +879,8 @@ void cMap::Save( const std::string& path ) { StrCopy( tProp.Name, (*lit).first.c_str(), MAP_PROPERTY_SIZE ); StrCopy( tProp.Value, (*lit).second.c_str(), MAP_PROPERTY_SIZE ); + + IOS.Write( (const char*)&tProp, sizeof(sPropertyHdr) ); } } @@ -918,7 +930,7 @@ void cMap::Save( const std::string& path ) { } //! Writes the current tile flags - fs.write( reinterpret_cast ( &tReadFlag ), sizeof(Uint32) ); + IOS.Write( (const char*)&tReadFlag, sizeof(Uint32) ); //! Writes every game object header corresponding to this tile for ( i = 0; i < mLayerCount; i++ ) { @@ -941,7 +953,7 @@ void cMap::Save( const std::string& path ) { tTGOHdr.Flags = tObj->Flags(); - fs.write( reinterpret_cast ( &tTGOHdr ), sizeof(sMapTileGOHdr) ); + IOS.Write( (const char*)&tTGOHdr, sizeof(sMapTileGOHdr) ); } } } @@ -982,15 +994,19 @@ void cMap::Save( const std::string& path ) { tOGOHdr.PosY = (Int32)tObj->Pos().y; - fs.write( reinterpret_cast ( &tOGOHdr ), sizeof(sMapObjGOHdr) ); + IOS.Write( (const char*)&tOGOHdr, sizeof(sMapObjGOHdr) ); } } } - - fs.close(); } } +void cMap::Save( const std::string& path ) { + cIOStreamFile IOS( path, std::ios::out | std::ios::binary ); + + SaveToStream( IOS ); +} + std::vector cMap::GetShapeGroups() { cShapeGroupManager * SGM = cShapeGroupManager::instance(); std::list& Res = SGM->GetResources(); diff --git a/src/gaming/cmap.hpp b/src/gaming/cmap.hpp index 4cd6fa900..277e5a074 100644 --- a/src/gaming/cmap.hpp +++ b/src/gaming/cmap.hpp @@ -40,8 +40,12 @@ class cMap { virtual bool Load( const std::string& path ); + virtual bool LoadFromStream( cIOStream& IOS ); + virtual void Save( const std::string& path ); + virtual void SaveToStream( cIOStream& IOS ); + virtual void Draw(); virtual void Update(); diff --git a/src/graphics/cshader.cpp b/src/graphics/cshader.cpp index 503df5f5f..f9adfefdf 100644 --- a/src/graphics/cshader.cpp +++ b/src/graphics/cshader.cpp @@ -13,22 +13,16 @@ cShader::cShader( const Uint32& Type ) { cShader::cShader( const Uint32& Type, const std::string& Filename ) { Init( Type ); - std::fstream fs; - fs.open( Filename.c_str(), std::ios::in | std::ios::binary ); + if ( FileExists( Filename ) ) { + SafeDataPointer PData; - if ( !fs.is_open() ) { + FileGet( Filename, PData ); + + SetSource( (const char*)PData.Data, PData.DataSize ); + } else { cLog::instance()->Write( std::string( "Couldn't open shader object: " ) + Filename ); } - fs.seekg ( 0, std::ios::end ); - Int32 Length = fs.tellg(); - fs.seekg ( 0, std::ios::beg ); - std::string Buffer( Length + 1, 0 ); - fs.read( reinterpret_cast ( &Buffer[0] ), Length ); - fs.close(); - - SetSource( Buffer ); - Compile(); } diff --git a/src/graphics/ctexturegrouploader.cpp b/src/graphics/ctexturegrouploader.cpp index 28bfb4ceb..d1f23dcae 100644 --- a/src/graphics/ctexturegrouploader.cpp +++ b/src/graphics/ctexturegrouploader.cpp @@ -3,6 +3,8 @@ #include "cshapegroupmanager.hpp" #include "ctexturepacker.hpp" #include "cshapegroup.hpp" +#include "../system/ciostreamfile.hpp" +#include "../system/ciostreammemory.hpp" namespace EE { namespace Graphics { @@ -66,23 +68,18 @@ void cTextureGroupLoader::Update() { CreateShapes(); } -void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { +void cTextureGroupLoader::LoadFromStream( cIOStream& IOS ) { mRL.Threaded( mThreaded ); - if ( TextureGroupPath.size() ) - mTextureGroupPath = TextureGroupPath; - - std::fstream fs ( mTextureGroupPath.c_str() , std::ios::in | std::ios::binary ); - - if ( fs.is_open() ) { - fs.read( reinterpret_cast (&mTexGrHdr), sizeof(sTextureGroupHdr) ); + if ( IOS.IsOpen() ) { + IOS.Read( (char*)&mTexGrHdr, sizeof(sTextureGroupHdr) ); if ( mTexGrHdr.Magic == ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'T' << 16 ) | ( 'G' << 24 ) ) ) { for ( Uint32 i = 0; i < mTexGrHdr.TextureCount; i++ ) { sTextureHdr tTextureHdr; sTempTexGroup tTexGroup; - fs.read( reinterpret_cast (&tTextureHdr), sizeof(sTextureHdr) ); + IOS.Read( (char*)&tTextureHdr, sizeof(sTextureHdr) ); tTexGroup.Texture = tTextureHdr; tTexGroup.Shapes.resize( tTextureHdr.ShapeCount ); @@ -96,7 +93,7 @@ void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { if ( !mSkipResourceLoad && NULL == tTex ) mRL.Add( eeNew( cTextureLoader, ( path ) ) ); - fs.read( reinterpret_cast (&tTexGroup.Shapes[0]), sizeof(sShapeHdr) * tTextureHdr.ShapeCount ); + IOS.Read( (char*)&tTexGroup.Shapes[0], sizeof(sShapeHdr) * tTextureHdr.ShapeCount ); mTempGroups.push_back( tTexGroup ); } @@ -112,6 +109,15 @@ void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { } } +void cTextureGroupLoader::Load( const std::string& TextureGroupPath ) { + if ( TextureGroupPath.size() ) + mTextureGroupPath = TextureGroupPath; + + cIOStreamFile IOS( mTextureGroupPath, std::ios::in | std::ios::binary ); + + LoadFromStream( IOS ); +} + void cTextureGroupLoader::LoadFromPack( cPack * Pack, const std::string& FilePackPath ) { if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( FilePackPath ) ) { mPack = Pack; @@ -125,55 +131,12 @@ void cTextureGroupLoader::LoadFromPack( cPack * Pack, const std::string& FilePac } void cTextureGroupLoader::LoadFromMemory( const Uint8* Data, const Uint32& DataSize, const std::string& TextureGroupName ) { - mRL.Threaded( mThreaded ); - if ( TextureGroupName.size() ) mTextureGroupPath = TextureGroupName; - const Uint8* dataPtr = Data; + cIOStreamMemory IOS( (const char*)Data, DataSize ); - if ( NULL != dataPtr ) { - memcpy( (void*)&mTexGrHdr, dataPtr, sizeof(sTextureGroupHdr) ); - dataPtr += sizeof(sTextureGroupHdr); - - if ( mTexGrHdr.Magic == ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'T' << 16 ) | ( 'G' << 24 ) ) ) { - for ( Uint32 i = 0; i < mTexGrHdr.TextureCount; i++ ) { - sTextureHdr tTextureHdr; - sTempTexGroup tTexGroup; - - memcpy( (void*)&tTextureHdr, dataPtr, sizeof(sTextureHdr) ); - dataPtr += sizeof(sTextureHdr); - - tTexGroup.Texture = tTextureHdr; - tTexGroup.Shapes.resize( tTextureHdr.ShapeCount ); - - std::string name( &tTextureHdr.Name[0] ); - std::string path( FileRemoveFileName( mTextureGroupPath ) + name ); - - //! Checks if the texture is already loaded - cTexture * tTex = cTextureFactory::instance()->GetByName( path ); - - if ( NULL == tTex ) { - if ( NULL != mPack ) - mRL.Add( eeNew( cTextureLoader, ( mPack, path ) ) ); - else - mRL.Add( eeNew( cTextureLoader, ( mAppPath + path ) ) ); - } - - memcpy( (void*)(&tTexGroup.Shapes[0]), dataPtr, sizeof(sShapeHdr) * tTextureHdr.ShapeCount ); - dataPtr += sizeof(sShapeHdr) * tTextureHdr.ShapeCount; - - mTempGroups.push_back( tTexGroup ); - } - } - - mIsLoading = true; - - mRL.Load(); - - if ( !mThreaded || 0 == mRL.Count() ) - CreateShapes(); - } + LoadFromStream( IOS ); } cShapeGroup * cTextureGroupLoader::GetShapeGroup() const { diff --git a/src/graphics/ctexturegrouploader.hpp b/src/graphics/ctexturegrouploader.hpp index 142dd460d..d17b8b8c7 100644 --- a/src/graphics/ctexturegrouploader.hpp +++ b/src/graphics/ctexturegrouploader.hpp @@ -6,6 +6,7 @@ #include "ctextureloader.hpp" #include "ctexturefactory.hpp" #include "../system/cresourceloader.hpp" +#include "../system/ciostream.hpp" namespace EE { namespace Graphics { @@ -29,6 +30,8 @@ class EE_API cTextureGroupLoader { void Load( const std::string& TextureGroupPath = "" ); + void LoadFromStream( cIOStream& IOS ); + void LoadFromMemory( const Uint8* Data, const Uint32& DataSize, const std::string& TextureGroupName ); void LoadFromPack( cPack * Pack, const std::string& FilePackPath ); diff --git a/src/system/ciostream.hpp b/src/system/ciostream.hpp new file mode 100644 index 000000000..e47ab2d4d --- /dev/null +++ b/src/system/ciostream.hpp @@ -0,0 +1,31 @@ +#ifndef EE_SYSTEMCIOSTREAM_HPP +#define EE_SYSTEMCIOSTREAM_HPP + +#include "base.hpp" + +namespace EE { + typedef std::streamsize ios_size; +} + +namespace EE { namespace System { + +class cIOStream { + public: + virtual ~cIOStream() {} + + virtual ios_size Read( char * data, ios_size size ) = 0; + + virtual ios_size Write( const char * data, ios_size size ) = 0; + + virtual ios_size Seek( ios_size position ) = 0; + + virtual ios_size GetPosition() = 0; + + virtual ios_size GetSize() = 0; + + virtual bool IsOpen() = 0; +}; + +}} + +#endif diff --git a/src/system/ciostreamfile.cpp b/src/system/ciostreamfile.cpp new file mode 100644 index 000000000..d50f112ac --- /dev/null +++ b/src/system/ciostreamfile.cpp @@ -0,0 +1,63 @@ +#include "ciostreamfile.hpp" + +namespace EE { namespace System { + +cIOStreamFile::cIOStreamFile( const std::string& path, std::ios_base::openmode mode ) { + mFS.open( path.c_str(), mode ); +} + +cIOStreamFile::~cIOStreamFile() { + if ( IsOpen() ) { + mFS.close(); + } +} + +ios_size cIOStreamFile::Read( char * data, ios_size size ) { + if ( IsOpen() ) { + mFS.read( data, size ); + } + + return size; +} + +ios_size cIOStreamFile::Write( const char * data, ios_size size ) { + if ( IsOpen() ) { + mFS.write( data, size ); + } + + return size; +} + +ios_size cIOStreamFile::Seek( ios_size position ) { + if ( IsOpen() ) { + mFS.seekg( position , std::ios::beg ); + } + + return position; +} + +ios_size cIOStreamFile::GetPosition() { + return mFS.tellg(); +} + +ios_size cIOStreamFile::GetSize() { + if ( IsOpen() ) { + ios_size Pos = GetPosition(); + + mFS.seekg ( 0, std::ios::end ); + + ios_size Length = mFS.tellg(); + + mFS.seekg ( Pos, std::ios::beg ); + + return Length; + } + + return 0; +} + +bool cIOStreamFile::IsOpen() { + return mFS.is_open(); +} + +}} diff --git a/src/system/ciostreamfile.hpp b/src/system/ciostreamfile.hpp new file mode 100644 index 000000000..d879965fa --- /dev/null +++ b/src/system/ciostreamfile.hpp @@ -0,0 +1,31 @@ +#ifndef EE_SYSTEMCIOSTREAMFILE_HPP +#define EE_SYSTEMCIOSTREAMFILE_HPP + +#include "ciostream.hpp" + +namespace EE { namespace System { + +class cIOStreamFile : public cIOStream { + public: + cIOStreamFile( const std::string& path, std::ios_base::openmode mode ); + + virtual ~cIOStreamFile(); + + ios_size Read( char * data, ios_size size ); + + ios_size Write( const char * data, ios_size size ); + + ios_size Seek( ios_size position ); + + ios_size GetPosition(); + + ios_size GetSize(); + + bool IsOpen(); + protected: + std::fstream mFS; +}; + +}} + +#endif diff --git a/src/system/ciostreammemory.cpp b/src/system/ciostreammemory.cpp new file mode 100644 index 000000000..e9eb98285 --- /dev/null +++ b/src/system/ciostreammemory.cpp @@ -0,0 +1,63 @@ +#include "ciostreammemory.hpp" + +namespace EE { namespace System { + +cIOStreamMemory::cIOStreamMemory( const char * data, ios_size size ) : + mReadPtr( data ), + mWritePtr( NULL ), + mPos( 0 ), + mSize( size ) +{ +} + +cIOStreamMemory::cIOStreamMemory( char * data, ios_size size ) : + mReadPtr( const_cast( data ) ), + mWritePtr( data ), + mPos( 0 ), + mSize( size ) +{ +} + +cIOStreamMemory::~cIOStreamMemory() { +} + +ios_size cIOStreamMemory::Read( char * data, ios_size size ) { + if ( mPos + size <= mSize ) { + memcpy( data, mReadPtr + mPos, size ); + + mPos += size; + } + + return mPos; +} + +ios_size cIOStreamMemory::Write( const char * data, ios_size size ) { + if ( NULL != mWritePtr && mPos + size <= mSize ) { + memcpy( mWritePtr + mPos, data, size ); + + mPos += size; + } + + return mPos; +} + +ios_size cIOStreamMemory::Seek( ios_size position ) { + if ( position < mSize ) + mPos = position; + + return mPos; +} + +ios_size cIOStreamMemory::GetPosition() { + return mPos; +} + +ios_size cIOStreamMemory::GetSize() { + return mSize; +} + +bool cIOStreamMemory::IsOpen() { + return NULL != mReadPtr; +} + +}} diff --git a/src/system/ciostreammemory.hpp b/src/system/ciostreammemory.hpp new file mode 100644 index 000000000..9bff48f61 --- /dev/null +++ b/src/system/ciostreammemory.hpp @@ -0,0 +1,36 @@ +#ifndef EE_SYSTEMCIOSTREAMMEMORY_HPP +#define EE_SYSTEMCIOSTREAMMEMORY_HPP + +#include "ciostream.hpp" + +namespace EE { namespace System { + +class cIOStreamMemory : public cIOStream { + public: + cIOStreamMemory( const char * data, ios_size size ); + + cIOStreamMemory( char * data, ios_size size ); + + virtual ~cIOStreamMemory(); + + ios_size Read( char * data, ios_size size ); + + ios_size Write( const char * data, ios_size size ); + + ios_size Seek( ios_size position ); + + ios_size GetPosition(); + + ios_size GetSize(); + + bool IsOpen(); + protected: + const char * mReadPtr; + char * mWritePtr; + ios_size mPos; + ios_size mSize; +}; + +}} + +#endif