From 0e8188682ea7e4206a66007fad948eb8600ee7df Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 23 May 2022 19:12:27 -0700 Subject: [PATCH] game state now changes on next update --- src/Game.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Game.cs b/src/Game.cs index 7d31dd2c..835fd8c7 100644 --- a/src/Game.cs +++ b/src/Game.cs @@ -31,7 +31,9 @@ namespace MoonWorks public AudioDevice AudioDevice { get; } public Inputs Inputs { get; } + // FIXME: maybe the user should just manage this stuff private GameState GameState = null; + private GameState NextState = null; private Dictionary moonWorksToRefreshPresentMode = new Dictionary { @@ -80,7 +82,7 @@ namespace MoonWorks public void Run() { #if DEBUG - if (GameState == null) + if (NextState == null) { throw new NullReferenceException("Must call SetState before Run!"); } @@ -100,8 +102,7 @@ namespace MoonWorks public void SetState(GameState gameState) { - GameState = gameState; - GameState.Start(); + NextState = gameState; } private void Tick() @@ -149,6 +150,13 @@ namespace MoonWorks Inputs.Update(); AudioDevice.Update(); + if (NextState != null) + { + GameState = NextState; + GameState.Start(); + NextState = null; + } + GameState.Update(timestep); accumulatedElapsedTime -= timestep;