Make it not crash when player is deleted
This commit is contained in:
parent
3e5456b718
commit
2a81321b7e
@ -85,9 +85,11 @@ void app_Render(App *app) {
|
||||
}
|
||||
}
|
||||
}
|
||||
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));
|
||||
|
20
entity.c
20
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);
|
||||
}
|
||||
|
8
entity.h
8
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
|
||||
|
Loading…
Reference in New Issue
Block a user