Skip to content

Commit

Permalink
ng_cleanup and O3
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Nov 4, 2023
1 parent 7c36e8f commit 0087ab9
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 246 deletions.
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SAN_OPT = ASAN_OPTIONS=abort_on_error=1:fast_unwind_on_malloc=0:detect_leaks=0 U

DEBUG_CFLAGS = $(CFLAGS) -g
DBGSN_CFLAGS = $(DEBUG_CFLAGS) $(SAN_FLAGS)
RELEA_CFLAGS = $(CFLAGS) -flto -Os
RELEA_CFLAGS = $(CFLAGS) -flto -O3

all: OPT_FLAGS = $(DBGSN_CFLAGS)
all: assets $(INT_OBJ) $(EXT_OBJ)
Expand Down Expand Up @@ -98,10 +98,8 @@ memtest: valbuild
assets: tools/mapc
make -C c1k3-assets

tools/mapc: OPT_FLAGS = $(DBGSN_CFLAGS)
## tools/mapc: OPT_FLAGS = $(RELEA_CFLAGS)
tools/mapc: $(EXT_OBJ)
$(CC) $(OPT_FLAGS) tools/mapc.c -o tools/mapc $(EXT_OBJ) $(LFLAGS)
$(CC) $(DBGSN_CFLAGS) tools/mapc.c -o tools/mapc $(EXT_OBJ) $(LFLAGS)

%.o: %.c
$(CC) $(OPT_FLAGS) -c $< -o $@
Expand Down
3 changes: 3 additions & 0 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ void audio_play(Mix_Chunk * c) {
}

