Skip to content

Commit

Permalink
add new limiter_type type (PeekMessage)
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Dec 22, 2024
1 parent fb85d6e commit 7674328
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions inc/dd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions src/ddsurface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 7674328

Please sign in to comment.