From 57e0d0a84ab38af33a43cf77a4db338712f6818c Mon Sep 17 00:00:00 2001 From: jacob Date: Mon, 12 Aug 2024 19:41:39 -0500 Subject: [PATCH] begin firing/bullet work --- src/entity.h | 1 - src/game.c | 26 ++++++++++++++++++++------ src/world.c | 5 +++++ src/world.h | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/entity.h b/src/entity.h index cb74b9ec..a38544b5 100644 --- a/src/entity.h +++ b/src/entity.h @@ -7,7 +7,6 @@ enum entity_prop { ENTITY_PROP_NONE, - ENTITY_PROP_ANIMATING, ENTITY_PROP_PLAYER_CONTROLLED, ENTITY_PROP_CAMERA, ENTITY_PROP_CAMERA_ACTIVE, diff --git a/src/game.c b/src/game.c index 169bbdc4..f640b9eb 100644 --- a/src/game.c +++ b/src/game.c @@ -115,7 +115,6 @@ INTERNAL void spawn_test_entities(void) struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); entity_set_xform(e, xf); - entity_enable_prop(e, ENTITY_PROP_ANIMATING); e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase")); e->sprite_span_name = STR("idle.unarmed"); //e->sprite_span_name = STR("idle.one_handed"); @@ -142,7 +141,6 @@ INTERNAL void spawn_test_entities(void) struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); entity_set_local_xform(e, xf); - entity_enable_prop(e, ENTITY_PROP_ANIMATING); e->sprite = sprite_tag_from_path(STR("res/graphics/gun.ase")); entity_enable_prop(e, ENTITY_PROP_WEAPON); @@ -226,8 +224,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) /* Clear level */ case GAME_CMD_KIND_CLEAR_ALL: { logf_info("Clearing level"); - u64 count = store->count; - for (u64 i = 0; i < count; ++i) { + for (u64 i = 0; i < store->count; ++i) { struct entity *ent = &store->entities[i]; if (ent->valid && !ent->is_root) { entity_release(store, ent); @@ -256,7 +253,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) /* Update animation */ - if (entity_has_prop(ent, ENTITY_PROP_ANIMATING)) { + { struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite); struct sprite_sheet_span span = sprite_sheet_get_span(sheet, ent->sprite_span_name); @@ -281,7 +278,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) ent->animation_frame = frame_index; } - /* Update sprite xform */ + /* Update sprite local xform */ struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite); struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("pivot"), ent->animation_frame); @@ -423,10 +420,27 @@ 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; + u32 animation_frame = ent->animation_frame; + struct xform sprite_xform = xform_mul(xf, ent->sprite_local_xform); + struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, sprite); + + 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 + } } diff --git a/src/world.c b/src/world.c index 6f2b6b9d..14ea427d 100644 --- a/src/world.c +++ b/src/world.c @@ -9,6 +9,11 @@ void world_alloc(struct world *world) world->entity_store = entity_store_alloc(); } +void world_release(struct world *world) +{ + entity_store_release(world->entity_store); +} + void world_copy_replace(struct world *dest, struct world *src) { __prof; diff --git a/src/world.h b/src/world.h index 915d6810..b9cfc500 100644 --- a/src/world.h +++ b/src/world.h @@ -16,6 +16,7 @@ struct world { }; void world_alloc(struct world *world); +void world_release(struct world *world); void world_copy_replace(struct world *dest, struct world *src); #endif