diff --git a/src/graphics/cshapegroupmanager.cpp b/src/graphics/cshapegroupmanager.cpp index 5ee30259d..261f86007 100644 --- a/src/graphics/cshapegroupmanager.cpp +++ b/src/graphics/cshapegroupmanager.cpp @@ -31,4 +31,48 @@ cShape * cShapeGroupManager::GetShapeById( const Uint32& Id ) { return NULL; } +std::vector cShapeGroupManager::GetShapesByPattern( const std::string& name, const std::string& extension, cShapeGroup * SearchInShapeGroup ) { + std::vector Shapes; + std::string search; + bool found = true; + cShape * tShape = NULL; + std::string realext = ""; + eeInt c = 0; + if ( extension.size() ) + realext = "." + extension; + + do { + if ( c < 100 ) + search = StrFormated( "%s%02d%s", name.c_str(), c, realext.c_str() ); + else if ( c < 1000 ) + search = StrFormated( "%s%03d%s", name.c_str(), c, realext.c_str() ); + else if ( c < 10000 ) + search = StrFormated( "%s%04d%s", name.c_str(), c, realext.c_str() ); + else + found = false; + + if ( found ) { + if ( NULL == SearchInShapeGroup ) + tShape = GetShapeByName( search ); + else + tShape = SearchInShapeGroup->GetByName( search ); + + if ( NULL != tShape ) { + Shapes.push_back( tShape ); + + found = true; + } else { + if ( 0 == c ) // if didn't found "00", will search at least for "01" + found = true; + else + found = false; + } + } + + c++; + } while ( found ); + + return Shapes; +} + }} diff --git a/src/graphics/cshapegroupmanager.hpp b/src/graphics/cshapegroupmanager.hpp index db77fe88d..572bf36be 100644 --- a/src/graphics/cshapegroupmanager.hpp +++ b/src/graphics/cshapegroupmanager.hpp @@ -17,6 +17,14 @@ class EE_API cShapeGroupManager : public tResourceManager, public c cShape * GetShapeByName( const std::string& Name ); cShape * GetShapeById( const Uint32& Id ); + + /** Search for a pattern name + * @param name First part of the shape name + * @param extension Extension of the shape name ( if have one, otherwise "" ) + * @param SearchInShapeGroup If you want only to search in a especific group ( NULL if you want to search in all groups ) + * @example Search for name "car" with extensions "png", i will try to find car00.png car01.png car02.png, and so on, it will continue if find something, otherwise it will stop ( it will always search at least for car00.png and car01.png ) + */ + std::vector GetShapesByPattern( const std::string& name, const std::string& extension = "", cShapeGroup * SearchInShapeGroup = NULL ); }; }} diff --git a/src/graphics/csprite.cpp b/src/graphics/csprite.cpp index e2991f045..de53774e5 100755 --- a/src/graphics/csprite.cpp +++ b/src/graphics/csprite.cpp @@ -1,5 +1,6 @@ #include "csprite.hpp" #include "cglobalshapegroup.hpp" +#include "cshapegroupmanager.hpp" namespace EE { namespace Graphics { @@ -12,46 +13,47 @@ cSprite::~cSprite() { } void cSprite::ClearFrame() { - for ( eeUint i = 0; i < Frame.size(); i++ ) - Frame[i].Spr.clear(); + for ( eeUint i = 0; i < mFrames.size(); i++ ) + mFrames[i].Spr.clear(); - Frame.clear(); + mFrames.clear(); } void cSprite::Reset() { ClearFrame(); - mAutoAnim = true; - mAnimSpeed = 0.02f; - mScale = 1; - mRepeations = -1; - mReverseAnim = false; - mAnimPaused = false; - mAlpha = 255; - mAngle = 0; - mColor = eeRGBA(255, 255, 255, mAlpha); + + mAutoAnim = true; + mAnimSpeed = 0.02f; + mScale = 1; + mRepeations = -1; + mReverseAnim = false; + mAnimPaused = false; + mAlpha = 255; + mAngle = 0; + mColor = eeRGBA(255, 255, 255, mAlpha); + + mScaleCentered = true; + mBlend = ALPHA_NORMAL; + mEffect = RN_NORMAL; mColor0.voidRGB = true; mColor1.voidRGB = true; mColor2.voidRGB = true; mColor3.voidRGB = true; - mFrameData.CurrentFrame = 0; - mFrameData.CurrentSubFrame = 0; - mFrameData.fCurrentFrame = 0.f; - mFrameData.SubFrames = 1; - - mScaleCentered = true; - mBlend = ALPHA_NORMAL; - mEffect = RN_NORMAL; + mFrameData.CurrentFrame = 0; + mFrameData.CurrentSubFrame = 0; + mFrameData.fCurrentFrame = 0.f; + mFrameData.SubFrames = 1; } void cSprite::CurrentFrame (const eeFloat &CurFrame ) { mFrameData.fCurrentFrame = CurFrame; mFrameData.CurrentFrame = (eeUint)CurFrame; - if ( mFrameData.fCurrentFrame >= Frame.size() ) { - mFrameData.fCurrentFrame = (eeFloat)Frame.size() - 1; - mFrameData.CurrentFrame = (eeUint)Frame.size() - 1; + if ( mFrameData.fCurrentFrame >= mFrames.size() ) { + mFrameData.fCurrentFrame = (eeFloat)mFrames.size() - 1; + mFrameData.CurrentFrame = (eeUint)mFrames.size() - 1; } if ( mFrameData.fCurrentFrame < 0 ) { @@ -70,7 +72,7 @@ eeVector2f cSprite::GetRotationCenter( const eeRectf& DestRECT ) { } eeRecti cSprite::SprSrcRect() { - if ( Frame.size() ) + if ( mFrames.size() ) return GetCurrentShape()->SrcRect(); else return eeRecti(); @@ -79,7 +81,7 @@ eeRecti cSprite::SprSrcRect() { eeRectf cSprite::SprDestRectf() { eeRectf TmpR; - if ( Frame.size() ) { + if ( mFrames.size() ) { if ( mAngle != 0 || mEffect >= 4 ) { eeQuad2f Q = GetQuad(); eeFloat MinX = Q.V[0].x, MaxX = Q.V[0].x, MinY = Q.V[0].y, MaxY = Q.V[0].y; @@ -132,12 +134,12 @@ void cSprite::UpdatePos( const eeVector2f& NewPos ) { void cSprite::UpdateSize( const eeFloat& Width, const eeFloat& Height, const eeUint& FrameNum ) { eeUint FN; - if ( FrameNum >= Frame.size() ) + if ( FrameNum >= mFrames.size() ) FN = mFrameData.CurrentFrame; else FN = FrameNum; - cShape* S = Frame[FN].Spr[mFrameData.CurrentSubFrame]; + cShape* S = mFrames[FN].Spr[mFrameData.CurrentSubFrame]; S->DestWidth( Width ); S->DestHeight( Height ); } @@ -163,25 +165,30 @@ void cSprite::Update( const eeFloat& x, const eeFloat& y, const eeFloat& Scale, } Uint32 cSprite::GetTexture(const eeUint& FrameNum, const eeUint& SubFrameNum) { - if ( FrameNum < Frame.size() && SubFrameNum < mFrameData.SubFrames ) - return Frame[FrameNum].Spr[SubFrameNum]->Texture(); + if ( FrameNum < mFrames.size() && SubFrameNum < mFrameData.SubFrames ) + return mFrames[FrameNum].Spr[SubFrameNum]->Texture(); return 0; } eeUint cSprite::FramePos() { - Frame.push_back( cFrame() ); - return (eeUint)Frame.size() - 1; + mFrames.push_back( cFrame() ); + return (eeUint)mFrames.size() - 1; } -bool cSprite::CreateStatic(const Uint32& TexId, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector) { - if ( TexId < cTextureFactory::instance()->GetNumTextures() ) { - Reset(); - mFrameData.SubFrames = 1; - mAnimated = false; - eeUint id = FramePos(); +bool cSprite::CreateStatic( cShape * Shape ) { + Reset(); - return AddSubFrame(TexId, id, 0, DestWidth, DestHeight, offSetX, offSetY, TexSector); + AddFrame( Shape ); + + return true; +} + +bool cSprite::CreateStatic( const Uint32& TexId, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector ) { + if ( cTextureFactory::instance()->TextureIdExists( TexId ) ) { + Reset(); + + return 0 != AddFrame( TexId, DestWidth, DestHeight, offSetX, offSetY, TexSector ); } return false; @@ -189,7 +196,6 @@ bool cSprite::CreateStatic(const Uint32& TexId, const eeFloat& DestWidth, const void cSprite::CreateAnimation( const eeUint& SubFramesNum ) { Reset(); - mAnimated = true; if ( SubFramesNum < 1 ) mFrameData.SubFrames = 1; @@ -197,25 +203,36 @@ void cSprite::CreateAnimation( const eeUint& SubFramesNum ) { mFrameData.SubFrames = SubFramesNum; } -eeUint cSprite::AddFrame(const Uint32& TexId, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector) { - eeUint id = FramePos(); +bool cSprite::AddFrames( const std::vector Shapes ) { + if ( Shapes.size() ) { + for ( eeUint i = 0; i < Shapes.size(); i++ ) { + if ( NULL != Shapes[i] ) { + AddFrame( Shapes[i] ); + } + } - if ( TexId < cTextureFactory::instance()->GetNumTextures() ) { - AddSubFrame( TexId, id, 0, DestWidth, DestHeight, offSetX, offSetY, TexSector ); - return id; - } else - return 0; + return true; + } + + return false; } -bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeUint& NumSubFrame, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector) { - cTexture * Tex = cTextureFactory::instance()->GetTexture( TexId ); +bool cSprite::AddFramesByPattern( const std::string& name, const std::string& extension, cShapeGroup * SearchInShapeGroup ) { + std::vector Shapes = cShapeGroupManager::instance()->GetShapesByPattern( name, extension, SearchInShapeGroup ); - if ( NULL == Tex ) - return false; + if ( Shapes.size() ) { + AddFrames( Shapes ); + return true; + } + + return false; +} + +bool cSprite::AddSubFrame( cShape * Shape, const eeUint& NumFrame, const eeUint& NumSubFrame ) { eeUint NF, NSF; - if ( NumFrame >= Frame.size() ) + if ( NumFrame >= mFrames.size() ) NF = 0; else NF = NumFrame; @@ -225,42 +242,66 @@ bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeU else NSF = NumSubFrame; - if ( Frame[NF].Spr.size() != (eeUint)mFrameData.SubFrames ) - Frame[NF].Spr.resize( mFrameData.SubFrames ); + if ( mFrames[NF].Spr.size() != (eeUint)mFrameData.SubFrames ) + mFrames[NF].Spr.resize( mFrameData.SubFrames ); + mFrames[NF].Spr[NSF] = Shape; + + return true; +} + +eeUint cSprite::AddFrame( cShape * Shape ) { + eeUint id = FramePos(); + + AddSubFrame( Shape, id, mFrameData.CurrentSubFrame ); + + return id; +} + +eeUint cSprite::AddFrame(const Uint32& TexId, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector) { + eeUint id = FramePos(); + + if ( AddSubFrame( TexId, id, mFrameData.CurrentSubFrame, DestWidth, DestHeight, offSetX, offSetY, TexSector ) ) + return id; + + return 0; +} + +bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeUint& NumSubFrame, const eeFloat& DestWidth, const eeFloat& DestHeight, const eeFloat& offSetX, const eeFloat& offSetY, const eeRecti& TexSector) { + if ( !cTextureFactory::instance()->TextureIdExists( TexId ) ) + return false; + + cTexture * Tex = cTextureFactory::instance()->GetTexture( TexId ); cShape * S = cGlobalShapeGroup::instance()->Add( new cShape() ); - Frame[NF].Spr[NSF] = S; - if ( TexId ) { - S->Texture( TexId ); + S->Texture( TexId ); - if ( TexSector.Right > 0 && TexSector.Bottom > 0 ) - S->SrcRect( TexSector ); - else - S->SrcRect( eeRecti( 0, 0, (Int32)Tex->Width(), (Int32)Tex->Height() ) ); + if ( TexSector.Right > 0 && TexSector.Bottom > 0 ) + S->SrcRect( TexSector ); + else + S->SrcRect( eeRecti( 0, 0, (Int32)Tex->Width(), (Int32)Tex->Height() ) ); - if ( DestWidth > 0 ) - S->DestWidth( DestWidth ); - else - S->DestWidth( static_cast ( S->SrcRect().Right - S->SrcRect().Left ) ); + if ( DestWidth > 0 ) + S->DestWidth( DestWidth ); + else + S->DestWidth( static_cast ( S->SrcRect().Right - S->SrcRect().Left ) ); - if ( DestHeight > 0 ) - S->DestHeight( DestHeight ); - else - S->DestHeight( static_cast ( S->SrcRect().Bottom - S->SrcRect().Top ) ); + if ( DestHeight > 0 ) + S->DestHeight( DestHeight ); + else + S->DestHeight( static_cast ( S->SrcRect().Bottom - S->SrcRect().Top ) ); - S->OffsetX( offSetX ); - S->OffsetY( offSetY ); + S->OffsetX( offSetX ); + S->OffsetY( offSetY ); - return true; - } + AddSubFrame( S, NumFrame, NumSubFrame ); - return false; + return true; } void cSprite::Animate( const eeFloat& ElapsedTime ) { - if ( mAnimated && mAutoAnim && !mAnimPaused ) { - eeUint Size = (eeUint)Frame.size() - 1; + if ( mFrames.size() > 1 && mAutoAnim && !mAnimPaused ) { + eeUint Size = (eeUint)mFrames.size() - 1; eeFloat Elapsed = ( ElapsedTime != -99999.f ) ? (eeFloat)ElapsedTime : (eeFloat)cEngine::instance()->Elapsed(); if ( mRepeations == 0 ) @@ -321,13 +362,13 @@ eeUint cSprite::GetEndFrame() { if ( mReverseAnim ) { return 0; } else { - return (eeUint)Frame.size() - 1; + return (eeUint)mFrames.size() - 1; } } void cSprite::SetReverseFromStart() { mReverseAnim = true; - eeUint Size = (eeUint)Frame.size() - 1; + eeUint Size = (eeUint)mFrames.size() - 1; mFrameData.fCurrentFrame = (eeFloat)Size; mFrameData.CurrentFrame = Size; @@ -362,7 +403,7 @@ void cSprite::Draw( const EE_RENDERTYPE& Effect ) { eeUint cSprite::GetFrame( const eeUint& FrameNum ) { eeUint FN; - if ( FrameNum >= Frame.size() ) + if ( FrameNum >= mFrames.size() ) FN = mFrameData.CurrentFrame; else FN = FrameNum; @@ -423,23 +464,23 @@ void cSprite::OffSet( const eeVector2f& offset ) { } void cSprite::UpdateSprRECT( const eeRecti& R, const eeUint& FrameNum, const eeUint& SubFrame ) { - Frame[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->SrcRect( R ); + mFrames[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->SrcRect( R ); } void cSprite::Width( const eeFloat& Width, const eeUint& FrameNum, const eeUint& SubFrame ) { - Frame[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestWidth( Width ); + mFrames[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestWidth( Width ); } eeFloat cSprite::Width( const eeUint& FrameNum, const eeUint& SubFrame ) { - return Frame[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestWidth(); + return mFrames[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestWidth(); } void cSprite::Height( const eeFloat& Height, const eeUint& FrameNum, const eeUint& SubFrame ) { - Frame[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestHeight( Height ); + mFrames[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestHeight( Height ); } eeFloat cSprite::Height( const eeUint& FrameNum, const eeUint& SubFrame ) { - return Frame[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestHeight(); + return mFrames[ GetFrame(FrameNum) ].Spr[ GetSubFrame(SubFrame) ]->DestHeight(); } void cSprite::SetRepeations( const int& Repeations ) { @@ -451,7 +492,7 @@ void cSprite::SetAutoAnimate( const bool& Autoanim ) { } eeQuad2f cSprite::GetQuad() { - if ( Frame.size() ) { + if ( mFrames.size() ) { cShape* S = GetCurrentShape(); eeRectf TmpR; @@ -513,22 +554,22 @@ eeQuad2f cSprite::GetQuad() { } cShape* cSprite::GetCurrentShape() { - if ( Frame.size() ) - return Frame[ mFrameData.CurrentFrame ].Spr[ mFrameData.CurrentSubFrame ]; + if ( mFrames.size() ) + return mFrames[ mFrameData.CurrentFrame ].Spr[ mFrameData.CurrentSubFrame ]; return NULL; } cShape* cSprite::GetShape( const eeUint& frame ) { - if ( frame < Frame.size() ) - return Frame[ frame ].Spr[ mFrameData.CurrentSubFrame ]; + if ( frame < mFrames.size() ) + return mFrames[ frame ].Spr[ mFrameData.CurrentSubFrame ]; return NULL; } cShape* cSprite::GetShape( const eeUint& frame, const eeUint& SubFrame ) { - if ( frame < Frame.size() ) - return Frame[ frame ].Spr[ SubFrame ]; + if ( frame < mFrames.size() ) + return mFrames[ frame ].Spr[ SubFrame ]; return NULL; } diff --git a/src/graphics/csprite.hpp b/src/graphics/csprite.hpp index 79d9d80af..360a1c7d9 100755 --- a/src/graphics/csprite.hpp +++ b/src/graphics/csprite.hpp @@ -5,6 +5,7 @@ #include "../window/cengine.hpp" #include "ctexturefactory.hpp" #include "cshape.hpp" +#include "cshapegroup.hpp" using namespace EE::Window; @@ -170,6 +171,12 @@ class EE_API cSprite { */ Uint32 GetTexture( const eeUint& FrameNum = 0, const eeUint& SubFrameNum = 0 ); + /** Creates an static sprite (no animation) + * @param Shape The sprite shape + * @return True if success + */ + bool CreateStatic( cShape * Shape ); + /** Creates an static sprite (no animation) * @param TexId The internal Texture Id * @param DestWidth The default destination width of the sprite @@ -197,6 +204,20 @@ class EE_API cSprite { */ eeUint AddFrame( const Uint32& TexId, const eeFloat& DestWidth = 0, const eeFloat& DestHeight = 0, const eeFloat& offSetX = 0, const eeFloat& offSetY = 0, const eeRecti& TexSector = eeRecti(0,0,0,0) ); + /** Add a frame to the sprite (on the current sub frame) + * @param Shape The Shape used in the frame + * @return The frame position or 0 if fails + */ + eeUint AddFrame( cShape * Shape ); + + /** Add a vector of shapes as an animation. + * @param Shapes The Frames + */ + bool AddFrames( const std::vector Shapes ); + + /** @see cShapeGroupManager::GetShapesByPattern */ + bool AddFramesByPattern( const std::string& name, const std::string& extension = "", cShapeGroup * SearchInShapeGroup = NULL ); + /** Add a frame on an specific subframe to the sprite * @param TexId The internal Texture Id * @param NumFrame The Frame Number @@ -210,6 +231,14 @@ class EE_API cSprite { */ bool AddSubFrame( const Uint32& TexId, const eeUint& NumFrame, const eeUint& NumSubFrame, const eeFloat& DestWidth = 0, const eeFloat& DestHeight = 0, const eeFloat& offSetX = 0, const eeFloat& offSetY = 0, const eeRecti& TexSector = eeRecti(0,0,0,0) ); + /** Add a frame on an specific subframe to the sprite + * @param Shape The Shape used in the frame + * @param NumFrame The Frame Number + * @param NumSubFrame The Sub Frame Number + * @return True if success + */ + bool AddSubFrame( cShape * Shape, const eeUint& NumFrame, const eeUint& NumSubFrame ); + /** Draw the sprite to the screen */ void Draw(); @@ -232,8 +261,8 @@ class EE_API cSprite { /** Update the Frame Number SrcRECT * @param R The new SrcRECT - * @param FrameNum The Frame Number to change the SrcRECT. Default change the Current Frame. - * @param SubFrame The Sub Frame Number to change the SrcRECT. Default change the Current Sub Frame. + * @param FrameNum The Frame Number to change the SrcRECT. Default change the Current mFrames. + * @param SubFrame The Sub Frame Number to change the SrcRECT. Default change the Current Sub mFrames. */ void UpdateSprRECT( const eeRecti& R, const eeUint& FrameNum = 0, const eeUint& SubFrame = 0 ); @@ -261,7 +290,7 @@ class EE_API cSprite { /** Set the OffSet of the current frame */ void OffSet( const eeVector2f& offset ); - /** Reverse the animation from last frame to first frame. */ + /** Reverse the animation from last frame to first mFrames. */ void ReverseAnim( const bool& Reverse ) { mReverseAnim = Reverse; } /** @return If the animation is reversed */ @@ -271,7 +300,7 @@ class EE_API cSprite { eeUint GetEndFrame(); /** @return The number of frames */ - eeUint GetNumFrames() { return (eeUint)Frame.size(); } + eeUint GetNumFrames() { return (eeUint)mFrames.size(); } /** Will set Reverse active and set the first frame as the last frame */ void SetReverseFromStart(); @@ -286,7 +315,8 @@ class EE_API cSprite { cShape* GetShape( const eeUint& frame, const eeUint& SubFrame ); protected: eeFloat mX, mY, mAngle, mScale, mAnimSpeed; - bool mAutoAnim, mAnimated, mScaleCentered; + bool mAutoAnim; + bool mScaleCentered; EE_RENDERALPHAS mBlend; EE_RENDERTYPE mEffect; @@ -307,7 +337,7 @@ class EE_API cSprite { public: std::vector Spr; }; - std::vector Frame; + std::vector mFrames; eeUint FramePos(); void ClearFrame(); diff --git a/src/graphics/ctexturegrouploader.cpp b/src/graphics/ctexturegrouploader.cpp index 46f3323c4..76a05632f 100644 --- a/src/graphics/ctexturegrouploader.cpp +++ b/src/graphics/ctexturegrouploader.cpp @@ -91,6 +91,9 @@ void cTextureGroupLoader::CreateShapes() { // Create the Shape Group with the name of the real texture, not the Childs ( example load 1.png and not 1_ch1.png ) if ( 0 == z ) { + if ( tTexHdr->Flags & HDR_TEXTURE_FLAG_REMOVE_EXTENSION ) + name = FileRemoveExtension( name ); + tSG = new cShapeGroup( name ); cShapeGroupManager::instance()->Add( tSG ); } @@ -100,6 +103,10 @@ void cTextureGroupLoader::CreateShapes() { sShapeHdr * tSh = &tTexGroup->Shapes[i]; std::string ShapeName( &tSh->Name[0] ); + + if ( tSh->Flags & HDR_SHAPE_FLAG_REMOVE_EXTENSION ) + ShapeName = FileRemoveExtension( ShapeName ); + eeRecti tRect( tSh->X, tSh->Y, tSh->X + tSh->Width, tSh->Y + tSh->Height ); cShape * tShape = new cShape( tTex->TexId(), tRect, tSh->DestWidth, tSh->DestHeight, tSh->OffsetX, tSh->OffsetY, ShapeName ); diff --git a/src/graphics/ctexturepacker.cpp b/src/graphics/ctexturepacker.cpp index 9f4e66636..f460cec34 100644 --- a/src/graphics/ctexturepacker.cpp +++ b/src/graphics/ctexturepacker.cpp @@ -485,7 +485,7 @@ Int32 cTexturePacker::PackTextures() { // pack the textures, the return code is return ( mWidth * mHeight ) - mTotalArea; } -void cTexturePacker::Save( const std::string& Filepath, const EE_SAVETYPE& Format ) { +void cTexturePacker::Save( const std::string& Filepath, const EE_SAVETYPE& Format, const bool& SaveExtensions ) { if ( !mPacked ) PackTextures(); @@ -493,6 +493,7 @@ void cTexturePacker::Save( const std::string& Filepath, const EE_SAVETYPE& Forma return; mFilepath = Filepath; + mSaveExtensions = SaveExtensions; cImage Img( (Uint32)mWidth, (Uint32)mHeight, (Uint32)4 ); @@ -616,9 +617,10 @@ void cTexturePacker::CreateShapesHdr( cTexturePacker * Packer, std::vectorPlaced() ) { - std::string name = FileNameFromPath(tTex->Name() ); + std::string name = FileNameFromPath( tTex->Name() ); memset( tShapeHdr.Name, 0, HDR_NAME_SIZE ); + StrCopy( tShapeHdr.Name, name.c_str(), HDR_NAME_SIZE ); tShapeHdr.ResourceID = MakeHash( name ); @@ -636,6 +638,9 @@ void cTexturePacker::CreateShapesHdr( cTexturePacker * Packer, std::vectorFlipped() ) tShapeHdr.Flags |= HDR_SHAPE_FLAG_FLIPED; + if ( !mSaveExtensions ) + tShapeHdr.Flags |= HDR_SHAPE_FLAG_REMOVE_EXTENSION; + fs->write( reinterpret_cast (&tShapeHdr), sizeof(sShapeHdr) ); } } @@ -647,6 +652,7 @@ sTextureHdr cTexturePacker::CreateTextureHdr( cTexturePacker * Packer ) { std::string name( FileNameFromPath( Packer->GetFilepath() ) ); memset( TexHdr.Name, 0, HDR_NAME_SIZE ); + StrCopy( TexHdr.Name, name.c_str(), HDR_NAME_SIZE ); TexHdr.ResourceID = MakeHash( name ); @@ -654,6 +660,10 @@ sTextureHdr cTexturePacker::CreateTextureHdr( cTexturePacker * Packer ) { TexHdr.Width = Packer->GetWidth(); TexHdr.Height = Packer->GetHeight(); TexHdr.ShapeCount = Packer->GetPlacedCount(); + TexHdr.Flags = 0; + + if ( !mSaveExtensions ) + TexHdr.Flags |= HDR_TEXTURE_FLAG_REMOVE_EXTENSION; return TexHdr; } @@ -675,7 +685,7 @@ void cTexturePacker::ChildSave( const EE_SAVETYPE& Format ) { std::string fExt = FileExtension( LastParent->GetFilepath() ); std::string fName = fFpath + "_ch" + toStr( ParentCount ) + "." + fExt; - mChild->Save( fName, Format ); + mChild->Save( fName, Format, mSaveExtensions ); } } diff --git a/src/graphics/ctexturepacker.hpp b/src/graphics/ctexturepacker.hpp index 1f9e8ddb4..222643841 100644 --- a/src/graphics/ctexturepacker.hpp +++ b/src/graphics/ctexturepacker.hpp @@ -54,7 +54,7 @@ class EE_API cTexturePacker { Int32 PackTextures(); - void Save( const std::string& Filepath, const EE_SAVETYPE& Format = EE_SAVE_TYPE_DDS ); + void Save( const std::string& Filepath, const EE_SAVETYPE& Format = EE_SAVE_TYPE_DDS, const bool& SaveExtensions = false ); void Close(); @@ -88,6 +88,7 @@ class EE_API cTexturePacker { Int32 mPlacedCount; bool mForcePowOfTwo; Int32 mPixelBorder; + bool mSaveExtensions; cTexturePacker * GetChild() const; diff --git a/src/graphics/packerhelper.hpp b/src/graphics/packerhelper.hpp index a7eebadba..7f906883b 100644 --- a/src/graphics/packerhelper.hpp +++ b/src/graphics/packerhelper.hpp @@ -22,7 +22,8 @@ typedef struct sShapeHdrS { Uint32 Flags; } sShapeHdr; -#define HDR_SHAPE_FLAG_FLIPED ( 1 << 0 ) +#define HDR_SHAPE_FLAG_FLIPED ( 1 << 0 ) +#define HDR_SHAPE_FLAG_REMOVE_EXTENSION ( 1 << 1 ) typedef struct sTextureHdrS { char Name[ HDR_NAME_SIZE ]; @@ -31,8 +32,11 @@ typedef struct sTextureHdrS { Int32 Width; Int32 Height; Int32 ShapeCount; + Uint32 Flags; } sTextureHdr; +#define HDR_TEXTURE_FLAG_REMOVE_EXTENSION ( 1 << 1 ) + typedef struct sTextureGroupHdrS { Uint32 Magic; Uint32 TextureCount; diff --git a/src/test/ee.cpp b/src/test/ee.cpp index 9f1ae11ba..d4c40d3db 100644 --- a/src/test/ee.cpp +++ b/src/test/ee.cpp @@ -1,7 +1,6 @@ #include "../ee.h" /** -@TODO Load Animated Sprites from Shape Groups. @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. @TODO Create a basic UI system ( add basic controls, add skinning support ). @@ -192,6 +191,7 @@ class cEETest : private cThread { Uint32 mFace; cTextureGroupLoader * mTGL; + cSprite mBlindy; }; @@ -256,8 +256,6 @@ void cEETest::Init() { Scenes[1] = boost::bind( &cEETest::Screen2, this ); Scenes[2] = boost::bind( &cEETest::Screen3, this ); - mTGL = new cTextureGroupLoader( MyPath + "res/1.etg", true ); - InBuf.Start(); SetRandomSeed(); @@ -491,8 +489,6 @@ void cEETest::LoadTextures() { mFacePtr->Unlock(false,true); }*/ - SP.CreateAnimation(); - for ( Int32 my = 0; my < 4; my++ ) for( Int32 mx = 0; mx < 8; mx++ ) SP.AddFrame( TN[4], 0, 0, 0, 0, eeRecti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); @@ -532,13 +528,18 @@ void cEETest::LoadTextures() { EE->ShowCursor(false); - CL1.CreateStatic(TN[2]); + CL1.AddFrame(TN[2]); CL1.UpdatePos(500,400); CL1.Scale(0.5f); - CL2.CreateStatic(TN[0], 96, 96); + CL2.AddFrame(TN[0], 96, 96); CL2.Color( eeRGBA( 255, 255, 255, 255 ) ); + mTGL = new cTextureGroupLoader( MyPath + "res/1.etg", false ); + + mBlindy.AddFramesByPattern( "rn" ); + mBlindy.UpdatePos( 320.f, 0.f ); + Map.myFont = reinterpret_cast ( &FF ); Map.Create( 100, 100, 2, 128, 64, eeColor(175,175,175) ); @@ -612,6 +613,16 @@ void cEETest::Screen1() { } void cEETest::Screen2() { + if ( mTextureLoaded ) { + cTexture * TexLoaded = TF->GetByName( "1.jpg" ); + + if ( NULL != TexLoaded ) + TexLoaded->Draw( 0, 0 ); + } + + if ( KM->MouseLeftPressed() ) + TNP[3]->DrawEx( 0.f, 0.f, (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() ); + eeFloat PlanetX = HWidth - TNP[6]->Width() * 0.5f; eeFloat PlanetY = HHeight - TNP[6]->Height() * 0.5f; @@ -772,12 +783,7 @@ void cEETest::Screen3() { } void cEETest::Render() { - if ( mTextureLoaded ) { - /*cTexture * TexLoaded = TF->GetByName( "1.jpg" ); - - if ( NULL != TexLoaded ) - TexLoaded->Draw( 0, 0 );*/ - } else + if ( !mTextureLoaded ) mResLoad.Update(); HWidth = EE->GetWidth() * 0.5f; @@ -859,6 +865,8 @@ void cEETest::Render() { FF2->SetText( L"FPS: " + toWStr( EE->FPS() ) ); FF2->Draw( EE->GetWidth() - FF2->GetTextWidth() - 15, 0 ); + mBlindy.Draw(); + cUIManager::instance()->Update(); cUIManager::instance()->Draw(); @@ -1062,9 +1070,6 @@ void cEETest::Input() { if ( KM->IsKeyUp(KEY_D) ) SP.ReverseAnim( !SP.ReverseAnim() ); - if ( KM->MouseLeftPressed() ) - TNP[3]->DrawEx( 0.f, 0.f, (eeFloat)EE->GetWidth(), (eeFloat)EE->GetHeight() ); - if ( !KM->MouseRightPressed() ) DrawBack = false; @@ -1092,19 +1097,6 @@ void cEETest::Process() { else mFontLoader.Update(); - if ( !mTGL->IsLoaded() ) - mTGL->Update(); - else { - cShapeGroup * tSG = cShapeGroupManager::instance()->GetByName( "1.png" ); - - if ( NULL != tSG ) { - cShape * tS = tSG->GetByName( "rn01.png" ); - - if ( NULL != tS ) - tS->Draw( 320, 0 ); - } - } - if ( KM->IsKeyUp(KEY_F12) ) EE->TakeScreenshot( MyPath + "data/screenshots/" ); //After render and before Display EE->Display();