Say I was making a game and let's pretend I was using a Console Application rather than using something like Unity etc etc.
And imagine I wanted to implement a game loop, the same concept would apply to a dedicated network server for the game.
This is usually how I would have done it, but is this a good option?
public void Start()
{
_isRunning = true;
var sw = new Stopwatch();
while (_isRunning)
{
sw.Start();
/* Update Game Logic */
sw.Stop();
var sleepDelta = Constants.Tickrate - (int)sw.ElapsedMilliseconds;
if (sleepDelta > 0)
Thread.Sleep(sleepDelta);
else
Console.WriteLine(
$"Server can't keep up!\nElapsed: {(int)sw.ElapsedMilliseconds}\nElapsed: {sleepDelta}");
sw.Reset();
}
}
What's the difference between doing that vs something like the Timer and using the OnElapsed event