Game Development Community

Bits And Mask

by Eyaly · in Torque Game Builder · 07/16/2008 (12:53 pm) · 7 replies

Hi
i have some object that i want to be ignored from pickRadius function.
this object is set to group number 1

lets say we have Ship in group 1
in this example Ship is the "%this".

i want ship and all group 1 to be ignored from pickRadius function
so i set
%this.groupMask = bits(0);

then
%targets = %this.pickRadius(%this.position,15,%this.groupMask,%this.layerMask,false );

but its not working as i expecting.
do i miss something?

#1
07/16/2008 (1:29 pm)
If you want it pick everything except group 1, then you need to do something like this:

for (%i = 0; %i <= 31; %i++)
    %this.groupMask |= bits(%i);
 
// Remove group 1
%this.groupMask -= bits(1);

If you aren't concerned with a layer mask, just set it to -1 to pick all layers. If you want to ignore the player from the pick, you need to add in one more argument on the end.

Also, if your ship is "%this", then you'll need to pick the scenegraph, not the player:

%this.getSceneGraph().pickRadius(...);
#2
07/16/2008 (1:32 pm)
The groupmask and layermask you pass to pickRadius is the mask for what you DO want to pick. So if you want all groups/layers except 1, you need to do an XOR. I'm not sure if this is the correct syntax for an XOR in torqueScript, but you might try this...

%groupMask = 0xFFFFF ^ BIT(1);
%layerMask = 0xFFFFF ^ BIT(1);

%targets = SceneWindow2D.getSceneGraph().pickRadius( %this.position, 15, %groupMask, %layerMask, false );

Alternatively, if its just one object you want to ignore, you could do...
%targets = SceneWindow2D.getSceneGraph().pickRadius( %this.position, 15 );
for ( %i = 0; %i < getWordCount(%targets); %i++ )
{
   %obj = getWord(%targets,%i);
   if ( %obj == %avoidObj )
      continue;

   // do stuff..
}
#3
07/16/2008 (1:47 pm)
Use James' method, I didn't even know you could do what he just said!
#4
07/16/2008 (3:10 pm)
Ok it appears that works, but I got my number of F(s) wrong.

8 F(s) = 32 BITS

%groupMask = 0xFFFFFFFF ^ BIT(1);
%layerMask = 0xFFFFFFFF ^ BIT(1);

As it turns out this is the same as...

%groupMask = -1 ^ BIT(1);
%layerMask = -1 ^ BIT(1);

Since the bit pattern of -1 and U32_MAX is the same.

Whichever way floats your boat (or game).
#5
07/17/2008 (1:58 am)
Hi

this is what im trying to do:

i set Ship to be in group 1 ( Ship is the %this )
then i turn off bit 0
%this.groupMask = 0xFFFFFFFF ^ BIT(0);
%targets = %this.owner.scenegraph.pickRadius(%this.owner.position,%this.MagnetRadius,%this.groupMask,%this.layerMask,false );

still not working.
any idea?
#6
07/17/2008 (2:40 am)
Hi
problem solved.

pickRadius return all objects in a given radius but also return the %this.owner
so i just need to ignore the %this.owner and the problem is eleminated.

bit manipulation works great.

thanks
#7
07/17/2008 (10:23 am)
If your ship is in group 1 and you want to turn off the bit for group one shouldn't that be...

0xFFFFFFFF ^ BIT(1)

not...

0xFFFFFFFF ^ BIT(0)

I also wouldn't assign to %this.groupMask because that sounds a lot like it could be a real field and overwriting something, or even if not, it could be called something better like %this.enemyGroupMask (assuming they are enemies).