From bdfb45bca7d8aacaa3e6be6cff4e72958df62cd1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Jan 2026 09:25:58 -0800 Subject: [PATCH] imgui delta time needs to use float math Our prior math converted to float after int which made our delta time wrong making hovers and stuff not work. --- src/apprt/embedded.zig | 7 ++++--- src/apprt/gtk/class/imgui_widget.zig | 12 ++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index a035caf62..2fbae8fdf 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -1205,10 +1205,11 @@ pub const Inspector = struct { // Determine our delta time const now = try std.time.Instant.now(); io.DeltaTime = if (self.instant) |prev| delta: { - const since_ns = now.since(prev); - const since_s: f32 = @floatFromInt(since_ns / std.time.ns_per_s); + const since_ns: f64 = @floatFromInt(now.since(prev)); + const ns_per_s: f64 = @floatFromInt(std.time.ns_per_s); + const since_s: f32 = @floatCast(since_ns / ns_per_s); break :delta @max(0.00001, since_s); - } else (1 / 60); + } else (1.0 / 60.0); self.instant = now; } }; diff --git a/src/apprt/gtk/class/imgui_widget.zig b/src/apprt/gtk/class/imgui_widget.zig index 79e85fad2..8ad75f5d0 100644 --- a/src/apprt/gtk/class/imgui_widget.zig +++ b/src/apprt/gtk/class/imgui_widget.zig @@ -131,21 +131,17 @@ pub const ImguiWidget = extern struct { /// Initialize the frame. Expects that the context is already current. fn newFrame(self: *Self) void { - // If we can't determine the time since the last frame we default to - // 1/60th of a second. - const default_delta_time = 1 / 60; - const priv = self.private(); - const io: *cimgui.c.ImGuiIO = cimgui.c.ImGui_GetIO(); // Determine our delta time const now = std.time.Instant.now() catch unreachable; io.DeltaTime = if (priv.instant) |prev| delta: { - const since_ns = now.since(prev); - const since_s: f32 = @floatFromInt(since_ns / std.time.ns_per_s); + const since_ns: f64 = @floatFromInt(now.since(prev)); + const ns_per_s: f64 = @floatFromInt(std.time.ns_per_s); + const since_s: f32 = @floatCast(since_ns / ns_per_s); break :delta @max(0.00001, since_s); - } else default_delta_time; + } else (1.0 / 60.0); priv.instant = now; }