Network Play: Planning Ahead Has Advantages
After ~10 hours of coding, suddenly, Gpremacy has the basics of network play. I’m not kidding - I open a copy on each computer on my desktop, they all connect to a server and units move around the map on each screen! There are a few synchronization issues, and I haven’t coded up selecting which country you wish to play, but the toughest part, getting the data from client to client, is done.
Warning: The following is very geeky!
The truly amazing thing is how simple this ended up being. You see, I planned ahead. Everything in Gpremacy which affects the game state (e.g., everything important) happens in a particular code object called a Command object. These things all have an Execute() method which does their magic, and the game creates a Command object for each action a player takes, and then calls that Execute() function. To make this work for network play all I had to do was send these Command objects to each client and Execute() them there. Sending them to each client was amazingly simple through C#’s BinaryFormatter::Serialize() method.
Keeping everything as a Command object has an additional bonus: implementing an Undo function is trivial.
This is a practical example of the Command Design Pattern’s ability to take names and kick serious arse.
I expect there’s about 10 more hours of work left in multi-play support. Sweet.
Nothing like going from Local -> Network Play in a complicated game in ~ 2 days.
3 Comments so far
Leave a reply
*POUNCETEHPUG!!* XD
booyah!
Very much awesome. You are such a nerd, but you seem to really love designing this stuff, so I support it, and encourage you to make 3V1L amounts of money from it.