Fixed choppiness with variable framerate.

Note: framerate seemed to decrease, may be due to processes at the time.
This commit is contained in:
Harrison Deng 2020-07-10 23:48:30 -05:00
parent 110c7dbfad
commit 1f8bc5fb61

View File

@ -83,6 +83,7 @@ namespace SlatedGameToolkit.Framework {
DateTime previousTime = DateTime.Now;
TimeSpan timePassedFromLastUpdate = TimeSpan.Zero;
TimeSpan timePassedFromLastRender = TimeSpan.Zero;
TimeSpan updateTimePassedFromLastRender =TimeSpan.Zero;
TimeSpan updateDeltaTime = GameEngine.updateDeltaTime;
TimeSpan frameDeltaTime = GameEngine.frameDeltaTime;
deltaChanged = true;
@ -160,6 +161,7 @@ namespace SlatedGameToolkit.Framework {
previousTime = frameStart;
timePassedFromLastUpdate += difference;
updateTimePassedFromLastRender += difference;
while (timePassedFromLastUpdate > updateDeltaTime) {
//Updates.
manager.Update(updateDeltaTime.TotalSeconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds);
@ -173,7 +175,14 @@ namespace SlatedGameToolkit.Framework {
timePassedFromLastRender += difference;
if (timePassedFromLastRender > frameDeltaTime) {
//Draw calls.
manager.Render(updateDeltaTime.TotalSeconds <= 0 ? 1 : Math.Max(timePassedFromLastUpdate / updateDeltaTime, 0));
double prog = updateTimePassedFromLastRender / updateDeltaTime;
if (prog > 1) {
prog = 1;
} else if (prog < 0) {
prog = 0;
}
manager.Render(updateDeltaTime.TotalSeconds <= 0 ? 1 : prog);
updateTimePassedFromLastRender = TimeSpan.Zero;
timePassedFromLastRender = TimeSpan.Zero;
} else {
Thread.Yield();