mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-19 00:50:38 +00:00
keep framerate stable even without vsync (#2165)
This commit is contained in:
parent
56a6c95730
commit
8695383d35
7 changed files with 38 additions and 17 deletions
|
@ -187,7 +187,7 @@ ImGuiID NewFrame(bool is_reusing_frame) {
|
|||
ImGui::NewFrame();
|
||||
|
||||
ImGuiWindowFlags flags = ImGuiDockNodeFlags_PassthruCentralNode;
|
||||
if (!DebugState.ShowingDebugMenuBar()) {
|
||||
if (!DebugState.IsShowingDebugMenuBar()) {
|
||||
flags |= ImGuiDockNodeFlags_NoTabBar;
|
||||
}
|
||||
ImGuiID dockId = DockSpaceOverViewport(0, GetMainViewport(), flags);
|
||||
|
@ -237,6 +237,10 @@ void Render(const vk::CommandBuffer& cmdbuf, const vk::ImageView& image_view,
|
|||
}
|
||||
}
|
||||
|
||||
bool MustKeepDrawing() {
|
||||
return layers.size() > 1 || DebugState.IsShowingDebugMenuBar();
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
void Layer::AddLayer(Layer* layer) {
|
||||
|
|
|
@ -31,4 +31,6 @@ ImGuiID NewFrame(bool is_reusing_frame = false);
|
|||
void Render(const vk::CommandBuffer& cmdbuf, const vk::ImageView& image_view,
|
||||
const vk::Extent2D& extent);
|
||||
|
||||
bool MustKeepDrawing(); // Force the emulator redraw
|
||||
|
||||
} // namespace ImGui::Core
|
||||
|
|
|
@ -46,6 +46,11 @@ struct SdlData {
|
|||
ImVector<SDL_Gamepad*> gamepads{};
|
||||
GamepadMode gamepad_mode{};
|
||||
bool want_update_gamepads_list{};
|
||||
|
||||
// Framerate counting (based on ImGui impl)
|
||||
std::array<float, 60> framerateSecPerFrame;
|
||||
int framerateSecPerFrameIdx{};
|
||||
float framerateSecPerFrameAcc{};
|
||||
};
|
||||
|
||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui
|
||||
|
@ -812,12 +817,15 @@ void NewFrame(bool is_reusing_frame) {
|
|||
: 1.0f / 60.0f;
|
||||
bd->nonReusedtime = current_time;
|
||||
DebugState.FrameDeltaTime = deltaTime;
|
||||
float distribution = 0.016f / deltaTime / 10.0f;
|
||||
if (distribution > 1.0f) {
|
||||
distribution = 1.0f;
|
||||
}
|
||||
DebugState.Framerate =
|
||||
deltaTime * distribution + DebugState.Framerate * (1.0f - distribution);
|
||||
|
||||
int& frameIdx = bd->framerateSecPerFrameIdx;
|
||||
float& framerateSec = bd->framerateSecPerFrame[frameIdx];
|
||||
float& acc = bd->framerateSecPerFrameAcc;
|
||||
int count = bd->framerateSecPerFrame.size();
|
||||
acc += deltaTime - framerateSec;
|
||||
framerateSec = deltaTime;
|
||||
frameIdx = (frameIdx + 1) % count;
|
||||
DebugState.Framerate = acc > 0.0f ? 1.0f / (acc / (float)count) : FLT_MAX;
|
||||
}
|
||||
|
||||
if (bd->mouse_pending_leave_frame && bd->mouse_pending_leave_frame >= ImGui::GetFrameCount() &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue