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-ira
for suggesting this idea to me months ago)As a quick background, both
Update
andFixedUpdate
follow "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
Time
API usable inFixedUpdate
, with the goal of making plugin systems more portable. IfTime
is setup so the clock is correct in bothUpdate
andFixedUpdate
, 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
Update
andFixedUpdate
equivalents.Some other issues:
FixedUpdate
takes longer than the fixed timestep, the app can enter a "death spiral" and ultimately freeze as each frame sees an ever-increasing queue ofFixedUpdate
steps and never catches up.FixedUpdate
simulation debt. The app will seem to freeze until it catches up.Solution
Clock
data structure to reduce code duplication.Time
report "fixed time" while runningFixedUpdate
.FixedUpdate
steps per frame. This will spread "paying off a large simulation debt" over multiple frames.FixedUpdate
steps can build up between two updates).I moved the "real time" (same speed as
Instant
) clock into a separateRealTime
resource. Maybe having all three clocks crammed insideTime
would 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
FixedTimestep
struct 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
FixedTimestep
andTime
instead of hard-coded constants.FixedTime::period
withTime::delta
.FixedTime
methods withFixedTimestep
equivalents.on_fixed_timer
has been removed. Replace it withon_timer
asTime
now works correctly in both schedules.Footnotes
On some platforms. ↩