Blockland Forums > Modification Help
TypeMasks, what are they?
(1/2) > >>
Greek2me:
What are typemasks and are they server or client-sided? I know that doing something like (%player.getType() & $TypeMasks::PlayerObjectType) returns whatever $TypeMasks::PlayerObjectType is, but that's about all I know.
Amade:
As a most basic definition, a typemask is a category into which a physical object fits. They are similar to classnames in this way but they are much more flexible.

To get more in depth, typemasks are binary numbers. Looking at them in binary makes them significantly simpler to understand, in my opinion. For example, $Typemasks::PlayerObjectType is 16384 in decimal. In binary, this number is 100000000000000. $Typemasks::VehicleObjectType is 65536, 10000000000000000 in binary.

You begin to have some insight upon examining the two brick typemasks that are defined by default, $Typemasks::FxBrickAlwaysObjectType and $Typemasks::FxBrickObjectType. These are 67108864 and 33554432, respectively. In binary, one of them has one more zero than the other. However, getting the type off of a raycasting brick returns 100663296 - neither of these! Why is that? Let's look at the three in binary:

100000000000000000000000000 $Typemasks::FxBrickAlwaysObjectType
010000000000000000000000000 $Typemasks::FxBrickObjectType
110000000000000000000000000 Typemask of a raycasting brick

What this means is that a raycasting brick is both of these typemasks. If you disable raycasting on the brick and check its type, it will 67108864 (FxBrickAlwaysObjectType).

This is one flexibility of typemasks that classnames do not have - an object can belong to multiple typemasks. Checking if an object belongs to any of several typemasks is also easier than doing the same with classnames. The typemasks are "stacked" (I have no idea what any of the binary operations are called, I'm sure they have formal names) with a single | character. You can create the typemask a raycasting brick returns with this:

%mask = $Typemasks::FxBrickAlwaysObjectType | $Typemasks::FxBrickObjectType;

And as you know two binary numbers are "compared" with a single & character. If any bit of the number preceding the & is 1 and matches a 1 in the succeeding number, the operation will return true, else it is false.

I'm sorry if this was a substantially more thorough examination than you were looking for, I just wanted to be thorough and I find the way typemasks work to be very interesting.
otto-san:

--- Quote from: Amade on December 06, 2011, 09:32:12 PM ----snip-

--- End quote ---
Type masks are neat. :D
Chrono:
Now we just need collision masks. :)
Uristqwerty:
The operators are called bitwise operators, as they operate on the individual bits.

| is a bitwise or (1 if either bit is 1, 0 otherwise)
& is a bitwise and (1 if both bits are 1, otherwise 0)
^ is a bitwise xor (1 if one bit is 1 and the other is 0, 0 if both bits are the same)

Then there are a few others...

~ is a bitwise not. It only uses one number, and it turns 0 into 1, and 1 into 0. You use it like a minus sign for making negative numbers, used like ~42

>> is a bitwise right shift. It's basically the same as dividing by two a certain number of times. It's used like 47650 >> 3 (this is the same as dividing by 2 to the power of 3)

<< is a bitwise left shift, the opposite of the right shift.


Wikipedia has an article here.
Navigation
Message Index
Next page

Go to full version