From cab7a894e4972ad75a116fee33447093f8724488 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Fri, 2 Jul 2010 09:32:04 +0000 Subject: [PATCH] zzogl-pg: Move the logging code to its own file. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3366 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/gui/Panels/VideoPanel.cpp | 2 +- plugins/zzogl-pg/opengl/CMakeLists.txt | 6 +- plugins/zzogl-pg/opengl/GSmain.cpp | 239 +--------------- plugins/zzogl-pg/opengl/Util.h | 153 +--------- .../zzogl-pg/opengl/Win32/zerogsogl.vcxproj | 2 + .../opengl/Win32/zerogsogl_2008.vcproj | 8 + plugins/zzogl-pg/opengl/ZZLog.cpp | 265 ++++++++++++++++++ plugins/zzogl-pg/opengl/ZZLog.h | 184 ++++++++++++ 8 files changed, 466 insertions(+), 393 deletions(-) create mode 100644 plugins/zzogl-pg/opengl/ZZLog.cpp create mode 100644 plugins/zzogl-pg/opengl/ZZLog.h diff --git a/pcsx2/gui/Panels/VideoPanel.cpp b/pcsx2/gui/Panels/VideoPanel.cpp index f0ee55098a..1389a6f136 100644 --- a/pcsx2/gui/Panels/VideoPanel.cpp +++ b/pcsx2/gui/Panels/VideoPanel.cpp @@ -147,7 +147,7 @@ void Panels::FramelimiterPanel::Apply() throw Exception::CannotApplySettings( this ) .SetDiagMsg(wxsFormat( L"Error while parsing either NTSC or PAL framerate settings.\n\tNTSC Input = %s\n\tPAL Input = %s", - m_text_BaseNtsc->GetValue(), m_text_BasePal->GetValue() + m_text_BaseNtsc->GetValue().c_str(), m_text_BasePal->GetValue().c_str() ) ) .SetUserMsg(_("Error while parsing either NTSC or PAL framerate settings. Settings must be valid floating point numerics.")); } diff --git a/plugins/zzogl-pg/opengl/CMakeLists.txt b/plugins/zzogl-pg/opengl/CMakeLists.txt index 7f9542250b..b484a6ac15 100644 --- a/plugins/zzogl-pg/opengl/CMakeLists.txt +++ b/plugins/zzogl-pg/opengl/CMakeLists.txt @@ -83,7 +83,8 @@ set(zzoglSources ZZoglSave.cpp ZZoglShaders.cpp ZZoglShoots.cpp - ZZoglVB.cpp) + ZZoglVB.cpp + ZZLog.cpp) # zzogl headers set(zzoglHeaders @@ -104,7 +105,8 @@ set(zzoglHeaders zerogs.h zerogsmath.h zpipe.h - ZZoglCRTC.h) + ZZoglCRTC.h + ZZLog.h) # zzogl S sources set(zzoglSSources diff --git a/plugins/zzogl-pg/opengl/GSmain.cpp b/plugins/zzogl-pg/opengl/GSmain.cpp index 84bfcb6e36..5e08ace59d 100644 --- a/plugins/zzogl-pg/opengl/GSmain.cpp +++ b/plugins/zzogl-pg/opengl/GSmain.cpp @@ -49,10 +49,10 @@ using namespace std; GSinternal gs; char GStitle[256]; +extern FILE *gsLog; GSconf conf; int ppf; primInfo *prim; -FILE *gsLog; int g_GSMultiThreaded = 0; void (*GSirq)(); u8* g_pBasePS2Mem = NULL; @@ -115,243 +115,6 @@ HWND GShwnd = NULL; u32 THR_KeyEvent = 0; // Value for key event processing between threads bool THR_bShift = false; -namespace ZZLog -{ -bool IsLogging() -{ - // gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session. - // (GSinit won't have been called then) - return (gsLog != NULL && conf.log); -} - -bool OpenLog() { - bool result = true; - const std::string LogFile(s_strLogPath + "GSzzogl.log"); - - gsLog = fopen(LogFile.c_str(), "w"); - if (gsLog != NULL) - setvbuf(gsLog, NULL, _IONBF, 0); - else { - SysMessage("Can't create log file %s\n", LogFile.c_str()); - result = false; - } - - return result; -} - -void WriteToScreen(const char* pstr, u32 ms) -{ - ZeroGS::AddMessage(pstr, ms); -} - -void _Message(const char *str) -{ - SysMessage(str); -} - -void _Log(const char *str) -{ - if (IsLogging()) fprintf(gsLog, str); -} - -void _WriteToConsole(const char *str) -{ - fprintf(stderr,"ZZogl-PG: %s", str); -} - -void _Print(const char *str) -{ - fprintf(stderr,"ZZogl-PG: %s", str); - - if (IsLogging()) fprintf(gsLog, str); -} - -void Message(const char *fmt, ...) -{ - va_list list; - char tmp[512]; - - va_start(list, fmt); - vsprintf(tmp, fmt, list); - va_end(list); - - SysMessage(tmp); -} - -void Log(const char *fmt, ...) -{ - va_list list; - - va_start(list, fmt); - - if (IsLogging()) vfprintf(gsLog, fmt, list); - - va_end(list); -} - -void WriteToConsole(const char *fmt, ...) -{ - va_list list; - - va_start(list, fmt); - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - va_end(list); -} - -void Print(const char *fmt, ...) -{ - va_list list; - - va_start(list, fmt); - - if (IsLogging()) vfprintf(gsLog, fmt, list); - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - - va_end(list); -} - - -void WriteLn(const char *fmt, ...) -{ - va_list list; - - va_start(list, fmt); - - if (IsLogging()) vfprintf(gsLog, fmt, list); - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - va_end(list); - fprintf(stderr,"\n"); -} - -void Greg_Log(const char *fmt, ...) -{ - // Not currently used -#if 0 - va_list list; - char tmp[512]; - - va_start(list, fmt); - - if (IsLogging()) vfprintf(gsLog, fmt, list); - - va_end(list); - -#endif -} - -void Prim_Log(const char *fmt, ...) -{ -#if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS) - va_list list; - char tmp[512]; - - va_start(list, fmt); - - if (conf.log /*& 0x00000010*/) - { - if (IsLogging()) vfprintf(gsLog, fmt, list); - - fprintf(stderr, "ZZogl-PG(PRIM): "); - vfprintf(stderr, fmt, list); - - vprintf(fmt, list); - } - - va_end(list); - fprintf(stderr,"\n"); - -#endif -} - -void GS_Log(const char *fmt, ...) -{ -#ifdef ZEROGS_DEVBUILD - va_list list; - - va_start(list, fmt); - - if (IsLogging()) - { - vfprintf(gsLog, fmt, list); - fprintf(gsLog, "\n"); - } - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - fprintf(stderr, "\n"); - - va_end(list); -#endif -} - -void Warn_Log(const char *fmt, ...) -{ -#ifdef ZEROGS_DEVBUILD - va_list list; - - va_start(list, fmt); - - if (IsLogging()) - { - vfprintf(gsLog, fmt, list); - fprintf(gsLog, "\n"); - } - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - fprintf(stderr, "\n"); - - va_end(list); -#endif -} - -void Debug_Log(const char *fmt, ...) -{ -#if _DEBUG - va_list list; - - va_start(list, fmt); - - if (IsLogging()) - { - vfprintf(gsLog, fmt, list); - fprintf(gsLog, "\n"); - } - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - fprintf(stderr, "\n"); - - va_end(list); -#endif -} - -void Error_Log(const char *fmt, ...) -{ - va_list list; - - va_start(list, fmt); - - if (IsLogging()) - { - vfprintf(gsLog, fmt, list); - fprintf(gsLog, "\n"); - } - - fprintf(stderr, "ZZogl-PG: "); - vfprintf(stderr, fmt, list); - fprintf(stderr, "\n"); - - va_end(list); -} -}; - void CALLBACK GSsetBaseMem(void* pmem) { g_pBasePS2Mem = (u8*)pmem; diff --git a/plugins/zzogl-pg/opengl/Util.h b/plugins/zzogl-pg/opengl/Util.h index dc071f39ca..df61e4a0b5 100644 --- a/plugins/zzogl-pg/opengl/Util.h +++ b/plugins/zzogl-pg/opengl/Util.h @@ -44,6 +44,7 @@ extern HWND GShwnd; #define GSdefs #include "PS2Edefs.h" #include "CRC.h" +#include "ZZLog.h" // need C definitions -- no mangling please! extern "C" u32 CALLBACK PS2EgetLibType(void); @@ -246,158 +247,6 @@ typedef struct } GSconf; -//Logging for errors that are called often should have a time counter. -#ifdef __LINUX__ -static u32 __attribute__((unused)) lasttime = 0; -static u32 __attribute__((unused)) BigTime = 5000; -static bool __attribute__((unused)) SPAM_PASS; -#else -static u32 lasttime = 0; -static u32 BigTime = 5000; -static bool SPAM_PASS; -#endif - -#define ERROR_LOG_SPAM(text) { \ - if( timeGetTime() - lasttime > BigTime ) { \ - ZZLog::Error_Log(text); \ - lasttime = timeGetTime(); \ - } \ -} -// The same macro with one-argument substitution. -#define ERROR_LOG_SPAMA(fmt, value) { \ - if( timeGetTime() - lasttime > BigTime ) { \ - ZZLog::Error_Log(fmt, value); \ - lasttime = timeGetTime(); \ - } \ -} - -#define ERROR_LOG_SPAM_TEST(text) {\ - if( timeGetTime() - lasttime > BigTime ) { \ - ZZLog::Error_Log(text); \ - lasttime = timeGetTime(); \ - SPAM_PASS = true; \ - } \ - else \ - SPAM_PASS = false; \ -} - -#if DEBUG_PROF -#define FILE_IS_IN_CHECK ((strcmp(__FILE__, "targets.cpp") == 0) || (strcmp(__FILE__, "ZZoglFlush.cpp") == 0)) - -#define FUNCLOG {\ - static bool Was_Here = false; \ - static unsigned long int waslasttime = 0; \ - if (!Was_Here && FILE_IS_IN_CHECK) { \ - Was_Here = true;\ - ZZLog::Error_Log("%s:%d %s", __FILE__, __LINE__, __func__); \ - waslasttime = timeGetTime(); \ - } \ - if (FILE_IS_IN_CHECK && (timeGetTime() - waslasttime > BigTime )) { \ - Was_Here = false; \ - } \ -} -#else -#define FUNCLOG -#endif - -//#define WRITE_PRIM_LOGS -#if defined(_DEBUG) && !defined(ZEROGS_DEVBUILD) -#define ZEROGS_DEVBUILD -#endif - -#ifdef ZEROGS_DEVBUILD -//#define DEVBUILD -#endif - - -// sends a message to output window if assert fails -#define BMSG(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); } } -#define BMSG_RETURN(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return; } } -#define BMSG_RETURNX(x, str, rtype) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return (##rtype); } } -#define B(x) { if( !(x) ) { ZZLog::Log(_#x"\n"); ZZLog::Log(#x"\n"); } } -#define B_RETURN(x) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return; } } -#define B_RETURNX(x, rtype) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return (##rtype); } } -#define B_G(x, action) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); action; } } - -#define GL_REPORT_ERROR() \ -{ \ - GLenum err = glGetError(); \ - if( err != GL_NO_ERROR ) \ - { \ - ZZLog::Error_Log("%s:%d: gl error %s(0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \ - ZeroGS::HandleGLError(); \ - } \ -} - -#ifdef _DEBUG -# define GL_REPORT_ERRORD() \ -{ \ - GLenum err = glGetError(); \ - if( err != GL_NO_ERROR ) \ - { \ - ZZLog::Error_Log("%s:%d: gl error %s (0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \ - ZeroGS::HandleGLError(); \ - } \ -} -#else -# define GL_REPORT_ERRORD() -#endif - - -inline const char *error_name(int err) -{ - switch (err) - { - case GL_NO_ERROR: - return "GL_NO_ERROR"; - - case GL_INVALID_ENUM: - return "GL_INVALID_ENUM"; - - case GL_INVALID_VALUE: - return "GL_INVALID_VALUE"; - - case GL_INVALID_OPERATION: - return "GL_INVALID_OPERATION"; - - case GL_STACK_OVERFLOW: - return "GL_STACK_OVERFLOW"; - - case GL_STACK_UNDERFLOW: - return "GL_STACK_UNDERFLOW"; - - case GL_OUT_OF_MEMORY: - return "GL_OUT_OF_MEMORY"; - - case GL_TABLE_TOO_LARGE: - return "GL_TABLE_TOO_LARGE"; - - case GL_INVALID_FRAMEBUFFER_OPERATION: - return "GL_INVALID_FRAMEBUFFER_OPERATION"; - - default: - return "Unknown GL error"; - } -} - -extern void __LogToConsole(const char *fmt, ...); - -namespace ZZLog -{ -extern void Message(const char *fmt, ...); -extern void Log(const char *fmt, ...); -extern void WriteToConsole(const char *fmt, ...); -extern void Print(const char *fmt, ...); -extern void WriteLn(const char *fmt, ...); - -extern void Greg_Log(const char *fmt, ...); -extern void Prim_Log(const char *fmt, ...); -extern void GS_Log(const char *fmt, ...); - -extern void Debug_Log(const char *fmt, ...); -extern void Warn_Log(const char *fmt, ...); -extern void Error_Log(const char *fmt, ...); -}; #define REG64(name) \ union name \ diff --git a/plugins/zzogl-pg/opengl/Win32/zerogsogl.vcxproj b/plugins/zzogl-pg/opengl/Win32/zerogsogl.vcxproj index fe8ef0860c..98d5c69ed1 100644 --- a/plugins/zzogl-pg/opengl/Win32/zerogsogl.vcxproj +++ b/plugins/zzogl-pg/opengl/Win32/zerogsogl.vcxproj @@ -154,6 +154,7 @@ + @@ -199,6 +200,7 @@ + diff --git a/plugins/zzogl-pg/opengl/Win32/zerogsogl_2008.vcproj b/plugins/zzogl-pg/opengl/Win32/zerogsogl_2008.vcproj index 804b473a9a..f5cff5f61b 100644 --- a/plugins/zzogl-pg/opengl/Win32/zerogsogl_2008.vcproj +++ b/plugins/zzogl-pg/opengl/Win32/zerogsogl_2008.vcproj @@ -348,6 +348,10 @@ RelativePath="..\zpipe.cpp" > + + @@ -453,6 +457,10 @@ RelativePath="..\x86.h" > + + diff --git a/plugins/zzogl-pg/opengl/ZZLog.cpp b/plugins/zzogl-pg/opengl/ZZLog.cpp new file mode 100644 index 0000000000..7584c55a50 --- /dev/null +++ b/plugins/zzogl-pg/opengl/ZZLog.cpp @@ -0,0 +1,265 @@ +/* ZeroGS KOSMOS + * Copyright (C) 2005-2006 zerofrog@gmail.com + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "ZZLog.h" + +extern GSconf conf; +extern std::string s_strIniPath; +extern std::string s_strLogPath; + +FILE *gsLog; + +namespace ZZLog +{ +bool IsLogging() +{ + // gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session. + // (GSinit won't have been called then) + return (gsLog != NULL && conf.log); +} + +bool OpenLog() +{ + bool result = true; + const std::string LogFile(s_strLogPath + "GSzzogl.log"); + + gsLog = fopen(LogFile.c_str(), "w"); + if (gsLog != NULL) + setvbuf(gsLog, NULL, _IONBF, 0); + else + { + SysMessage("Can't create log file %s\n", LogFile.c_str()); + result = false; + } + + return result; +} + +void WriteToScreen(const char* pstr, u32 ms) +{ + ZeroGS::AddMessage(pstr, ms); +} + +void _Message(const char *str) +{ + SysMessage(str); +} + +void _Log(const char *str) +{ + if (IsLogging()) fprintf(gsLog, str); +} + +void _WriteToConsole(const char *str) +{ + fprintf(stderr,"ZZogl-PG: %s", str); +} + +void _Print(const char *str) +{ + fprintf(stderr,"ZZogl-PG: %s", str); + + if (IsLogging()) fprintf(gsLog, str); +} + +void Message(const char *fmt, ...) +{ + va_list list; + char tmp[512]; + + va_start(list, fmt); + vsprintf(tmp, fmt, list); + va_end(list); + + SysMessage(tmp); +} + +void Log(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + + if (IsLogging()) vfprintf(gsLog, fmt, list); + + va_end(list); +} + +void WriteToConsole(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + va_end(list); +} + +void Print(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + + if (IsLogging()) vfprintf(gsLog, fmt, list); + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + + va_end(list); +} + + +void WriteLn(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + + if (IsLogging()) vfprintf(gsLog, fmt, list); + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + va_end(list); + fprintf(stderr,"\n"); +} + +void Greg_Log(const char *fmt, ...) +{ + // Not currently used +#if 0 + va_list list; + char tmp[512]; + + va_start(list, fmt); + + if (IsLogging()) vfprintf(gsLog, fmt, list); + + va_end(list); + +#endif +} + +void Prim_Log(const char *fmt, ...) +{ +#if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS) + va_list list; + char tmp[512]; + + va_start(list, fmt); + + if (conf.log /*& 0x00000010*/) + { + if (IsLogging()) vfprintf(gsLog, fmt, list); + + fprintf(stderr, "ZZogl-PG(PRIM): "); + vfprintf(stderr, fmt, list); + + vprintf(fmt, list); + } + + va_end(list); + fprintf(stderr,"\n"); + +#endif +} + +void GS_Log(const char *fmt, ...) +{ +#ifdef ZEROGS_DEVBUILD + va_list list; + + va_start(list, fmt); + + if (IsLogging()) + { + vfprintf(gsLog, fmt, list); + fprintf(gsLog, "\n"); + } + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + fprintf(stderr, "\n"); + + va_end(list); +#endif +} + +void Warn_Log(const char *fmt, ...) +{ +#ifdef ZEROGS_DEVBUILD + va_list list; + + va_start(list, fmt); + + if (IsLogging()) + { + vfprintf(gsLog, fmt, list); + fprintf(gsLog, "\n"); + } + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + fprintf(stderr, "\n"); + + va_end(list); +#endif +} + +void Debug_Log(const char *fmt, ...) +{ +#if _DEBUG + va_list list; + + va_start(list, fmt); + + if (IsLogging()) + { + vfprintf(gsLog, fmt, list); + fprintf(gsLog, "\n"); + } + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + fprintf(stderr, "\n"); + + va_end(list); +#endif +} + +void Error_Log(const char *fmt, ...) +{ + va_list list; + + va_start(list, fmt); + + if (IsLogging()) + { + vfprintf(gsLog, fmt, list); + fprintf(gsLog, "\n"); + } + + fprintf(stderr, "ZZogl-PG: "); + vfprintf(stderr, fmt, list); + fprintf(stderr, "\n"); + + va_end(list); +} +}; diff --git a/plugins/zzogl-pg/opengl/ZZLog.h b/plugins/zzogl-pg/opengl/ZZLog.h new file mode 100644 index 0000000000..05c3d3cefe --- /dev/null +++ b/plugins/zzogl-pg/opengl/ZZLog.h @@ -0,0 +1,184 @@ +/* ZeroGS KOSMOS + * Copyright (C) 2005-2006 zerofrog@gmail.com + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ZZLOG_H_INCLUDED +#define ZZLOG_H_INCLUDED + +#include "Util.h" + + +//Logging for errors that are called often should have a time counter. +#ifdef __LINUX__ +static u32 __attribute__((unused)) lasttime = 0; +static u32 __attribute__((unused)) BigTime = 5000; +static bool __attribute__((unused)) SPAM_PASS; +#else +static u32 lasttime = 0; +static u32 BigTime = 5000; +static bool SPAM_PASS; +#endif + +#define ERROR_LOG_SPAM(text) { \ + if( timeGetTime() - lasttime > BigTime ) { \ + ZZLog::Error_Log(text); \ + lasttime = timeGetTime(); \ + } \ +} +// The same macro with one-argument substitution. +#define ERROR_LOG_SPAMA(fmt, value) { \ + if( timeGetTime() - lasttime > BigTime ) { \ + ZZLog::Error_Log(fmt, value); \ + lasttime = timeGetTime(); \ + } \ +} + +#define ERROR_LOG_SPAM_TEST(text) {\ + if( timeGetTime() - lasttime > BigTime ) { \ + ZZLog::Error_Log(text); \ + lasttime = timeGetTime(); \ + SPAM_PASS = true; \ + } \ + else \ + SPAM_PASS = false; \ +} + +#if DEBUG_PROF +#define FILE_IS_IN_CHECK ((strcmp(__FILE__, "targets.cpp") == 0) || (strcmp(__FILE__, "ZZoglFlush.cpp") == 0)) + +#define FUNCLOG {\ + static bool Was_Here = false; \ + static unsigned long int waslasttime = 0; \ + if (!Was_Here && FILE_IS_IN_CHECK) { \ + Was_Here = true;\ + ZZLog::Error_Log("%s:%d %s", __FILE__, __LINE__, __func__); \ + waslasttime = timeGetTime(); \ + } \ + if (FILE_IS_IN_CHECK && (timeGetTime() - waslasttime > BigTime )) { \ + Was_Here = false; \ + } \ +} +#else +#define FUNCLOG +#endif + +//#define WRITE_PRIM_LOGS +#if defined(_DEBUG) && !defined(ZEROGS_DEVBUILD) +#define ZEROGS_DEVBUILD +#endif + +#ifdef ZEROGS_DEVBUILD +//#define DEVBUILD +#endif + + +// sends a message to output window if assert fails +#define BMSG(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); } } +#define BMSG_RETURN(x, str) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return; } } +#define BMSG_RETURNX(x, str, rtype) { if( !(x) ) { ZZLog::Log(str); ZZLog::Log(str); return (##rtype); } } +#define B(x) { if( !(x) ) { ZZLog::Log(_#x"\n"); ZZLog::Log(#x"\n"); } } +#define B_RETURN(x) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return; } } +#define B_RETURNX(x, rtype) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); return (##rtype); } } +#define B_G(x, action) { if( !(x) ) { ZZLog::Error_Log("%s:%d: %s", __FILE__, (u32)__LINE__, #x); action; } } + +#define GL_REPORT_ERROR() \ +{ \ + GLenum err = glGetError(); \ + if( err != GL_NO_ERROR ) \ + { \ + ZZLog::Error_Log("%s:%d: gl error %s(0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \ + ZeroGS::HandleGLError(); \ + } \ +} + +#ifdef _DEBUG +# define GL_REPORT_ERRORD() \ +{ \ + GLenum err = glGetError(); \ + if( err != GL_NO_ERROR ) \ + { \ + ZZLog::Error_Log("%s:%d: gl error %s (0x%x)", __FILE__, (int)__LINE__, error_name(err), err); \ + ZeroGS::HandleGLError(); \ + } \ +} +#else +# define GL_REPORT_ERRORD() +#endif + + +inline const char *error_name(int err) +{ + switch (err) + { + case GL_NO_ERROR: + return "GL_NO_ERROR"; + + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM"; + + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE"; + + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION"; + + case GL_STACK_OVERFLOW: + return "GL_STACK_OVERFLOW"; + + case GL_STACK_UNDERFLOW: + return "GL_STACK_UNDERFLOW"; + + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY"; + + case GL_TABLE_TOO_LARGE: + return "GL_TABLE_TOO_LARGE"; + + case GL_INVALID_FRAMEBUFFER_OPERATION: + return "GL_INVALID_FRAMEBUFFER_OPERATION"; + + default: + return "Unknown GL error"; + } +} + +extern void __LogToConsole(const char *fmt, ...); +namespace ZeroGS +{ +extern void AddMessage(const char* pstr, u32 ms); +} + +namespace ZZLog +{ +extern bool IsLogging(); +extern bool OpenLog(); +extern void Message(const char *fmt, ...); +extern void Log(const char *fmt, ...); +extern void WriteToConsole(const char *fmt, ...); +extern void Print(const char *fmt, ...); +extern void WriteLn(const char *fmt, ...); + +extern void Greg_Log(const char *fmt, ...); +extern void Prim_Log(const char *fmt, ...); +extern void GS_Log(const char *fmt, ...); + +extern void Debug_Log(const char *fmt, ...); +extern void Warn_Log(const char *fmt, ...); +extern void Error_Log(const char *fmt, ...); +}; + +#endif // ZZLOG_H_INCLUDED