diff options
Diffstat (limited to 'clld.c')
-rw-r--r-- | clld.c | 81 |
1 files changed, 24 insertions, 57 deletions
@@ -13,8 +13,10 @@ #include <string.h> #include <unistd.h> #define TERASGN(a, b, c, d) (a) ? (b = d) : (c = d) +#define max(a, b) (abs(a-b)+(a+b))/2 +#define min(a, b) -max(-a, -b) -enum {THM, AABB, PPX }; +enum {THM, AABB}; /* Collision type */ int colltype = -1; @@ -72,8 +74,8 @@ int main(int argc, char **argv) { double d1; double d2; - /* Bitmask used in Per Pixel, and Tile Heightmap collision. */ - uint8_t **bitmask; + /* Heightmap, used in Tile Heightmap collision. */ + uint8_t *heightmap; /* X axis collision. */ unsigned int clx : 1; @@ -117,32 +119,11 @@ int main(int argc, char **argv) { */ tmp.w = atoi(strtok(buf, ",")); tmp.h = atoi(strtok(NULL, "\n")); - /* Initialize y axis of bitmask. */ - if (colltype == THM || colltype == PPX) - tmp.bitmask = malloc(sizeof(uint8_t *)*tmp.h); - /* Initialize x axis of bitmask. */ - if (colltype == PPX) - for(unsigned int i = 0; i<tmp.h; i++) - tmp.bitmask[i] = malloc(sizeof(uint8_t)*tmp.w); - /* Get Per Pixel data. */ - if (colltype == PPX) { - for (unsigned int j = 0; j<tmp.h; j++) { - buf = NULL; - size_t newidth = getline(&buf, &size, stdin); - /* - * Format is: - * - * 000111000... Until bit w-1. - * . - * . - * - * Until bit h-1. - */ - tmp.w = (newidth >= tmp.w) ? tmp.w : newidth; - for (unsigned int i = 0; i <tmp.w; i++) - tmp.bitmask[j][i] = buf[i] - '0'; - } - } + /* + * Initialize heightmap. + */ + if (colltype == THM && coll) + tmp.heightmap = malloc(sizeof(uint8_t *)*tmp.w); /* Get Tile Heightmap data. */ if (colltype == THM && coll) { /* Get vertical flip flag */ @@ -161,36 +142,25 @@ int main(int argc, char **argv) { for (unsigned int i = 0; i <tmp.w; i++) { char *tmptok = strtok((i == 0) ? buf : NULL,","); tmptok = (tmptok == NULL) ? strtok(NULL,"\n") : tmptok; - tmp.bitmask[i] = (uint8_t *)((atoi(tmptok) <= tmp.h) ? atoi(tmptok) : tmp.h); + tmp.heightmap[i] = (uint8_t *)((atoi(tmptok) <= tmp.h) ? atoi(tmptok) : tmp.h); hmpeak = (atoi(tmptok)+1 >= hmpeak) ? atoi(tmptok)+1 : hmpeak; } } /* - * Copy width, height, and bitmask over - * to either the Cursor, or the Floor. + * Copy width, and height to either + * the Cursor, or the Floor. */ (coll) ? (floor.w = tmp.w) : (cursor.w = tmp.w); (coll) ? (floor.h = tmp.h) : (cursor.h = tmp.h); - (coll) ? (floor.bitmask = tmp.bitmask) : (cursor.bitmask = tmp.bitmask); + if (coll) + floor.heightmap = tmp.heightmap; /* Debugging stuff. */ if (verbose >= 1) { if (colltype == THM && coll) for (unsigned int i = 0; i<floor.h; i++) - printf((i < floor.h-1 && i % 16 != 0 || i == 0) ? "%u, " : ("%u\n"), floor.bitmask[i]); - - - if (colltype == PPX) { - for (unsigned int j = 0; j<((coll) ? floor.h : cursor.h); j++) { - for (unsigned int i = 0; i<((coll) ? floor.w : cursor.w); i++) - if((coll) ? floor.bitmask[j][i] : cursor.bitmask[j][i]) - printf("%u", (coll) ? floor.bitmask[j][i] : cursor.bitmask[j][i]); - else - printf(" "); - printf("\n"); - } - } + printf((i < floor.h-1 && i % 16 != 0 || i == 0) ? "%u, " : ("%u\n"), floor.heightmap[i]); } @@ -259,9 +229,9 @@ int main(int argc, char **argv) { if (cursor.clx) { if (cursor.a2-floor.a1 < 0 || cursor.a2-floor.a1 > floor.w) { /* Is the Cursor coming from the left? */ - if (cursor.a2 > floor.a1-(int)cursor.xvel-1 && floor.b2-cursor.b2 < (int)floor.bitmask[0] && !floor.flp && cursor.xvel > 0) + if (cursor.a2 > floor.a1-(int)cursor.xvel-1 && floor.b2-cursor.b2 < (int)floor.heightmap[0] && !floor.flp && cursor.xvel > 0) cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1; - else if (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && floor.b2-cursor.b2 < (int)floor.bitmask[floor.w-1] && !floor.flp && cursor.xvel < 0) + else if (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && floor.b2-cursor.b2 < (int)floor.heightmap[floor.w-1] && !floor.flp && cursor.xvel < 0) cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1; /* Is the Cursor coming from the right? */ if (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && cursor.b1-floor.b1 < 0 && floor.flp && cursor.xvel < 0) @@ -274,7 +244,7 @@ int main(int argc, char **argv) { if (cursor.cly) { if (cursor.a2-floor.a1 < floor.w) { cursor.yvel = 0; - newy = (int)floor.bitmask[cursor.a2-floor.a1]; + newy = (int)floor.heightmap[cursor.a2-floor.a1]; /* Is the Floor, really a floor? */ if (cursor.b2 > (floor.b2-hmpeak)-(int)cursor.yvel && floor.b2-cursor.b2 >= 0 && !floor.flp) cursor.pos.y = ((floor.b2-cursor.h)-newy)-(int)cursor.yvel; @@ -318,9 +288,9 @@ int main(int argc, char **argv) { if (cursor.clx) { if (cursor.c2-floor.c1 < -1 || cursor.c2-floor.c1 > floor.w) { /* Is the Cursor coming from the left? */ - if (cursor.c2 > floor.c1-cursor.xvel-1 && floor.d2-cursor.d2 < (int)floor.bitmask[0] && !floor.flp && cursor.xvel > 0) + if (cursor.c2 > floor.c1-cursor.xvel-1 && floor.d2-cursor.d2 < (int)floor.heightmap[0] && !floor.flp && cursor.xvel > 0) cursor.pos.fx = (floor.pos.x-cursor.xvel)-cursor.w-1; - else if (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && floor.d2-cursor.d2 < (int)floor.bitmask[floor.w-1] && !floor.flp && cursor.xvel < 0) + else if (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && floor.d2-cursor.d2 < (int)floor.heightmap[floor.w-1] && !floor.flp && cursor.xvel < 0) cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1; /* Is the Cursor coming from the right? */ if (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && cursor.d1-floor.d1 < 0 && floor.flp && cursor.xvel < 0) @@ -333,7 +303,7 @@ int main(int argc, char **argv) { if (cursor.cly) { if (cursor.c2-floor.c1 < floor.w) { cursor.yvel = 0; - newy = (int)floor.bitmask[(int)cursor.c2-(int)floor.c1]; + newy = (int)floor.heightmap[(int)cursor.c2-(int)floor.c1]; /* Is the Floor, really a floor? */ if (cursor.d2 > (floor.d2-hmpeak)-cursor.yvel && floor.d2-cursor.d2 >= 0 && !floor.flp) cursor.pos.fy = ((floor.d2-cursor.h)-newy)-cursor.yvel; @@ -436,11 +406,8 @@ int main(int argc, char **argv) { uint8_t a = 0; unsigned int i = 0; free(buf); - if(colltype == THM || colltype == PPX) { - while (!a && colltype == PPX) - (i<tmp.h) ? (free(tmp.bitmask[i]), ++i) : (a=1); - free(cursor.bitmask); - free(floor.bitmask); + if(colltype == THM) { + free(floor.heightmap); } fflush(stdout); |