From 5d2d258d5264c32e2277d9fea7e91746ac6fdf4b Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Mon, 19 Nov 2018 08:36:18 +0100 Subject: [PATCH] save last flip tick to force redraw in case the game switches between blt and flip --- inc/surface.h | 1 + src/surface.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/inc/surface.h b/inc/surface.h index 149a9bd..c53b30b 100644 --- a/inc/surface.h +++ b/inc/surface.h @@ -50,6 +50,7 @@ typedef struct IDirectDrawSurfaceImpl HBITMAP bitmap; HDC hDC; DDCOLORKEY colorKey; + DWORD lastFlipTick; } IDirectDrawSurfaceImpl; diff --git a/src/surface.c b/src/surface.c index 2032c92..11ebea9 100644 --- a/src/surface.c +++ b/src/surface.c @@ -21,6 +21,9 @@ #include "surface.h" #include "scale_pattern.h" +// enables redraw via blt/unlock if there wasn't any flip for X ms +#define FLIP_REDRAW_TIMEOUT 1000 / 20 + void dump_ddbltflags(DWORD dwFlags); void dump_ddscaps(DWORD dwCaps); void dump_ddsd(DWORD dwFlags); @@ -425,7 +428,9 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR } } - if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run) + if(This->caps & DDSCAPS_PRIMARYSURFACE && + ddraw->render.run && + (!(This->flags & DDSD_BACKBUFFERCOUNT) || This->lastFlipTick + FLIP_REDRAW_TIMEOUT < timeGetTime())) { InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL); @@ -564,7 +569,9 @@ HRESULT __stdcall ddraw_surface_BltFast(IDirectDrawSurfaceImpl *This, DWORD dst_ } } - if (This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run) + if (This->caps & DDSCAPS_PRIMARYSURFACE && + ddraw->render.run && + (!(This->flags & DDSD_BACKBUFFERCOUNT) || This->lastFlipTick + FLIP_REDRAW_TIMEOUT < timeGetTime())) { InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL); @@ -639,6 +646,8 @@ HRESULT __stdcall ddraw_surface_Flip(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWS if(This->caps & DDSCAPS_PRIMARYSURFACE && ddraw->render.run) { + This->lastFlipTick = timeGetTime(); + InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); if (ddraw->renderer == render_soft_main) @@ -912,7 +921,9 @@ HRESULT __stdcall ddraw_surface_Unlock(IDirectDrawSurfaceImpl *This, LPVOID lpRe printf("DirectDrawSurface::Unlock(This=%p, lpRect=%p)\n", This, lpRect); #endif - if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run) + if (This->caps & DDSCAPS_PRIMARYSURFACE && + ddraw->render.run && + (!(This->flags & DDSD_BACKBUFFERCOUNT) || This->lastFlipTick + FLIP_REDRAW_TIMEOUT < timeGetTime())) { InterlockedExchange(&ddraw->render.surfaceUpdated, TRUE); ReleaseSemaphore(ddraw->render.sem, 1, NULL);