1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

remove duplicate debug code

This commit is contained in:
FunkyFr3sh 2018-10-02 11:38:38 +02:00
parent fa6f9e197e
commit ebae1add37
5 changed files with 56 additions and 79 deletions

View File

@ -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

View File

@ -1,7 +1,11 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#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();
}

View File

@ -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)

View File

@ -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)

View File

@ -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)