diff --git a/include/eepp/graphics/cconsole.hpp b/include/eepp/graphics/cconsole.hpp index 7185aa9b8..5a1e1b5d0 100755 --- a/include/eepp/graphics/cconsole.hpp +++ b/include/eepp/graphics/cconsole.hpp @@ -13,13 +13,15 @@ using namespace EE::Window; namespace EE { namespace Graphics { -class EE_API cConsole{ +class EE_API cConsole : protected iLogReader { public: //! The Console Callback return a vector of parameters ( String ) typedef cb::Callback1& > ConsoleCallback; cConsole( Window::cWindow * window = NULL ); + cConsole( cFont* Font, const bool& MakeDefaultCommands = true, const bool& AttachToLog = true, const eeUint& MaxLogLines = 1024, const Uint32& TextureId = 0, Window::cWindow * window = NULL ); + ~cConsole(); /** Set the Console Height when it's Minimized ( Not Maximized ) */ @@ -85,6 +87,7 @@ class EE_API cConsole{ /** Creates the new console * @param Font The cFont pointer to class * @param MakeDefaultCommands Register the default commands provided by the class? + * @param AttachToLog Attach the console to the cLog instance * @param MaxLogLines Maximun number of lines stored on the console * @param Background texture ( 0 if don't want a texture ) * @param ConsoleColor The Console Background Color @@ -92,7 +95,7 @@ class EE_API cConsole{ * @param FontColor The Console Font Color * @param FontLineColor The Console Line Font Color ( The Client Input ) */ - void Create( cFont* Font, const bool& MakeDefaultCommands = true, const eeUint& MaxLogLines = 1024, const Uint32& TextureId = 0 ); + void Create( cFont* Font, const bool& MakeDefaultCommands = true, const bool& AttachToLog = true, const eeUint& MaxLogLines = 1024, const Uint32& TextureId = 0 ); /** Add Text to Console */ void PushText( const String& str ); @@ -240,6 +243,8 @@ class EE_API cConsole{ void PrintCommandsStartingWith( const String& start ); void PrivVideoResize(); + + void WriteLog( const std::string& Text ); }; }} diff --git a/include/eepp/graphics/ctexturefont.hpp b/include/eepp/graphics/ctexturefont.hpp index c844d9cca..79b6c635d 100755 --- a/include/eepp/graphics/ctexturefont.hpp +++ b/include/eepp/graphics/ctexturefont.hpp @@ -10,6 +10,9 @@ namespace EE { namespace Graphics { /** @brief This class loads texture fonts and draw strings to the screen. */ class EE_API cTextureFont : public cFont { public: + /** Creates an instance of a texture font */ + static cTextureFont * New( const std::string FontName ); + cTextureFont( const std::string FontName ); /** The destructor will not unload the texture from memory. If you want that you'll have to remove it manually ( cTextureFactory::instance()->Remove( MyFontInstance->GetTexId() ) ). */ diff --git a/include/eepp/graphics/ctextureloader.hpp b/include/eepp/graphics/ctextureloader.hpp index 6a5771490..19fd9ad1d 100644 --- a/include/eepp/graphics/ctextureloader.hpp +++ b/include/eepp/graphics/ctextureloader.hpp @@ -64,6 +64,8 @@ class EE_API cTextureLoader : public cObjectLoader { bool mIsDDS; int mIsDDSCompressed; + cTimeElapsed mTE; + void LoadFromPath(); void LoadFromMemory(); void LoadFromPack(); diff --git a/include/eepp/graphics/cttffont.hpp b/include/eepp/graphics/cttffont.hpp index 81d5bc286..6632ad671 100755 --- a/include/eepp/graphics/cttffont.hpp +++ b/include/eepp/graphics/cttffont.hpp @@ -17,6 +17,8 @@ class EE_API cTTFFont : public cFont { /** Creates an instance of a true type font */ static cTTFFont * New( const std::string FontName ); + cTTFFont( const std::string FontName ); + /** The destructor will not unload the texture from memory. If you want that you'll have to remove it manually ( cTextureFactory::instance()->Remove( MyFontInstance->GetTexId() ) ). */ virtual ~cTTFFont(); @@ -92,8 +94,6 @@ class EE_API cTTFFont : public cFont { bool mThreadedLoading; bool mTexReady; - cTTFFont( const std::string FontName ); - bool ThreadedLoading() const; void ThreadedLoading( const bool& isThreaded ); diff --git a/include/eepp/system/clog.hpp b/include/eepp/system/clog.hpp index 94583ead5..f38a47d6c 100755 --- a/include/eepp/system/clog.hpp +++ b/include/eepp/system/clog.hpp @@ -1,6 +1,7 @@ #ifndef EECLOG_H #define EECLOG_H +#include #include #include #include @@ -9,13 +10,19 @@ namespace EE { namespace System { +/** @brief The reader interface is usefull if you want to keep track of what is write in the log, for example for a console. */ +class iLogReader { + public: + virtual void WriteLog( const std::string& Text ) = 0; +}; + class EE_API cLog : protected cMutex { SINGLETON_DECLARE_HEADERS(cLog) public: void Save(const std::string& filepath = "" ); - void Write(const std::string& Text, const bool& newLine = true); + void Write( std::string Text, const bool& newLine = true); void Writef( const char* format, ... ); @@ -29,20 +36,27 @@ class EE_API cLog : protected cMutex { void LiveWrite( const bool& lw ); + void AddLogReader( iLogReader * reader ); + + void RemoveLogReader( iLogReader * reader ); + ~cLog(); protected: cLog(); - private: - std::string mData; - std::string mFilePath; - bool mSave; - bool mConsoleOutput; - bool mLiveWrite; - cIOStreamFile * mFS; - void openfs(); + std::string mData; + std::string mFilePath; + bool mSave; + bool mConsoleOutput; + bool mLiveWrite; + cIOStreamFile * mFS; + std::list mReaders; - void closefs(); + void OpenFS(); + + void CloseFS(); + + void WriteToReaders( std::string& text ); }; }} diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 8118d4434..990d22ed6 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -48,7 +48,7 @@ Desktop Desktop {388e5431-b31b-42b3-b9ad-9002d279d75d} - 0 + 10 0 0 diff --git a/src/eepp/graphics/cconsole.cpp b/src/eepp/graphics/cconsole.cpp index 3f36da5e1..ddfd942ca 100755 --- a/src/eepp/graphics/cconsole.cpp +++ b/src/eepp/graphics/cconsole.cpp @@ -46,6 +46,42 @@ cConsole::cConsole( Window::cWindow * window ) : } } +cConsole::cConsole( cFont* Font, const bool& MakeDefaultCommands, const bool& AttachToLog, const eeUint& MaxLogLines, const Uint32& TextureId, Window::cWindow * window ) : + mWindow( window ), + mConColor(35, 47, 73, 230), + mConLineColor(55, 67, 93, 230), + mFontColor(153, 153, 179, 230), + mFontLineColor(255, 255, 255, 230), + mWidth(0), + mHeight(0), + mHeightMin(0), + mY(0.0f), + mA(0.0f), + mFadeSpeed(250.f), + mMyCallback(0), + mVidCb(0), + mMaxLogLines(1024), + mLastLogPos(0), + mTBuf( eeNew( cInputTextBuffer, () ) ), + mFont(NULL), + mTexId(0), + mCurAlpha(0), + mEnabled(false), + mVisible(false), + mFadeIn(false), + mFadeOut(false), + mExpand(false), + mFading(false), + mShowFps(false), + mCurSide(false) +{ + if ( NULL == mWindow ) { + mWindow = cEngine::instance()->GetCurrentWindow(); + } + + Create( Font, MakeDefaultCommands, AttachToLog, MaxLogLines, TextureId ); +} + cConsole::~cConsole() { mCallbacks.clear(); mCmdLog.clear(); @@ -61,9 +97,13 @@ cConsole::~cConsole() { } eeSAFE_DELETE( mTBuf ); + + if ( cLog::ExistsSingleton() ) { + cLog::instance()->RemoveLogReader( this ); + } } -void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUint& MaxLogLines, const Uint32& TextureId ) { +void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const bool& AttachToLog, const eeUint& MaxLogLines, const Uint32& TextureId ) { if ( NULL == mWindow ) { mWindow = cEngine::instance()->GetCurrentWindow(); } @@ -106,6 +146,10 @@ void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUin mCon.ConModif = 0; CmdGetLog(); + + if ( AttachToLog ) { + cLog::instance()->AddLogReader( this ); + } } void cConsole::AddCommand( const String& Command, ConsoleCallback CB ) { @@ -218,12 +262,12 @@ void cConsole::ProcessLine() { mLastCommands.pop_front(); if ( str.size() > 0 ) { - PushText( "> " + params[0] ); + PrivPushText( "> " + params[0] ); if ( mCallbacks.find( params[0] ) != mCallbacks.end() ) { mCallbacks[ params[0] ]( params ); } else { - PushText( "Unknown Command: '" + params[0] + "'" ); + PrivPushText( "Unknown Command: '" + params[0] + "'" ); } } mTBuf->Clear(); @@ -237,7 +281,15 @@ void cConsole::PrivPushText( const String& str ) { } void cConsole::PushText( const String& str ) { - PrivPushText( str ); + if ( std::string::npos != str.find_first_of( '\n' ) ) { + std::vector Strings = String::Split( String( str ) ); + + for ( Uint32 i = 0; i < Strings.size(); i++ ) { + PrivPushText( Strings[i] ); + } + } else { + PrivPushText( str ); + } } void cConsole::PushText( const char * format, ... ) { @@ -336,12 +388,12 @@ void cConsole::PrintCommandsStartingWith( const String& start ) { } if ( cmds.size() > 1 ) { - PushText( "> " + mTBuf->Buffer() ); + PrivPushText( "> " + mTBuf->Buffer() ); std::list::iterator ite; for ( ite = cmds.begin(); ite != cmds.end(); ite++ ) - PushText( (*ite) ); + PrivPushText( (*ite) ); } else if ( cmds.size() ) { mTBuf->Buffer( cmds.front() ); @@ -455,7 +507,7 @@ void cConsole::CmdClear () { } for (Uint16 i = 0; i < CutLines; i++ ) - PushText( "" ); + PrivPushText( "" ); } void cConsole::CmdClear ( const std::vector < String >& params ) { @@ -465,13 +517,13 @@ void cConsole::CmdClear ( const std::vector < String >& params ) { void cConsole::CmdMaximize ( const std::vector < String >& params ) { mExpand = true; mY = mHeight; - PushText( "Console Maximized" ); + PrivPushText( "Console Maximized" ); } void cConsole::CmdMinimize ( const std::vector < String >& params ) { mExpand = false; mY = mHeightMin; - PushText( "Console Minimized" ); + PrivPushText( "Console Minimized" ); } void cConsole::CmdQuit ( const std::vector < String >& params ) { @@ -479,13 +531,13 @@ void cConsole::CmdQuit ( const std::vector < String >& params ) { } void cConsole::CmdGetTextureMemory ( const std::vector < String >& params ) { - PushText( "Total texture memory used: " + FileSystem::SizeToString( cTextureFactory::instance()->MemorySize() ) ); + PrivPushText( "Total texture memory used: " + FileSystem::SizeToString( cTextureFactory::instance()->MemorySize() ) ); } void cConsole::CmdCmdList ( const std::vector < String >& params ) { std::map < String, ConsoleCallback >::iterator itr; for (itr = mCallbacks.begin(); itr != mCallbacks.end(); itr++) { - PushText( "\t" + itr->first ); + PrivPushText( "\t" + itr->first ); } } @@ -497,11 +549,11 @@ void cConsole::CmdShowCursor ( const std::vector < String >& params ) { if ( Res && ( tInt == 0 || tInt == 1 ) ) { mWindow->GetCursorManager()->Visible( 0 != tInt ); - PushText( "showcursor " + String::ToStr( tInt ) ); + PrivPushText( "showcursor " + String::ToStr( tInt ) ); } else - PushText( "Valid parameters are 0 or 1." ); + PrivPushText( "Valid parameters are 0 or 1." ); } else { - PushText( "No parameters. Valid parameters are 0 ( hide ) or 1 ( show )." ); + PrivPushText( "No parameters. Valid parameters are 0 ( hide ) or 1 ( show )." ); } } @@ -513,19 +565,19 @@ void cConsole::CmdFrameLimit ( const std::vector < String >& params ) { if ( Res && ( tInt >= 0 && tInt <= 10000 ) ) { mWindow->FrameRateLimit( tInt ); - PushText( "setfpslimit " + String::ToStr( tInt ) ); + PrivPushText( "setfpslimit " + String::ToStr( tInt ) ); return; } } - PushText( "Valid parameters are between 0 and 10000 (0 = no limit)." ); + PrivPushText( "Valid parameters are between 0 and 10000 (0 = no limit)." ); } void cConsole::CmdGetLog() { std::vector < String > tvec = String::Split( String( String::ToStr( cLog::instance()->Buffer() ) ) ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) - PushText( tvec[i] ); + PrivPushText( tvec[i] ); } } @@ -538,7 +590,7 @@ void cConsole::CmdGetGpuExtensions() { std::vector < String > tvec = String::Split( String( String::ToStr( std::string( Exts ) ) ), ' ' ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) - PushText( tvec[i] ); + PrivPushText( tvec[i] ); } } @@ -554,12 +606,12 @@ void cConsole::CmdSetGamma( const std::vector < String >& params ) { if ( Res && ( tFloat > 0.1f && tFloat <= 10.0f ) ) { mWindow->SetGamma( tFloat, tFloat, tFloat ); - PushText( "setgamma " + String::ToStr( tFloat ) ); + PrivPushText( "setgamma " + String::ToStr( tFloat ) ); return; } } - PushText( "Valid parameters are between 0.1 and 10." ); + PrivPushText( "Valid parameters are between 0.1 and 10." ); } void cConsole::CmdSetVolume( const std::vector < String >& params ) { @@ -570,21 +622,17 @@ void cConsole::CmdSetVolume( const std::vector < String >& params ) { if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) { EE::Audio::cAudioListener::GlobalVolume( tFloat ); - PushText( "setvolume " + String::ToStr( tFloat ) ); + PrivPushText( "setvolume " + String::ToStr( tFloat ) ); return; } } - PushText( "Valid parameters are between 0 and 100." ); + PrivPushText( "Valid parameters are between 0 and 100." ); } void cConsole::CmdDir( const std::vector < String >& params ) { if ( params.size() >= 2 ) { - #if EE_PLATFORM == EE_PLATFORM_WIN - String Slash( "/\\" ); - #else - String Slash( "/" ); - #endif + String Slash( FileSystem::GetOSlash() ); String myPath = params[1]; String myOrder; @@ -607,7 +655,7 @@ void cConsole::CmdDir( const std::vector < String >& params ) { std::vector mFiles = FileSystem::FilesGetInPath( myPath ); std::sort( mFiles.begin(), mFiles.end() ); - PushText( "Directory: " + myPath ); + PrivPushText( "Directory: " + myPath ); if ( myOrder == "ff" ) { std::vector mFolders; @@ -622,29 +670,29 @@ void cConsole::CmdDir( const std::vector < String >& params ) { } if ( mFolders.size() ) - PushText( "Folders: " ); + PrivPushText( "Folders: " ); for ( i = 0; i < mFolders.size(); i++ ) - PushText( " " + mFolders[i] ); + PrivPushText( " " + mFolders[i] ); if ( mFolders.size() ) - PushText( "Files: " ); + PrivPushText( "Files: " ); for ( i = 0; i < mFile.size(); i++ ) - PushText( " " + mFile[i] ); + PrivPushText( " " + mFile[i] ); } else { for ( i = 0; i < mFiles.size(); i++ ) - PushText( " " + mFiles[i] ); + PrivPushText( " " + mFiles[i] ); } } else { if ( myPath == "help" ) - PushText( "You can use a third parameter to show folders first, the parameter is ff." ); + PrivPushText( "You can use a third parameter to show folders first, the parameter is ff." ); else - PushText( "Path is not a directory." ); + PrivPushText( "Path is not a directory." ); } } else { - PushText( "Expected a path to list. Example of usage: ls /home" ); + PrivPushText( "Expected a path to list. Example of usage: ls /home" ); } } @@ -656,12 +704,12 @@ void cConsole::CmdShowFps( const std::vector < String >& params ) { if ( Res && ( tInt == 0 || tInt == 1 ) ) { mShowFps = 0 != tInt; - PushText( "showfps " + String::ToStr( tInt ) ); + PrivPushText( "showfps " + String::ToStr( tInt ) ); return; } } - PushText( "Valid parameters are 0 ( hide ) or 1 ( show )." ); + PrivPushText( "Valid parameters are 0 ( hide ) or 1 ( show )." ); } void cConsole::IgnoreCharOnPrompt( const Uint32& ch ) { @@ -676,4 +724,12 @@ void cConsole::ShowFps( const bool& Show ) { mShowFps = Show; } +void cConsole::WriteLog( const std::string& Text ) { + std::vector Strings = String::Split( String( Text ) ); + + for ( Uint32 i = 0; i < Strings.size(); i++ ) { + PrivPushText( Strings[i] ); + } +} + }} diff --git a/src/eepp/graphics/ctexturefactory.cpp b/src/eepp/graphics/ctexturefactory.cpp index e6fdc0f48..d25716f62 100755 --- a/src/eepp/graphics/ctexturefactory.cpp +++ b/src/eepp/graphics/ctexturefactory.cpp @@ -87,8 +87,6 @@ Uint32 cTextureFactory::PushTexture( const std::string& Filepath, const Uint32& Unlock(); - cLog::instance()->Write( "Texture " + Filepath + " loaded." ); - return Pos; } diff --git a/src/eepp/graphics/ctexturefont.cpp b/src/eepp/graphics/ctexturefont.cpp index 7f755efcc..99587b953 100755 --- a/src/eepp/graphics/ctexturefont.cpp +++ b/src/eepp/graphics/ctexturefont.cpp @@ -5,6 +5,10 @@ namespace EE { namespace Graphics { +cTextureFont * cTextureFont::New( const std::string FontName ) { + return eeNew( cTextureFont, ( FontName ) ); +} + cTextureFont::cTextureFont( const std::string FontName ) : cFont( FONT_TYPE_TEX, FontName ), mStartChar(0), diff --git a/src/eepp/graphics/ctextureloader.cpp b/src/eepp/graphics/ctextureloader.cpp index 82de9d939..01b4ac98d 100644 --- a/src/eepp/graphics/ctextureloader.cpp +++ b/src/eepp/graphics/ctextureloader.cpp @@ -220,6 +220,8 @@ cTextureLoader::~cTextureLoader() { void cTextureLoader::Start() { cObjectLoader::Start(); + mTE.Reset(); + if ( TEX_LT_PATH == mLoadType ) LoadFromPath(); else if ( TEX_LT_MEM == mLoadType ) @@ -389,6 +391,8 @@ void cTextureLoader::LoadFromPixels() { mTexId = cTextureFactory::instance()->PushTexture( mFilepath, tTexId, mImgWidth, mImgHeight, width, height, mMipmap, mChannels, mClampMode, mCompressTexture || mIsDDSCompressed, 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 { diff --git a/src/eepp/system/clog.cpp b/src/eepp/system/clog.cpp index da89da1f0..808b0c599 100755 --- a/src/eepp/system/clog.cpp +++ b/src/eepp/system/clog.cpp @@ -25,12 +25,12 @@ cLog::~cLog() { Write( "...::: Entropia Engine++ Unloaded :::...\n" ); if ( mSave && !mLiveWrite ) { - openfs(); + OpenFS(); mFS->Write( mData.c_str(), mData.size() ); } - closefs(); + CloseFS(); } void cLog::Save( const std::string& filepath ) { @@ -43,48 +43,38 @@ void cLog::Save( const std::string& filepath ) { mSave = true; } -void cLog::Write( const std::string& Text, const bool& newLine ) { +void cLog::Write( std::string Text, const bool& newLine ) { + if ( newLine ) { + Text += '\n'; + } + mData += Text; - if ( newLine ) { - mData += '\n'; - } - + WriteToReaders( Text ); + if ( mConsoleOutput ) { #if EE_PLATFORM == EE_PLATFORM_ANDROID - if ( newLine ) { - ANDROID_LOGI( ( Text + std::string( "\n" ) ).c_str() ); - } else { - ANDROID_LOGI( Text.c_str() ); - } + ANDROID_LOGI( Text.c_str() ); #else - if ( newLine ) { - std::cout << Text << std::endl; - } else { - std::cout << Text; - } + std::cout << Text; #endif } if ( mLiveWrite ) { - openfs(); + OpenFS(); mFS->Write( Text.c_str(), Text.size() ); - if ( newLine ) { - mFS->Write( "\n", 1 ); - } - mFS->Flush(); } } -void cLog::openfs() { +void cLog::OpenFS() { if ( mFilePath.empty() ) { mFilePath = Sys::GetProcessPath(); } - closefs(); + CloseFS(); if ( NULL == mFS ) { std::string str = mFilePath + "log.log"; @@ -93,7 +83,7 @@ void cLog::openfs() { } } -void cLog::closefs() { +void cLog::CloseFS() { Lock(); eeSAFE_DELETE( mFS ); @@ -114,21 +104,22 @@ void cLog::Writef( const char* format, ... ) { if ( n > -1 && n < size ) { tstr.resize( n ); + tstr += '\n'; - mData += tstr + '\n'; + mData += tstr; + + WriteToReaders( tstr ); if ( mConsoleOutput ) { #if EE_PLATFORM != EE_PLATFORM_ANDROID - std::cout << tstr << std::endl; + std::cout << tstr; #else - ANDROID_LOGI( ( tstr + std::string( "\n" ) ).c_str() ); + ANDROID_LOGI( tstr.c_str() ); #endif } if ( mLiveWrite ) { - openfs(); - - tstr += '\n'; + OpenFS(); mFS->Write( tstr.c_str(), tstr.size() ); @@ -176,4 +167,18 @@ void cLog::LiveWrite( const bool& lw ) { mLiveWrite = lw; } +void cLog::AddLogReader( iLogReader * reader ) { + mReaders.push_back( reader ); +} + +void cLog::RemoveLogReader( iLogReader * reader ) { + mReaders.remove( reader ); +} + +void cLog::WriteToReaders( std::string& text ) { + for ( std::list::iterator it = mReaders.begin(); it != mReaders.end(); it++ ) { + (*it)->WriteLog( text ); + } +} + }}