From ebae1add37ed72ec24b79ba069a662160d012132 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Tue, 2 Oct 2018 11:38:38 +0200 Subject: [PATCH] remove duplicate debug code --- inc/debug.h | 5 +++++ src/debug.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/render.c | 28 ++-------------------------- src/render_d3d9.c | 35 +++++++---------------------------- src/render_soft.c | 26 ++------------------------ 5 files changed, 56 insertions(+), 79 deletions(-) diff --git a/inc/debug.h b/inc/debug.h index 04e5509..9c30178 100644 --- a/inc/debug.h +++ b/inc/debug.h @@ -6,6 +6,11 @@ void CounterStart(); double CounterStop(); void DebugPrint(const char *format, ...); +void DrawFrameInfoStart(); +void DrawFrameInfoEnd(); + +extern double DebugFrameTime; +extern DWORD DebugFrameCount; //#define _DEBUG 1 diff --git a/src/debug.c b/src/debug.c index 9c359a5..f17e55d 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,7 +1,11 @@ -#define WIN32_LEAN_AND_MEAN + #include #include +#include "main.h" +#include "surface.h" +double DebugFrameTime = 0; +DWORD DebugFrameCount = 0; static LONGLONG CounterStartTime = 0; static double CounterFreq = 0.0; @@ -30,3 +34,38 @@ void DebugPrint(const char *format, ...) _vsnprintf(buffer, sizeof(buffer), format, args); OutputDebugStringA(buffer); } + +void DrawFrameInfoStart() +{ + static DWORD tick_fps = 0; + static char debugText[512] = { 0 }; + + RECT debugrc = { 0, 0, ddraw->width, ddraw->height }; + + if (ddraw->primary && ddraw->primary->palette) + DrawText(ddraw->primary->hDC, debugText, -1, &debugrc, DT_NOCLIP); + + DWORD tick_start = timeGetTime(); + if (tick_start >= tick_fps) + { + snprintf( + debugText, + sizeof(debugText), + "FPS: %lu | Time: %2.2f ms ", + DebugFrameCount, + DebugFrameTime); + + DebugFrameCount = 0; + tick_fps = tick_start + 1000; + + CounterStart(); + } + + DebugFrameCount++; +} + +void DrawFrameInfoEnd() +{ + if (DebugFrameCount == 1) + DebugFrameTime = CounterStop(); +} diff --git a/src/render.c b/src/render.c index 73bc750..ce190a8 100644 --- a/src/render.c +++ b/src/render.c @@ -550,31 +550,7 @@ static void Render() while (UseOpenGL && ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED) { #if _DEBUG - static DWORD tick_fps = 0; - static DWORD frame_count = 0; - static char debugText[512] = { 0 }; - static double frameTime = 0; - RECT debugrc = { 0, 0, ddraw->width, ddraw->height }; - - if (ddraw->primary && ddraw->primary->palette) - DrawText(ddraw->primary->hDC, debugText, -1, &debugrc, DT_NOCLIP); - - tick_start = timeGetTime(); - if (tick_start >= tick_fps) - { - snprintf( - debugText, - sizeof(debugText), - "FPS: %lu | Time: %2.2f ms ", - frame_count, - frameTime); - - frame_count = 0; - tick_fps = tick_start + 1000; - - CounterStart(); - } - frame_count++; + DrawFrameInfoStart(); #endif ScaleW = (float)ddraw->width / SurfaceTexWidth; @@ -804,7 +780,7 @@ static void Render() glFinish(); #if _DEBUG - if (frame_count == 1) frameTime = CounterStop(); + DrawFrameInfoEnd(); #endif if (MaxFPS > 0) diff --git a/src/render_d3d9.c b/src/render_d3d9.c index fec6288..c3cbdb9 100644 --- a/src/render_d3d9.c +++ b/src/render_d3d9.c @@ -40,7 +40,7 @@ static BOOL CreateDirect3D(); static BOOL CreateResources(); static void SetStates(); static void UpdateVertices(BOOL inCutscene); -static void Reset(); +static BOOL Reset(); static void SetMaxFPS(int baseMaxFPS); static void Render(); static void ReleaseDirect3D(); @@ -199,12 +199,15 @@ static void UpdateVertices(BOOL inCutscene) } } -static void Reset() +static BOOL Reset() { if (SUCCEEDED(D3ddev->lpVtbl->Reset(D3ddev, &D3dpp))) { SetStates(); + return TRUE; } + + return FALSE; } static void SetMaxFPS(int baseMaxFPS) @@ -232,31 +235,7 @@ static void Render() while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED) { #if _DEBUG - static DWORD tick_fps = 0; - static DWORD frame_count = 0; - static char debugText[512] = { 0 }; - static double frameTime = 0; - RECT debugrc = { 0, 0, ddraw->width, ddraw->height }; - - if (ddraw->primary && ddraw->primary->palette) - DrawText(ddraw->primary->hDC, debugText, -1, &debugrc, DT_NOCLIP); - - tick_start = timeGetTime(); - if (tick_start >= tick_fps) - { - snprintf( - debugText, - sizeof(debugText), - "FPS: %lu | Time: %2.2f ms ", - frame_count, - frameTime); - - frame_count = 0; - tick_fps = tick_start + 1000; - - CounterStart(); - } - frame_count++; + DrawFrameInfoStart(); #endif if (MaxFPS > 0) @@ -332,7 +311,7 @@ static void Render() } #if _DEBUG - if (frame_count == 1) frameTime = CounterStop(); + DrawFrameInfoEnd(); #endif if (MaxFPS > 0) diff --git a/src/render_soft.c b/src/render_soft.c index 98a275d..55ac633 100644 --- a/src/render_soft.c +++ b/src/render_soft.c @@ -87,29 +87,7 @@ DWORD WINAPI render_soft_main(void) while (ddraw->render.run && WaitForSingleObject(ddraw->render.sem, INFINITE) != WAIT_FAILED) { #if _DEBUG - static DWORD tick_fps = 0; - static DWORD frame_count = 0; - static char debugText[512] = { 0 }; - static double frameTime = 0; - RECT debugrc = { 0, 0, ddraw->width, ddraw->height }; - - if (ddraw->primary && ddraw->primary->palette) - DrawText(ddraw->primary->hDC, debugText, -1, &debugrc, DT_NOCLIP); - - tick_start = timeGetTime(); - if (tick_start >= tick_fps) - { - snprintf( - debugText, sizeof(debugText), - "FPS: %lu | Time: %2.2f ms ", - frame_count, frameTime); - - frame_count = 0; - tick_fps = tick_start + 1000; - - CounterStart(); - } - frame_count++; + DrawFrameInfoStart(); #endif if(maxfps > 0) @@ -192,7 +170,7 @@ DWORD WINAPI render_soft_main(void) LeaveCriticalSection(&ddraw->cs); #if _DEBUG - if (frame_count == 1) frameTime = CounterStop(); + DrawFrameInfoEnd(); #endif if(maxfps > 0)