Multiplayer game for iphone

I searched and read many articles and looked at the Apple GKTank sample (I don’t see any features of my problem, it seems to handle events as they occur), but I do not see an example or tutorial, answer the following

in a multiplayer game via bluetooth / internet (possibly), how do you synchronize the interaction of players so that the result of the game comes out taking into account the delay, etc.

eg:

Each player A and B displays one button on two separate devices connected via bluetooth.

Player A pushes a button (player A plays the game, and therefore latency is not a problem) Player B pushes a button in front of Player A, but his connection to Player A has at least 200 ms network latency.

problem: the game must know that player B is pressed first, even if the Touch Touch player first reaches the game code - that is, there is no advantage for hosting.

I know that the touch event has a timestamp, and so I could make sure that the actual press time was sent from player B to the game code ... but I'm not sure if this is the right approach, and if it is where to go from there ..

I expect that the answer will depend on some game time cycle, when touches are not processed immediately, but in the game cycle ...

any help on this or pointers to a textbook or specific source code that handles this will be appreciated.

Adam

+4
source share
2 answers

You might want to ask this question at https://gamedev.stackexchange.com/ , as this is a general question about the delay or delay of a multiplayer game and is not particularly specific to the iPhone.

You may be able to use timestamps to order activity messages. I think the iPhone is in sync with the date & time server supported by AT & T.

+2
source

Well, I have no real experience in creating multiplayer games. But, as is the case with most game development issues, I believe that there is nothing wrong or right, so some kind of logical thinking should do the trick.

Here are some thoughts you might consider:

  • Even if there is no latency on Player A, you will have to enter some to compensate player B (and vice versa, since from the point of view of player B, player A is also late)
  • Thus, you need to enter some kind of “team stack” to buffer the input of both players and execute the commands, when both players had the opportunity to make their inputs for this point in game play mode
  • You might want to enter ping commands to measure the actual delay from time to time.
  • Only one device (host) should measure the delay and announce it to the client
  • Based on the measured delay, calculate the time offset (relative to the time of the hosts) or the delay for the commands on the stack (use the delay to convert Player B timestamps to "local" time).
  • Keep the dynamics of the delay, if possible, to compensate for the different delay (keep the measurement delay throughout the session
  • If the actual latency exceeds the calculated one, the commands from player B can be pushed onto the stack late - make sure that they are executed anyway (lag can be experienced at this point)
  • You will need two “layers” - the input level, which exchanges, buffers and synchronizes the actual input, and the game layer, which receives pending commands from the input level

So far my 2 cents; -)

+1
source

Source: https://habr.com/ru/post/1335248/


All Articles