Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

How to clear this offset bit?

This topic is 874 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

void Remove(const T* inValue)
{
    int offset = inValue->x*MAXTILE_YLEN + inValue->z;
    mbVisited[offset] &= ~(1 << inValue->direction);
    Count--;
}

BYTE     mbVisited[MAXTILE_XLEN*MAXTILE_YLEN];

I want to clear the corresponding mbVisited bit based on the x,y and dir given as
the argument to Remove.
But I am not sure if this would work or not?
Thanks
Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites
Advertisement
Did you test it? We are not your Visual Studio debugger.

You did not give us enough information and it would have been faster just to try it in your debugger (since you have already written the code).
The array is based off X and Y but your offset is calculated via X and Z. Why?
Is direction the bit index into that byte? 0-7?

You’ve already written it, so why did you post it here instead of just testing it in a debugger? Why don’t you tell us if it works or not?


L. Spiro

Share this post


Link to post
Share on other sites

I need to check it. But for the time being, it is working as normal.

But I am not sure, because I copy it off somewhere from the web.

Share this post


Link to post
Share on other sites

You could verify the function by reading the documentation of the bitwise operators used therein, and testing it by feeding various values to it and comparing the returned values with known, expected values. It would also be a good chance to learn unit testing.

 

It is dangerous to use copy/pasted code in production projects, if you don't understand what it does. When stuff breaks, it is your fault, whether or not you understand why.

Edited by Nik02

Share this post


Link to post
Share on other sites

Unit tests are your friend. An important step when integrating 3rd-party code is to write unit/integration tests that ensure it does in fact work as you think it does.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!