diff --git a/include/eepp/graphics/cconsole.hpp b/include/eepp/graphics/cconsole.hpp index 5faa66528..666d185b2 100755 --- a/include/eepp/graphics/cconsole.hpp +++ b/include/eepp/graphics/cconsole.hpp @@ -219,7 +219,10 @@ class EE_API cConsole : protected iLogReader { void CmdShowFps( const std::vector < String >& params ); /** Internal Callback for default command ( gettexturememory ) */ - void CmdGetTextureMemory ( const std::vector < String >& params ); + void CmdGetTextureMemory( const std::vector < String >& params ); + + /** Internal Callback for default command ( hide ) */ + void CmdHideConsole( const std::vector < String >& params ); /** The Default Commands Callbacks for the Console ( don't call it ) */ void PrivInputCallback( InputEvent * Event ); diff --git a/include/eepp/graphics/cimage.hpp b/include/eepp/graphics/cimage.hpp index 064ad82ca..99fe6d9aa 100644 --- a/include/eepp/graphics/cimage.hpp +++ b/include/eepp/graphics/cimage.hpp @@ -58,11 +58,15 @@ class EE_API cImage { /** Create an empty image */ cImage( const Uint32& Width, const Uint32& Height, const Uint32& Channels, const eeColorA& DefaultColor = eeColorA(0,0,0,0) ); - /** Load an image from path */ - cImage( std::string Path ); + /** Load an image from path + * @param forceChannels Number of channels to use for the image, default 0 means that it use the default image channels. + */ + cImage( std::string Path, const eeUint& forceChannels = 0 ); - /** Load an image from pack */ - cImage( cPack * Pack, std::string FilePackPath ); + /** Load an image from pack + * @param forceChannels Number of channels to use for the image, default 0 means that it use the default image channels. + */ + cImage( cPack * Pack, std::string FilePackPath, const eeUint& forceChannels = 0 ); virtual ~cImage(); diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 3d7841231..f070aacc6 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/src/eepp/gaming/cmap.cpp b/src/eepp/gaming/cmap.cpp index 0677edac2..edfb09156 100644 --- a/src/eepp/gaming/cmap.cpp +++ b/src/eepp/gaming/cmap.cpp @@ -627,7 +627,7 @@ cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, c { cGameObjectPolyData& ObjData = GetPolyObjData( DataId ); - cGameObjectObject * tObject; + cGameObjectObject * tObject = NULL; if ( GAMEOBJECT_TYPE_OBJECT == Type ) { tObject = eeNew( cGameObjectObject, ( DataId, ObjData.Poly.ToAABB(), Layer, Flags ) ); @@ -637,9 +637,11 @@ cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, c tObject = eeNew( cGameObjectPolyline, ( DataId, ObjData.Poly, Layer, Flags ) ); } - tObject->Name( ObjData.Name ); - tObject->TypeName( ObjData.Type ); - tObject->SetProperties( ObjData.Properties ); + if ( NULL != tObject ) { + tObject->Name( ObjData.Name ); + tObject->TypeName( ObjData.Type ); + tObject->SetProperties( ObjData.Properties ); + } return tObject; } diff --git a/src/eepp/graphics/cconsole.cpp b/src/eepp/graphics/cconsole.cpp index ddfd942ca..8499f9559 100755 --- a/src/eepp/graphics/cconsole.cpp +++ b/src/eepp/graphics/cconsole.cpp @@ -128,7 +128,7 @@ void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const bool& mWidth = (eeFloat) mWindow->GetWidth(); mHeight = (eeFloat) mWindow->GetHeight(); - mHeightMin = (eeFloat) mWindow->GetHeight() * 0.4f; + mHeightMin = (eeFloat) mWindow->GetHeight() * 0.5f; if ( NULL != cEngine::ExistsSingleton() && cEngine::instance()->ExistsWindow( mWindow ) ) @@ -496,6 +496,7 @@ void cConsole::CreateDefaultCommands() { AddCommand( "ls", cb::Make1( this, &cConsole::CmdDir) ); AddCommand( "showfps", cb::Make1( this, &cConsole::CmdShowFps) ); AddCommand( "gettexturememory", cb::Make1( this, &cConsole::CmdGetTextureMemory) ); + AddCommand( "hide", cb::Make1( this, &cConsole::CmdHideConsole ) ); } void cConsole::CmdClear () { @@ -712,6 +713,10 @@ void cConsole::CmdShowFps( const std::vector < String >& params ) { PrivPushText( "Valid parameters are 0 ( hide ) or 1 ( show )." ); } +void cConsole::CmdHideConsole( const std::vector < String >& params ) { + FadeOut(); +} + void cConsole::IgnoreCharOnPrompt( const Uint32& ch ) { mTBuf->PushIgnoredChar( ch ); } diff --git a/src/eepp/graphics/cimage.cpp b/src/eepp/graphics/cimage.cpp index 1b46e8ff4..2478195f8 100644 --- a/src/eepp/graphics/cimage.cpp +++ b/src/eepp/graphics/cimage.cpp @@ -104,24 +104,26 @@ cImage::cImage( Uint8* data, const eeUint& Width, const eeUint& Height, const ee { } -cImage::cImage( std::string Path ) : +cImage::cImage( std::string Path, const eeUint& forceChannels ) : mPixels(NULL), mWidth(0), mHeight(0), - mChannels(0), + mChannels(forceChannels), mSize(0), mAvoidFree(false), mLoadedFromStbi(false) { int w, h, c; cPack * tPack = NULL; - Uint8 * data = stbi_load( Path.c_str(), &w, &h, &c, 0 ); + Uint8 * data = stbi_load( Path.c_str(), &w, &h, &c, mChannels ); if ( NULL != data ) { mPixels = data; mWidth = (eeUint)w; mHeight = (eeUint)h; - mChannels = (eeUint)c; + + if ( STBI_default == mChannels ) + mChannels = (eeUint)c; mSize = mWidth * mHeight * mChannels; @@ -139,11 +141,11 @@ cImage::cImage( std::string Path ) : } } -cImage::cImage( cPack * Pack, std::string FilePackPath ) : +cImage::cImage( cPack * Pack, std::string FilePackPath, const eeUint& forceChannels ) : mPixels(NULL), mWidth(0), mHeight(0), - mChannels(0), + mChannels(forceChannels), mSize(0), mAvoidFree(false), mLoadedFromStbi(false) @@ -163,13 +165,15 @@ void cImage::LoadFromPack( cPack * Pack, const std::string& FilePackPath ) { Pack->ExtractFileToMemory( FilePackPath, PData ); int w, h, c; - Uint8 * data = stbi_load_from_memory( PData.Data, PData.DataSize, &w, &h, &c, 0 ); + Uint8 * data = stbi_load_from_memory( PData.Data, PData.DataSize, &w, &h, &c, mChannels ); if ( NULL != data ) { mPixels = data; mWidth = (eeUint)w; mHeight = (eeUint)h; - mChannels = (eeUint)c; + + if ( STBI_default == mChannels ) + mChannels = (eeUint)c; mSize = mWidth * mHeight * mChannels; @@ -312,7 +316,9 @@ void cImage::ReplaceColor( const eeColorA& ColorKey, const eeColorA& NewColor ) if ( NULL == mPixels ) return; - for ( eeUint i = 0; i < mWidth * mHeight; i++ ) { + eeUint size = mWidth * mHeight; + + for ( eeUint i = 0; i < size; i++ ) { Pos = i * mChannels; if ( 4 == mChannels ) { @@ -354,8 +360,9 @@ void cImage::FillWithColor( const eeColorA& Color ) { return; eeUint z; + eeUint size = mWidth * mHeight; - for ( eeUint i = 0; i < mWidth * mHeight; i += mChannels ) { + for ( eeUint i = 0; i < size; i += mChannels ) { for ( z = 0; z < mChannels; z++ ) { if ( 0 == z ) mPixels[ i + z ] = Color.R(); diff --git a/src/eepp/graphics/csprite.cpp b/src/eepp/graphics/csprite.cpp index ebb85aa8a..63f9768b2 100755 --- a/src/eepp/graphics/csprite.cpp +++ b/src/eepp/graphics/csprite.cpp @@ -408,7 +408,7 @@ bool cSprite::AddSubFrame(const Uint32& TexId, const eeUint& NumFrame, const eeU if ( TexSector.Right > 0 && TexSector.Bottom > 0 ) S->SrcRect( TexSector ); else - S->SrcRect( eeRecti( 0, 0, (Int32)Tex->Width(), (Int32)Tex->Height() ) ); + S->SrcRect( eeRecti( 0, 0, (Int32)Tex->ImgWidth(), (Int32)Tex->ImgHeight() ) ); eeSizef destSize( DestSize ); diff --git a/src/eepp/graphics/csubtexture.cpp b/src/eepp/graphics/csubtexture.cpp index 0439ec4ef..b34629c9e 100644 --- a/src/eepp/graphics/csubtexture.cpp +++ b/src/eepp/graphics/csubtexture.cpp @@ -26,14 +26,10 @@ cSubTexture::cSubTexture( const Uint32& TexId, const std::string& Name ) : mId( String::Hash( mName ) ), mTexId( TexId ), mTexture( cTextureFactory::instance()->GetTexture( TexId ) ), - mSrcRect( eeRecti( 0, 0, NULL != mTexture ? mTexture->Width() : 0, NULL != mTexture ? mTexture->Height() : 0 ) ), + mSrcRect( eeRecti( 0, 0, NULL != mTexture ? mTexture->ImgWidth() : 0, NULL != mTexture ? mTexture->ImgHeight() : 0 ) ), mDestSize( (eeFloat)mSrcRect.Size().Width(), (eeFloat)mSrcRect.Size().Height() ), mOffset(0,0) { - if ( !GLi->IsExtension( EEGL_ARB_texture_non_power_of_two ) ) { - mSrcRect = eeRecti( 0, 0, mTexture->ImgWidth(), mTexture->ImgHeight() ); - } - CreateUnnamed(); } diff --git a/src/eepp/graphics/ctexturefactory.cpp b/src/eepp/graphics/ctexturefactory.cpp index d25716f62..cd3340726 100755 --- a/src/eepp/graphics/ctexturefactory.cpp +++ b/src/eepp/graphics/ctexturefactory.cpp @@ -65,8 +65,6 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& cTexture * Tex = NULL; Uint32 Pos; - eeInt MyWidth = ImgWidth; - eeInt MyHeight = ImgHeight; std::string FPath( Filepath ); @@ -75,7 +73,7 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& Pos = FindFreeSlot(); Tex = mTextures[ Pos ] = eeNew( cTexture, () ); - Tex->Create( TexId, Width, Height, MyWidth, MyHeight, Mipmap, Channels, FPath, ClampMode, CompressTexture, MemSize ); + Tex->Create( TexId, Width, Height, ImgWidth, ImgHeight, Mipmap, Channels, FPath, ClampMode, CompressTexture, MemSize ); Tex->Id( Pos ); if ( LocalCopy ) { @@ -83,7 +81,7 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& Tex->Unlock( true, false ); } - mMemSize += GetTexMemSize( Pos ); + mMemSize += MemSize; Unlock(); diff --git a/src/eepp/graphics/ctextureloader.cpp b/src/eepp/graphics/ctextureloader.cpp index c7b841325..18371573d 100644 --- a/src/eepp/graphics/ctextureloader.cpp +++ b/src/eepp/graphics/ctextureloader.cpp @@ -271,7 +271,7 @@ void cTextureLoader::LoadFromPath() { mIsCompressed = mDirectUpload = true; stbi_pkm_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels ); } else { - mPixels = stbi_load( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, STBI_default ); + mPixels = stbi_load( mFilepath.c_str(), &mImgWidth, &mImgHeight, &mChannels, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default ); } if ( NULL == mPixels ) { @@ -328,7 +328,7 @@ void cTextureLoader::LoadFromMemory() { stbi_pkm_info_from_memory( mPixels, mSize, &mImgWidth, &mImgHeight, &mChannels ); mIsCompressed = mDirectUpload = true; } else { - mPixels = stbi_load_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, STBI_default ); + mPixels = stbi_load_from_memory( mImagePtr, mSize, &mImgWidth, &mImgHeight, &mChannels, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default ); } if ( NULL == mPixels ) { @@ -385,7 +385,7 @@ void cTextureLoader::LoadFromStream() { mIsCompressed = mDirectUpload = true; } else { mStream->Seek( 0 ); - mPixels = stbi_load_from_callbacks( &callbacks, mStream, &mImgWidth, &mImgHeight, &mChannels, STBI_default ); + mPixels = stbi_load_from_callbacks( &callbacks, mStream, &mImgWidth, &mImgHeight, &mChannels, ( NULL != mColorKey ) ? STBI_rgb_alpha : STBI_default ); mStream->Seek( 0 ); } @@ -427,6 +427,18 @@ void cTextureLoader::LoadFromPixels() { tTexId = SOIL_direct_load_ETC1_from_memory( mPixels, mSize, SOIL_CREATE_NEW_ID, flags ); } } else { + if ( NULL != mColorKey ) { + mChannels = STBI_rgb_alpha; + + cImage * tImg = eeNew ( cImage, ( mPixels, mImgWidth, mImgHeight, mChannels ) ); + + tImg->CreateMaskFromColor( eeColorA( mColorKey->R(), mColorKey->G(), mColorKey->B(), 255 ), 0 ); + + tImg->AvoidFreeImage( true ); + + eeSAFE_DELETE( tImg ); + } + tTexId = SOIL_create_OGL_texture( mPixels, &width, &height, mChannels, SOIL_CREATE_NEW_ID, flags ); } @@ -446,12 +458,9 @@ void cTextureLoader::LoadFromPixels() { mSize = mWidth * mHeight * mChannels; } - mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mClampMode, mCompressTexture || mIsCompressed, mLocalCopy, mSize ); + mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, width, height, mImgWidth, mImgHeight, mMipmap, mChannels, mClampMode, mCompressTexture || mIsCompressed, mLocalCopy, mSize ); cLog::instance()->Write( "Texture " + mFilepath + " loaded in " + String::ToStr( mTE.Elapsed() ) + " ms." ); - - if ( NULL != mColorKey && 0 != mTexId ) - cTextureFactory::instance()->GetTexture( mTexId )->CreateMaskFromColor( eeColorA( mColorKey->R(), mColorKey->G(), mColorKey->B(), 255 ), 0 ); } else { cLog::instance()->Write( "Failed to create texture. Reason: " + std::string( SOIL_last_result() ) ); } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index a26234480..9dbe0bac9 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -475,6 +475,8 @@ void cEETest::CreateUI() { Menu->Add( "Show Screen 5" ); Menu->Add( "Show Screen 6" ); Menu->AddSeparator(); + Menu->Add( "Show Console" ); + Menu->AddSeparator(); Menu->AddCheckBox( "Show Window" ); Menu->Add( "Show Window 2" ); Menu->AddCheckBox( "Multi Viewport" ); @@ -681,6 +683,15 @@ void cEETest::ItemClick( const cUIEvent * Event ) { SetScreen( 4 ); } else if ( "Show Screen 6" == txt ) { SetScreen( 5 ); + } else if ( "Show Console" == txt ) { + Con.Toggle(); + InBuf.Active( !Con.Active() ); + + if ( Con.Active() ) { + mWindow->StartTextInput(); + } else { + mWindow->StopTextInput(); + } } else if ( "Show Window" == txt ) { cUIMenuCheckBox * Chk = reinterpret_cast ( Event->Ctrl() ); @@ -841,9 +852,15 @@ void cEETest::LoadTextures() { } Tiles[6] = SG->Add( TF->LoadFromPack( PAK, "objects/1.png" ), "7" ); - Tiles[7] = SG->Add( TF->LoadFromPack( PAK, "objects/2.png" ), "8" ); + #ifdef EE_GLES + cImage tImg( PAK, "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]->GetTexture()->CreateMaskFromColor( eeColorA(0,0,0,255), 0 ); + #endif } eeInt w, h; @@ -861,7 +878,7 @@ void cEETest::LoadTextures() { Con.AddCommand( "setparticlesnum", cb::Make1( this, &cEETest::CmdSetPartsNum ) ); - cTexture * Tex = TF->GetTexture( TN[2] ); + cTexture * Tex = TNP[2]; if ( NULL != Tex && Tex->Lock() ) { w = (eeInt)Tex->Width();