linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ern0 <ern0@linkbroker.hu>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Multiplayer game
Date: Tue, 23 Feb 2010 21:33:26 +0100	[thread overview]
Message-ID: <4B843B96.40401@linkbroker.hu> (raw)
In-Reply-To: <27707442.post@talk.nabble.com>

> since I am not a good C programmer 

1. It's the smallest problem, wheter you're familiar with C programming 
or not.

A multiplayer game has several property, which are hard to implement 
each, and even harder to implement together. They are:
- managing a common scene wich is controlled by asynchronous user events;
- setting up communication infrastructure between a server and at least 
two clients;
- everything must be pretty quick.

2. Sockets: if the game is designed for LAN, socket is OK. But if your 
players are using internet, HTTP is a better choice - you can't sure 
that your players' firewall will enable using UDP, but HTTP is always 
enabled. It has overhead, and a bit harder to implement.

3. Sync

> Also how
> can I make the movements of each player atomic since I don't want the system
> to interupt one of the player and when it allocates the CPU back to it the
> other players have already been moved when the first player had to move
> before them. 

Yep, you're right, you've found it: it's the most important problem of 
the multi-user worlds. The solution is not trivial, but it's not rocket 
science, and I assume there're lot of good documentations on the net in 
this topic.

The problem is, that say, two players are pressing fire button at the 
very same moment, but both of them can see that the other player was 
launching the rocket a bit later than other player. That leads to chaos.

The solution is:
- time sync and
- message queuing.

Time sync: the server and each client (player) as well must have a 
clock, which are syncronized. It will be quite useful, see below.

Message queuing:
- When a player takes any action, it musn't be handled by the client 
immediatelly: the event just has to sent to the server.
- The server receives and queues the events arriving from clients. The 
most important: the server assigns a time stamp for each event. The 
value of the timestamp is some millisecs ahead (it must be enough for 
sending the message back to the client).
- The server sends the appropiate (soon upcoming, useful for the 
receiver client etc.) events to the clients (even ones which are 
generated by the same client, they just get back their events with 
timestamp).
- The client receives events, and performs the appropiate action, but 
not immediatelly, they're firing the action at the moment, which is 
described in the event's timestamp.
- If the time is synced between server and clients, all actions will be 
performed on each client at the very same moment. Because all clients 
are running the same code, and all clients has the same data (position 
of players etc.), every client will do the very same.
- It a client can't perform the event in-time, it must be download the 
actual scene state from the server.

And it's just the top of the iceberg.
-- 
ern0.scene.plus4.amiga.code.muzak
Haben Sie Fragen?


  parent reply	other threads:[~2010-02-23 20:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23 17:50 Multiplayer game iliali16
2010-02-23 18:11 ` Khalifa Rouis
2010-02-23 20:33 ` ern0 [this message]
2010-02-23 22:58 ` iliali16

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B843B96.40401@linkbroker.hu \
    --to=ern0@linkbroker.hu \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).