From: Lukas Krickl Date: Sat, 21 Feb 2026 20:55:59 +0000 (+0100) Subject: engine setup: Added some basic helpers X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=9dfde16ff8e642a2fa4ceab725aaac86b77112a7;p=lmud%2F.git engine setup: Added some basic helpers --- diff --git a/src/lmud.h b/src/lmud.h index 481e6b2..f65cbc8 100644 --- a/src/lmud.h +++ b/src/lmud.h @@ -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" @@ -16,6 +20,10 @@ #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 index 0000000..d948cdd --- /dev/null +++ b/src/t_actor.c @@ -0,0 +1 @@ +#include "t_actor.h" diff --git a/src/t_actor.h b/src/t_actor.h new file mode 100644 index 0000000..3d04524 --- /dev/null +++ b/src/t_actor.h @@ -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 index 0000000..19a6d57 --- /dev/null +++ b/src/u_assert.h @@ -0,0 +1,20 @@ +#ifndef U_ASSERT_H__ +#define U_ASSERT_H__ + +#include + +#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 diff --git a/src/u_mem.c b/src/u_mem.c index ec55198..5609b69 100644 --- a/src/u_mem.c +++ b/src/u_mem.c @@ -1 +1,11 @@ +#include #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); +} diff --git a/src/u_mem.h b/src/u_mem.h index 6984914..50cee6d 100644 --- a/src/u_mem.h +++ b/src/u_mem.h @@ -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 index 0000000..bd8daf3 --- /dev/null +++ b/src/u_rand.c @@ -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 index 0000000..1d06560 --- /dev/null +++ b/src/u_rand.h @@ -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