From 708072e716e7ab22a37f528311a433f195f75054 Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Sun, 9 Jul 2023 01:26:05 -0600 Subject: World entries added --- src/world.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 0ec3b32..3bc02cd 100644 --- a/src/world.c +++ b/src/world.c @@ -66,7 +66,7 @@ EntityId popVacantId(World * world) { // Already empty. if (world->vacantIds == NULL) - return ENTITY_ID_NONE; + return ENTITY_NONE; id = world->vacantIds[world->vacantIdsCount - 1]; @@ -120,7 +120,7 @@ EntityId addEntityToWorld(World * world, Entity entity) { if (world->entities == NULL || world->lookUp == NULL) { ALLOCATION_ERROR; - return ENTITY_ID_NONE; + return ENTITY_NONE; } // Set entity and id. @@ -141,7 +141,7 @@ EntityId addEntityToWorld(World * world, Entity entity) { if (world->entities == NULL) { ALLOCATION_ERROR; - return ENTITY_ID_NONE; + return ENTITY_NONE; } // Set entity. @@ -167,7 +167,7 @@ EntityId addEntityToWorld(World * world, Entity entity) { if (world->lookUp == NULL) { ALLOCATION_ERROR; - return ENTITY_ID_NONE; + return ENTITY_NONE; } // Set id. @@ -250,3 +250,26 @@ void drawWorld(World * world, Game * game) { entity->drawCb(game, entity); } } + +KfError addEntryToWorld(World * world, Game * game, WorldEntry entry) { + // Create entity. + Entity entity = createEntity(entry.type, game); + entity.position = entry.position; + entity.rotation = entry.rotation; + + // Add to world. + if (addEntityToWorld(world, entity) == ENTITY_NONE) + return KFERROR; + + return KFSUCCESS; +} + +KfError addEntriesToWorld(World * world, Game * game, WorldEntry * entries, size_t entriesCount) { + int i; + + for (i = 0; i < entriesCount; ++i) + if (addEntryToWorld(world, game, entries[i]) != KFSUCCESS) + return KFERROR; + + return KFSUCCESS; +} -- cgit v1.2.3