some more cleanup

This commit is contained in:
asrael 2026-04-15 00:27:16 -05:00
parent f4170614a7
commit 26e855369d
20 changed files with 22 additions and 41 deletions

View file

@ -2,6 +2,7 @@
#include <string.h>
#include "pxl8_bytes.h"
#include "pxl8_color.h"
#include "pxl8_io.h"
#include "pxl8_log.h"
@ -328,22 +329,6 @@ void demo3d_bsp_destroy(demo3d_bsp* bsp) {
memset(bsp, 0, sizeof(*bsp));
}
i32 demo3d_bsp_find_leaf(const demo3d_bsp* bsp, pxl8_vec3 pos) {
if (!bsp || bsp->num_nodes == 0) return -1;
i32 node_id = 0;
while (node_id >= 0) {
const demo3d_bsp_node* node = &bsp->nodes[node_id];
const demo3d_bsp_plane* plane = &bsp->planes[node->plane_id];
f32 dist = pxl8_vec3_dot(pos, plane->normal) - plane->dist;
node_id = node->children[dist < 0 ? 1 : 0];
}
return -(node_id + 1);
}
bool demo3d_bsp_is_leaf_visible(const demo3d_bsp* bsp, i32 leaf_from, i32 leaf_to) {
if (!bsp || !bsp->visdata || bsp->visdata_size == 0) return true;

View file

@ -157,6 +157,18 @@ static inline bool demo3d_bsp_get_edge_vertex(const demo3d_bsp* bsp, i32 surfedg
return *out_vert_idx < bsp->num_vertices;
}
static inline i32 demo3d_bsp_find_leaf(const demo3d_bsp* bsp, pxl8_vec3 pos) {
if (!bsp || bsp->num_nodes == 0) return -1;
i32 node_id = 0;
while (node_id >= 0) {
const demo3d_bsp_node* node = &bsp->nodes[node_id];
const demo3d_bsp_plane* plane = &bsp->planes[node->plane_id];
f32 dist = pxl8_vec3_dot(pos, plane->normal) - plane->dist;
node_id = node->children[dist < 0 ? 1 : 0];
}
return -(node_id + 1);
}
#ifdef __cplusplus
extern "C" {
#endif
@ -166,7 +178,6 @@ void demo3d_bsp_destroy(demo3d_bsp* bsp);
u32 demo3d_bsp_face_count(const demo3d_bsp* bsp);
pxl8_vec3 demo3d_bsp_face_normal(const demo3d_bsp* bsp, u32 face_id);
void demo3d_bsp_face_set_material(demo3d_bsp* bsp, u32 face_id, u16 material_id);
i32 demo3d_bsp_find_leaf(const demo3d_bsp* bsp, pxl8_vec3 pos);
bool demo3d_bsp_is_leaf_visible(const demo3d_bsp* bsp, i32 leaf_from, i32 leaf_to);
demo3d_bsp_lightmap demo3d_bsp_lightmap_mapped(u8 width, u8 height, u32 offset);
demo3d_bsp_lightmap demo3d_bsp_lightmap_uniform(u8 r, u8 g, u8 b);

View file

@ -2,13 +2,12 @@
#include "demo3d_bsp.h"
#include "pxl8_gfx.h"
#include "pxl8_mesh.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "pxl8_mesh.h"
typedef struct demo3d_bsp_render_state {
pxl8_gfx_material* materials;
pxl8_mesh* mesh;