Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Nov 1, 2023
1 parent 242f7a8 commit 978f196
Show file tree
Hide file tree
Showing 65 changed files with 235 additions and 236 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ tools/mapc: $(EXT_OBJ)

lint:
astyle -n $(INT_SRC) $(INT_H)
cppcheck $(INT_SRC) $(INT_H)
clang-tidy $(INT_SRC) $(INT_H)

test:
## super overkill with the linking and building in all objects
Expand Down
2 changes: 1 addition & 1 deletion c1k3-assets
1 change: 1 addition & 0 deletions compile_flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
-I/usr/include/libpng16
-Os
-flto
-std=c11
12 changes: 6 additions & 6 deletions entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ char * entity_param_lookup(char * key, vector * v) {
return NULL;
}

void entity_parse_animation_frames(ref_entt_t * curr_entt, animation_t * animations, size_t anim_len, ref_entt_t * last_entt) {
void entity_parse_animation_frames(ref_entt_t * curr_entt, animation_t * animations, size_t anim_len, ref_entt_t ** last_entt) {
// already cached
if(curr_entt == last_entt)
if(curr_entt == *last_entt)
return;

for(size_t i = 0; i < anim_len; i++) {
Expand All @@ -65,7 +65,7 @@ void entity_parse_animation_frames(ref_entt_t * curr_entt, animation_t * animati
}
}

last_entt = curr_entt;
*last_entt = curr_entt;
}

void entity_set_model(entity_t * e) {
Expand All @@ -77,7 +77,7 @@ 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, uint8_t p1, uint8_t p2) {
void entity_constructor(entity_t *e, vec3_t pos) {

e->p = pos;
e->s = (vec3_t) {
Expand Down Expand Up @@ -118,11 +118,11 @@ void entity_constructor(entity_t *e, vec3_t pos, uint8_t p1, uint8_t p2) {
e->_spawn_projectile = entity_spawn_projectile;
e->_attack = entity_attack;

entity_init(e, 0, 0);
entity_init(e);
}

// only to do something dynamic to every entity
void entity_init(entity_t * e, uint8_t p1, uint8_t p2) {}
void entity_init(entity_t * e) {}

void entity_update(entity_t * e) {
e->_draw_model(e);
Expand Down
8 changes: 4 additions & 4 deletions entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ typedef struct entity_t {
float _stepped_up_at;

// first param is actually entity_t *
void (*_init)(struct entity_t * e, uint8_t p1, uint8_t p2);
void (*_init)(struct entity_t * e);
void (*_update)(struct entity_t * e);
void (*_update_physics)(struct entity_t * e);
bool (*_collides)(struct entity_t * e, vec3_t p);
Expand All @@ -159,10 +159,10 @@ typedef struct entity_t {

int64_t entity_frame_from_name(char * needle, char (*haystack)[][100], size_t len);
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_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, uint8_t p1, uint8_t p2);
void entity_init(entity_t * e, uint8_t p1, uint8_t p2);
void entity_constructor(entity_t *e, vec3_t pos);
void entity_init(entity_t * e);
void entity_update(entity_t * e);
void entity_update_physics(entity_t * e);
bool entity_collides(entity_t * e, vec3_t p);
Expand Down
10 changes: 5 additions & 5 deletions entity_barrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
#include "model.h"
#include "audio.h"

void entity_barrel_init(entity_t * e, uint8_t p1, uint8_t p2);
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, uint8_t p1, uint8_t p2) {
entity_constructor(e, pos, p1, p2);
void entity_barrel_constructor(entity_t *e, vec3_t pos) {
entity_constructor(e, pos);

e->_kill = entity_barrel_kill;
e->_update = entity_barrel_update;

entity_barrel_init(e, p1, p2);
entity_barrel_init(e);
}

void entity_barrel_update(entity_t * e) {
e->_update_physics(e);
e->_draw_model(e);
}

void entity_barrel_init(entity_t * e, uint8_t p1, uint8_t p2) {
void entity_barrel_init(entity_t * e) {
e->_health = 10;
e->_group = ENTITY_GROUP_ENEMY;

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, uint8_t p1, uint8_t p2);
void entity_barrel_constructor(entity_t *e, vec3_t pos);

#endif
23 changes: 12 additions & 11 deletions entity_door.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
#include "text.h"
#include "render.h"

void entity_door_init(entity_t * e, uint8_t p1, uint8_t p2);
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, uint8_t p1, uint8_t p2) {
void entity_door_constructor(entity_t *e, vec3_t pos) {

char * str_p1 = entity_param_lookup("dir", e->_params->entity_generic_params.extras);
if (str_p1)
p1 = atoi(str_p1);
else
p1 = 0;

entity_constructor(e, pos, p1, p2);
entity_constructor(e, pos);

e->_update = entity_door_update;
e->_receive_damage = entity_door_receive_damage;
entity_door_init(e, p1, p2);

// todo, also set needs_key via params
char * str_p1 = entity_param_lookup("dir", e->_params->entity_generic_params.extras);
uint8_t dir = 0;
if (str_p1)
dir = atoi(str_p1);

entity_door_init(e, dir);
}

void entity_door_init(entity_t * e, uint8_t texture, uint8_t dir) {
void entity_door_init(entity_t * e,uint8_t dir) {
e->_health = 10;
e->s = vec3(64, 64, 64);
e->_start_pos = vec3_clone(e->p);
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, uint8_t p1, uint8_t p2);
void entity_door_constructor(entity_t *e, vec3_t pos);

#endif
11 changes: 5 additions & 6 deletions entity_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ enemy_state_t default_enemy_states[_ENEMY_STATE_NULL] = {
[ENEMY_STATE_EVADE] = {ENEMY_ANIMATION_RUN, 1.0, 0.8, ENEMY_STATE_ATTACK_AIM},
};

void entity_enemy_init(entity_t * e, uint8_t p1, uint8_t p2);
void entity_enemy_init(entity_t * e, uint8_t patrol);
void entity_enemy_set_state(entity_t * e, uint32_t state);
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);
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 p1, uint8_t p2) {
void entity_enemy_constructor(entity_t *e, vec3_t pos, uint8_t patrol) {

entity_constructor(e, pos, p1, p2);
entity_constructor(e, pos);

// todo, still hate this
e->_STATE_IDLE = ENEMY_STATE_IDLE;
Expand All @@ -75,18 +75,17 @@ void entity_enemy_constructor(entity_t *e, vec3_t pos, uint8_t p1, uint8_t p2) {
e->_STATE_EVADE = ENEMY_STATE_EVADE;
e->_STATE_NULL = _ENEMY_STATE_NULL;

e->_init = entity_enemy_init;
e->_set_state = entity_enemy_set_state;
e->_update = entity_enemy_update;
e->_spawn_projectile = entity_enemy_spawn_projectile;
e->_receive_damage = entity_enemy_receive_damage;
e->_kill = entity_enemy_kill;
e->_did_collide = entity_enemy_did_collide;

entity_enemy_init(e, p1, p2);
entity_enemy_init(e, patrol);
}

void entity_enemy_init(entity_t * e, uint8_t patrol_dir, uint8_t p2) {
void entity_enemy_init(entity_t * e, uint8_t patrol_dir) {
// todo, check patrol_dir

e->_state_collection = (enemy_state_collection_t) {
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 p1, uint8_t p2);
void entity_enemy_constructor(entity_t *e, vec3_t pos, uint8_t patrol);
void entity_enemy_receive_damage(entity_t * e, entity_t * from, int32_t amount);

#endif
18 changes: 12 additions & 6 deletions entity_enemy_enforcer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "audio.h"
#include "map.h"

void entity_enemy_enforcer_init(entity_t * e, uint8_t p1, uint8_t p2);
void entity_enemy_enforcer_init(entity_t * e);
void entity_enemy_enforcer_attack(entity_t * e);

animation_t enforcer_animations[] = {
Expand Down Expand Up @@ -70,21 +70,27 @@ vec3_t entity_get_size(model_t * model) {
return size;
}

void entity_enemy_enforcer_constructor(entity_t *e, vec3_t pos, uint8_t p1, uint8_t p2) {
entity_enemy_constructor(e, pos, p1, p2);
void entity_enemy_enforcer_constructor(entity_t *e, vec3_t pos) {

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);
e->_attack = entity_enemy_enforcer_attack;
entity_enemy_enforcer_init(e, p1, p2);
entity_enemy_enforcer_init(e);
}

void entity_enemy_enforcer_init(entity_t * e, uint8_t patrol_dir, uint8_t p2) {
void entity_enemy_enforcer_init(entity_t * e) {
e->_health = 80;
e->s = vec3(14,44,14);

entity_parse_animation_frames(
e->_params->entity_generic_params.ref_entt,
enforcer_animations,
sizeof(enforcer_animations)/sizeof(enforcer_animations[0]),
last_ref_entt
&last_ref_entt
);

e->_animation_collection = (animation_collection_t) {
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, uint8_t p1, uint8_t p2);
void entity_enemy_enforcer_constructor(entity_t *e, vec3_t pos);

#endif
17 changes: 8 additions & 9 deletions entity_enemy_grunt.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "map.h"
#include "vector.h"

void entity_enemy_grunt_init(entity_t * e, uint8_t p1, uint8_t p2);
void entity_enemy_grunt_init(entity_t * e);
void entity_enemy_grunt_attack(entity_t * e);

animation_t grunt_animations[] = {
Expand Down Expand Up @@ -64,27 +64,26 @@ 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, uint8_t p1, uint8_t p2) {
void entity_enemy_grunt_constructor(entity_t * e, vec3_t pos) {

char * str_p1 = entity_param_lookup("patrol", e->_params->entity_generic_params.extras);
uint8_t patrol = 0;
if (str_p1)
p1 = atoi(str_p1);
else
p1 = 0;
patrol = atoi(str_p1);

entity_enemy_constructor(e, pos, p1, p2);
entity_enemy_constructor(e, pos, patrol);
e->_attack = entity_enemy_grunt_attack;
entity_enemy_grunt_init(e, p1, p2);
entity_enemy_grunt_init(e);
}

void entity_enemy_grunt_init(entity_t * e, uint8_t patrol_dir, uint8_t p2) {
void entity_enemy_grunt_init(entity_t * e) {
e->_health = 40;

entity_parse_animation_frames(
e->_params->entity_generic_params.ref_entt,
grunt_animations,
sizeof(grunt_animations)/sizeof(grunt_animations[0]),
last_ref_entt
&last_ref_entt
);

entity_set_model(e);
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, uint8_t p1, uint8_t p2);
void entity_enemy_grunt_constructor(entity_t *e, vec3_t pos);

#endif
18 changes: 12 additions & 6 deletions entity_enemy_hound.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,24 @@ enemy_state_t hound_enemy_states[_ENEMY_STATE_NULL] = {
[ENEMY_STATE_EVADE] = {ENEMY_ANIMATION_RUN, 1.0, 0.3, ENEMY_STATE_ATTACK_AIM},
};

void entity_enemy_hound_init(entity_t * e, uint8_t p1, uint8_t p2);
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, uint8_t p1, uint8_t p2) {
entity_enemy_constructor(e, pos, p1, p2);
void entity_enemy_hound_constructor(entity_t * e, vec3_t pos) {

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);
e->_did_collide_with_entity = entity_enemy_hound_did_collide_with_entity;
e->_attack = entity_enemy_hound_attack;
entity_enemy_hound_init(e, p1, p2);
entity_enemy_hound_init(e);
}

void entity_enemy_hound_init(entity_t * e, uint8_t patrol_dir, uint8_t p2) {
void entity_enemy_hound_init(entity_t * e) {
e->_health = 25;
e->_check_against = ENTITY_GROUP_PLAYER;

Expand Down Expand Up @@ -104,7 +110,7 @@ void entity_enemy_hound_init(entity_t * e, uint8_t patrol_dir, uint8_t p2) {
e->_params->entity_generic_params.ref_entt,
hound_animations,
sizeof(hound_animations)/sizeof(hound_animations[0]),
last_ref_entt
&last_ref_entt
);

entity_set_model(e);
Expand Down
2 changes: 1 addition & 1 deletion entity_enemy_hound.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#include "entity.h"

void entity_enemy_hound_constructor(entity_t *e, vec3_t pos, uint8_t p1, uint8_t p2);
void entity_enemy_hound_constructor(entity_t *e, vec3_t pos);

#endif
Loading

0 comments on commit 978f196

Please sign in to comment.