diff --git a/ps1bsp.h b/ps1bsp.h index efa633f..0616ddf 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -30,7 +30,6 @@ typedef struct ps1bsp_dentry_t textures; ps1bsp_dentry_t vertices; - ps1bsp_dentry_t surfVertices; ps1bsp_dentry_t polygons; ps1bsp_dentry_t polyVertices; ps1bsp_dentry_t faces; @@ -57,13 +56,13 @@ typedef struct short pad; } ps1bsp_vertex_t; -// Texture UV and lighting data for a vertex on a particular surface. Can be shared between multiple polygons on the same surface. +// Texture UV and lighting data for a vertex on a particular polygon. typedef struct { unsigned short index; unsigned short light; // Can be made into u_char if we need to store more data; currently u_short for 32-bit alignment purposes unsigned short u, v; // Can be made into u_char if we need to store more data; currently u_short for 32-bit alignment purposes -} ps1bsp_surfvertex_t; +} ps1bsp_polyvertex_t; // Faces are broken up into one or more polygons, each of which can be drawn as a quad/triangle strip with a single texture. // This ahead-of-time tesselation is done to deal with the fact that the PS1 can't do texture wrapping, meaning tiling textures have to be broken up into separate polygons. diff --git a/test.ps1bsp b/test.ps1bsp index 9fb6515..60786f2 100755 Binary files a/test.ps1bsp and b/test.ps1bsp differ diff --git a/world.c b/world.c index c76ba2e..065d6a9 100644 --- a/world.c +++ b/world.c @@ -41,8 +41,8 @@ void world_load(const u_long *data, world_t *world) LOAD_CHUNK(ps1bsp_texture_t, world->textures, world->numTextures, bytes, header->textures); LOAD_CHUNK(ps1bsp_vertex_t, world->vertices, world->numVertices, bytes, header->vertices); - LOAD_CHUNK(ps1bsp_surfvertex_t, world->surfVertices, world->numSurfVertices, bytes, header->surfVertices); LOAD_CHUNK(ps1bsp_polygon_t, world->polygons, world->numPolygons, bytes, header->polygons); + LOAD_CHUNK(ps1bsp_polyvertex_t, world->polyVertices, world->numPolyVertices, bytes, header->polyVertices); LOAD_CHUNK(ps1bsp_face_t, world->faces, world->numFaces, bytes, header->faces); LOAD_CHUNK(ps1bsp_facevertex_t, world->faceVertices, world->numFaceVertices, bytes, header->faceVertices); LOAD_CHUNK(ps1bsp_plane_t, world->planes, world->numPlanes, bytes, header->planes); @@ -313,13 +313,13 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face) const ps1bsp_polygon_t* poly = &world->polygons[face->firstPolygon]; for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly) { - ps1bsp_surfvertex_t *surfVertex = &world->surfVertices[poly->firstPolyVertex]; + ps1bsp_polyvertex_t *polyVertex = &world->polyVertices[poly->firstPolyVertex]; SVECTOR *curVert = verts; - for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++surfVertex, ++curVert) + for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++polyVertex, ++curVert) { - const ps1bsp_vertex_t *vert = &world->vertices[surfVertex->index]; + const ps1bsp_vertex_t *vert = &world->vertices[polyVertex->index]; *curVert = *((SVECTOR*)vert); - curVert->pad = surfVertex->light; + curVert->pad = polyVertex->light; } if (poly->numPolyVertices == 3) @@ -336,62 +336,20 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face) const ps1bsp_polygon_t* poly = &world->polygons[face->firstPolygon]; for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly) { - ps1bsp_surfvertex_t *surfVertex = &world->surfVertices[poly->firstPolyVertex]; + ps1bsp_polyvertex_t *polyVertex = &world->polyVertices[poly->firstPolyVertex]; STVECTOR *curVert = verts; - for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++surfVertex, ++curVert) + for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++polyVertex, ++curVert) { - const ps1bsp_vertex_t *vert = &world->vertices[surfVertex->index]; + const ps1bsp_vertex_t *vert = &world->vertices[polyVertex->index]; *((SVECTOR*)curVert) = *((SVECTOR*)vert); - curVert->u = (u_short)surfVertex->u; - curVert->v = (u_short)surfVertex->v; - curVert->pad = surfVertex->light; + curVert->u = (u_short)polyVertex->u; + curVert->v = (u_short)polyVertex->v; + curVert->pad = polyVertex->light; } draw_quad_strip_tex(verts, poly->numPolyVertices, faceTexture->tpage); } } - - // if (!enableTexturing) - // { - // // Draw untextured, vertex colored polygons - // SVECTOR *vecs = (SVECTOR*)(scratchpad + 256); - - // // Copy this face's vertices into scratch RAM for fast reuse - // // TODO: this is the main performance bottleneck right now! - // ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex]; - // SVECTOR *curVec = vecs; - // for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex, ++curVec) - // { - // const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index]; - // *curVec = *((SVECTOR*)vert); - // curVec->pad = faceVertex->light; - // } - - // if (face->numFaceVertices == 3) // Special case: draw single triangles using the simplest method - // draw_triangle_fan(vecs, 3); - // else - // draw_quad_strip(vecs, face->numFaceVertices); - // } - // else - // { - // // Draw textured, vertex colored polygons - // STVECTOR *vecs = (STVECTOR*)(scratchpad + 256); - - // // Copy this face's vertices into scratch RAM for fast reuse - // ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex]; - // ps1bsp_texture_t *faceTexture = &world->textures[face->textureId]; - // STVECTOR *curVec = vecs; - // for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex, ++curVec) - // { - // const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index]; - // *((SVECTOR*)curVec) = *((SVECTOR*)vert); - // curVec->u = (u_short)faceVertex->u; - // curVec->v = (u_short)faceVertex->v; - // curVec->pad = faceVertex->light; - // } - - // draw_quad_strip_tex(vecs, face->numFaceVertices, faceTexture->tpage); - // } } static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs) diff --git a/world.h b/world.h index d886009..e8d9d2c 100644 --- a/world.h +++ b/world.h @@ -11,12 +11,12 @@ typedef struct u_short numVertices; ps1bsp_vertex_t *vertices; - u_short numSurfVertices; - ps1bsp_surfvertex_t *surfVertices; - u_short numPolygons; ps1bsp_polygon_t *polygons; + u_short numPolyVertices; + ps1bsp_polyvertex_t *polyVertices; + u_short numFaces; ps1bsp_face_t *faces;