Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Peaceman

why using Bitmasking

This topic is 6038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I read through TANSTAFFL''s tutorial on Iso maps, and he uses bitmasking. But where is the point? Why can''t you just loop through an array with the map values and then if y%2=0 forget shifting and else just shift by half a unit?

Share this post


Link to post
Share on other sites
Advertisement
Dredge, in this you are slightly incorrect... bitmasking is mostly useful to STORE information more compactly, such as using a single bit in a status byte to determine if a tile is walkable or not. That leaves you 7 more bits to store other simple info, such as whether or not the tile has objects on it or if it''s been dirtied by a sprite and needs to be redrawn.

A bitwise operation is generally not faster than a comparison of any basic data type like "if dwSomeData == 0x00008" because the CPU is always operating on 32-bit values anyway (depending on your platform of course). To compare a single bit against another you still have to load an entire word into a register.

A bitmask check is not really going to be any faster than a ^2 shift either, but it DEFINITELY look more readable in code:

if ( dwStatus & TILE_WALKABLE) ...

vs.

if ( dwStatus % 2 == 0 ) ...

Bitmasking is a very common practice, and when other people see the former code, they will know exactly what is going on.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!