game state now changes on next update
parent
9862bfd0a0
commit
0e8188682e
14
src/Game.cs
14
src/Game.cs
|
@ -31,7 +31,9 @@ namespace MoonWorks
|
||||||
public AudioDevice AudioDevice { get; }
|
public AudioDevice AudioDevice { get; }
|
||||||
public Inputs Inputs { get; }
|
public Inputs Inputs { get; }
|
||||||
|
|
||||||
|
// FIXME: maybe the user should just manage this stuff
|
||||||
private GameState GameState = null;
|
private GameState GameState = null;
|
||||||
|
private GameState NextState = null;
|
||||||
|
|
||||||
private Dictionary<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
|
private Dictionary<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
|
||||||
{
|
{
|
||||||
|
@ -80,7 +82,7 @@ namespace MoonWorks
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (GameState == null)
|
if (NextState == null)
|
||||||
{
|
{
|
||||||
throw new NullReferenceException("Must call SetState before Run!");
|
throw new NullReferenceException("Must call SetState before Run!");
|
||||||
}
|
}
|
||||||
|
@ -100,8 +102,7 @@ namespace MoonWorks
|
||||||
|
|
||||||
public void SetState(GameState gameState)
|
public void SetState(GameState gameState)
|
||||||
{
|
{
|
||||||
GameState = gameState;
|
NextState = gameState;
|
||||||
GameState.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Tick()
|
private void Tick()
|
||||||
|
@ -149,6 +150,13 @@ namespace MoonWorks
|
||||||
Inputs.Update();
|
Inputs.Update();
|
||||||
AudioDevice.Update();
|
AudioDevice.Update();
|
||||||
|
|
||||||
|
if (NextState != null)
|
||||||
|
{
|
||||||
|
GameState = NextState;
|
||||||
|
GameState.Start();
|
||||||
|
NextState = null;
|
||||||
|
}
|
||||||
|
|
||||||
GameState.Update(timestep);
|
GameState.Update(timestep);
|
||||||
|
|
||||||
accumulatedElapsedTime -= timestep;
|
accumulatedElapsedTime -= timestep;
|
||||||
|
|
Loading…
Reference in New Issue