[UI] add crude fps limiter for games that are too fast
This commit is contained in:
parent
fb5cf78e82
commit
90012608ce
|
@ -26,6 +26,8 @@
|
|||
#include "xenia/kernel/kernel_state.h"
|
||||
#include "xenia/kernel/user_module.h"
|
||||
|
||||
DECLARE_bool(fps_limit);
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
||||
|
@ -806,7 +808,7 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingBuffer* reader,
|
|||
uint32_t count) {
|
||||
SCOPE_profile_cpu_f("gpu");
|
||||
|
||||
XELOGI("XE_SWAP");
|
||||
XELOGD("XE_SWAP");
|
||||
|
||||
Profiler::Flip();
|
||||
|
||||
|
@ -828,6 +830,19 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingBuffer* reader,
|
|||
}
|
||||
|
||||
++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;
|
||||
}
|
||||
|
||||
|
|
|
@ -260,6 +260,8 @@ class CommandProcessor {
|
|||
std::wstring trace_stream_path_;
|
||||
std::wstring trace_frame_path_;
|
||||
|
||||
uint64_t swap_update_time_ns_ = 0;
|
||||
|
||||
std::atomic<bool> worker_running_;
|
||||
kernel::object_ref<kernel::XHostThread> worker_thread_;
|
||||
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/profiling.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_limit, false, "try to limit 2d games from being too fast", "Video");
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
|
@ -178,6 +181,17 @@ void Window::OnPaint(UIEvent* e) {
|
|||
++frame_count_;
|
||||
++fps_frame_count_;
|
||||
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) {
|
||||
fps_ = static_cast<uint32_t>(
|
||||
fps_frame_count_ /
|
||||
|
|
Loading…
Reference in New Issue