diff --git a/src/entity.c b/src/entity.c index b5ce23ee..74b769a5 100644 --- a/src/entity.c +++ b/src/entity.c @@ -108,7 +108,7 @@ struct entity *entity_alloc(struct entity *parent) { struct entity_store *store = entity_get_store(parent); struct entity *e = entity_alloc_internal(store); - entity_link_parent_child(parent, e); + entity_link_parent(e, parent); return e; } @@ -295,28 +295,26 @@ void entity_set_local_xform(struct entity *ent, struct xform xf) * ========================== */ /* FIXME: Unlink existing */ -void entity_link_parent_child(struct entity *parent, struct entity *child) +void entity_link_parent(struct entity *ent, struct entity *parent) { - struct entity_store *store = entity_get_store(parent); + struct entity_store *store = entity_get_store(ent); - struct entity_handle child_handle = child->handle; + struct entity_handle handle = ent->handle; struct entity_handle parent_handle = parent->handle; - child->parent = parent_handle; - - if (!parent->first.gen) { - parent->first = child_handle; - } + ent->parent = parent_handle; struct entity_handle last_child_handle = parent->last; struct entity *last_child = entity_from_handle(store, last_child_handle); if (last_child->valid) { - child->prev = last_child_handle; - last_child->next = child_handle; + ent->prev = last_child_handle; + last_child->next = handle; + } else { + parent->first = handle; } - parent->last = child_handle; + parent->last = handle; - child->is_top = parent->is_root; + ent->is_top = parent->is_root; } /* NOTE: Entity will be dangling after calling this, should re-link to root entity. */ @@ -343,35 +341,3 @@ void entity_unlink_parent(struct entity *ent) ent->prev = entity_nil_handle(); ent->next = entity_nil_handle(); } - -/* NOTE: Children will be re-linked as children to their grandparent (ent's parent) */ -void entity_unlink_children(struct entity *ent) -{ - struct entity_store *store = entity_get_store(ent); - - struct entity_handle parent_handle = ent->parent; - struct entity *parent = entity_from_handle(store, parent_handle); - - /* Link children to grandparent */ - struct entity_handle child_first_handle = ent->first; - if (child_first_handle.gen) { - struct entity_handle child_last_handle = ent->last; - - struct entity_handle parent_last_handle = parent->last; - struct entity *parent_last = entity_from_handle(store, parent_last_handle); - if (parent_last->valid) { - parent_last->next = child_first_handle; - } else { - parent->first = child_first_handle; - } - - parent->last = child_last_handle; - - /* Set children parent & is_top */ - b32 parent_is_root = parent->is_root; - for (struct entity *child = entity_from_handle(store, child_first_handle); child->valid; child = entity_from_handle(store, child->next)) { - child->parent = parent_handle; - child->is_top = parent_is_root; - } - } -} diff --git a/src/entity.h b/src/entity.h index 2d7c1758..bcfc8f1f 100644 --- a/src/entity.h +++ b/src/entity.h @@ -268,8 +268,7 @@ struct entity *entity_find_first_match_one(struct entity_store *store, enum enti struct entity *entity_find_first_match_all(struct entity_store *store, struct entity_prop_array props); /* Tree */ -void entity_link_parent_child(struct entity *parent, struct entity *child); +void entity_link_parent(struct entity *parent, struct entity *child); void entity_unlink_parent(struct entity *ent); -void entity_unlink_children(struct entity *ent); #endif