Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created April 24, 2016 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasboyt/0876867403b8825161d186b4d186e422 to your computer and use it in GitHub Desktop.
Save thomasboyt/0876867403b8825161d186b4d186e422 to your computer and use it in GitHub Desktop.

so there's two message types that matter for ball position: incoming "swing" messages and "sync" messages. swing messages come in as soon as another player swings. sync messages happen once a second and contain everyone's position and velocity.

both swings and sync messages have a timestamp associated with them. in perfect network conditions, the server runs slightly ahead of the client, so when yo uget a swing or sync message, you have to queue it until the client time catches up to the server.

in practice, sometimes, due to lag between the server sending you the message and you receving it, you may get a message that is "in the past." with syncs, this is fine: the world state is rolled back and synced from the past, then recalculated from that point. this is instant and, under perfect network conditions, unnoticable, since the recalculated should be the same as your current state.

with swings, however, there's an issue: due to implementation details, i can't "replay" the swing messages with a timestamp in the past if you receive the message late. the best i can do is play it at the current time, and then, when the sync message comes in, "fix" it from that snapshot. and i believe this lag is what's causing the big jumps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment