diff --git a/app_render.cpp b/app_render.cpp index 6d9c360..462d789 100644 --- a/app_render.cpp +++ b/app_render.cpp @@ -85,9 +85,11 @@ void app_Render(App *app) { } } } - setlinecolor(RGB(255, 0, 255)); - Vec2 respawn = camera_TransformVec2(app->camera, app->player->player->hazardRespawn); - circle((int)round(respawn.x), (int)round(respawn.y), 6); + if (app->player->player) { + setlinecolor(RGB(255, 0, 255)); + Vec2 respawn = camera_TransformVec2(app->camera, app->player->player->hazardRespawn); + circle((int)round(respawn.x), (int)round(respawn.y), 6); + } setfillcolor(RGB(255, 255, 255)); diff --git a/entity.c b/entity.c index 69ce489..1f8a509 100644 --- a/entity.c +++ b/entity.c @@ -123,3 +123,23 @@ void entity_Advance(System_Entity *sys, Duration deltaTime) { e->thinker(sys->super, e, deltaTime); } } + + +void entity_Clear(System_Entity *sys) { + // Build a list of all entity IDs + vector_Clear(sys->flaggedDelete); + for (tree_Node *i = tree_FirstNode(sys->entities); + i != NULL; + i = tree_Node_Next(i)) { + Entity *e = (Entity *)i->data; + vector_Push(sys->flaggedDelete, &e->id); + } + + // _Delete all of them + for (int i = 0; i < vector_Size(sys->flaggedDelete); i++) { + _entity_Delete(sys, *(uintptr_t *)(vector_At(sys->flaggedDelete, i))); + } + vector_Clear(sys->flaggedDelete); + + ASSERT(tree_Count(sys->entities) == 0); +} diff --git a/entity.h b/entity.h index 3bfe180..40e91c3 100644 --- a/entity.h +++ b/entity.h @@ -65,6 +65,14 @@ void entity_Delete(System_Entity *sys, uintptr_t id); void entity_Advance(System_Entity *sys, Duration deltaTime); +// Clears all the entities. Also calls other systems +// to update these removals. +// +// Should load all other new entities and the player +// before any game logic after this, or this probably +// will crash. Sketchy. +void entity_Clear(System_Entity *sys); + #ifdef __cplusplus } #endif