Skip to content

Commit

Permalink
trim garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Oct 31, 2023
1 parent f31dbf9 commit 748dfa0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 114 deletions.
2 changes: 1 addition & 1 deletion c1k3-assets
Submodule c1k3-assets updated 1 files
+34,562 −11,120 blend/map3.gltf
9 changes: 0 additions & 9 deletions data.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,9 @@ const uint32_t data_sfx_shotgun_reload_len = audio_sfx_shotgun_reload_ogg_len;
const uint8_t * data_sfx_shotgun_shoot = audio_sfx_shotgun_shoot_ogg;
const uint32_t data_sfx_shotgun_shoot_len = audio_sfx_shotgun_shoot_ogg_len;

// const uint8_t * data_song = file_example_OOG_1MG_ogg;
// const uint32_t data_song_len = file_example_OOG_1MG_ogg_len;

const uint8_t * data_song = audio_song_ogg;
const uint32_t data_song_len = audio_song_ogg_len;

#include "maps.h"
// #include "assets/testmap/testmap.h"

const uint8_t * data_maps = maps;
const uint32_t data_maps_len = maps_len;

#include "map1.h"

const uint8_t * data_map1 = blend_map1_map;
Expand Down
3 changes: 0 additions & 3 deletions data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ typedef struct {
extern const png_bin_t * data_textures;
extern const uint32_t data_textures_len;

extern const uint8_t * data_maps;
extern const uint32_t data_maps_len;

extern const uint8_t * data_models;
extern const uint32_t data_models_len;

Expand Down
3 changes: 2 additions & 1 deletion entity_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void entity_player_init(entity_t * e, uint8_t p1, uint8_t p2) {
e->_weapon_index = 0;

// Map 1 needs some rotation of the starting look-at direction
e->_yaw += game_map_index * PI;
// e->_yaw += game_map_index * PI;

e->_bob = 0;

game_entity_player = e;
Expand Down
109 changes: 9 additions & 100 deletions map.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,118 +539,27 @@ void map_parse() {

// todo, be smarter
mpack_map_parse((char *)data_map1, data_map1_len);

const uint8_t * data = data_maps;

for(uint32_t i = 0; i < data_maps_len;) {

// push empty map, get pointer back
map_t * tmp_map = vector_push(map_data, &(map_t) {
0
});

uint32_t blocks_size = data[i] | (data[i+1] << 8);
i += 2;
// uint32_t blocks_size = data[i++] | (data[i++] << 8);
uint8_t * b = (uint8_t *)&data[i];
i += blocks_size;
uint8_t cm[((map_size * map_size * map_size) >> 3) * sizeof(uint8_t)] = {0};

vector * blocks = vector_init(sizeof(block_t));
uint32_t t = 0;

for(uint32_t j = 0; j < blocks_size;) {
if(b[j] == 255) {
j++;
t = b[j++];
}
uint32_t x = b[j++];
uint32_t y = b[j++];
uint32_t z = b[j++];
uint32_t sx = b[j++];
uint32_t sy = b[j++];
uint32_t sz = b[j++];

vector_push(blocks, &(block_t) {
.t = t,
.b = r_push_block(x << 5, y << 4, z << 5, sx << 5, sy << 4, sz << 5, t),
});

// The collision map is a bitmap; 8 x blocks per byte
for (uint32_t cz = z; cz < z + sz; cz++) {
for (uint32_t cy = y; cy < y + sy; cy++) {
for (uint32_t cx = x; cx < x + sx; cx++) {
cm[
(
cz * map_size * map_size +
cy * map_size +
cx
) >> 3
] |= 1 << (cx & 7);
}
}
}
}
// Slice of entity data; we parse it when we actually spawn
// the entities in map_init()
uint32_t num_entities = data[i] | (data[i+1] << 8);
i += 2;
// uint32_t num_entities = data[i++] | (data[i++] << 8);
uint8_t * e = (uint8_t *)(data + i);
uint32_t e_size = num_entities * 6;
i += e_size;

// set map
memcpy(tmp_map->cm, cm, ((map_size * map_size * map_size) >> 3) * sizeof(uint8_t));
tmp_map->e = e;
tmp_map->e_size = e_size;
tmp_map->blocks = blocks;
}

mpack_map_parse((char *)data_map3, data_map3_len);
}

void map_load (map_t * m) {
// todo, should this just be an index into a global map_collection_t?
map = m;

if (map->map_entities != NULL)
goto map_load_ng;
for (uint32_t i = 0; i < map->e_size;) {
void (*func)(entity_t *, vec3_t, uint8_t, uint8_t) = spawn_class[map->e[i++]];
int x = m->e[i++] * 32;
int y = m->e[i++] * 16;
int z = m->e[i++] * 32;
uint8_t p1 = m->e[i++];
uint8_t p2 = m->e[i++];
if (func == NULL)
continue;
game_spawn(
func,
(vec3_t) {
.x = x, .y = y, .z = z
},
p1,
p2,
NULL
);
}
// exit if old maps were used
return;

map_load_ng:
for (uint32_t i = 0; i < map->e_size; i++) {
entity_params_t * ep = vector_at(map->map_entities, i);
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;
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;

pos->x *= 32;
pos->y *= 16;
pos->z *= 32;

game_spawn_ng(ep);
game_spawn_ng(&ep);
}

}
Expand Down

0 comments on commit 748dfa0

Please sign in to comment.