summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README128
-rw-r--r--clld.c106
-rw-r--r--test4
-rw-r--r--test-fp4
4 files changed, 242 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..7b4d5ab
--- /dev/null
+++ b/README
@@ -0,0 +1,128 @@
+clld - A standalone collision checker
+
+
+Contents/Index:
+
+ 1. Introduction 16
+ 2. Setup 26
+ 2.1. Compilation 28
+ 2.2. Installation 47
+ 2.3. Running 59
+ 3. Input Format 65
+ 4. Output Format 91
+ 5. License 117
+ 6. Authors 125
+
+1. Introduction
+
+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.
+
+
+
+2. Setup
+
+2.1. Compilation
+
+To compile clld, run:
+
+$ make
+
+You can add extra compiler options, with the CFLAGS_EXTRA variable.
+
+clld also supports compilers that are not bloat, such as
+TinyCC, and the Portable C Compiler.
+
+It is also recommended to compile clld with one of the
+compilers above, rather than compiling it with gcc, or llvm.
+
+The reason for saying this is because the program is very simple, and
+very optimized, so using gcc wouldn't net you any significant gain in
+performance, and would make the size of the binary, alot bigger.
+
+
+2.2. Installation
+
+To install clld, run:
+
+$ make install
+
+You can change the install prefix, and bin directories, by changing
+the PREFIX, and BIN environment variables.
+
+By default, PREFIX, and BIN are set to /usr/local, and bin respectivly.
+
+
+2.3. Running
+
+Run `clld --help`, or `clld -h` to get information about the options.
+
+
+
+3. Input Format
+
+The input format is plain text, and contains the collision type, the
+cursor position, and the floor position.
+
+The input format looks like this:
+
+<collision type>
+<cursor x>, <cursor y>[, <cursor z>]
+<floor x>, <floor y>[, <floor z]
+
+The collision type is the type of collision check that clld will use.
+
+Cursor x, y, and z are the coordinates of the cursor, which clld will
+test against the floor's position.
+
+Floor x, y, and z are the coordinates of the floor, which is used by
+clld as the reference position that will be tested against the cursor.
+
+The datatypes for each of the fields are:
+
+Collision type: flag
+Cursor, and floor position: integer, or floating point
+
+
+
+4. Output Format
+
+The output format is also plain text, and contains the
+collision flag, the grounded flag, and the cursor position.
+
+The output format looks like this:
+
+<collision flag>
+<grounded flag>
+<cursor x>, <cursor y>[, <cursor z>]
+
+The collision flag is set, when a collision has occured.
+
+The grounded flag is set when the cursors y coordinate matches
+the floors y coordinate.
+
+Cursor x, y, and z are the new coordinates for the cursor to be set to.
+
+The datatypes for each of the fields are:
+
+Collision flag: flag
+Grounded flag: flag
+Cursor position: integer, or floating point
+
+
+
+5. License
+
+clld is released under the GNU General Public License version 2. The
+full text of the license can be found in the LICENSE file that should
+be included in the clld distribution.
+
+
+
+6. Authors
+
+Original author:
+ mr b0nk 500 <b0nk@mrb0nk500.xyz>
diff --git a/clld.c b/clld.c
new file mode 100644
index 0000000..70e111d
--- /dev/null
+++ b/clld.c
@@ -0,0 +1,106 @@
+/*
+ * Main Program file.
+ *
+ * Platform: Anything with a C compiler.
+ * Author: mr b0nk 500 <b0nk@mrb0nk500.xyz>
+ * Notes: Who would even use this kind of collision checker?
+ * Created: September 27, 2019 @ 09:25PM
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* Collision type */
+int colltype = -1;
+
+/* Position type */
+int postype = -1;
+
+/* Level of verbosity. */
+int verbose = 0;
+
+
+static int usage() {
+ printf(
+ "clld Version MFIYA.\n"
+ "Usage: clld [options]\n"
+ "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;
+}
+
+int main(int argc, char **argv) {
+ struct pos {
+ int x;
+ int y;
+ int z;
+ double fx;
+ double fy;
+ double fz;
+ };
+ struct pos cursor;
+ struct pos floor;
+ struct pos tmp;
+
+ char *buf = NULL;
+ size_t size;
+
+ getline(&buf, &size, stdin);
+ if (postype == -1)
+ postype = atoi(strtok(buf, "\n"));
+
+ 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++) {
+ char *tmp2;
+ buf = NULL;
+ getline(&buf, &size, stdin);
+ if (strchr(buf, '.') != NULL) {
+ tmp.fx = atof(strtok(buf,","));
+ tmp.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);
+ }
+ } else {
+ tmp.x = atoi(strtok(buf,","));
+ tmp.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);
+ }
+ }
+ }
+
+ free(buf);
+ fflush(stdout);
+ return 0;
+}
diff --git a/test b/test
new file mode 100644
index 0000000..4cada87
--- /dev/null
+++ b/test
@@ -0,0 +1,4 @@
+0
+1
+1, 2, 3
+4, 5, 6
diff --git a/test-fp b/test-fp
new file mode 100644
index 0000000..bcc97cc
--- /dev/null
+++ b/test-fp
@@ -0,0 +1,4 @@
+0
+1
+98724.14568, 13.21456, 45834.11245
+47954.54981, 14879.41456, 32118.12784