Skip to content

Commit

Permalink
get rid of frames_ng, game_spawn_ng
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Nov 2, 2023
1 parent 433cdf4 commit 7c36e8f
Show file tree
Hide file tree
Showing 59 changed files with 183 additions and 177 deletions.
2 changes: 1 addition & 1 deletion c1k3-assets
17 changes: 8 additions & 9 deletions entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

animation_t default_anim[] = {
{
.frames_ng = (animation_frame_t[]){ 0 },
.frames = (animation_frame_t[]){ 0 },
.num_frames = 1,
.time = 1,
}
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions entity_barrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion entity_barrel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions entity_door.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion entity_door.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions entity_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
},
};

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion entity_enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions entity_enemy_enforcer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion entity_enemy_enforcer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions entity_enemy_grunt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion entity_enemy_grunt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 7c36e8f

Please sign in to comment.