From 2a357c127fe6b8a5ad171b704494578d78a1aa59 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 14 Aug 2024 14:21:51 -0500 Subject: [PATCH] more bullet testing --- res/graphics/bullet.ase | 4 ++-- src/entity.h | 2 +- src/game.c | 14 ++++++++++++-- src/user.c | 8 +------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/res/graphics/bullet.ase b/res/graphics/bullet.ase index dfc5e1df..329b2c96 100644 --- a/res/graphics/bullet.ase +++ b/res/graphics/bullet.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1abb4e1ce9a682baa114c468381371d4d5e805231af6cde7e503ba02fad9dcd0 -size 361 +oid sha256:b92f866a624fbf8c5305fb140fbf5c689d839900683a8cfc677003e9a5953a15 +size 419 diff --git a/src/entity.h b/src/entity.h index 1a0043c9..85f65034 100644 --- a/src/entity.h +++ b/src/entity.h @@ -126,7 +126,7 @@ struct entity { /* ====================================================================== */ /* Bullet */ - struct entity_handle bullet_src_ent; + struct entity_handle bullet_src; /* ====================================================================== */ /* Testing */ diff --git a/src/game.c b/src/game.c index ab2dd86a..d8ae3170 100644 --- a/src/game.c +++ b/src/game.c @@ -559,6 +559,12 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) out_vec = v2_norm(out_vec); out_vec = v2_mul(out_vec, 25); + /* TODO: Remove this (testing) */ + { + struct entity *parent = entity_from_handle(store, ent->parent); + out_vec = v2_add(out_vec, parent->velocity); + } + { /* FIXME: Weapon velocity should affect bullet velocity * (This should also make bullet_src_ent unnecessary for @@ -567,10 +573,10 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) /* Spawn bullet */ struct entity *bullet = entity_alloc(root); bullet->sprite = sprite_tag_from_path(STR("res/graphics/bullet.ase")); - struct xform bullet_xf = XFORM_POS(out_pos); + struct xform bullet_xf = XFORM_TRS(.t = out_pos, .r = v2_angle(out_vec) + PI / 2); entity_set_xform(bullet, bullet_xf); bullet->velocity = out_vec; - bullet->bullet_src_ent = ent->handle; + bullet->bullet_src = ent->handle; entity_enable_prop(bullet, ENTITY_PROP_BULLET); } } @@ -625,6 +631,10 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) * Update sound emitters * ========================== */ + /* TODO: Sound entities should be created by game thread, but played by the + * user thread. This is so sounds play at the correct time on the user + * thread regardless of interp delay. */ + 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; diff --git a/src/user.c b/src/user.c index d99f47b6..501e2dca 100644 --- a/src/user.c +++ b/src/user.c @@ -793,12 +793,6 @@ INTERNAL void user_update(void) struct sprite_tag sprite = ent->sprite; - /* Skip undrawable entities */ - if (ent->is_root - || (sprite_tag_is_nil(sprite) && !entity_has_prop(ent, ENTITY_PROP_CAMERA))) { - continue; - } - struct entity *parent = entity_from_handle(store, ent->parent); struct xform xf = entity_get_xform(ent); @@ -819,7 +813,7 @@ INTERNAL void user_update(void) struct v2 end = xf.og; struct v2 start; - struct entity *src = entity_from_handle(store, ent->bullet_src_ent); + struct entity *src = entity_from_handle(store, ent->bullet_src); if (src->valid) { start = xform_mul_v2(src->sprite_local_xform, sprite_sheet_get_slice(sprite_sheet_from_tag_await(sprite_frame_scope, src->sprite), STR("out"), src->animation_frame).center); start = xform_mul_v2(entity_get_xform(src), start);