From bfb58a9f401a9c949a667d00bc5a1db0b99ff7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 29 May 2013 14:34:42 -0300 Subject: [PATCH] Added "sprites" example. Assets in eetest are loaded directly from the file system. App icon now is searched in the local relative path. Fixed some minor bugs. Added userdata pointer to the sprites events. --- .hgignore | 1 + include/eepp/ee.hpp | 2 +- include/eepp/graphics/cimage.hpp | 7 +- include/eepp/graphics/csprite.hpp | 14 +- premake4.lua | 6 + projects/android-project/README | 6 +- projects/linux/ee.config | 3 +- projects/linux/ee.creator.user | 97 ++++++++++- projects/linux/ee.files | 1 + src/eepp/graphics/cimage.cpp | 3 + src/eepp/graphics/csprite.cpp | 20 ++- src/eepp/graphics/ctexture.cpp | 4 +- src/eepp/math/cinterpolation.cpp | 1 + src/eepp/window/backend/SDL/cwindowsdl.cpp | 17 +- src/eepp/window/backend/SDL2/cwindowsdl2.cpp | 21 ++- src/eepp/window/backend/SFML/cwindowsfml.cpp | 11 +- .../window/backend/allegro5/cwindowal.cpp | 21 ++- src/examples/sprites/sprites.cpp | 160 ++++++++++++++++++ src/test/eetest.cpp | 47 +++-- src/test/eetest.hpp | 3 +- 20 files changed, 366 insertions(+), 79 deletions(-) create mode 100644 src/examples/sprites/sprites.cpp diff --git a/.hgignore b/.hgignore index 9934e9cfd..3ec0575e7 100644 --- a/.hgignore +++ b/.hgignore @@ -17,6 +17,7 @@ syntax: glob ./eeew* ./eetest* ./eesound* +./eesprite* ./docs ee.tag log.log diff --git a/include/eepp/ee.hpp b/include/eepp/ee.hpp index 0be94d76d..622343c06 100755 --- a/include/eepp/ee.hpp +++ b/include/eepp/ee.hpp @@ -37,7 +37,7 @@ EE::Gaming Not documented at all. @TODO Add more commented examples, showing at least the basic usage of the engine ( 10 or more examples at least ). - STATE: 3 examples available. ( 30 % ) + STATE: 4 examples available. ( 40 % ) @TODO Improve the map editor ( add triggers, tiles selection to copy paste in other zones of the map, undo/redo actions ). STATE: Needs at least to reoffset tiles and objects for the map resizing. diff --git a/include/eepp/graphics/cimage.hpp b/include/eepp/graphics/cimage.hpp index 99fe6d9aa..59d5eed2b 100644 --- a/include/eepp/graphics/cimage.hpp +++ b/include/eepp/graphics/cimage.hpp @@ -7,13 +7,14 @@ using namespace EE::Math; #include -#include -#include -#include using namespace EE::System; #include +namespace EE { namespace System { +class cPack; +}} + namespace EE { namespace Graphics { /** @brief A simple image class to manipulate them. */ diff --git a/include/eepp/graphics/csprite.hpp b/include/eepp/graphics/csprite.hpp index 69a08fb4e..006d4b719 100755 --- a/include/eepp/graphics/csprite.hpp +++ b/include/eepp/graphics/csprite.hpp @@ -11,13 +11,15 @@ namespace EE { namespace Graphics { /** @brief A Sprite controller class, can hold and control sprites animations. */ class EE_API cSprite { public: - typedef cb::Callback2< void, Uint32, cSprite * > SpriteCallback; + /// Event ID - Sprite - User Data + typedef cb::Callback3< void, Uint32, cSprite *, void * > SpriteCallback; /** @enum cSprite::SpriteEvents The events that can be reported by the Sprite */ enum SpriteEvents { SPRITE_EVENT_LAST_FRAME, SPRITE_EVENT_FIRST_FRAME, - SPRITE_EVENT_END_ANIM_TO + SPRITE_EVENT_END_ANIM_TO, + SPRITE_EVENT_USER // User Events }; /** Instanciate an empty sprite */ @@ -319,7 +321,7 @@ class EE_API cSprite { void AnimToFrameAndStop( Uint32 GoTo ); /** Set the sprite events callback */ - void SetEventsCallback( const SpriteCallback& Cb ); + void SetEventsCallback( const SpriteCallback& Cb, void * UserData = NULL ); /** Removes the current callback */ void ClearCallback(); @@ -332,6 +334,9 @@ class EE_API cSprite { /** Update the sprite animation using the current elapsed time provided by cEngine */ void Update(); + + /** Fire a User Event in the sprite */ + void FireEvent( const Uint32& Event ); protected: enum SpriteFlags { SPRITE_FLAG_AUTO_ANIM = ( 1 << 0 ), @@ -363,6 +368,7 @@ class EE_API cSprite { eeUint mAnimTo; SpriteCallback mCb; + void * mUserData; class cFrame { public: @@ -379,8 +385,6 @@ class EE_API cSprite { eeUint GetFrame( const eeUint& FrameNum ); eeUint GetSubFrame( const eeUint& SubFrame ); - - void FireEvent( const Uint32& Event ); }; }} diff --git a/premake4.lua b/premake4.lua index 306fa2635..1e20937f3 100644 --- a/premake4.lua +++ b/premake4.lua @@ -724,3 +724,9 @@ solution "eepp" language "C++" files { "src/examples/sound/*.cpp" } build_link_configuration( "eesound" ) + + project "eepp-sprites" + kind "WindowedApp" + language "C++" + files { "src/examples/sprites/*.cpp" } + build_link_configuration( "eesprites" ) diff --git a/projects/android-project/README b/projects/android-project/README index f082ac766..4d81d8eb8 100644 --- a/projects/android-project/README +++ b/projects/android-project/README @@ -1,5 +1 @@ -Inside: - -src/eepp/helper/SDL2/include - -add a symbolic link to the same folder in a subfolder called SDL ( ln -s . SDL ) +Create a symbolic link to the assets folder in this current folder ( ln -s ../../assets ./assets ) diff --git a/projects/linux/ee.config b/projects/linux/ee.config index 11f6a2d0c..a963c8e16 100644 --- a/projects/linux/ee.config +++ b/projects/linux/ee.config @@ -1,7 +1,8 @@ #define EE_BACKEND_SDL_ACTIVE #define EE_BACKEND_ALLEGRO_ACTIVE #define EE_BACKEND_SFML_ACTIVE +#define EE_SDL_VERSION_2 +#define EE_SDL_VERSION_1_2 #define EE_BACKEND_SDL2 #define EE_BACKEND_SDL_1_2 -#define EE_SDL_VERSION_2 #define EE_X11_PLATFORM diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 5b7c74f7b..daf4548bf 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -48,9 +48,9 @@ Desktop Desktop {388e5431-b31b-42b3-b9ad-9002d279d75d} - 0 + 15 0 - 0 + 7 /home/programming/eepp/make/linux @@ -349,6 +349,46 @@ debug-sound GenericProjectManager.GenericBuildConfiguration + + /home/programming/eepp/make/linux + + + + false + -j4 eepp-sprites + make + true + Make + + GenericProjectManager.GenericMakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + clean + make + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + debug-test + debug-sprites + GenericProjectManager.GenericBuildConfiguration + /home/programming/eepp/make/linux @@ -669,7 +709,7 @@ release-es GenericProjectManager.GenericBuildConfiguration - 15 + 16 0 @@ -1013,7 +1053,54 @@ false true - 7 + + true + + false + false + false + false + true + 0.01 + 10 + true + 25 + + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + /home/programming/eepp/eesprites-debug + false + + %{buildDir} + Run /home/programming/eepp/eesprites-debug + eesprites-debug + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + true + false + false + true + + 8 diff --git a/projects/linux/ee.files b/projects/linux/ee.files index ac1148f94..b625af567 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -609,3 +609,4 @@ ../../src/eepp/audio/openal.hpp ../../src/eepp/window/backend/SDL2/cbackendsdl2.cpp ../../src/examples/sound/sound.cpp +../../src/examples/sprites/sprites.cpp diff --git a/src/eepp/graphics/cimage.cpp b/src/eepp/graphics/cimage.cpp index 2478195f8..04c61291d 100644 --- a/src/eepp/graphics/cimage.cpp +++ b/src/eepp/graphics/cimage.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include #include diff --git a/src/eepp/graphics/csprite.cpp b/src/eepp/graphics/csprite.cpp index 63f9768b2..78dd9f733 100755 --- a/src/eepp/graphics/csprite.cpp +++ b/src/eepp/graphics/csprite.cpp @@ -24,7 +24,8 @@ cSprite::cSprite() : mfCurrentFrame( 0.f ), mCurrentSubFrame( 0 ), mSubFrames( 1 ), - mAnimTo( 0 ) + mAnimTo( 0 ), + mUserData( NULL ) { mCb.Reset(); } @@ -44,7 +45,8 @@ cSprite::cSprite( const std::string& name, const std::string& extension, cTextur mfCurrentFrame( 0.f ), mCurrentSubFrame( 0 ), mSubFrames( 1 ), - mAnimTo( 0 ) + mAnimTo( 0 ), + mUserData( NULL ) { mCb.Reset(); AddFramesByPattern( name, extension, SearchInTextureAtlas ); @@ -65,7 +67,8 @@ cSprite::cSprite( cSubTexture * SubTexture ) : mfCurrentFrame( 0.f ), mCurrentSubFrame( 0 ), mSubFrames( 1 ), - mAnimTo( 0 ) + mAnimTo( 0 ), + mUserData( NULL ) { mCb.Reset(); CreateStatic( SubTexture ); @@ -86,13 +89,13 @@ cSprite::cSprite( const Uint32& TexId, const eeSizef &DestSize, const eeVector2i mfCurrentFrame( 0.f ), mCurrentSubFrame( 0 ), mSubFrames( 1 ), - mAnimTo( 0 ) + mAnimTo( 0 ), + mUserData( NULL ) { mCb.Reset(); CreateStatic( TexId, DestSize, Offset, TexSector ); } - cSprite::~cSprite() { eeSAFE_DELETE_ARRAY( mVertexColors ); } @@ -876,8 +879,9 @@ void cSprite::AnimToFrameAndStop( Uint32 GoTo ) { } } -void cSprite::SetEventsCallback( const SpriteCallback& Cb ) { - mCb = Cb; +void cSprite::SetEventsCallback(const SpriteCallback& Cb , void * UserData ) { + mCb = Cb; + mUserData = UserData; } void cSprite::ClearCallback() { @@ -886,7 +890,7 @@ void cSprite::ClearCallback() { void cSprite::FireEvent( const Uint32& Event ) { if ( SPR_FGET( SPRITE_FLAG_EVENTS_ENABLED ) && mCb.IsSet() ) { - mCb( Event, this ); + mCb( Event, this, mUserData ); } } diff --git a/src/eepp/graphics/ctexture.cpp b/src/eepp/graphics/ctexture.cpp index 1e13d4bd6..4ba200fa0 100755 --- a/src/eepp/graphics/ctexture.cpp +++ b/src/eepp/graphics/ctexture.cpp @@ -469,8 +469,8 @@ void cTexture::DrawEx( const eeFloat &x, const eeFloat &y, const eeFloat &width, if ( Scale != 1.0f ) { if ( ScaleCentered ) { - eeFloat halfW = w * 0.5f; - eeFloat halfH = h * 0.5f; + eeFloat halfW = width * 0.5f; + eeFloat halfH = height * 0.5f; mx = mx + halfW - halfW * Scale; my = my + halfH - halfH * Scale; } diff --git a/src/eepp/math/cinterpolation.cpp b/src/eepp/math/cinterpolation.cpp index a60aea75a..7a8395606 100644 --- a/src/eepp/math/cinterpolation.cpp +++ b/src/eepp/math/cinterpolation.cpp @@ -11,6 +11,7 @@ cInterpolation::cInterpolation() : mLoop(false), mEnded(false), mTotDist(0.f), + mCurPos(0.f), mCurPoint(0), mCurTime(0), mSpeed(1.3f), diff --git a/src/eepp/window/backend/SDL/cwindowsdl.cpp b/src/eepp/window/backend/SDL/cwindowsdl.cpp index bb658beab..ad326143b 100644 --- a/src/eepp/window/backend/SDL/cwindowsdl.cpp +++ b/src/eepp/window/backend/SDL/cwindowsdl.cpp @@ -217,13 +217,18 @@ bool cWindowSDL::Icon( const std::string& Path ) { return false; } - cImage Img( Path ); + cImage * Img = eeNew( cImage, ( Path ) ); - if ( NULL != Img.GetPixelsPtr() ) { - const Uint8 * Ptr = Img.GetPixelsPtr(); - x = Img.Width(); - y = Img.Height(); - c = Img.Channels(); + if ( NULL == Img->GetPixelsPtr() ) { + eeSAFE_DELETE( Img ); + Img = eeNew( cImage, ( Sys::GetProcessPath() + Path ) ); + } + + if ( NULL != Img->GetPixelsPtr() ) { + const Uint8 * Ptr = Img->GetPixelsPtr(); + x = Img->Width(); + y = Img->Height(); + c = Img->Channels(); if ( ( x % 8 ) == 0 && ( y % 8 ) == 0 ) { Uint32 rmask, gmask, bmask, amask; diff --git a/src/eepp/window/backend/SDL2/cwindowsdl2.cpp b/src/eepp/window/backend/SDL2/cwindowsdl2.cpp index 1122cac0e..d73fd79ab 100644 --- a/src/eepp/window/backend/SDL2/cwindowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/cwindowsdl2.cpp @@ -496,13 +496,18 @@ bool cWindowSDL::Icon( const std::string& Path ) { return false; } - cImage Img( Path ); + cImage * Img = eeNew( cImage, ( Path ) ); - if ( NULL != Img.GetPixelsPtr() ) { - const Uint8 * Ptr = Img.GetPixelsPtr(); - x = Img.Width(); - y = Img.Height(); - c = Img.Channels(); + if ( NULL == Img->GetPixelsPtr() ) { + eeSAFE_DELETE( Img ); + Img = eeNew( cImage, ( Sys::GetProcessPath() + Path ) ); + } + + if ( NULL != Img->GetPixelsPtr() ) { + const Uint8 * Ptr = Img->GetPixelsPtr(); + x = Img->Width(); + y = Img->Height(); + c = Img->Channels(); if ( ( x % 8 ) == 0 && ( y % 8 ) == 0 ) { Uint32 rmask, gmask, bmask, amask; @@ -533,10 +538,14 @@ bool cWindowSDL::Icon( const std::string& Path ) { SDL_FreeSurface( TempGlyphSheet ); + eeSAFE_DELETE( Img ); + return true; } } + eeSAFE_DELETE( Img ); + return false; } diff --git a/src/eepp/window/backend/SFML/cwindowsfml.cpp b/src/eepp/window/backend/SFML/cwindowsfml.cpp index be1ebfcc1..2657c227d 100644 --- a/src/eepp/window/backend/SFML/cwindowsfml.cpp +++ b/src/eepp/window/backend/SFML/cwindowsfml.cpp @@ -124,9 +124,16 @@ void cWindowSFML::Caption( const std::string& Caption ) { bool cWindowSFML::Icon( const std::string& Path ) { mWindow.WindowConfig.Icon = Path; - cImage Img( Path ); + cImage * Img = eeNew( cImage, ( Path ) ); - mSFMLWindow.setIcon( Img.Width(), Img.Height(), Img.GetPixelsPtr() ); + if ( NULL == Img->GetPixelsPtr() ) { + eeSAFE_DELETE( Img ); + Img = eeNew( cImage, ( Sys::GetProcessPath() + Path ) ); + } + + mSFMLWindow.setIcon( Img->Width(), Img->Height(), Img->GetPixelsPtr() ); + + eeSAFE_DELETE( Img ); return true; } diff --git a/src/eepp/window/backend/allegro5/cwindowal.cpp b/src/eepp/window/backend/allegro5/cwindowal.cpp index 5d550f5c3..4b6c92b33 100644 --- a/src/eepp/window/backend/allegro5/cwindowal.cpp +++ b/src/eepp/window/backend/allegro5/cwindowal.cpp @@ -424,13 +424,18 @@ bool cWindowAl::Icon( const std::string& Path ) { return false; } - cImage Img( Path ); + cImage * Img = eeNew( cImage, ( Path ) ); - if ( NULL != Img.GetPixelsPtr() ) { - const Uint8 * Ptr = Img.GetPixelsPtr(); - Int32 W = Img.Width(); - Int32 H = Img.Height(); - c = Img.Channels(); + if ( NULL == Img->GetPixelsPtr() ) { + eeSAFE_DELETE( Img ); + Img = eeNew( cImage, ( Sys::GetProcessPath() + Path ) ); + } + + 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(); @@ -470,10 +475,14 @@ bool cWindowAl::Icon( const std::string& Path ) { mWindow.WindowConfig.Icon = Path; + eeSAFE_DELETE( Img ); + return true; } } + eeSAFE_DELETE( Img ); + return false; } diff --git a/src/examples/sprites/sprites.cpp b/src/examples/sprites/sprites.cpp new file mode 100644 index 000000000..5981f5233 --- /dev/null +++ b/src/examples/sprites/sprites.cpp @@ -0,0 +1,160 @@ +#include + +// Define a user sprite event +static const Uint32 USER_SPRITE_EVENT = cSprite::SPRITE_EVENT_USER + 1; + +// Get the sprite event callback +void spriteCallback( Uint32 Event, cSprite * Sprite, void * UserData ) { + // Sprite Animation entered the first frame? + if ( Event == cSprite::SPRITE_EVENT_FIRST_FRAME ) { + // Fire a user Event + Sprite->FireEvent( USER_SPRITE_EVENT ); + } else if ( Event == USER_SPRITE_EVENT ) { + // Create an interpolation to change the angle of the sprite + cInterpolation * AngleInterpolation = reinterpret_cast( UserData ); + AngleInterpolation->ClearWaypoints(); + AngleInterpolation->AddWaypoint( Sprite->Angle() ); + AngleInterpolation->AddWaypoint( Sprite->Angle() + 45.f ); + AngleInterpolation->SetTotalTime( 500 ); + AngleInterpolation->Type( BOUNCEOUT ); // Set the easing effect used for the interpolation + AngleInterpolation->Start(); + + // Scale the sprite + if ( Sprite->Scale() < 3 ) { + Sprite->Scale( Sprite->Scale() + 0.25f ); + } + } +} + +EE_MAIN_FUNC int main (int argc, char * argv []) +{ + // Create a new window + cWindow * win = cEngine::instance()->CreateWindow( WindowSettings( 640, 480, "eepp - Sprites" ), ContextSettings( true ) ); + + // Set window background color + win->BackColor( eeColor( 0, 0, 0 ) ); + + // Check if created + if ( win->Created() ) { + // Get the application path + std::string AppPath = Sys::GetProcessPath(); + + // Load the rock texture + Uint32 PlanetId = cTextureFactory::instance()->Load( AppPath + "assets/sprites/t7.png" ); + Uint32 RockId = cTextureFactory::instance()->Load( AppPath + "assets/sprites/t5.png" ); + + // Load a previously generated texture atlas that contains the SubTextures needed to load an animated sprite + cTextureAtlasLoader Blindies( AppPath + "assets/atlases/bnb.eta" ); + + // Create some new sprites + cSprite Rock; + + // Load the rock frames from the texture, adding the frames manually + for ( Int32 my = 0; my < 4; my++ ) { + for( Int32 mx = 0; mx < 8; mx++ ) { + // DestSize as 0,0 will use the SubTexture size + Rock.AddFrame( RockId, eeSizef( 0, 0 ), eeVector2i( 0, 0 ), eeRecti( mx * 64, my * 64, mx * 64 + 64, my * 64 + 64 ) ); + } + } + + // Set the sprite animation speed, set in Frames per Second + // Sprites are auto-animated by default. + Rock.AnimSpeed( 32 ); + + cSprite Planet( PlanetId ); // Create a static sprite + + // This constructor is the same that creating sprite and calling Sprite.AddFramesByPattern. + // It will look for a SubTexture ( in any Texture Atlas loaded, or the GlobalTextureAtlas ) animation by its name, it will search + // for "gn00" to "gnXX" to create a new animation + // see cTextureAtlasManager::GetSubTexturesByPattern for more information. + // This is the easiest way to load animated sprites. + cSprite Blindy( "gn" ); + + // Set the render mode of the sprite + Blindy.RenderMode( RN_MIRROR ); + + // Set the Blend Mode of the sprite + Blindy.BlendMode( ALPHA_BLENDONE ); + + // Create a primitive drawer instance to draw the AABB of the Rock + cPrimitives P; + P.FillMode( EE_DRAW_LINE ); + + // Set the sprites position to the screen center + eeVector2i ScreenCenter( cEngine::instance()->GetWidth() / 2, cEngine::instance()->GetHeight() / 2 ); + + Planet.Position( ScreenCenter.x - Planet.GetAABB().Size().Width() / 2, ScreenCenter.y - Planet.GetAABB().Size().Height() / 2 ); + + Rock.Position( ScreenCenter.x - Rock.GetAABB().Size().Width() / 2, ScreenCenter.y - Rock.GetAABB().Size().Height() / 2 ); + + Blindy.Position( ScreenCenter.x - Blindy.GetAABB().Size().Width() / 2, ScreenCenter.y - Blindy.GetAABB().Size().Height() / 2 ); + + // Define a interpolation to control the Rock sprite angle + cInterpolation RockAngle; + + cInterpolation PlanetAngle; + PlanetAngle.AddWaypoint( 0 ); + PlanetAngle.AddWaypoint( 360 ); + PlanetAngle.SetTotalTime( 10000 ); + PlanetAngle.Loop( true ); + PlanetAngle.Start(); + + // Create a Event callback for the rock sprite + Rock.SetEventsCallback( cb::Make3( &spriteCallback ), &RockAngle ); + + // Application loop + while ( win->Running() ) + { + // Update the input + win->GetInput()->Update(); + + // Check if ESCAPE key is pressed + if ( win->GetInput()->IsKeyDown( KEY_ESCAPE ) ) { + // Close the window + win->Close(); + } + + // Check if the D key was pressed + if ( win->GetInput()->IsKeyUp( KEY_D ) ) { + // Reverse the Rock animation + Rock.ReverseAnim( !Rock.ReverseAnim() ); + } + + // Update the angle interpolation + PlanetAngle.Update( win->Elapsed() ); + RockAngle.Update( win->Elapsed() ); + + // Set the Planet and Rock angle from the interpolation + Planet.Angle( PlanetAngle.GetPos() ); + Rock.Angle( RockAngle.GetPos() ); + + // Draw the static planet sprite + Planet.Draw(); + + // Draw the animated Rock sprite + Rock.Draw(); + + // Draw the blindy animation + Blindy.Draw(); + + // Draw the Rock Axis-Aligned Bounding Box + P.SetColor( eeColorA( 255, 255, 255, 255 ) ); + P.DrawRectangle( Rock.GetAABB() ); + + // Draw the Rock Quad + P.SetColor( eeColorA( 255, 0, 0, 255 ) ); + P.DrawQuad( Rock.GetQuad() ); + + // Draw frame + win->Display(); + } + } + + // Destroy the engine instance. Destroys all the windows and engine singletons. + cEngine::DestroySingleton(); + + // If was compiled in debug mode it will print the memory manager report + EE::MemoryManager::ShowResults(); + + return EXIT_SUCCESS; +} diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 1668927f5..80718c4b1 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -8,7 +8,6 @@ void cEETest::Init() { cLog::instance()->LiveWrite( true ); cLog::instance()->ConsoleOutput( true ); - run = false; DrawBack = false; MultiViewportMode = false; @@ -48,14 +47,9 @@ void cEETest::Init() { WindowSettings WinSettings = EE->CreateWindowSettings( &Ini ); ContextSettings ConSettings = EE->CreateContextSettings( &Ini ); - PAK = eeNew( cZip, () ); - PAK->Open( MyPath + "ee.zip" ); - mWindow = EE->CreateWindow( WinSettings, ConSettings ); - run = ( NULL != mWindow && mWindow->Created() && PAK->IsOpen() ); - - if ( run ) { + if ( NULL != mWindow && mWindow->Created() ) { SetScreen( StartScreen ); mWindow->Caption( "EE++ Test Application" ); @@ -161,13 +155,13 @@ void cEETest::CreateUIThemeTextureAtlas() { void cEETest::LoadFonts() { mFTE.Reset(); - cTextureLoader * tl = eeNew( cTextureLoader, ( PAK, "conchars.png" ) ); + cTextureLoader * tl = eeNew( cTextureLoader, ( MyPath + "fonts/conchars.png" ) ); tl->SetColorKey( eeColor(0,0,0) ); mFontLoader.Add( eeNew( cTextureFontLoader, ( "conchars", tl, (eeUint)32 ) ) ); - mFontLoader.Add( eeNew( cTextureFontLoader, ( "ProggySquareSZ", eeNew( cTextureLoader, ( PAK, "ProggySquareSZ.png" ) ), PAK, "ProggySquareSZ.dat" ) ) ); - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255) ) ) ); - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", PAK, "arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); + mFontLoader.Add( eeNew( cTextureFontLoader, ( "ProggySquareSZ", eeNew( cTextureLoader, ( MyPath + "fonts/ProggySquareSZ.png" ) ), MyPath + "fonts/ProggySquareSZ.dat" ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", MyPath + "fonts/arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255) ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", MyPath + "fonts/arial.ttf", 12, EE_TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); mFontLoader.Load( cb::Make1( this, &cEETest::OnFontLoaded ) ); } @@ -207,7 +201,7 @@ void cEETest::CreateShaders() { if ( mUseShaders ) { mBlurFactor = 0.01f; - mShaderProgram = cShaderProgram::New( MyPath + "shader/blur.vert", MyPath + "shader/blur.frag" ); + mShaderProgram = cShaderProgram::New( MyPath + "shaders/blur.vert", MyPath + "shaders/blur.frag" ); } } @@ -263,7 +257,7 @@ void cEETest::CreateUI() { //mTheme = cUITheme::LoadFromPath( eeNew( cUIDefaultTheme, ( "uitheme", "uitheme" ) ), MyPath + "uitheme/" ); - cTextureAtlasLoader tgl( MyPath + "uithemeta/uitheme" + EE_TEXTURE_ATLAS_EXTENSION ); + cTextureAtlasLoader tgl( MyPath + "ui/uitheme" + EE_TEXTURE_ATLAS_EXTENSION ); mTheme = cUITheme::LoadFromTextureAtlas( eeNew( cUIDefaultTheme, ( "uitheme", "uitheme" ) ), cTextureAtlasManager::instance()->GetByName( "uitheme" ) ); @@ -558,10 +552,10 @@ void cEETest::CreateUI() { #ifdef EE_PLATFORM_TOUCH cTextureAtlas * SG = cGlobalTextureAtlas::instance(); - cTexture * butTex = TF->GetTexture( TF->Load( MyPath + "extra/button-te_normal.png" ) ); + cTexture * butTex = TF->GetTexture( TF->Load( MyPath + "sprites/button-te_normal.png" ) ); SG->Add( butTex->Id(), "button-te_normal" ); - SG->Add( TF->Load( MyPath + "extra/button-te_mdown.png" ), "button-te_mdown" ); + SG->Add( TF->Load( MyPath + "sprites/button-te_mdown.png" ), "button-te_mdown" ); cUISkinSimple nSkin( "button-te" ); @@ -829,7 +823,7 @@ void cEETest::LoadTextures() { } #endif - mResLoad.Add( eeNew( cSoundLoader, ( &SndMng, "mysound", PAK, "sound.ogg" ) ) ); + mResLoad.Add( eeNew( cSoundLoader, ( &SndMng, "mysound", MyPath + "sounds/sound.ogg" ) ) ); mResLoad.Load( cb::Make1( this, &cEETest::OnTextureLoaded ) ); @@ -837,13 +831,13 @@ void cEETest::LoadTextures() { TNP.resize(12); for ( i = 0; i <= 7; i++ ) { - TN[i] = TF->LoadFromPack( PAK, "t" + String::ToStr(i+1) + ".png", ( (i+1) == 7 ) ? true : false, ( (i+1) == 4 ) ? EE_CLAMP_REPEAT : EE_CLAMP_TO_EDGE ); + TN[i] = TF->Load( MyPath + "sprites/t" + String::ToStr(i+1) + ".png", ( (i+1) == 7 ) ? true : false, ( (i+1) == 4 ) ? EE_CLAMP_REPEAT : EE_CLAMP_TO_EDGE ); TNP[i] = TF->GetTexture( TN[i] ); } Tiles.resize(10); - cTextureAtlasLoader tgl( PAK, "tiles.etg" ); + cTextureAtlasLoader tgl( MyPath + "atlases/tiles.etg" ); cTextureAtlas * SG = cTextureAtlasManager::instance()->GetByName( "tiles" ); if ( NULL != SG ) { @@ -851,14 +845,14 @@ void cEETest::LoadTextures() { Tiles[i] = SG->GetByName( String::ToStr( i+1 ) ); } - Tiles[6] = SG->Add( TF->LoadFromPack( PAK, "objects/1.png" ), "7" ); + Tiles[6] = SG->Add( TF->Load( MyPath + "sprites/objects/1.png" ), "7" ); #ifdef EE_GLES - cImage tImg( PAK, "objects/2.png", 4 ); + cImage tImg( MyPath + "sprites/objects/2.png", 4 ); tImg.CreateMaskFromColor( eeColorA(0,0,0,255), 0 ); Tiles[7] = SG->Add( TF->LoadFromPixels( tImg.GetPixelsPtr(), tImg.Width(), tImg.Height(), tImg.Channels() ), "8" ); #else - Tiles[7] = SG->Add( TF->LoadFromPack( PAK, "objects/2.png" ), "8" ); + Tiles[7] = SG->Add( TF->Load( MyPath + "sprites/objects/2.png" ), "8" ); Tiles[7]->GetTexture()->CreateMaskFromColor( eeColorA(0,0,0,255), 0 ); #endif } @@ -898,9 +892,9 @@ void cEETest::LoadTextures() { Tex->Unlock(false, true); } - Cursor[0] = TF->LoadFromPack( PAK, "cursor.png" ); + Cursor[0] = TF->Load( MyPath + "cursors/cursor.png" ); CursorP[0] = TF->GetTexture( Cursor[0] ); - Cursor[1] = TF->LoadFromPack( PAK, "cursor.tga" ); + Cursor[1] = TF->Load( MyPath + "cursors/cursor.tga" ); CursorP[1] = TF->GetTexture( Cursor[1] ); cCursorManager * CurMan = mWindow->GetCursorManager(); @@ -916,8 +910,8 @@ void cEETest::LoadTextures() { CL2.AddFrame(TN[0], eeSizef(96, 96) ); CL2.Color( eeColorA( 255, 255, 255, 255 ) ); - if ( cImage::IsImage( MyPath + "extra/bnb.png" ) ) { - mTGL = eeNew( cTextureAtlasLoader, ( MyPath + "extra/bnb" + EE_TEXTURE_ATLAS_EXTENSION ) ); + if ( cImage::IsImage( MyPath + "atlases/bnb.png" ) ) { + mTGL = eeNew( cTextureAtlasLoader, ( MyPath + "atlases/bnb" + EE_TEXTURE_ATLAS_EXTENSION ) ); } mBlindy.AddFramesByPattern( "rn" ); @@ -1575,7 +1569,7 @@ void cEETest::Input() { void cEETest::Process() { Init(); - if ( run ) { + if ( NULL != mWindow && mWindow->Created() ) { do { et = mWindow->Elapsed(); @@ -1941,7 +1935,6 @@ void cEETest::End() { eeSAFE_DELETE( mVBO ); eeSAFE_DELETE( mBoxSprite ); eeSAFE_DELETE( mCircleSprite ); - eeSAFE_DELETE( PAK ); eeSAFE_DELETE( PakTest ); cLog::instance()->Save(); diff --git a/src/test/eetest.hpp b/src/test/eetest.hpp index 7396550d2..5818bfcf8 100644 --- a/src/test/eetest.hpp +++ b/src/test/eetest.hpp @@ -93,7 +93,7 @@ class cEETest : private cThread { cInput* KM; cInputTextBuffer InBuf; - bool run, side, aside; + bool side, aside; eeFloat ang, scale, alpha, Ang; eeFloat et; Int32 x, y; @@ -152,7 +152,6 @@ class cEETest : private cThread { void Screen4(); void Screen5(); - cZip * PAK; cZip * PakTest; std::vector tmpv;