From 47f33148829a97b19326eae42eff633e63584454 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 12 Oct 2019 18:36:46 -0400 Subject: 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. --- clld.c | 81 ++++++++++++++++++------------------------------------------ test-bitmask | 55 ----------------------------------------- 2 files changed, 24 insertions(+), 112 deletions(-) delete mode 100644 test-bitmask diff --git a/clld.c b/clld.c index e4c3679..6d6d3a0 100644 --- a/clld.c +++ b/clld.c @@ -13,8 +13,10 @@ #include #include #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.w) ? tmp.w : newidth; - for (unsigned int i = 0; i = 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.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