From ce53081bb9fb0f5e9f1966a343b888da7235a455 Mon Sep 17 00:00:00 2001 From: Thomas Vollmer <34384788+thovoll@users.noreply.github.com> Date: Wed, 12 Sep 2018 17:30:39 -0700 Subject: [PATCH 1/3] Make tick interval configurable. --- src/SimulationApp.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/SimulationApp.cs b/src/SimulationApp.cs index 5bf66f6..13d3e52 100644 --- a/src/SimulationApp.cs +++ b/src/SimulationApp.cs @@ -26,8 +26,7 @@ public abstract class SimulationApp : ITick /// Constant for the amount of time difference that should occur from last tick and current tick in milliseconds before /// the simulation logic will be ticked. /// - // ReSharper disable once InconsistentNaming - private const double TICK_INTERVAL = 1000.0d; + private readonly double _tickInterval; /// /// Time and date of latest system tick, used to measure total elapsed time and tick simulation after each second. @@ -47,10 +46,19 @@ public abstract class SimulationApp : ITick private SpinningPixel _spinningPixel; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class with default tick interval (1000ms). /// - protected SimulationApp() + protected SimulationApp() : this(1000.0d) { + } + + /// + /// Initializes a new instance of the class with given tick interval. + /// + protected SimulationApp(double tickInterval) + { + _tickInterval = tickInterval; + // We are not closing... IsClosing = false; @@ -162,7 +170,7 @@ public virtual void OnTick(bool systemTick, bool skipDay = false) var elapsedSpan = new TimeSpan(elapsedTicks); // Check if more than an entire second has gone by. - if (!(elapsedSpan.TotalMilliseconds > TICK_INTERVAL)) + if (!(elapsedSpan.TotalMilliseconds > _tickInterval)) return; // Reset last tick time to current time for measuring towards next second tick. From 88cd46b22d20f54d59d70648f5230d02fedd98c4 Mon Sep 17 00:00:00 2001 From: Thomas Vollmer <34384788+thovoll@users.noreply.github.com> Date: Wed, 12 Sep 2018 17:33:01 -0700 Subject: [PATCH 2/3] Fix name. --- src/SimulationApp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SimulationApp.cs b/src/SimulationApp.cs index 13d3e52..a1c9b96 100644 --- a/src/SimulationApp.cs +++ b/src/SimulationApp.cs @@ -46,14 +46,14 @@ public abstract class SimulationApp : ITick private SpinningPixel _spinningPixel; /// - /// Initializes a new instance of the class with default tick interval (1000ms). + /// Initializes a new instance of the class with default tick interval (1000ms). /// protected SimulationApp() : this(1000.0d) { } /// - /// Initializes a new instance of the class with given tick interval. + /// Initializes a new instance of the class with given tick interval. /// protected SimulationApp(double tickInterval) { From a16f400c4be5bbf09d0c00befc475af4494ca128 Mon Sep 17 00:00:00 2001 From: Thomas Vollmer <34384788+thovoll@users.noreply.github.com> Date: Wed, 12 Sep 2018 17:41:17 -0700 Subject: [PATCH 3/3] Better name. --- src/SimulationApp.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SimulationApp.cs b/src/SimulationApp.cs index a1c9b96..ad3d3bf 100644 --- a/src/SimulationApp.cs +++ b/src/SimulationApp.cs @@ -26,7 +26,7 @@ public abstract class SimulationApp : ITick /// Constant for the amount of time difference that should occur from last tick and current tick in milliseconds before /// the simulation logic will be ticked. /// - private readonly double _tickInterval; + private readonly double _tickIntervalInMillis; /// /// Time and date of latest system tick, used to measure total elapsed time and tick simulation after each second. @@ -55,9 +55,9 @@ protected SimulationApp() : this(1000.0d) /// /// Initializes a new instance of the class with given tick interval. /// - protected SimulationApp(double tickInterval) + protected SimulationApp(double tickIntervalInMillis) { - _tickInterval = tickInterval; + _tickIntervalInMillis = tickIntervalInMillis; // We are not closing... IsClosing = false; @@ -170,7 +170,7 @@ public virtual void OnTick(bool systemTick, bool skipDay = false) var elapsedSpan = new TimeSpan(elapsedTicks); // Check if more than an entire second has gone by. - if (!(elapsedSpan.TotalMilliseconds > _tickInterval)) + if (!(elapsedSpan.TotalMilliseconds > _tickIntervalInMillis)) return; // Reset last tick time to current time for measuring towards next second tick.