fix updates not ran on new entities added from game commands
This commit is contained in:
parent
bac9d797b9
commit
38a2478325
22
src/entity.c
22
src/entity.c
@ -214,20 +214,22 @@ void entity_link(struct entity *parent, struct entity *child)
|
||||
{
|
||||
struct entity_store *store = entity_get_store(parent);
|
||||
|
||||
struct entity *first_child = entity_from_handle(store, parent->first);
|
||||
struct entity *last_child = entity_from_handle(store, parent->last);
|
||||
struct entity_handle child_handle = child->handle;
|
||||
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) {
|
||||
last_child->next = child->handle;
|
||||
}
|
||||
parent->last = child->handle;
|
||||
|
||||
if (!first_child->valid) {
|
||||
parent->first = child->handle;
|
||||
child->prev = last_child_handle;
|
||||
last_child->next = child_handle;
|
||||
}
|
||||
parent->last = child_handle;
|
||||
}
|
||||
|
||||
void entity_unlink(struct entity *ent)
|
||||
|
||||
@ -222,7 +222,6 @@ INTERNAL void game_update(void)
|
||||
G.world.tick_ts = sys_timestamp();
|
||||
G.world.dt = max_f64(0.0, (1.0 / GAME_FPS) * G.world.timescale);
|
||||
G.world.time += G.world.dt;
|
||||
struct entity_array entities_array = entity_store_as_array(G.world.entity_store);
|
||||
|
||||
/* ========================== *
|
||||
* Process game cmds
|
||||
@ -245,8 +244,8 @@ INTERNAL void game_update(void)
|
||||
/* Clear level */
|
||||
case GAME_CMD_KIND_CLEAR_ALL: {
|
||||
logf_info("Clearing level");
|
||||
for (u64 i = 0; i < entities_array.count; ++i) {
|
||||
struct entity *ent = &entities_array.entities[i];
|
||||
for (u64 i = 0; i < G.world.entity_store->count; ++i) {
|
||||
struct entity *ent = &G.world.entity_store->entities[i];
|
||||
if (ent->valid && !ent->root) {
|
||||
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_array entities_array = entity_store_as_array(G.world.entity_store);
|
||||
|
||||
/* ========================== *
|
||||
* Update sprite
|
||||
|
||||
Loading…
Reference in New Issue
Block a user