Adding Variables to packUpdate
by Jeff Trier · in Torque Game Engine · 09/20/2003 (6:07 am) · 2 replies
Hi Guys and Gals,
I have just added a few variables (representing skills) to the player class.
I wasn't able to get the game to recognize certain variable changes in the game, even stock variables such as changing "maxForwardSpeed". If I change the variables in the datablock, before running the game, the changes work, otherwise they don't.
After a fair bit of reading, it appears that I need to have the variables integrated with packUpdate and unpackUpdate. After a fair bit more searching through forums and source, I was unable to find a tutorial or good example on how to do this. I will chalk that up to me being still new to C++ as I am sure most of you were able to figure it out by example. :)
Any help on this would be great!
-Jeff
I have just added a few variables (representing skills) to the player class.
I wasn't able to get the game to recognize certain variable changes in the game, even stock variables such as changing "maxForwardSpeed". If I change the variables in the datablock, before running the game, the changes work, otherwise they don't.
After a fair bit of reading, it appears that I need to have the variables integrated with packUpdate and unpackUpdate. After a fair bit more searching through forums and source, I was unable to find a tutorial or good example on how to do this. I will chalk that up to me being still new to C++ as I am sure most of you were able to figure it out by example. :)
Any help on this would be great!
-Jeff
About the author
Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.
#2
That gives me some understanding as to how the masks work. I am going to have to digest this a little while.
Thanks! :)
-Jeff
09/20/2003 (12:46 pm)
Thanks Chris,That gives me some understanding as to how the masks work. I am going to have to digest this a little while.
Thanks! :)
-Jeff
Torque Owner Chris \"Hobbiticus\" Weiland
You can use flags/bitmasks in order to block writing in certain instances. You'll see a lot of things like this:
if (stream->writeFlag(mask & ShieldMask)) { //do some more writing }And then a matching:
if (stream->readFlag()) { //do some more reading }This might be a little hard to understand, but basically, "mask" is a 32 bit integer. You can think of this as a list of boolean values, since a 32 bit integer is just 32 bits, or bools, interpreted as an integer. Then, each type of mask (PositionMask, InitialUpdateMask, etc) is another 32 bit integer, defined in an enumeration. Usually, each mask type has exactly one bit in it's 32 set to 1. And, each mask type is usually unique, so each mask type affects a different bit position. Basically, every mask type maps to a different bit.
So, when you use the & operator, it's like the intersection operation in sets. It evalutes each bit individually and returns the bits that are both true in the left and right variables. Then, when any number is evaluated in an if statement, any non-zero number is considered to be "true". So, as long as the mask and mask type overlap in at least 1 bit, it returns true. If they don't share any bits, then it returns false.
To put it graphically...
Let's just consider 8 bits because I don't want to write out 32 :)
Say the mask is 00110010, and PositionMask is 00000010. If you line up the bits, you get something like this:
00110010 <-- mask
00000010 <-- PositionMask
They both share the second to last bit, so (mask & PositionMask) would return true. Now, if RotationMask is 00001000, the bits would line up like this:
00110010 <-- mask
00001000 <-- RotationMask
They don't share any bits, so it would return false.
So, if you wanted to write a 32 bit integer to the client only at certain times, every time you didn't want to send it, you'd write 1 bit (just the flag), and when you did want to, you'd write 33 bits (the flag + 32 bit integer). It makes the net code a LOT more efficient when things don't have to be transmitted all the time.