Roblox backend: optional SetBusyRenderRate (lower redraw rate while scrolling/resizing/moving)

This commit is contained in:
4DBug
2026-10-08 11:43:31 -05:00
parent ab108d288b
commit c4816a4237
4 changed files with 47 additions and 7 deletions
+22 -3
View File
@@ -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,
}