diff --git a/src/game.c b/src/game.c index 4ec50aff..ac8431a3 100644 --- a/src/game.c +++ b/src/game.c @@ -145,6 +145,8 @@ INTERNAL void spawn_test_entities(void) e->mass_unscaled = 70; e->ground_friction = 1000; + entity_enable_prop(e, ENTITY_PROP_TEST); + player_ent = e; } @@ -478,24 +480,22 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) { struct entity *ent = &store->entities[entity_index]; if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue; + if (!entity_has_prop(ent, ENTITY_PROP_ATTACHED)) continue; - if (entity_has_prop(ent, ENTITY_PROP_ATTACHED)) { - struct entity *parent = entity_from_handle(store, ent->parent); - struct sprite_tag parent_sprite = parent->sprite; - struct sprite_sheet *parent_sheet = sprite_sheet_from_tag_await(sprite_frame_scope, parent_sprite); + struct entity *parent = entity_from_handle(store, ent->parent); + struct sprite_tag parent_sprite = parent->sprite; + struct sprite_sheet *parent_sheet = sprite_sheet_from_tag_await(sprite_frame_scope, parent_sprite); - struct xform parent_xf = entity_get_xform(parent); - struct xform parent_sprite_xf = xform_mul(parent_xf, parent->sprite_local_xform); + struct xform parent_sprite_xf = parent->sprite_local_xform; - struct sprite_sheet_slice attach_slice = sprite_sheet_get_slice(parent_sheet, ent->attach_slice, parent->animation_frame); - struct v2 attach_pos = xform_mul_v2(parent_sprite_xf, attach_slice.center); - struct v2 attach_dir = xform_basis_mul_v2(parent_sprite_xf, attach_slice.dir); + struct sprite_sheet_slice attach_slice = sprite_sheet_get_slice(parent_sheet, ent->attach_slice, parent->animation_frame); + struct v2 attach_pos = xform_mul_v2(parent_sprite_xf, attach_slice.center); + struct v2 attach_dir = xform_basis_mul_v2(parent_sprite_xf, attach_slice.dir); - struct xform xf = entity_get_xform(ent); - xf.og = attach_pos; - xf = xform_rotated_to(xf, v2_angle(attach_dir) + PI / 2); - entity_set_xform(ent, xf); - } + struct xform xf = entity_get_local_xform(ent); + xf.og = attach_pos; + xf = xform_rotated_to(xf, v2_angle(attach_dir) + PI / 2); + entity_set_local_xform(ent, xf); } /* ========================== * @@ -566,32 +566,31 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) { struct entity *ent = &store->entities[entity_index]; if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue; + if (!entity_has_prop(ent, ENTITY_PROP_TEST)) continue; - if (entity_has_prop(ent, ENTITY_PROP_TEST)) { - if (!ent->test_initialized) { - ent->test_initialized = true; - ent->test_start_local_xform = entity_get_local_xform(ent); - ent->test_start_sprite_xform = ent->sprite_local_xform; - } - - f32 t = (f32)time; - struct v2 og = v2_mul(V2(math_cos(t), math_sin(t)), 3); - f32 r = t * 3; - struct v2 s = V2(1 + (math_fabs(math_sin(t * 5)) * 3), 1); - (UNUSED)og; - (UNUSED)r; - (UNUSED)s; - - og = v2_add(og, ent->test_start_local_xform.og); - r += xform_get_rotation(ent->test_start_local_xform); - s = v2_add(s, xform_get_scale(ent->test_start_local_xform)); - - struct xform xf = entity_get_local_xform(ent); - xf.og = og; - xf = xform_rotated_to(xf, r); - xf = xform_scaled_to(xf, s); - entity_set_local_xform(ent, xf); + if (!ent->test_initialized) { + ent->test_initialized = true; + ent->test_start_local_xform = entity_get_local_xform(ent); + ent->test_start_sprite_xform = ent->sprite_local_xform; } + + f32 t = (f32)time; + struct v2 og = v2_mul(V2(math_cos(t), math_sin(t)), 3); + f32 r = t * 3; + struct v2 s = V2(1 + (math_fabs(math_sin(t * 5)) * 3), 1); + (UNUSED)og; + (UNUSED)r; + (UNUSED)s; + + og = v2_add(og, ent->test_start_local_xform.og); + r += xform_get_rotation(ent->test_start_local_xform); + s = v2_add(s, xform_get_scale(ent->test_start_local_xform)); + + struct xform xf = entity_get_local_xform(ent); + xf.og = og; + xf = xform_rotated_to(xf, r); + xf = xform_scaled_to(xf, s); + entity_set_local_xform(ent, xf); } /* ========================== *