unlink existing parent when linking

This commit is contained in:
jacob 2024-08-16 15:55:16 -05:00
parent 3f98cdb669
commit 00560af92c
3 changed files with 15 additions and 12 deletions

View File

@ -294,11 +294,15 @@ void entity_set_local_xform(struct entity *ent, struct xform xf)
* Tree * Tree
* ========================== */ * ========================== */
/* FIXME: Unlink existing */
void entity_link_parent(struct entity *ent, struct entity *parent) void entity_link_parent(struct entity *ent, struct entity *parent)
{ {
struct entity_store *store = entity_get_store(ent); struct entity_store *store = entity_get_store(ent);
if (ent->parent.gen) {
/* Unlink from current parent */
entity_unlink_parent(ent);
}
struct entity_handle handle = ent->handle; struct entity_handle handle = ent->handle;
struct entity_handle parent_handle = parent->handle; struct entity_handle parent_handle = parent->handle;

View File

@ -49,20 +49,19 @@ struct entity_store {
}; };
struct entity { struct entity {
/* ====================================================================== */
/* Metadata */ /* Metadata */
b32 valid; /* Is this entity allocated in memory that can be written to (can always be read) */ b32 valid; /* Is this entity allocated in memory that can be written to (can always be read) */
struct entity_handle handle; struct entity_handle handle;
u64 continuity_gen; u64 continuity_gen;
u64 props[(ENTITY_PROP_COUNT + 63) / 64]; u64 props[(ENTITY_PROP_COUNT + 63) / 64];
struct entity_handle next_free; struct entity_handle next_free;
/* Special value stored in first entity in store array */
u64 store_offset;
/* Is this the root entity */ /* Is this the root entity */
b32 is_root; b32 is_root;
/* Is the parent the root entity */ /* Is entity a child of the root entity */
b32 is_top; b32 is_top;
/* Tree */ /* Tree */

View File

@ -530,7 +530,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
bullet->bullet_src = ent->handle; bullet->bullet_src = ent->handle;
bullet->bullet_src_pos = rel_pos; bullet->bullet_src_pos = rel_pos;
bullet->bullet_src_dir = rel_dir; bullet->bullet_src_dir = rel_dir;
bullet->bullet_impulse = 100; bullet->bullet_impulse = 5;
entity_enable_prop(bullet, ENTITY_PROP_BULLET); entity_enable_prop(bullet, ENTITY_PROP_BULLET);
} }
@ -618,14 +618,14 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
if (entity_has_prop(ent, ENTITY_PROP_KINEMATIC)) { if (entity_has_prop(ent, ENTITY_PROP_KINEMATIC)) {
f32 dt = (f32)G.tick.dt; f32 dt = (f32)G.tick.dt;
/* Apply acceleration to velocity */
struct v2 a = v2_mul(ent->acceleration, dt);
ent->velocity = v2_add(ent->velocity, a);
/* Apply velocity to position */
struct xform xf = entity_get_xform(ent); struct xform xf = entity_get_xform(ent);
/* Integrate acceleration to find velocity */
ent->velocity = v2_add(ent->velocity, v2_mul(ent->acceleration, dt));
/* Integrate velocity to find position */
xf.og = v2_add(xf.og, v2_mul(ent->velocity, dt)); xf.og = v2_add(xf.og, v2_mul(ent->velocity, dt));
entity_set_xform(ent, xf); entity_set_xform(ent, xf);
} }
} }