Game Development Community

BitStream U32 U64 Write functions (for packupdate)

by David Schwanke · in Torque Game Engine · 06/14/2004 (1:31 pm) · 8 replies

Umm. Am I missing some basic code guru knowledge as to why there are no Bitstream write functions for U32 and U64 if they are declared in the rest of the code?

Is there a trick to makeing the functions there do the same thing?

I was thinking of using the RangedU32 function and putting in the whole range but that doesnt feel as 'sleek' as the way the rest of torque is coded. Would that work? My math is rusty, whats 2^32? :D (j/k i have calc :D)

Still doesnt solve the problem for U64.

Or do I have to do some nasty magic sending it one bit at a time?

Just doesnt make sense to me to not have one for those two unless those two are just not commonly used?

Thanks in advance. Feel like i missed something obvious.

#1
06/14/2004 (1:45 pm)
Also, why is there a writeInt and a writeSigned int. Both taking S32 values and bit counts? Wouldnt that be the same function? If one of them took U32's it would make more sense and I would be a happy man. :D
#2
06/15/2004 (5:32 am)
U32 i = 4;

stream->write(i);

U32 j;
stream->read(&j);
#3
06/15/2004 (8:16 pm)
Means I can pretty much read() and write() anything then doesnt it?

What then is the reason for the other specialized ones? Effeciency? So the code reads nice?

Just wanna learn. Thanks for the info though.
#4
06/15/2004 (9:11 pm)
The writeRangedU32 allows you to specify a range of possible values of the variable you are writting to the network. So if you happen to know that a particular value wont be smaller then or bigger then a particular range, you can specify those ranges and the network transmision code can compress the data much better.

There are a wide variety of functions to use. I suggest looking at the projectile or shapebase or player packUpdate and unpackUpdate functions. They use a variety of different methods.
#5
06/15/2004 (10:16 pm)
Yah, I guessed as much. I guessed the meaning of most of the read/write functions listed in the torque documentation on the bitstream class.

I was just curious why functions were written for certain variable types and not others. And why there seemed to be two different functions for the same variable type. I just didnt see the rhyme or reason.

I did however not think to check to see how read/write by themselves were used. So Ill look into that.
#6
06/16/2004 (2:20 pm)
Read/write are the generic variety. You pass them almost any type and they'll work. But they're also inefficient.

So there are these other varieties that exist for more specialized uses, as Robert mentions.
#7
06/16/2004 (8:33 pm)
So then does it make sense if I use a particular type often enough I should think about writing a specialized version for it?

Or is the list of ones already written everything that can be optimized and everything thats left is already as effecient as it gets?

Not saying i have the skills now to dig that deep into the source, but optimizing 6 months to a year from now it might make sense. (Like I'll remember this conversation. :P)
#8
06/16/2004 (11:24 pm)
It depends what you're doing and how. Optimization is bred of specialization.