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++; 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. 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(); AudBlankSound();
} }
} else { } else {
pBurnDraw = NULL; // Do one frame w/RunAhead pBurnDraw = (BurnDrvGetFlags() & BDF_RUNAHEAD_DRAWSYNC) ? pVidImage : NULL;
BurnDrvFrame(); BurnDrvFrame();
StateRunAheadSave(); StateRunAheadSave();
pBurnSoundOut = NULL; INT16 *pBurnSoundOut_temp = pBurnSoundOut;
VidFrame(); pBurnSoundOut = NULL;
StateRunAheadLoad(); 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) VidPaint(0); // paint the screen (no need to validate)
} } else { // frame skipping
else
{ // frame skipping
pBurnDraw = NULL; // Make sure no image is drawn pBurnDraw = NULL; // Make sure no image is drawn
BurnDrvFrame(); BurnDrvFrame();
} }
@ -346,8 +363,8 @@ int RunExit()
#ifdef BUILD_SDL2 #ifdef BUILD_SDL2
void pause_game() void pause_game()
{ {
AudSoundStop(); AudSoundStop();
if(nVidSelect) { if(nVidSelect) {
// no Text in OpenGL... // no Text in OpenGL...
SDL_GL_SwapWindow(sdlWindow); SDL_GL_SwapWindow(sdlWindow);
@ -355,12 +372,12 @@ void pause_game()
inprint_shadowed(sdlRenderer, "PAUSE", 10, 10); inprint_shadowed(sdlRenderer, "PAUSE", 10, 10);
SDL_RenderPresent(sdlRenderer); SDL_RenderPresent(sdlRenderer);
} }
int finished = 0; int finished = 0;
while (!finished) while (!finished)
{ {
starting_stick = SDL_GetTicks(); starting_stick = SDL_GetTicks();
SDL_Event e; SDL_Event e;
while (SDL_PollEvent(&e)) while (SDL_PollEvent(&e))
@ -381,9 +398,9 @@ void pause_game()
break; break;
} }
} }
if (e.type == SDL_WINDOWEVENT) if (e.type == SDL_WINDOWEVENT)
{ // Window Event { // Window Event
switch (e.window.event) switch (e.window.event)
{ {
//case SDL_WINDOWEVENT_RESTORED: // keep pause when restore window //case SDL_WINDOWEVENT_RESTORED: // keep pause when restore window
case SDL_WINDOWEVENT_FOCUS_GAINED: 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) { if ( ( 1000 / 5 ) > SDL_GetTicks() - starting_stick) {
SDL_Delay( 1000 / 5 - ( SDL_GetTicks() - starting_stick ) ); SDL_Delay( 1000 / 5 - ( SDL_GetTicks() - starting_stick ) );
} }
} }
AudSoundPlay(); AudSoundPlay();
} }
#endif #endif
@ -421,7 +438,7 @@ int RunMessageLoop()
while (!quit) while (!quit)
{ {
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
@ -433,16 +450,16 @@ int RunMessageLoop()
#ifdef BUILD_SDL2 #ifdef BUILD_SDL2
case SDL_WINDOWEVENT: // Window Event case SDL_WINDOWEVENT: // Window Event
switch (event.window.event) switch (event.window.event)
{ {
case SDL_WINDOWEVENT_MINIMIZED: case SDL_WINDOWEVENT_MINIMIZED:
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
pause_game(); pause_game();
break; break;
} }
break; break;
#endif #endif
case SDL_KEYDOWN: // need to find a nicer way of doing this... case SDL_KEYDOWN: // need to find a nicer way of doing this...
switch (event.key.keysym.sym) switch (event.key.keysym.sym)
{ {
@ -474,9 +491,9 @@ int RunMessageLoop()
pause_game(); pause_game();
} }
break; break;
case SDLK_RETURN: case SDLK_RETURN:
if (event.key.keysym.mod & KMOD_ALT) if (event.key.keysym.mod & KMOD_ALT)
{ {
SetFullscreen(!GetFullscreen()); SetFullscreen(!GetFullscreen());
AdjustImageSize(); AdjustImageSize();
@ -516,7 +533,7 @@ int RunMessageLoop()
case SDLK_F1: case SDLK_F1:
bAppDoFast = 0; bAppDoFast = 0;
break; break;
case SDLK_F6: case SDLK_F6:
bscreenshot = 0; bscreenshot = 0;
break; break;
case SDLK_F12: case SDLK_F12:
@ -529,7 +546,7 @@ int RunMessageLoop()
break; break;
} }
} }
RunIdle(); RunIdle();
} }