Browse Source

Provide some additional data in the PS1 BSP file, including linked list pointers for leaf-based polygon sorting

master
Nico de Poel 3 years ago
parent
commit
fb66f93b46
  1. 12
      bsp.h
  2. 7
      main.cpp
  3. 31
      ps1bsp.h

12
bsp.h

@ -122,6 +122,16 @@ typedef struct BBoxShort // Bounding Box, Short values
short min[3]; // minimum values of X,Y,Z short min[3]; // minimum values of X,Y,Z
short max[3]; // maximum values of X,Y,Z short max[3]; // maximum values of X,Y,Z
vec3_t getMins() const
{
return Vec3(min[0], min[1], min[2]);
}
vec3_t getMaxs() const
{
return Vec3(max[0], max[1], max[2]);
}
vec3_t getCenter() const vec3_t getCenter() const
{ {
return vec3_t( return vec3_t(
@ -134,7 +144,7 @@ typedef struct BBoxShort // Bounding Box, Short values
SVECTOR toBoundingSphere() const SVECTOR toBoundingSphere() const
{ {
Vec3 center = getCenter(); Vec3 center = getCenter();
Vec3 extents = Vec3(max[0], max[1], max[2]) - center;
Vec3 extents = getMaxs() - center;
SVECTOR sphere = center.convertWorldPosition(); SVECTOR sphere = center.convertWorldPosition();
sphere.pad = (short)(extents.magnitude() * 4); sphere.pad = (short)(extents.magnitude() * 4);

7
main.cpp

@ -181,6 +181,8 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
outPoly.numPolyVertices = (unsigned short)(outPolyVertices.size() - outPoly.firstPolyVertex); outPoly.numPolyVertices = (unsigned short)(outPolyVertices.size() - outPoly.firstPolyVertex);
outPolygons.push_back(outPoly); outPolygons.push_back(outPoly);
outFace->totalQuads += (outPoly.numPolyVertices - 1) / 2;
} }
// TODO: calculate average face lighting * color from texture data // TODO: calculate average face lighting * color from texture data
@ -250,12 +252,13 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
dleaf_t* leaf = &world->leaves[leafIdx]; dleaf_t* leaf = &world->leaves[leafIdx];
ps1bsp_leaf_t outLeaf = { 0 }; ps1bsp_leaf_t outLeaf = { 0 };
outLeaf.type = leaf->type;
outLeaf.type = (short)leaf->type;
outLeaf.vislist = leaf->vislist; outLeaf.vislist = leaf->vislist;
outLeaf.firstLeafFace = leaf->lface_id; outLeaf.firstLeafFace = leaf->lface_id;
outLeaf.numLeafFaces = leaf->lface_num; outLeaf.numLeafFaces = leaf->lface_num;
outLeaf.boundingSphere = leaf->bound.toBoundingSphere();
outLeaf.mins = leaf->bound.getMins().convertWorldPosition();
outLeaf.maxs = leaf->bound.getMaxs().convertWorldPosition();
outLeaves.push_back(outLeaf); outLeaves.push_back(outLeaf);
} }

31
ps1bsp.h

@ -84,23 +84,13 @@ typedef struct
unsigned char b : 5; unsigned char b : 5;
} ps1bsp_facevertex_t; } ps1bsp_facevertex_t;
#define SURF_PLANEBACK 0x2
#define SURF_DRAWSKY 0x4
#define SURF_DRAWSPRITE 0x8
#define SURF_DRAWTURB 0x10
#define SURF_DRAWTILED 0x20
#define SURF_DRAWBACKGROUND 0x40
#define SURF_UNDERWATER 0x80
#define SURF_NOTEXTURE 0x100
#define SURF_DRAWFENCE 0x200
#define SURF_DRAWLAVA 0x400
#define SURF_DRAWSLIME 0x800
#define SURF_DRAWTELE 0x1000
#define SURF_DRAWWATER 0x2000
#define SURF_DRAWSKY 0x2
#define SURF_DRAWTURB 0x4
#define SURF_DRAWWATER 0x8
// High quality: Face -> polygons -> polygon vertex indices (index + UV + light) -> vertices // High quality: Face -> polygons -> polygon vertex indices (index + UV + light) -> vertices
// Low quality: Face -> face vertex indices (index + color) -> vertices // Low quality: Face -> face vertex indices (index + color) -> vertices
typedef struct
typedef struct ps1bsp_face_s
{ {
unsigned short planeId; unsigned short planeId;
unsigned char side; unsigned char side;
@ -108,18 +98,20 @@ typedef struct
// Used for high-quality tesselated textured drawing // Used for high-quality tesselated textured drawing
unsigned short firstPolygon; unsigned short firstPolygon;
unsigned char numPolygons; unsigned char numPolygons;
unsigned char totalQuads;
// Used for low-quality untextured vertex colored drawing // Used for low-quality untextured vertex colored drawing
unsigned short firstFaceVertex; unsigned short firstFaceVertex;
unsigned char numFaceVertices; unsigned char numFaceVertices;
unsigned char textureId; unsigned char textureId;
unsigned short flags;
unsigned char flags;
// Used for backface culling // Used for backface culling
SVECTOR center; SVECTOR center;
// Run-time data // Run-time data
const struct ps1bsp_face_s* nextFace; // For chaining faces in drawing order
u_long drawFrame; // Which frame was this face last drawn on? Used to check if this face should be drawn. u_long drawFrame; // Which frame was this face last drawn on? Used to check if this face should be drawn.
} ps1bsp_face_t; } ps1bsp_face_t;
@ -138,19 +130,18 @@ typedef struct
SVECTOR boundingSphere; SVECTOR boundingSphere;
} ps1bsp_node_t; } ps1bsp_node_t;
typedef struct
typedef struct ps1bsp_leaf_s
{ {
int type;
short type;
int vislist; int vislist;
SVECTOR boundingSphere;
SVECTOR mins, maxs;
u_short firstLeafFace; u_short firstLeafFace;
u_short numLeafFaces; u_short numLeafFaces;
// Run-time data // Run-time data
u_short nextLeaf; // For chaining leafs in drawing order
u_short leafDepth; // At what depth the leaf's faces should be placed in the ordering table
const struct ps1bsp_leaf_s* nextLeaf; // For chaining leafs in drawing order
} ps1bsp_leaf_t; } ps1bsp_leaf_t;
// Pre-parsed and encoded entity data (this runs the risk of becoming too bloated) // Pre-parsed and encoded entity data (this runs the risk of becoming too bloated)

Loading…
Cancel
Save