Game Development Community

High bandwidth need using 12 vehicles

by Tcangussu · in Torque Game Engine · 01/24/2007 (5:11 am) · 1 replies

Hi,

I'm trying to put 8 players to play online together in a racing game.
In the game I will also have 4 NPCs running with the players.

Because of that I will have 12 players in the screen almost all the time,
I can also see the player behind me.

The problem is that the vehicle class need +/- 54 bytes to update it's position,
and since the position of the vehicles change evey time, all the vehicles always need to be updated.

// Vehicle update position code (packUpdate)
if (stream->writeFlag(mask & PositionMask))
{
stream->writeCompressedPoint(mRigid.linPosition); //vec3
mathWrite(*stream, mRigid.angPosition); // quaternion
mathWrite(*stream, mRigid.linMomentum); // vec3
mathWrite(*stream, mRigid.angMomentum); // vec3
stream->writeFlag(mRigid.atRest);
}

I also noticed that the packets start with +/- 25 bytes (maybe connection manager).
So I will need something around 673 bytes (12 * 54 + 25) to update all the players.

Using the packet size of 450 I have all the players lagged in the game, but removing this limit
and setting the packet size to +/-700 all the players have a smooth movement. So I'm certain that the problem is because of the amount of data sent.

I looked at the Player class, but it doesnt work in the same way of the vehicle class...
The player class seems to update the position, direction and velocity of the players,
it appears to update much less data than the vehicle class.


Anyone have any ideia how can I optimize the vehicle code, or how can I reduce the data traffic over the network??? I thought about not sending the mRigid.linMomentum and mRigid.angMomentum...

Thanks a lot!!!

#1
01/26/2007 (6:42 pm)
Here's some advice to hopefully get you started (and a bump so perhaps someone more knowledgeable will come along):

-Go through the engine and look for unnecessary write()'s (i.e. stream->write(someData);). The core engine code is typically pretty good about sending only what's necessary but certain community resources might require some optimization. Pay attention to how the variables in question are being used. There's no reason to write all 32 bits of a U32, for example, if the value never exceeds 1024. Simply changing that to a writeInt() (and a corresponding readInt()) can yield significant savings.

-Go through the engine and check to ensure everything is properly making use of the masking system. The code above should only be writing that data across the wire when PositionMask is set (this presumably occurs when a vehicle moves, which is quite often). It may be you have some resources which would benefit from the masking system.

-Up the packet size. As you said, upping the packet size is probably the easiest way of avoiding this problem but it depends entirely on your game.

-Are you mounting things to your vehicle using mountObject()? You might consider (if applicable) using images and mountImage(). Mounting a player to the vehicle might also be unnecessary depending on your game.