feat: fixed-timestep update loop decoupled from render - #185
Merged
Conversation
Split engine::tick() into an accumulator-driven fixed-step update and a variable-rate render so simulation behaviour no longer depends on frame rate. core::time gains fixed-delta accounting: accumulate() feeds elapsed wall-clock time into a clamped accumulator (the spiral-of-death guard caps it at max_steps_per_frame), next_fixed_step() drains whole steps, and interpolation_alpha() exposes the remainder for render-time smoothing. Game-logic (core::frame) now fires once per fixed step, driven by the engine; window::tick() only pumps input per rendered frame. The render_* events still fire per render inside renderer->render(), and scene-graph component propagation runs once per frame before the draw walk. Closes #168
CI build artifactsWindows Debug and Release builds are attached to the workflow run summary under Artifacts:
Run #254 — commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #168. Splits
engine::tick()into a fixed-step update decoupled from a variable-rate render, so deterministic gameplay, animation, and physics no longer depend on frame rate.Changes
core::time— fixed-delta accounting alongside the existing wall-clock delta:accumulate(frame_delta_time)feeds elapsed real time into an accumulator, clamped tomax_steps_per_framesteps — the spiral-of-death guard (a slow frame falls behind real time rather than queueing an unbounded backlog).next_fixed_step()drains one whole fixed step; drive withwhile (time->next_fixed_step()) { update(); }.interpolation_alpha()exposes the leftover remainder in[0, 1)for render-time smoothing between simulated states.fixed_delta_time()accessor; rate + clamp are constructor parameters (default 60 Hz, 5 steps).runtime::engine::tick— pumps input once per rendered frame, drains the accumulator emittingcore::frameper fixed step (game logic), then propagates scene-graph transforms and renders once.render_*events still fire per render insiderenderer->render().window::tick— no longer emitscore::frame; it now only pumps OS input at the variable render rate.Where update vs. render fire
core::frame(game-logic update). Carries the fixed delta, so per-second motion is preserved across frame rates — behaviour-preserving for the existing demos.scenes->update()(transform propagation), and therender_scene/render_ui/render_debugevents.Tests
tests/core/time_test.cppcovers draining, remainder carry-over across frames,interpolation_alphabounds, and the spiral-of-death clamp.core/time.cppwired into the headless test target.clang-formatandclang-tidynaming gates pass; Release build + the 7 new tests pass locally.Closes #168