Real Time Strategy (RTS) Game - Multiplayer LAN Problems
Author |
Message |
Jephir
|
Posted: Thu Nov 29, 2007 7:27 pm Post subject: Real Time Strategy (RTS) Game - Multiplayer LAN Problems |
|
|
Hi everyone. I'm currently creating an RTS and have ran into a few design problems. I already have the basic features working (spawning, moving units, etc.), however there are a few problems with the multiplayer portion of the game. I'm trying to have multiplayer over LAN, and so far it's functioning fine (except for a bit of lag). A problem I have ran into is related to how to keep the game synced on the host and client computers.
I think there are two options that can be done for this. The first, which I am using right now, is to send "events" in the game to the other computer. For example, when a new unit is created, send a message to the other computer to create a unit. Or, when a unit is moved, send the location of where the ship is to be moved to the other computer. The nice thing about this method is that it is very efficient and you only have to send necessary information to the other computer. The problem is that if there is network lag, messages may be lost and this will cause a de-sync in the game.
The other method that I am thinking of using is to send the "gamestate" to the other computer instead. For example, during each tick of the game, all the unit positions and their current actions will be sent to the other computer, instead of just new events. This is fairly inefficient because a lot of data has to be resent, but ensures that both computers will be synced.
Another issue I am having is network lag between the two computers. I am using a using a direct connection using an Ethernet cable and router, however sometimes there is lag of up to 100ms. I'm not sure what is causing this. There is only one line of data being sent every tick of the game (all the information compressed into it), and the router has all ports open.
Any help would be appreciated, thanks! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Wolf_Destiny
|
Posted: Thu Nov 29, 2007 7:40 pm Post subject: Re: Real Time Strategy (RTS) Game - Multiplayer LAN Problems |
|
|
The problem I commonly found was that a character might get lopped off of the beginning or end, but I never actually "lost" any transmissions completely.
The way I solved it was to have a bunch of useless characters, just a few before and after, then use index and "marker" characters to get the actual info.
IE if CU was the command to create a unit, with position x:y then
Comp1 Sends:
Quote: ~~~~!CU120:358#~~~~
Comp2 Gets:
Quote: ~~~!CU120:358#~~
Comp2 Ignores everything except: (as in it takes everything from "~" to "#" by using index)
Quote: CU120:358
Comp2 creates a unit at 120,358
Hope that helps! |
|
|
|
|
|
|
|