engine: Added basic logging
authorLukas Krickl <lukas@krickl.dev>
Mon, 23 Feb 2026 05:38:23 +0000 (06:38 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 23 Feb 2026 05:38:23 +0000 (06:38 +0100)
TODO.md
src/lrts.c
src/lrts.h
src/p_pc/p_pc.h [new file with mode: 0644]
src/p_pc/u_log.c [new file with mode: 0644]
src/p_pc/u_stdio.c
src/p_r_sdl/p_init.c
src/u_log.c [new file with mode: 0644]
src/u_log.h [new file with mode: 0644]
src/u_stdio.h

diff --git a/TODO.md b/TODO.md
index b6dbda7f350106bf4ad180200790a61d91f2a1ae..51a02a49df06c41bb527fc7a151b3acf7427d612 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,2 +1,18 @@
 # TODO
 
+## Gameplay
+
+## Goals
+
+- Portable
+- Avoid libraries
+- Simple
+- C89 only (if possible should compile with gcc, clang and tcc)
+- Built-in scripting language
+- Built in map editor
+- Built in sprite editor
+- Resource files and assets are git-friendly
+- Isometric map rendering
+- Replays
+- Networking is optional
+- Lockstep networking 
index 364fdbc2ab4e7b98e6611e26c974aa47d29e5030..ff85d87f842ba9445b2187d7e12198c55e3a6ba0 100644 (file)
@@ -10,7 +10,7 @@ struct lrts_config* lrts_cfg() {
 
 void lrts_help(int argc, char **argv) {
   u_fprintf(u_stderr, "%s\n", argv[0]);
-  u_fprintf(u_stderr, "Usage: %s [-%s] [-c=command]\n\n",
+  u_fprintf(u_stderr, "Usage: %s [-%s] [-c=command] [demo file]\n\n",
          argv[0], LRTS_OPTS);
   LRTS_HELP("h", "display this help and exit");
        LRTS_HELP("V", "display version info and exit");
index d3ee797ba4653d72848b0deb0c6f071be5d220c6..b24dc6bb4362f8be6e799ca22ab9fd1b74156938 100644 (file)
@@ -26,6 +26,7 @@
 #include "p_pc/u_assert.c"
 #include "p_posix/p_init.c"
 #include "p_posix/p_getopt.c"
+#include "p_pc/u_log.c"
 #else
 #error "No platform is provided"
 #endif
@@ -48,6 +49,7 @@
 #include "n_conn.c"
 #include "u_math.c"
 #include "t_tile.c"
+#include "u_log.c"
 
 #endif
 
diff --git a/src/p_pc/p_pc.h b/src/p_pc/p_pc.h
new file mode 100644 (file)
index 0000000..a8bda81
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef P_PC_H__
+#define P_PC_H__
+
+int u_vfprintf(U_FILE* stream, const char *fmt, void *args);
+
+#endif
diff --git a/src/p_pc/u_log.c b/src/p_pc/u_log.c
new file mode 100644 (file)
index 0000000..48ef2b5
--- /dev/null
@@ -0,0 +1,18 @@
+#include "../u_log.h"
+#include "../u_stdio.h"
+#include "p_pc.h"
+#include <stdarg.h>
+#include <stdio.h>
+
+int u_log(enum u_log_levels level, const char *fmt, ...) {
+       va_list args;
+       int res = 0;
+
+       if (!u_log_should_log(level)) {
+               return 0;
+       }
+       va_start(args, fmt);
+       res = u_fprintf(u_stderr, fmt, args);
+       va_end(args);
+       return res;
+}
index ea7f4891f527c55ed02caaff408911b5e84999cd..4b73a30f8497a82e8374a2d2a05e06de174f153d 100644 (file)
@@ -6,14 +6,22 @@ void *u_stdin;
 void *u_stdout;
 void *u_stderr;
 
+
+int u_vfprintf(U_FILE* stream, const char *fmt, void *args) {
+               return vfprintf(stream, fmt, args);
+}
+
 int u_fprintf(U_FILE* stream, const char *fmt, ...) {
                int res = 0;
                va_list args;
                
                va_start(args, fmt);
-               res = vfprintf(stream, fmt, args);
+               u_vfprintf(stream, fmt, args);
                va_end(args);
 
                return res;
 }
 
+int u_fputs(const char *s, U_FILE* stream) {
+       return fputs(s, stream);
+}
index d7784e9216776b604ed310dfd13838c34d721580..fe05c0e8e6b96daa2135df03f4f33ec41c701356 100644 (file)
@@ -2,27 +2,31 @@
 #include <SDL3/SDL.h>
 #include "p_window.h"
 #include "../u_defs.h"
+#include "../u_log.h"
 
 #include "p_window.c"
 
 int p_render_init(void) {
        if (!SDL_Init(SDL_INIT_VIDEO)) {
-               u_fprintf(u_stderr, "Failed to init video: %s\n", 
+               u_log(U_LOG_ERR, "Failed to init video: %s\n", 
                                SDL_GetError());
                exit(-1);
        }
 
        p_main_window = SDL_CreateWindow(lrts_cfg()->name, 640, 640, 0);
        if (p_main_window == LRTS_NULL) {
-               u_fprintf(u_stderr, "Failed to create window: %s\n", SDL_GetError());
+               u_log(U_LOG_ERR, "Failed to create window: %s\n", SDL_GetError());
                exit(-1);
        }
 
+       u_log(U_LOG_DEBUG, "Init successful\n");
+
        return 0;
 }
 
 int p_renderer_finish(void) {
        SDL_DestroyWindow(p_main_window);
        SDL_Quit();
+       u_log(U_LOG_DEBUG, "Exiting...\n");
        return 0;
 }
diff --git a/src/u_log.c b/src/u_log.c
new file mode 100644 (file)
index 0000000..47d65ce
--- /dev/null
@@ -0,0 +1,6 @@
+#include "u_log.h"
+
+lrts_bool u_log_should_log(enum u_log_levels level) {
+       /* TODO: implement log levels */
+       return LRTS_TRUE;
+}
diff --git a/src/u_log.h b/src/u_log.h
new file mode 100644 (file)
index 0000000..40dc233
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef U_LOG_H__
+#define U_LOG_H__
+
+#include "u_defs.h"
+#include "u_stdio.h"
+
+enum u_log_levels {
+       U_LOG_DEBUG,
+       U_LOG_INF,
+       U_LOG_WARN,
+       U_LOG_ERR,
+       U_LOG_CRIT
+};
+
+/**
+ * Logs a message to the log stream
+ * this is platform specific
+ */
+int u_log(enum u_log_levels level, const char *fmt, ...);
+
+/**
+ * informs the platform if u_log level should be logged
+ */
+lrts_bool u_log_should_log(enum u_log_levels level);
+
+#endif
index ea2369a3ea51ed0d88e0eb829c4695be6c049218..88deabd059e426f751f2a4fc6c8fe1ee01c5dc47 100644 (file)
@@ -9,6 +9,7 @@ extern void *u_stdout;
 extern void *u_stderr;
 
 int u_fprintf(U_FILE* stream, const char *fmt, ...);
+int u_fputs(const char *s, U_FILE* stream);
 
 
 #endif