]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - portals.c
changed FL_ONGROUND handling for pushers (lifts for example) so you now ride down...
[xonotic/darkplaces.git] / portals.c
index 7d79b32cb082c272d3cc1047d1ee22a571edd7cd..fccaae935d48eaa43cf324a66c8cc86bea43aee3 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -13,29 +13,28 @@ static float portaltemppoints2[256][3];
 static int portal_markid = 0;
 static float boxpoints[4*3];
 
-int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
+static int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
 {
-       int numpoints, i;
-       if (targnumpoints < 3)
-               return targnumpoints;
-       if (maxpoints < 3)
-               return -1;
-       numpoints = targnumpoints;
-       memcpy(&portaltemppoints[0][0][0], targpoints, numpoints * 3 * sizeof(float));
-       for (i = 0;i < clipnumplanes;i++)
+       int numpoints = targnumpoints, i, w;
+       if (numpoints < 1)
+               return numpoints;
+       if (maxpoints > 256)
+               maxpoints = 256;
+       w = 0;
+       memcpy(&portaltemppoints[w][0][0], targpoints, numpoints * 3 * sizeof(float));
+       for (i = 0;i < clipnumplanes && numpoints > 0;i++)
        {
-               PolygonF_Divide(numpoints, &portaltemppoints[0][0][0], clipplanes[i].normal[0], clipplanes[i].normal[1], clipplanes[i].normal[2], clipplanes[i].dist, 1.0f/32.0f, 256, &portaltemppoints[1][0][0], &numpoints, 0, NULL, NULL);
-               if (numpoints < 3)
-                       return numpoints;
-               memcpy(&portaltemppoints[0][0][0], &portaltemppoints[1][0][0], numpoints * 3 * sizeof(float));
+               PolygonF_Divide(numpoints, &portaltemppoints[w][0][0], clipplanes[i].normal[0], clipplanes[i].normal[1], clipplanes[i].normal[2], clipplanes[i].dist, 1.0f/32.0f, 256, &portaltemppoints[1-w][0][0], &numpoints, 0, NULL, NULL, NULL);
+               w = 1-w;
+               numpoints = min(numpoints, 256);
        }
-       if (numpoints > maxpoints)
-               return -1;
-       memcpy(out, &portaltemppoints[0][0][0], numpoints * 3 * sizeof(float));
+       numpoints = min(numpoints, maxpoints);
+       if (numpoints > 0)
+               memcpy(out, &portaltemppoints[w][0][0], numpoints * 3 * sizeof(float));
        return numpoints;
 }
 
-int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
+static int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
 {
        mportal_t *p;
        int newpoints, i, prev;
@@ -71,7 +70,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
                                        VectorSubtract(eye, portaltemppoints2[i], v1);
                                        VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v2);
                                        CrossProduct(v1, v2, newplanes[i].normal);
-                                       VectorNormalizeFast(newplanes[i].normal);
+                                       VectorNormalize(newplanes[i].normal);
                                        newplanes[i].dist = DotProduct(eye, newplanes[i].normal);
                                        if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist)
                                        {
@@ -96,7 +95,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
        return false;
 }
 
