From 76743284105ffefe7e5528f4fc0eac5be5c5bb52 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sun, 22 Dec 2024 02:21:23 +0100 Subject: [PATCH] add new limiter_type type (PeekMessage) --- inc/dd.h | 2 ++ src/config.c | 2 +- src/ddsurface.c | 10 ++++++++-- src/winapi_hooks.c | 7 +++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/inc/dd.h b/inc/dd.h index b9382b18c8..fe175f7c99 100644 --- a/inc/dd.h +++ b/inc/dd.h @@ -51,6 +51,7 @@ HRESULT dd_CreateEx(GUID* lpGuid, LPVOID* lplpDD, REFIID iid, IUnknown* pUnkOute #define LIMIT_TESTCOOP 1 #define LIMIT_BLTFAST 2 #define LIMIT_UNLOCK 3 +#define LIMIT_PEEKMESSAGE 4 #define CENTER_WINDOW_NEVER 0 #define CENTER_WINDOW_AUTO 1 @@ -126,6 +127,7 @@ typedef struct CNCDDRAW LONG palette_updated; LONG surface_updated; LONG clear_screen; + LONG screen_updated; float scale_w; float scale_h; diff --git a/src/config.c b/src/config.c index dee87c7a12..87e34a7f44 100644 --- a/src/config.c +++ b/src/config.c @@ -290,7 +290,7 @@ static void cfg_create_ini() "; Note: Usually one of the following values will work: 60 / 30 / 25 / 20 / 15 (lower value = slower game speed)\n" "maxgameticks=0\n" "\n" - "; Method that should be used to limit game ticks (maxgameticks=): 0 = Automatic, 1 = TestCooperativeLevel, 2 = BltFast, 3 = Unlock\n" + "; Method that should be used to limit game ticks (maxgameticks=): 0 = Automatic, 1 = TestCooperativeLevel, 2 = BltFast, 3 = Unlock, 4 = PeekMessage\n" "limiter_type=0\n" "\n" "; Force minimum FPS, possible values: 0 = disabled, -1 = use 'maxfps=' value, -2 = same as -1 but force full redraw, 1-1000 = custom FPS\n" diff --git a/src/ddsurface.c b/src/ddsurface.c index ae4fcfd852..454ca24dff 100644 --- a/src/ddsurface.c +++ b/src/ddsurface.c @@ -430,6 +430,7 @@ HRESULT dds_Blt( if ((This->caps & DDSCAPS_PRIMARYSURFACE) && g_ddraw.ref && g_ddraw.render.run) { InterlockedExchange(&g_ddraw.render.surface_updated, TRUE); + InterlockedExchange(&g_ddraw.render.screen_updated, TRUE); if (!(This->flags & DDSD_BACKBUFFERCOUNT) || This->last_flip_tick + FLIP_REDRAW_TIMEOUT < timeGetTime()) { @@ -438,7 +439,7 @@ HRESULT dds_Blt( ReleaseSemaphore(g_ddraw.render.sem, 1, NULL); SwitchToThread(); - if (g_ddraw.ticks_limiter.tick_length > 0) + if (g_ddraw.ticks_limiter.tick_length > 0 && g_config.limiter_type != LIMIT_PEEKMESSAGE) { g_ddraw.ticks_limiter.dds_unlock_limiter_disabled = TRUE; util_limit_game_ticks(); @@ -666,6 +667,7 @@ HRESULT dds_BltFast( if ((This->caps & DDSCAPS_PRIMARYSURFACE) && g_ddraw.ref && g_ddraw.render.run) { InterlockedExchange(&g_ddraw.render.surface_updated, TRUE); + InterlockedExchange(&g_ddraw.render.screen_updated, TRUE); DWORD time = timeGetTime(); @@ -824,6 +826,7 @@ HRESULT dds_Flip(IDirectDrawSurfaceImpl* This, IDirectDrawSurfaceImpl* lpDDSurfa This->last_flip_tick = timeGetTime(); InterlockedExchange(&g_ddraw.render.surface_updated, TRUE); + InterlockedExchange(&g_ddraw.render.screen_updated, TRUE); ReleaseSemaphore(g_ddraw.render.sem, 1, NULL); SwitchToThread(); @@ -832,7 +835,7 @@ HRESULT dds_Flip(IDirectDrawSurfaceImpl* This, IDirectDrawSurfaceImpl* lpDDSurfa dd_WaitForVerticalBlank(DDWAITVB_BLOCKEND, NULL); } - if (g_ddraw.ticks_limiter.tick_length > 0) + if (g_ddraw.ticks_limiter.tick_length > 0 && g_config.limiter_type != LIMIT_PEEKMESSAGE) { g_ddraw.ticks_limiter.dds_unlock_limiter_disabled = TRUE; util_limit_game_ticks(); @@ -1027,6 +1030,7 @@ HRESULT dds_ReleaseDC(IDirectDrawSurfaceImpl* This, HDC hDC) if ((This->caps & DDSCAPS_PRIMARYSURFACE) && g_ddraw.ref && g_ddraw.render.run) { InterlockedExchange(&g_ddraw.render.surface_updated, TRUE); + InterlockedExchange(&g_ddraw.render.screen_updated, TRUE); DWORD time = timeGetTime(); @@ -1212,6 +1216,7 @@ HRESULT dds_Unlock(IDirectDrawSurfaceImpl* This, LPRECT lpRect) if ((This->caps & DDSCAPS_PRIMARYSURFACE) && g_ddraw.ref && g_ddraw.render.run) { InterlockedExchange(&g_ddraw.render.surface_updated, TRUE); + InterlockedExchange(&g_ddraw.render.screen_updated, TRUE); DWORD time = timeGetTime(); @@ -1221,6 +1226,7 @@ HRESULT dds_Unlock(IDirectDrawSurfaceImpl* This, LPRECT lpRect) ReleaseSemaphore(g_ddraw.render.sem, 1, NULL); if (g_ddraw.ticks_limiter.tick_length > 0 && + g_config.limiter_type != LIMIT_PEEKMESSAGE && (!g_ddraw.ticks_limiter.dds_unlock_limiter_disabled || g_config.limiter_type == LIMIT_UNLOCK)) { util_limit_game_ticks(); diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index a1c9787112..fa45f895da 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -780,6 +780,13 @@ BOOL WINAPI fake_GetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wM BOOL WINAPI fake_PeekMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) { + if (g_config.limiter_type == LIMIT_PEEKMESSAGE && + g_ddraw.ticks_limiter.tick_length > 0 && + InterlockedExchange(&g_ddraw.render.screen_updated, FALSE)) + { + util_limit_game_ticks(); + } + if (g_ddraw.ref && (!hWnd || hWnd == g_ddraw.hwnd)) g_ddraw.last_msg_pull_tick = timeGetTime();