Skip to main content

Timeline for Server game loop

Current License: CC BY-SA 4.0

14 events
when toggle format what by license comment
Aug 2, 2019 at 15:35 comment added Jody Sowald While it may be a little complex for your initial stages, if sleep time is a concern for you, the concepts of multiple buffering apply to any update loop. animated or just dataprocessing alike. Here's a link to information on how to buffer your frames for different effects en.wikipedia.org/wiki/Multiple_buffering
Aug 2, 2019 at 6:51 comment added Theraot @Logan Stopwatch will measure elapsed time. Then you can use that to compute what to pass to Thread.Sleep, that is the idea.
Aug 2, 2019 at 6:49 comment added Logan Should I be using the Stopwatch to calculate delta time and for the Thread.Sleep?
Aug 2, 2019 at 6:45 comment added Theraot @Logan that is true everywhere, it will always sleep for a little more, that goes down to the operating system. Well, to the other extreme you can let the server run the loop as fast as it can. However, if you have multiple threads, you do not want one eating all the CPU (in a busy loop or otherwise). Sleep ensures the thread takes a pause. I would advocate for Thread.Yield if you are not going to use Sleep... now, given that Sleep is not very accurate, we cannot get away with passing a constant. Instead if we measure, it will compensate for the variations. So, to use Sleep measure.
Aug 2, 2019 at 6:40 comment added Logan The reason I didn't just use Thread.Sleep for the entire delay was because in Java the time a thread sleeps for isn't very accurate. In C# if I enter 1 will it actually sleep for 1 millisecond nothing more nothing less?
Aug 2, 2019 at 6:11 comment added Theraot @Logan servers usually have a fixed number of ticks per seconds. That is the state of the art. However, even if you are fixing the timestep, you still need to measure elapsed time, so you can have the thread wait until the next tick. I have the basic use of Stopwatch here (scroll down to C#): gamedev.stackexchange.com/questions/173757/… - addendum: see the pseudo code above in this answer for what to do with the elapsed time. There tick is the time between server ticks.
Aug 2, 2019 at 5:56 comment added Logan Are ticks supposed to last a certain amount of time or is it just the delay between each? I'm a bit confused on that. Would I be able to use the Stopwatch to control that?
Aug 2, 2019 at 5:49 history edited Theraot CC BY-SA 4.0
added 180 characters in body
Aug 2, 2019 at 5:34 vote accept Logan
Aug 2, 2019 at 5:27 history edited Theraot CC BY-SA 4.0
added 4106 characters in body
Aug 2, 2019 at 5:21 comment added Theraot @Logan expanded answer.
Aug 2, 2019 at 5:21 history edited Theraot CC BY-SA 4.0
added 4106 characters in body
Aug 2, 2019 at 4:23 comment added Logan I accept connections in a different thread which is why there is a lock on connections. Should I also accept connections in that same thread? Also, what if one of the clients takes a while to send data? Wouldn't that slow down the entire game loop? How would I avoid something like that?
Aug 1, 2019 at 13:27 history answered Theraot CC BY-SA 4.0