|
|
@ -41,6 +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_texture_t, world->textures, world->numTextures, bytes, header->textures); |
|
|
LOAD_CHUNK(ps1bsp_vertex_t, world->vertices, world->numVertices, bytes, header->vertices); |
|
|
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_face_t, world->faces, world->numFaces, bytes, header->faces); |
|
|
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_facevertex_t, world->faceVertices, world->numFaceVertices, bytes, header->faceVertices); |
|
|
LOAD_CHUNK(ps1bsp_plane_t, world->planes, world->numPlanes, bytes, header->planes); |
|
|
LOAD_CHUNK(ps1bsp_plane_t, world->planes, world->numPlanes, bytes, header->planes); |
|
|
@ -50,20 +52,20 @@ void world_load(const u_long *data, world_t *world) |
|
|
LOAD_CHUNK(u_char, world->visData, world->numVisData, bytes, header->visData); |
|
|
LOAD_CHUNK(u_char, world->visData, world->numVisData, bytes, header->visData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static INLINE void drawface_triangle_fan(const ps1bsp_face_t *face, SVECTOR *vecs) |
|
|
|
|
|
|
|
|
static INLINE void draw_triangle_fan(SVECTOR *verts, u_char numVerts) |
|
|
{ |
|
|
{ |
|
|
int p; |
|
|
int p; |
|
|
|
|
|
|
|
|
if (!mem_checkprim(sizeof(POLY_G3), face->numFaceVertices - 2)) |
|
|
|
|
|
|
|
|
if (!mem_checkprim(sizeof(POLY_G3), numVerts - 2)) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
// Draw the face as a triangle fan |
|
|
// Draw the face as a triangle fan |
|
|
u_char maxVert = face->numFaceVertices - 1; |
|
|
|
|
|
|
|
|
u_char maxVert = numVerts - 1; |
|
|
for (int vertIdx = 1; vertIdx < maxVert; ++vertIdx) |
|
|
for (int vertIdx = 1; vertIdx < maxVert; ++vertIdx) |
|
|
{ |
|
|
{ |
|
|
const SVECTOR *v0 = &vecs[0]; |
|
|
|
|
|
const SVECTOR *v1 = &vecs[vertIdx]; |
|
|
|
|
|
const SVECTOR *v2 = &vecs[vertIdx + 1]; |
|
|
|
|
|
|
|
|
const SVECTOR *v0 = &verts[0]; |
|
|
|
|
|
const SVECTOR *v1 = &verts[vertIdx]; |
|
|
|
|
|
const SVECTOR *v2 = &verts[vertIdx + 1]; |
|
|
|
|
|
|
|
|
// Naively draw the triangle with GTE, nothing special or optimized about this |
|
|
// Naively draw the triangle with GTE, nothing special or optimized about this |
|
|
gte_ldv3(v0, v1, v2); |
|
|
gte_ldv3(v0, v1, v2); |
|
|
@ -90,18 +92,18 @@ static INLINE void drawface_triangle_fan(const ps1bsp_face_t *face, SVECTOR *vec |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static INLINE void drawface_triangle_strip(const ps1bsp_face_t *face, SVECTOR *vecs) |
|
|
|
|
|
|
|
|
static INLINE void draw_triangle_strip(SVECTOR *verts, u_char numVerts) |
|
|
{ |
|
|
{ |
|
|
int p; |
|
|
int p; |
|
|
|
|
|
|
|
|
u_char numTris = face->numFaceVertices - 2; |
|
|
|
|
|
|
|
|
u_char numTris = numVerts - 2; |
|
|
if (!mem_checkprim(sizeof(POLY_G3), numTris)) |
|
|
if (!mem_checkprim(sizeof(POLY_G3), numTris)) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
// Draw the face as a triangle strip |
|
|
// Draw the face as a triangle strip |
|
|
const SVECTOR *v0, *v1, *v2; |
|
|
const SVECTOR *v0, *v1, *v2; |
|
|
const SVECTOR *head = vecs; |
|
|
|
|
|
const SVECTOR *tail = vecs + face->numFaceVertices; |
|
|
|
|
|
|
|
|
const SVECTOR *head = verts; |
|
|
|
|
|
const SVECTOR *tail = verts + numVerts; |
|
|
u_char reverse = 0; |
|
|
u_char reverse = 0; |
|
|
|
|
|
|
|
|
v2 = head++; // Initialize first vertex to index 0 and set head to index 1 |
|
|
v2 = head++; // Initialize first vertex to index 0 and set head to index 1 |
|
|
@ -146,18 +148,18 @@ static INLINE void drawface_triangle_strip(const ps1bsp_face_t *face, SVECTOR *v |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs) |
|
|
|
|
|
|
|
|
static INLINE void draw_quad_strip(SVECTOR *verts, u_char numVerts) |
|
|
{ |
|
|
{ |
|
|
int p; |
|
|
int p; |
|
|
|
|
|
|
|
|
u_char numQuads = (face->numFaceVertices - 1) / 2; |
|
|
|
|
|
|
|
|
u_char numQuads = (numVerts - 1) / 2; |
|
|
if (!mem_checkprim(sizeof(POLY_G4), numQuads)) |
|
|
if (!mem_checkprim(sizeof(POLY_G4), numQuads)) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
// Draw the face as a quad strip |
|
|
// Draw the face as a quad strip |
|
|
const SVECTOR *v0, *v1, *v2, *v3; |
|
|
const SVECTOR *v0, *v1, *v2, *v3; |
|
|
const SVECTOR *head = vecs; |
|
|
|
|
|
const SVECTOR *tail = vecs + face->numFaceVertices; |
|
|
|
|
|
|
|
|
const SVECTOR *head = verts; |
|
|
|
|
|
const SVECTOR *tail = verts + numVerts; |
|
|
|
|
|
|
|
|
// Initialize the first two vertices |
|
|
// Initialize the first two vertices |
|
|
v2 = --tail; |
|
|
v2 = --tail; |
|
|
@ -204,24 +206,24 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static INLINE void drawface_quad_strip_tex(const ps1bsp_face_t *face, STVECTOR *vecs, u_short tpage) |
|
|
|
|
|
|
|
|
static INLINE void draw_quad_strip_tex(STVECTOR *verts, u_char numVerts, u_short tpage) |
|
|
{ |
|
|
{ |
|
|
int p; |
|
|
int p; |
|
|
|
|
|
|
|
|
u_char numQuads = (face->numFaceVertices - 1) / 2; |
|
|
|
|
|
|
|
|
// Normally a quad strip would have (N-2)/2 quads, but we might end up with a sole triangle at the end which will be drawn as a collapsed quad |
|
|
|
|
|
u_char numQuads = (numVerts - 1) / 2; |
|
|
if (!mem_checkprim(sizeof(POLY_GT4), numQuads)) |
|
|
if (!mem_checkprim(sizeof(POLY_GT4), numQuads)) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
// Draw the face as a quad strip |
|
|
// Draw the face as a quad strip |
|
|
const STVECTOR *v0, *v1, *v2, *v3; |
|
|
const STVECTOR *v0, *v1, *v2, *v3; |
|
|
const STVECTOR *head = vecs; |
|
|
|
|
|
const STVECTOR *tail = vecs + face->numFaceVertices; |
|
|
|
|
|
|
|
|
const STVECTOR *head = verts; |
|
|
|
|
|
const STVECTOR *tail = verts + numVerts; |
|
|
|
|
|
|
|
|
// Initialize the first two vertices |
|
|
// Initialize the first two vertices |
|
|
v2 = --tail; |
|
|
v2 = --tail; |
|
|
v3 = head++; |
|
|
v3 = head++; |
|
|
|
|
|
|
|
|
// Normally a quad strip would have (N-2)/2 quads, but we might end up with a sole triangle at the end which will be drawn as a collapsed quad |
|
|
|
|
|
for (u_char quadIdx = 0; quadIdx < numQuads; ++quadIdx) |
|
|
for (u_char quadIdx = 0; quadIdx < numQuads; ++quadIdx) |
|
|
{ |
|
|
{ |
|
|
v0 = v2; |
|
|
v0 = v2; |
|
|
@ -307,46 +309,91 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face) |
|
|
if (!enableTexturing) |
|
|
if (!enableTexturing) |
|
|
{ |
|
|
{ |
|
|
// Draw untextured, vertex colored polygons |
|
|
// 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) |
|
|
|
|
|
|
|
|
SVECTOR *verts = (SVECTOR*)(scratchpad + 256); |
|
|
|
|
|
const ps1bsp_polygon_t* poly = &world->polygons[face->firstPolygon]; |
|
|
|
|
|
for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly) |
|
|
{ |
|
|
{ |
|
|
const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index]; |
|
|
|
|
|
*curVec = *((SVECTOR*)vert); |
|
|
|
|
|
curVec->pad = faceVertex->light; |
|
|
|
|
|
|
|
|
ps1bsp_surfvertex_t *surfVertex = &world->surfVertices[poly->firstPolyVertex]; |
|
|
|
|
|
SVECTOR *curVert = verts; |
|
|
|
|
|
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++surfVertex, ++curVert) |
|
|
|
|
|
{ |
|
|
|
|
|
const ps1bsp_vertex_t *vert = &world->vertices[surfVertex->index]; |
|
|
|
|
|
*curVert = *((SVECTOR*)vert); |
|
|
|
|
|
curVert->pad = surfVertex->light; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (face->numFaceVertices == 3) // Special case: draw single triangles using the simplest method |
|
|
|
|
|
drawface_triangle_fan(face, vecs); |
|
|
|
|
|
|
|
|
if (poly->numPolyVertices == 3) |
|
|
|
|
|
draw_triangle_fan(verts, 3); |
|
|
else |
|
|
else |
|
|
drawface_quad_strip(face, vecs); |
|
|
|
|
|
|
|
|
draw_quad_strip(verts, poly->numPolyVertices); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
// Draw textured, vertex colored polygons |
|
|
// 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]; |
|
|
|
|
|
|
|
|
STVECTOR *verts = (STVECTOR*)(scratchpad + 256); |
|
|
ps1bsp_texture_t *faceTexture = &world->textures[face->textureId]; |
|
|
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; |
|
|
|
|
|
|
|
|
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]; |
|
|
|
|
|
STVECTOR *curVert = verts; |
|
|
|
|
|
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++surfVertex, ++curVert) |
|
|
|
|
|
{ |
|
|
|
|
|
const ps1bsp_vertex_t *vert = &world->vertices[surfVertex->index]; |
|
|
|
|
|
*((SVECTOR*)curVert) = *((SVECTOR*)vert); |
|
|
|
|
|
curVert->u = (u_short)surfVertex->u; |
|
|
|
|
|
curVert->v = (u_short)surfVertex->v; |
|
|
|
|
|
curVert->pad = surfVertex->light; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
drawface_quad_strip_tex(face, vecs, faceTexture->tpage); |
|
|
|
|
|
|
|
|
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) |
|
|
static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs) |
|
|
{ |
|
|
{ |
|
|
u_long frameNum = time_getFrameNumber(); |
|
|
u_long frameNum = time_getFrameNumber(); |
|
|
|