Fix/sprite frame timing - #2384
Open
Delfayne wants to merge 2 commits into
Open
Conversation
frameTime is added to the accumulator and again in the threshold test, so a frame advances one tick early. At 60fps a 50ms frame shows for 33ms, and the real rate tracks the display's refresh rate.
Resetting the accumulator discards the overshoot and rounds every period up to a whole frame interval. Subtracting the display time keeps the mean on target. DURATION must subtract it too, or the carried remainder gets counted twice and a timed animation ends early.
Author
|
Looks like it's blocked on the unrelated Mac stuff. I can look into that on the side if you need eyes |
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.
Spriteadvances frames early and discards the remainderorg.korge.engine:korge)7.0.0-SNAPSHOT; identical inv6.0.0korge/src/commonMain/kotlin/korlibs/korge/view/Sprite.kt,nextSprite(:285)commonMainSummary
A sprite shows each frame for about one frame interval less than
spriteDisplayTime, so animationsplay fast and their real speed depends on the display's refresh rate. Two independent causes, both in
nextSprite.Reproduction
Dispatch
UpdateEventat a fixed delta and count ticks between advances - no window needed:Each cell is short by roughly one frame interval of whatever display it runs on, which is why the
same
spriteDisplayTimeplays at a different speed on different hardware.Cause
1. The frame's delta is counted twice (
:286-287) - added to the accumulator, then added againin the test, so the threshold fires a whole tick early:
2. The accumulator is reset, not decremented (
:305), discarding however far past the thresholdit had gone. Every period is rounded up to a whole multiple of the frame interval with nothing to
compensate later:
Fix
DURATIONhas to change with it: once the remainder carries, the accumulator includes time theprevious advance already deducted. Counting it twice would end a timed animation early.
Measured after:
Notes
TileMapgets this right in the same package (view/tiles/TileMap.kt:407-411) - it counts thedelta once and subtracts the frame duration. The two animation paths currently disagree.
ifrather thanwhile, so neither can advance more than one frame per tick. Left alonehere: changing it converts slow-down-under-lag into frame-skipping, which is a behaviour choice
rather than a defect. I might be inclined to fix this under an engine flag, though