diff --git a/src/entity.c b/src/entity.c index 74b769a5..77f438a8 100644 --- a/src/entity.c +++ b/src/entity.c @@ -294,11 +294,15 @@ void entity_set_local_xform(struct entity *ent, struct xform xf) * Tree * ========================== */ -/* FIXME: Unlink existing */ void entity_link_parent(struct entity *ent, struct entity *parent) { 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 parent_handle = parent->handle; diff --git a/src/entity.h b/src/entity.h index bcfc8f1f..a34bbd7b 100644 --- a/src/entity.h +++ b/src/entity.h @@ -49,20 +49,19 @@ struct entity_store { }; struct entity { + /* ====================================================================== */ /* Metadata */ + b32 valid; /* Is this entity allocated in memory that can be written to (can always be read) */ struct entity_handle handle; u64 continuity_gen; u64 props[(ENTITY_PROP_COUNT + 63) / 64]; struct entity_handle next_free; - /* Special value stored in first entity in store array */ - u64 store_offset; - /* Is this the root entity */ b32 is_root; - /* Is the parent the root entity */ + /* Is entity a child of the root entity */ b32 is_top; /* Tree */ diff --git a/src/game.c b/src/game.c index 5deb701e..06173ec2 100644 --- a/src/game.c +++ b/src/game.c @@ -530,7 +530,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) bullet->bullet_src = ent->handle; bullet->bullet_src_pos = rel_pos; bullet->bullet_src_dir = rel_dir; - bullet->bullet_impulse = 100; + bullet->bullet_impulse = 5; 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)) { 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); + + /* 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)); + entity_set_xform(ent, xf); } }