From b0f17043bd288b6fae49ac49d9bcd3564f184f31 Mon Sep 17 00:00:00 2001 From: nakeee Date: Sun, 14 Dec 2008 22:00:18 +0000 Subject: [PATCH] new MsgHandler replacing common Most things moved to macros git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1542 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Common.vcproj | 2 +- Source/Core/Common/Src/Common.cpp | 142 ------------------ Source/Core/Common/Src/Common.h | 24 ++- Source/Core/Common/Src/MsgHandler.cpp | 67 +++++++++ Source/Core/Common/Src/SConscript | 2 +- Source/Core/Core/Src/HLE/HLE.cpp | 2 +- Source/Core/Core/Src/HLE/HLE_Misc.cpp | 2 +- Source/Core/Core/Src/HLE/HLE_Misc.h | 18 +-- Source/Core/DolphinWX/Src/Main.cpp | 13 +- .../Plugin_DSP_LLE/Src/gdsp_interpreter.cpp | 1 - 10 files changed, 103 insertions(+), 170 deletions(-) delete mode 100644 Source/Core/Common/Src/Common.cpp create mode 100644 Source/Core/Common/Src/MsgHandler.cpp diff --git a/Source/Core/Common/Common.vcproj b/Source/Core/Common/Common.vcproj index 3a2aefca7f..d14592aada 100644 --- a/Source/Core/Common/Common.vcproj +++ b/Source/Core/Common/Common.vcproj @@ -475,7 +475,7 @@ > - -#include "Common.h" -#include "StringUtil.h" - -namespace -{ - static PanicAlertHandler panic_handler = 0; -} - -void RegisterPanicAlertHandler(PanicAlertHandler handler) -{ - panic_handler = handler; -} - -void SuccessAlert(const char* format, ...) -{ - va_list args; - va_start(args, format); - - if (panic_handler) - { - char buffer[2048]; - CharArrayFromFormatV(buffer, 2048, format, args); - LOG(MASTER_LOG, "SUCCESS: %s", buffer); - panic_handler(buffer, false); - } - else - { -#ifdef _WIN32 - char buffer[2048]; - CharArrayFromFormatV(buffer, 2048, format, args); - LOG(MASTER_LOG, "SUCCESS: %s", buffer); - MessageBox(0, buffer, "SUCCESS!", MB_ICONWARNING); -#elif __GNUC__ - //#error Do a messagebox! - vprintf(format, args); - printf("\n"); -// asm ("int $3") ; -#endif - } - - va_end(args); -} - -void PanicAlert(const char* format, ...) -{ - va_list args; - va_start(args, format); - - if (panic_handler) - { - char buffer[2048]; - CharArrayFromFormatV(buffer, 2048, format, args); - LOG(MASTER_LOG, "PANIC: %s", buffer); - panic_handler(buffer, false); - } - else - { -#ifdef _WIN32 - char buffer[2048]; - CharArrayFromFormatV(buffer, 2048, format, args); - LOG(MASTER_LOG, "PANIC: %s", buffer); - MessageBox(0, buffer, "PANIC!", MB_ICONWARNING); -#elif __GNUC__ - //#error Do a messagebox! - vprintf(format, args); - printf("\n"); -// asm ("int $3") ; -#endif - } - - va_end(args); -} - - -bool PanicYesNo(const char* format, ...) -{ - va_list args; - va_start(args, format); - bool retval; -#ifdef _WIN32 - char buffer[2048]; - CharArrayFromFormatV(buffer, 2048, format, args); - LOG(MASTER_LOG, "PANIC: %s", buffer); - retval = IDYES == MessageBox(0, buffer, "PANIC! Continue?", MB_ICONQUESTION | MB_YESNO); -#elif __GNUC__ - //vprintf(format, args); - return(true); //#error Do a messagebox! -#endif - - va_end(args); - return(retval); -} - - -bool AskYesNo(const char* format, ...) -{ - va_list args; - va_start(args, format); - bool retval; -#ifdef _WIN32 - char buffer[2048]; - CharArrayFromFormatV(buffer, 2048, format, args); - LOG(MASTER_LOG, "ASK: %s", buffer); - retval = IDYES == MessageBox(0, buffer, "Dolphin", MB_ICONQUESTION | MB_YESNO); -#elif __GNUC__ - //vprintf(format, args); - return(true); //#error Do a messagebox! -#endif - - va_end(args); - return(retval); -} - -// Standard implementation of logging - simply print to standard output. -// Programs are welcome to override this. -/* - void __Log(int logNumber, const char *text, ...) - { - va_list args; - va_start(args, text); - vprintf(text, args); - va_end(args); - }*/ diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index 0b7cb106cc..b18493ad6e 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -190,15 +190,25 @@ inline u64 swap64(u64 data) {return(((u64)swap32(data) << 32) | swap32(data >> 3 // Utility functions -void PanicAlert(const char* text, ...); -void SuccessAlert(const char* text, ...); -bool PanicYesNo(const char* text, ...); -bool AskYesNo(const char* text, ...); - +// Msg Alert +typedef bool (*MsgAlertHandler)(const char* caption, const char* text, + bool yes_no); +void RegisterMsgAlertHandler(MsgAlertHandler handler); +extern bool MsgAlert(const char* caption, bool yes_no, const char* format, ...); +#ifdef _WIN32 +#define SuccessAlert(format, ...) MsgAlert("SUCCESS", false, format, __VA_ARGS__) +#define PanicAlert(format, ...) MsgAlert("PANIC", false, format, __VA_ARGS__) +#define PanicYesNo(format, ...) MsgAlert("PANIC", true, format, __VA_ARGS__) +#define AskYesNo(format, ...) MsgAlert("ASK", true, format, __VA_ARGS__) +#else +#define SuccessAlert(format, ...) MsgAlert("SUCCESS", false, format, ##__VA_ARGS__) +#define PanicAlert(format, ...) MsgAlert("PANIC", false, format, ##__VA_ARGS__) +#define PanicYesNo(format, ...) MsgAlert("PANIC", true, format, ##__VA_ARGS__) +#define AskYesNo(format, ...) MsgAlert("ASK", true, format, ##__VA_ARGS__) +#endif extern void __Log(int logNumber, const char* text, ...); extern void __Logv(int log, int v, const char *format, ...); - // dummy class class LogTypes { @@ -241,8 +251,6 @@ class LogTypes }; }; -typedef bool (*PanicAlertHandler)(const char* text, bool yes_no); -void RegisterPanicAlertHandler(PanicAlertHandler handler); void Host_UpdateLogDisplay(); diff --git a/Source/Core/Common/Src/MsgHandler.cpp b/Source/Core/Common/Src/MsgHandler.cpp new file mode 100644 index 0000000000..9485c31b23 --- /dev/null +++ b/Source/Core/Common/Src/MsgHandler.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2003-2008 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include + +#include "Common.h" +#include "StringUtil.h" + +bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no); + +static MsgAlertHandler msg_handler = DefaultMsgHandler; + +void RegisterMsgAlertHandler(MsgAlertHandler handler) { + msg_handler = handler; +} + +bool MsgAlert(const char* caption, bool yes_no, + const char* format, ...) { + + char buffer[2048]; + va_list args; + bool ret = false; + + va_start(args, format); + CharArrayFromFormatV(buffer, 2048, format, args); + + LOG(MASTER_LOG, "%s: %s", caption, buffer); + + if (msg_handler) { + ret = msg_handler(caption, buffer, yes_no); + } + + va_end(args); + return ret; +} + +bool DefaultMsgHandler(const char* caption, const char* text, + bool yes_no) { + +#ifdef _WIN32 + if (yes_no) + return IDYES == MessageBox(0, text, caption, + MB_ICONQUESTION | MB_YESNO); + else { + MessageBox(0, text, caption, MB_ICONWARNING); + return true; + } +#else + printf("%s\n", text); + return true; +#endif +} + diff --git a/Source/Core/Common/Src/SConscript b/Source/Core/Common/Src/SConscript index 4adfd8d255..7de9965b01 100644 --- a/Source/Core/Common/Src/SConscript +++ b/Source/Core/Common/Src/SConscript @@ -4,7 +4,7 @@ Import('env') files = [ "ABI.cpp", - "Common.cpp", + "MsgHandler.cpp", "ChunkFile.cpp", "CPUDetect.cpp", "DynamicLibrary.cpp", diff --git a/Source/Core/Core/Src/HLE/HLE.cpp b/Source/Core/Core/Src/HLE/HLE.cpp index ca3e730104..d5c277b0af 100644 --- a/Source/Core/Core/Src/HLE/HLE.cpp +++ b/Source/Core/Core/Src/HLE/HLE.cpp @@ -69,7 +69,7 @@ static const SPatch OSPatches[] = { ".evil_vec_cosine", HLE_Misc::SMB_EvilVecCosine }, { ".evil_normalize", HLE_Misc::SMB_EvilNormalize }, { ".evil_vec_setlength", HLE_Misc::SMB_evil_vec_setlength }, - { "PanicAlert", HLE_Misc::PanicAlert }, + { "PanicAlert", HLE_Misc::HLEPanicAlert }, { ".sqrt_internal_needs_cr1", HLE_Misc::SMB_sqrt_internal }, { ".rsqrt_internal_needs_cr1", HLE_Misc::SMB_rsqrt_internal }, { ".atan2", HLE_Misc::SMB_atan2}, diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.cpp b/Source/Core/Core/Src/HLE/HLE_Misc.cpp index 825fc04ddb..f8df025c69 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/Src/HLE/HLE_Misc.cpp @@ -66,7 +66,7 @@ void GXPeekARGB() NPC = LR; } -void PanicAlert() +void HLEPanicAlert() { ::PanicAlert("HLE: PanicAlert %08x", LR); NPC = LR; diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.h b/Source/Core/Core/Src/HLE/HLE_Misc.h index 8089acaa3b..2a93881d19 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.h +++ b/Source/Core/Core/Src/HLE/HLE_Misc.h @@ -21,18 +21,18 @@ namespace HLE_Misc { void Pass(); - void PanicAlert(); + void HLEPanicAlert(); void UnimplementedFunction(); void UnimplementedFunctionTrue(); void UnimplementedFunctionFalse(); - void GXPeekZ(); - void GXPeekARGB(); - void SMB_EvilVecCosine(); - void SMB_EvilNormalize(); - void SMB_sqrt_internal(); - void SMB_rsqrt_internal(); - void SMB_atan2(); - void SMB_evil_vec_setlength(); + void GXPeekZ(); + void GXPeekARGB(); + void SMB_EvilVecCosine(); + void SMB_EvilNormalize(); + void SMB_sqrt_internal(); + void SMB_rsqrt_internal(); + void SMB_atan2(); + void SMB_evil_vec_setlength(); } #endif diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index e1fd87f87e..a04cfb8c6c 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -45,7 +45,7 @@ IMPLEMENT_APP(DolphinApp) #if defined(HAVE_WX) && HAVE_WX -bool wxPanicAlert(const char* text, bool /*yes_no*/); +bool wxMsgAlert(const char*, const char*, bool); #endif CFrame* main_frame = NULL; @@ -92,7 +92,7 @@ bool DolphinApp::OnInit() #endif #if defined(HAVE_WX) && HAVE_WX - RegisterPanicAlertHandler(&wxPanicAlert); + RegisterMsgAlertHandler(&wxMsgAlert); #endif #ifdef _WIN32 @@ -264,10 +264,11 @@ void DolphinApp::OnEndSession() } -bool wxPanicAlert(const char* text, bool /*yes_no*/) -{ - wxMessageBox(wxString::FromAscii(text), _T("PANIC ALERT")); - return(true); +bool wxMsgAlert(const char* caption, const char* text, + bool yes_no) { + return wxYES == wxMessageBox(wxString::FromAscii(text), + wxString::FromAscii(caption), + (yes_no)?wxYES_NO:wxOK); } diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp index a20a279d8f..3a3c1e001f 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/gdsp_interpreter.cpp @@ -364,7 +364,6 @@ void gdsp_stop() #include "Mixer.h" uint16 r30 = 0, r31 = 0; -void PanicAlert(const char* text, ...); extern WaveFileWriter g_wave_writer; extern uint16 dsp_swap16(uint16 x);