Forum Multiplayer AddTimer firing quite a bit slower then it should

Discussion and help relating to the PlayerIO Multiplayer API.

AddTimer firing quite a bit slower then it should

Postby robscherer123 » July 30th, 2018, 8:59 pm

So I've had this issue in the past, but never made a topic. I've started my next big game and am having some issues with the AddTimer. My server has its own "game loop" that is intended to run at 30 fps in order to update its own representation of what is going on in the game. It will update things like players and enemy locations, so that when new players join the locations of the players and enemies are sent to the newly joined players. Obviously, loads of other things will later be calculated in the game loop as well, down the road.

Anyway, I need the server game loop to fire at 30 frames per second. 1 divided by 30 being about every 33 milliseconds I need the game loop to fire.

So simple enough it should look like this:
Code: Select all
AddTimer(GameLoop, 33);

However, the GameLoop function is being called a fairly significant bit slower than the intended 33 fps.

So I ran a simple test, incrementing a counter every time the GameLoop fires, for 60 seconds.

Ideally, my result for the counter at the end of the 60 seconds should be about 1818. (60,000 / 33 = 1,818)
However the counter was much lower, being around 1336 at the end of the 60 seconds. (around 26% slower!)
Setting the timer intervals to 32 instead of 33 gave me around 1,406.
27 gave around 1,696.
26 gave around 1,836.

So I'm not sure what to do here. Is this a bug? Why is it so far off? Should I just set the intervals to 26 instead of 33 since the result was closer to my intended target? This test was ran on the development server. Once uploaded to the main server, will this still behave the same?

Thanks!
robscherer123
Paid Member
 
Posts: 313
Joined: December 12th, 2012, 8:46 pm

Re: AddTimer firing quite a bit slower then it should

Postby Henrik » August 17th, 2018, 5:56 am

Hey,

The underlying issue is that the timers available in Windows and .Net aren't good enough to get the behaviour you want. They're slowly improving as .Net itself improves, but they're still not good enough for what you want.

The solution, as usual, is to cheat. Can you live with the gameloop going at half that speed and let the clients extrapolate instead?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to Multiplayer



cron