diff --git a/ps1bsp.h b/ps1bsp.h index 0ce50fe..56217df 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -92,8 +92,7 @@ typedef struct typedef struct { int planeId; - short front; - short back; + short children[2]; // TODO: add bounding box for frustum culling diff --git a/world.c b/world.c index dacd3f8..0386c0f 100644 --- a/world.c +++ b/world.c @@ -287,16 +287,9 @@ static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs) short dist = world_pointPlaneDist(&cam_pos, plane); // Draw child nodes in front-to-back order; adding faces to the OT will reverse the drawing order - if (dist > 0) - { - world_drawnode(world, node->front, pvs); - world_drawnode(world, node->back, pvs); - } - else - { - world_drawnode(world, node->back, pvs); - world_drawnode(world, node->front, pvs); - } + char order = dist < 0; + world_drawnode(world, node->children[order], pvs); + world_drawnode(world, node->children[order ^ 1], pvs); } // Decompress PVS data for the given leaf ID and store it in RAM at the given buffer pointer location. @@ -354,7 +347,7 @@ static u_short world_leafAtPoint(const world_t *world, const VECTOR *point) const ps1bsp_plane_t *plane = &world->planes[node->planeId]; short dist = world_pointPlaneDist(point, plane); - nodeIdx = dist > 0 ? node->front : node->back; // TODO: this can be done branchless with (dist < 0)^1 + nodeIdx = node->children[(dist > 0) ^ 1]; } return ~nodeIdx;