summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clld.c123
-rw-r--r--test-bitmask56
2 files changed, 142 insertions, 37 deletions
diff --git a/clld.c b/clld.c
index 70e111d..2ff7975 100644
--- a/clld.c
+++ b/clld.c
@@ -7,10 +7,14 @@
* Created: September 27, 2019 @ 09:25PM
*/
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#define TERASGN(a, b, c, d) (a) ? (b = d) : (c = d)
+
+enum {THM, AABB, PPX };
/* Collision type */
int colltype = -1;
@@ -29,8 +33,6 @@ static int usage() {
"Options:\n"
" -c<type> Force the collision type to be\n"
" the specified type (0-2).\n"
- " -p<type> Force the position type to be\n"
- " the specified type (0-2).\n"
" -v[level] Sets the verbosity level (0-3).\n"
);
return 0;
@@ -45,62 +47,109 @@ int main(int argc, char **argv) {
double fy;
double fz;
};
- struct pos cursor;
- struct pos floor;
- struct pos tmp;
+
+ struct colis {
+ unsigned int w;
+ unsigned int h;
+ struct pos pos;
+ uint8_t **bitmask;
+ unsigned int clds : 1;
+ unsigned int gnded : 1;
+ };
+
+
+
+ struct colis cursor;
+ struct colis floor;
+ struct colis tmp;
char *buf = NULL;
size_t size;
- getline(&buf, &size, stdin);
- if (postype == -1)
- postype = atoi(strtok(buf, "\n"));
+ /*getline(&buf, &size, stdin);*/
+ /*if (postype == -1)
+ postype = atoi(strtok(buf, "\n"));*/
- buf = NULL;
+ /*buf = NULL;*/
getline(&buf, &size, stdin);
if (colltype == -1)
colltype = atoi(strtok(buf, "\n"));
- printf("%i\n%i\n", postype, colltype);
- for (int i = 0; i <= 1; i++) {
+ printf("%i\n", colltype);
+ for (int coll = 0; coll <= 1; coll++) {
+ buf = NULL;
+ getline(&buf, &size, stdin);
+ /* <w>, <h> */
+ tmp.w = atoi(strtok(buf, ","));
+ tmp.h = atoi(strtok(NULL, "\n"));
+ /* Initialize y axis of bitmask. */
+ tmp.bitmask = malloc(sizeof(int *)*tmp.h);
+ /* Initialize x axis of bitmask. */
+ for(int i = 0; i<tmp.h; i++)
+ tmp.bitmask[i] = malloc(sizeof(int)*tmp.w);
+ /* Per Pixel Colision. */
+ if (colltype == PPX) {
+ for (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 (int i = 0; i <tmp.w; i++)
+ tmp.bitmask[j][i] = buf[i] - '0';
+ }
+ }
+ (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");
+ }
+ int delms = 0;
char *tmp2;
buf = NULL;
getline(&buf, &size, stdin);
+ for (int j = 0; buf[j] != '\0'; j++)
+ if (buf[j] == ',')
+ delms++;
+ postype = (delms == 2) ? 1 : 0;
+ /* Check for floating point coordinates. */
if (strchr(buf, '.') != NULL) {
- tmp.fx = atof(strtok(buf,","));
- tmp.fy = atof(strtok(NULL,","));
+ tmp.pos.fx = atof(strtok(buf,","));
+ if(postype)
+ tmp.pos.fy = atof(strtok(NULL,","));
tmp2 = strtok(NULL, "\n");
- if (tmp2 == NULL)
- tmp.fz = atof(strtok(NULL,"\0"));
- else
- tmp.fz = atof(tmp2);
- if (!i) {
- cursor = tmp;
- printf ("%07.06f, %07.06f, %07.06f\n", cursor.fx, cursor.fy, cursor.fz);
- } else {
- floor = tmp;
- printf ("%07.06f, %07.06f, %07.06f\n", floor.fx, floor.fy, floor.fz);
- }
+ TERASGN(postype, tmp.pos.fz, tmp.pos.fy, atof((tmp2 == NULL ? strtok(NULL,"\0") : tmp2)));
+ (coll) ? (floor.pos = tmp.pos) : (cursor.pos = tmp.pos);
+ printf("%07.06f, %07.06f%s", (!coll) ? cursor.pos.fx : floor.pos.fx, (!coll) ? cursor.pos.fy : floor.pos.fy, (postype) ? ", " : "\n");
+ if(postype)
+ printf("%07.06f\n", (!coll) ? cursor.pos.fz : floor.pos.fz);
} else {
- tmp.x = atoi(strtok(buf,","));
- tmp.y = atoi(strtok(NULL,","));
+ tmp.pos.x = atoi(strtok(buf,","));
+ if(postype)
+ tmp.pos.y = atoi(strtok(NULL,","));
tmp2 = strtok(NULL, "\n");
- if (tmp2 == NULL)
- tmp.z = atoi(strtok(NULL, "\0"));
- else
- tmp.z = atoi(tmp2);
- if (!i) {
- cursor = tmp;
- printf ("%i, %i, %i\n", cursor.x, cursor.y, cursor.z);
- } else {
- floor = tmp;
- printf ("%i, %i, %i\n", floor.x, floor.y, floor.z);
- }
+ TERASGN(postype, tmp.pos.z, tmp.pos.y, atoi((tmp2 == NULL ? strtok(NULL,"\0") : tmp2)));
+ (coll) ? (floor.pos = tmp.pos) : (cursor.pos = tmp.pos);
+ printf("%i, %i%s", (!coll) ? cursor.pos.x : floor.pos.x, (!coll) ? cursor.pos.y : floor.pos.y, (postype) ? ", " : "\n");
+ if(postype)
+ printf("%i\n", (!coll) ? cursor.pos.z : floor.pos.z);
}
}
free(buf);
fflush(stdout);
+
return 0;
}
diff --git a/test-bitmask b/test-bitmask
new file mode 100644
index 0000000..a9334f6
--- /dev/null
+++ b/test-bitmask
@@ -0,0 +1,56 @@
+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
+1, 2, 3
+16, 16
+0000000000000001
+0000000000000011
+0000000000000101
+0000000000001001
+0000000000010001
+0000000000100001
+0000000001000001
+0000000010000001
+0000000100000001
+0000001000000001
+0000010000000001
+0000100000000001
+0001000000000001
+0010000000000001
+0100000000000001
+1111111111111111
+4, 5, 6