]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - portals.c
added cl_avidemo cvar (saves a series of tga images named gamedir/dpavi000000.tga...
[xonotic/darkplaces.git] / portals.c
index 85a8c7d0be34533402dabab02d68b9f8f1fac838..1ad130c2c08525f0d668eb44c5bc620dfdbf3933 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -4,13 +4,17 @@
 #define MAXRECURSIVEPORTALPLANES 1024
 #define MAXRECURSIVEPORTALS 256
 
-tinyplane_t portalplanes[MAXRECURSIVEPORTALPLANES];
-int portalplanestack[MAXRECURSIVEPORTALS];
-int portalplanecount;
-int ranoutofportalplanes;
-int ranoutofportals;
+static tinyplane_t portalplanes[MAXRECURSIVEPORTALPLANES];
+static int portalplanecount;
+static int ranoutofportalplanes;
+static int ranoutofportals;
+static float portaltemppoints[2][256][3];
+static float portaltemppoints2[256][3];
+static int portal_markid = 0;
+//float viewportalpoints[16*3];
+static float boxpoints[4*3];
 
-int R_ClipPolygonToPlane(float *in, float *out, int inpoints, int maxoutpoints, tinyplane_t *p)
+int Portal_ClipPolygonToPlane(float *in, float *out, int inpoints, int maxoutpoints, tinyplane_t *p)
 {
        int i, outpoints, prevside, side;
        float *prevpoint, prevdist, dist, dot;
@@ -62,11 +66,8 @@ begin:
        return outpoints;
 }
 
-float portaltemppoints[2][256][3];
-float portaltemppoints2[256][3];
-
 /*
-void R_TriangleToPlane(vec3_t point1, vec3_t point2, vec3_t point3, tinyplane_t *p)
+void Portal_TriangleToPlane(vec3_t point1, vec3_t point2, vec3_t point3, tinyplane_t *p)
 {
        vec3_t v1, v2;
        VectorSubtract(point1, point2, v1);
@@ -78,7 +79,7 @@ void R_TriangleToPlane(vec3_t point1, vec3_t point2, vec3_t point3, tinyplane_t
 }
 */
 
-int R_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
+int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
 {
        int numpoints, i;
        if (targnumpoints < 3)
@@ -89,7 +90,7 @@ int R_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, floa
        memcpy(&portaltemppoints[0][0][0], targpoints, numpoints * 3 * sizeof(float));
        for (i = 0;i < clipnumplanes;i++)
        {
-               numpoints = R_ClipPolygonToPlane(&portaltemppoints[0][0][0], &portaltemppoints[1][0][0], numpoints, 256, clipplanes + i);
+               numpoints = Portal_ClipPolygonToPlane(&portaltemppoints[0][0][0], &portaltemppoints[1][0][0], numpoints, 256, clipplanes + i);
                if (numpoints < 3)
                        return numpoints;
                memcpy(&portaltemppoints[0][0][0], &portaltemppoints[1][0][0], numpoints * 3 * sizeof(float));
@@ -100,11 +101,12 @@ int R_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, floa
        return numpoints;
 }
 
-static int portal_markid = 0;
-
 int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
 {
        mportal_t *p;
+       int newpoints, i, prev;
+       vec3_t center, v1, v2;
+       tinyplane_t *newplanes;
 
        if (leaf->portalmarkid == portal_markid)
                return true;
@@ -112,14 +114,10 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
        // follow portals into other leafs
        for (p = leaf->portals;p;p = p->next)
        {
-               int newpoints, i, prev;
-               vec3_t center;
-               vec3_t v1, v2;
-               tinyplane_t *newplanes;
                // only flow through portals facing away from the viewer
                if (PlaneDiff(eye, (&p->plane)) < 0)
                {
-                       newpoints = R_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, (float *) p->points, p->numpoints, &portaltemppoints2[0][0], 256);
+                       newpoints = Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, (float *) p->points, p->numpoints, &portaltemppoints2[0][0], 256);
                        if (newpoints < 3)
                                continue;
                        else if (firstclipplane + numclipplanes + newpoints > MAXRECURSIVEPORTALPLANES)
@@ -136,7 +134,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
                                newplanes = &portalplanes[firstclipplane + numclipplanes];
                                for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++)
                                {
-//                                     R_TriangleToPlane(eye, portaltemppoints2[i], portaltemppoints2[prev], newplanes + i);
+//                                     Portal_TriangleToPlane(eye, portaltemppoints2[i], portaltemppoints2[prev], newplanes + i);
                                        VectorSubtract(eye, portaltemppoints2[i], v1);
                                        VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v2);
                                        CrossProduct(v1, v2, newplanes[i].normal);
@@ -165,8 +163,6 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
        return false;
 }
 
-//float viewportalpoints[16*3];
-
 void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints)
 {
        int i, front;
@@ -207,6 +203,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
 
        portal_markid++;
 
+       Mod_CheckLoaded(model);
        Portal_PolygonRecursiveMarkLeafs(model->nodes, polypoints, numpoints);
 
        eyeleaf = Mod_PointInLeaf(eye, model);
@@ -221,7 +218,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
        // calculate the planes, and make sure the polygon can see it's own center
        for (prev = numpoints - 1, i = 0;i < numpoints;prev = i, i++)
        {
-//             R_TriangleToPlane(eye, portaltemppoints2[i], portaltemppoints2[prev], newplanes + i);
+//             Portal_TriangleToPlane(eye, portaltemppoints2[i], portaltemppoints2[prev], newplanes + i);
                VectorSubtract(eye, (&polypoints[i * 3]), v1);
                VectorSubtract((&polypoints[prev * 3]), (&polypoints[i * 3]), v2);
                CrossProduct(v1, v2, portalplanes[i].normal);
@@ -248,8 +245,6 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
        return returnvalue;
 }
 
-float boxpoints[4*3];
-
 #define Portal_MinsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4) \
 {\
        if (eye[(axis)] < ((axisvalue) - 0.5f))\
@@ -281,9 +276,7 @@ int Portal_CheckBox(model_t *model, vec3_t eye, vec3_t a, vec3_t b)
        if (eye[0] >= (a[0] - 1.0f) && eye[0] < (b[0] + 1.0f)
         && eye[1] >= (a[1] - 1.0f) && eye[1] < (b[1] + 1.0f)
         && eye[2] >= (a[2] - 1.0f) && eye[2] < (b[2] + 1.0f))
-       {
                return true;
-       }
 
        Portal_MinsBoxPolygon
        (