-void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints)
+static void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints)
 {
        int i, front;
        float *p;
@@ -140,7 +139,6 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
 
        portal_markid++;
 
-       Mod_CheckLoaded(model);
        Portal_PolygonRecursiveMarkLeafs(model->brush.data_nodes, polypoints, numpoints);
 
        eyeleaf = model->brush.PointInLeaf(model, eye);
@@ -158,7 +156,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
                VectorSubtract(eye, (&polypoints[i * 3]), v1);
                VectorSubtract((&polypoints[prev * 3]), (&polypoints[i * 3]), v2);
                CrossProduct(v1, v2, portalplanes[i].normal);
-               VectorNormalizeFast(portalplanes[i].normal);
+               VectorNormalize(portalplanes[i].normal);
                portalplanes[i].dist = DotProduct(eye, portalplanes[i].normal);
                if (DotProduct(portalplanes[i].normal, center) <= portalplanes[i].dist)
                {
@@ -265,8 +263,6 @@ int Portal_CheckBox(model_t *model, vec3_t eye, vec3_t a, vec3_t b)
        return false;
 }
 
-vec3_t trianglepoints[3];
-
 typedef struct portalrecursioninfo_s
 {
        int exact;
@@ -275,10 +271,10 @@ typedef struct portalrecursioninfo_s
        vec3_t boxmaxs;
        int numsurfaces;
        int *surfacelist;
-       qbyte *surfacepvs;
+       unsigned char *surfacepvs;
        int numleafs;
        int *leaflist;
-       qbyte *leafpvs;
+       unsigned char *leafpvs;
        model_t *model;
        vec3_t eye;
        float *updateleafsmins;
@@ -286,12 +282,12 @@ typedef struct portalrecursioninfo_s
 }
 portalrecursioninfo_t;
 
-void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes)
+static void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes)
 {
        mportal_t *p;
        int newpoints, i, prev;
        float dist;
-       vec3_t center, v1, v2;
+       vec3_t center;
        tinyplane_t *newplanes;
 
        for (i = 0;i < 3;i++)
@@ -319,7 +315,7 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
                        int surfaceindex = leaf->firstleafsurface[i];
                        if (!CHECKPVSBIT(info->surfacepvs, surfaceindex))
                        {
-                               msurface_t *surface = info->model->brush.data_surfaces + surfaceindex;
+                               msurface_t *surface = info->model->data_surfaces + surfaceindex;
                                if (BoxesOverlap(surface->mins, surface->maxs, info->boxmins, info->boxmaxs))
                                {
                                        if (info->exact)
@@ -328,8 +324,8 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
                                                const int *elements;
                                                const float *vertex3f;
                                                float v[9], trimins[3], trimaxs[3];
-                                               vertex3f = surface->groupmesh->data_vertex3f;
-                                               elements = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);
+                                               vertex3f = info->model->surfmesh.data_vertex3f;
+                                               elements = (info->model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);
                                                for (j = 0;j < surface->num_triangles;j++, elements += 3)
                                                {
                                                        VectorCopy(vertex3f + elements[0] * 3, v + 0);
@@ -343,7 +339,7 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
                                                                trimaxs[1] = max(v[1], max(v[4], v[7]));
                                                                trimins[2] = min(v[2], min(v[5], v[8]));
                                                                trimaxs[2] = max(v[2], max(v[5], v[8]));
-                                                               if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs) && Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, v, 3, &portaltemppoints2[0][0], 256) >= 3)
+                                                               if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs) && Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, v, 3, &portaltemppoints2[0][0], 256) > 0)
                                                                {
                                                                        SETPVSBIT(info->surfacepvs, surfaceindex);
                                                                        info->surfacelist[info->numsurfaces++] = surfaceindex;
@@ -382,18 +378,16 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
                                        VectorAdd(center, portaltemppoints2[i], center);
                                // ixtable is a 1.0f / N table
                                VectorScale(center, ixtable[newpoints], center);
-                               // calculate the planes, and make sure the polygon can see it's own center
+                               // calculate the planes, and make sure the polygon can see its own center
                                newplanes = &portalplanes[firstclipplane + numclipplanes];
                                for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++)
                                {
-                                       VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v1);
-                                       VectorSubtract(info->eye, portaltemppoints2[i], v2);
-                                       CrossProduct(v1, v2, newplanes[i].normal);
-                                       VectorNormalizeFast(newplanes[i].normal);
+                                       TriangleNormal(portaltemppoints2[prev], portaltemppoints2[i], info->eye, newplanes[i].normal);
+                                       VectorNormalize(newplanes[i].normal);
                                        newplanes[i].dist = DotProduct(info->eye, newplanes[i].normal);
                                        if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist)
                                        {
-                                               // polygon can't see it's own center, discard and use parent portal
+                                               // polygon can't see its own center, discard and use parent portal
                                                break;
                                        }
                                }
@@ -406,7 +400,7 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
        }
 }
 
-void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
+static void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
 {
        if (node->plane)
        {
@@ -419,12 +413,12 @@ void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
        else
        {
                mleaf_t *leaf = (mleaf_t *)node;
-               if (leaf->portals)
+               if (leaf->clusterindex >= 0)
                        Portal_RecursiveFlow(info, leaf, 0, info->numfrustumplanes);
        }
 }
 
-void Portal_Visibility(model_t *model, const vec3_t eye, int *leaflist, qbyte *leafpvs, int *numleafspointer, int *surfacelist, qbyte *surfacepvs, int *numsurfacespointer, const mplane_t *frustumplanes, int numfrustumplanes, int exact, const float *boxmins, const float *boxmaxs, float *updateleafsmins, float *updateleafsmaxs)
+void Portal_Visibility(model_t *model, const vec3_t eye, int *leaflist, unsigned char *leafpvs, int *numleafspointer, int *surfacelist, unsigned char *surfacepvs, int *numsurfacespointer, const mplane_t *frustumplanes, int numfrustumplanes, int exact, const float *boxmins, const float *boxmaxs, float *updateleafsmins, float *updateleafsmaxs)
 {
        int i;
        portalrecursioninfo_t info;
@@ -436,9 +430,7 @@ void Portal_Visibility(model_t *model, const vec3_t eye, int *leaflist, qbyte *l
                return;
        }
 
-       Mod_CheckLoaded(model);
-
-       if (!model->brush.num_portals)
+       if (!model->brush.data_nodes)
        {
                Con_Print("Portal_Visibility: not a brush model\n");
                return;