Quote:Original post by graveyard filla
Basisor, i guess i just dont understand exactly how this all works. i mean, the whole XOR thing confuses me really.
also, if your not using all the bits in that integer, how do you convert the integer to something that is N bits big, for sending over the wire?
btw: i thought a UDP packet minimum was 28 bytes?
as hplus said i use ^ as power not as XOR
well the server and the client define a format for a vector
lets say
DELTA_FLOAT_VECTOR (7,N)
where N is the number of bits the integer uses and 7 is the exponent which you use to multiply a float with
2^7 = 128
so you multiply a float with 128 and move the decimal 2 positions to the right
ab,cd*128 = ab,cd*100 + ab,cd*28 >abcd,00
so on the server and on the client you know the number of bits of the integer and the exponent to use to convert the abcd->ab,cd *rounding error: loss of precision*
HL1 does this btw
now i think you wanted to know how to pack a 20 integer into a buffer right?
ok i have a gamestate class which sums up all the variables i send and get the number of bits needed to create a buffer
iBits = getBitsNeeded();
iBytes = iBits / 8;
if(iSpace = iBits%8){//modulo 8
++iBytes; //add one byte to reach >= iBits size
}
ok now we have got a buffer large enought to write the variables to
now you need a routine to write x bits of a variable to the buffer
i don t have my code on this computer now, but i think it shouldn t be too difficult to figure out the rest on your own
my routine is approximately 8-10 lines of code but still unoptimized
if you wish ill post it here but you should try it on your own its a nice practise :)