From 764a5a09fc94862aa978baf267769e73cf3607a7 Mon Sep 17 00:00:00 2001 From: snit Date: Sun, 29 Sep 2024 01:28:14 -0500 Subject: [PATCH] move NULL entity registration to world initialisation --- src/entity/registry.c | 5 ----- src/world.c | 9 +++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/entity/registry.c b/src/entity/registry.c index af9d175..b0482ea 100644 --- a/src/entity/registry.c +++ b/src/entity/registry.c @@ -42,11 +42,6 @@ enum error_t entity_registry_init(struct entity_registry_t *self) { if (entities == NULL) return ERR_ALLOC; - struct entity_registrant_t null_entity; - entity_registrant_init(&null_entity, "NULL", '0'); - - entities[0] = null_entity; - self->entities = entities; return ERR_OK; } diff --git a/src/world.c b/src/world.c index 2d418e9..7f44790 100644 --- a/src/world.c +++ b/src/world.c @@ -20,6 +20,15 @@ enum error_t world_init(struct world_t *self, size_t height, size_t width) { enum error_t err = entity_registry_init(&self->registered_entities); if (err != ERR_OK) return err; + struct entity_registrant_t null_entity; + err = entity_registrant_init(&null_entity, "NULL", '?'); + if (err != ERR_OK) { + entity_registry_free(&self->registered_entities); + return err; + } + + self->registered_entities.entities[0] = null_entity; + return ERR_OK; }