blob: 83029c2465d27ddab5c2b04b8525a3b2d5766b5d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using PUSG.Web.Models;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace PUSG.Web.Services
{
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();
}
}
}
|