From 9aa457c8b8a81c3bfb1724f4099a6cf6f1ad6e26 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sun, 14 Apr 2019 07:28:06 +0200 Subject: [PATCH] add dprintf from ts-ddraw --- inc/debug.h | 3 +++ src/debug.c | 30 ++++++++++++++++++++++++++++++ src/main.c | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/inc/debug.h b/inc/debug.h index 9c30178..19d9907 100644 --- a/inc/debug.h +++ b/inc/debug.h @@ -8,6 +8,7 @@ double CounterStop(); void DebugPrint(const char *format, ...); void DrawFrameInfoStart(); void DrawFrameInfoEnd(); +int dprintf(const char *fmt, ...); extern double DebugFrameTime; extern DWORD DebugFrameCount; @@ -24,6 +25,8 @@ extern DWORD DebugFrameCount; #ifdef _DEBUG_S #define printf(format, ...) DebugPrint("xDBG " format, ##__VA_ARGS__) +#else +#define printf(format, ...) dprintf(format, ##__VA_ARGS__) #endif #else diff --git a/src/debug.c b/src/debug.c index 88690e1..b9e08f2 100644 --- a/src/debug.c +++ b/src/debug.c @@ -35,6 +35,36 @@ void DebugPrint(const char *format, ...) OutputDebugStringA(buffer); } +int dprintf(const char *fmt, ...) +{ + static CRITICAL_SECTION cs; + static BOOL initialized; + + if (!initialized) + { + initialized = TRUE; + InitializeCriticalSection(&cs); + } + + EnterCriticalSection(&cs); + + va_list args; + int ret; + + SYSTEMTIME st; + GetLocalTime(&st); + + fprintf(stdout, "[%lu] %02d:%02d:%02d.%03d ", GetCurrentThreadId(), st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); + + va_start(args, fmt); + ret = vfprintf(stdout, fmt, args); + va_end(args); + + LeaveCriticalSection(&cs); + + return ret; +} + void DrawFrameInfoStart() { static DWORD tick_fps = 0; diff --git a/src/main.c b/src/main.c index fdce3c5..cab0719 100644 --- a/src/main.c +++ b/src/main.c @@ -1646,7 +1646,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk #if _DEBUG if(!stdout_open) { - freopen("ra95stdout.txt", "w", stdout); + freopen("cnc-ddraw.log", "w", stdout); setvbuf(stdout, NULL, _IOLBF, 1024); stdout_open = 1; }