Boris D. Teoharov
Boris D. Teoharov

Reputation: 2388

Game network latency compensation

I am developing a simple fast-paced 2 dimensional real-time multiplayer game in Flash. Players can only shoot and walk in point to move fashion. I use TCP socket connection (AS3 doesnt offer UDP).

All I want is to synchronize players' actions so Player1 could see the same on its screen as Player2,Player3... or just see close representation (position,taking damage,etc).

I know movement vector coordinates and I can easily interpolate on them using latency. However, I can not figure out an effective way to determine how much time (T1) did it take the state update to travel client1-server-client2 and then make corrections to client2's screen based on T1. (You know, ping times may fluctuate quite a bit).

I need a way to do the above-mentioned, i need way which is as fast and as accurate as posssible but not extremely sophisticated. (what algorithm should i use? what is the solution - timestamps, maybe or what? - I dont know.)

Upvotes: 2

Views: 1355

Answers (1)

vulkanino
vulkanino

Reputation: 9134

First of all, I think the server should constantly have updated information about the entire "world". All the clients send their playing actions (that is, what the player does, like movements, shootings, etc) to the server, and using compressed data.

I would divide the "world" into regions. Each player has of course a limited view, so he can't see all the world at once (luckily), thus he needs to get updates to only the regions he can see.

So the thing is:

  • The server generates the world, and divides it into regions.
  • When a player enters the world, it gets general information about the entire world and detailed information about the regions in his sight
  • Each action of a player that has consequences, must be sent to the server (compressed) that acquires the information. If the status change has the effect of changing one or more regions, each user interested in those regions must receive the change notification

It looks like a publish/subscribe design pattern (Observer), but

  • each client is the publisher and the server is the subscriber for what concerns the player status change.
  • the server is publisher and the clients are subscribers for what concerns the world change, but only for the regions each player is interested in. this is a particular Observer in that the subscription changes over time (regions) due to movement

Upvotes: 4

Related Questions