diff --git a/frustum.c b/frustum.c index e8975e8..e90049b 100644 --- a/frustum.c +++ b/frustum.c @@ -4,7 +4,7 @@ #include -static SVECTOR left, right, top, bottom; +static SVECTOR *left, *right, *top, *bottom; static INLINE void frustum_buildPlane(MATRIX *rot_matrix, VECTOR *normal, SVECTOR *outPlane) { @@ -44,10 +44,16 @@ void frustum_update(int width, int height) MATRIX rot_matrix; RotMatrixQ(&cam_rot, &rot_matrix); - frustum_buildPlane(&rot_matrix, &l, &left); - frustum_buildPlane(&rot_matrix, &r, &right); - frustum_buildPlane(&rot_matrix, &t, &top); - frustum_buildPlane(&rot_matrix, &b, &bottom); + // Place the frustum planes at the start of the fast RAM buffer + left = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 0); + right = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 1); + top = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 2); + bottom = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 3); + + frustum_buildPlane(&rot_matrix, &l, left); + frustum_buildPlane(&rot_matrix, &r, right); + frustum_buildPlane(&rot_matrix, &t, top); + frustum_buildPlane(&rot_matrix, &b, bottom); // FntPrint(-1, "l = %d %d, r = %d %d, t = %d %d, b = %d %d\n", // left.vx, left.pad, right.vx, right.pad, top.vz, top.pad, bottom.vz, bottom.pad); @@ -55,29 +61,29 @@ void frustum_update(int width, int height) static INLINE u_char frustum_pointInside_(const SVECTOR p) { - if (m_dot12(left, p) + left.pad < 0) return 0; - if (m_dot12(right, p) + right.pad < 0) return 0; - if (m_dot12(top, p) + top.pad < 0) return 0; - if (m_dot12(bottom, p) + bottom.pad < 0) return 0; + if (m_dot12(*left, p) + left->pad < 0) return 0; + if (m_dot12(*right, p) + right->pad < 0) return 0; + if (m_dot12(*top, p) + top->pad < 0) return 0; + if (m_dot12(*bottom, p) + bottom->pad < 0) return 0; return 1; } u_char frustum_pointInside(const SVECTOR *point) { - if (m_dot12(left, *point) + left.pad < 0) return 0; - if (m_dot12(right, *point) + right.pad < 0) return 0; - if (m_dot12(top, *point) + top.pad < 0) return 0; - if (m_dot12(bottom, *point) + bottom.pad < 0) return 0; + if (m_dot12(*left, *point) + left->pad < 0) return 0; + if (m_dot12(*right, *point) + right->pad < 0) return 0; + if (m_dot12(*top, *point) + top->pad < 0) return 0; + if (m_dot12(*bottom, *point) + bottom->pad < 0) return 0; return 1; } u_char frustum_sphereInside(const SVECTOR *sphere) { short radius = -sphere->pad; - if (m_dot12(left, *sphere) + left.pad < radius) return 0; - if (m_dot12(right, *sphere) + right.pad < radius) return 0; - if (m_dot12(top, *sphere) + top.pad < radius) return 0; - if (m_dot12(bottom, *sphere) + bottom.pad < radius) return 0; + if (m_dot12(*left, *sphere) + left->pad < radius) return 0; + if (m_dot12(*right, *sphere) + right->pad < radius) return 0; + if (m_dot12(*top, *sphere) + top->pad < radius) return 0; + if (m_dot12(*bottom, *sphere) + bottom->pad < radius) return 0; return 1; } diff --git a/ps1bsp.h b/ps1bsp.h index 14b9562..0a7cffc 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -89,9 +89,9 @@ typedef struct unsigned char b : 5; } ps1bsp_facevertex_t; -#define SURF_DRAWSKY 0x2 -#define SURF_DRAWLIQUID 0x4 -#define SURF_DRAWWATER 0x8 +#define SURF_DRAWSKY 0x4 +#define SURF_DRAWLIQUID 0x8 +#define SURF_DRAWWATER 0x10 // High quality: Face -> polygons -> polygon vertex indices (index + UV + light) -> vertices // Low quality: Face -> face vertex indices (index + color) -> vertices @@ -147,9 +147,10 @@ typedef struct ps1bsp_leaf_s // Run-time data const struct ps1bsp_leaf_s* nextLeaf; // For chaining leafs in drawing order + const struct ps1bsp_model_s* models; } ps1bsp_leaf_t; -typedef struct +typedef struct ps1bsp_model_s { SVECTOR boundingSphere; SVECTOR origin; @@ -158,6 +159,9 @@ typedef struct u_short nodeId1; u_short nodeId2; u_short nodeId3; + + // Run-time data + const struct ps1bsp_model_s* nextModel; } ps1bsp_model_t; // Pre-parsed and encoded entity data (this runs the risk of becoming too bloated) diff --git a/test.ps1bsp b/test.ps1bsp index bb4139a..65577e3 100755 Binary files a/test.ps1bsp and b/test.ps1bsp differ diff --git a/world.c b/world.c index 06e32c3..e07450d 100644 --- a/world.c +++ b/world.c @@ -322,7 +322,7 @@ void world_draw(const world_t *world) cam_leaf = world_leafAtPoint(world, &cam_pos); - u_char *pvsbuf = scratchpad; + u_char *pvsbuf = scratchpad + 32; // Place the PVS data after the frustum in fast RAM u_char *pvs = world_loadVisData(world, cam_leaf, &pvsbuf); //u_char *pvs = world_noVisData(world, &pvsbuf);