diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2019-10-12 18:36:46 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2019-10-12 18:36:46 -0400 |
commit | 47f33148829a97b19326eae42eff633e63584454 (patch) | |
tree | 83b68b517e4113ccb92fae9e6cd22caac73fb70b | |
parent | c22612764c3078e839aa7eadfd9f9d31f5ed2aa1 (diff) |
Remove Per Pixel Collision.
Why? Because it was too hard to actually implement, in
this case.
I will be adding a diff file, in case someone wants to
actually get ppx working.
-rw-r--r-- | clld.c | 81 | ||||
-rw-r--r-- | test-bitmask | 55 |
2 files changed, 24 insertions, 112 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); diff --git a/test-bitmask b/test-bitmask deleted file mode 100644 index 42884fe..0000000 --- a/test-bitmask +++ /dev/null @@ -1,55 +0,0 @@ -2 -18, 34 -000000000000000000 -000000000000110000 -000000000001010000 -000000000010010000 -000000000010010000 -000000000010010000 -000000001111110000 -000000010000010000 -000000100000010000 -000001000000010000 -000001000000010000 -000010000000010000 -000010000000010000 -000001000000010000 -000001000000010000 -000000100000010000 -000000111111110000 -000000100000010000 -000001000111010000 -000001000101010000 -000001000101010000 -000001000111010000 -000001000101010000 -000001001001010000 -000001001101010000 -000000100111010000 -000000100000010000 -000000100000010000 -000000111111110000 -000000001001000000 -000000001111000000 -000000011001000000 -000000010001000000 -000000011111000000 -1, 2, 3 -16, 16 -0000000000000001 -0000000000000011 -0000000000000101 -0000000000001001 -0000000000010001 -0000000000100001 -0000000001000001 -0000000010000001 -0000000100000001 -0000001000000001 -0000010000000001 -0000100000000001 -0001000000000001 -0010000000000001 -0100000000000001 -1111111111111111 -4, 5, 6 |