X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbitmask.h;h=e699a7ff56ae28fb864d778f4943ac1865af6803;hb=4c53a552c13dbe9d587e34e3cf48e82877d09288;hp=932f8c4a53ea148b4abe4cca4d3671d6877ca295;hpb=2f395aba3974db45f45a8587ed423a3abeab4cd5;p=supertux.git diff --git a/src/bitmask.h b/src/bitmask.h index 932f8c4a5..e699a7ff5 100644 --- a/src/bitmask.h +++ b/src/bitmask.h @@ -10,7 +10,6 @@ * to check for collisions. * The current implementation uses 32 bit wide stripes to hold * the masks, but should work just as well with 64 bit sizes. - * (Note that the current bitcount function is 32 bit only!) * * The overlap tests uses the following offsets (which may be negative): * @@ -26,11 +25,6 @@ * with some kind of pre-sorting to avoid comparing objects far from * each other. * - * BUGS: No known bugs, even though they may certainly be in here somewhere. - * Possible performance improvements could be to remove the div in - * bitmask_overlap_pos() and to implement wider stripes if the masks used - * are wider than 64 bits on the average. - * * Performance of the various functions goes something like: * (relative timings, smaller is better) * @@ -61,15 +55,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef BITMASK_H -#define BITMASK_H +#ifndef SUPERTUX_BITMASK_H +#define SUPERTUX_BITMASK_H #include +#include /* Define INLINE for different compilers. */ #ifndef INLINE # ifdef __GNUC__ -# define INLINE __inline__ +# define INLINE inline # else # ifdef _MSC_VER # define INLINE __inline @@ -80,15 +75,15 @@ #endif #define BITW unsigned long int -#define BITW_LEN 32 -#define BITW_MASK 31 +#define BITW_LEN (sizeof(BITW)*CHAR_BIT) +#define BITW_MASK (BITW_LEN - 1) #define BITN(n) ((BITW)1 << (n)) -typedef struct bitmask +struct bitmask { int w,h; BITW *bits; -} bitmask; +}; /* Creates a bitmask of width w and height h. * The mask is automatically cleared when created. @@ -96,6 +91,9 @@ typedef struct bitmask bitmask *bitmask_create(int w, int h); void bitmask_free(bitmask *m); +void bitmask_clear(bitmask *m); +void bitmask_fill(bitmask *m); + /* Returns nonzero if the bit at (x,y) is set. * Coordinates start at (0,0) */ @@ -123,7 +121,7 @@ static INLINE void bitmask_clearbit(bitmask *m,int x,int y) int bitmask_overlap(const bitmask *a,const bitmask *b,int xoffset, int yoffset); /* Like bitmask_overlap(), but will also give a point of intersection. - * x and y are given in the coordinates of mask a, and are untouched if the is + * x and y are given in the coordinates of mask a, and are untouched if there is * no overlap. */ int bitmask_overlap_pos(const bitmask *a,const bitmask *b,int xoffset, int yoffset, int *x, int *y); @@ -140,4 +138,4 @@ void bitmask_draw(bitmask *a,bitmask *b,int xoffset, int yoffset); /* Create a bitmask from a SDL_Surface */ bitmask* bitmask_create_SDL(SDL_Surface* surf); -#endif +#endif /*SUPERTUX_BITMASK_H*/