From ce13cd4be59c0415877571d92aaea3fd0d5a7e49 Mon Sep 17 00:00:00 2001 From: zlago Date: Wed, 2 Oct 2024 20:39:39 +0200 Subject: entities --- src/main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 6b195b4..8fc400f 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,8 @@ struct entity player[1] = {0}; struct entity *player_new(void); int player_property(struct entity *const restrict entity, char const *const restrict property, char const *const restrict value); +void funs_init(void); + int main(int const argc, char *const *const argv) { struct option opts[] = { {"help", 0, NULL, 'h'}, @@ -156,6 +158,7 @@ int main(int const argc, char *const *const argv) { { res_init(); + funs_init(); if (optind == argc) { void *a = util_executableRelativePath("assets.res", *argv, 0); puts(a); @@ -175,6 +178,55 @@ int main(int const argc, char *const *const argv) { } struct blob map = res_get_map("untitled"); tilemap = tilemap_load(map.data, map.size); + char *a = (char *) map.data + tilemap->input_bytes; + map.size -= tilemap->input_bytes; + while (map.size) { + size_t len; + if ((len = strnlen(a, map.size)) == map.size) { + return 1; // hack + } + char *name = a; + puts(name); + struct entity *(*fun)(void) = res_get_newfun(name); + a += len + 1; + map.size -= len + 1; + if (fun) { + struct entity *entity = fun(); + while (1) { + if ((len = strnlen(a, map.size)) == map.size) { + return 1; // hack + } else if (len == 0) { + a++; + map.size--; + break; + } + char *key = a; + a += len + 1; + map.size -= len + 1; + if ((len = strnlen(a, map.size)) == map.size) { + return 1; // hack + } + char *value = a; + a += len + 1; + map.size -= len + 1; + if (res_get_setfun(name)(entity, key, value)) { + return 1; // hack + } + } + } else { + while (1) { // hack + if ((len = strnlen(a, map.size)) == map.size) { // hack + return 1; // hack + } else if (len == 0) { + a++; + map.size--; + break; + } + a += len + 1; + map.size -= len + 1; + } + } + } //memmem(map.data + tilemap->byte_count, map.size - tilemap->byte_count, (char []) {0, 0}, 2); printf("load_tilemap %p\n", (void *) tilemap); SDL_SetRenderTarget(renderer, NULL); -- cgit 1.4.1-2-gfad0