engine setup: Added some basic helpers
authorLukas Krickl <lukas@krickl.dev>
Sat, 21 Feb 2026 20:55:59 +0000 (21:55 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 21 Feb 2026 20:55:59 +0000 (21:55 +0100)
src/lmud.h
src/t_actor.c [new file with mode: 0644]
src/t_actor.h [new file with mode: 0644]
src/u_assert.h [new file with mode: 0644]
src/u_mem.c
src/u_mem.h
src/u_rand.c [new file with mode: 0644]
src/u_rand.h [new file with mode: 0644]

index 481e6b2c114ac38d934bd0d5702499f9e2666707..f65cbc81062030eef3dcef413f8f4073d6bfaad8 100644 (file)
@@ -1,11 +1,15 @@
 #ifndef LMUD_H__
 #define LMUD_H__
 
+#define LMUD_DEBUG
+
 /**
  * System includes
  */
 #include "u_stdio.h"
 #include "u_mem.h"
+#include "t_actor.h"
+#include "u_assert.h"
 
 #define LMUD_VER "0.0.1"
 
 #define LMUD_OPTS_ARG "c:"
 #define LMUD_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc);
 
+/**
+ * generic typedefs
+ */
+
 typedef unsigned char lmud_bool;
 #define LMUD_TRUE 1
 #define LMUD_FALSE 0
@@ -27,6 +35,13 @@ struct lmud_config {
        int argc;
 };
 
+typedef unsigned char u8;
+typedef char i8;
+typedef unsigned short u16;
+typedef short i16;
+typedef unsigned int u32;
+typedef int i32;
+
 struct lmud_config* lmud_cfg();
 void lmud_help(int argc, char **argv);
 void lmud_version(void);
@@ -43,6 +58,8 @@ int lmud_main(int argc, char **argv);
 #include "lmud.c"
 #include "u_stdio.c"
 #include "u_mem.c"
+#include "t_actor.c"
+#include "u_rand.h"
 
 #endif
 
diff --git a/src/t_actor.c b/src/t_actor.c
new file mode 100644 (file)
index 0000000..d948cdd
--- /dev/null
@@ -0,0 +1 @@
+#include "t_actor.h"
diff --git a/src/t_actor.h b/src/t_actor.h
new file mode 100644 (file)
index 0000000..3d04524
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef T_ACTOR_H__
+#define T_ACTOR_H__
+
+enum t_actor_flags {
+       T_ACTOR_F_NONE = 0
+};
+
+/**
+ * Character stats
+ */
+struct t_stats {
+       /**
+        * base stats
+        */ 
+       short str;
+       short wis;
+       short agi;
+       short vit;
+
+       /* resistances */
+       short poison_res;
+       short fire_res;
+       short holy_res;
+       short chaos_res;
+
+       /* damage stats */
+       unsigned int physical_damage;
+       unsigned int magic_damage;
+
+       /* misc */
+       unsigned char tohit;
+};
+
+/* current actor state
+ * this struct mostly contains 
+ * mutable variables related to an actor
+ */
+struct t_actor_state {
+       int hp;
+       int mp;
+       int level;
+       int xp;
+};
+
+struct t_actor {
+       unsigned int id;
+       unsigned short faction_id;
+
+       struct t_stats stats;
+       struct t_actor_state state;
+};
+
+
+#endif
diff --git a/src/u_assert.h b/src/u_assert.h
new file mode 100644 (file)
index 0000000..19a6d57
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef U_ASSERT_H__
+#define U_ASSERT_H__
+
+#include <assert.h>
+
+#ifdef DEBUG
+
+#define lmud_assert(e, message) assert(e)
+
+#define lmud_todo(message) assert(0)
+
+#else
+
+#define lmud_assert(e, message)
+
+#define lmud_todo(message)
+
+#endif
+
+#endif
index ec55198f05541a6909f7ecd405c9b7714961ad1d..5609b699fd645d395f1fb1e7fc9058cf9821af34 100644 (file)
@@ -1 +1,11 @@
+#include <string.h>
 #include "u_mem.h"
+
+
+void *u_memset(void *src, int c, size_t n) {
+       return memset(src, c, n);
+}
+
+void *u_memcpy(void *dst, const void *src, size_t n) {
+       return memcpy(dst, src, n);
+}
index 69849149769f3de74565ece7815b715005df60f2..50cee6d9bd4664deb1ec663ade3b3aa53b92e6ec 100644 (file)
@@ -2,5 +2,7 @@
 #define U_MEM_H__
 
 
+void *u_memset(void *src, int count, size_t n);
+void *u_memcpy(void *det, const void *src, size_t n);
 
 #endif
diff --git a/src/u_rand.c b/src/u_rand.c
new file mode 100644 (file)
index 0000000..bd8daf3
--- /dev/null
@@ -0,0 +1,10 @@
+#include "u_rand.h"
+#include "u_assert.h"
+
+void u_srand(u32 s) {
+       lmud_assert();
+}
+
+u32 u_rand(void) {
+       lmud_todo("Not yet implemented")
+}
diff --git a/src/u_rand.h b/src/u_rand.h
new file mode 100644 (file)
index 0000000..1d06560
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef U_RAND_H__
+#define U_RAND_H__
+
+#include "lmud.h"
+
+void u_srand(u32 s);
+
+u32 u_rand(void);
+
+#endif