Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to use timestamps for packets instead of ticks


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Angus Hollands   Members   -  Reputation: 717

Like
0Likes
Like

Posted 31 July 2012 - 10:08 AM

Hi everyone!
I've been working on an authoritative server design for a few months, and I've hit a snag.
After working initially with a tick-based approach, simulations break down (prediction and extrapolation) when the client tick rate differs to that of the server.
The server will always have a constant frame-rate, typically 60 fps. However, this may change for the clients, so how can I account for that?

I've read about using time instead of ticks, however here are my following concerns:
  • Time is not an integer - unless you perform multiplication and rounding.
  • Time does not progress at a constant rate with a tick based logic loop, thus states won't be derived at exactly the same time, even if the simulations run at the same tick rate and are started at exactly the same time.
Because of these issues, whilst I can think of how to modify my system to use time, I cannot think how one could access the gamestate that was determined for that time. This is my current idea for a solution:
  • As the server runs at 60 ticks per second, use a division function to determine the current "tick" of the server using a tick rate and time (e.g tick = time / tick_rate(per second)). I'd have to round to the nearest integer, so i'd use the floor of the result.
  • This tick can be used to determine a constant tick rate.
  • When comparing predictions against server states, use interpolation between client predictions (if the client tick rate is 15hz, ever 4 server ticks)
Some final notes:
  • I'm using a game engine that runs all game elements (render, animation, logic) sequentially in the game loop. Thus all are affected by a varying frame rate
  • The physics system is constrained to the tick rate, so i'd have to simply modify the velocity values by hand using the tick system as a scalar against the velocity vector.
Does this sound like a viable solution? I'd assume that the tick rate of the client is capped at a maximum of 60.

Edited by Angus Hollands, 31 July 2012 - 10:14 AM.


Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 16001

Like
0Likes
Like

Posted 31 July 2012 - 01:06 PM

The typical solution is to run both at a reduced tick rate; 30Hz is pretty common.

#3 hplus0603   Moderators   -  Reputation: 5518

Like
1Likes
Like

Posted 31 July 2012 - 02:00 PM

Actually, the real solution is to step zero, one, or more physics steps per display step, depending on frame rate.

The canonical game loop looks something like this.

enum Bool { True, False, FileNotFound };

#4 ApochPiQ   Moderators   -  Reputation: 16001

Like
0Likes
Like

Posted 31 July 2012 - 02:26 PM

That's what I was going for, actually; just did a terrible job of saying it.

Must stop replying when in a hurry :-D

#5 Angus Hollands   Members   -  Reputation: 717

Like
0Likes
Like

Posted 31 July 2012 - 05:32 PM

I'd like to, however I can't. I cannot modify the physics tick rate, without modifying the logic tick rate, as they are sequentially performed, with no user control. Therefore, will my solution work?

#6 ApochPiQ   Moderators   -  Reputation: 16001

Like
0Likes
Like

Posted 31 July 2012 - 06:12 PM

How important is perfect determinism to your game model?

#7 Angus Hollands   Members   -  Reputation: 717

Like
0Likes
Like

Posted 01 August 2012 - 05:52 AM

As a first person shooter, it depends on what is being determined! But generally speaking, it is important.

#8 hplus0603   Moderators   -  Reputation: 5518

Like
0Likes
Like

Posted 01 August 2012 - 07:18 AM

Again: You should always run a fixed-length (in time) physics/simulation tick, and if more time has elapsed since the last time, you should run more than one tick. There is no other way.
enum Bool { True, False, FileNotFound };

#9 Angus Hollands   Members   -  Reputation: 717

Like
0Likes
Like

Posted 01 August 2012 - 11:12 AM

In other words, I am stuck?

#10 hplus0603   Moderators   -  Reputation: 5518

Like
0Likes
Like

Posted 02 August 2012 - 09:56 AM

In other words, I am stuck?


If your client code locks the physics simulation time step size to the frame draw duration, then it would seem like it.
If you can run simulation separate from display, perhaps even in another thread, then you don't need to be stuck.
enum Bool { True, False, FileNotFound };

#11 JohnnyCode   Members   -  Reputation: 261

Like
-1Likes
Like

Posted 04 August 2012 - 09:08 PM

you should always get most actual data to compute the frame. If there is more data in the stack (info for 3 frames has arrived while client was computing its previous frame, then you should pick the latest, while it can couse problems, you may need to process all of those that arrived, but this will couse you dilema you are solving). I would say that you should pick the latest and if player did not see 3 frames that got interacted on him, it is his penalty. In this way your aplication can allways decide on client's side. Imagine everyone is positioned on their places most up to date, so that if you aim someone, the other one is informed of it, even that he didn't spot you for a lag.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS