aboutsummaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-12 21:53:32 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-12 21:53:32 -0600
commit7d4d948dfa92416c802229b1c444a44785ee2a0c (patch)
tree129fcf7141640ec8b3c7647de174755d04858ce2 /src/world.c
parentc759231e1e8570ffe5fdda2f1eb5d011b1c6a29f (diff)
Guided missile worky worky
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/world.c b/src/world.c
index ebfc7ed..26ac9cd 100644
--- a/src/world.c
+++ b/src/world.c
@@ -13,6 +13,9 @@ void initWorld(World * world) {
world->vacantIds = NULL;
world->vacantIdsCount = 0;
+ world->entitiesToAdd = NULL;
+ world->entitiesToAddCount = 0;
+
// Set current fingerprint.
SetRandomSeed(time(NULL));
@@ -227,6 +230,49 @@ KfError removeEntityFromWorld(World * world, EntityId id) {
return KFSUCCESS;
}
+KfError scheduleEntityToAdd(World * world, Entity entity) {
+ ++world->entitiesToAddCount;
+
+ // Allocate shit.
+ if (world->entitiesToAdd == NULL)
+ world->entitiesToAdd = (Entity*)KF_CALLOC(world->entitiesToAddCount, sizeof(Entity));
+ else
+ world->entitiesToAdd = (Entity*)KF_REALLOCARRAY(
+ world->entitiesToAdd,
+ world->entitiesToAddCount,
+ sizeof(Entity)
+ );
+
+ if (world->entitiesToAdd == NULL) {
+ ALLOCATION_ERROR;
+ return KFERROR;
+ }
+
+ world->entitiesToAdd[world->entitiesToAddCount - 1] = entity;
+ return KFSUCCESS;
+}
+
+KfError handleScheduledEntities(World * world) {
+ int i;
+
+ // No entities to add.
+ if (world->entitiesToAdd == NULL)
+ return KFSUCCESS;
+
+ for (i = 0; i < world->entitiesToAddCount; ++i) {
+ // Add entity indeed.
+ if (addEntityToWorld(world, world->entitiesToAdd[i]) == ENTITY_NONE)
+ return KFERROR;
+ }
+
+ // Clean up this shit.
+ KF_FREE(world->entitiesToAdd);
+ world->entitiesToAdd = NULL;
+ world->entitiesToAddCount = 0;
+
+ return KFSUCCESS;
+}
+
void handleCollisionInWorld(Entity * entity1, Entity * entity2) {
//if (entity1->id != 0)
// entity1->health = 0.0;
@@ -303,6 +349,9 @@ void updateWorld(World * world, Game * game) {
removeEntityFromWorld(world, kills[i]);
}
+
+ // Handle some shit.
+ handleScheduledEntities(world);
}
void drawWorld(World * world, Game * game) {