Skip to content

Commit

Permalink
Disable FPS idling settings when remoting
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Apr 12, 2024
1 parent 435d5d1 commit c9cb432
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 35 deletions.
2 changes: 1 addition & 1 deletion external/netImgui
11 changes: 11 additions & 0 deletions src/hello_imgui/impl/hello_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ ImGuiTestEngine* GetImGuiTestEngine() { return nullptr; }
#endif


bool _isDisplayingOnRemoteServer()
{
return true;
#ifdef HELLOIMGUI_WITH_NETIMGUI
return HelloImGui::GetRunnerParams()->remoteParams.enableRemoting;
#else
return false;
#endif
}


void SaveUserPref(const std::string& userPrefName, const std::string& userPrefContent)
{
gLastRunner->SaveUserPref(userPrefName, userPrefContent);
Expand Down
8 changes: 4 additions & 4 deletions src/hello_imgui/impl/hello_imgui_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ namespace HelloImGui
return dpiResponsiveFont;
}

bool _ReloadAllDpiResponsiveFonts()
bool _reloadAllDpiResponsiveFonts()
{
if (gWasLoadFontBareCalled)
{
fprintf(stderr, "_ReloadAllDpiResponsiveFonts failed: ony call LoadFontDpiResponsive if you want this to work\n");
fprintf(stderr, "_reloadAllDpiResponsiveFonts failed: ony call LoadFontDpiResponsive if you want this to work\n");
return false;
}
if (gAllDpiResponsiveFonts.empty())
return false;
printf("_ReloadAllDpiResponsiveFonts\n");
printf("_reloadAllDpiResponsiveFonts\n");
auto& imguiFonts = ImGui::GetIO().Fonts;
imguiFonts->Clear();
for (auto & dpiResponsiveFont : gAllDpiResponsiveFonts)
Expand All @@ -275,7 +275,7 @@ namespace HelloImGui
dpiResponsiveFont.font = newFont;
}
bool buildSuccess = imguiFonts->Build();
IM_ASSERT(buildSuccess && "_ReloadAllDpiResponsiveFonts: Failed to build fonts");
IM_ASSERT(buildSuccess && "_reloadAllDpiResponsiveFonts: Failed to build fonts");
return true;
}

Expand Down
35 changes: 23 additions & 12 deletions src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ namespace HelloImGui
void setFinalAppWindowScreenshotRgbBuffer(const ImageBuffer& b);

// Encapsulated inside hello_imgui_font.cpp
bool _ReloadAllDpiResponsiveFonts();
bool _reloadAllDpiResponsiveFonts();
bool _isDisplayingOnRemoteServer();


// =====================================================================================================================
Expand Down Expand Up @@ -990,6 +991,7 @@ void AbstractRunner::RenderGui()

void _UpdateFrameRateStats(); // See hello_imgui.cpp


