1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-24 17:49:52 +01:00

remove sleep hack and add a smarter game speed limiter that takes the games performance into account

This commit is contained in:
FunkyFr3sh 2018-10-31 11:48:41 +01:00
parent 2d4841beda
commit 0e6d415f63
4 changed files with 34 additions and 12 deletions

View File

@ -32,6 +32,7 @@ extern BOOL ShowDriverWarning;
extern RECT WindowRect; extern RECT WindowRect;
BOOL detect_cutscene(); BOOL detect_cutscene();
void LimitGameTicks();
DWORD WINAPI render_main(void); DWORD WINAPI render_main(void);
DWORD WINAPI render_soft_main(void); DWORD WINAPI render_soft_main(void);
@ -104,8 +105,8 @@ typedef struct IDirectDrawImpl
BOOL hidemouse; BOOL hidemouse;
char shader[MAX_PATH]; char shader[MAX_PATH];
BOOL wine; BOOL wine;
int sleep;
LONG minimized; LONG minimized;
DWORD ticklength;
} IDirectDrawImpl; } IDirectDrawImpl;

View File

@ -131,6 +131,24 @@ BOOL detect_cutscene()
return FALSE; return FALSE;
} }
void LimitGameTicks()
{
static DWORD nextGameTick;
if (!nextGameTick)
{
nextGameTick = timeGetTime();
return;
}
nextGameTick += ddraw->ticklength;
DWORD tickCount = timeGetTime();
int sleepTime = nextGameTick - tickCount;
if (sleepTime <= 0 || sleepTime > ddraw->ticklength)
nextGameTick = tickCount;
else
Sleep(sleepTime);
}
HRESULT __stdcall ddraw_Compact(IDirectDrawImpl *This) HRESULT __stdcall ddraw_Compact(IDirectDrawImpl *This)
{ {
printf("DirectDraw::Compact(This=%p) ???\n", This); printf("DirectDraw::Compact(This=%p) ???\n", This);

View File

@ -43,13 +43,16 @@ void Settings_Load()
ddraw->vhack = GetBool("vhack", FALSE); ddraw->vhack = GetBool("vhack", FALSE);
ddraw->hidemouse = GetBool("hidemouse", TRUE); ddraw->hidemouse = GetBool("hidemouse", TRUE);
ddraw->sleep = GetInt("sleep", 0);
ddraw->render.maxfps = GetInt("maxfps", 125); ddraw->render.maxfps = GetInt("maxfps", 125);
WindowRect.right = GetInt("width", 0); WindowRect.right = GetInt("width", 0);
WindowRect.bottom = GetInt("height", 0); WindowRect.bottom = GetInt("height", 0);
WindowRect.left = GetInt("posX", -32000); WindowRect.left = GetInt("posX", -32000);
WindowRect.top = GetInt("posY", -32000); WindowRect.top = GetInt("posY", -32000);
int maxTicks = GetInt("maxgameticks", 0);
if (maxTicks > 0 && maxTicks < 1000)
ddraw->ticklength = 1000.0f / maxTicks;
GetString("screenshotKey", "G", tmp, sizeof(tmp)); GetString("screenshotKey", "G", tmp, sizeof(tmp));
ddraw->screenshotKey = toupper(tmp[0]); ddraw->screenshotKey = toupper(tmp[0]);
@ -195,18 +198,18 @@ static void CreateSettingsIni()
"devmode=false\n" "devmode=false\n"
"; preliminary libretro shader support - e.g. cubic.glsl (OpenGL only) https://github.com/libretro/glsl-shaders\n" "; preliminary libretro shader support - e.g. cubic.glsl (OpenGL only) https://github.com/libretro/glsl-shaders\n"
"shader=\n" "shader=\n"
"; Sleep for X ms after drawing each frame (Slows down scrollrate on C&C95 / Prevents visual glitches on Carmageddon)\n" "; Max game ticks per second (Can be used to slow down a too fast running game)\n"
"sleep=0\n" "maxgameticks=0\n"
"; Hide/Show the mouse cursor on lock/unlock (Ctrl+Tab)\n" "; Hide/Show the mouse cursor on lock/unlock (Ctrl+Tab)\n"
"hidemouse=true\n" "hidemouse=true\n"
"\n" "\n"
"[CARMA95]\n" "[CARMA95]\n"
"fakecursorpos=false\n" "fakecursorpos=false\n"
"noactivateapp=true\n" "noactivateapp=true\n"
"sleep=33\n" "maxgameticks=30\n"
"\n" "\n"
"[C&C95]\n" "[C&C95]\n"
"sleep=10\n" "maxgameticks=60\n"
"\n" "\n"
"[empires]\n" "[empires]\n"
"hidemouse=false\n" "hidemouse=false\n"
@ -234,7 +237,7 @@ static void CreateSettingsIni()
"\n" "\n"
"[olwin]\n" "[olwin]\n"
"noactivateapp=true\n" "noactivateapp=true\n"
"sleep=10\n" "maxgameticks=60\n"
"\n" "\n"
"[KEEPER95]\n" "[KEEPER95]\n"
"border=false\n" "border=false\n"
@ -242,7 +245,7 @@ static void CreateSettingsIni()
"posY=0\n" "posY=0\n"
"\n" "\n"
"[DKReign]\n" "[DKReign]\n"
"sleep=10\n" "maxgameticks=60\n"
"\n" "\n"
, fh); , fh);

View File

@ -199,8 +199,8 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR
SwitchToThread(); SwitchToThread();
} }
if (ddraw->sleep > 0) if (ddraw->ticklength > 0)
Sleep(ddraw->sleep); LimitGameTicks();
} }
return DD_OK; return DD_OK;
@ -366,8 +366,8 @@ HRESULT __stdcall ddraw_surface_Flip(IDirectDrawSurfaceImpl *This, LPDIRECTDRAWS
SwitchToThread(); SwitchToThread();
} }
if (ddraw->sleep > 0) if (ddraw->ticklength > 0)
Sleep(ddraw->sleep); LimitGameTicks();
} }
return DD_OK; return DD_OK;