|
|
@ -39,6 +39,7 @@ void world_load(const u_long *data, world_t *world) |
|
|
|
|
|
|
|
|
ps1bsp_header_t* header = (ps1bsp_header_t*)bytes; |
|
|
ps1bsp_header_t* header = (ps1bsp_header_t*)bytes; |
|
|
|
|
|
|
|
|
|
|
|
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_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); |
|
|
@ -203,6 +204,70 @@ 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) |
|
|
|
|
|
{ |
|
|
|
|
|
int p; |
|
|
|
|
|
|
|
|
|
|
|
if (!mem_checkprim(sizeof(POLY_GT4), face->numFaceVertices)) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
// Draw the face as a quad strip |
|
|
|
|
|
const STVECTOR *v0, *v1, *v2, *v3; |
|
|
|
|
|
const STVECTOR *head = vecs; |
|
|
|
|
|
const STVECTOR *tail = vecs + face->numFaceVertices; |
|
|
|
|
|
|
|
|
|
|
|
// Initialize the first two vertices |
|
|
|
|
|
v2 = --tail; |
|
|
|
|
|
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 |
|
|
|
|
|
u_char numQuads = (face->numFaceVertices - 1) / 2; |
|
|
|
|
|
for (u_char quadIdx = 0; quadIdx < numQuads; ++quadIdx) |
|
|
|
|
|
{ |
|
|
|
|
|
v0 = v2; |
|
|
|
|
|
v1 = v3; |
|
|
|
|
|
v2 = --tail; |
|
|
|
|
|
v3 = head++; |
|
|
|
|
|
|
|
|
|
|
|
// Naively draw the quad with GTE, nothing special or optimized about this |
|
|
|
|
|
gte_ldv3(v0, v1, v2); |
|
|
|
|
|
gte_rtpt(); // Rotation, translation, perspective projection |
|
|
|
|
|
|
|
|
|
|
|
// Average Z for depth sorting and culling |
|
|
|
|
|
gte_avsz3(); |
|
|
|
|
|
gte_stotz(&p); |
|
|
|
|
|
short depth = p >> 2; |
|
|
|
|
|
if (depth <= 0 || depth >= OTLEN) |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
// Draw a flat-shaded untextured colored quad |
|
|
|
|
|
POLY_GT4 *poly = (POLY_GT4*)mem_prim(sizeof(POLY_GT4)); |
|
|
|
|
|
setPolyGT4(poly); |
|
|
|
|
|
gte_stsxy0(&poly->x0); |
|
|
|
|
|
gte_stsxy1(&poly->x1); |
|
|
|
|
|
gte_stsxy2(&poly->x2); |
|
|
|
|
|
|
|
|
|
|
|
// Transform the fourth vertex to complete the quad |
|
|
|
|
|
gte_ldv0(v3); |
|
|
|
|
|
gte_rtps(); |
|
|
|
|
|
gte_stsxy(&poly->x3); |
|
|
|
|
|
|
|
|
|
|
|
// Texture UVs |
|
|
|
|
|
setUV4(poly, v0->u, v0->v, v1->u, v1->v, v2->u, v2->v, v3->u, v3->v); |
|
|
|
|
|
poly->clut = quake_clut; |
|
|
|
|
|
poly->tpage = tpage; |
|
|
|
|
|
|
|
|
|
|
|
// Vertex color lighting |
|
|
|
|
|
poly->r0 = poly->g0 = poly->b0 = (uint8_t)v0->pad; |
|
|
|
|
|
poly->r1 = poly->g1 = poly->b1 = (uint8_t)v1->pad; |
|
|
|
|
|
poly->r2 = poly->g2 = poly->b2 = (uint8_t)v2->pad; |
|
|
|
|
|
poly->r3 = poly->g3 = poly->b3 = (uint8_t)v3->pad; |
|
|
|
|
|
|
|
|
|
|
|
addPrim(curOT + depth, poly); |
|
|
|
|
|
++polyCount; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static INLINE short world_pointPlaneDist(const VECTOR *point, const ps1bsp_plane_t *plane) |
|
|
static INLINE short world_pointPlaneDist(const VECTOR *point, const ps1bsp_plane_t *plane) |
|
|
{ |
|
|
{ |
|
|
// Make use of axis-aligned planes to skip the need for a dot product |
|
|
// Make use of axis-aligned planes to skip the need for a dot product |
|
|
@ -237,22 +302,47 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face) |
|
|
if ((dot >= 0) ^ face->side) |
|
|
if ((dot >= 0) ^ face->side) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
if (0) |
|
|
|
|
|
{ |
|
|
|
|
|
// Draw untextured, vertex colored polygons |
|
|
SVECTOR *vecs = (SVECTOR*)(scratchpad + 256); |
|
|
SVECTOR *vecs = (SVECTOR*)(scratchpad + 256); |
|
|
|
|
|
|
|
|
// Copy this face's vertices into scratch RAM for fast reuse |
|
|
// Copy this face's vertices into scratch RAM for fast reuse |
|
|
// TODO: this is the main performance bottleneck right now! |
|
|
// TODO: this is the main performance bottleneck right now! |
|
|
ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex]; |
|
|
ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex]; |
|
|
for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex) |
|
|
|
|
|
|
|
|
SVECTOR *curVec = vecs; |
|
|
|
|
|
for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex, ++curVec) |
|
|
{ |
|
|
{ |
|
|
const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index]; |
|
|
const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index]; |
|
|
vecs[vertIdx] = *((SVECTOR*)vert); |
|
|
|
|
|
vecs[vertIdx].pad = faceVertex->light; |
|
|
|
|
|
|
|
|
*curVec = *((SVECTOR*)vert); |
|
|
|
|
|
curVec->pad = faceVertex->light; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (face->numFaceVertices == 3) // Special case: draw single triangles using the simplest method |
|
|
if (face->numFaceVertices == 3) // Special case: draw single triangles using the simplest method |
|
|
drawface_triangle_fan(face, vecs); |
|
|
drawface_triangle_fan(face, vecs); |
|
|
else |
|
|
else |
|
|
drawface_quad_strip(face, vecs); |
|
|
drawface_quad_strip(face, vecs); |
|
|
|
|
|
} |
|
|
|
|
|
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 = faceVertex->u + faceTexture->uoffs; |
|
|
|
|
|
curVec->v = faceVertex->v + faceTexture->voffs; |
|
|
|
|
|
curVec->pad = faceVertex->light; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
drawface_quad_strip_tex(face, vecs, 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) |
|
|
|