Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Web / PUSG.Web / Services / GameLoopService.cs
diff options
context:
space:
mode:
1 files changed, 38 insertions, 0 deletions
-rw-r--r--src/Web/PUSG.Web/Services/GameLoopService.cs38
diff --git a/src/Web/PUSG.Web/Services/GameLoopService.cs b/src/Web/PUSG.Web/Services/GameLoopService.cs
new file mode 100644
index 0000000..9ddbb20
--- /dev/null
+++ b/src/Web/PUSG.Web/Services/GameLoopService.cs
@@ -0,0 +1,38 @@
+using PUSG.Web.Models;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace PUSG.Web.Static
+{
+ public class GameLoopService : IGameLoopService
+ {
+ private Timer timer;
+
+ public GameSession GameSession { get; set; }
+
+ private void Step(object state)
+ {
+ this.GameSession?.Update();
+ }
+
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ this.timer = new Timer(Step, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(17));
+
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ this.timer?.Change(Timeout.Infinite, 0);
+
+ return Task.CompletedTask;
+ }
+
+ public void Dispose()
+ {
+ this.timer?.Dispose();
+ }
+ }
+}