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.
This commit is contained in:
Martín Lucas Golini
2013-05-29 14:34:42 -03:00
parent 1517278451
commit bfb58a9f40
20 changed files with 366 additions and 79 deletions

View File

@@ -17,6 +17,7 @@ syntax: glob
./eeew*
./eetest*
./eesound*
./eesprite*
./docs
ee.tag
log.log

View File

@@ -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.

View File

@@ -7,13 +7,14 @@
using namespace EE::Math;
#include <eepp/system/colors.hpp>
#include <eepp/system/clog.hpp>
#include <eepp/system/cpack.hpp>
#include <eepp/system/cpackmanager.hpp>
using namespace EE::System;
#include <eepp/graphics/renders.hpp>
namespace EE { namespace System {
class cPack;
}}
namespace EE { namespace Graphics {
/** @brief A simple image class to manipulate them. */

View File

@@ -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 );
};
}}

View File

@@ -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" )

View File

@@ -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 )

View File

@@ -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

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 2.7.1, 2013-05-29T01:12:21. -->
<!-- Written by QtCreator 2.7.1, 2013-05-29T14:28:55. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -48,9 +48,9 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">{388e5431-b31b-42b3-b9ad-9002d279d75d}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">15</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">7</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory">/home/programming/eepp/make/linux</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
@@ -349,6 +349,46 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">debug-sound</value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.15">
<value type="QString" key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory">/home/programming/eepp/make/linux</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets"/>
<value type="bool" key="GenericProjectManager.GenericMakeStep.Clean">false</value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeArguments">-j4 eepp-sprites</value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand">make</value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">clean</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">make</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{buildDir}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Process Step</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.ProcessStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">debug-test</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">debug-sprites</value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="QString" key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory">/home/programming/eepp/make/linux</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
@@ -669,7 +709,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">release-es</value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">15</value>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">16</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
@@ -1013,7 +1053,54 @@
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">7</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.7">
<value type="bool" key="Analyzer.Project.UseGlobal">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">0</value>
<value type="int">1</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">11</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">14</value>
</valuelist>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
<value type="int" key="ProjectExplorer.CustomExecutableRunConfiguration.BaseEnvironmentBase">2</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/home/programming/eepp/eesprites-debug</value>
<value type="bool" key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.CustomExecutableRunConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /home/programming/eepp/eesprites-debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">eesprites-debug</value>
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">8</value>
</valuemap>
</data>
<data>

View File

@@ -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

View File

@@ -1,4 +1,7 @@
#include <eepp/graphics/cimage.hpp>
#include <eepp/system/clog.hpp>
#include <eepp/system/cpack.hpp>
#include <eepp/system/cpackmanager.hpp>
#include <eepp/helper/SOIL2/src/SOIL2/image_helper.h>
#include <eepp/helper/SOIL2/src/SOIL2/stb_image.h>
#include <eepp/helper/SOIL2/src/SOIL2/SOIL2.h>

View File

@@ -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 );
}
}

View File

@@ -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;
}

View File

@@ -11,6 +11,7 @@ cInterpolation::cInterpolation() :
mLoop(false),
mEnded(false),
mTotDist(0.f),
mCurPos(0.f),
mCurPoint(0),
mCurTime(0),
mSpeed(1.3f),

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,160 @@
#include <eepp/ee.hpp>
// 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<cInterpolation*>( 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;
}

View File

@@ -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();

View File

@@ -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<Uint8> tmpv;