Browse Source

Write face vertex indices to output file instead of triangle data, which takes up less space and allows the PS1 code to decide how to draw the primitives.

master
Nico de Poel 3 years ago
parent
commit
ba68bc128e
  1. 16
      main.cpp
  2. 9
      ps1bsp.h

16
main.cpp

@ -211,6 +211,9 @@ int process_faces(const world_t* world)
{ {
face_t* face = &world->faces[faceIdx]; face_t* face = &world->faces[faceIdx];
ps1bsp_face_t outFace = { 0 };
outFace.firstVertexIndex = faceVertIndices.size();
// Traverse the list of face edges to collect all of the face's vertices // Traverse the list of face edges to collect all of the face's vertices
for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx) for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx)
{ {
@ -223,9 +226,6 @@ int process_faces(const world_t* world)
faceVertIndices.push_back(vertIndex); faceVertIndices.push_back(vertIndex);
} }
ps1bsp_face_t outFace = { 0 };
outFace.firstTriangleId = outTriangles.size();
//printf("Face %d: %d vertices\n", faceIdx, faceVerts.size()); //printf("Face %d: %d vertices\n", faceIdx, faceVerts.size());
// Triangulate face into polygons (triangle fan, the naive method) // Triangulate face into polygons (triangle fan, the naive method)
@ -240,19 +240,17 @@ int process_faces(const world_t* world)
outTriangles.push_back(outTriangle); outTriangles.push_back(outTriangle);
} }
outFace.numTriangles = outTriangles.size() - outFace.firstTriangleId;
outFace.numVertices = faceVertIndices.size() - outFace.firstVertexIndex;
outFaces.push_back(outFace); outFaces.push_back(outFace);
faceVertIndices.clear();
} }
// Write triangle and face data to file // Write triangle and face data to file
fwrite(outTriangles.data(), sizeof(ps1bsp_triangle_t), outTriangles.size(), fbsp);
fwrite(faceVertIndices.data(), sizeof(unsigned short), faceVertIndices.size(), fbsp);
fwrite(outFaces.data(), sizeof(ps1bsp_face_t), outFaces.size(), fbsp); fwrite(outFaces.data(), sizeof(ps1bsp_face_t), outFaces.size(), fbsp);
// Update header information // Update header information
outHeader.numVertices = world->numVertices; outHeader.numVertices = world->numVertices;
outHeader.numTriangles = outTriangles.size();
outHeader.numFaceVertIndices = faceVertIndices.size();
outHeader.numFaces = outFaces.size(); outHeader.numFaces = outFaces.size();
// Write final header // Write final header
@ -260,7 +258,7 @@ int process_faces(const world_t* world)
fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp); fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp);
fclose(fbsp); fclose(fbsp);
printf("PS1BSP: wrote %d vertices, %d triangles, %d faces\n", outHeader.numVertices, outHeader.numTriangles, outHeader.numFaces);
printf("PS1BSP: wrote %d vertices, %d indices, %d faces\n", outHeader.numVertices, outHeader.numFaceVertIndices, outHeader.numFaces);
return 1; return 1;
} }

9
ps1bsp.h

@ -22,7 +22,7 @@ Probable rendering process:
typedef struct typedef struct
{ {
unsigned short numVertices; unsigned short numVertices;
unsigned short numTriangles;
unsigned short numFaceVertIndices;
unsigned short numFaces; unsigned short numFaces;
} ps1bsp_header_t; } ps1bsp_header_t;
@ -62,11 +62,8 @@ typedef struct
typedef struct typedef struct
{ {
unsigned short firstTriangleId; // TODO: could also just do first-index, num-indices here. No real need for a triangle_t struct.
unsigned short numTriangles;
unsigned short firstQuadId; // For if/when we decide to add quads to the mix
unsigned short numQuads;
unsigned short firstVertexIndex;
unsigned short numVertices;
} ps1bsp_face_t; } ps1bsp_face_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