[UI] add crude fps limiter for games that are too fast

This commit is contained in:
Cancerous 2020-01-25 13:11:00 -05:00 committed by illusion98
parent fb5cf78e82
commit 90012608ce
3 changed files with 32 additions and 1 deletions

View File

@ -26,6 +26,8 @@
#include "xenia/kernel/kernel_state.h" #include "xenia/kernel/kernel_state.h"
#include "xenia/kernel/user_module.h" #include "xenia/kernel/user_module.h"
DECLARE_bool(fps_limit);
namespace xe { namespace xe {
namespace gpu { namespace gpu {
@ -806,7 +808,7 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingBuffer* reader,
uint32_t count) { uint32_t count) {
SCOPE_profile_cpu_f("gpu"); SCOPE_profile_cpu_f("gpu");
XELOGI("XE_SWAP"); XELOGD("XE_SWAP");
Profiler::Flip(); Profiler::Flip();
@ -828,6 +830,19 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingBuffer* reader,
} }
++counter_; ++counter_;
// crude FPS limiter until one of you does a better implementation
if(cvars::fps_limit) {
if (xe::Clock::QueryHostSystemTime() > swap_update_time_ns_ + 16666) {
swap_update_time_ns_ = xe::Clock::QueryHostSystemTime();
} else {
xe::threading::MaybeYield();
xe::threading::Sleep(std::chrono::nanoseconds((swap_update_time_ns_ +
16666) - xe::Clock::QueryHostSystemTime()));
}
}
return true; return true;
} }

View File

@ -260,6 +260,8 @@ class CommandProcessor {
std::wstring trace_stream_path_; std::wstring trace_stream_path_;
std::wstring trace_frame_path_; std::wstring trace_frame_path_;
uint64_t swap_update_time_ns_ = 0;
std::atomic<bool> worker_running_; std::atomic<bool> worker_running_;
kernel::object_ref<kernel::XHostThread> worker_thread_; kernel::object_ref<kernel::XHostThread> worker_thread_;

View File

@ -18,9 +18,12 @@
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/profiling.h" #include "xenia/base/profiling.h"
#include "xenia/ui/imgui_drawer.h" #include "xenia/ui/imgui_drawer.h"
#include "xenia/cpu/thread.h"
DEFINE_bool(fps_titlebar, true, "Show FPS in titlebar", "General"); DEFINE_bool(fps_titlebar, true, "Show FPS in titlebar", "General");
DEFINE_bool(fps_limit, false, "try to limit 2d games from being too fast", "Video");
namespace xe { namespace xe {
namespace ui { namespace ui {
@ -178,6 +181,17 @@ void Window::OnPaint(UIEvent* e) {
++frame_count_; ++frame_count_;
++fps_frame_count_; ++fps_frame_count_;
uint64_t now_ns = xe::Clock::QueryHostSystemTime(); uint64_t now_ns = xe::Clock::QueryHostSystemTime();
// crude FPS limiter until one of you does a better implementation
if(cvars::fps_limit) {
if (now_ns > fps_update_time_ns_ + 16666) {
// do nothing
} else {
xe::threading::Sleep(std::chrono::nanoseconds((fps_update_time_ns_ +
16666) - now_ns));
}
}
if (now_ns > fps_update_time_ns_ + 1000 * 10000) { if (now_ns > fps_update_time_ns_ + 1000 * 10000) {
fps_ = static_cast<uint32_t>( fps_ = static_cast<uint32_t>(
fps_frame_count_ / fps_frame_count_ /