PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

bit vectors/arrays?

I have collision detection on my map, but it's just lame rectangle detection (32x32 areas). I was thinking of making it insanely accurate by overlaying a bit vector, so I can mark each individual pixel collidable or not.

However, I'm not seeing any C++ keyword for bit, and the closest thing I can come across is unsigned char (which BOOL is typedef'd as). This or int would typically be acceptable, but I'm considering the size of my saved map files. Obviously bits would be ideal, but I'm afraid ints could produce quite large file sizes.

Anyone have suggestions? Thanks in advance.
C++ doesn't have a bit datatype.

For a 32*32 tile long integers would be perfect since you can hold one line (32 bits) of data in one int.

Code could look like this:

Code:

int cell[32];

int checkbit (int x, int y)
{
return cell[y]&(1<<x);
}

void setbit (int x, int y)
{
cell[y]|=(1<<x);
}

void clearbit (int x, int y)
{
cell[y]&=^(1<<x);
}


and so on.

I wouldn't use bytes for such a task.
hi dan,

take a look at this link

http://www.ifm.liu.se/~ulfek/projects/2 ... ction.html

it should help you out.
If you had a compiler that supported template specialization, vector<bool> should do the bit packing for you. I'm a bit out of the loop regarding PPC compilers, so who knows how useful that info is.