[gameprogrammer] Re: Networking

On Monday 03 July 2006 07:38, Kevin Jenkins wrote:
> There are two approaches - event based and polling.  Both have pros
> and cons:

I guess I was more or less thinking about an event-based approximation of 
polling. I'll try to keep it more flexible though. ;)

> Make collisions event based, since they don't happen very frequently.
> Poll position at the same time, so that errors in the event
> transmissions are less visible.

Most approaches seem to be based on centralised "event" handling, i.e. the 
server handles all critical events (player collisions, weapon collision etc.) 
and informs the clients. I've always (perhaps out of some natural naivety 
regarding this topic :)

Like this (the current project is primarily a proof (or rather test) of 
concept; I plan on applying the resulting experience for a vertical 
shoot'em'up ala Galaga, with 2-player network mode): The "server" informs the 
client of all "unpredictable" (for both sides) events; in all other cases, 
the side that "causes" the event sends it to the other computer. E.g. if 
the "client" player dies, it sends the event to the client; however, 
the "client" still takes care of testing the client's shots vs. the foes 
(spawned by the server), so the "exact" collision testing is done for the 
player who fired the shot. I somehow expect that, for a classic shooter, this 
exactness would be important.

The usual approach, as far as I have found out yet, seems to be having the 
server handle *all* collision tests. Is there more to this than "just" 
protection against hacked clients?

> So for example, you can interpolate between positions on the recipient
> so that if you are knocked away you are still in the generally correct
> spot.  But when you get a collision event you know this will result in
> a large change, as well as show vehicle damage.  In your collision
> event you can include all the necessary info to reproduce the
> collision and take it from there.  The position updates will correct
> for any errors.

The one thing I'm mostly worried about here is lag. Mind you, I have 
absolutely *no* idea about typical values here (I study computer sciences, 
but when it comes to networking, the more I learn about it, the more I'm 
simply amazed that it works at all), and I don't have much practical 
experience with online gaming either.

My concern is this: I send all the necessary data, and the client reproduces 
the server's collision exactly - but n milliseconds too late. Wouldn't the 
results be obviously "odd"?

I have thought about timestamping my messages, both to ensure correct ordering 
of UDP packages (I'm still undecided about UDP vs. TCP; the majority seems to 
argue that UDP is more performant, while some individuals claim that the 
handling overhead doesn't leave a large advantage, and TCP handling is 
obviously simpler). For small lag, this would allow me to queue the messages 
and "trigger" them according to the current logical frame (after each 
graphical frame, I loop through the next n logical frames depending on the 
elapsed time), but if I get a message *after* I've already handled that 
frame, I'd have to either throw it away or do some sort of interpolation that 
so far seems like black magic to me. :)

> If you haven't looked at it yet, you might be interested in my network
> library, which solves some of your problems (
> http://www.rakkarsoft.com ).  Among the things I covered here, it
> gives you a nice way to transmit compressed orthonormal matrices and
> vectors.  It also gives you both reliable and updates, both in and out
> of order.  It also has a game level update system (ReplicaManager)
> which covers some of the issues of synchronization of object creation
> and destruction as well as scoping, to reduce bandwidth use.

I admit I'm very (probably overly) cautious about dual-licensed libs. I 
suppose mostly because I'm still trying to grasp the basic concepts involved, 
and I don't want to end up having found a nice working pattern and a library 
which (for whatever unlikely reasons, I admit) has the "wrong" license for me 
next project. In short - I'll rely on some LGPL stuff for now, but I'll 
definitely keep raknet in mind, particularly since I'm not really happy about 
having to deal with all the low-level networking myself. :)

Well, sorry for my (hopefully not too much all-over-the-place (no thanks to 
too many parantheses)) rambling. I guess a major part of my problem is lack 
of personal gaming experience - mostly, it's from some Need for Speed and 
Heretic several years back when my connection was still highly unreliable.

For what it's worth, I'm thinking about converting the current project into a 
kind of "the important basics of everything you need" tutorial once it works 
reasonably well. Looking at the mass of loosely-connected thoughts in this 
mail, I expect that'll require a LOT more organisation though. ;)

Thx,
Marian.

-- 
http://www.musgit.com
http://marian.musgit.com

Hofstadter's law: "It always takes longer than you think,
even when you take account of Hofstadter's law".


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: