Browse Source

Reworked PS1BSP format to use dentry-style header info

tess_experiment
Nico de Poel 3 years ago
parent
commit
0e1bb7a5bf
  1. 48
      ps1bsp.h
  2. BIN
      test.ps1bsp
  3. 19
      world.c
  4. 8
      world.h

48
ps1bsp.h

@ -18,12 +18,23 @@ Probable rendering process:
Note: we may not have to calculate average depth for BSP polygons, as the leafs already provide an ordering, and leafs are convex so there is no need to sort the polygons within.
We do however need some kind of depth value per leaf to insert alias models at the correct positions in the ordering table.
*/
typedef struct
{
unsigned int offset;
unsigned int size;
} ps1bsp_dentry_t;
typedef struct
{
unsigned short numVertices;
unsigned short numFaceVertices;
unsigned short numFaces;
u_short version;
ps1bsp_dentry_t vertices;
ps1bsp_dentry_t faces;
ps1bsp_dentry_t faceVertices;
ps1bsp_dentry_t planes;
ps1bsp_dentry_t nodes;
ps1bsp_dentry_t leafs;
ps1bsp_dentry_t leafFaces;
} ps1bsp_header_t;
typedef struct
@ -63,6 +74,32 @@ typedef struct
unsigned char numFaceVertices;
} ps1bsp_face_t;
typedef struct
{
SVECTOR normal;
u_short dist;
} ps1bsp_plane_t;
typedef struct
{
u_int planeId;
u_short front;
u_short back;
// TODO: add bounding box for frustum culling
// TODO: not sure if face list is needed here
} ps1bsp_node_t;
typedef struct
{
int type;
int vislist;
// TODO: add bounding box for frustum culing
u_short firstLeafFace;
u_short numLeafFaces;
} ps1bsp_leaf_t;
// Pre-parsed and encoded entity data (this runs the risk of becoming too bloated)
typedef struct
{
@ -79,11 +116,6 @@ typedef struct
char message[];
} ps1bsp_message_t;
typedef struct
{
// TODO: add floating origin position, so face vertices can be moved relative to the camera position
} ps1bsp_leaf_t;
#ifdef __cplusplus
}
#endif

BIN
test.ps1bsp

19
world.c

@ -25,17 +25,16 @@ void world_load(const u_long *data, world_t *world)
{
const char *bytes = (const char*)data;
world->header = (ps1bsp_header_t*)bytes;
bytes += sizeof(ps1bsp_header_t);
ps1bsp_header_t* header = (ps1bsp_header_t*)bytes;
world->vertices = (ps1bsp_vertex_t*)bytes;
bytes += sizeof(ps1bsp_vertex_t) * world->header->numVertices;
world->vertices = (ps1bsp_vertex_t*)(bytes + header->vertices.offset);
world->numVertices = header->vertices.size / sizeof(ps1bsp_vertex_t);
world->faceVertices = (ps1bsp_facevertex_t*)bytes;
bytes += sizeof(ps1bsp_facevertex_t) * world->header->numFaceVertices;
world->faces = (ps1bsp_face_t*)(bytes + header->faces.offset);
world->numFaces = header->faces.size / sizeof(ps1bsp_face_t);
world->faces = (ps1bsp_face_t*)bytes;
bytes += sizeof(ps1bsp_face_t) * world->header->numFaces;
world->faceVertices = (ps1bsp_facevertex_t*)(bytes + header->faceVertices.offset);
world->numFaceVertices = header->faceVertices.size / sizeof(ps1bsp_facevertex_t);
}
static INLINE void drawface_triangle_fan(const ps1bsp_face_t *face, SVECTOR *vecs)
@ -185,7 +184,7 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs)
if (depth <= 0 || depth >= OTLEN)
continue;
// Draw a flat-shaded untextured colored triangle
// Draw a flat-shaded untextured colored quad
POLY_G4 *poly = (POLY_G4*)mem_prim(sizeof(POLY_G4));
if (poly == NULL)
break;
@ -218,7 +217,7 @@ void world_draw(const world_t *world)
gte_SetRotMatrix(&vp_matrix);
gte_SetTransMatrix(&vp_matrix);
for (int faceIdx = 0; faceIdx < world->header->numFaces; ++faceIdx)
for (int faceIdx = 0; faceIdx < world->numFaces; ++faceIdx)
{
const ps1bsp_face_t *face = &world->faces[faceIdx];
const CVECTOR *col = &colors[faceIdx % numColors];

8
world.h

@ -5,10 +5,14 @@
typedef struct
{
ps1bsp_header_t *header;
u_short numVertices;
ps1bsp_vertex_t *vertices;
ps1bsp_facevertex_t *faceVertices;
u_short numFaces;
ps1bsp_face_t *faces;
u_short numFaceVertices;
ps1bsp_facevertex_t *faceVertices;
} world_t;
void world_load(const u_long *data, world_t *world);

Loading…
Cancel
Save