mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Implement a frame limiter.
This commit is contained in:
parent
11dea728fd
commit
939f4a4771
5 changed files with 45 additions and 1 deletions
5
.gitmodules
vendored
5
.gitmodules
vendored
|
|
@ -57,4 +57,7 @@
|
|||
url = https://github.com/martinus/unordered_dense.git
|
||||
[submodule "thirdparty/SDL_mixer"]
|
||||
path = thirdparty/SDL_mixer
|
||||
url = https://github.com/libsdl-org/SDL_mixer
|
||||
url = https://github.com/libsdl-org/SDL_mixer
|
||||
[submodule "thirdparty/implot"]
|
||||
path = thirdparty/implot
|
||||
url = https://github.com/epezent/implot.git
|
||||
|
|
|
|||
|
|
@ -6,6 +6,32 @@
|
|||
#include <user/config.h>
|
||||
#include <os/process.h>
|
||||
|
||||
void FrameLimiter::execute(int64_t fps)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
auto next = start + frame * 1000000000ns / fps;
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
if (next > now && (next - now) < (2000000000ns / fps))
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::floor<std::chrono::milliseconds>(next - now - 1ms));
|
||||
|
||||
while ((now = std::chrono::steady_clock::now()) < next)
|
||||
std::this_thread::yield();
|
||||
}
|
||||
|
||||
frame = std::chrono::nanoseconds(std::chrono::steady_clock::now() - start).count() * fps / 1000000000ll + 1;
|
||||
}
|
||||
|
||||
static FrameLimiter g_frameLimiter;
|
||||
|
||||
void ApplicationUpdateMidAsmHook()
|
||||
{
|
||||
if (Config::FPS >= 15 && Config::FPS < 240)
|
||||
g_frameLimiter.execute(Config::FPS);
|
||||
}
|
||||
|
||||
void App::Restart(std::vector<std::string> restartArgs)
|
||||
{
|
||||
os::process::StartProcess(os::process::GetExecutablePath(), restartArgs, os::process::GetWorkingDirectory());
|
||||
|
|
@ -48,3 +74,4 @@ PPC_FUNC(sub_822C1130)
|
|||
|
||||
__imp__sub_822C1130(ctx, base);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
#include <user/config.h>
|
||||
|
||||
struct FrameLimiter
|
||||
{
|
||||
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
||||
int64_t frame = 0;
|
||||
|
||||
void execute(int64_t fps);
|
||||
};
|
||||
|
||||
class App
|
||||
{
|
||||
public:
|
||||
|
|
@ -15,3 +23,4 @@ public:
|
|||
static void Restart(std::vector<std::string> restartArgs = {});
|
||||
static void Exit();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -588,3 +588,7 @@ registers = ["r3"]
|
|||
name = "PostureDPadSupportMidAsmHook"
|
||||
address = 0x823CDA2C
|
||||
registers = ["r3"]
|
||||
|
||||
[[midasm_hook]]
|
||||
name = "ApplicationUpdateMidAsmHook"
|
||||
address = 0x822C0EC8
|
||||
|
|
|
|||
1
thirdparty/implot
vendored
Submodule
1
thirdparty/implot
vendored
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 77674d270e851d3f3718aad00234201af2b76ac9
|
||||
Loading…
Add table
Reference in a new issue