diff --git a/world.c b/world.c index a73df94..146bf9c 100644 --- a/world.c +++ b/world.c @@ -54,7 +54,7 @@ static INLINE void drawface_triangle_fan(const ps1bsp_face_t *face, SVECTOR *vec { int p; - if (!mem_checkprim(sizeof(POLY_G3), face->numFaceVertices)) + if (!mem_checkprim(sizeof(POLY_G3), face->numFaceVertices - 2)) return; // Draw the face as a triangle fan @@ -94,7 +94,8 @@ static INLINE void drawface_triangle_strip(const ps1bsp_face_t *face, SVECTOR *v { int p; - if (!mem_checkprim(sizeof(POLY_G3), face->numFaceVertices)) + u_char numTris = face->numFaceVertices - 2; + if (!mem_checkprim(sizeof(POLY_G3), numTris)) return; // Draw the face as a triangle strip @@ -105,7 +106,6 @@ static INLINE void drawface_triangle_strip(const ps1bsp_face_t *face, SVECTOR *v v2 = head++; // Initialize first vertex to index 0 and set head to index 1 - u_char numTris = face->numFaceVertices - 2; for (u_char triIdx = 0; triIdx < numTris; ++triIdx) { if (reverse ^= 1) @@ -150,7 +150,8 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs) { int p; - if (!mem_checkprim(sizeof(POLY_G4), face->numFaceVertices)) + u_char numQuads = (face->numFaceVertices - 1) / 2; + if (!mem_checkprim(sizeof(POLY_G4), numQuads)) return; // Draw the face as a quad strip @@ -163,7 +164,6 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs) 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; @@ -208,7 +208,8 @@ static INLINE void drawface_quad_strip_tex(const ps1bsp_face_t *face, STVECTOR * { int p; - if (!mem_checkprim(sizeof(POLY_GT4), face->numFaceVertices)) + u_char numQuads = (face->numFaceVertices - 1) / 2; + if (!mem_checkprim(sizeof(POLY_GT4), numQuads)) return; // Draw the face as a quad strip @@ -221,7 +222,6 @@ static INLINE void drawface_quad_strip_tex(const ps1bsp_face_t *face, STVECTOR * 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;