diff options
Diffstat (limited to 'clld.c')
-rw-r--r-- | clld.c | 66 |
1 files changed, 52 insertions, 14 deletions
@@ -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; |