revert Game and GameState change

main
cosmonaut 2022-06-01 18:31:22 -07:00
parent 0e8188682e
commit 5a9709c843
2 changed files with 5 additions and 51 deletions

View File

@ -9,7 +9,7 @@ using System.Diagnostics;
namespace MoonWorks
{
public class Game
public abstract class Game
{
public TimeSpan MAX_DELTA_TIME = TimeSpan.FromMilliseconds(100);
@ -31,10 +31,6 @@ 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<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
{
{ PresentMode.Immediate, RefreshCS.Refresh.PresentMode.Immediate },
@ -81,13 +77,6 @@ namespace MoonWorks
public void Run()
{
#if DEBUG
if (NextState == null)
{
throw new NullReferenceException("Must call SetState before Run!");
}
#endif
while (!quit)
{
Tick();
@ -100,10 +89,8 @@ namespace MoonWorks
SDL.SDL_Quit();
}
public void SetState(GameState gameState)
{
NextState = gameState;
}
protected abstract void Update(TimeSpan delta);
protected abstract void Draw(TimeSpan delta, double alpha);
private void Tick()
{
@ -150,21 +137,14 @@ namespace MoonWorks
Inputs.Update();
AudioDevice.Update();
if (NextState != null)
{
GameState = NextState;
GameState.Start();
NextState = null;
}
GameState.Update(timestep);
Update(timestep);
accumulatedElapsedTime -= timestep;
}
var alpha = accumulatedElapsedTime / timestep;
GameState.Draw(timestep, alpha);
Draw(timestep, alpha);
}
}

View File

@ -1,26 +0,0 @@
using System;
using MoonWorks.Audio;
using MoonWorks.Graphics;
using MoonWorks.Input;
namespace MoonWorks
{
public abstract class GameState
{
protected readonly Game Game;
public Window Window => Game.Window;
public GraphicsDevice GraphicsDevice => Game.GraphicsDevice;
public AudioDevice AudioDevice => Game.AudioDevice;
public Inputs Inputs => Game.Inputs;
public GameState(Game game)
{
Game = game;
}
public abstract void Start();
public abstract void Update(TimeSpan delta);
public abstract void Draw(TimeSpan delta, double alpha);
}
}