forked from MoonsideGames/MoonWorks
Game.Timestep is now public
parent
f06ad263b7
commit
c649b24dad
13
src/Game.cs
13
src/Game.cs
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue