diff --git a/src/Assets/Assets.bf b/src/Assets/Assets.bf index 852ac54..34e4e04 100644 --- a/src/Assets/Assets.bf +++ b/src/Assets/Assets.bf @@ -30,7 +30,7 @@ namespace Strawberry static public void LoadAll() { Textures = new .(); - Load("textures", "*.png", Textures, (path) => Game.PlatformLayer.LoadTexture(path)); + Load("textures", "*.png", Textures, (path) => PlatformLayer.LoadTexture(path)); Sprites = new .(); Load("sprites", "*.ase", Sprites, (path) => { return new Sprite(new String(path)); }); diff --git a/src/Input/Input.bf b/src/Input/Input.bf index ef70bc5..a1bd64c 100644 --- a/src/Input/Input.bf +++ b/src/Input/Input.bf @@ -26,31 +26,31 @@ namespace Strawberry { for (let i < previousKeyboard.Count) { - if (!previousKeyboard[i] && Game.PlatformLayer.PollKey((Keys)i)) + if (!previousKeyboard[i] && PlatformLayer.PollKey((Keys)i)) lastKeypressTimes[i] = Time.Elapsed; - previousKeyboard[i] = Game.PlatformLayer.PollKey((Keys)i); + previousKeyboard[i] = PlatformLayer.PollKey((Keys)i); } } static public bool Ctrl => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl); static public bool Alt => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl); static public bool Shift => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl); - static public bool CapsLock => Game.PlatformLayer.CapsLock; - static public bool NumLock => Game.PlatformLayer.NumLock; + static public bool CapsLock => PlatformLayer.CapsLock; + static public bool NumLock => PlatformLayer.NumLock; static public bool KeyCheck(Keys key) { - return Game.PlatformLayer.PollKey(key); + return PlatformLayer.PollKey(key); } static public bool KeyPressed(Keys key) { - return Game.PlatformLayer.PollKey(key) && !previousKeyboard[(int)key]; + return PlatformLayer.PollKey(key) && !previousKeyboard[(int)key]; } static public bool KeyPressed(Keys key, float repeatDelay, float repeatInterval) { - if (Game.PlatformLayer.PollKey(key)) + if (PlatformLayer.PollKey(key)) return !previousKeyboard[(int)key] || Time.OnInterval(repeatInterval, lastKeypressTimes[(int)key] + repeatDelay); else return false; @@ -58,7 +58,7 @@ namespace Strawberry static public bool KeyReleased(Keys key) { - return !Game.PlatformLayer.PollKey(key) && previousKeyboard[(int)key]; + return !PlatformLayer.PollKey(key) && previousKeyboard[(int)key]; } static public void KeystrokesIntoString(String toString, float keyRepeatDelay, float keyRepeatInterval) @@ -172,12 +172,12 @@ namespace Strawberry static public bool GamepadButtonCheck(int gamepadID, Buttons button) { - return Game.PlatformLayer.PollGamepadButton(gamepadID, button); + return PlatformLayer.PollGamepadButton(gamepadID, button); } static public float GamepadAxisCheck(int gamepadID, Axes axis) { - return Game.PlatformLayer.PollGamepadAxis(gamepadID, axis); + return PlatformLayer.PollGamepadAxis(gamepadID, axis); } } } diff --git a/src/Modules/Editor.bf b/src/Modules/Editor.bf index db8aa0e..69dd0f8 100644 --- a/src/Modules/Editor.bf +++ b/src/Modules/Editor.bf @@ -2,11 +2,6 @@ namespace Strawberry { public abstract class Editor : Module { - public this(PlatformLayer platformLayer) - : base(platformLayer) - { - - } protected override void Update() { diff --git a/src/Modules/Game.bf b/src/Modules/Game.bf index 892f391..2e61533 100644 --- a/src/Modules/Game.bf +++ b/src/Modules/Game.bf @@ -30,12 +30,11 @@ namespace Strawberry private int32 updateCounter; private float msCounter; - public this(PlatformLayer platformLayer) - : base(platformLayer) + public this() { Game = this; - Batcher = platformLayer.CreateBatcher(); + Batcher = PlatformLayer.CreateBatcher(); VirtualInputs = new List(); Assets.LoadAll(); } diff --git a/src/Modules/Module.bf b/src/Modules/Module.bf index 94dfbd4..88186c6 100644 --- a/src/Modules/Module.bf +++ b/src/Modules/Module.bf @@ -1,17 +1,16 @@ +using System.Diagnostics; namespace Strawberry { public abstract class Module { public enum RunResults { Quit, Swap } - public PlatformLayer PlatformLayer { get; private set; } - private float msCounter; private uint32 prevTicks; - public this(PlatformLayer platformLayer) + public this() { - PlatformLayer = platformLayer; + Debug.Assert(PlatformLayer != null, "Must create PlatformLayer before Modules."); } private Module Run() diff --git a/src/PlatformLayer/Batcher.bf b/src/PlatformLayer/Batcher.bf index 920e094..ea4c143 100644 --- a/src/PlatformLayer/Batcher.bf +++ b/src/PlatformLayer/Batcher.bf @@ -29,7 +29,7 @@ namespace Strawberry public void ClearMatrix() { matrixStack.Clear(); - matrixStack.Add(Game.PlatformLayer.ScreenMatrix); + matrixStack.Add(PlatformLayer.ScreenMatrix); } public void PushMatrix(Mat4x4 mat) diff --git a/src/PlatformLayer/PlatformLayer.bf b/src/PlatformLayer/PlatformLayer.bf index d2fb412..b2c4d40 100644 --- a/src/PlatformLayer/PlatformLayer.bf +++ b/src/PlatformLayer/PlatformLayer.bf @@ -1,6 +1,12 @@ using System; +using System.Diagnostics; namespace Strawberry { + static + { + static public PlatformLayer PlatformLayer = null; + } + public abstract class PlatformLayer { public readonly String Title; @@ -12,6 +18,9 @@ namespace Strawberry public this(String title, int screenWidth, int screenHeight, int windowScale) { + Debug.Assert(PlatformLayer == null, "Cannot create more than one PlatformLayer"); + PlatformLayer = this; + Title = title; ScreenWidth = screenWidth; ScreenHeight = screenHeight;