Game Development Community

What are Mask Bits?

by John Rockefeller · in Torque Game Engine · 04/22/2006 (12:05 pm) · 5 replies

This is probably the dumbest question for anyone with a working knowledge of the Torque engine or C++ programming in general, but I'm going to ask it any way, since I can't find any documentation that's easy to read on what these things are.

My game is currently experiencing a problem with my wheeledvehicle unpack/pack, but how does that affect your network and what exactly are Mask bits? Why do we get 32 and how do you get to that number?

Can anyone help me?

#1
04/22/2006 (1:00 pm)
The torque uses a bitmask to store network update flags.
the bitmask is a simple 4 byte int (long probably, been a long time since I looked)

a 4 byte int is broken up into 32 bits
each bit has a single value that affects the bitmask.

so..
you can build a bitmask using the 32 available bits.
this allows you to check for anyone of upto 32 "states" in the mask.

here is some simple code to see what is happening.
const long BIT_0 = 0x00000000;
      const long BIT_1 = 0x00000001;
      const long BIT_2 = 0x00000002;
      const long BIT_3 = 0x00000004; // Exclusive bit's for the mask
 
      const long BIT_ALL = BIT_1|BIT_2|BIT_3; // create a bitmask with all bits set

      long mask = BIT_0; // null bit use assignment.
      mask |= BIT_ALL;  // "or" it in so as to not modify current state but only add bits
   
      if((mask & BIT_1) == BIT_1)
      {
          // bit 1 is set.
      }

there is alot more to this obviously but this should get you started.
hope this helps.
#2
04/22/2006 (1:16 pm)
That's pretty smart. So this system doesn't always send the same stuff every time, it only sends what has it's bit set (IE: What has changed). Is this what they mean when it is dirty?

Secondly, I've got a problem with my vehicle packet. I've used the Transmission resource found on the site, but I split the transmission and engine sections into their own objects. I was thinking about doing that for all of the different parts my game will have (exhaust, transmission, suspension, etc.) but is that a dumb idea? Would it be better to just have it all in an Engine object and then put all the stats in there?
#3
04/22/2006 (1:24 pm)
Yep, dirty is when one or more bits are set in the update mask.

Depends really what your overall plan is with the now seperated pieces.
is it necessary? usable? featurefull? what are you getting from the split?
more code to write/test ? :)

I would start simple and prolly keep the transmission and engine as one part of the vehicle no?
get that to work for you.


Like if the reason to split them is so you can have them interchange. that probably isnt necessary.

but if you really want to take use of the datablock system and have mount points where this stuff goes
maybe you do?
I dont know it should work either way but you have to make sure the processing all these seperate objects in the right order.
#4
04/22/2006 (1:39 pm)
@John - Yes, you are correct. Each derived object of NetObject (this includes ShapeBase) has an enum defined in it's class with a list of masks that you can use to decide whether or not the object needs to be updated in unpack/pack update. You can find examples of them in every object derived from NetObject - just look for an enum with a list of declarations with the "mask" suffix (indicating it's a bit mask).

To set mask bit - use setMaskBits(myEnumHere);

There are only a total of 32 different bit masks you can use down the hierachy when deriving from NetObject. But this isn't usually a problem because when you need to update a certain property or characteristic of an object to be sent over the network, you usually need to send over a whole lot more (properties tend to depend on each other).

Your second problem seems to be more of a design decision that would ulitmately have to be your choice. I would personally keep it all in Engine object - but if it gets too crowded/complicated, split it up.

- Eric
#5
04/22/2006 (3:08 pm)
Thank you for your responses, guys. Every day I'm impressed more and more with how awesome the Torque community is.

I hear what you're both saying, though I have no experience in this area. Can I have your advice?

My game is one where people will buy different types of transmissions and engines and then swap them, much like gran tourismo or Forza motorsport. The players will have an inventory of parts and continually upgrade their cars over time.

I wanted to split it in code because that's how I have my design set up for the database of parts. But just because it's designed that way doesn't mean it has to be coded that way. There are going to be a lot of people playing online all at the same time and even if it's a little more confusing, I want the fastest possible solution.

Thanks!