Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working on a simple two player networked asteroids game using XNA and the Lidgren networking library. For this set up I have a Lidgren server maintaining what I want to be the true state of the game, and the XNA game is the Lidgren client. The client sends key inputs to the server, and the server process the key inputs against game logic, sending back updates. (This seemed like a better idea then sending local positions to the server.) The client also processes the key inputs on its own, so as to not have any visible lag, and then interpolates between the local position and remote position. Based on what I have been reading this is the correct way to smooth out a networked game. The only thing I don’t get is what value to use as the time deltas.

Currently every message the server sends it also sends a delta-time update with it, which is time between the last update. The client then saves this delta time to use for its local position updates, so they can be using roughly the same time deltas to calculate position updates.

I know the XNA game update gets called 60 times a second, so I set my server to update the game state at the same speed. This will probably only work as long as the game is working on a fixed time step and will probably cause problems if I want to change that in the future. The server sends updates to clients on another thread, which runs at 10 updates per second to cut down on bandwidth.

I do not see noticeable lag in movement and over time if no user input is received the local and remote positions converge on each other as they should. I am also not currently calculating for any latency as I am trying to go one step at a time.

So my question is should the XNA client be using its current game time to update the local game state and not being using time deltas sent by the server? If I should be using the clients time delta between updates how do I keep it in-line with how fast the server is updating its game state?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

The best way to prevent lag in a two person game is to connect them with a peer to peer library. This means that you are using the server to pair users to games but once the arcade mode of the game starts you connect them directly to minimize lag.

Here is a great resource about different multi-player gaming architecture - http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

It's important to note however that P2P is not a recommended architecture for games that include more than 2 players. The lag time becomes a factor of the weakest link in the chain and the more links you have the bigger the chances you will have one of the users on a slow connection that slows everyone down.

share|improve this answer
    
I am using a server because I eventually plan on adding in more players. I just started with two to make it simple. –  aalcutt Oct 9 '12 at 15:59
    
I see. In that case - your architecture is a good choice. I think there should be a way to increase the updates per second on the client side but request only to send the time sensitive information or simply the delta from the last time. This way the bandwidth usage is not too high. –  Scott Fisher Oct 9 '12 at 16:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.