[SDL] SDL_net latency
jared at wordzoo.com
Mon Aug 18 13:46:01 PDT 2003
[santi == sdl at libsdl.org on Mon, 18 Aug 2003 21:56:35 +0200]
santi> I show you here a sketch of the protocol I use:
Some games may require a completely synchronous game loop like you've
described. What's more commonly done, though is to have each desktop
be fairly autonomous. The implementation has a current state, and
assumes that the world will stay the same unless a network update is
received. So if 10 characters/sprites are heading in 10 different
directions, they will keep going that direction (on that one desktop)
until a network update is received. If it's been a long time since a
network update was received, the desktop might need to make the
characters "jump" a bit to get things up to speed.
The need for this style of implementation is what someone was hinting
at when they suggested putting the network code in another thread.
With current networking technology, you'll just not get the framerates
you're hoping for if you stick with a fully "lock-step, don't proceed
until next packet is received". You'll might be able to do ok over a
LAN (though you're already seeing performance problems), but with any
open-Internet implementation, you'll end up freezing the game
frequently. The problem people see with your design is that the whole
game will freeze for every single dekstop if just one computer has a
bit of a lag in sending out one single packet, which most people would
consider unacceptable gameplay.
Also, on a hub-based LAN, you'll can run into packet collisions, which
will cause a client to pause a random delay before trying again. This
will also freeze the game.
Consider redesigning your game loop around the "everything keeps
moving in the direction it was last moving" style, updating that state
whenever a packet happens to arrive (to a different thread).
None of this has anything to do with SDL, though.
-- jared at wordzoo.com
"We suffer primarily not from our vices or our weaknesses, but from our
illusions. We are haunted, not by reality, but by those images we have put
in place of reality." - Daniel J. Boorstin
More information about the SDL