From 139265585a2ca1515865df8d3bd4c0cb81fafb7e Mon Sep 17 00:00:00 2001 From: Marvin Pohl Date: Tue, 7 Feb 2017 19:30:54 +0100 Subject: [PATCH] Enter now Pauses the simulation --- EvoNet/Controls/EvoSimControl.cs | 9 ++++++--- EvoNet/EvoNet.csproj | 3 --- EvoNet/Input/InputManager.cs | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/EvoNet/Controls/EvoSimControl.cs b/EvoNet/Controls/EvoSimControl.cs index 8f00a0b..621f23d 100644 --- a/EvoNet/Controls/EvoSimControl.cs +++ b/EvoNet/Controls/EvoSimControl.cs @@ -135,10 +135,13 @@ protected override void Update(GameTime gameTime) foreach (var module in modules) { - module.NotifyTick((float)gameTime.ElapsedGameTime.TotalSeconds); + if (!inputManager.Paused || !module.WantsFastForward) + { + module.NotifyTick((float)gameTime.ElapsedGameTime.TotalSeconds); + } } - - if (inputManager.EnableFastForward) + + if (!inputManager.Paused && inputManager.EnableFastForward) { DateTime startFastForward = DateTime.UtcNow; double clampedElapsedTime = Math.Min(gameTime.ElapsedGameTime.TotalSeconds, 0.033); diff --git a/EvoNet/EvoNet.csproj b/EvoNet/EvoNet.csproj index d86ff87..32581d0 100644 --- a/EvoNet/EvoNet.csproj +++ b/EvoNet/EvoNet.csproj @@ -50,9 +50,6 @@ EvoNet.Program - - - diff --git a/EvoNet/Input/InputManager.cs b/EvoNet/Input/InputManager.cs index fbe4dd7..5493596 100644 --- a/EvoNet/Input/InputManager.cs +++ b/EvoNet/Input/InputManager.cs @@ -17,6 +17,7 @@ public class InputManager : UpdateModule bool rightMouseDown = false; bool oldSpaceDown = false; + bool oldEnterDown = false; Vector2 oldMousePosition = Vector2.Zero; int scrollWheelValue; @@ -25,6 +26,7 @@ public class InputManager : UpdateModule SimulationRenderer renderer; public bool EnableFastForward { get; private set; } + public bool Paused { get; private set; } public override bool WantsFastForward { @@ -76,6 +78,13 @@ protected override void Update(float gameTime) EnableFastForward = !EnableFastForward; } + bool enterDown = keyboardState.IsKeyDown(Keys.Enter); + + if (!oldEnterDown && enterDown) + { + Paused = !Paused; + } + if (keyboardState.IsKeyDown(Keys.R)) { float viewportWidth = renderer.GraphicsDevice.Viewport.Width; @@ -88,6 +97,7 @@ protected override void Update(float gameTime) } oldSpaceDown = spaceDown; + oldEnterDown = enterDown; scrollWheelValue = mouseState.ScrollWheelValue; oldMousePosition = new Vector2(mouseState.X, mouseState.Y);