# 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
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");
#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
#include "n_conn.c"
#include "u_math.c"
#include "t_tile.c"
+#include "u_log.c"
#endif
--- /dev/null
+#ifndef P_PC_H__
+#define P_PC_H__
+
+int u_vfprintf(U_FILE* stream, const char *fmt, void *args);
+
+#endif
--- /dev/null
+#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;
+}
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);
+}
#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;
}
--- /dev/null
+#include "u_log.h"
+
+lrts_bool u_log_should_log(enum u_log_levels level) {
+ /* TODO: implement log levels */
+ return LRTS_TRUE;
+}
--- /dev/null
+#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
extern void *u_stderr;
int u_fprintf(U_FILE* stream, const char *fmt, ...);
+int u_fputs(const char *s, U_FILE* stream);
#endif