Game Development Community

32 hurts me

by Joobot · in Torque Game Engine · 08/20/2005 (6:24 am) · 2 replies

I have a piece of code here i need some help with:

if (stream->writeFlag(mask & AgilityMask))
	   stream->writeInt(mAgility,5);

the AgilityMask is set in a function I have called SetAgility. I use the agility variable as a multiplier for all my speed variables. If I set my agility to 31, the game runs smooth, but if it's 32, the client isn't keeping up with the server, resulting in chuggy gameplay. Here's how the client recieves the data.

if (stream->readFlag())
   {
	   S32 agility = stream->readInt(5);
	   setAgility(agility);
   }

and here is the actual function:

void Player::setAgility(S32 value)
{
   if(value > 0)
      mAgility = value;
   else
      mAgility = 1;

   mMaxForwardSpeed = mDataBlock->maxForwardSpeed * ((mAgility + 20) / 20.0);
   mMaxBackwardSpeed = mDataBlock->maxBackwardSpeed * ((mAgility + 20) / 20.0);
   mMaxSideSpeed = mDataBlock->maxSideSpeed * ((mAgility + 20) / 20.0);
   mMaxUnderwaterForwardSpeed = mDataBlock->maxUnderwaterForwardSpeed * ((mAgility + 20) / 20.0);
   mMaxUnderwaterBackwardSpeed = mDataBlock->maxUnderwaterBackwardSpeed * ((mAgility + 20) / 20.0);
   mMaxUnderwaterSideSpeed = mDataBlock->maxUnderwaterSideSpeed * ((mAgility + 20) / 20.0);
   mJumpForce = mDataBlock->jumpForce * ((mAgility + 20) / 20.0);
   mDoubleJumpForce = mDataBlock->doubleJumpForce * ((mAgility + 20) / 20.0);

   if(isServerObject())
      setMaskBits(AgilityMask);
}

How do I make it so it doesn't chug.

#1
08/20/2005 (8:51 am)
With a 5-bit integer, you can only store values from 0 to 31 (if its unsigned, which seems to be how the net code is treating it). The second parameter in writeInt is the number of bits to write. Raise that and readInt's parameter to 6 and you shoud be able to use values up to 63.
#2
08/20/2005 (11:10 am)
Great, thx.
I thought 32 was the first number to use 5 bits, but it's the first to not.