I am making a 2-player iphone action game using a synchronization service (in this case Firebase). The service allows state syncing through the internet, but I have to execute all game logic on the phones.
I've read a bunch of game networking articles, and since I have no server, it seems like if I can get both phones to start the game at "exactly" the same time in realtime, I can adjust everything from there. (Planning on using a "tick" count on each phone, and sending the tick along with actions, then rewinding the simulation if necessary. The phones divide the game into halves to determine authority).
But how do you get remote clients to start a game tick at the same time?? It seems like this would be necessarily in lock step peer-to-peer, and something like it in FPS games.
The strategy I'm using now tries to have one client "guess" the other client's clock time, including ping time. If correct, they both start the game based on the guess (since for that message it was on).
- a: sends a.localTime
- b: receives message. Returns b.localTime, and dTime(a-b)
- a: receives message. Returns a.localTime, and dTime(b-a)
- b: receives message. If a.localTime + dTime(b-a) is very close to new b.localTime, send accept message.
- b: starts game at: new b.localTime + 1 second
- a: receives accept. Starts game at accepted a.localTime + dTime(b-a) + 1s
I made a little number counter thing to go with the tick, and they're just barely off. I can't see how this is possible though, since A "guessed" B's time, they should start at exactly the same time...
See anything wrong with my method? What's an easier way? I'm trying to avoid using a server if possible.