From e7622ebbd6992c6dfe66bf74a09f605d4db5044d Mon Sep 17 00:00:00 2001 From: Steven Cherry Date: Thu, 9 May 2013 19:36:23 -0500 Subject: [PATCH] Custom Fps Limiter First time contributing. Set FPS limit on second page of graphics settings. Press Tab key or on 360 controller, press left stick to toggle between 3 states. --- Core/Config.h | 1 + Core/CoreParameter.h | 2 + Core/HLE/sceDisplay.cpp | 27 +- UI/EmuScreen.cpp | 27 +- UI/MenuScreens.cpp | 20 +- Windows/PPSSPP.vcxproj | 726 +++++++++++++++++++------------------- Windows/WndMainWindow.cpp | 4 + 7 files changed, 430 insertions(+), 377 deletions(-) diff --git a/Core/Config.h b/Core/Config.h index 85ac8833e4..e439e9a9c9 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -78,6 +78,7 @@ public: int iTexScalingLevel; // 1 = off, 2 = 2x, ..., 5 = 5x int iTexScalingType; // 0 = xBRZ, 1 = Hybrid bool bTexDeposterize; + int iFpsLimit; // Sound bool bEnableSound; diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index 5b9124860f..e4fdf176d7 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -66,4 +66,6 @@ struct CoreParameter // Can be modified at runtime. bool unthrottle; + int fpsLimit; + double customLimit; }; diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 1939c85c80..03b9969668 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -278,9 +278,10 @@ void __DisplayGetDebugStats(char stats[2048]) } // Let's collect all the throttling and frameskipping logic here. -void DoFrameTiming(bool &throttle, bool &skipFrame) { +void DoFrameTiming(bool &throttle, bool &skipFrame, int &fpsLimiter, double &customLimiter) { throttle = !PSP_CoreParameter().unthrottle; - + fpsLimiter = PSP_CoreParameter().fpsLimit; + customLimiter = g_Config.iFpsLimit; skipFrame = false; if (PSP_CoreParameter().headLess) throttle = false; @@ -309,7 +310,7 @@ void DoFrameTiming(bool &throttle, bool &skipFrame) { curFrameTime = time_now_d(); if (nextFrameTime == 0.0) - nextFrameTime = time_now_d() + 1.0 / 60.0; + nextFrameTime = time_now_d() + 1.0 / 60; if (curFrameTime > nextFrameTime && doFrameSkip) { // Argh, we are falling behind! Let's skip a frame and see if we catch up. @@ -321,8 +322,8 @@ void DoFrameTiming(bool &throttle, bool &skipFrame) { if (curFrameTime < nextFrameTime && throttle) { // If time gap is huge just jump (somebody unthrottled) - if (nextFrameTime - curFrameTime > 1.0 / 30.0) { - nextFrameTime = curFrameTime + 1.0 / 60.0; + if (nextFrameTime - curFrameTime > 1.0 / 30) { + nextFrameTime = curFrameTime + 1.0 / 60; } else { // Wait until we've catched up. while (time_now_d() < nextFrameTime) { @@ -336,10 +337,16 @@ void DoFrameTiming(bool &throttle, bool &skipFrame) { // but don't let it get too far behind as things can get very jumpy. const double maxFallBehindFrames = 5.5; - if (throttle || doFrameSkip) { + // 3 states of fps limiter + if (fpsLimiter == 0) { nextFrameTime = std::max(nextFrameTime + 1.0 / 60.0, time_now_d() - maxFallBehindFrames / 60.0); - } else { - nextFrameTime = nextFrameTime + 1.0 / 60.0; + } else if (fpsLimiter == 1) { + nextFrameTime = std::max(nextFrameTime + 1.0 / customLimiter, time_now_d() - maxFallBehindFrames / customLimiter); + } else if (fpsLimiter == 2) { + nextFrameTime = std::max(nextFrameTime + 1.0 / 2000.0, time_now_d() - maxFallBehindFrames / 2000.0); + } + else { + nextFrameTime = nextFrameTime + 1.0 / 60; } // Max 4 skipped frames in a row - 15 fps is really the bare minimum for playability. @@ -402,8 +409,10 @@ void hleEnterVblank(u64 userdata, int cyclesLate) { gstate_c.skipDrawReason &= ~SKIPDRAW_SKIPFRAME; bool throttle, skipFrame; + int fpsLimiter; + double customLimiter; - DoFrameTiming(throttle, skipFrame); + DoFrameTiming(throttle, skipFrame, fpsLimiter, customLimiter); if (skipFrame) { gstate_c.skipDrawReason |= SKIPDRAW_SKIPFRAME; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 50a6f95a45..6dc06bcfd9 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -214,11 +214,30 @@ void EmuScreen::update(InputState &input) { __CtrlSetAnalog(stick_x, stick_y, 0); __CtrlSetAnalog(rightstick_x, rightstick_x, 1); - if (input.pad_buttons & PAD_BUTTON_LEFT_THUMB) { - PSP_CoreParameter().unthrottle = true; - } else { - PSP_CoreParameter().unthrottle = false; + //if (input.pad_buttons & PAD_BUTTON_LEFT_THUMB) { + // PSP_CoreParameter().unthrottle = true; + //} else { + //PSP_CoreParameter().unthrottle = false; + //} + // Make sure fpsLimit starts at 0 + if (PSP_CoreParameter().fpsLimit != 0 && PSP_CoreParameter().fpsLimit != 1 && PSP_CoreParameter().fpsLimit != 2) { + PSP_CoreParameter().fpsLimit = 0; } + //Toggle between 3 different states of fpsLimit + if (input.pad_buttons_down & PAD_BUTTON_LEFT_THUMB) { + if (PSP_CoreParameter().fpsLimit == 0){ + PSP_CoreParameter().fpsLimit = 1; + } + else if (PSP_CoreParameter().fpsLimit == 1){ + PSP_CoreParameter().fpsLimit = 2; + } + else if (PSP_CoreParameter().fpsLimit == 2){ + PSP_CoreParameter().fpsLimit = 0; + } + } + + + if (input.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK | PAD_BUTTON_RIGHT_THUMB)) { if (g_Config.bBufferedRendering) diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 892467437b..8c00e9e1a9 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -764,7 +764,25 @@ void GraphicsScreenP2::render() { } else { g_Config.iAnisotropyLevel = 0; } - + bool FpsLimit = g_Config.iFpsLimit != 0; + UICheckBox(GEN_ID, x, y += stride + 15, gs->T("Fps Limit"), ALIGN_TOPLEFT, &FpsLimit); + if (FpsLimit) { + if (g_Config.iFpsLimit == 0) + g_Config.iFpsLimit = 60; + + ui_draw2d.DrawText(UBUNTU24, gs->T("Fps :"), x + 60, y += stride, 0xFFFFFFFF, ALIGN_LEFT); + HLinear hlinear1(x + 160 , y, 20); + if (UIButton(GEN_ID, hlinear1, 45, 0, "90", ALIGN_LEFT)) + g_Config.iFpsLimit = 90; + if (UIButton(GEN_ID, hlinear1, 45, 0, "120", ALIGN_LEFT)) + g_Config.iFpsLimit = 120; + if (UIButton(GEN_ID, hlinear1, 45, 0, "180", ALIGN_LEFT)) + g_Config.iFpsLimit = 180; + if (UIButton(GEN_ID, hlinear1, 45, 0, "240", ALIGN_LEFT)) + g_Config.iFpsLimit = 240; + } else { + g_Config.iFpsLimit = 60; + } bool TexScaling = g_Config.iTexScalingLevel > 1; UICheckBox(GEN_ID, x, y += stride + 15, gs->T("xBRZ Texture Scaling"), ALIGN_TOPLEFT, &TexScaling); if (TexScaling) { diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index 0a47f37212..e602b4efe8 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -1,364 +1,364 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {567AF8DB-42C1-4D08-96CD-D70A2DFEFC6B} - DaSh - Win32Proj - PPSSPPWindows - - - - Application - MultiByte - false - - - Application - MultiByte - - - Application - MultiByte - false - - - Application - MultiByte - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\ - true - ..\ - $(Platform)\$(Configuration)\ - true - ..\ - $(Configuration)\ - false - ..\ - $(Platform)\$(Configuration)\ - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - ..\ - PPSSPPDebug - - - PPSSPPDebug64 - - - PPSSPPWindows64 - - - - Disabled - WIN32;_DEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS - true - Sync - Use - Level3 - EditAndContinue - ../common;..;../native;../native/ext/glew;../ext/zlib - stdafx.h - MultiThreadedDebugDLL - StreamingSIMDExtensions2 - Fast - - - XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;glu32.lib;comctl32.lib;dsound.lib;xinput.lib;%(AdditionalDependencies) - true - Windows - MachineX86 - $(OutDir)$(TargetName)$(TargetExt) - false - true - 0x00400000 - true - - - - - X64 - - - Disabled - WIN32;_DEBUG;%(PreprocessorDefinitions) - true - Sync - Use - Level3 - ProgramDatabase - ../common;..;../native;../native/ext/glew;../ext/zlib - stdafx.h - MultiThreadedDebugDLL - false - StreamingSIMDExtensions2 - Fast - - - XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;glu32.lib;comctl32.lib;dsound.lib;%(AdditionalDependencies) - true - $(OutDir)$(ProjectName).pdb - Windows - MachineX64 - false - true - 0x00400000 - true - - - - - AnySuitable - true - Speed - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS - true - Sync - MultiThreadedDLL - false - StreamingSIMDExtensions2 - Fast - Use - Level3 - ProgramDatabase - ../common;..;../native;../native/ext/glew;../ext/zlib - stdafx.h - stdafx.h - - - XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;dsound.lib;glu32.lib;comctl32.lib;%(AdditionalDependencies) - $(OutDir)$(TargetName)$(TargetExt) - %(AdditionalLibraryDirectories) - true - Windows - true - true - MachineX86 - /ignore:4049 %(AdditionalOptions) - UseLinkTimeCodeGeneration - 0x00400000 - false - true - true - true - - - - - X64 - - - AnySuitable - true - Speed - false - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - Sync - MultiThreadedDLL - false - StreamingSIMDExtensions2 - Fast - Use - Level3 - ProgramDatabase - ../common;..;../native;../native/ext/glew;../ext/zlib - stdafx.h - - - XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;comctl32.lib;%(AdditionalDependencies) - %(AdditionalLibraryDirectories) - true - Windows - true - true - MachineX64 - 0x00400000 - false - true - - - - - true - true - true - true - - - - NotUsing - - - NotUsing - - - NotUsing - - - NotUsing - - - - - - - - - - - - - - - - $(IntDir)%(Filename)2.obj - $(IntDir)%(Filename)2.obj - $(IntDir)%(Filename)2.obj - $(IntDir)%(Filename)2.obj - - - - - - - - - - - - Create - Create - Create - Create - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {3fcdbae2-5103-4350-9a8e-848ce9c73195} - - - {533f1d30-d04d-47cc-ad71-20f658907e36} - - - {3baae095-e0ab-4b0e-b5df-ce39c8ae31de} - - - {457f45d2-556f-47bc-a31d-aff0d15beaed} - - - {C4DF647E-80EA-4111-A0A8-218B1B711E18} - - - {f761046e-6c38-4428-a5f1-38391a37bb34} - - - {004b8d11-2be3-4bd9-ab40-2be04cf2096f} - - - - - - - - - - + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {567AF8DB-42C1-4D08-96CD-D70A2DFEFC6B} + DaSh + Win32Proj + PPSSPPWindows + + + + Application + MultiByte + false + + + Application + MultiByte + + + Application + MultiByte + false + + + Application + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(Configuration)\ + true + ..\ + $(Platform)\$(Configuration)\ + true + ..\Bin + $(Configuration)\ + false + ..\ + $(Platform)\$(Configuration)\ + false + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + ..\ + PPSSPPDebug + + + PPSSPPDebug64 + + + PPSSPPWindows64 + + + + Disabled + WIN32;_DEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + true + Sync + Use + Level3 + EditAndContinue + ../common;..;../native;../native/ext/glew;../ext/zlib + stdafx.h + MultiThreadedDebugDLL + StreamingSIMDExtensions2 + Fast + + + XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;glu32.lib;comctl32.lib;dsound.lib;xinput.lib;%(AdditionalDependencies) + true + Windows + MachineX86 + $(OutDir)$(TargetName)$(TargetExt) + false + true + 0x00400000 + true + + + + + X64 + + + Disabled + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + Sync + Use + Level3 + ProgramDatabase + ../common;..;../native;../native/ext/glew;../ext/zlib + stdafx.h + MultiThreadedDebugDLL + false + StreamingSIMDExtensions2 + Fast + + + XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;glu32.lib;comctl32.lib;dsound.lib;%(AdditionalDependencies) + true + $(OutDir)$(ProjectName).pdb + Windows + MachineX64 + false + true + 0x00400000 + true + + + + + AnySuitable + true + Speed + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + true + Sync + MultiThreadedDLL + false + StreamingSIMDExtensions2 + Fast + Use + Level3 + ProgramDatabase + ../common;..;../native;../native/ext/glew;../ext/zlib + stdafx.h + stdafx.h + + + XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;..\ffmpeg\Windows\x86\lib\avcodec.lib;..\ffmpeg\Windows\x86\lib\avdevice.lib;..\ffmpeg\Windows\x86\lib\avformat.lib;..\ffmpeg\Windows\x86\lib\avutil.lib;..\ffmpeg\Windows\x86\lib\swresample.lib;..\ffmpeg\Windows\x86\lib\swscale.lib;dsound.lib;glu32.lib;comctl32.lib;%(AdditionalDependencies) + $(OutDir)$(TargetName)$(TargetExt) + %(AdditionalLibraryDirectories) + true + Windows + true + true + MachineX86 + /ignore:4049 %(AdditionalOptions) + UseLinkTimeCodeGeneration + 0x00400000 + false + true + true + true + + + + + X64 + + + AnySuitable + true + Speed + false + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + Sync + MultiThreadedDLL + false + StreamingSIMDExtensions2 + Fast + Use + Level3 + ProgramDatabase + ../common;..;../native;../native/ext/glew;../ext/zlib + stdafx.h + + + XInput.lib;Winmm.lib;Ws2_32.lib;opengl32.lib;dsound.lib;glu32.lib;comctl32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + true + Windows + true + true + MachineX64 + 0x00400000 + false + true + + + + + true + true + true + true + + + + NotUsing + + + NotUsing + + + NotUsing + + + NotUsing + + + + + + + + + + + + + + + + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.obj + $(IntDir)%(Filename)2.obj + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {3fcdbae2-5103-4350-9a8e-848ce9c73195} + + + {533f1d30-d04d-47cc-ad71-20f658907e36} + + + {3baae095-e0ab-4b0e-b5df-ce39c8ae31de} + + + {457f45d2-556f-47bc-a31d-aff0d15beaed} + + + {C4DF647E-80EA-4111-A0A8-218B1B711E18} + + + {f761046e-6c38-4428-a5f1-38391a37bb34} + + + {004b8d11-2be3-4bd9-ab40-2be04cf2096f} + + + + + + + + + + \ No newline at end of file diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index a701fd2c60..5d38cbf55a 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -185,6 +185,10 @@ namespace MainWindow g_Config.iTexScalingType = num; if(gpu) gpu->ClearCacheNextFrame(); } + void setFpsLimit(int fps) { + g_Config.iFpsLimit = fps; + if(gpu) gpu->ClearCacheNextFrame(); + } BOOL Show(HINSTANCE hInstance, int nCmdShow) {