engine: Added error handling setup and arena allocator stub
authorLukas Krickl <lukas@krickl.dev>
Mon, 23 Feb 2026 07:22:53 +0000 (08:22 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 23 Feb 2026 07:22:53 +0000 (08:22 +0100)
STYLE.md
makefile
src/lrts.c
src/lrts.h
src/u_arena.c [new file with mode: 0644]
src/u_arena.h [new file with mode: 0644]
src/u_defs.h
src/u_errno.h [new file with mode: 0644]
src/u_log.c
src/u_math.c
src/u_rand.c

index cf024841d6b002d3708a5480057681348a2a98e8..22ea69b90a1dca46dfdb2c181437fe8b692a9d15 100644 (file)
--- a/STYLE.md
+++ b/STYLE.md
@@ -51,3 +51,8 @@ Some C features might be hard to wrap.
 These are allowed even in core code.
 
 - stdarg.h: for va_list va_start and va_end
+
+## Vendoring
+
+All 3rd party libraries should be forked and included as a submodule.
+Linking should be static.
index b2aff0451f335851ddabe5db5885c214991e41b4..bf1d2c9e6e742222d997ba0230da8deeab6cae0c 100644 (file)
--- a/makefile
+++ b/makefile
@@ -2,7 +2,7 @@ NAME=lrts
 TEST_NAME=test$(NAME)
 DBGCFLAGS=-g
 DBGLDFLAGS=
-CFLAGS=-Wall -pedantic $(DBGCFLAGS) -std=c89
+CFLAGS=-Wall -Wextra -Werror -pedantic $(DBGCFLAGS) -std=c89
 LIBS=-lSDL3
 LDFLAGS=$(DBGLDFLAGS) $(LIBS)
 
index ff85d87f842ba9445b2187d7e12198c55e3a6ba0..ab3ae2f0a55c236e891cc321018b4229172b1580 100644 (file)
@@ -9,6 +9,8 @@ struct lrts_config* lrts_cfg() {
 }
 
 void lrts_help(int argc, char **argv) {
+       LRTS_UNUSED(argc);
+
   u_fprintf(u_stderr, "%s\n", argv[0]);
   u_fprintf(u_stderr, "Usage: %s [-%s] [-c=command] [demo file]\n\n",
          argv[0], LRTS_OPTS);
index 278276a9d67927265ecbdf0a9242e7a3ce73b2f5..0f83a5fc8a860e92a523f313697f44b8eb6f2719 100644 (file)
@@ -49,6 +49,7 @@
 #include "u_math.c"
 #include "t_tile.c"
 #include "u_log.c"
+#include "u_arena.c"
 
 #endif
 
diff --git a/src/u_arena.c b/src/u_arena.c
new file mode 100644 (file)
index 0000000..46c89a5
--- /dev/null
@@ -0,0 +1,2 @@
+#include "u_arena.h"
+
diff --git a/src/u_arena.h b/src/u_arena.h
new file mode 100644 (file)
index 0000000..460b5c2
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef U_ARENA_H__
+#define U_ARENA_H__
+
+#include "u_defs.h"
+#include "u_errno.h"
+
+/**
+ * This module contains a simple arena allocator
+ * This is the most common type of allocator that should 
+ * be used in the program.
+ */
+
+struct u_arena {
+       enum u_errno_code err;
+       u32 o_size;
+       u32 o_max;
+
+       /* The current object index */
+       u32 o_index;
+
+       void *data;
+};
+
+/**
+ * Creates a new arena 
+ * suitable for o_max objects of o_size size
+ * returns a new arena. sets err to 0 if no error occured
+ */
+struct u_arena u_arena_init(u32 o_size, u32 o_max);
+
+/**
+ * Allocates n objects from an arena
+ * sets err if allocation is not possible
+ */
+void *u_arena_alloc(struct u_arena *a, u32 n);
+
+/* Clears the arena resetting the current o_index */
+void u_arena_clear(struct u_arena *a);
+
+/* Releases an arena buffer */
+void u_arena_free(struct u_arena *a);
+
+#endif
index bf2b82acc011a05c48e9eea4026a4c1846e3ba0f..25b62df74953bbb9755570475af30042abf75f18 100644 (file)
@@ -52,4 +52,6 @@ int lrts_main(int argc, char **argv);
 #define U_RENDER_W 640
 #define U_RENDER_H 640
 
+#define LRTS_UNUSED(x) (void)(x)
+
 #endif
diff --git a/src/u_errno.h b/src/u_errno.h
new file mode 100644 (file)
index 0000000..462a633
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef U_ERRNO_H__
+#define U_ERRNO_H__
+
+#define U_ERRNO_MESSAGE_MAX 512
+
+/**
+ * This message may be written to whenever a function fails
+ */
+extern char u_errno_message[U_ERRNO_MESSAGE_MAX];
+
+/**
+ * This error code usually gets returned by
+ * functions that may fail.
+ * usually the pattenr is as follows
+ * return_type my_fun(enum u_errno_code *err);
+ * or 
+ * struct my_struct {
+ *     enum u_errno_code err;
+ * }
+ */
+enum u_errno_code {
+       U_ERRNO_OK = 0,
+       U_ERRNO_FAIL
+};
+
+#endif
index 0459f5c1a5f56ad098ea697956f169e66cede6c6..93a94ea7fd7fea2149d1d8ae4b45668eeb7fe88a 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdarg.h>
 
 lrts_bool u_log_should_log(enum u_log_levels level) {
+       LRTS_UNUSED(level);
        /* TODO: implement log levels */
        return LRTS_TRUE;
 }
index a1af48a0846606419dde2d2cf7294064af7e7134..ff65375bd516c3e720b7a24c34ba8c1e0b022662 100644 (file)
@@ -2,30 +2,45 @@
 
 struct u_fp u_fp_add(struct u_fp a, struct u_fp b) {
        struct u_fp c = U_FP(0, 0);
+
+       LRTS_UNUSED(a);
+       LRTS_UNUSED(b);
        lrts_todo("");
        return c;
 }
 
 struct u_fp u_fp_sub(struct u_fp a, struct u_fp b) {
        struct u_fp c = U_FP(0, 0);
+
+       LRTS_UNUSED(a);
+       LRTS_UNUSED(b);
        lrts_todo("");
        return c;
 }
 
 struct u_fp u_fp_mul(struct u_fp a, struct u_fp b) {
        struct u_fp c = U_FP(0, 0);
+
+       LRTS_UNUSED(a);
+       LRTS_UNUSED(b);
        lrts_todo("");
        return c;
 }
 
 struct u_fp u_fp_div(struct u_fp a, struct u_fp b) {
        struct u_fp c = U_FP(0, 0);
+
+       LRTS_UNUSED(a);
+       LRTS_UNUSED(b);
        lrts_todo("");
        return c;
 }
 
 struct u_fp u_fp_mod(struct u_fp a, struct u_fp b) {
        struct u_fp c = U_FP(0, 0);
+
+       LRTS_UNUSED(a);
+       LRTS_UNUSED(b);
        lrts_todo("");
        return c;
 }
index 874c09bd3551b57555c013004f83b38e0fd90819..703dda9e10f3d6bb3a1f9dadf81c562ef5cebbe2 100644 (file)
@@ -2,6 +2,7 @@
 #include "u_assert.h"
 
 void u_srand(u32 s) {
+       LRTS_UNUSED(s);
        lrts_todo("Not yet implemented");
 }