diff options
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | clld.c | 66 | ||||
-rw-r--r-- | test | 3 | ||||
-rw-r--r-- | test-bitmask | 71 | ||||
-rw-r--r-- | test-fp | 3 | ||||
-rw-r--r-- | test-tile | 6 |
6 files changed, 99 insertions, 53 deletions
@@ -19,7 +19,7 @@ clld is a simple collision checker, that takes two 2D, or 3D points, tests the collision of the points, and outputs the results to stdout. It can do many different types of collision checks, including -tile heightmask, AABB, per pixel, and more. +tile heightmap, AABB, per pixel, and more. @@ -70,6 +70,7 @@ cursor position, and the floor position. The input format looks like this: <collision type> +<collision type specific data> <cursor x>, <cursor y>[, <cursor z>] <floor x>, <floor y>[, <floor z] @@ -48,7 +48,6 @@ int main(int argc, char **argv) { double fz; }; - struct colis { unsigned int w; unsigned int h; @@ -58,8 +57,6 @@ int main(int argc, char **argv) { unsigned int gnded : 1; }; - - struct colis cursor; struct colis floor; struct colis tmp; @@ -84,13 +81,15 @@ int main(int argc, char **argv) { tmp.w = atoi(strtok(buf, ",")); tmp.h = atoi(strtok(NULL, "\n")); /* Initialize y axis of bitmask. */ - tmp.bitmask = malloc(sizeof(int *)*tmp.h); + if (colltype == THM || colltype == PPX) + tmp.bitmask = malloc(sizeof(uint8_t *)*tmp.h); /* Initialize x axis of bitmask. */ - for(int i = 0; i<tmp.h; i++) - tmp.bitmask[i] = malloc(sizeof(int)*tmp.w); + if (colltype == PPX) + for(unsigned int i = 0; i<tmp.h; i++) + tmp.bitmask[i] = malloc(sizeof(uint8_t)*tmp.w); /* Per Pixel Colision. */ if (colltype == PPX) { - for (int j = 0; j<tmp.h; j++) { + for (unsigned int j = 0; j<tmp.h; j++) { buf = NULL; size_t newidth = getline(&buf, &size, stdin); /* @@ -103,20 +102,52 @@ int main(int argc, char **argv) { * Until bit h-1. */ tmp.w = (newidth >= tmp.w) ? tmp.w : newidth; - for (int i = 0; i <tmp.w; i++) + for (unsigned int i = 0; i <tmp.w; i++) tmp.bitmask[j][i] = buf[i] - '0'; } } + + /* Tile Heightmap Collision. */ + if (colltype == THM && coll) { + buf = NULL; + size_t newheight = getline(&buf, &size, stdin); + /* + * Format is: + * + * 0, 1, 2, 3, ... Until element h-1. + */ + tmp.h = (newheight >= tmp.h) ? tmp.h : newheight; + for (unsigned int i = 0; i <tmp.h; i++) { + char *tmptok = strtok((i == 0) ? buf : NULL,","); + if(atoi(tmptok) <= tmp.h) + tmp.bitmask[i] = (uint8_t *)atoi((tmptok == NULL ? strtok(NULL,"\n") : tmptok)); + } + } + + + (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); - for (int j = 0; j<((coll) ? floor.h : cursor.h); j++) { - for (int i = 0; i<((coll) ? floor.w : cursor.w); i++) - printf("%u", (coll) ? floor.bitmask[j][i] : cursor.bitmask[j][i]); - printf("\n"); + if (colltype == THM && coll) + for (unsigned int i = 0; i<floor.h; i++) + printf((i<floor.h-1) ? "%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"); + } } - int delms = 0; + + + uint8_t delms = 0; char *tmp2; buf = NULL; getline(&buf, &size, stdin); @@ -147,8 +178,15 @@ int main(int argc, char **argv) { printf("%i\n", (!coll) ? cursor.pos.z : floor.pos.z); } } - + 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); + } fflush(stdout); return 0; @@ -1,4 +1,5 @@ -0 1 +1, 2 1, 2, 3 +3, 4 4, 5, 6 diff --git a/test-bitmask b/test-bitmask index a9334f6..42884fe 100644 --- a/test-bitmask +++ b/test-bitmask @@ -1,40 +1,39 @@ 2 -19, 35 -0000000000000000000 -0000000000000110000 -0000000000001010000 -0000000000010010000 -0000000000010010000 -0000000000010010000 -0000000001111110000 -0000000010000010000 -0000000100000010000 -0000001000000010000 -0000010000000010000 -0000010000000010000 -0000100000000010000 -0000100000000010000 -0000010000000010000 -0000010000000010000 -0000001000000010000 -0000001111111110000 -0000001000000010000 -0000010000111010000 -0000010000101010000 -0000010000101010000 -0000010000111010000 -0000010000101010000 -0000010001001010000 -0000010001101010000 -0000001000111010000 -0000001000000010000 -0000001000000010000 -0000001111111110000 -0000000010010000000 -0000000011110000000 -0000000110010000000 -0000000100010000000 -0000000111110000000 +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 @@ -1,4 +1,5 @@ -0 1 +1, 2 98724.14568, 13.21456, 45834.11245 +3, 4 47954.54981, 14879.41456, 32118.12784 diff --git a/test-tile b/test-tile new file mode 100644 index 0000000..f9b058e --- /dev/null +++ b/test-tile @@ -0,0 +1,6 @@ +0 +1,1 +1,2,3 +16,16 +1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 +4,5,6 |