1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 22:14:49 +01:00
This commit is contained in:
FunkyFr3sh 2017-11-26 08:49:30 +01:00
parent b82cffb728
commit c526cf63de
9 changed files with 75 additions and 15 deletions

@ -3,7 +3,8 @@ WINDRES=windres
CFLAGS=-DHAVE_LIBPNG -Iinc -Wall -Wl,--enable-stdcall-fixup -O3 -s
LIBS=lib/libpng14.a lib/libz.a -lgdi32 -lopengl32 -lwinmm
FILES = src/main.c \
FILES = src/debug.c \
src/main.c \
src/mouse.c \
src/palette.c \
src/surface.c \

24
inc/debug.h Normal file

@ -0,0 +1,24 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
void DebugPrint(const char *format, ...);
//#define _DEBUG 1
//use OutputDebugStringA rather than printf
//#define _DEBUGstring 1
//log everything (slow)
//#define _DEBUGx 1
#ifdef _DEBUG
#ifdef _DEBUGstring
#define printf(format, ...) DebugPrint("xDBG " format, ##__VA_ARGS__)
#endif
#else
#define printf(format, ...)
#endif

@ -19,13 +19,10 @@
#include <windows.h>
#include "ddraw.h"
#include "debug.h"
#include <GL/gl.h>
#include <GL/glu.h>
#ifndef _DEBUG
#define printf(format, ...)
#endif
struct IDirectDrawImpl;
struct IDirectDrawImplVtbl;
struct IDirectDrawSurfaceImpl;

12
src/debug.c Normal file

@ -0,0 +1,12 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
void DebugPrint(const char *format, ...)
{
va_list args;
va_start(args, format);
char buffer[512];
_vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, format, args);
OutputDebugStringA(buffer);
}

@ -702,7 +702,7 @@ HRESULT __stdcall ddraw_SetCooperativeLevel(IDirectDrawImpl *This, HWND hWnd, DW
HRESULT __stdcall ddraw_WaitForVerticalBlank(IDirectDrawImpl *This, DWORD a, HANDLE b)
{
#if _DEBUG
#if _DEBUGx
printf("DirectDraw::WaitForVerticalBlank(This=%p, ...)\n", This);
#endif
return DD_OK;
@ -819,7 +819,7 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk
#if _DEBUG
if(!stdout_open)
{
freopen("stdout.txt", "w", stdout);
freopen("ra95stdout.txt", "w", stdout);
setvbuf(stdout, NULL, _IONBF, 0);
stdout_open = 1;
}

@ -42,7 +42,7 @@ HRESULT __stdcall ddraw_palette_SetEntries(IDirectDrawPaletteImpl *This, DWORD d
{
int i;
#if _DEBUG
#if _DEBUGx
printf("DirectDrawPalette::SetEntries(This=%p, dwFlags=%d, dwStartingEntry=%d, dwCount=%d, lpEntries=%p)\n", This, (int)dwFlags, (int)dwStartingEntry, (int)dwCount, lpEntries);
#endif

@ -147,6 +147,19 @@ DWORD WINAPI render_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;
tick_start = timeGetTime();
if (tick_start >= tick_fps)
{
printf("Frames: %lu - Elapsed: %lu ms\n", frame_count, (tick_start - tick_fps) + 1000);
frame_count = 0;
tick_fps = tick_start + 1000;
}
frame_count++;
#endif
static int index = 0;
scale_w = (float)ddraw->width/tex_width;
scale_h = (float)ddraw->height/tex_height;

@ -97,6 +97,19 @@ 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;
tick_start = timeGetTime();
if (tick_start >= tick_fps)
{
printf("Frames: %lu - Elapsed: %lu ms\n", frame_count, (tick_start - tick_fps) + 1000);
frame_count = 0;
tick_fps = tick_start + 1000;
}
frame_count++;
#endif
if(ddraw->render.maxfps > 0)
{
tick_start = timeGetTime();

@ -81,7 +81,7 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
{
IDirectDrawSurfaceImpl *Source = (IDirectDrawSurfaceImpl *)lpDDSrcSurface;
#if _DEBUG
#if _DEBUGx
printf("DirectDrawSurface::Blt(This=%p, lpDestRect=%p, lpDDSrcSurface=%p, lpSrcRect=%p, dwFlags=%d, lpDDBltFx=%p)\n", This, lpDestRect, lpDDSrcSurface, lpSrcRect, (int)dwFlags, lpDDBltFx);
if(lpDestRect)
{
@ -151,7 +151,7 @@ HRESULT __stdcall ddraw_surface_DeleteAttachedSurface(IDirectDrawSurfaceImpl *Th
HRESULT __stdcall ddraw_surface_GetSurfaceDesc(IDirectDrawSurfaceImpl *This, LPDDSURFACEDESC lpDDSurfaceDesc)
{
#if _DEBUG
#if _DEBUGx
printf("IDirectDrawSurface::GetSurfaceDesc(This=%p, lpDDSurfaceDesc=%p)\n", This, lpDDSurfaceDesc);
#endif
@ -197,7 +197,7 @@ HRESULT __stdcall ddraw_surface_EnumOverlayZOrders(IDirectDrawSurfaceImpl *This,
HRESULT __stdcall ddraw_surface_Flip(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWSURFACE a, DWORD b)
{
#if _DEBUG
#if _DEBUGx
printf("IDirectDrawSurface::Flip(This=%p, ...)\n", This);
#endif
@ -219,7 +219,7 @@ HRESULT __stdcall ddraw_surface_GetAttachedSurface(IDirectDrawSurfaceImpl *This,
HRESULT __stdcall ddraw_surface_GetBltStatus(IDirectDrawSurfaceImpl *This, DWORD a)
{
#if _DEBUG
#if _DEBUGx
printf("IDirectDrawSurface::GetBltStatus(This=%p, ...)\n", This);
#endif
return DD_OK;
@ -283,7 +283,7 @@ HRESULT __stdcall ddraw_surface_Initialize(IDirectDrawSurfaceImpl *This, LPDIREC
HRESULT __stdcall ddraw_surface_IsLost(IDirectDrawSurfaceImpl *This)
{
#if _DEBUG
#if _DEBUGx
printf("IDirectDrawSurface::IsLost(This=%p)\n", This);
#endif
return DD_OK;
@ -291,7 +291,7 @@ HRESULT __stdcall ddraw_surface_IsLost(IDirectDrawSurfaceImpl *This)
HRESULT __stdcall ddraw_surface_Lock(IDirectDrawSurfaceImpl *This, LPRECT lpDestRect, LPDDSURFACEDESC lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent)
{
#if _DEBUG
#if _DEBUGx
printf("DirectDrawSurface::Lock(This=%p, lpDestRect=%p, lpDDSurfaceDesc=%p, dwFlags=%d, hEvent=%p)\n", This, lpDestRect, lpDDSurfaceDesc, (int)dwFlags, hEvent);
if(dwFlags & DDLOCK_SURFACEMEMORYPTR)
@ -367,7 +367,7 @@ HRESULT __stdcall ddraw_surface_SetPalette(IDirectDrawSurfaceImpl *This, LPDIREC
HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRect)
{
#if _DEBUG
#if _DEBUGx
printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect);
#endif