diff --git a/ps1bsp.h b/ps1bsp.h index 574f551..0ce50fe 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -85,7 +85,8 @@ typedef struct typedef struct { SVECTOR normal; - int dist; + short dist; + short type; } ps1bsp_plane_t; typedef struct diff --git a/test.ps1bsp b/test.ps1bsp index 4d79a12..bca53a5 100755 Binary files a/test.ps1bsp and b/test.ps1bsp differ diff --git a/world.c b/world.c index d5bf477..dacd3f8 100644 --- a/world.c +++ b/world.c @@ -205,10 +205,22 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs) static INLINE short world_pointPlaneDist(const VECTOR *point, const ps1bsp_plane_t *plane) { - // TODO: can be optimized for axis-aligned planes, no need for a dot product there + // Make use of axis-aligned planes to skip the need for a dot product + if (plane->type < 3) + return (short)(((int*)point)[plane->type] - plane->dist); + return m_pointPlaneDist2(*point, plane->normal, plane->dist); } +static INLINE short world_planeDot(const SVECTOR *dir, const ps1bsp_plane_t *plane) +{ + // Make use of axis-aligned planes to skip the need for a dot product + if (plane->type < 3) + return ((short*)dir)[plane->type]; + + return m_dot12s(*dir, plane->normal); +} + static void world_drawface(const world_t *world, const ps1bsp_face_t *face) { // Backface culling using the face's plane and center point @@ -219,7 +231,7 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face) cam_vec.vz = center.vz - cam_pos.vz; const ps1bsp_plane_t *plane = &world->planes[face->planeId]; - short dot = m_dot12s(cam_vec, plane->normal); + short dot = world_planeDot(&cam_vec, plane); if ((dot >= 0) ^ face->side) return;