From c4816a423783c002d3bac62b1f2587ea9875a716 Mon Sep 17 00:00:00 2001 From: 4DBug <4DBug@github.com> Date: Thu, 8 Oct 2026 11:43:31 -0500 Subject: [PATCH] Roblox backend: optional SetBusyRenderRate (lower redraw rate while scrolling/resizing/moving) --- build/ImGui.linemap.json | 2 +- build/ImGui.luau | 26 +++++++++++++++++++++++--- imgui/backend/imgui_impl_roblox.lua | 25 ++++++++++++++++++++++--- main.client.luau | 1 + 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/build/ImGui.linemap.json b/build/ImGui.linemap.json index 15d7489..3d48d17 100644 --- a/build/ImGui.linemap.json +++ b/build/ImGui.linemap.json @@ -1 +1 @@ -[[12, "imgui.lua"], [13795, "imgui_demo.lua"], [14728, "imgui_demo_2.lua"], [17803, "imgui_demo_apps.lua"], [19062, "imgui_demo_tools.lua"], [20388, "imgui_demo_widgets.lua"], [22312, "imgui_docking.lua"], [25440, "imgui_dragdrop.lua"], [25732, "imgui_draw.lua"], [30979, "imgui_h.lua"], [33153, "imgui_impl_roblox.lua"], [34121, "imgui_impl_roblox_fonts.lua"], [40524, "imgui_internal.lua"], [43696, "imgui_tables.lua"], [48043, "imgui_tabs.lua"], [49210, "imgui_widgets.lua"], [57744, "imstb_rectpack.lua"], [58190, "imstb_textedit.lua"], [59431, "imstb_truetype.lua"], [61899, "imstd_minstdio.lua"]] \ No newline at end of file +[[12, "imgui.lua"], [13795, "imgui_demo.lua"], [14728, "imgui_demo_2.lua"], [17803, "imgui_demo_apps.lua"], [19062, "imgui_demo_tools.lua"], [20388, "imgui_demo_widgets.lua"], [22312, "imgui_docking.lua"], [25440, "imgui_dragdrop.lua"], [25732, "imgui_draw.lua"], [30979, "imgui_h.lua"], [33153, "imgui_impl_roblox.lua"], [34140, "imgui_impl_roblox_fonts.lua"], [40543, "imgui_internal.lua"], [43715, "imgui_tables.lua"], [48062, "imgui_tabs.lua"], [49229, "imgui_widgets.lua"], [57763, "imstb_rectpack.lua"], [58209, "imstb_textedit.lua"], [59450, "imstb_truetype.lua"], [61918, "imstd_minstdio.lua"]] \ No newline at end of file diff --git a/build/ImGui.luau b/build/ImGui.luau index 69d9474..00cac61 100644 --- a/build/ImGui.luau +++ b/build/ImGui.luau @@ -33718,10 +33718,23 @@ function ImGui_ImplRoblox_RenderDrawData(draw_data) PE() -- Render rate cap: textures are always updated (imgui expects it), tiles only at bd.RenderRate Hz - if bd.RenderRate > 0 then + -- Optional lower cap while scrolling / resizing / moving a window (SetBusyRenderRate, off by default) + local rate = bd.RenderRate + if bd.BusyRenderRate > 0 then + local g = ImGui.GetCurrentContext() + local busy = g.WheelingWindow ~= nil or g.MovingWindow ~= nil -- (io.MouseWheel is already cleared by EndFrame) + if not busy and g.ActiveId ~= 0 then + local w = g.ActiveIdWindow + local cur = g.MouseCursor -- ResizeAll..ResizeNWSE while a resize grip/border is held + busy = (cur >= ImGuiMouseCursor.ResizeAll and cur <= ImGuiMouseCursor.ResizeNWSE) + or (w ~= nil and (g.ActiveId == ImGui.GetWindowScrollbarID(w, ImGuiAxis.X) or g.ActiveId == ImGui.GetWindowScrollbarID(w, ImGuiAxis.Y))) + end + if busy and (rate <= 0 or bd.BusyRenderRate < rate) then rate = bd.BusyRenderRate end + end + if rate > 0 then local now = os.clock() if now + 0.002 < bd.NextRender then PE(); return end - bd.NextRender = math.max(bd.NextRender + 1 / bd.RenderRate, now) + bd.NextRender = math.max(bd.NextRender + 1 / rate, now) end local sw, sh = floor(draw_data.DisplaySize.x), floor(draw_data.DisplaySize.y) @@ -33980,7 +33993,7 @@ function ImGui_ImplRoblox_Init(parent, render_scale) local bd = { Time = os.clock(), Gui = gui, Connections = {}, Textures = {}, TextureCount = 0, MouseX = -1, MouseY = -1, - Layers = {}, FrameNo = 0, Scale = render_scale or 1, TilesActive = false, RenderRate = 60, NextRender = 0, LastPrimCount = 0, ForceRedraw = true, + Layers = {}, FrameNo = 0, Scale = render_scale or 1, TilesActive = false, RenderRate = 60, BusyRenderRate = 0, NextRender = 0, LastPrimCount = 0, ForceRedraw = true, } io.BackendPlatformUserData = bd @@ -34090,6 +34103,11 @@ function ImGui_ImplRoblox_SetRenderRate(hz) ImGui_ImplRoblox_GetBackendData().RenderRate = hz or 0 end +--- Optional: max tile redraws per second while scrolling, resizing or moving a window (0 = off, the default) +function ImGui_ImplRoblox_SetBusyRenderRate(hz) + ImGui_ImplRoblox_GetBackendData().BusyRenderRate = hz or 0 +end + --- Toggle MicroProfiler labels (debug.profilebegin) for the backend function ImGui_ImplRoblox_SetProfiling(enabled) profiling = enabled and true or false end local function ImGui_ImplRoblox_IsProfiling() return profiling end @@ -34110,6 +34128,7 @@ ImGui_ImplRoblox = { AddFile = ImGui_ImplRoblox_AddFile, SetRenderScale = ImGui_ImplRoblox_SetRenderScale, SetRenderRate = ImGui_ImplRoblox_SetRenderRate, + SetBusyRenderRate = ImGui_ImplRoblox_SetBusyRenderRate, SetProfiling = ImGui_ImplRoblox_SetProfiling, IsProfiling = ImGui_ImplRoblox_IsProfiling, } @@ -62511,6 +62530,7 @@ return { ImGui_ImplRoblox_Init = ImGui_ImplRoblox_Init, ImGui_ImplRoblox_NewFrame = ImGui_ImplRoblox_NewFrame, ImGui_ImplRoblox_RenderDrawData = ImGui_ImplRoblox_RenderDrawData, + ImGui_ImplRoblox_SetBusyRenderRate = ImGui_ImplRoblox_SetBusyRenderRate, ImGui_ImplRoblox_SetProfiling = ImGui_ImplRoblox_SetProfiling, ImGui_ImplRoblox_SetRenderRate = ImGui_ImplRoblox_SetRenderRate, ImGui_ImplRoblox_SetRenderScale = ImGui_ImplRoblox_SetRenderScale, diff --git a/imgui/backend/imgui_impl_roblox.lua b/imgui/backend/imgui_impl_roblox.lua index 20ea591..aca2693 100644 --- a/imgui/backend/imgui_impl_roblox.lua +++ b/imgui/backend/imgui_impl_roblox.lua @@ -566,10 +566,23 @@ function ImGui_ImplRoblox_RenderDrawData(draw_data) PE() -- Render rate cap: textures are always updated (imgui expects it), tiles only at bd.RenderRate Hz - if bd.RenderRate > 0 then + -- Optional lower cap while scrolling / resizing / moving a window (SetBusyRenderRate, off by default) + local rate = bd.RenderRate + if bd.BusyRenderRate > 0 then + local g = ImGui.GetCurrentContext() + local busy = g.WheelingWindow ~= nil or g.MovingWindow ~= nil -- (io.MouseWheel is already cleared by EndFrame) + if not busy and g.ActiveId ~= 0 then + local w = g.ActiveIdWindow + local cur = g.MouseCursor -- ResizeAll..ResizeNWSE while a resize grip/border is held + busy = (cur >= ImGuiMouseCursor.ResizeAll and cur <= ImGuiMouseCursor.ResizeNWSE) + or (w ~= nil and (g.ActiveId == ImGui.GetWindowScrollbarID(w, ImGuiAxis.X) or g.ActiveId == ImGui.GetWindowScrollbarID(w, ImGuiAxis.Y))) + end + if busy and (rate <= 0 or bd.BusyRenderRate < rate) then rate = bd.BusyRenderRate end + end + if rate > 0 then local now = os.clock() if now + 0.002 < bd.NextRender then PE(); return end - bd.NextRender = math.max(bd.NextRender + 1 / bd.RenderRate, now) + bd.NextRender = math.max(bd.NextRender + 1 / rate, now) end local sw, sh = floor(draw_data.DisplaySize.x), floor(draw_data.DisplaySize.y) @@ -828,7 +841,7 @@ function ImGui_ImplRoblox_Init(parent, render_scale) local bd = { Time = os.clock(), Gui = gui, Connections = {}, Textures = {}, TextureCount = 0, MouseX = -1, MouseY = -1, - Layers = {}, FrameNo = 0, Scale = render_scale or 1, TilesActive = false, RenderRate = 60, NextRender = 0, LastPrimCount = 0, ForceRedraw = true, + Layers = {}, FrameNo = 0, Scale = render_scale or 1, TilesActive = false, RenderRate = 60, BusyRenderRate = 0, NextRender = 0, LastPrimCount = 0, ForceRedraw = true, } io.BackendPlatformUserData = bd @@ -938,6 +951,11 @@ function ImGui_ImplRoblox_SetRenderRate(hz) ImGui_ImplRoblox_GetBackendData().RenderRate = hz or 0 end +--- Optional: max tile redraws per second while scrolling, resizing or moving a window (0 = off, the default) +function ImGui_ImplRoblox_SetBusyRenderRate(hz) + ImGui_ImplRoblox_GetBackendData().BusyRenderRate = hz or 0 +end + --- Toggle MicroProfiler labels (debug.profilebegin) for the backend function ImGui_ImplRoblox_SetProfiling(enabled) profiling = enabled and true or false end local function ImGui_ImplRoblox_IsProfiling() return profiling end @@ -958,6 +976,7 @@ ImGui_ImplRoblox = { AddFile = ImGui_ImplRoblox_AddFile, SetRenderScale = ImGui_ImplRoblox_SetRenderScale, SetRenderRate = ImGui_ImplRoblox_SetRenderRate, + SetBusyRenderRate = ImGui_ImplRoblox_SetBusyRenderRate, SetProfiling = ImGui_ImplRoblox_SetProfiling, IsProfiling = ImGui_ImplRoblox_IsProfiling, } diff --git a/main.client.luau b/main.client.luau index fa8751a..b3b7b7b 100755 --- a/main.client.luau +++ b/main.client.luau @@ -75,6 +75,7 @@ end ImGui_ImplRoblox.Init(nil, render_scale) ImGui_ImplRoblox.SetRenderRate(60) -- tile redraws per second; imgui logic + your code still run every frame +-- ImGui_ImplRoblox.SetBusyRenderRate(30) -- optional: lower redraw rate while scrolling/resizing/moving windows ImGui_ImplRoblox.SetProfiling(true) -- MicroProfiler (Ctrl+F6) labels; turn off when not profiling local function P(name) if ImGui_ImplRoblox.IsProfiling() then debug.profilebegin(name) end end