Unify FixedTime and Time (ver. B) (proof-of-concept)
#8946
Closed
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.
This is an alternative to #8930 (pretty similar though).
(credit to
@devil-irafor suggesting this idea to me months ago)As a quick background, both
UpdateandFixedUpdatefollow "virtual" time (time that can be sped up, slowed down, and paused) but each needs its own clock to measure it because they advance at different rates.Objective
I wrote this PR to make the
TimeAPI usable inFixedUpdate, with the goal of making plugin systems more portable. IfTimeis setup so the clock is correct in bothUpdateandFixedUpdate, then users can write and import systems that accessRes<Time>and they'll always work no matter which scheduled they're added to.This would take us off a path that leads to some really annoying compatibility issues that plague third-party code in other engines (e.g. store assets for Unity) because their logic can't be freely moved between their
UpdateandFixedUpdateequivalents.Some other issues:
FixedUpdatetakes longer than the fixed timestep, the app can enter a "death spiral" and ultimately freeze as each frame sees an ever-increasing queue ofFixedUpdatesteps and never catches up.FixedUpdatesimulation debt. The app will seem to freeze until it catches up.Solution
Clockdata structure to reduce code duplication.Timereport "fixed time" while runningFixedUpdate.FixedUpdatesteps per frame. This will spread "paying off a large simulation debt" over multiple frames.FixedUpdatesteps can build up between two updates).I moved the "real time" (same speed as
Instant) clock into a separateRealTimeresource. Maybe having all three clocks crammed insideTimewould have been better, but (1) I didn't like the look of having clock-specific methods (e.g.time.delta(),time.raw_delta(),time.fixed_delta()) and (2) "real time" is pretty meaningless inFixedUpdate. More breaking changes though.I've also kept a
FixedTimestepstruct because keeping the step size and accumulator separate from the clock is much cleaner IMO and leaves room for, say, a networking plugin to sub in its own handling (without requiring more API from us).Migration Guide
FixedTimestepandTimeinstead of hard-coded constants.FixedTime::periodwithTime::delta.FixedTimemethods withFixedTimestepequivalents.on_fixed_timerhas been removed. Replace it withon_timerasTimenow works correctly in both schedules.Footnotes
On some platforms. ↩