veeenu / hudhook

A videogame overlay framework written in Rust, supporting DirectX and OpenGL
MIT License
185 stars 27 forks source link

make pipeline reports `delta_time` to imgui #187

Closed ruby3141 closed 4 months ago

ruby3141 commented 4 months ago

According to imgui's custom backend implementation exhibit and first-party backend implementations, io.DeltaTime is "usually" meant to be updated by backend code.

(you can check platform backend impls of ocornut/imgui for example)

This PR solves issue #186.

ruby3141 commented 4 months ago

imgui prohibits IO.DeltaTime of 0 when it's not in its first frame, \ but Duration::ZERO will be boundary checked by imgui::Io::update_delta_time() into f32::MIN_POSITIVE seconds. https://github.com/ocornut/imgui/blob/a1566c5e1ba22755c359e3079f5f25ab53f1eafb/imgui.cpp#L9784 https://github.com/imgui-rs/imgui-rs/blob/cb8beeb74cceec787275ec3e121c0068ba08fbf7/imgui/src/io.rs#L435-L437

I've considered Duration::from_nanos(1) instead of Duration::ZERO, but turns out it was too large.

f32::MIN_POSITIVE seconds is small enough not to actually increment global timer(which is f64 btw) while being positive. it is about 0.000000000000000000000000000000000000011754944 seconds, or 0.00000001 quectoseconds, and when added into f64 global timer, which is usually larger than 1, it just rounded down into zero. (It has about 30 zeros too many. In f64, the very next value after 1 is 1.0000000000000002.)

veeenu commented 4 months ago

That's great, thank you!