From ef5a886b3a6259a11ba4503374cf8e9afdba035b Mon Sep 17 00:00:00 2001 From: Maddy Thorson Date: Sun, 21 Feb 2021 12:48:53 -0800 Subject: [PATCH] Module swapping works --- src/Assets/Assets.bf | 7 ++++- src/Modules/Editor.bf | 4 +++ src/Modules/Game.bf | 7 ++++- src/PlatformLayer/PlatformLayer.bf | 1 + src/PlatformLayer/SDL2/SDL2PlatformLayer.bf | 33 ++++++++++++--------- src/Static/Engine.bf | 1 + 6 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/Assets/Assets.bf b/src/Assets/Assets.bf index 34e4e04..b6e75aa 100644 --- a/src/Assets/Assets.bf +++ b/src/Assets/Assets.bf @@ -29,9 +29,13 @@ namespace Strawberry static public void LoadAll() { + if (Textures != null) + DeleteDictionaryAndKeysAndValues!(Textures); Textures = new .(); Load("textures", "*.png", Textures, (path) => PlatformLayer.LoadTexture(path)); + if (Sprites != null) + DeleteDictionaryAndKeysAndValues!(Sprites); Sprites = new .(); Load("sprites", "*.ase", Sprites, (path) => { return new Sprite(new String(path)); }); } @@ -39,8 +43,9 @@ namespace Strawberry static public void DisposeAll() { DeleteDictionaryAndKeysAndValues!(Textures); + Textures = null; DeleteDictionaryAndKeysAndValues!(Sprites); - Sprite.[Friend]Dispose(); + Sprites = null; } static private void Load(String directory, String wildcard, Dictionary putInto, function T(String) loader) diff --git a/src/Modules/Editor.bf b/src/Modules/Editor.bf index 69dd0f8..46e3665 100644 --- a/src/Modules/Editor.bf +++ b/src/Modules/Editor.bf @@ -1,3 +1,4 @@ +using ImGui; namespace Strawberry { public abstract class Editor : Module @@ -10,8 +11,11 @@ namespace Strawberry protected override void Render() { + PlatformLayer.RenderBegin(); PlatformLayer.ImGuiRenderBegin(); + ImGui.PushID("Editor"); UI(); + ImGui.PopID(); PlatformLayer.ImGuiRenderEnd(); PlatformLayer.RenderEnd(); } diff --git a/src/Modules/Game.bf b/src/Modules/Game.bf index 2e61533..7956517 100644 --- a/src/Modules/Game.bf +++ b/src/Modules/Game.bf @@ -23,7 +23,6 @@ namespace Strawberry private bool updating; public Batcher Batcher { get; private set; } - public Color ClearColor = .Black; public bool DebugOverlay = false; private bool* keyboardState; @@ -92,14 +91,20 @@ namespace Strawberry protected override void Render() { + PlatformLayer.RenderBegin(); + + // game PlatformLayer.GameRenderBegin(); Draw(); PlatformLayer.GameRenderEnd(); + // debug overlay if (DebugOverlay) { PlatformLayer.ImGuiRenderBegin(); + ImGui.PushID("DebugOverlay"); DebugOverlay(); + ImGui.PopID(); PlatformLayer.ImGuiRenderEnd(); } diff --git a/src/PlatformLayer/PlatformLayer.bf b/src/PlatformLayer/PlatformLayer.bf index b2c4d40..92166e0 100644 --- a/src/PlatformLayer/PlatformLayer.bf +++ b/src/PlatformLayer/PlatformLayer.bf @@ -39,6 +39,7 @@ namespace Strawberry public abstract bool Closed(); // Returns whether the game window has been closed //Rendering + public abstract void RenderBegin(); public abstract void GameRenderBegin(); public abstract void GameRenderEnd(); public abstract void ImGuiRenderBegin(); diff --git a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf index 32c2374..90ebfc6 100644 --- a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf +++ b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf @@ -11,6 +11,7 @@ namespace Strawberry.SDL2 public int TextureMatrixLocation { get; private set; } public Texture.Filters TextureFilter = .Nearest; public bool TextureClamping = false; + public Color ClearColor = .Black; private SDL.Window* window; private SDL.Surface* screen; @@ -169,6 +170,24 @@ namespace Strawberry.SDL2 public override uint32 Ticks => SDL.GetTicks(); + public override void RenderBegin() + { + GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); + GL.glClearColor(ClearColor.Rf, ClearColor.Gf, ClearColor.Bf, ClearColor.Af); + GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + } + + public override void GameRenderBegin() + { + GL.glUseProgram(glProgram); + } + + public override void GameRenderEnd() + { + GL.glUseProgram(0); + GL.glFlush(); + } + public override void ImGuiRenderBegin() { ImGuiImplOpenGL3.NewFrame(); @@ -182,20 +201,6 @@ namespace Strawberry.SDL2 ImGuiImplOpenGL3.RenderDrawData(ImGui.ImGui.GetDrawData()); } - public override void GameRenderBegin() - { - GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); - GL.glClearColor(Game.ClearColor.Rf, Game.ClearColor.Gf, Game.ClearColor.Bf, Game.ClearColor.Af); - GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - GL.glUseProgram(glProgram); - } - - public override void GameRenderEnd() - { - GL.glUseProgram(0); - GL.glFlush(); - } - public override void RenderEnd() { SDL.GL_SwapWindow(window); diff --git a/src/Static/Engine.bf b/src/Static/Engine.bf index 750e21e..7951fd3 100644 --- a/src/Static/Engine.bf +++ b/src/Static/Engine.bf @@ -27,6 +27,7 @@ namespace Strawberry static private void Shutdown() { Input.[Friend]Shutdown(); + Sprite.[Friend]Dispose(); } } }