Iphone/Ipod multiplayer game

Started by
7 comments, last by nitin_daviet88 12 years, 11 months ago
Currently we are working on IPhone platform.

I am developing a game that requires real time synchronization. At the max 7 players can play this game at a time on a local wifi/bluetooth. I am using GKSession for networking.

How should i design multiplayer architecture for this game?

Advertisement
That's a question without much to go on. What have you tried, and why didn't it work?

I would suggest a logical star topology -- elect one of the iPhones as the "hub" (server) and all the others send to that. That then echoes back aggregate packets to all the "spokes" (clients). This is similar to how games like Quake or Counterstrike or Minecraft work on the Internet today.
enum Bool { True, False, FileNotFound };
I am using star topology. A person can either host game or join the game.
Whoever host the game, will be the server and rest will be the clients.

Responsibilities of server:

1) Check clients input data , if any data found then take appropriate action.
2) Update world.
3) Create world frame and send it to all clients.

Responsibilities of clients:

1) If user taps on iPhone create input packet and send it to server.
2) Render world.

So far now this architecture is working but as client's world rendering depends on the world update defined by server it shows delay and lag at the client side.

What coding standards and techniques should i use to hide this delay and lag?
Quote:What coding standards and techniques should i use to hide this delay and lag?


That depends on what type of game you're building.

If your send rate is 20 packets per second, then you should expect a latency of no more than 100 milliseconds. You may want to develop some timing code that verifies that you're not seeing more latency than you expect. Also, if it's low-power devices, you may not be able to keep up a high rate of packet sending, which would increase the latency.

Often, the "hiding" of latency has to be done in game design, rather than in any particular technical solution. Latency is latency; at a fundamental level you cannot make it lower than the technological limitations.

The main tool in your toolchest is guessing. For example, when the user presses a command button, you can guess that the command will work fine, and show the result immediately to the user. When the result comes back from the server, if it doesn't work, then you have to change the display of the command to make it clear that it didn't work. How to make this acceptable to the user is a presentation issue, not a technical issue.
enum Bool { True, False, FileNotFound };
I have kept server's packet sending rate at 1/20 .I am trying to implement time mechanism. But i don't understand how should i sync server's time with client time.
It shows around 22 to 30 seconds gap between server's and client time. I think server's and client's time is not in sync.
I am trying this for the first time so i don't know from where i should start implementing time mechanism and how should i proceed.

It shows around 22 to 30 seconds gap between server's and client time.


There are two kinds of dis-sync:
1) a difference in absolute time (from a second, to an hour, to potentially years if the clock is out of date)
2) a different in rate of progression

Within a single game, you may be able to assume that 2) doesn't matter. Thus, the only thing you need to compensate for is 1).
This is not that hard. When the client connects, it can send a copy of its current time stamp. When the server sends a response packet, it can include:
a: the timestamp that the client sent
b: the server timestamp at the time the packet was received
c: the server timestamp at which the packet is sent
The client can then, in turn, add d: its timestamp for when it received that packet.

Now, you have enough information to measure round trip time through the system and network. A reasonable estimate is rtt = ((d - a) - (c - B))/2.
You also have an estimate for the difference between server and client clock. It will be offset = ((d - c - rtt) + (b - a - rtt)) / 2.
Now you can easily estimate the server clock simply by taking local time and subtracting "offset" (which may be negative).

Another option is to run the simulation in fixed time steps, and calculate all actions based on integral time steps. All you need is a mapping from local clock to time step, which you can establish by seeing what time step the server provides in its packets updating the client.
enum Bool { True, False, FileNotFound };

offset = ((d - c - rtt) + (b - a - rtt)) / 2


It always returns 0.
I think it should be "offset =((c - d + rtt) + (b - a - rtt)) / 2". I got this information from website : "http://www.mindcontrol.org/~hplus/time-offset.html".
And should i add offset to client's local time or subtract it.Currently i am subtracting offset from servers timestamps.And its giving me proper values.

After calculating latency what should i do?
Currently when client receives world update from server it tries to predict server's current frame and then with the help of prediction algorithm
it predicts players position then it compares that values with the current players position on his system. I wanted to ask am i following the right mechanism.

I think it should be "offset =((c - d + rtt) + (b - a - rtt)) / 2". I got this information from website : "http://www.mindcontrol.org/~hplus/time-offset.html".



Hey, I wrote that article :-) I should just have pointed at that.
Yes, it's quite likely I got one of the terms wrong.

Anyway, yes, the approach you take is one way that games use the clock to display predicted positions. There are other ways, such as only ever displaying an entity in the "past" so that you know that you're displaying it at the correct location. The drawback there is that you get higher visible latency.
enum Bool { True, False, FileNotFound };

[quote name='kaushik_poria' timestamp='1294923596' post='4758265']
I think it should be "offset =((c - d + rtt) + (b - a - rtt)) / 2". I got this information from website : "http://www.mindcontrol.org/~hplus/time-offset.html".



Hey, I wrote that article :-) I should just have pointed at that.
Yes, it's quite likely I got one of the terms wrong.

Anyway, yes, the approach you take is one way that games use the clock to display predicted positions. There are other ways, such as only ever displaying an entity in the "past" so that you know that you're displaying it at the correct location. The drawback there is that you get higher visible latency.
[/quote]

hey,
I too have to implement this in my app... read this post but dont know where to start from....any help regarding that. also whats the prediction algorithm...
regards

This topic is closed to new replies.

Advertisement