From 7c36e8fb56eda8d134badc9b420f53a8ae57a3f3 Mon Sep 17 00:00:00 2001 From: byoung Date: Thu, 2 Nov 2023 16:48:11 -0600 Subject: [PATCH] get rid of frames_ng, game_spawn_ng --- c1k3-assets | 2 +- entity.c | 17 +++++----- entity.h | 4 +-- entity_barrel.c | 6 ++-- entity_barrel.h | 2 +- entity_door.c | 4 +-- entity_door.h | 2 +- entity_enemy.c | 16 +++++----- entity_enemy.h | 2 +- entity_enemy_enforcer.c | 14 ++++----- entity_enemy_enforcer.h | 2 +- entity_enemy_grunt.c | 16 +++++----- entity_enemy_grunt.h | 2 +- entity_enemy_hound.c | 14 ++++----- entity_enemy_hound.h | 2 +- entity_enemy_mutant.c | 6 ++-- entity_enemy_mutant.h | 2 +- entity_enemy_ogre.c | 14 ++++----- entity_enemy_ogre.h | 2 +- entity_enemy_zombie.c | 14 ++++----- entity_enemy_zombie.h | 2 +- entity_light.c | 4 +-- entity_light.h | 2 +- entity_particle.c | 4 +-- entity_particle.h | 2 +- entity_pickup.c | 4 +-- entity_pickup.h | 2 +- entity_pickup_grenadelauncher.c | 4 +-- entity_pickup_grenadelauncher.h | 2 +- entity_pickup_grenades.c | 4 +-- entity_pickup_grenades.h | 2 +- entity_pickup_health.c | 4 +-- entity_pickup_health.h | 2 +- entity_pickup_key.c | 4 +-- entity_pickup_key.h | 2 +- entity_pickup_nailgun.c | 4 +-- entity_pickup_nailgun.h | 2 +- entity_pickup_nails.c | 4 +-- entity_pickup_nails.h | 2 +- entity_player.c | 6 ++-- entity_player.h | 2 +- entity_projectile_gib.c | 4 +-- entity_projectile_gib.h | 2 +- entity_projectile_grenade.c | 6 ++-- entity_projectile_grenade.h | 2 +- entity_projectile_nail.c | 6 ++-- entity_projectile_nail.h | 2 +- entity_projectile_plasma.c | 6 ++-- entity_projectile_plasma.h | 2 +- entity_projectile_shell.c | 6 ++-- entity_projectile_shell.h | 2 +- entity_torch.c | 6 ++-- entity_torch.h | 2 +- entity_trigger_level.c | 4 +-- entity_trigger_level.h | 2 +- game.c | 55 +++++++++++++++++++++------------ map.c | 18 +++++------ map.h | 8 +---- weapon.c | 20 ++++++------ 59 files changed, 183 insertions(+), 177 deletions(-) diff --git a/c1k3-assets b/c1k3-assets index 4c0f369..967e2ed 160000 --- a/c1k3-assets +++ b/c1k3-assets @@ -1 +1 @@ -Subproject commit 4c0f3696b3104f272a74002b8ab099b2baef70c9 +Subproject commit 967e2ed1b14a6bf296d7d27c77655b2b71a7556e diff --git a/entity.c b/entity.c index 7821a07..716ffde 100644 --- a/entity.c +++ b/entity.c @@ -14,7 +14,7 @@ animation_t default_anim[] = { { - .frames_ng = (animation_frame_t[]){ 0 }, + .frames = (animation_frame_t[]){ 0 }, .num_frames = 1, .time = 1, } @@ -53,13 +53,13 @@ void entity_parse_animation_frames(ref_entt_t * curr_entt, animation_t * animati for(size_t i = 0; i < anim_len; i++) { animation_t tmp_anim = animations[i]; for(size_t j = 0; j < tmp_anim.num_frames; j++) { - char * needle = tmp_anim.frames_ng[j].name; + char * needle = tmp_anim.frames[j].name; int64_t f = entity_frame_from_name(needle, curr_entt->frame_names, curr_entt->frame_len); if(f < 0) { fprintf(stderr, "E: couldn't find frame %s for %s\n", needle, curr_entt->entity_name); continue; } - tmp_anim.frames_ng[j].id = f; + tmp_anim.frames[j].id = f; } } @@ -75,9 +75,9 @@ void entity_set_model(entity_t * e) { e->s = e->_params->entity_generic_params.ref_entt->size; } -void entity_constructor(entity_t *e, vec3_t pos) { +void entity_constructor(entity_t *e) { - e->p = pos; + e->p = e->_params->position; e->s = (vec3_t) { 2.0f, 2.0f, 2.0f }; @@ -278,12 +278,11 @@ void entity_draw_model(entity_t * e) { float f = e->_anim_time / (float)e->_anim->time; float mix = f - floorf(f); - // todo, consolidate after frame_ng is in place uint32_t frame_cur = 0; uint32_t frame_next = 0; - frame_cur = e->_anim->frames_ng[(uint32_t)f % e->_anim->num_frames].id; - frame_next = e->_anim->frames_ng[(1 + (uint32_t)f) % e->_anim->num_frames].id; + frame_cur = e->_anim->frames[(uint32_t)f % e->_anim->num_frames].id; + frame_next = e->_anim->frames[(1 + (uint32_t)f) % e->_anim->num_frames].id; // Swap frames if we're looping to the first frame again if (frame_next < frame_cur) { @@ -314,7 +313,7 @@ void entity_spawn_particles(entity_t * e, int amount, int speed, entity_id_t eid vec3_t move_dist = vec3_mulf(e->v, game_tick); vec3_t tickdist = vec3_divf(move_dist, 16.0f); - ep.entity_generic_params.position = vec3_sub(e->p, tickdist); + ep.position = vec3_sub(e->p, tickdist); for (uint32_t i = 0; i < amount; i++) { entity_t * particle = game_spawn_ng(&ep); diff --git a/entity.h b/entity.h index b623c1a..e934f01 100644 --- a/entity.h +++ b/entity.h @@ -60,7 +60,7 @@ typedef struct { typedef struct { float time; uint32_t num_frames; - animation_frame_t * frames_ng; + animation_frame_t * frames; } animation_t; typedef struct { @@ -159,7 +159,7 @@ int64_t entity_frame_from_name(char * needle, char (*haystack)[][100], size_t le char * entity_param_lookup(char * key, vector * v); void entity_parse_animation_frames(ref_entt_t * curr_entt, animation_t * animations, size_t anim_len, ref_entt_t ** last_entt); void entity_set_model(entity_t * e); -void entity_constructor(entity_t *e, vec3_t pos); +void entity_constructor(entity_t *e); void entity_init(entity_t * e); void entity_update(entity_t * e); void entity_update_physics(entity_t * e); diff --git a/entity_barrel.c b/entity_barrel.c index 9e06c2b..63c4694 100644 --- a/entity_barrel.c +++ b/entity_barrel.c @@ -13,8 +13,8 @@ void entity_barrel_init(entity_t * e); void entity_barrel_kill(entity_t * e); void entity_barrel_update(entity_t * e); -void entity_barrel_constructor(entity_t *e, vec3_t pos) { - entity_constructor(e, pos); +void entity_barrel_constructor(entity_t *e) { + entity_constructor(e); e->_kill = entity_barrel_kill; e->_update = entity_barrel_update; @@ -56,8 +56,8 @@ void entity_barrel_kill(entity_t * e) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = vec3_add(e->p, vec3(0,16,0)), .entity_light_params = { - .position = vec3_add(e->p, vec3(0,16,0)), .rgba[0] = 0xE0, .rgba[1] = 0x60, .rgba[2] = 0x80, diff --git a/entity_barrel.h b/entity_barrel.h index 721eeb7..0b1cb9b 100644 --- a/entity_barrel.h +++ b/entity_barrel.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_barrel_constructor(entity_t *e, vec3_t pos); +void entity_barrel_constructor(entity_t *e); #endif diff --git a/entity_door.c b/entity_door.c index 09bc883..5aba18c 100644 --- a/entity_door.c +++ b/entity_door.c @@ -9,9 +9,9 @@ void entity_door_init(entity_t * e, uint8_t dir); void entity_door_update(entity_t * e); void entity_door_receive_damage(entity_t * e, entity_t * from, int32_t amount); -void entity_door_constructor(entity_t *e, vec3_t pos) { +void entity_door_constructor(entity_t *e) { - entity_constructor(e, pos); + entity_constructor(e); e->_update = entity_door_update; e->_receive_damage = entity_door_receive_damage; diff --git a/entity_door.h b/entity_door.h index 6327fa6..00e47d4 100644 --- a/entity_door.h +++ b/entity_door.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_door_constructor(entity_t *e, vec3_t pos); +void entity_door_constructor(entity_t *e); #endif diff --git a/entity_enemy.c b/entity_enemy.c index aaafa7e..f182722 100644 --- a/entity_enemy.c +++ b/entity_enemy.c @@ -17,27 +17,27 @@ animation_t default_animations[] = { { // 0: Idle .time = 1, .num_frames = 1, - .frames_ng = (animation_frame_t[]){ 0 }, + .frames = (animation_frame_t[]){ 0 }, }, { // 1: Walk .time = 0.40f, .num_frames = 4, - .frames_ng = (animation_frame_t[]){ 0 }, + .frames = (animation_frame_t[]){ 0 }, }, { // 2: Run .time = 0.20f, .num_frames = 4, - .frames_ng = (animation_frame_t[]){ 0 }, + .frames = (animation_frame_t[]){ 0 }, }, { // 3: Attack prepare .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]){ 0 }, + .frames = (animation_frame_t[]){ 0 }, }, { // 4: Attack .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]){ 0 }, + .frames = (animation_frame_t[]){ 0 }, }, }; @@ -60,9 +60,9 @@ void entity_enemy_receive_damage(entity_t * e, entity_t * from, int32_t amount); void entity_enemy_kill(entity_t * e); void entity_enemy_did_collide(entity_t * e, int axis); -void entity_enemy_constructor(entity_t *e, vec3_t pos, uint8_t patrol) { +void entity_enemy_constructor(entity_t *e, uint8_t patrol) { - entity_constructor(e, pos); + entity_constructor(e); // todo, still hate this e->_STATE_IDLE = ENEMY_STATE_IDLE; @@ -228,7 +228,7 @@ void entity_enemy_update(entity_t * e) { entity_t * entity_enemy_spawn_projectile(entity_t * e, entity_id_t eid, float speed, float yaw_offset, float pitch_offset) { entity_params_t ep = map_entt_params_from_eid(eid); - ep.entity_generic_params.position = e->p; + ep.position = e->p; entity_t * projectile = game_spawn_ng(&ep); projectile->_check_against = ENTITY_GROUP_PLAYER; diff --git a/entity_enemy.h b/entity_enemy.h index ec05b97..8654ee3 100644 --- a/entity_enemy.h +++ b/entity_enemy.h @@ -4,7 +4,7 @@ #include "entity.h" -void entity_enemy_constructor(entity_t *e, vec3_t pos, uint8_t patrol); +void entity_enemy_constructor(entity_t *e, uint8_t patrol); void entity_enemy_receive_damage(entity_t * e, entity_t * from, int32_t amount); #endif diff --git a/entity_enemy_enforcer.c b/entity_enemy_enforcer.c index 2acdfac..7babfa9 100644 --- a/entity_enemy_enforcer.c +++ b/entity_enemy_enforcer.c @@ -13,14 +13,14 @@ animation_t enforcer_animations[] = { { // 0: Idle .time = 1, .num_frames = 1, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, }, }, { // 1: Walk .time = 0.40f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -30,7 +30,7 @@ animation_t enforcer_animations[] = { { // 2: Run .time = 0.20f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -40,7 +40,7 @@ animation_t enforcer_animations[] = { { // 3: Attack prepare .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, {.name = "shoot"}, {.name = "shoot"}, @@ -50,7 +50,7 @@ animation_t enforcer_animations[] = { { // 4: Attack .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "shoot"}, {.name = "default"}, {.name = "default"}, @@ -70,14 +70,14 @@ vec3_t entity_get_size(model_t * model) { return size; } -void entity_enemy_enforcer_constructor(entity_t *e, vec3_t pos) { +void entity_enemy_enforcer_constructor(entity_t *e) { char * str_p1 = entity_param_lookup("patrol", e->_params->entity_generic_params.extras); uint8_t patrol = 0; if (str_p1) patrol = atoi(str_p1); - entity_enemy_constructor(e, pos, patrol); + entity_enemy_constructor(e, patrol); e->_attack = entity_enemy_enforcer_attack; entity_enemy_enforcer_init(e); } diff --git a/entity_enemy_enforcer.h b/entity_enemy_enforcer.h index 192438a..3acb94a 100644 --- a/entity_enemy_enforcer.h +++ b/entity_enemy_enforcer.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_enemy_enforcer_constructor(entity_t *e, vec3_t pos); +void entity_enemy_enforcer_constructor(entity_t *e); #endif diff --git a/entity_enemy_grunt.c b/entity_enemy_grunt.c index 6bd64be..fb86ec6 100644 --- a/entity_enemy_grunt.c +++ b/entity_enemy_grunt.c @@ -15,14 +15,14 @@ animation_t grunt_animations[] = { { // 0: Idle .time = 1, .num_frames = 1, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, }, }, { // 1: Walk .time = 0.40f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -32,7 +32,7 @@ animation_t grunt_animations[] = { { // 2: Run .time = 0.20f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -42,7 +42,7 @@ animation_t grunt_animations[] = { { // 3: Attack prepare .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, {.name = "shoot"}, {.name = "shoot"}, @@ -52,7 +52,7 @@ animation_t grunt_animations[] = { { // 4: Attack .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "shoot"}, {.name = "default"}, {.name = "default"}, @@ -64,14 +64,14 @@ animation_t grunt_animations[] = { // hack for caching parsed frame names per-map static ref_entt_t * last_ref_entt = NULL; -void entity_enemy_grunt_constructor(entity_t * e, vec3_t pos) { +void entity_enemy_grunt_constructor(entity_t * e) { char * str_p1 = entity_param_lookup("patrol", e->_params->entity_generic_params.extras); uint8_t patrol = 0; if (str_p1) patrol = atoi(str_p1); - entity_enemy_constructor(e, pos, patrol); + entity_enemy_constructor(e, patrol); e->_attack = entity_enemy_grunt_attack; entity_enemy_grunt_init(e); } @@ -102,8 +102,8 @@ void entity_enemy_grunt_attack(entity_t * e) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = vec3_add(e->p, vec3(0,30,0)), .entity_light_params = { - .position = vec3_add(e->p, vec3(0,30,0)), .rgba[0] = 0xff, .rgba[1] = 0xff, .rgba[2] = 0xff, diff --git a/entity_enemy_grunt.h b/entity_enemy_grunt.h index f671b8e..02602cd 100644 --- a/entity_enemy_grunt.h +++ b/entity_enemy_grunt.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_enemy_grunt_constructor(entity_t *e, vec3_t pos); +void entity_enemy_grunt_constructor(entity_t *e); #endif diff --git a/entity_enemy_hound.c b/entity_enemy_hound.c index b19e23a..403b228 100644 --- a/entity_enemy_hound.c +++ b/entity_enemy_hound.c @@ -9,14 +9,14 @@ animation_t hound_animations[] = { .time = 1, .num_frames = 1, // .frames = (uint32_t[]){0, 0}, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, }, }, { // 2: Run .time = 0.15f, .num_frames = 2, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run1"}, {.name = "run2"}, }, @@ -24,7 +24,7 @@ animation_t hound_animations[] = { { // 2: Run .time = 0.15f, .num_frames = 2, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run1"}, {.name = "run2"}, }, @@ -32,14 +32,14 @@ animation_t hound_animations[] = { { // 3: Attack prepare .time = 1, .num_frames = 1, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run1"}, }, }, { // 4: Attack .time = 0.1f, .num_frames = 7, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run1"}, {.name = "run2"}, {.name = "run2"}, @@ -69,14 +69,14 @@ void entity_enemy_hound_init(entity_t * e); void entity_enemy_hound_did_collide_with_entity(entity_t * e, entity_t * other); void entity_enemy_hound_attack(entity_t * e); -void entity_enemy_hound_constructor(entity_t * e, vec3_t pos) { +void entity_enemy_hound_constructor(entity_t * e) { char * str_p1 = entity_param_lookup("patrol", e->_params->entity_generic_params.extras); uint8_t patrol = 0; if (str_p1) patrol = atoi(str_p1); - entity_enemy_constructor(e, pos, patrol); + entity_enemy_constructor(e, patrol); e->_did_collide_with_entity = entity_enemy_hound_did_collide_with_entity; e->_attack = entity_enemy_hound_attack; entity_enemy_hound_init(e); diff --git a/entity_enemy_hound.h b/entity_enemy_hound.h index c525952..ac2aab0 100644 --- a/entity_enemy_hound.h +++ b/entity_enemy_hound.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_enemy_hound_constructor(entity_t *e, vec3_t pos); +void entity_enemy_hound_constructor(entity_t *e); #endif diff --git a/entity_enemy_mutant.c b/entity_enemy_mutant.c index 7c991b3..786a902 100644 --- a/entity_enemy_mutant.c +++ b/entity_enemy_mutant.c @@ -16,7 +16,7 @@ animation_t mutant_animations[] = { { // 0: Idle .time = 0.25, .num_frames = 9, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, {.name = "MutantMesh.001"}, {.name = "MutantMesh.002"}, @@ -47,8 +47,8 @@ enemy_state_t mutant_enemy_states[_ENEMY_STATE_NULL] = { // todo, do something less stupid with this model_t model_mutant = { 0 }; -void entity_enemy_mutant_constructor(entity_t * e, vec3_t pos) { - entity_enemy_constructor(e, pos, 0); +void entity_enemy_mutant_constructor(entity_t * e) { + entity_enemy_constructor(e, 0); e->_attack = entity_enemy_mutant_attack; entity_enemy_mutant_init(e); } diff --git a/entity_enemy_mutant.h b/entity_enemy_mutant.h index 227cbbb..1ec99eb 100644 --- a/entity_enemy_mutant.h +++ b/entity_enemy_mutant.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_enemy_mutant_constructor(entity_t *e, vec3_t pos); +void entity_enemy_mutant_constructor(entity_t *e); #endif diff --git a/entity_enemy_ogre.c b/entity_enemy_ogre.c index c55be12..65189fc 100644 --- a/entity_enemy_ogre.c +++ b/entity_enemy_ogre.c @@ -9,14 +9,14 @@ animation_t ogre_animations[] = { { // 0: Idle .time = 1, .num_frames = 1, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, }, }, { // 1: Walk .time = 0.80f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -26,7 +26,7 @@ animation_t ogre_animations[] = { { // 2: Run .time = 0.40f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -36,7 +36,7 @@ animation_t ogre_animations[] = { { // 3: Attack prepare .time = 0.35f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, {.name = "shoot"}, {.name = "shoot"}, @@ -46,7 +46,7 @@ animation_t ogre_animations[] = { { // 4: Attack .time = 0.35f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "shoot"}, {.name = "default"}, {.name = "default"}, @@ -61,14 +61,14 @@ static ref_entt_t * last_ref_entt = NULL; void entity_enemy_ogre_init(entity_t * e); void entity_enemy_ogre_attack(entity_t * e); -void entity_enemy_ogre_constructor(entity_t * e, vec3_t pos) { +void entity_enemy_ogre_constructor(entity_t * e) { char * str_p1 = entity_param_lookup("patrol", e->_params->entity_generic_params.extras); uint8_t patrol = 0; if (str_p1) patrol = atoi(str_p1); - entity_enemy_constructor(e, pos, patrol); + entity_enemy_constructor(e, patrol); e->_attack = entity_enemy_ogre_attack; entity_enemy_ogre_init(e); } diff --git a/entity_enemy_ogre.h b/entity_enemy_ogre.h index b9e6afd..b57b285 100644 --- a/entity_enemy_ogre.h +++ b/entity_enemy_ogre.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_enemy_ogre_constructor(entity_t *e, vec3_t pos); +void entity_enemy_ogre_constructor(entity_t *e); #endif diff --git a/entity_enemy_zombie.c b/entity_enemy_zombie.c index 06a8bca..fc39bba 100644 --- a/entity_enemy_zombie.c +++ b/entity_enemy_zombie.c @@ -8,14 +8,14 @@ animation_t zombie_animations[] = { { // 0: Idle .time = 1, .num_frames = 1, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, }, }, { // 1: Walk .time = 0.40f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -25,7 +25,7 @@ animation_t zombie_animations[] = { { // 2: Run .time = 0.20f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "run_1"}, {.name = "run_2"}, {.name = "run_3"}, @@ -35,7 +35,7 @@ animation_t zombie_animations[] = { { // 3: Attack prepare .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, {.name = "default"}, {.name = "shoot"}, @@ -45,7 +45,7 @@ animation_t zombie_animations[] = { { // 4: Attack .time = 0.25f, .num_frames = 4, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "shoot"}, {.name = "default"}, {.name = "default"}, @@ -72,8 +72,8 @@ void entity_enemy_zombie_init(entity_t * e); void entity_enemy_zombie_receive_damage(entity_t * e, entity_t *from, int32_t amount); void entity_enemy_zombie_attack(entity_t * e); -void entity_enemy_zombie_constructor(entity_t * e, vec3_t pos) { - entity_enemy_constructor(e, pos, 0); +void entity_enemy_zombie_constructor(entity_t * e) { + entity_enemy_constructor(e, 0); e->_receive_damage = entity_enemy_zombie_receive_damage; e->_attack = entity_enemy_zombie_attack; entity_enemy_zombie_init(e); diff --git a/entity_enemy_zombie.h b/entity_enemy_zombie.h index 018dfb7..5389f58 100644 --- a/entity_enemy_zombie.h +++ b/entity_enemy_zombie.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_enemy_zombie_constructor(entity_t *e, vec3_t pos); +void entity_enemy_zombie_constructor(entity_t *e); #endif diff --git a/entity_light.c b/entity_light.c index 177a1cb..4c81c1c 100644 --- a/entity_light.c +++ b/entity_light.c @@ -11,8 +11,8 @@ void entity_light_init(entity_t * e); void entity_light_update(entity_t * e); -void entity_light_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_light_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_light_update; diff --git a/entity_light.h b/entity_light.h index 04cebc1..6d03a6d 100644 --- a/entity_light.h +++ b/entity_light.h @@ -5,6 +5,6 @@ #include "entity.h" #include "map.h" -void entity_light_constructor(entity_t *e, vec3_t pos); +void entity_light_constructor(entity_t *e); #endif diff --git a/entity_particle.c b/entity_particle.c index 562d0b8..3dd1ce3 100644 --- a/entity_particle.c +++ b/entity_particle.c @@ -6,8 +6,8 @@ void entity_particle_init(entity_t * e); void entity_particle_update(entity_t * e); -void entity_particle_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_particle_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_particle_update; entity_particle_init(e); diff --git a/entity_particle.h b/entity_particle.h index ad30f12..bc0485b 100644 --- a/entity_particle.h +++ b/entity_particle.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_particle_constructor(entity_t *e, vec3_t pos); +void entity_particle_constructor(entity_t *e); #endif diff --git a/entity_pickup.c b/entity_pickup.c index 20eda02..59228f3 100644 --- a/entity_pickup.c +++ b/entity_pickup.c @@ -5,8 +5,8 @@ void entity_pickup_init(entity_t * e); void entity_pickup_update(entity_t * e); -void entity_pickup_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_pickup_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_pickup_update; entity_pickup_init(e); } diff --git a/entity_pickup.h b/entity_pickup.h index b78610e..aa6ea61 100644 --- a/entity_pickup.h +++ b/entity_pickup.h @@ -4,7 +4,7 @@ #include "entity.h" -void entity_pickup_constructor(entity_t *e, vec3_t pos); +void entity_pickup_constructor(entity_t *e); void entity_pickup_update(entity_t * e); #endif diff --git a/entity_pickup_grenadelauncher.c b/entity_pickup_grenadelauncher.c index 7284714..0a3821c 100644 --- a/entity_pickup_grenadelauncher.c +++ b/entity_pickup_grenadelauncher.c @@ -9,8 +9,8 @@ void entity_pickup_grenadelauncher_init(entity_t * e); void entity_pickup_grenadelauncher_update(entity_t * e); void entity_pickup_grenadelauncher_pickup(entity_t * e); -void entity_pickup_grenadelauncher_constructor(entity_t * e, vec3_t pos) { - entity_pickup_constructor(e, pos); +void entity_pickup_grenadelauncher_constructor(entity_t * e) { + entity_pickup_constructor(e); e->_update = entity_pickup_grenadelauncher_update; e->_pickup = entity_pickup_grenadelauncher_pickup; entity_pickup_grenadelauncher_init(e); diff --git a/entity_pickup_grenadelauncher.h b/entity_pickup_grenadelauncher.h index 23144a2..9943f1b 100644 --- a/entity_pickup_grenadelauncher.h +++ b/entity_pickup_grenadelauncher.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_pickup_grenadelauncher_constructor(entity_t *e, vec3_t pos); +void entity_pickup_grenadelauncher_constructor(entity_t *e); #endif diff --git a/entity_pickup_grenades.c b/entity_pickup_grenades.c index e56cd11..4518cc5 100644 --- a/entity_pickup_grenades.c +++ b/entity_pickup_grenades.c @@ -8,8 +8,8 @@ void entity_pickup_grenades_init(entity_t * e); void entity_pickup_grenades_pickup(entity_t * e); -void entity_pickup_grenades_constructor(entity_t * e, vec3_t pos) { - entity_pickup_constructor(e, pos); +void entity_pickup_grenades_constructor(entity_t * e) { + entity_pickup_constructor(e); e->_pickup = entity_pickup_grenades_pickup; entity_pickup_grenades_init(e); } diff --git a/entity_pickup_grenades.h b/entity_pickup_grenades.h index f9fefa5..9616b23 100644 --- a/entity_pickup_grenades.h +++ b/entity_pickup_grenades.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_pickup_grenades_constructor(entity_t *e, vec3_t pos); +void entity_pickup_grenades_constructor(entity_t *e); #endif diff --git a/entity_pickup_health.c b/entity_pickup_health.c index 4cb3f91..e9d2235 100644 --- a/entity_pickup_health.c +++ b/entity_pickup_health.c @@ -7,8 +7,8 @@ void entity_pickup_health_init(entity_t * e); void entity_pickup_health_pickup(entity_t * e); -void entity_pickup_health_constructor(entity_t * e, vec3_t pos) { - entity_pickup_constructor(e, pos); +void entity_pickup_health_constructor(entity_t * e) { + entity_pickup_constructor(e); e->_pickup = entity_pickup_health_pickup; entity_pickup_health_init(e); } diff --git a/entity_pickup_health.h b/entity_pickup_health.h index 5787b90..78b2a03 100644 --- a/entity_pickup_health.h +++ b/entity_pickup_health.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_pickup_health_constructor(entity_t *e, vec3_t pos); +void entity_pickup_health_constructor(entity_t *e); #endif diff --git a/entity_pickup_key.c b/entity_pickup_key.c index 6560d25..f9f27b5 100644 --- a/entity_pickup_key.c +++ b/entity_pickup_key.c @@ -10,8 +10,8 @@ void entity_pickup_key_init(entity_t * e); void entity_pickup_key_update(entity_t * e); void entity_pickup_key_pickup(entity_t * e); -void entity_pickup_key_constructor(entity_t * e, vec3_t pos) { - entity_pickup_constructor(e, pos); +void entity_pickup_key_constructor(entity_t * e) { + entity_pickup_constructor(e); e->_update = entity_pickup_key_update; e->_pickup = entity_pickup_key_pickup; entity_pickup_key_init(e); diff --git a/entity_pickup_key.h b/entity_pickup_key.h index f29b7f8..92671bc 100644 --- a/entity_pickup_key.h +++ b/entity_pickup_key.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_pickup_key_constructor(entity_t *e, vec3_t pos); +void entity_pickup_key_constructor(entity_t *e); #endif diff --git a/entity_pickup_nailgun.c b/entity_pickup_nailgun.c index f28ab27..1f1c46e 100644 --- a/entity_pickup_nailgun.c +++ b/entity_pickup_nailgun.c @@ -11,8 +11,8 @@ void entity_pickup_nailgun_update(entity_t * e); void entity_pickup_nailgun_pickup(entity_t * e); void entity_pickup_nailgun_draw_model(entity_t * e); -void entity_pickup_nailgun_constructor(entity_t *e, vec3_t pos) { - entity_pickup_constructor(e, pos); +void entity_pickup_nailgun_constructor(entity_t *e) { + entity_pickup_constructor(e); e->_update = entity_pickup_nailgun_update; e->_pickup = entity_pickup_nailgun_pickup; entity_pickup_nailgun_init(e); diff --git a/entity_pickup_nailgun.h b/entity_pickup_nailgun.h index c1135ee..89da6cd 100644 --- a/entity_pickup_nailgun.h +++ b/entity_pickup_nailgun.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_pickup_nailgun_constructor(entity_t *e, vec3_t pos); +void entity_pickup_nailgun_constructor(entity_t *e); #endif diff --git a/entity_pickup_nails.c b/entity_pickup_nails.c index 46b3136..376e1b9 100644 --- a/entity_pickup_nails.c +++ b/entity_pickup_nails.c @@ -8,8 +8,8 @@ void entity_pickup_nails_init(entity_t * e); void entity_pickup_nail_pickup(entity_t * e); -void entity_pickup_nails_constructor(entity_t * e, vec3_t pos) { - entity_pickup_constructor(e, pos); +void entity_pickup_nails_constructor(entity_t * e) { + entity_pickup_constructor(e); e->_pickup = entity_pickup_nail_pickup; entity_pickup_nails_init(e); } diff --git a/entity_pickup_nails.h b/entity_pickup_nails.h index 3772e69..b66ffff 100644 --- a/entity_pickup_nails.h +++ b/entity_pickup_nails.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_pickup_nails_constructor(entity_t *e, vec3_t pos); +void entity_pickup_nails_constructor(entity_t *e); #endif diff --git a/entity_player.c b/entity_player.c index 23a3c73..7b3a030 100644 --- a/entity_player.c +++ b/entity_player.c @@ -26,9 +26,9 @@ void entity_player_update(entity_t * e); void entity_player_receive_damage(entity_t * e, entity_t * from, int32_t amount); void entity_player_kill(entity_t * e); -void entity_player_constructor(entity_t * e, vec3_t pos) { +void entity_player_constructor(entity_t * e) { - entity_constructor(e, pos); + entity_constructor(e); // todo, parameter for spawn face direction // @@ -187,8 +187,8 @@ void entity_player_update(entity_t * e) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = e->p, .entity_light_params = { - .position = e->p, .rgba[0] = 0xff, .rgba[1] = 0xff, .rgba[2] = 0xff, diff --git a/entity_player.h b/entity_player.h index 6afaeb1..c4bec94 100644 --- a/entity_player.h +++ b/entity_player.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_player_constructor(entity_t *e, vec3_t pos); +void entity_player_constructor(entity_t *e); #endif diff --git a/entity_projectile_gib.c b/entity_projectile_gib.c index e5542f1..7a4d49c 100644 --- a/entity_projectile_gib.c +++ b/entity_projectile_gib.c @@ -10,8 +10,8 @@ void entity_projectile_gib_update(entity_t * e); void entity_projectile_gib_did_collide(entity_t * e, int axis); void entity_projectile_gib_did_collide_with_entity(entity_t * e, entity_t * other); -void entity_projectile_gib_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_projectile_gib_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_projectile_gib_update; e->_did_collide = entity_projectile_gib_did_collide; diff --git a/entity_projectile_gib.h b/entity_projectile_gib.h index e16c338..b6af7a7 100644 --- a/entity_projectile_gib.h +++ b/entity_projectile_gib.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_projectile_gib_constructor(entity_t *e, vec3_t pos); +void entity_projectile_gib_constructor(entity_t *e); #endif diff --git a/entity_projectile_grenade.c b/entity_projectile_grenade.c index a1c83e5..fc7bb2d 100644 --- a/entity_projectile_grenade.c +++ b/entity_projectile_grenade.c @@ -14,8 +14,8 @@ void entity_projectile_grenade_did_collide(entity_t * e, int axis); void entity_projectile_grenade_did_collide_with_entity(entity_t * e, entity_t * other); void entity_projectile_grenade_kill(entity_t * e); -void entity_projectile_grenade_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_projectile_grenade_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_projectile_grenade_update; e->_did_collide = entity_projectile_grenade_did_collide; @@ -75,8 +75,8 @@ void entity_projectile_grenade_kill(entity_t * e) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = vec3_add(e->p, vec3(0,16,0)), .entity_light_params = { - .position = vec3_add(e->p, vec3(0,16,0)), .rgba[0] = 0xE0, .rgba[1] = 0x60, .rgba[2] = 0x80, diff --git a/entity_projectile_grenade.h b/entity_projectile_grenade.h index c2d7226..38900b4 100644 --- a/entity_projectile_grenade.h +++ b/entity_projectile_grenade.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_projectile_grenade_constructor(entity_t *e, vec3_t pos); +void entity_projectile_grenade_constructor(entity_t *e); #endif diff --git a/entity_projectile_nail.c b/entity_projectile_nail.c index d96798a..3d53415 100644 --- a/entity_projectile_nail.c +++ b/entity_projectile_nail.c @@ -11,8 +11,8 @@ void entity_projectile_nail_update(entity_t * e); void entity_projectile_nail_did_collide(entity_t * e, int axis); void entity_projectile_nail_did_collide_with_entity(entity_t * e, entity_t * other); -void entity_projectile_nail_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_projectile_nail_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_projectile_nail_update; e->_did_collide = entity_projectile_nail_did_collide; @@ -41,8 +41,8 @@ void entity_projectile_nail_did_collide(entity_t * e, int axis) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = e->p, .entity_light_params = { - .position = e->p, .rgba[0] = 0xff, .rgba[1] = 0xff, .rgba[2] = 0xff, diff --git a/entity_projectile_nail.h b/entity_projectile_nail.h index ba6f1ee..a34df77 100644 --- a/entity_projectile_nail.h +++ b/entity_projectile_nail.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_projectile_nail_constructor(entity_t *e, vec3_t pos); +void entity_projectile_nail_constructor(entity_t *e); #endif diff --git a/entity_projectile_plasma.c b/entity_projectile_plasma.c index 0245c3e..851eb51 100644 --- a/entity_projectile_plasma.c +++ b/entity_projectile_plasma.c @@ -12,8 +12,8 @@ void entity_projectile_plasma_update(entity_t * e); void entity_projectile_plasma_did_collide(entity_t * e, int axis); void entity_projectile_plasma_did_collide_with_entity(entity_t * e, entity_t * other); -void entity_projectile_plasma_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_projectile_plasma_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_projectile_plasma_update; e->_did_collide = entity_projectile_plasma_did_collide; @@ -44,8 +44,8 @@ void entity_projectile_plasma_did_collide(entity_t * e, int axis) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = vec3_add(e->p, vec3(0,10,0)), .entity_light_params = { - .position = vec3_add(e->p, vec3(0,10,0)), .rgba[0] = 0xff, .rgba[1] = 0xff, .rgba[2] = 0xff, diff --git a/entity_projectile_plasma.h b/entity_projectile_plasma.h index a6932b0..a4ded8a 100644 --- a/entity_projectile_plasma.h +++ b/entity_projectile_plasma.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_projectile_plasma_constructor(entity_t *e, vec3_t pos); +void entity_projectile_plasma_constructor(entity_t *e); #endif diff --git a/entity_projectile_shell.c b/entity_projectile_shell.c index 75fa726..4c25053 100644 --- a/entity_projectile_shell.c +++ b/entity_projectile_shell.c @@ -11,8 +11,8 @@ void entity_projectile_shell_update(entity_t * e); void entity_projectile_shell_did_collide(entity_t * e, int axis); void entity_projectile_shell_did_collide_with_entity(entity_t * e, entity_t * other); -void entity_projectile_shell_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_projectile_shell_constructor(entity_t * e) { + entity_constructor(e); e->_init = entity_projectile_shell_init; e->_update = entity_projectile_shell_update; @@ -41,8 +41,8 @@ void entity_projectile_shell_did_collide(entity_t * e, int axis) { entity_params_t l = { .id = ENTITY_ID_LIGHT, + .position = e->p, .entity_light_params = { - .position = e->p, .rgba[0] = 0xff, .rgba[1] = 0xff, .rgba[2] = 0xff, diff --git a/entity_projectile_shell.h b/entity_projectile_shell.h index fbeb383..5eb620a 100644 --- a/entity_projectile_shell.h +++ b/entity_projectile_shell.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_projectile_shell_constructor(entity_t *e, vec3_t pos); +void entity_projectile_shell_constructor(entity_t *e); #endif diff --git a/entity_torch.c b/entity_torch.c index 9b817a7..f9a6a92 100644 --- a/entity_torch.c +++ b/entity_torch.c @@ -12,7 +12,7 @@ animation_t torch_animation[] = { { // 0: Idle .time = .25, .num_frames = 14, - .frames_ng = (animation_frame_t[]) { + .frames = (animation_frame_t[]) { {.name = "default"}, {.name = "torch1"}, {.name = "torch2"}, @@ -38,8 +38,8 @@ static ref_entt_t * last_ref_entt = NULL; void entity_torch_init(entity_t * e); void entity_torch_update(entity_t * e); -void entity_torch_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_torch_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_torch_update; diff --git a/entity_torch.h b/entity_torch.h index b33314c..ef4b69a 100644 --- a/entity_torch.h +++ b/entity_torch.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_torch_constructor(entity_t *e, vec3_t pos); +void entity_torch_constructor(entity_t *e); #endif diff --git a/entity_trigger_level.c b/entity_trigger_level.c index 8b8ef59..a7aeacd 100644 --- a/entity_trigger_level.c +++ b/entity_trigger_level.c @@ -5,8 +5,8 @@ void entity_trigger_level_update(entity_t * e); -void entity_trigger_level_constructor(entity_t * e, vec3_t pos) { - entity_constructor(e, pos); +void entity_trigger_level_constructor(entity_t * e) { + entity_constructor(e); e->_update = entity_trigger_level_update; e->_init(e); diff --git a/entity_trigger_level.h b/entity_trigger_level.h index 06e210b..1da443a 100644 --- a/entity_trigger_level.h +++ b/entity_trigger_level.h @@ -4,6 +4,6 @@ #include "entity.h" -void entity_trigger_level_constructor(entity_t *e, vec3_t pos); +void entity_trigger_level_constructor(entity_t *e); #endif diff --git a/game.c b/game.c index 217d0da..0d90981 100644 --- a/game.c +++ b/game.c @@ -142,39 +142,56 @@ entity_t * game_spawn (void (*init)(entity_t *, vec3_t), vec3_t pos, entity_para } // todo, fix this import -typedef void (*constfunc)(entity_t *, vec3_t); +typedef void (*constfunc)(entity_t *); extern constfunc map_constfunc_from_eid(entity_id_t eid); entity_t * game_spawn_ng (entity_params_t * ep) { - void (*constructor)(entity_t *, vec3_t) = map_constfunc_from_eid(ep->id); + void (*constructor)(entity_t *) = map_constfunc_from_eid(ep->id); // todo, spawn the things with parameters if(ep->id >= __ENTITY_ID_END) { fprintf(stderr, "E: unimp -- %d\n", ep->id); return NULL; } - entity_t * e = NULL; - // todo, set e->_params, and use that position - if(ep->id == ENTITY_ID_LIGHT) { - e = game_spawn( - constructor, - ep->entity_light_params.position, ep); - } else if(ep->id == ENTITY_ID_PLAYER) { - e = game_spawn( - constructor, - ep->entity_player_params.position, ep); - } else { - e = game_spawn( - constructor, - ep->entity_generic_params.position, ep); - // todo - // free kv - } + entity_t * e = calloc(1, sizeof(entity_t)); + e->_params = ep; + vector_push(__game_entities, &e); + constructor(e); return e; } +// entity_t * bak_game_spawn_ng (entity_params_t * ep) { + +// void (*constructor)(entity_t *, vec3_t) = map_constfunc_from_eid(ep->id); +// // todo, spawn the things with parameters +// if(ep->id >= __ENTITY_ID_END) { +// fprintf(stderr, "E: unimp -- %d\n", ep->id); +// return NULL; +// } + +// entity_t * e = NULL; +// // todo, set e->_params, and use that position +// if(ep->id == ENTITY_ID_LIGHT) { +// e = game_spawn( +// constructor, +// ep->entity_light_params.position, ep); +// } else if(ep->id == ENTITY_ID_PLAYER) { +// e = game_spawn( +// constructor, +// ep->entity_player_params.position, ep); +// } else { +// e = game_spawn( +// constructor, +// ep->entity_generic_params.position, ep); +// // todo +// // free kv +// } + +// return e; +// } + void game_run(float time_now) { time_now *= 0.001f; diff --git a/map.c b/map.c index 0b35aed..3f7347a 100644 --- a/map.c +++ b/map.c @@ -45,7 +45,7 @@ vector * map_data = NULL; typedef struct { char * entity_string; - void (*constructor_func)(entity_t *, vec3_t); + void (*constructor_func)(entity_t *); } map_entity_table_t; map_entity_table_t map_entity_table[__ENTITY_ID_END] = { 0 }; @@ -154,7 +154,7 @@ void map_init() { }; } -typedef void (*constfunc)(entity_t *, vec3_t); +typedef void (*constfunc)(entity_t *); constfunc map_constfunc_from_eid(entity_id_t eid) { return map_entity_table[eid].constructor_func; } @@ -455,7 +455,7 @@ void mpack_map_parse(const char * data, const size_t data_len) { case ENTITY_ID_PLAYER: vector_push(map_entities, &(entity_params_t) { .id = id, - .entity_player_params.position = { + .position = { .x = mpack_node_float(mpack_node_array_at(mp_me_pos, 0)), .y = mpack_node_float(mpack_node_array_at(mp_me_pos, 1)), .z = mpack_node_float(mpack_node_array_at(mp_me_pos, 2)), @@ -465,7 +465,7 @@ void mpack_map_parse(const char * data, const size_t data_len) { case ENTITY_ID_LIGHT: vector_push(map_entities, &(entity_params_t) { .id = id, - .entity_light_params.position = { + .position = { .x = mpack_node_float(mpack_node_array_at(mp_me_pos, 0)), .y = mpack_node_float(mpack_node_array_at(mp_me_pos, 1)), .z = mpack_node_float(mpack_node_array_at(mp_me_pos, 2)), @@ -481,12 +481,12 @@ void mpack_map_parse(const char * data, const size_t data_len) { default: vector_push(map_entities, &(entity_params_t) { .id = id, - .entity_generic_params.ref_entt = vector_at(tmp_map->ref_entities, id), - .entity_generic_params.position = { + .position = { .x = mpack_node_float(mpack_node_array_at(mp_me_pos, 0)), .y = mpack_node_float(mpack_node_array_at(mp_me_pos, 1)), .z = mpack_node_float(mpack_node_array_at(mp_me_pos, 2)), }, + .entity_generic_params.ref_entt = vector_at(tmp_map->ref_entities, id), .entity_generic_params.extras = map_get_entity_kv(mp_ml_extras) }); } @@ -520,11 +520,7 @@ void map_load (map_t * m) { for (uint32_t i = 0; i < map->e_size; i++) { entity_params_t * ref_ep = vector_at(map->map_entities, i); entity_params_t ep = *ref_ep; - vec3_t * pos = &ep.entity_generic_params.position; - if (ep.id == ENTITY_ID_PLAYER) - pos = &ep.entity_player_params.position; - if (ep.id == ENTITY_ID_LIGHT) - pos = &ep.entity_light_params.position; + vec3_t * pos = &ep.position; pos->x *= 32; pos->y *= 16; diff --git a/map.h b/map.h index 6234b14..5e51473 100644 --- a/map.h +++ b/map.h @@ -71,16 +71,10 @@ typedef struct { } entity_extra_params_t; typedef struct { - vec3_t position; -} entity_player_params_t; - -typedef struct { - vec3_t position; uint8_t rgba[4]; } entity_light_params_t; typedef struct { - vec3_t position; ref_entt_t * ref_entt; vector * extras; } entity_generic_params_t; @@ -90,8 +84,8 @@ typedef struct { typedef struct { entity_id_t id; + vec3_t position; union { - entity_player_params_t entity_player_params; entity_light_params_t entity_light_params; entity_generic_params_t entity_generic_params; }; diff --git a/weapon.c b/weapon.c index f734ed3..8e6b049 100644 --- a/weapon.c +++ b/weapon.c @@ -53,16 +53,16 @@ void weapon_shoot(weapon_t * w, vec3_t pos, float yaw, float pitch) { void weapon_spawn_projectile(weapon_t * w, vec3_t pos, float yaw, float pitch) { entity_params_t ep = map_entt_params_from_eid(w->_projectile_type_ng); - ep.entity_generic_params.position = vec3_add( - pos, - vec3_add( - vec3(0, 12, 0), - vec3_rotate_yaw_pitch( - w->_projectile_offset, - yaw, pitch - ) - ) - ); + ep.position = vec3_add( + pos, + vec3_add( + vec3(0, 12, 0), + vec3_rotate_yaw_pitch( + w->_projectile_offset, + yaw, pitch + ) + ) + ); entity_t * projectile = game_spawn_ng(&ep);