From 8763c437b3d6a57537c25ff65d7bc3801a7ecca7 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 4 Jan 2025 06:13:33 +0000 Subject: [PATCH] Add tag and prev, next pointers to entity structs --- game/main.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/game/main.c b/game/main.c index 9117bde..a033d6e 100644 --- a/game/main.c +++ b/game/main.c @@ -79,7 +79,19 @@ typedef struct { dvec_t off, ext; } dbox_t; +typedef enum { + ENTITY_DYN, + ENTITY_OBJ, +} entitytag_t; + +typedef struct entity { + entitytag_t tag; + struct entity *prev; + struct entity *next; +} entity_t; + typedef struct { + entity_t e; int svar, animlen; double speed; dvec_t pos, dir; @@ -95,6 +107,7 @@ typedef struct { } objtype_t; typedef struct { + entity_t e; unsigned type; ivec_t pos; } objentity_t; @@ -142,7 +155,7 @@ map_tile(const map_t map, int layeridx, double x, double y) return map[layeridx][row][col]; } -static inline int propint(xmlNodePtr node, const char *prop) +static inline int prop_int(xmlNodePtr node, const char *prop) { xmlChar *str = xmlGetProp(node, (const xmlChar *)prop); assert(str); @@ -165,8 +178,8 @@ static void load_layer(map_t map, xmlNodePtr layernode, int layeridx) if (0 != xmlStrcmp(node->name, (const xmlChar *)"chunk")) continue; - const int chunk_x = propint(node, "x"); - const int chunk_y = propint(node, "y"); + const int chunk_x = prop_int(node, "x"); + const int chunk_y = prop_int(node, "y"); chunk_contents = node->xmlChildrenNode; assert( @@ -227,15 +240,15 @@ load_objtype(gamestate_t *state, const char *templ, SDL_Renderer *renderer) && xmlStrcmp(node->name, (const xmlChar *)"object") != 0) node = node->next; assert(NULL != node); - unsigned id = propint(node, "gid"); + unsigned id = prop_int(node, "gid"); assert(id < MAXOBJTYPES); // Populate objtype struct if not already loaded if (NULL == state->objtypes[id].tex) { state->objtypes[id].src.x = 0; state->objtypes[id].src.y = 0; - state->objtypes[id].src.w = propint(node, "width"); - state->objtypes[id].src.h = propint(node, "height"); + state->objtypes[id].src.w = prop_int(node, "width"); + state->objtypes[id].src.h = prop_int(node, "height"); node = node->xmlChildrenNode; while (node != NULL @@ -293,6 +306,7 @@ load_objects(gamestate_t *state, xmlNodePtr node, SDL_Renderer *renderer) assert(state->objcol.buf); } objentity_t *o = &state->objcol.buf[state->objcol.n++]; + o->e.tag = ENTITY_OBJ; // Load object type xmlChar *templ = xmlGetProp(node, (const xmlChar *)"template"); @@ -301,8 +315,8 @@ load_objects(gamestate_t *state, xmlNodePtr node, SDL_Renderer *renderer) xmlFree(templ); // Load object location - o->pos.x = propint(node, "x"); - o->pos.y = propint(node, "y"); + o->pos.x = prop_int(node, "x"); + o->pos.y = prop_int(node, "y"); } while ((node = node->next) != NULL); } @@ -363,6 +377,7 @@ void game_init(int argc, char *argv[], void *mem, SDL_Renderer *renderer) state->vpos.y = -96; // Initialize player state + state->p.e.tag = ENTITY_DYN; state->p.svar = SPRITE_DIR_DOWN; state->p.animlen = PANIMLEN; state->p.animstep.x = PWIDTH;