From bcbf9c95883b602afd4274aafc9d607791a296c6 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 13 Aug 2024 14:30:42 -0500 Subject: [PATCH] bullet testing --- res/graphics/bullet.ase | 3 +++ res/graphics/gun.ase | 4 ++-- src/entity.c | 19 +++++++------------ src/entity.h | 4 +--- src/game.c | 37 +++++++++++++++++++++++-------------- 5 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 res/graphics/bullet.ase diff --git a/res/graphics/bullet.ase b/res/graphics/bullet.ase new file mode 100644 index 00000000..13eb940e --- /dev/null +++ b/res/graphics/bullet.ase @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45e5aaaab5cced39a4b4eee1cb4dad70f58dc2102d4fdcf9701c082eff41c464 +size 370 diff --git a/res/graphics/gun.ase b/res/graphics/gun.ase index 43394560..cb30ac7a 100644 --- a/res/graphics/gun.ase +++ b/res/graphics/gun.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c02919188c293812b7743dfa50da32a88b711f0f6cc2e9e86ed587ec9de714c0 -size 698 +oid sha256:f44b16ea484509e632739567c4091236a1348cdc85fa6077d7b6b52f49cbd2b0 +size 816 diff --git a/src/entity.c b/src/entity.c index d3a0d33d..dd92b92d 100644 --- a/src/entity.c +++ b/src/entity.c @@ -32,9 +32,11 @@ GLOBAL READONLY struct entity g_entity_default = { * Store allocation * ========================== */ +INTERNAL struct entity *entity_alloc_internal(struct entity_store *store); + INTERNAL void store_make_root(struct entity_store *store) { - struct entity *root = entity_alloc_unlinked(store); + struct entity *root = entity_alloc_internal(store); root->is_root = true; root->local_xform = XFORM_IDENT; root->cached_global_xform = XFORM_IDENT; @@ -80,7 +82,7 @@ void entity_store_reset(struct entity_store *store) * Allocation * ========================== */ -struct entity *entity_alloc_unlinked(struct entity_store *store) +INTERNAL struct entity *entity_alloc_internal(struct entity_store *store) { struct entity *entity = NULL; struct entity_handle handle = { 0 }; @@ -100,18 +102,10 @@ struct entity *entity_alloc_unlinked(struct entity_store *store) return entity; } -struct entity *entity_alloc_top(struct entity_store *store) -{ - struct entity *e = entity_alloc_unlinked(store); - struct entity *root = entity_from_handle(store, store->root); - entity_link_parent_child(root, e); - return e; -} - -struct entity *entity_alloc_child(struct entity *parent) +struct entity *entity_alloc(struct entity *parent) { struct entity_store *store = entity_get_store(parent); - struct entity *e = entity_alloc_unlinked(store); + struct entity *e = entity_alloc_internal(store); entity_link_parent_child(parent, e); return e; } @@ -288,6 +282,7 @@ void entity_set_local_xform(struct entity *ent, struct xform xf) * Tree * ========================== */ +/* FIXME: Unlink existing */ void entity_link_parent_child(struct entity *parent, struct entity *child) { struct entity_store *store = entity_get_store(parent); diff --git a/src/entity.h b/src/entity.h index ddd18748..d41cb600 100644 --- a/src/entity.h +++ b/src/entity.h @@ -222,9 +222,7 @@ void entity_store_copy_replace(struct entity_store *dest, struct entity_store *s void entity_store_reset(struct entity_store *store); /* Entity */ -struct entity *entity_alloc_unlinked(struct entity_store *store); -struct entity *entity_alloc_top(struct entity_store *store); -struct entity *entity_alloc_child(struct entity *parent); +struct entity *entity_alloc(struct entity *parent); void entity_release(struct entity_store *store, struct entity *ent); /* Xform */ diff --git a/src/game.c b/src/game.c index 75e9af41..b3b2652b 100644 --- a/src/game.c +++ b/src/game.c @@ -103,6 +103,8 @@ INTERNAL struct game_cmd_array pop_cmds(struct arena *arena) INTERNAL void spawn_test_entities(void) { + struct entity *root = entity_from_handle(G.tick.entity_store, G.tick.entity_store->root); + /* Player */ struct entity *player_ent; { @@ -110,7 +112,7 @@ INTERNAL void spawn_test_entities(void) struct v2 size = V2(1, 1); f32 r = 0; - struct entity *e = entity_alloc_top(G.tick.entity_store); + struct entity *e = entity_alloc(root); struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); entity_set_xform(e, xf); @@ -132,11 +134,18 @@ INTERNAL void spawn_test_entities(void) /* Weapon */ { +#if 0 struct v2 pos = V2(1, 0); struct v2 size = V2(1, 1); f32 r = PI / 4; + struct entity *e = entity_alloc(root); +#else + struct v2 pos = V2(0.1, 0); + struct v2 size = V2(1, 1); + f32 r = 0; + struct entity *e = entity_alloc(player_ent); +#endif - struct entity *e = entity_alloc_top(G.tick.entity_store); struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); entity_set_local_xform(e, xf); @@ -151,7 +160,7 @@ INTERNAL void spawn_test_entities(void) /* Camera */ { - struct entity *e = entity_alloc_top(G.tick.entity_store); + struct entity *e = entity_alloc(root); entity_set_xform(e, XFORM_IDENT); entity_enable_prop(e, ENTITY_PROP_CAMERA); @@ -417,12 +426,6 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) /* Fire weapon */ if (entity_has_prop(ent, ENTITY_PROP_WEAPON)) { -#if 1 - f32 r = 1.0f * ((f32)sys_rand_u32() / U32_MAX); - f32 g = 1.0f * ((f32)sys_rand_u32() / U32_MAX); - f32 b = 1.0f * ((f32)sys_rand_u32() / U32_MAX); - ent->sprite_tint = RGBA_32_F(r, g, b, 1); -#else struct xform xf = entity_get_xform(ent); struct sprite_tag sprite = ent->sprite; @@ -432,12 +435,18 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) struct sprite_sheet_slice out_slice = sprite_sheet_get_slice(sheet, STR("out"), animation_frame); struct v2 out_pos = xform_mul_v2(sprite_xform, out_slice.center); - struct v2 out_dir = xform_basis_mul_v2(sprite_xform, out_slice.dir); - - (UNUSED)out_pos; - (UNUSED)out_dir; -#endif + struct v2 out_vec = xform_basis_mul_v2(sprite_xform, out_slice.dir); + out_vec = v2_norm(out_vec); + out_vec = v2_mul(out_vec, 2); + { + /* 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); + entity_set_xform(bullet, bullet_xf); + bullet->velocity = out_vec; + } } }