Port over win32 runahead fixes to SDL (#1770)

* Port over win32 runahead fixes to SDL

* Fix formatting
This commit is contained in:
Jason Han 2024-05-05 06:18:10 -07:00 committed by GitHub
parent c46b16f225
commit acea063357
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,23 +160,40 @@ static int RunFrame(int bDraw, int bPause)
{
nFramesRendered++;
if (!bRunAhead || bAppDoFast) { // Run-Ahead feature -dink aug 02, 2021
if (!bRunAhead || (BurnDrvGetFlags() & BDF_RUNAHEAD_DISABLED) || bAppDoFast) { // Run-Ahead feature -dink aug 02, 2021
if (VidFrame()) { // Do one frame w/o RunAhead or if FFWD is pressed.
// VidFrame() failed, but we must run a driver frame because we have
// a clocked input. Possibly from recording or netplay(!)
// Note: VidFrame() calls BurnDrvFrame() on success.
pBurnDraw = NULL; // Make sure no image is drawn
BurnDrvFrame();
AudBlankSound();
}
} else {
pBurnDraw = NULL; // Do one frame w/RunAhead
BurnDrvFrame();
StateRunAheadSave();
pBurnSoundOut = NULL;
VidFrame();
StateRunAheadLoad();
pBurnDraw = (BurnDrvGetFlags() & BDF_RUNAHEAD_DRAWSYNC) ? pVidImage : NULL;
BurnDrvFrame();
StateRunAheadSave();
INT16 *pBurnSoundOut_temp = pBurnSoundOut;
pBurnSoundOut = NULL;
nCurrentFrame++;
bBurnRunAheadFrame = 1;
if (VidFrame()) {
// VidFrame() failed, but we must run a driver frame because we have
// an input. Possibly from recording or netplay(!)
pBurnDraw = NULL; // Make sure no image is drawn, since video failed this time 'round.
BurnDrvFrame();
}
bBurnRunAheadFrame = 0;
nCurrentFrame--;
StateRunAheadLoad();
pBurnSoundOut = pBurnSoundOut_temp; // restore pointer, for wav & avi writer
}
VidPaint(0); // paint the screen (no need to validate)
}
else
{ // frame skipping
} else { // frame skipping
pBurnDraw = NULL; // Make sure no image is drawn
BurnDrvFrame();
}
@ -346,8 +363,8 @@ int RunExit()
#ifdef BUILD_SDL2
void pause_game()
{
AudSoundStop();
AudSoundStop();
if(nVidSelect) {
// no Text in OpenGL...
SDL_GL_SwapWindow(sdlWindow);
@ -355,12 +372,12 @@ void pause_game()
inprint_shadowed(sdlRenderer, "PAUSE", 10, 10);
SDL_RenderPresent(sdlRenderer);
}
int finished = 0;
while (!finished)
{
starting_stick = SDL_GetTicks();
SDL_Event e;
while (SDL_PollEvent(&e))
@ -381,9 +398,9 @@ void pause_game()
break;
}
}
if (e.type == SDL_WINDOWEVENT)
if (e.type == SDL_WINDOWEVENT)
{ // Window Event
switch (e.window.event)
switch (e.window.event)
{
//case SDL_WINDOWEVENT_RESTORED: // keep pause when restore window
case SDL_WINDOWEVENT_FOCUS_GAINED:
@ -398,15 +415,15 @@ void pause_game()
}
}
}
// limit 5 FPS (free CPU usage)
// limit 5 FPS (free CPU usage)
if ( ( 1000 / 5 ) > SDL_GetTicks() - starting_stick) {
SDL_Delay( 1000 / 5 - ( SDL_GetTicks() - starting_stick ) );
}
}
AudSoundPlay();
}
AudSoundPlay();
}
#endif
@ -421,7 +438,7 @@ int RunMessageLoop()
while (!quit)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
@ -433,16 +450,16 @@ int RunMessageLoop()
#ifdef BUILD_SDL2
case SDL_WINDOWEVENT: // Window Event
switch (event.window.event)
switch (event.window.event)
{
case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_FOCUS_LOST:
pause_game();
break;
}
break;
break;
#endif
case SDL_KEYDOWN: // need to find a nicer way of doing this...
switch (event.key.keysym.sym)
{
@ -474,9 +491,9 @@ int RunMessageLoop()
pause_game();
}
break;
case SDLK_RETURN:
if (event.key.keysym.mod & KMOD_ALT)
if (event.key.keysym.mod & KMOD_ALT)
{
SetFullscreen(!GetFullscreen());
AdjustImageSize();
@ -516,7 +533,7 @@ int RunMessageLoop()
case SDLK_F1:
bAppDoFast = 0;
break;
case SDLK_F6:
case SDLK_F6:
bscreenshot = 0;
break;
case SDLK_F12:
@ -529,7 +546,7 @@ int RunMessageLoop()
break;
}
}
RunIdle();
}