void AbstractRunner::CreateFramesAndRender()
{
// Notes:
Expand Down Expand Up @@ -1026,7 +1028,7 @@ void AbstractRunner::CreateFramesAndRender()

if (_CheckDpiAwareParamsChanges(params)) // Reload fonts if DPI scale changed
{
if (_ReloadAllDpiResponsiveFonts())
if (_reloadAllDpiResponsiveFonts())
{
printf("_CheckDpiAwareParamsChanges returned true => reloaded all fonts\n");
// cf https://github.com/ocornut/imgui/issues/6547: we need to recreate the rendering backend device objects
Expand All @@ -1042,12 +1044,6 @@ void AbstractRunner::CreateFramesAndRender()
}
}

if (foldable_region) // Update frame rate stats
{
_UpdateFrameRateStats();
// printf("Render frame %i, fps=%.1f\n", mIdxFrame, HelloImGui::FrameRate());
}

if (foldable_region) // basic layout checks
{ // SCOPED_RELEASE_GIL_ON_MAIN_THREAD start
SCOPED_RELEASE_GIL_ON_MAIN_THREAD;
Expand Down Expand Up @@ -1151,7 +1147,7 @@ void AbstractRunner::CreateFramesAndRender()
#ifndef __EMSCRIPTEN__
// Idling for non emscripten, where HelloImGui is responsible for the main loop.
// This form of idling will call WaitForEventTimeout(), which may call sleep():
IdleBySleeping();
IdleBySleeping();
#endif

// Poll Events (this fills GImGui.InputEventsQueue)
Expand All @@ -1168,7 +1164,13 @@ void AbstractRunner::CreateFramesAndRender()
#endif
} // SCOPED_RELEASE_GIL_ON_MAIN_THREAD end

if (foldable_region) // Load additional fonts during execution
if (foldable_region) // Update frame rate stats
{
_UpdateFrameRateStats();
// printf("Render frame %i, fps=%.1f\n", mIdxFrame, HelloImGui::FrameRate());
}

if (foldable_region) // Load additional fonts during execution
{
if (params.callbacks.LoadAdditionalFonts != nullptr)
{
Expand Down Expand Up @@ -1286,9 +1288,18 @@ void AbstractRunner::IdleBySleeping()
#ifdef HELLOIMGUI_WITH_TEST_ENGINE
if (params.useImGuiTestEngine && TestEngineCallbacks::IsRunningTest())
return;
#endif
#endif

if (_isDisplayingOnRemoteServer())
{
// if displaying remote, the FPS is limited on the server to a value between 30 and 60 fps
// We cannot idle too slow, other the GUI becomes really sluggish
// Ideally, we should ask the server about it current refresh rate
// (At the moment, we can only deliver 30fps)
params.fpsIdling.fpsIdle = 30.f;
}

assert(params.fpsIdling.fpsIdle >= 0.f);
assert(params.fpsIdling.fpsIdle >= 0.f);
params.fpsIdling.isIdling = false;
if ((params.fpsIdling.fpsIdle > 0.f) && params.fpsIdling.enableIdling)
{
Expand Down
19 changes: 12 additions & 7 deletions src/hello_imgui/internal/docking_details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

namespace HelloImGui
{
// From hello_imgui.cpp
bool _isDisplayingOnRemoteServer();


void _Themes_MenuGui(RunnerParams& runnerParams); // see hello_imgui_themes.cpp

std::map<DockSpaceName, ImGuiID> gImGuiSplitIDs;
Expand Down Expand Up @@ -171,14 +175,15 @@ void MenuView_Misc(RunnerParams& runnerParams)
if (ImGui::MenuItem("View Status bar##xxxx", nullptr, runnerParams.imGuiWindowParams.showStatusBar))
runnerParams.imGuiWindowParams.showStatusBar = ! runnerParams.imGuiWindowParams.showStatusBar;

if (ImGui::BeginMenu("FPS"))
{
if (ImGui::MenuItem("FPS in status bar##xxxx", nullptr, runnerParams.imGuiWindowParams.showStatus_Fps))
runnerParams.imGuiWindowParams.showStatus_Fps = ! runnerParams.imGuiWindowParams.showStatus_Fps;
if (ImGui::BeginMenu("FPS"))
{
if (ImGui::MenuItem("FPS in status bar##xxxx", nullptr, runnerParams.imGuiWindowParams.showStatus_Fps))
runnerParams.imGuiWindowParams.showStatus_Fps = ! runnerParams.imGuiWindowParams.showStatus_Fps;

ImGui::MenuItem("Enable Idling", nullptr, &runnerParams.fpsIdling.enableIdling);
ImGui::EndMenu();
}
if (! _isDisplayingOnRemoteServer())
ImGui::MenuItem("Enable Idling", nullptr, &runnerParams.fpsIdling.enableIdling);
ImGui::EndMenu();
}

if (runnerParams.imGuiWindowParams.showMenu_View_Themes)
Theme_MenuGui(runnerParams.imGuiWindowParams.tweakedTheme);
Expand Down
30 changes: 19 additions & 11 deletions src/hello_imgui/internal/menu_statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace HelloImGui
{
bool _isDisplayingOnRemoteServer(); // from hello_imgui.cpp

namespace Menu_StatusBar
{

Expand Down Expand Up @@ -97,17 +99,23 @@ void ShowStatusBar(RunnerParams & params)

if (params.imGuiWindowParams.showStatus_Fps)
{
float dy = ImGui::GetFontSize() * 0.15f;

ImGui::SameLine(ImGui::GetIO().DisplaySize.x - 14.f * ImGui::GetFontSize());

const char* idlingInfo = params.fpsIdling.isIdling ? " (Idling)" : "";

ImGui::SetCursorPosY(ImGui::GetCursorPosY() - dy); // The checkbox seems visually misaligned, let's fix this
ImGui::Checkbox("Enable idling", &params.fpsIdling.enableIdling);
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - dy);
ImGui::Text("FPS: %.1f%s", HelloImGui::FrameRate(), idlingInfo);
if (_isDisplayingOnRemoteServer())
{
ImGui::SameLine(ImGui::GetIO().DisplaySize.x - 5.f * ImGui::GetFontSize());
ImGui::Text("FPS: %.1f", HelloImGui::FrameRate());
}
else
{
float dy = ImGui::GetFontSize() * 0.15f;

ImGui::SameLine(ImGui::GetIO().DisplaySize.x - 14.f * ImGui::GetFontSize());
const char* idlingInfo = params.fpsIdling.isIdling ? " (Idling)" : "";
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - dy); // The checkbox seems visually misaligned, let's fix this
ImGui::Checkbox("Enable idling", &params.fpsIdling.enableIdling);
ImGui::SameLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - dy);
ImGui::Text("FPS: %.1f%s", HelloImGui::FrameRate(), idlingInfo);
}
}

ImGui::End();
Expand Down

0 comments on commit c9cb432

Please sign in to comment.