uint32_t audio_schedule(uint32_t interval, void *param) {
// silence unused warnings
interval = interval;

audio_play(param);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion c1k3-assets
49 changes: 39 additions & 10 deletions entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

animation_t default_anim[] = {
{
.frames = (animation_frame_t[]){ 0 },
.num_frames = 1,
.time = 1,
.num_frames = 1,
.frames = (animation_frame_t[]) {
{
0
}
},
}
};

Expand Down Expand Up @@ -120,7 +124,9 @@ void entity_constructor(entity_t *e) {
}

// only to do something dynamic to every entity
void entity_init(entity_t * e) {}
void entity_init(entity_t * e) {
e = e;
}

void entity_update(entity_t * e) {
e->_draw_model(e);
Expand Down Expand Up @@ -267,9 +273,15 @@ bool entity_collides(entity_t * e, vec3_t p) {
return map_block_at_box(vec3_sub(p, e->s), vec3_add(p, e->s));
}

void entity_did_collide(entity_t * e, int axis) {}
void entity_did_collide(entity_t * e, int axis) {
e = e;
axis = axis;
}

void entity_did_collide_with_entity(entity_t * e, entity_t * other) {}
void entity_did_collide_with_entity(entity_t * e, entity_t * other) {
e = e;
other = other;
}

void entity_draw_model(entity_t * e) {
e->_anim_time += game_tick;
Expand Down Expand Up @@ -304,7 +316,7 @@ void entity_draw_model(entity_t * e) {
r_draw(call);
}

void entity_spawn_particles(entity_t * e, int amount, int speed, entity_id_t eid, float lifetime) {
void entity_spawn_particles(entity_t * e, uint32_t amount, float speed, entity_id_t eid, float lifetime) {

entity_params_t ep = map_entt_params_from_eid(eid);

Expand All @@ -316,7 +328,7 @@ void entity_spawn_particles(entity_t * e, int amount, int speed, entity_id_t eid
ep.position = vec3_sub(e->p, tickdist);

for (uint32_t i = 0; i < amount; i++) {
entity_t * particle = game_spawn_ng(&ep);
entity_t * particle = game_spawn(&ep);
particle->_expires = true;
particle->_die_at = game_time + lifetime + randf() * lifetime * 0.2;
particle->v = vec3(
Expand All @@ -328,6 +340,9 @@ void entity_spawn_particles(entity_t * e, int amount, int speed, entity_id_t eid
}

void entity_receive_damage(entity_t * e, entity_t * from, int32_t amount) {
// silence Wunused
from = from;

if (e->_dead)
return;

Expand All @@ -346,9 +361,23 @@ void entity_kill(entity_t * e) {
e->_dead = 1;
}

void entity_pickup(entity_t * e) {}
void entity_set_state(entity_t * e, uint32_t state) {}
void entity_attack(entity_t * e) {}
void entity_pickup(entity_t * e) {
e = e;
}
void entity_set_state(entity_t * e, uint32_t state) {
e = e;
state = state;
}
void entity_attack(entity_t * e) {
e = e;
}
entity_t * entity_spawn_projectile(entity_t * e, entity_id_t eid, float speed, float yaw_offset, float pitch_offset) {
// silence Wunused
e = e;
eid = eid;
speed = speed;
yaw_offset = yaw_offset;
pitch_offset = pitch_offset;

return NULL;
}
4 changes: 2 additions & 2 deletions entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct entity_t {
void (*_did_collide)(struct entity_t * e, int axis);
void (*_did_collide_with_entity)(struct entity_t * e, struct entity_t * other);
void (*_draw_model)(struct entity_t * e);
void (*_spawn_particles)(struct entity_t * e, int amount, int speed, entity_id_t eid, float lifetime);
void (*_spawn_particles)(struct entity_t * e, uint32_t amount, float speed, entity_id_t eid, float lifetime);
void (*_set_state)(struct entity_t * e, uint32_t state);
struct entity_t * (*_spawn_projectile)(struct entity_t * e, entity_id_t eid, float speed, float yaw_offset, float pitch_offset);
void (*_receive_damage)(struct entity_t * e, struct entity_t * from, int32_t amount);
Expand All @@ -167,7 +167,7 @@ bool entity_collides(entity_t * e, vec3_t p);
void entity_did_collide(entity_t * e, int axis); // todo, axis should probably be an enum
void entity_did_collide_with_entity(entity_t * e, entity_t * other);
void entity_draw_model(entity_t * e);
void entity_spawn_particles(entity_t * e, int amount, int speed, entity_id_t eid, float lifetime);
void entity_spawn_particles(entity_t * e, uint32_t amount, float speed, entity_id_t eid, float lifetime);
void entity_receive_damage(entity_t * e, entity_t * from, int32_t amount);
void entity_play_sound(entity_t * e, Mix_Chunk * sound);
void entity_kill(entity_t * e);
Expand Down
2 changes: 1 addition & 1 deletion entity_barrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void entity_barrel_kill(entity_t * e) {
.rgba[3] = 0xFF,
},
};
entity_t * tmp_light = game_spawn_ng(&l);
entity_t * tmp_light = game_spawn(&l);

tmp_light->_expires = true;
tmp_light->_die_at = game_time + 0.2;
Expand Down
6 changes: 5 additions & 1 deletion entity_door.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ void entity_door_update(entity_t * e) {
e->p = vec3_add(e->_start_pos, vec3_rotate_y(vec3(96 * e->_open,0,0), e->_yaw));
}

void entity_door_receive_damage(entity_t * e, entity_t * from, int32_t amount) {}
void entity_door_receive_damage(entity_t * e, entity_t * from, int32_t amount) {
e = e;
from = from;
amount = amount;
}
32 changes: 26 additions & 6 deletions entity_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,47 @@ animation_t default_animations[] = {
{ // 0: Idle
.time = 1,
.num_frames = 1,
.frames = (animation_frame_t[]){ 0 },
.frames = (animation_frame_t[]) {
{
0
}
},
},
{ // 1: Walk
.time = 0.40f,
.num_frames = 4,
.frames = (animation_frame_t[]){ 0 },
.frames = (animation_frame_t[]) {
{
0
}
},
},
{ // 2: Run
.time = 0.20f,
.num_frames = 4,
.frames = (animation_frame_t[]){ 0 },
.frames = (animation_frame_t[]) {
{
0
}
},
},
{ // 3: Attack prepare
.time = 0.25f,
.num_frames = 4,
.frames = (animation_frame_t[]){ 0 },
.frames = (animation_frame_t[]) {
{
0
}
},
},
{ // 4: Attack
.time = 0.25f,
.num_frames = 4,
.frames = (animation_frame_t[]){ 0 },
.frames = (animation_frame_t[]) {
{
0
}
},
},
};

Expand Down Expand Up @@ -230,7 +250,7 @@ entity_t * entity_enemy_spawn_projectile(entity_t * e, entity_id_t eid, float sp
entity_params_t ep = map_entt_params_from_eid(eid);
ep.position = e->p;

entity_t * projectile = game_spawn_ng(&ep);
entity_t * projectile = game_spawn(&ep);
projectile->_check_against = ENTITY_GROUP_PLAYER;
projectile->_yaw = e->_yaw + PI/2.0f;

Expand Down
2 changes: 1 addition & 1 deletion entity_enemy_grunt.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void entity_enemy_grunt_attack(entity_t * e) {
.rgba[3] = 0x0a,
},
};
entity_t * tmplight = game_spawn_ng(&l);
entity_t * tmplight = game_spawn(&l);

tmplight->_expires = true;
tmplight->_die_at = game_time + 0.1;
Expand Down
4 changes: 3 additions & 1 deletion entity_enemy_mutant.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ void entity_enemy_mutant_init(entity_t * e) {
};
}

void entity_enemy_mutant_attack(entity_t * e) {}
void entity_enemy_mutant_attack(entity_t * e) {
e = e;
}
6 changes: 3 additions & 3 deletions entity_particle.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "entity_particle.h"
#include "model.h"
#include <sys/types.h>
#include "game.h"

void entity_particle_init(entity_t * e);
void entity_particle_update(entity_t * e);
Expand All @@ -21,8 +21,8 @@ void entity_particle_init(entity_t * e) {
}

void entity_particle_update(entity_t * e) {
e->_yaw += e->v.y * 0.001;
e->_pitch += e->v.x * 0.001;
e->_yaw += e->v.y * game_tick * 0.1;
e->_pitch += e->v.x * game_tick * 0.1;
e->_update_physics(e);
e->_draw_model(e);
}
13 changes: 6 additions & 7 deletions entity_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ void entity_player_update(entity_t * e) {
else {
weapon->_shoot(weapon, e->p, e->_yaw, e->_pitch);

typedef struct {
vec3_t position;
uint8_t rgba[4];
} entity_light_params_t;

entity_params_t l = {
.id = ENTITY_ID_LIGHT,
.position = e->p,
Expand All @@ -195,13 +190,13 @@ void entity_player_update(entity_t * e) {
.rgba[3] = 0x0a,
},
};
entity_t * tmp_light = game_spawn_ng(&l);
entity_t * tmp_light = game_spawn(&l);
tmp_light->_expires = game_time + 0.1;
tmp_light->_die_at = game_time + 0.1;
}
}

e->_bob += vec3_length(e->a) * 0.0001;
e->_bob += vec3_length(e->a) * game_tick * 0.01;
e->f = e->_on_ground ? 10 : 2.5;
e->_update_physics(e);

Expand Down Expand Up @@ -264,6 +259,10 @@ void entity_player_receive_damage(entity_t * e, entity_t * from, int32_t amount)
}

uint32_t entity_player_reset_level(uint32_t interval, void *param) {
// silence unused
interval = interval;
param = param;

game_reset_level = 1;
return 0;
}
Expand Down
9 changes: 5 additions & 4 deletions entity_projectile_grenade.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void entity_projectile_grenade_update(entity_t * e) {
e->_pitch += (fabs(e->v.x) + fabs(e->v.y) + fabs(e->v.z)) * .02 * game_tick;

e->_draw_model(e);
r_push_light(vec3_add(e->p, vec3(0,16,0)), (sinf(game_time*10)+2)*0.5, 255, 32, 0);
r_push_light(vec3_add(e->p, vec3(0,16,0)), (sinf(game_time*10)+2)*5, 255, 32, 0);
e->f = e->_on_ground ? 5 : 0.5;
}

Expand All @@ -52,6 +52,9 @@ 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) {
// silence unused
other = other;

e->_kill(e);
}

Expand All @@ -71,8 +74,6 @@ void entity_projectile_grenade_kill(entity_t * e) {
e->_play_sound(e, sfx_grenade_explode);
e->_spawn_particles(e, 2, 800, ENTITY_ID_PARTICLE_SLUG, 1);



entity_params_t l = {
.id = ENTITY_ID_LIGHT,
.position = vec3_add(e->p, vec3(0,16,0)),
Expand All @@ -83,7 +84,7 @@ void entity_projectile_grenade_kill(entity_t * e) {
.rgba[3] = 0xFF,
},
};
entity_t * tmplight = game_spawn_ng(&l);
entity_t * tmplight = game_spawn(&l);

tmplight->_expires = true;
tmplight->_die_at = game_time + 0.2;
Expand Down
5 changes: 4 additions & 1 deletion entity_projectile_nail.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void entity_projectile_nail_update(entity_t * e) {
}

void entity_projectile_nail_did_collide(entity_t * e, int axis) {
// silence unused
axis = axis;

e->_kill(e);
e->_play_sound(e, sfx_nailgun_hit);
e->_spawn_particles(e, 2, 80, ENTITY_ID_PARTICLE_SLUG, 0.4);
Expand All @@ -49,7 +52,7 @@ void entity_projectile_nail_did_collide(entity_t * e, int axis) {
.rgba[3] = 0x01,
},
};
entity_t * tmplight = game_spawn_ng(&l);
entity_t * tmplight = game_spawn(&l);

tmplight->_expires = true;
tmplight->_die_at = game_time + 0.1;
Expand Down
5 changes: 4 additions & 1 deletion entity_projectile_plasma.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void entity_projectile_plasma_update(entity_t * e) {
}

void entity_projectile_plasma_did_collide(entity_t * e, int axis) {
// silence Wunused
axis = axis;

e->_kill(e);
e->_play_sound(e, sfx_nailgun_hit);
e->_spawn_particles(e, 2, 80, ENTITY_ID_PARTICLE_SLUG, 0.4);
Expand All @@ -52,7 +55,7 @@ void entity_projectile_plasma_did_collide(entity_t * e, int axis) {
.rgba[3] = 0x05,
},
};
entity_t * tmplight = game_spawn_ng(&l);
entity_t * tmplight = game_spawn(&l);

tmplight->_expires = true;
tmplight->_die_at = game_time + 0.1;
Expand Down
Loading

0 comments on commit 0087ab9

Please sign in to comment.