pxl8/src/bsp/pxl8_bsp.h

152 lines
3.2 KiB
C
Raw Normal View History

2025-10-07 10:32:48 -05:00
#pragma once
#include "pxl8_math.h"
#include "pxl8_types.h"
typedef struct pxl8_bsp_edge {
u16 vertex[2];
} pxl8_bsp_edge;
typedef struct pxl8_bsp_face {
u32 first_edge;
u32 lightmap_offset;
u16 num_edges;
u16 plane_id;
u16 side;
u8 styles[4];
2026-01-21 23:19:50 -06:00
u16 material_id;
pxl8_vec3 aabb_min;
pxl8_vec3 aabb_max;
2025-10-07 10:32:48 -05:00
} pxl8_bsp_face;
typedef struct pxl8_bsp_leaf {
u8 ambient_level[4];
i32 contents;
u16 first_marksurface;
i16 maxs[3];
i16 mins[3];
u16 num_marksurfaces;
i32 visofs;
} pxl8_bsp_leaf;
typedef struct pxl8_bsp_model {
i32 first_face;
i32 headnode[4];
f32 maxs[3];
f32 mins[3];
i32 num_faces;
pxl8_vec3 origin;
i32 visleafs;
} pxl8_bsp_model;
2025-11-27 15:48:11 -06:00
typedef struct pxl8_bsp_node {
i32 children[2];
u16 first_face;
i16 maxs[3];
i16 mins[3];
u16 num_faces;
u32 plane_id;
} pxl8_bsp_node;
typedef struct pxl8_bsp_plane {
f32 dist;
pxl8_vec3 normal;
i32 type;
} pxl8_bsp_plane;
typedef struct pxl8_bsp_vertex {
pxl8_vec3 position;
} pxl8_bsp_vertex;
typedef struct pxl8_bsp_lightmap {
u8 color[3];
u8 height;
u32 offset;
u8 width;
} pxl8_bsp_lightmap;
typedef struct pxl8_bsp_lightmap_sample {
u8 b;
u8 g;
u8 r;
} pxl8_bsp_lightmap_sample;
typedef struct pxl8_bsp_pvs {
u8* data;
u32 size;
} pxl8_bsp_pvs;
2026-01-21 23:19:50 -06:00
typedef struct pxl8_bsp_portal {
f32 x0, z0;
f32 x1, z1;
u32 target_leaf;
} pxl8_bsp_portal;
typedef struct pxl8_bsp_cell_portals {
pxl8_bsp_portal portals[4];
u8 num_portals;
} pxl8_bsp_cell_portals;
2025-10-07 10:32:48 -05:00
typedef struct pxl8_bsp {
2026-01-21 23:19:50 -06:00
pxl8_bsp_cell_portals* cell_portals;
2025-10-07 10:32:48 -05:00
pxl8_bsp_edge* edges;
pxl8_bsp_face* faces;
pxl8_bsp_leaf* leafs;
u8* lightdata;
pxl8_bsp_lightmap* lightmaps;
2025-10-07 10:32:48 -05:00
u16* marksurfaces;
pxl8_bsp_model* models;
pxl8_bsp_node* nodes;
pxl8_bsp_plane* planes;
i32* surfedges;
u32* vertex_lights;
2025-10-07 10:32:48 -05:00
pxl8_bsp_vertex* vertices;
u8* visdata;
u32 lightdata_size;
2026-01-21 23:19:50 -06:00
u32 num_cell_portals;
2025-10-07 10:32:48 -05:00
u32 num_edges;
u32 num_faces;
u32 num_leafs;
u32 num_lightmaps;
2025-10-07 10:32:48 -05:00
u32 num_marksurfaces;
u32 num_models;
u32 num_nodes;
u32 num_planes;
u32 num_surfedges;
u32 num_vertex_lights;
2025-10-07 10:32:48 -05:00
u32 num_vertices;
u32 visdata_size;
} pxl8_bsp;
#ifdef __cplusplus
extern "C" {
#endif
2026-01-25 09:26:30 -06:00
pxl8_bsp_pvs pxl8_bsp_decompress_pvs(const pxl8_bsp* bsp, i32 leaf);
2025-10-07 10:32:48 -05:00
void pxl8_bsp_destroy(pxl8_bsp* bsp);
2026-01-25 09:26:30 -06:00
u32 pxl8_bsp_face_count(const pxl8_bsp* bsp);
pxl8_vec3 pxl8_bsp_face_normal(const pxl8_bsp* bsp, u32 face_id);
void pxl8_bsp_face_set_material(pxl8_bsp* bsp, u32 face_id, u16 material_id);
2025-10-07 10:32:48 -05:00
i32 pxl8_bsp_find_leaf(const pxl8_bsp* bsp, pxl8_vec3 pos);
bool pxl8_bsp_is_leaf_visible(const pxl8_bsp* bsp, i32 leaf_from, i32 leaf_to);
2026-01-25 09:26:30 -06:00
pxl8_bsp_lightmap pxl8_bsp_lightmap_mapped(u8 width, u8 height, u32 offset);
pxl8_bsp_lightmap pxl8_bsp_lightmap_uniform(u8 r, u8 g, u8 b);
pxl8_result pxl8_bsp_load(const char* path, pxl8_bsp* bsp);
void pxl8_bsp_pvs_destroy(pxl8_bsp_pvs* pvs);
bool pxl8_bsp_pvs_is_visible(const pxl8_bsp_pvs* pvs, i32 leaf);
u8 pxl8_bsp_light_at(const pxl8_bsp* bsp, f32 x, f32 y, f32 z, u8 ambient);
2026-01-25 09:26:30 -06:00
pxl8_bsp_lightmap_sample pxl8_bsp_sample_lightmap(const pxl8_bsp* bsp, u32 face_idx, f32 u, f32 v);
2025-10-07 10:32:48 -05:00
#ifdef __cplusplus
}
#endif