-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPBGE: Fix and simplify frame time management. (#852)
Previously a commit introduce for external clock the targeting of one frame at every call to NextFrame, not more. The original behaviour is if the user enabled fixed framerate then compute as many as frame possible respecting the FPS value (m_ticrate). This behaviour is restored in the refactor. The refactor is simplyfing the time calculation and isolating it. The function KX_KetsjiEngine::GetFrameTimes is returning a struct FrameTimes with the number of frames to proceed and the time/frame step. Inside this function we first update the clock time if the user isn't (case of external clock) then the elapsed time is computed. Next the timestep and frame number are computed using fixed value or elapsed time. The number of frame is clamped by max logic/physics frame using the simple method: If the number of frame is higher than the maximum for logic or physics, then clamp it and set timestep to the elasped time (which is always greater than fixed time step 1/FPS) divided by the maximum number of frames. Finally if the user is not using fixed framerate update the previous clock else if the number of frames to proceed is zero sleep. Issue were noticed using a sleep, they were caused by the resolution of the sleep which is about some ~10us, to fix this a part of the sleep is consumed with std::this_thread::sleep_for and the rest is busy wait. CM_Clock has now a function Reset to ensure it starts from 0, this is useful for external clock starting at 0.
- Loading branch information
1 parent
bde85e2
commit e9b0780
Showing
4 changed files
with
96 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
e9b0780
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This thing is still not separating the logic from the drawing code. The logic and graphics need to run independently at different rates. Variable rates. Not fixed.