Moved inputs inside update section of game loop.
This commit is contained in:
parent
ad77fec3a2
commit
3ecd32520c
@ -99,60 +99,6 @@ namespace SlatedGameToolkit.Framework {
|
|||||||
}
|
}
|
||||||
deltaChanged = false;
|
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;
|
DateTime frameStart = DateTime.Now;
|
||||||
TimeSpan difference = frameStart - currentTime;
|
TimeSpan difference = frameStart - currentTime;
|
||||||
currentTime = frameStart;
|
currentTime = frameStart;
|
||||||
@ -160,6 +106,61 @@ namespace SlatedGameToolkit.Framework {
|
|||||||
timePassedFromLastUpdate += difference;
|
timePassedFromLastUpdate += difference;
|
||||||
while (timePassedFromLastUpdate > updateDeltaTime) {
|
while (timePassedFromLastUpdate > updateDeltaTime) {
|
||||||
//Updates.
|
//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);
|
manager.update(updateDeltaTime.TotalSeconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds);
|
||||||
timePassedFromLastUpdate -= updateDeltaTime;
|
timePassedFromLastUpdate -= updateDeltaTime;
|
||||||
if (updateDeltaTime.TotalSeconds <= 0) {
|
if (updateDeltaTime.TotalSeconds <= 0) {
|
||||||
|
@ -162,8 +162,8 @@ namespace SlatedGameToolkit.Framework.Graphics.Text
|
|||||||
|
|
||||||
context.BindTexture(TextureTarget.Texture2D, Handle);
|
context.BindTexture(TextureTarget.Texture2D, Handle);
|
||||||
context.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat.Red, length, length, 0, PixelFormat.Red, PixelType.UnsignedByte, IntPtr.Zero);
|
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.TextureWrapS, (int)TextureWrapMode.Repeat);
|
||||||
context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
|
context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
|
||||||
context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
|
||||||
context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
context.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
|
|||||||
renderer.Draw(logo);
|
renderer.Draw(logo);
|
||||||
renderer.Draw(textureTester);
|
renderer.Draw(textureTester);
|
||||||
renderer.Draw(untextured);
|
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.Draw(new RectangleMesh(new RectangleF(-1, -1, 0.5f, 0.5f), new RectangleF(0, 1, 1, -1), font.GetTextureBacking(0), Color.White));
|
||||||
renderer.End();
|
renderer.End();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user