PDA

View Full Version : Scaling up to multiplayer


mt_maui
2006.12.11, 03:00 AM
I'm in the very early stages of designing a turn based strategy game, one that I want to scale up gradually. One of the last things I want to add is multiplayer support, and I want to take that into consideration early before I end up coding myself into a corner and having to throw everything out and start over.

So I'm a little confused on how to proceed. One thing I'm considering is just creating a separate update loop for the client, and just forking it off when I need to contact the server:

if(multiPlayerGame == true) {
updateWithServer();
} else {
updateLocally();
}

Or would it make more sense to always be running as a client/server, and just have the client side connect locally for single player mode? Note that single player is going to be a big part of the game no matter what.

Ideally, I'd like to do something along the lines of the first solution, so that I can focus on the game itself and then go back and work out the networking aspect of it, but I'm not sure if that is realistic.

akb825
2006.12.11, 03:15 AM
You could have your update functions return the same data as would the server, which you would feed into your objects to update them. That way you aren't doing anything like running a server in the background and socketing the data to yourself which, while it would work, wouldn't be the most efficient method. Of course, you always want to do as much on the client as possible: that way you won't be quite as susceptible to hangups and you don't have to have a constant (and fast) stream of data just to run the game smoothly. (for a turn-based strategy game, that probably won't be an issue, unless you're trying to stream over the animations :p)

isgoed
2007.07.07, 08:42 AM
I can't really comment what the best way is to implement multiplayer. I do advise to let your network code and offline code run over the same code as much as possible. It can easily occur that a bug only occurs on network play and that may be difficult to notice and debug. my code looks something like:

on the senders part:
if(isNetworkingGame){
SendPlayerDestroyed(PlayerX)}
DestroyPlayer(PlayerX);

on the receiver part:
GetNewNetworkMessage(&message)
if(message == PlayerDestroyed){
DestroyPlayer(PlayerX);}

I also have some if(isHost) calls, since some calls only need to be handled by the host. Synchronisation may also be a major problem and you have to consider in advance how you are going to deal with missed messages.

Finnaly it is smart to consider networking from the beginning.