Advertisement

A little verification!!

Started by February 01, 2005 10:58 AM
8 comments, last by toXic1337 20 years ago
Hey all, So far, here's the scoop. My game is a 2d side scrolling action game designed in a sense much like Smash Bros on N64. It's written in C++/SDL and uses Winsock TCP for communication. TCP, as I have found, is my first problem. It lags. Sooooo... I've decided to use RakNet for my game as a reliable UDP solution. What I'm looking for is any suggestions before I go out and put work into implementing RakNet (im lazy sorry :D ). Basically, all I'm doing is sending a struct with: 1)Character info (which sprite to draw) 2)Position (x,y) 3)Attack state(basically whether or not a client hit another client) Any suggestions or critiques of this system are welcome also. As I have said before and will say again, I'm new to the whole networking in games thing, but im learning fast and I hope to stop bugging people soon :P. Well thanks guys! PS: For the position I was thinking about instead of sending an absolute position... maybe just sending a velocity and let the client to some calculation. Give me your thoughts on this please.
toXic1337
Maybe I am getting this backwards. But UDP does not care if the packet ever gets there, it just sends the information and calls it good. This could cause a problem I think, if packets get lost in transit, the the character will 'leap' past the last movement frame. I think it could also recv the lost packet, get it out of order, and jump the player back to where the missing movement was. That is just something to think about when you are choosing the protocol. TCP may have a bit more lag, but the lost/out-of-order packets get reported to the sender, so they will be retransmited to the reciever.

absolute position VS veolicty,
I say direction and velocity based over absolute position, because of the prevoius point.
Advertisement
Do you want a client/server model or something p2p?

You need timestamps in your data, latency varies and a packet send later might arrive first and the one send first might arrive 1 sec later -> character jumps around

Move the remote characters according to the usual rules of your game and assume either that they continue doing whatever they are doing now or that they do nothing.

If that isn't good enough you need a real prediction algorithm.
Here's what I've been told:

1) that "RakNet" is a layer that is placed above winsock's traditional UDP in order to take care of all the "out-of-orderness" and that it is a reliable solution to UDP implementation into games.

I'm using a client/server model with only 2 players at the moment.

Is RakNet not the savior and solution to all my TCP woes? Or should I be looking elsewhere to solve problems that I do not forsee? Maybe I'm not getting the point of the high-level API's. If I'm wrong in saying that RakNet takes care of the unreliability of UDP please tell me what it does. I really want to get a firm grip on the big picture.
toXic1337
Read the manual, it's quite good. Resending and reordering are optional.

Timestamping is necessary for a nice real-time look and feel over the internet.
I've never used RakNet but one of the common problems with reliable UDP is that what you're doing is basically reimplementing TCP which doesn't exactly buy you much. You can eliminate some of TCP's congestion control logic (e.g. slow start) so there's room for some improvement. But don't expect your lag problems to be magically solved for you. Maybe they'll improve under some conditions and maybe they won't.
-Mike
Advertisement
You could also look at OpenTNL for a library that's alternative to RakNet, or take a look at the Forum FAQ for a bigger list.

The biggest challenge in networking is designing your data, how you talk about your data, and how you distribute your data. This has to be done to match both your application domain (the game) and your implementation domain (the network). When you change networking methods, you usually also have to change how you deal with your data.

So, when you move from TCP, which is "guaranteed" but jittery/laggy, to UDP, you will likely need to change the way that you interpolate and render the players (i e, how you interpret the data you have available). That's where the challenge is, rather than in the low-level networking code.
enum Bool { True, False, FileNotFound };
Quote:
Original post by toXic1337
Here's what I've been told:

1) that "RakNet" is a layer that is placed above winsock's traditional UDP in order to take care of all the "out-of-orderness" and that it is a reliable solution to UDP implementation into games.

I'm using a client/server model with only 2 players at the moment.

Is RakNet not the savior and solution to all my TCP woes? Or should I be looking elsewhere to solve problems that I do not forsee? Maybe I'm not getting the point of the high-level API's. If I'm wrong in saying that RakNet takes care of the unreliability of UDP please tell me what it does. I really want to get a firm grip on the big picture.


just to reiterate, yes, RakNet offers reliable UDP, and can be ordered if you want as well. it also offers different ordering channels, and send priorities, as well as packet splitting and coalescing (sp), bandwith throttling, secure connections for both authentication and encryption, huffman string encoding, bit packing, etc. etc. man i love RakNet [grin].
FTA, my 2D futuristic action MMORPG
One thing I would try BEFORE you move on to something else is to disable the nagle algorithm under TCP. This algorithm waits for a certain timeout before it sends data so that it can bundle larger blocks together. Disabling causes data to be sent immediately.

Thanks for all the feedback,

I'm gonna stay with RakNet's reliable UDP (although I will try disabling the TCP delay real quick for kicks and giggs). Again thanks for all the feedback and I'll probably be back with a moderately cool ... cool game! :D
toXic1337

This topic is closed to new replies.

Advertisement