fix updates not ran on new entities added from game commands

This commit is contained in:
jacob 2024-08-06 17:58:52 -05:00
parent bac9d797b9
commit 38a2478325
2 changed files with 15 additions and 13 deletions

View File

@ -214,20 +214,22 @@ void entity_link(struct entity *parent, struct entity *child)
{ {
struct entity_store *store = entity_get_store(parent); struct entity_store *store = entity_get_store(parent);
struct entity *first_child = entity_from_handle(store, parent->first); struct entity_handle child_handle = child->handle;
struct entity *last_child = entity_from_handle(store, parent->last); struct entity_handle parent_handle = parent->handle;
child->prev = last_child->handle; child->parent = parent_handle;
child->parent = parent->handle;
if (!parent->first.gen) {
parent->first = child_handle;
}
struct entity_handle last_child_handle = parent->last;
struct entity *last_child = entity_from_handle(store, last_child_handle);
if (last_child->valid) { if (last_child->valid) {
last_child->next = child->handle; child->prev = last_child_handle;
} last_child->next = child_handle;
parent->last = child->handle;
if (!first_child->valid) {
parent->first = child->handle;
} }
parent->last = child_handle;
} }
void entity_unlink(struct entity *ent) void entity_unlink(struct entity *ent)

View File

@ -222,7 +222,6 @@ INTERNAL void game_update(void)
G.world.tick_ts = sys_timestamp(); G.world.tick_ts = sys_timestamp();
G.world.dt = max_f64(0.0, (1.0 / GAME_FPS) * G.world.timescale); G.world.dt = max_f64(0.0, (1.0 / GAME_FPS) * G.world.timescale);
G.world.time += G.world.dt; G.world.time += G.world.dt;
struct entity_array entities_array = entity_store_as_array(G.world.entity_store);
/* ========================== * /* ========================== *
* Process game cmds * Process game cmds
@ -245,8 +244,8 @@ INTERNAL void game_update(void)
/* Clear level */ /* Clear level */
case GAME_CMD_KIND_CLEAR_ALL: { case GAME_CMD_KIND_CLEAR_ALL: {
logf_info("Clearing level"); logf_info("Clearing level");
for (u64 i = 0; i < entities_array.count; ++i) { for (u64 i = 0; i < G.world.entity_store->count; ++i) {
struct entity *ent = &entities_array.entities[i]; struct entity *ent = &G.world.entity_store->entities[i];
if (ent->valid && !ent->root) { if (ent->valid && !ent->root) {
entity_release(G.world.entity_store, ent); entity_release(G.world.entity_store, ent);
} }
@ -272,6 +271,7 @@ INTERNAL void game_update(void)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct entity_handle root_handle = G.world.entity_store->root; struct entity_handle root_handle = G.world.entity_store->root;
struct entity_array entities_array = entity_store_as_array(G.world.entity_store);
/* ========================== * /* ========================== *
* Update sprite * Update sprite