Game.Timestep is now public

main
cosmonaut 2022-08-11 21:55:12 -07:00
parent f06ad263b7
commit c649b24dad
1 changed files with 6 additions and 7 deletions

View File

@ -12,11 +12,10 @@ namespace MoonWorks
public abstract class Game public abstract class Game
{ {
public TimeSpan MAX_DELTA_TIME = TimeSpan.FromMilliseconds(100); public TimeSpan MAX_DELTA_TIME = TimeSpan.FromMilliseconds(100);
public TimeSpan Timestep { get; private set; }
private bool quit = false; private bool quit = false;
private Stopwatch gameTimer; private Stopwatch gameTimer;
private TimeSpan timestep;
private long previousTicks = 0; private long previousTicks = 0;
TimeSpan accumulatedUpdateTime = TimeSpan.Zero; TimeSpan accumulatedUpdateTime = TimeSpan.Zero;
TimeSpan accumulatedDrawTime = TimeSpan.Zero; TimeSpan accumulatedDrawTime = TimeSpan.Zero;
@ -51,7 +50,7 @@ namespace MoonWorks
bool debugMode = false bool debugMode = false
) )
{ {
timestep = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / targetTimestep); Timestep = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / targetTimestep);
gameTimer = Stopwatch.StartNew(); gameTimer = Stopwatch.StartNew();
FramerateCapped = framerateSettings.Mode == FramerateMode.Capped; FramerateCapped = framerateSettings.Mode == FramerateMode.Capped;
@ -159,17 +158,17 @@ namespace MoonWorks
if (!quit) if (!quit)
{ {
while (accumulatedUpdateTime >= timestep) while (accumulatedUpdateTime >= Timestep)
{ {
Inputs.Update(); Inputs.Update();
AudioDevice.Update(); AudioDevice.Update();
Update(timestep); Update(Timestep);
accumulatedUpdateTime -= timestep; accumulatedUpdateTime -= Timestep;
} }
var alpha = accumulatedUpdateTime / timestep; var alpha = accumulatedUpdateTime / Timestep;
Draw(alpha); Draw(alpha);
accumulatedDrawTime -= FramerateCapTimeSpan; accumulatedDrawTime -= FramerateCapTimeSpan;