From 636e4a8b42b8eaa46af2dc616b81bc3d81154654 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Tue, 27 Jan 2009 16:40:06 +0000 Subject: [PATCH] Fixed a speed bottleneck introduced in r643, which required retooling the way the Console::Write API passes parameters. The C++ compiler doesn't optimize const string objects very well, which was leading to a lot of redundancy object creation and exception handling. git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@644 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/Console.cpp | 47 ++++++++++++------------------- pcsx2/DebugTools/DisR5900.cpp | 2 +- pcsx2/DebugTools/DisR5900asm.cpp | 2 +- pcsx2/Elfheader.cpp | 2 +- pcsx2/Exceptions.h | 1 + pcsx2/Hw.cpp | 6 ++-- pcsx2/Memory.cpp | 4 +-- pcsx2/Misc.cpp | 10 ++++--- pcsx2/SaveState.cpp | 2 +- pcsx2/StringUtils.h | 11 ++++---- pcsx2/System.cpp | 28 ++++++++++-------- pcsx2/System.h | 40 +++++++++++++------------- pcsx2/vssprintf.cpp | 35 ++++++++++++++--------- pcsx2/windows/ConfigDlg.cpp | 2 +- pcsx2/windows/WinConsole.cpp | 17 +++++------ pcsx2/windows/WinMain.cpp | 14 ++++++--- pcsx2/windows/WinSysExec.cpp | 22 +++++++-------- pcsx2/windows/ini.cpp | 2 +- pcsx2/x86/ix86/ix86_cpudetect.cpp | 4 +-- 19 files changed, 131 insertions(+), 120 deletions(-) diff --git a/pcsx2/Console.cpp b/pcsx2/Console.cpp index cb7c2af65e..6abcbde6ec 100644 --- a/pcsx2/Console.cpp +++ b/pcsx2/Console.cpp @@ -30,31 +30,26 @@ const _VARG_PARAM va_arg_dummy = { 0 }; namespace Console { - static __forceinline void __fastcall _WriteLn( Colors color, const string& fmt, va_list args ) + static __forceinline void __fastcall _WriteLn( Colors color, const char* fmt, va_list args ) { - string dest; - vssprintf( dest, fmt, args); SetColor( color ); - WriteLn( dest ); + WriteLn( vfmt_string( fmt, args ).c_str() ); ClearColor(); } - bool Write( const string& fmt, VARG_PARAM dummy, ... ) + bool Write( const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); - string dest; - va_list list; va_start(list,dummy); - vssprintf( dest, fmt, list); + WriteLn( vfmt_string( fmt, list ).c_str() ); va_end(list); - WriteLn( dest ); return false; } - bool Write( Colors color, const string& fmt ) + bool Write( Colors color, const char* fmt ) { SetColor( color ); Write( fmt ); @@ -62,39 +57,33 @@ namespace Console return false; } - bool Write( Colors color, const string& fmt, VARG_PARAM dummy, ... ) + bool Write( Colors color, const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); - string dest; - va_list list; va_start(list,dummy); - vssprintf( dest, fmt, list); + Write( vfmt_string( fmt, list ).c_str() ); va_end(list); - Write( dest ); return false; } - bool WriteLn( const string& fmt, VARG_PARAM dummy, ... ) + bool WriteLn( const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); - string dest; - va_list list; va_start(list,dummy); - vssprintf( dest, fmt, list); + WriteLn( vfmt_string( fmt, list).c_str() ); va_end(list); - WriteLn( dest ); return false; } // Writes an unformatted string of text to the console (fast!) // A newline is automatically appended. - __forceinline bool __fastcall WriteLn( const string& fmt ) + __forceinline bool __fastcall WriteLn( const char* fmt ) { Write( fmt ); Newline(); @@ -103,7 +92,7 @@ namespace Console // Writes an unformatted string of text to the console (fast!) // A newline is automatically appended. - __forceinline bool __fastcall WriteLn( Colors color, const string& fmt ) + __forceinline bool __fastcall WriteLn( Colors color, const char* fmt ) { Write( color, fmt ); Newline(); @@ -111,7 +100,7 @@ namespace Console } // Writes a line of colored text to the console, with automatic newline appendage. - bool WriteLn( Colors color, const string& fmt, VARG_PARAM dummy, ... ) + bool WriteLn( Colors color, const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); @@ -124,7 +113,7 @@ namespace Console // Displays a message in the console with red emphasis. // Newline is automatically appended. - bool Error( const string& fmt, VARG_PARAM dummy, ... ) + bool Error( const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); @@ -137,7 +126,7 @@ namespace Console // Displays a message in the console with yellow emphasis. // Newline is automatically appended. - bool Notice( const string& fmt, VARG_PARAM dummy, ... ) + bool Notice( const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); @@ -151,7 +140,7 @@ namespace Console // Displays a message in the console with green emphasis. // Newline is automatically appended. - bool Status( const string& fmt, VARG_PARAM dummy, ... ) + bool Status( const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); @@ -164,7 +153,7 @@ namespace Console // Displays a message in the console with red emphasis. // Newline is automatically appended. - bool Error( const string& fmt ) + bool Error( const char* fmt ) { WriteLn( Color_Red, fmt ); return false; @@ -172,7 +161,7 @@ namespace Console // Displays a message in the console with yellow emphasis. // Newline is automatically appended. - bool Notice( const string& fmt ) + bool Notice( const char* fmt ) { WriteLn( Color_Yellow, fmt ); return false; @@ -180,7 +169,7 @@ namespace Console // Displays a message in the console with green emphasis. // Newline is automatically appended. - bool Status( const string& fmt ) + bool Status( const char* fmt ) { WriteLn( Color_Green, fmt ); return false; diff --git a/pcsx2/DebugTools/DisR5900.cpp b/pcsx2/DebugTools/DisR5900.cpp index e8caa5ad0e..56f7df0fcc 100644 --- a/pcsx2/DebugTools/DisR5900.cpp +++ b/pcsx2/DebugTools/DisR5900.cpp @@ -76,7 +76,7 @@ typedef void (*TdisR5900F)DisFInterface; // These macros are used to assemble the disassembler functions #define MakeDisF(fn, b) \ void fn DisFInterface { \ - ssprintf(output, "(%8.8x) ", params code); \ + ssprintf(output, "(%8.8x) ", code); \ b; \ } diff --git a/pcsx2/DebugTools/DisR5900asm.cpp b/pcsx2/DebugTools/DisR5900asm.cpp index 2067cf1537..0a62e1abf5 100644 --- a/pcsx2/DebugTools/DisR5900asm.cpp +++ b/pcsx2/DebugTools/DisR5900asm.cpp @@ -651,7 +651,7 @@ void P_COP2_Unknown( string& output ) void label_decode( string& output, u32 addr ) { string buf; - ssprintf(buf, "0x%08X",params addr); + ssprintf(buf, "0x%08X", addr); const char* label = disR5900GetSym( addr ); if( label != NULL ) diff --git a/pcsx2/Elfheader.cpp b/pcsx2/Elfheader.cpp index 41a2419600..e977a02cb2 100644 --- a/pcsx2/Elfheader.cpp +++ b/pcsx2/Elfheader.cpp @@ -539,7 +539,7 @@ int loadElfFile(const char *filename) { if( filename == NULL || filename[0] == 0 ) { - Console::Notice( "Running the PS2 BIOS...", params filename ); + Console::Notice( "Running the PS2 BIOS..." ); return -1; } diff --git a/pcsx2/Exceptions.h b/pcsx2/Exceptions.h index 2812a7a0a2..a12aa2b177 100644 --- a/pcsx2/Exceptions.h +++ b/pcsx2/Exceptions.h @@ -76,6 +76,7 @@ namespace Exception {} const std::string& Message() const { return m_message; } + const char* cMessage() const { return m_message.c_str(); } }; class RuntimeError : public BaseException diff --git a/pcsx2/Hw.cpp b/pcsx2/Hw.cpp index 25f757324c..b626a4448e 100644 --- a/pcsx2/Hw.cpp +++ b/pcsx2/Hw.cpp @@ -183,7 +183,7 @@ __forceinline u32 hwRead32(u32 mem) case 0x10001810: return (u16)counters[3].modeval; case 0x10001820: return (u16)counters[3].target; -//#ifdef PCSX2_DEVBUILD +#ifdef PCSX2_DEVBUILD case 0x1000A000: //dma2 chcr HW_LOG("Hardware read DMA2_CHCR 32bit at %lx, ret %lx\n", mem, psHu32(mem)); return psHu32(mem); @@ -220,7 +220,7 @@ __forceinline u32 hwRead32(u32 mem) case 0x1000f010: // INTC_MASK HW_LOG("INTC_MASK Read 32bit %x\n", psHu32(0xf010)); return psHu32(0xf010); -//#endif +#endif case 0x1000f130: case 0x1000f260:// SIF? @@ -292,7 +292,7 @@ __forceinline u32 hwRead32(u32 mem) if (mem < 0x10010000) return psHu32(mem); else - Console::Notice("*PCSX2* 32bit HW read of invalid address 0x%x\n", params mem); + Console::Notice("*PCSX2* 32bit HW read of invalid address 0x%x", params mem); return 0; } diff --git a/pcsx2/Memory.cpp b/pcsx2/Memory.cpp index ea17cf34af..68941f5d0d 100644 --- a/pcsx2/Memory.cpp +++ b/pcsx2/Memory.cpp @@ -101,7 +101,7 @@ void loadBiosRom( const char *ext, u8 *dest, long maxSize ) Path::Combine( Bios, Config.BiosDir, Config.Bios ); // Try first a basic extension concatenation (normally results in something like name.bin.rom1) - ssprintf(Bios1, "%hs.%s", params &Bios, ext); + ssprintf(Bios1, "%hs.%s", &Bios, ext); if( (filesize=Path::getFileSize( Bios1 ) ) <= 0 ) { // Try the name properly extensioned next (name.rom1) @@ -542,7 +542,7 @@ template void __fastcall vuMicroWrite64(u32 addr,const mem64_t* data) { addr&=(vunum==0)?0xfff:0x3fff; - VURegs* vu=(vunum==0)?&VU0:&VU1;; + VURegs* vu=(vunum==0)?&VU0:&VU1; if (*(u64*)&vu->Micro[addr]!=data[0]) { diff --git a/pcsx2/Misc.cpp b/pcsx2/Misc.cpp index 337ce75b75..414e7864f4 100644 --- a/pcsx2/Misc.cpp +++ b/pcsx2/Misc.cpp @@ -384,7 +384,9 @@ void SaveGSState(const string& file) { if( g_SaveGSStream ) return; - Console::WriteLn( _("Saving GS State...") + file ); + Console::WriteLn( _("Saving GS State...") ); + Console::WriteLn( "\t%hs", params file ); + g_fGSSave = new gzSavingState( file ); g_SaveGSStream = 1; @@ -507,7 +509,7 @@ char* mystrlwr( char* string ) static void GetGSStateFilename( string& dest ) { string gsText; - ssprintf( gsText, "/%8.8X.%d.gs",params ElfCRC, StatesC); + ssprintf( gsText, "/%8.8X.%d.gs", ElfCRC, StatesC); Path::Combine( dest, SSTATES_DIR, gsText ); } @@ -571,7 +573,7 @@ void ProcessFKeys(int fkey, int shift) // to be aborted. Sorry user! We'll give you some info for your trouble: Console::Error( _("An error occured while trying to load saveslot %d"), params StatesC ); - Console::Error( ex.Message() ); + Console::Error( ex.cMessage() ); Msgbox::Alert( "Pcsx2 encountered an error while trying to load the savestate\n" "and emulation had to be aborted." ); @@ -674,7 +676,7 @@ void ProcessFKeys(int fkey, int shift) tok = strtok(NULL, " "); if( tok != NULL ) strcat(name, tok); - ssprintf( gsText, "%s.%d.gs", params name, StatesC); + ssprintf( gsText, "%s.%d.gs", name, StatesC); Path::Combine( Text, SSTATES_DIR, gsText ); } else diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index bcc1b5cfbd..83c7f644ae 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -73,7 +73,7 @@ static void PostLoadPrep() void SaveState::GetFilename( string& dest, int slot ) { string elfcrcText; - ssprintf( elfcrcText, "%8.8X.%3.3d", params ElfCRC, slot ); + ssprintf( elfcrcText, "%8.8X.%3.3d", ElfCRC, slot ); Path::Combine( dest, SSTATES_DIR, elfcrcText ); } diff --git a/pcsx2/StringUtils.h b/pcsx2/StringUtils.h index 23f605b607..d9707ed59b 100644 --- a/pcsx2/StringUtils.h +++ b/pcsx2/StringUtils.h @@ -65,10 +65,11 @@ typedef _VARG_PARAM const * VARG_PARAM; extern const _VARG_PARAM va_arg_dummy; -extern void ssprintf(std::string& dest, const std::string& fmt, VARG_PARAM dummy, ...); -extern void ssappendf( std::string& dest, const std::string& format, VARG_PARAM dummy, ...); -extern void vssprintf(std::string& dest, const std::string& format, va_list args); -extern void vssappendf(std::string& dest, const std::string& format, va_list args); +extern void ssprintf(std::string& dest, const char* fmt, ...); +extern void ssappendf( std::string& dest, const char* format, ...); +extern void vssprintf(std::string& dest, const char* format, va_list args); +extern void vssappendf(std::string& dest, const char* format, va_list args); -extern std::string fmt_string( const std::string& fmt, VARG_PARAM dummy, ... ); +extern std::string fmt_string( const char* fmt, ... ); +extern std::string vfmt_string( const char* fmt, va_list args ); #endif diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp index 3f2be42203..b23d68bc57 100644 --- a/pcsx2/System.cpp +++ b/pcsx2/System.cpp @@ -98,10 +98,10 @@ void SysDetect() if( sysInitialized ) return; sysInitialized = true; - Notice("PCSX2 " PCSX2_VERSION " - compiled on " __DATE__ ); + Notice("PCSX2 " PCSX2_VERSION " - compiled on %s", params __DATE__ ); Notice("Savestate version: %x", params g_SaveVersion); - // fixme: what's the point of this line? Anything? Or just to look "cool"? (air) + // fixme: This line is here for the purpose of creating external ASM code. Yah. >_< DevCon::Notice( "EE pc offset: 0x%x, IOP pc offset: 0x%x", params (u32)&cpuRegs.pc - (u32)&cpuRegs, (u32)&psxRegs.pc - (u32)&psxRegs ); cpudetectInit(); @@ -176,7 +176,7 @@ bool SysAllocateMem() // the VTLB build instead. If it's the VTLB build then ... ouch. #ifdef PCSX2_VIRTUAL_MEM - Console::Error( ex.Message() ); + Console::Error( ex.cMessage() ); if( MessageBox(NULL, "Failed to allocate enough physical memory to run pcsx2. Try closing\n" "down background programs, restarting windows, or buying more memory.\n\n" @@ -204,7 +204,7 @@ bool SysAllocateMem() } #else // VTLB build must fail outright... - Msgbox::Alert( "Failed to allocate memory needed to run pcsx2.\n\nError: " + ex.Message() ); + Msgbox::Alert( "Failed to allocate memory needed to run pcsx2.\n\nError: %s", params ex.cMessage() ); #endif SysShutdownMem(); @@ -215,7 +215,7 @@ bool SysAllocateMem() } -// Allocates memory for all recompilers,a nd force-disables any recs that fail to initialize. +// Allocates memory for all recompilers, and force-disables any recs that fail to initialize. // This should be done asap, since the recompilers tend to demand a lot of system resources, and prefer // to have those resources at specific address ranges. The sooner memory is allocated, the better. // Returns FALSE on *critical* failure (GUI should issue a msg and exit). @@ -234,8 +234,10 @@ void SysAllocateDynarecs() catch( Exception::BaseException& ex ) { Msgbox::Alert( - "The EE/IOP recompiler failed to initialize with the following error:\n\n" + ex.Message() + - "\n\nThe EE/IOP interpreter will be used instead (slow!)." + "The EE/IOP recompiler failed to initialize with the following error:\n\n" + "%s" + "\n\nThe EE/IOP interpreter will be used instead (slow!).", params + ex.cMessage() ); g_Session.ForceDisableEErec = true; @@ -251,8 +253,10 @@ void SysAllocateDynarecs() catch( Exception::BaseException& ex ) { Msgbox::Alert( - "The VU0 recompiler failed to initialize with the following error:\n\n" + ex.Message() + - "\n\nThe VU0 interpreter will be used for this session (may slow down some games)." + "The VU0 recompiler failed to initialize with the following error:\n\n" + "%s" + "\n\nThe VU0 interpreter will be used for this session (may slow down some games).", params + ex.cMessage() ); g_Session.ForceDisableVU0rec = true; @@ -266,8 +270,10 @@ void SysAllocateDynarecs() catch( Exception::BaseException& ex ) { Msgbox::Alert( - "The VU1 recompiler failed to initialize with the following error:\n\n" + ex.Message() + - "\n\nThe VU1 interpreter will be used for this session (will slow down most games)." + "The VU1 recompiler failed to initialize with the following error:\n\n" + "%s" + "\n\nThe VU1 interpreter will be used for this session (will slow down most games).", params + ex.cMessage() ); g_Session.ForceDisableVU1rec = true; diff --git a/pcsx2/System.h b/pcsx2/System.h index 769b4ca837..220c7ac1f9 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -84,7 +84,7 @@ namespace Console }; // va_args version of WriteLn, mostly for internal use only. - extern void __fastcall _WriteLn( Colors color, const std::string& fmt, va_list args ); + extern void __fastcall _WriteLn( Colors color, const char* fmt, va_list args ); extern void Open(); extern void Close(); @@ -106,61 +106,61 @@ namespace Console // Writes an unformatted string of text to the console (fast!) // No newline is appended. - extern bool __fastcall Write( const std::string& fmt ); + extern bool __fastcall Write( const char* fmt ); // Writes an unformatted string of text to the console (fast!) // A newline is automatically appended. - extern bool __fastcall WriteLn( const std::string& fmt ); + extern bool __fastcall WriteLn( const char* fmt ); // Writes an unformatted string of text to the console (fast!) // A newline is automatically appended, and the console color reset to default. - extern bool __fastcall WriteLn( Colors color, const std::string& fmt ); + extern bool __fastcall WriteLn( Colors color, const char* fmt ); // Writes a line of colored text to the console, with automatic newline appendage. // The console color is reset to default when the operation is complete. - extern bool WriteLn( Colors color, const std::string& fmt, VARG_PARAM dummy, ... ); + extern bool WriteLn( Colors color, const char* fmt, VARG_PARAM dummy, ... ); // Writes a line of colored text to the console (no newline). // The console color is reset to default when the operation is complete. - extern bool Write( Colors color, const std::string& fmt, VARG_PARAM dummy, ... ); - extern bool Write( Colors color, const std::string& fmt ); + extern bool Write( Colors color, const char* fmt, VARG_PARAM dummy, ... ); + extern bool Write( Colors color, const char* fmt ); // Writes a formatted message to the console (no newline) - extern bool Write( const std::string& fmt, VARG_PARAM dummy, ... ); + extern bool Write( const char* fmt, VARG_PARAM dummy, ... ); // Writes a formatted message to the console, with appended newline. - extern bool WriteLn( const std::string& fmt, VARG_PARAM dummy, ... ); + extern bool WriteLn( const char* fmt, VARG_PARAM dummy, ... ); // Displays a message in the console with red emphasis. // Newline is automatically appended. - extern bool Error( const std::string& fmt, VARG_PARAM dummy, ... ); - extern bool Error( const std::string& fmt ); + extern bool Error( const char* fmt, VARG_PARAM dummy, ... ); + extern bool Error( const char* fmt ); // Displays a message in the console with yellow emphasis. // Newline is automatically appended. - extern bool Notice( const std::string& fmt, VARG_PARAM dummy, ... ); - extern bool Notice( const std::string& fmt ); + extern bool Notice( const char* fmt, VARG_PARAM dummy, ... ); + extern bool Notice( const char* fmt ); // Displays a message in the console with yellow emphasis. // Newline is automatically appended. - extern bool Status( const std::string& fmt, VARG_PARAM dummy, ... ); - extern bool Status( const std::string& fmt ); + extern bool Status( const char* fmt, VARG_PARAM dummy, ... ); + extern bool Status( const char* fmt ); } // Different types of message boxes that the emulator can employ from the friendly confines // of it's blissful unawareness of whatever GUI it runs under. :) All message boxes exhibit -// blocking behavior -- they promt the user for action and only return after the user has +// blocking behavior -- they prompt the user for action and only return after the user has // responded to the prompt. namespace Msgbox { // Pops up an alert Dialog Box with a singular "OK" button. // Always returns false. Replacement for SysMessage. - extern bool Alert( const std::string& fmt, VARG_PARAM dummy, ... ); - extern bool Alert( const std::string& fmt ); + extern bool Alert( const char* fmt, VARG_PARAM dummy, ... ); + extern bool Alert( const char* fmt ); // Pops up a dialog box with Ok/Cancel buttons. Returns the result of the inquiry, // true if OK, false if cancel. - extern bool OkCancel( const std::string& fmt, VARG_PARAM dummy, ... ); + extern bool OkCancel( const char* fmt, VARG_PARAM dummy, ... ); } using Console::Color_Red; @@ -282,6 +282,8 @@ protected: T* m_ptr; int m_size; // size of the allocation of memory + const static std::string m_str_Unnamed; + public: virtual ~MemoryAlloc() { diff --git a/pcsx2/vssprintf.cpp b/pcsx2/vssprintf.cpp index 0d64a6fc19..38c45bbcbc 100644 --- a/pcsx2/vssprintf.cpp +++ b/pcsx2/vssprintf.cpp @@ -510,7 +510,7 @@ static void flt( std::string& dest, double num, int size, int precision, char fm /////////////////////////////////////////////////////////////////////////// // This is a "mostly" direct replacement for vsprintf, that is more secure and easier // to use than vsnprintf or vsprintf_s. See the docs for ssprintf for usage notes. -void vssappendf(std::string& dest, const std::string& format, va_list args) +void vssappendf(std::string& dest, const char* format, va_list args) { int base; @@ -522,9 +522,9 @@ void vssappendf(std::string& dest, const std::string& format, va_list args) // Optimization: Memory is cheap. Allocating it on the fly is not. Allocate more room // than we'll likely need right upfront! - dest.reserve( format.length() * 2 ); + dest.reserve( strlen( format ) * 2 ); - for( const char* fmt = format.c_str(); *fmt; fmt++ ) + for( const char* fmt = format; *fmt; fmt++ ) { if (*fmt != '%') { @@ -734,18 +734,16 @@ repeat: } } -void vssprintf( std::string& dest, const std::string& format, va_list args ) +void vssprintf( std::string& dest, const char* format, va_list args ) { dest.clear(); vssappendf( dest, format, args ); } -void ssappendf( std::string& dest, const std::string& format, VARG_PARAM dummy, ...) +void ssappendf( std::string& dest, const char* format, ...) { - varg_assert(); - va_list args; - va_start(args, dummy); + va_start(args, format); vssappendf( dest, format, args ); va_end(args); } @@ -779,27 +777,36 @@ void ssappendf( std::string& dest, const std::string& format, VARG_PARAM dummy, // // ssprintf( dest, "Yo Joe, %Ld, %Lx.", params int64, hex64 ); // -void ssprintf(std::string& str, const std::string& fmt, VARG_PARAM dummy, ...) +void ssprintf(std::string& str, const char* fmt, ...) { - varg_assert(); + //varg_assert(); va_list args; - va_start(args, dummy); + va_start(args, fmt); vssprintf(str, fmt, args); va_end(args); } // See ssprintf for usage details and differences from sprintf formatting. -std::string fmt_string( const std::string& fmt, VARG_PARAM dummy, ... ) +std::string fmt_string( const char* fmt, ... ) { - varg_assert(); + //varg_assert(); std::string retval; va_list args; - va_start( args, dummy ); + va_start( args, fmt ); vssprintf( retval, fmt, args ); va_end( args ); return retval; } +std::string vfmt_string( const char* fmt, va_list args ) +{ + //varg_assert(); + + std::string retval; + vssprintf( retval, fmt, args ); + + return retval; +} diff --git a/pcsx2/windows/ConfigDlg.cpp b/pcsx2/windows/ConfigDlg.cpp index 9ed30d2852..6468a97c11 100644 --- a/pcsx2/windows/ConfigDlg.cpp +++ b/pcsx2/windows/ConfigDlg.cpp @@ -87,7 +87,7 @@ struct ComboInitializer string tmpStr; int i; - ssprintf(tmpStr, "%s %d.%d.%d", params PS2E_GetLibName(), (version>>8)&0xff, version&0xff, (version>>24)&0xff); + ssprintf(tmpStr, "%s %d.%d.%d", PS2E_GetLibName(), (version>>8)&0xff, version&0xff, (version>>24)&0xff); char* lp = (char *)malloc(strlen(FindData.cFileName)+8); sprintf(lp, "%s", FindData.cFileName); i = ComboBox_AddString(hwndCombo, tmpStr.c_str()); diff --git a/pcsx2/windows/WinConsole.cpp b/pcsx2/windows/WinConsole.cpp index 660eb86dd0..0b20c83522 100644 --- a/pcsx2/windows/WinConsole.cpp +++ b/pcsx2/windows/WinConsole.cpp @@ -104,17 +104,17 @@ namespace Console // Writes an unformatted string of text to the console (fast!) // No newline is appended. - __forceinline bool __fastcall Write( const string& fmt ) + __forceinline bool __fastcall Write( const char* fmt ) { if (hConsole != NULL) { DWORD tmp; - WriteConsole(hConsole, fmt.c_str(), (DWORD)fmt.length(), &tmp, 0); + WriteConsole(hConsole, fmt, (DWORD)strlen(fmt), &tmp, 0); } // No flushing here -- only flush after newlines. if (emuLog != NULL) - fputs((char*)fmt.c_str(), emuLog); + fputs(fmt, emuLog); return false; } @@ -122,25 +122,22 @@ namespace Console namespace Msgbox { - bool Alert( const string& fmt ) + bool Alert( const char* fmt ) { - MessageBox(0, fmt.c_str(), _("Pcsx2 Msg"), 0); + MessageBox(0, fmt, _("Pcsx2 Msg"), 0); return false; } // Pops up an alert Dialog Box. // Replacement for SysMessage. - bool Alert( const string& fmt, VARG_PARAM dummy, ... ) + bool Alert( const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); - string dest; va_list list; - va_start(list,dummy); - vssprintf(dest,fmt,list); + MessageBox(0, fmt_string(fmt,list).c_str(), _("Pcsx2 Msg"), 0); va_end(list); - MessageBox(0, dest.c_str(), _("Pcsx2 Msg"), 0); return false; } diff --git a/pcsx2/windows/WinMain.cpp b/pcsx2/windows/WinMain.cpp index 77275592fb..7885451d98 100644 --- a/pcsx2/windows/WinMain.cpp +++ b/pcsx2/windows/WinMain.cpp @@ -283,14 +283,20 @@ void WinRun( int nCmdShow ) catch( Exception::BaseException& ex ) { Msgbox::Alert( - "An unhandled or unrecoverable exception occurred, with the message:\n\n" + ex.Message() + - "\n\nPcsx2 will now close. More details may be available via the emuLog.txt file." ); + "An unhandled or unrecoverable exception occurred, with the message:\n\n" + "%s" + "\n\nPcsx2 will now close. More details may be available via the emuLog.txt file.", params + ex.cMessage() + ); } catch( std::exception& ex ) { Msgbox::Alert( - string( "An unhandled or unrecoverable exception occurred, with the message:\n\n" ) + ex.what() + - "\n\nPcsx2 will now close. More details may be available via the emuLog.txt file." ); + "An unhandled or unrecoverable exception occurred, with the message:\n\n" + "%s" + "\n\nPcsx2 will now close. More details may be available via the emuLog.txt file.", params + ex.what() + ); } } diff --git a/pcsx2/windows/WinSysExec.cpp b/pcsx2/windows/WinSysExec.cpp index c0a1b1c11b..4fcbf1f0de 100644 --- a/pcsx2/windows/WinSysExec.cpp +++ b/pcsx2/windows/WinSysExec.cpp @@ -268,7 +268,7 @@ void RunExecute( const char* elf_file, bool use_bios ) } catch( Exception::BaseException& ex ) { - Msgbox::Alert( ex.Message() ); + Msgbox::Alert( ex.cMessage() ); return; } @@ -436,9 +436,9 @@ void States_Load( const string& file, int num ) catch( Exception::StateLoadError_Recoverable& ex) { if( num != -1 ) - Console::Notice( "Could not load savestate from slot %d.\n\n" + ex.Message(), params num ); + Console::Notice( "Could not load savestate from slot %d.\n\n%s", params num, ex.cMessage() ); else - Console::Notice( "Could not load savestate file: %s.\n\n" + ex.Message(), params file ); + Console::Notice( "Could not load savestate file: %s.\n\n%s", params file, ex.cMessage() ); // At this point the cpu hasn't been reset, so we can return // control to the user safely... (that's why we use a console notice instead of a popup) @@ -453,17 +453,17 @@ void States_Load( const string& file, int num ) if( num != -1 ) ssprintf( message, - "Encountered an error while loading savestate from slot %d.\n", params num ); + "Encountered an error while loading savestate from slot %d.\n", num ); else ssprintf( message, - "Encountered an error while loading savestate from file: %s.\n", params file ); + "Encountered an error while loading savestate from file: %s.\n", file ); if( g_EmulationInProgress ) message += "Since the savestate load was incomplete, the emulator has been reset.\n"; message += "\nError: " + ex.Message(); - Msgbox::Alert( message ); + Msgbox::Alert( message.c_str() ); SysClose(); return; } @@ -479,9 +479,9 @@ void States_Save( const string& file, int num ) string text; RecoveryZipSavingState( file ).FreezeAll(); if( num != -1 ) - ssprintf( text, _( "State saved to slot %d" ), params num ); + ssprintf( text, _( "State saved to slot %d" ), num ); else - ssprintf( text, _( "State saved to file: %s" ), params file ); + ssprintf( text, _( "State saved to file: %s" ), file ); StatusBar_Notice( text ); } @@ -490,13 +490,13 @@ void States_Save( const string& file, int num ) string message; if( num != -1 ) - ssprintf( message, "An error occured while trying to save to slot %d\n", params num ); + ssprintf( message, "An error occurred while trying to save to slot %d\n", num ); else - ssprintf( message, "An error occured while trying to save to file: %s\n", params file ); + ssprintf( message, "An error occurred while trying to save to file: %s\n", file ); message += "Your emulation state has not been saved!\n\nError: " + ex.Message(); - Console::Error( message ); + Console::Error( message.c_str() ); } } diff --git a/pcsx2/windows/ini.cpp b/pcsx2/windows/ini.cpp index 266897a031..5d7e0e1348 100644 --- a/pcsx2/windows/ini.cpp +++ b/pcsx2/windows/ini.cpp @@ -320,7 +320,7 @@ bool LoadConfig() { string text; extern int _nl_msg_cat_cntr; - ssprintf(text, "LANGUAGE=%s", params Config.Lang); + ssprintf(text, "LANGUAGE=%s", Config.Lang); gettext_putenv(text.c_str()); } #endif diff --git a/pcsx2/x86/ix86/ix86_cpudetect.cpp b/pcsx2/x86/ix86/ix86_cpudetect.cpp index 48f1aa26cf..d3a31d6984 100644 --- a/pcsx2/x86/ix86/ix86_cpudetect.cpp +++ b/pcsx2/x86/ix86/ix86_cpudetect.cpp @@ -391,8 +391,8 @@ void cpudetectInit() SysMunmap( recSSE, 0x1000 ); } - // --> Core Counting <-- - // Hopefully this "best guess" method won't break on AMD cpus! + ////////////////////////////////////// + // Core Counting! if( !cpucaps.hasMultiThreading || LogicalCoresPerPhysicalCPU == 0 ) LogicalCoresPerPhysicalCPU = 1;