From eafe85d96b0e0381f9368b317f1a383a8f218976 Mon Sep 17 00:00:00 2001 From: Sulter Date: Sun, 26 Jul 2020 19:28:29 +0200 Subject: [PATCH] Added fast-forward functionality --- Source/Config/ConfigOptions.cpp | 1 + Source/Config/ConfigOptions.h | 1 + Source/Core/CPU.cpp | 3 +- Source/HLEAudio/AudioBuffer.cpp | 2 +- Source/SysVita/UI/InGameMenuScreen.cpp | 46 +++++++++++++++++++++++--- Source/SysVita/UI/Menu.h | 18 ++++++++++ 6 files changed, 65 insertions(+), 6 deletions(-) diff --git a/Source/Config/ConfigOptions.cpp b/Source/Config/ConfigOptions.cpp index c4ecd429..a4d1aacb 100644 --- a/Source/Config/ConfigOptions.cpp +++ b/Source/Config/ConfigOptions.cpp @@ -44,5 +44,6 @@ bool gFogEnabled = false; // Enable fog bool gMemoryAccessOptimisation = false; // Enable the memory access optimisation bool gCheatsEnabled = true; // Enable cheat codes u32 gControllerIndex = 0; // Which controller config to set +bool gFastForward = false; DaedalusConfig g_DaedalusConfig; diff --git a/Source/Config/ConfigOptions.h b/Source/Config/ConfigOptions.h index 6839936e..779650e9 100644 --- a/Source/Config/ConfigOptions.h +++ b/Source/Config/ConfigOptions.h @@ -49,6 +49,7 @@ extern bool gVideoRateMatch; extern bool gFogEnabled; extern bool gMemoryAccessOptimisation; extern bool gCheatsEnabled; +extern bool gFastForward; //ToDo: Needs moving to Graphics plugin config extern bool gCleanSceneEnabled; extern u32 gCheckTextureHashFrequency; diff --git a/Source/Core/CPU.cpp b/Source/Core/CPU.cpp index 67e453cb..c88ef1ac 100644 --- a/Source/Core/CPU.cpp +++ b/Source/Core/CPU.cpp @@ -673,7 +673,8 @@ void CPU_HANDLE_COUNT_INTERRUPT() gVerticalInterrupts++; - FramerateLimiter_Limit(); + if(!gFastForward) + FramerateLimiter_Limit(); #ifdef DAEDALUS_W32 if (gAudioPlugin != nullptr) gAudioPlugin->Update(false); diff --git a/Source/HLEAudio/AudioBuffer.cpp b/Source/HLEAudio/AudioBuffer.cpp index 669c06f5..bfba77b6 100644 --- a/Source/HLEAudio/AudioBuffer.cpp +++ b/Source/HLEAudio/AudioBuffer.cpp @@ -121,7 +121,7 @@ void CAudioBuffer::AddSamples( const Sample * samples, u32 num_samples, u32 freq if( write_ptr >= mBufferEnd ) write_ptr = mBufferBegin; - while( write_ptr == read_ptr ) + while( write_ptr == read_ptr && !gFastForward) { // The buffer is full - spin until the read pointer advances. // Note - spends a lot of time here if program is running diff --git a/Source/SysVita/UI/InGameMenuScreen.cpp b/Source/SysVita/UI/InGameMenuScreen.cpp index a94b3d2b..ca5dc240 100644 --- a/Source/SysVita/UI/InGameMenuScreen.cpp +++ b/Source/SysVita/UI/InGameMenuScreen.cpp @@ -30,8 +30,37 @@ #include "SysVita/UI/Menu.h" static uint64_t tmr1; -static uint32_t oldpad; bool pause_emu = false; +ButtonSce selectBtn {false, 0, 500000, SCE_CTRL_SELECT}; + +int update_button(ButtonSce* btn, const SceCtrlData* pad, uint32_t ticks) +{ + if ((pad->buttons & btn->btn) && !btn->down){ + btn->down = true; + btn->downTime = ticks; + return BUTTON_SHORT_HOLD; + } else if (!(pad->buttons & btn->btn) && btn->down){ + btn->down = false; + uint32_t deltaTime = ticks - btn->downTime; + if(deltaTime > btn->longPressTime){ + return BUTTON_LONG_RELEASED; + } + else { + return BUTTON_SHORT_RELEASED; + } + } else if ((pad->buttons & btn->btn) && btn->down){ + uint32_t deltaTime = ticks - btn->downTime; + if(deltaTime > btn->longPressTime){ + return BUTTON_LONG_HOLD; + } + else { + return BUTTON_SHORT_HOLD; + } + } + else { + return BUTTON_NEUTRAL; + } +} void DrawInGameMenu() { DrawInGameMenuBar(); @@ -53,12 +82,21 @@ void DrawInGameMenu() { show_menubar = !gHideMenubar; } - // Handling emulation pause + // Handling select button (menu pause and fast-forward) SceCtrlData pad; sceCtrlPeekBufferPositive(0, &pad, 1); - if ((pad.buttons & SCE_CTRL_SELECT) && (!(oldpad & SCE_CTRL_SELECT))) { + int statusSelectBtn = update_button(&selectBtn, &pad, sceKernelGetProcessTimeWide()); + if(statusSelectBtn == BUTTON_SHORT_RELEASED){ pause_emu = !pause_emu; EnableMenuButtons(pause_emu); + } else if(statusSelectBtn == BUTTON_LONG_HOLD){ + if(!gFastForward && !pause_emu){ + gFastForward = true; + vglWaitVblankStart(GL_FALSE); + } + } + else if(statusSelectBtn == BUTTON_LONG_RELEASED){ + gFastForward = false; + vglWaitVblankStart(gUseVSync); } - oldpad = pad.buttons; } diff --git a/Source/SysVita/UI/Menu.h b/Source/SysVita/UI/Menu.h index 7a9b3be7..cf269170 100644 --- a/Source/SysVita/UI/Menu.h +++ b/Source/SysVita/UI/Menu.h @@ -246,6 +246,15 @@ enum { MEM_DOWNLOAD }; +// Button status types +enum { + BUTTON_SHORT_HOLD, + BUTTON_SHORT_RELEASED, + BUTTON_LONG_HOLD, + BUTTON_LONG_RELEASED, + BUTTON_NEUTRAL +}; + struct Download { void (*post_func)(); char url[256]; @@ -277,6 +286,13 @@ struct Overlay { Overlay *next; }; +struct ButtonSce { + bool down; + uint32_t downTime; + uint32_t longPressTime; + const SceCtrlButtons btn; +}; + extern Dialog cur_dialog; extern Alert cur_alert; extern Download cur_download; @@ -349,3 +365,5 @@ void extract_file(char *file, char *dir); int download_file(char *url, char *file, char *msg, float int_total_bytes, bool has_temp_file); void dummy_func(); + +int update_button(ButtonSce* btn, const SceCtrlData* pad, uint32_t ticks);