PDA

View Full Version : synchronizing game mechanics online



EricLang
24-03-2009, 09:15 AM
I'm currently brainstorming on my Lemmings Multiplayer Online Game and solving problems in my head already.
Now the next problem must have been encountered by other game-programmers too:

How do you synchronize game-mechanics when some people are playing a game together?
Let's take a lemmings-level as example. 2 players have control over their own lemmings in the same level. Now we know lemmings can change the world they are in, by building digging etc.
I can imagine problems because of network-latency (lag) for example: Player A starts digging at frame 100, Player B starts building at the same place at frame 100, but because of lag does not yet see what player A is doing.
How to handle these kind of problems? The Lemmings game needs a high degree of precision on timing and pixels.

noeska
24-03-2009, 05:59 PM
Yes that is quite a puzzle.

One thought
- what is leading server vs clients

You say the clients are leading giving the problems you mentioned.
Try to add a server (could be a client) and let that control the logic.
e.g. look at quake.

EricLang
24-03-2009, 07:21 PM
No I'm not saying the clients are leading.
I just try to think of a way in which the games are in sync. Ideally there is one game on the server, I think.

Look at Quake
What do you mean?

noeska
24-03-2009, 09:01 PM
quake (3 arena) can be played online and uses one client to be a server to that other clients conect. The server keeps everything in sync. Quake is opensource so it may be of help.

Also try to search this forum.

igel457
24-03-2009, 10:05 PM
Hi,

as Noeska already wrote: client/server based games normally work in the following way: The clients send the player's actions to the (single) server. While there is no response from the server, the game continues as if it was a single player game. Finally everything gets synced by the server - so in your case you would have to implement something like an "undo" if an action has been marked as invalid - or you have to ask the server for permission everytime an action is performed by the player. Most time the latency (in the internet) should be < 100ms, so this shouldn't be a real problem.

User137
24-03-2009, 11:17 PM
Most time the latency (in the internet) should be < 100ms, so this shouldn't be a real problem.
Not very often from my experience. Latency that low can only be achieved realistically if playing with people from your own country only. In common international games (WoW, GW) i see anything between 100ms to 300ms but when i ask other players about their ping it is usually even higher.

To topic though.. it is best to do what you can as far as possible and analyze where it goes wrong. Game is only synchronized when everything happens in same order same time. To do that something will have to wait for permission to go forward ("tick") or be stored in case of rollback. Both have their downsides; either game control seems laggy or game visuals may suddenly appear elsewhere. Personally i'd go for control tick and server that is process on its own but that is subject that i still have to test.

EricLang
25-03-2009, 11:44 AM
Hmm, some good ideas here. Thanks for the answers. I dont know if I can read the code of Quake, but i'll analyze the different options.

jdarling
25-03-2009, 02:49 PM
The answer to this question is a very long and tedious one. There are literally 1000's of articles on the net about this, some of the best are on Gammasutra and GD.

Long and short of it is:
Lat should be thought of as the time it takes for a message to be delivered and how the size of that message affects that delivery time. Make sure your message size is appropriate to your pipe and keep the sends in tight bursts. If you can get 2 or 3 messages into one packet then do so.
Use two types of networking, UDP and TCP. Research both, and it should be obvious why and when to use each.
Consider multiple types of message importance. Make sure you process the most important 1st and wait for the less important ones.
Realize it won't be perfect, just get it close enough. Some of the best parts of games are due to "bugs" in the network.

For your example about digging and building. Here is one way of achieving it:
Client 1, send lock x,y to server
Client 2, send lock x,y to server
Server gets client 2 request first, locks x,y and sends ok to client 2
Server broadcasts client 2's lock
Server gets client 1's request, sends fail
Client 1 gets fail back. Don't change animation.

To achieve this, you have an interm animation. I tell him to dig and build, he "thinks" for a split second (maybe a question mark above head) while messages are sent and received. Once a "decision" is made by the server, the animation changes as appropriate.

Hope that helps, remember your problem is only as big or small as the solutions you come up with. In this case, having interm animations makes the most sense. It also adds to the lemings feel :)

EricLang
26-03-2009, 06:57 PM
Ok sounds good. Only thing is: the server does not really have to "play" the game, because it's not a global game (like WoW for instance). The game is played by 1 to max 10 people, so maybe (if i understood correctly) a Quake model is best:
One of the players who is actually playing the game with a group has the function of server? All synchronization is done through this one player of the group.
Of course the computer of the leading player is more busy than the other ones, but it seems to me that that's better than playing ALL games globally on one server.
Again: I have no experience with online programming at all. Just brainstorming on it, for the moment...

User137
26-03-2009, 10:04 PM
From programmer point of view it should be simplest to make server actually play the game and control it for all players. Having 1 client act as server is vulnerable to very difficult to find bugs that only certain players experience. Full server style makes all players equal. Still, you can make that server run as a thread within 1 client that creates the game.

EricLang
27-03-2009, 11:29 AM
Ok I can imagine that.
But one game takes a few megabytes of memory and a lot of processor time... Can one computer handle several games at the same time (let's say 100 games) with enough speed?

Memphis
27-03-2009, 11:55 AM
why would someone run 100 games on 1 computer?

no one runs 100 quake games on 1 computer.

EricLang
27-03-2009, 02:10 PM
There are hundreds of different levels, which can be played. When users are connected they can select a level to play. This means that all these different games (levels) must be processed on the server.

User137
27-03-2009, 03:59 PM
Some tips that come to mind:

- It is possible to make server only pass the control messages to players and not control the game itself. However that would mean games have to be in absolute synchronizity. (Different computers count differently with floating point numbers etc can make difference in time)

- Only 1 level per game is needed to load in memory at the time, rest are waiting in map files on disk. 1 game would not take much memory.

- If you are worried about server handling numerous games for many people, you can let server make 1 of the clients start a server. That would be kind of a Login-server, or similar to Battle.net. (This is not something i'd be worried at all at the beginning. Start from simple 1 game server and expand from there once skills are growing.)