Skip to content

Commit

Permalink
more dead code elim
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Oct 31, 2023
1 parent 8d2259c commit 242f7a8
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 115 deletions.
25 changes: 0 additions & 25 deletions map.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,6 @@ constfunc map_constfunc_from_eid(entity_id_t eid) {
return map_entity_table[eid].constructor_func;
}

// todo, remove once levels have been reproduced
void (*spawn_class[])(entity_t *, vec3_t, uint8_t, uint8_t) = {
/* 00 */ entity_player_constructor,
/* 01 */ entity_enemy_grunt_constructor,
/* 02 */ entity_enemy_enforcer_constructor,
/* 03 */ entity_enemy_ogre_constructor,
/* 04 */ entity_enemy_zombie_constructor,
/* 05 */ entity_enemy_hound_constructor,
/* 06 */ entity_pickup_nailgun_constructor,
/* 07 */ entity_pickup_grenadelauncher_constructor,
/* 08 */ entity_pickup_health_constructor,
/* 09 */ entity_pickup_nails_constructor,
/* 10 */ entity_pickup_grenades_constructor,
/* 11 */ entity_barrel_constructor,
/* 12 */ entity_light_constructor,
/* 13 */ entity_trigger_level_constructor,
/* 14 */ entity_door_constructor,
/* 15 */ entity_pickup_key_constructor,
/* 16 */ entity_torch_constructor,
};

ref_entt_t * map_ref_entt_from_eid(entity_id_t eid) {
if(eid < 0 || eid > __ENTITY_ID_END) {
fprintf(stderr, "eid not found: %d\n", eid);
Expand Down Expand Up @@ -241,8 +220,6 @@ vector * map_get_entity_kv(mpack_node_t n) {
mpack_node_t v = mpack_node_map_value_at(n, i);
if(mpack_node_type(k) != mpack_type_str || mpack_node_type(v) != mpack_type_str)
return NULL;
size_t klen = mpack_node_strlen(k);
size_t vlen = mpack_node_strlen(v);
entity_extra_params_t tmpx = { 0 };
strncpy(tmpx.k, mpack_node_str(k), mpack_node_strlen(k));
strncpy(tmpx.v, mpack_node_str(v), mpack_node_strlen(v));
Expand Down Expand Up @@ -363,10 +340,8 @@ void mpack_map_parse(const char * data, const size_t data_len) {
float (*frames)[frame_arr_len][tmp_entt.vert_len][3] = calloc(1, sizeof(*frames));
for(size_t fi = 0; fi < frame_arr_len; fi++) {
mpack_node_t frame_vert_arr = mpack_node_array_at(frame_arr, fi);
size_t fva_len = mpack_node_array_length(frame_vert_arr);
for (size_t vi = 0; vi < tmp_entt.vert_len; vi++) {
mpack_node_t frame_vert_xyz_arr = mpack_node_array_at(frame_vert_arr, vi);
size_t fvax_len = mpack_node_array_length(frame_vert_xyz_arr);
(*frames)[fi][vi][0] = mpack_node_float(mpack_node_array_at(frame_vert_xyz_arr, 0));
(*frames)[fi][vi][1] = mpack_node_float(mpack_node_array_at(frame_vert_xyz_arr, 1));
(*frames)[fi][vi][2] = mpack_node_float(mpack_node_array_at(frame_vert_xyz_arr, 2));
Expand Down
89 changes: 0 additions & 89 deletions model.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,95 +8,6 @@
#include "render.h"
#include "vector.h"

// todo, return different type, like entity_model/parsed_model
model_t model_load(uint8_t * data, vec3_t scale) {
uint32_t j = 0;
uint8_t num_frames = data[j++];
uint8_t num_vertices = data[j++];
uint8_t num_indices = data[j++];
float vertices[num_vertices * num_frames * 3];
uint8_t indices[num_indices * 3];

int index_increment = 0;

int min_x = 16;
int max_x = -16;
int min_y = 16;
int max_y = -16;

for (uint32_t i = 0; i < num_vertices * num_frames * 3; i += 3) {
vertices[i] = (data[j++] - 15) * scale.x;
vertices[i+1] = (data[j++] - 15) * scale.y;
vertices[i+2] = (data[j++] - 15) * scale.z;

// Find min/max only for the first frame
if (i < num_vertices * 3) {
min_x = min(min_x, vertices[i]);
max_x = max(max_x, vertices[i]);
min_y = min(min_y, vertices[i+1]);
max_y = max(max_y, vertices[i+1]);
}
}

// Load indices, 1x 2bit increment, 2x 7bit absolute
for (uint32_t i = 0; i < num_indices * 3; i += 3) {
index_increment += data[j++];
indices[i] = index_increment;
indices[i+1] = data[j++];
indices[i+2] = data[j++];
}

// UV coords in texture space and width/height as fraction of model size
float uf = 1.0f / (float)(max_x - min_x);
float u = -min_x * uf;
float vf = -1.0f / (float)(max_y - min_y);
float v = max_y * vf;

model_t out = {0};
// todo, junk
out.data = data;
out.nv = num_indices * 3;

for (uint32_t frame_index = 0; frame_index < num_frames; frame_index++) {
out.frame_len++;
out.frames = realloc(out.frames, sizeof(uint32_t) * out.frame_len);
// todo, some weirdass alternative to pointers??
out.frames[out.frame_len - 1] = r_num_verts;

uint32_t vertex_offset = frame_index * num_vertices * 3;
for (uint32_t i = 0; i < num_indices * 3; i += 3) {

vec3_t mv[3];

typedef struct {
float u;
float v;
} uv_t;

uv_t uv[3];
for (uint32_t face_vertex = 0; face_vertex < 3; face_vertex++) {
uint32_t idx = indices[i + face_vertex] * 3;
mv[face_vertex] = vec3(
vertices[vertex_offset + idx + 0],
vertices[vertex_offset + idx + 1],
vertices[vertex_offset + idx + 2]
);
uv[face_vertex] = (uv_t) {
.u = vertices[idx + 0] * uf + u,
.v = vertices[idx + 1] * vf + v
};
}

vec3_t n = vec3_face_normal(mv[2], mv[1], mv[0]);
r_push_vert(mv[2], n, uv[2].u, uv[2].v);
r_push_vert(mv[1], n, uv[1].u, uv[1].v);
r_push_vert(mv[0], n, uv[0].u, uv[0].v);
}
}

return out;
}

vector * model_load_ng(void * void_verts, uint32_t frame_len, uint32_t vert_len, float * u, float * v) {
// todo, scale??
vector * frame_ids = vector_init(sizeof(uint32_t));
Expand Down
1 change: 0 additions & 1 deletion model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typedef struct {
uint32_t nv;
} model_ng_t;

model_t model_load(uint8_t * data, vec3_t scale);
vector * model_load_ng(void * void_verts, uint32_t frame_len, uint32_t vert_len, float * u, float * v);
void model_quit();

Expand Down

0 comments on commit 242f7a8

Please sign in to comment.