From 3ecd32520c7537314243ee8bbfdc3265ed7c61ab Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 3 Jul 2020 18:16:16 -0500 Subject: [PATCH] Moved inputs inside update section of game loop. --- src/SlatedGameToolkit.Framework/GameEngine.cs | 109 +++++++++--------- .../Graphics/Text/BitmapFont.cs | 4 +- .../Utilities/Playground/MainState.cs | 2 +- 3 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/SlatedGameToolkit.Framework/GameEngine.cs b/src/SlatedGameToolkit.Framework/GameEngine.cs index 8422539..7dce74d 100644 --- a/src/SlatedGameToolkit.Framework/GameEngine.cs +++ b/src/SlatedGameToolkit.Framework/GameEngine.cs @@ -99,60 +99,6 @@ namespace SlatedGameToolkit.Framework { } deltaChanged = false; } - //Events - SDL.SDL_Event SDL_Event; - while (SDL.SDL_PollEvent(out SDL_Event) != 0) { - switch (SDL_Event.type) { - case SDL.SDL_EventType.SDL_MOUSEMOTION: - Mouse.OnMouseMoved(SDL_Event.motion.x, SDL_Event.motion.y); - break; - case SDL.SDL_EventType.SDL_MOUSEWHEEL: - Mouse.OnScroll(SDL_Event.wheel.x, SDL_Event.wheel.y); - break; - case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: - if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) { - Mouse.OnLeftChange(true); - } else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) { - Mouse.OnRightChange(true); - } else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) { - Mouse.OnMiddleChange(true); - } - break; - case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: - if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) { - Mouse.OnLeftChange(false); - } else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) { - Mouse.OnRightChange(false); - } else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) { - Mouse.OnMiddleChange(false); - } - break; - case SDL.SDL_EventType.SDL_KEYDOWN: - Keyboard.OnKeyPressed(SDL_Event.key.keysym.sym); - break; - case SDL.SDL_EventType.SDL_KEYUP: - Keyboard.OnKeyReleased(SDL_Event.key.keysym.sym); - break; - case SDL.SDL_EventType.SDL_WINDOWEVENT: - WindowContext handle = WindowContextsManager.ContextFromWindowID(SDL_Event.window.windowID); - switch (SDL_Event.window.windowEvent) - { - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: - handle.OnResize(SDL_Event.window.data1, SDL_Event.window.data2); - break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: - handle.OnFocusLost(); - break; - case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: - handle.OnFocusGained(); - break; - } - break; - case SDL.SDL_EventType.SDL_QUIT: - Stop(); - break; - } - } DateTime frameStart = DateTime.Now; TimeSpan difference = frameStart - currentTime; currentTime = frameStart; @@ -160,6 +106,61 @@ namespace SlatedGameToolkit.Framework { timePassedFromLastUpdate += difference; while (timePassedFromLastUpdate > updateDeltaTime) { //Updates. + //Events + SDL.SDL_Event SDL_Event; + while (SDL.SDL_PollEvent(out SDL_Event) != 0) { + switch (SDL_Event.type) { + case SDL.SDL_EventType.SDL_MOUSEMOTION: + Mouse.OnMouseMoved(SDL_Event.motion.x, SDL_Event.motion.y); + break; + case SDL.SDL_EventType.SDL_MOUSEWHEEL: + Mouse.OnScroll(SDL_Event.wheel.x, SDL_Event.wheel.y); + break; + case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: + if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) { + Mouse.OnLeftChange(true); + } else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) { + Mouse.OnRightChange(true); + } else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) { + Mouse.OnMiddleChange(true); + } + break; + case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: + if (SDL.SDL_BUTTON_LEFT == SDL_Event.button.button) { + Mouse.OnLeftChange(false); + } else if (SDL.SDL_BUTTON_RIGHT == SDL_Event.button.button) { + Mouse.OnRightChange(false); + } else if (SDL.SDL_BUTTON_MIDDLE == SDL_Event.button.button) { + Mouse.OnMiddleChange(false); + } + break; + case SDL.SDL_EventType.SDL_KEYDOWN: + Keyboard.OnKeyPressed(SDL_Event.key.keysym.sym); + break; + case SDL.SDL_EventType.SDL_KEYUP: + Keyboard.OnKeyReleased(SDL_Event.key.keysym.sym); + break; + case SDL.SDL_EventType.SDL_WINDOWEVENT: + WindowContext handle = WindowContextsManager.ContextFromWindowID(SDL_Event.window.windowID); + switch (SDL_Event.window.windowEvent) + { + case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: + handle.OnResize(SDL_Event.window.data1, SDL_Event.window.data2); + break; + case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: + handle.OnFocusLost(); + break; + case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: + handle.OnFocusGained(); + break; + } + break; + case SDL.SDL_EventType.SDL_QUIT: + Stop(); + break; + } + } + manager.update(updateDeltaTime.TotalSeconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds); timePassedFromLastUpdate -= updateDeltaTime; if (updateDeltaTime.TotalSeconds <= 0) { diff --git a/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs b/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs index 094efe2..1cd0ac3 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Text/BitmapFont.cs @@ -162,8 +162,8 @@ namespace SlatedGameToolkit.Framework.Graphics.Text context.BindTexture(TextureTarget.Texture2D, Handle); context.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Red, length, length, 0, PixelFormat.Red, PixelType.UnsignedByte, IntPtr.Zero); - context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); - context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); + context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); + context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); diff --git a/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs b/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs index 3569439..516f3f2 100644 --- a/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs +++ b/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs @@ -88,7 +88,7 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground renderer.Draw(logo); renderer.Draw(textureTester); renderer.Draw(untextured); - font.Draw(renderer, 0.25f, -0.35f, "ABCDEFHIJKLMNOPQRSTUVWXYZ1234567890", Color.White); + font.Draw(renderer, 0.25f, -0.35f, "Hello World.", Color.White); renderer.Draw(new RectangleMesh(new RectangleF(-1, -1, 0.5f, 0.5f), new RectangleF(0, 1, 1, -1), font.GetTextureBacking(0), Color.White)); renderer.End(); }