Make it not crash when player is deleted

This commit is contained in:
Edgaru089 2024-04-02 15:04:05 +08:00
parent 3e5456b718
commit 2a81321b7e
3 changed files with 33 additions and 3 deletions

View File

@ -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));

View File

@ -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);
}

View File

@ -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