-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntry.cs
44 lines (35 loc) · 1.18 KB
/
Entry.cs
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
39
40
41
42
43
44
using System;
using System.Threading;
namespace AutobahnRacingServer
{
class Entry
{
private static bool isRunning = false;
static void Main(string[] args)
{
Console.Title = "Autobahn Racing - Server";
ServerLogger.Log("Autobahn Racing - Server", ConsoleColor.Green, 1);
isRunning = true;
Thread mainThread = new Thread(new ThreadStart(MainThread));
mainThread.Start();
Server.Start(Constants.MAX_PLAYERS, Constants.PORT);
}
private static void MainThread()
{
Console.WriteLine($"Main thread started. Running at {Constants.TICKS_PER_SEC} ticks per second");
DateTime _nextLoop = DateTime.Now;
while (isRunning)
{
while(_nextLoop < DateTime.Now)
{
GameLogic.Update();
_nextLoop = _nextLoop.AddMilliseconds(Constants.MS_PER_TICK);
if(_nextLoop > DateTime.Now)
{
Thread.Sleep(_nextLoop - DateTime.Now);
}
}
}
}
}
}