2
votes

I'm trying to implement multiplayer to my RTS game. It's not turn-based so the way I see it I should go with UDP, right?

I'm also a little bit confused about what should be sent to the server from the client. Every object displayed in the game (buildings, trees, units etc) is in an ArrayList of type GameObject (that keeps track of positions and all that good stuff). So one way to go would be to have the clients send their ArrayList to the server, and merge it with the others and then send it back. An other way would be to send the clients input (where he clicks and what's selected etc) to the server and have the server decide what should happen. That would cause a delay though when giving orders to units or whatever.

So I guess my question is, except for the one about using UDP/TCP, how I should structure the multiplayer part? What should be sent from the client to the server and so on.

1

1 Answers

4
votes

The type of networking you are describing is best for realtime games with few moving parts that can handle lost data (FPS, etc). The problem with RTS games is that they usually involve too many units to replicate with a standard UDP state replication model. Instead, most RTS games use whats called lockstep. This works by synchronizing the game state between each machine, and then transferring mouse click events to all the players of the game. Given the same initial game state, and same events applied, the game will look the same to all players. Either the TCP or UDP protocols could be used to achieve this, although TCP is probably easier.

Read about lockstep in Age of Empires:

1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond

Rather than passing the status of each unit in the game, the expectation was to run the exact same simulation on each machine, passing each an identical set of commands that were issued by the users at the same time. The PCs would basically synchronize their game watches in best war-movie tradition, allow players to issue commands, and then execute in exactly the same way at the same time and have identical games.