patches: experimental mode that allows setting collision stride to -1 to avoid ANY...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 21 Nov 2009 15:03:21 +0000 (15:03 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 21 Nov 2009 15:03:21 +0000 (15:03 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9508 d7cf8633-e32d-0410-b094-e92efae38249

collision.c
model_brush.c

index 843b1f3..49efcd7 100644 (file)
@@ -1044,7 +1044,7 @@ void Collision_TraceBrushTriangleMeshFloat(trace_t *trace, const colbrushf_t *th
                brush.planes[i].q3surfaceflags = q3surfaceflags;
                brush.planes[i].texture = texture;
        }
-       if(stride)
+       if(stride > 0)
        {
                int k, cnt, tri;
                cnt = (numtriangles + stride - 1) / stride;
@@ -1069,7 +1069,7 @@ void Collision_TraceBrushTriangleMeshFloat(trace_t *trace, const colbrushf_t *th
                        }
                }
        }
-       else
+       else if(stride == 0)
        {
                for (i = 0;i < numtriangles;i++, element3i += 3)
                {
@@ -1086,14 +1086,27 @@ void Collision_TraceBrushTriangleMeshFloat(trace_t *trace, const colbrushf_t *th
                        }
                }
        }
+       else
+       {
+               for (i = 0;i < numtriangles;i++, element3i += 3)
+               {
+                       VectorCopy(vertex3f + element3i[0] * 3, points[0].v);
+                       VectorCopy(vertex3f + element3i[1] * 3, points[1].v);
+                       VectorCopy(vertex3f + element3i[2] * 3, points[2].v);
+                       Collision_SnapCopyPoints(brush.numpoints, points, points, COLLISION_SNAPSCALE, COLLISION_SNAP);
+                       Collision_CalcEdgeDirsForPolygonBrushFloat(&brush);
+                       Collision_CalcPlanesForPolygonBrushFloat(&brush);
+                       //Collision_PrintBrushAsQHull(&brush, "brush");
+                       Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &brush, &brush);
+               }
+       }
 }
 
 void Collision_TraceLineTriangleMeshFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numtriangles, const int *element3i, const float *vertex3f, int stride, float *bbox6f, int supercontents, int q3surfaceflags, texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
 {
        int i;
-#if 1
        // FIXME: snap vertices?
-       if(stride)
+       if(stride > 0)
        {
                int k, cnt, tri;
                cnt = (numtriangles + stride - 1) / stride;
@@ -1116,43 +1129,6 @@ void Collision_TraceLineTriangleMeshFloat(trace_t *trace, const vec3_t linestart
                for (i = 0;i < numtriangles;i++, element3i += 3)
                        Collision_TraceLineTriangleFloat(trace, linestart, lineend, vertex3f + element3i[0] * 3, vertex3f + element3i[1] * 3, vertex3f + element3i[2] * 3, supercontents, q3surfaceflags, texture);
        }
-#else
-       colpointf_t points[3];
-       colpointf_t edgedirs[3];
-       colplanef_t planes[5];
-       colbrushf_t brush;
-       memset(&brush, 0, sizeof(brush));
-       brush.isaabb = false;
-       brush.hasaabbplanes = false;
-       brush.numpoints = 3;
-       brush.numedgedirs = 3;
-       brush.numplanes = 5;
-       brush.points = points;
-       brush.edgedirs = edgedirs;
-       brush.planes = planes;
-       brush.supercontents = supercontents;
-       brush.q3surfaceflags = q3surfaceflags;
-       brush.texture = texture;
-       for (i = 0;i < brush.numplanes;i++)
-       {
-               brush.planes[i].q3surfaceflags = q3surfaceflags;
-               brush.planes[i].texture = texture;
-       }
-       for (i = 0;i < numtriangles;i++, element3i += 3)
-       {
-               if (TriangleOverlapsBox(vertex3f + element3i[0]*3, vertex3 + [element3i[1]*3, vertex3f + element3i[2]*3, segmentmins, segmentmaxs))
-               {
-                       VectorCopy(vertex3f + element3i[0] * 3, points[0].v);
-                       VectorCopy(vertex3f + element3i[1] * 3, points[1].v);
-                       VectorCopy(vertex3f + element3i[2] * 3, points[2].v);
-                       Collision_SnapCopyPoints(brush.numpoints, points, points, COLLISION_SNAPSCALE, COLLISION_SNAP);
-                       Collision_CalcEdgeDirsForPolygonBrushFloat(&brush);
-                       Collision_CalcPlanesForPolygonBrushFloat(&brush);
-                       //Collision_PrintBrushAsQHull(&brush, "brush");
-                       Collision_TraceLineBrushFloat(trace, linestart, lineend, &brush, &brush);
-               }
-       }
-#endif
 }
 
 void Collision_BrushForBox(colboxbrushf_t *boxbrush, const vec3_t mins, const vec3_t maxs, int supercontents, int q3surfaceflags, texture_t *texture)
index 10b5bf4..d8fe5ae 100644 (file)
@@ -39,8 +39,8 @@ cvar_t r_subdivisions_collision_mintess = {0, "r_subdivisions_collision_mintess"
 cvar_t r_subdivisions_collision_maxtess = {0, "r_subdivisions_collision_maxtess", "1024", "maximum number of subdivisions (prevents curves beyond a certain detail level, limits smoothing)"};
 cvar_t r_subdivisions_collision_maxvertices = {0, "r_subdivisions_collision_maxvertices", "4225", "maximum vertices allowed per subdivided curve"};
 cvar_t mod_q3bsp_curves_collisions = {0, "mod_q3bsp_curves_collisions", "1", "enables collisions with curves (SLOW)"};
-cvar_t mod_q3bsp_curves_collisions_stride = {0, "mod_q3bsp_curves_collisions_stride", "16", "collisions against curves: optimize performance by doing a combined collision check for this triangle amount first"};
-cvar_t mod_q3bsp_curves_stride = {0, "mod_q3bsp_curves_stride", "16", "particle effect collisions against curves: optimize performance by doing a combined collision check for this triangle amount first"};
+cvar_t mod_q3bsp_curves_collisions_stride = {0, "mod_q3bsp_curves_collisions_stride", "16", "collisions against curves: optimize performance by doing a combined collision check for this triangle amount first (-1 avoids any box tests)"};
+cvar_t mod_q3bsp_curves_stride = {0, "mod_q3bsp_curves_stride", "16", "particle effect collisions against curves: optimize performance by doing a combined collision check for this triangle amount first (-1 avoids any box tests)"};
 cvar_t mod_q3bsp_optimizedtraceline = {0, "mod_q3bsp_optimizedtraceline", "1", "whether to use optimized traceline code for line traces (as opposed to tracebox code)"};
 cvar_t mod_q3bsp_debugtracebrush = {0, "mod_q3bsp_debugtracebrush", "0", "selects different tracebrush bsp recursion algorithms (for debugging purposes only)"};
 cvar_t mod_q3bsp_lightmapmergepower = {CVAR_SAVE, "mod_q3bsp_lightmapmergepower", "4", "merges the quake3 128x128 lightmap textures into larger lightmap group textures to speed up rendering, 1 = 256x256, 2 = 512x512, 3 = 1024x1024, 4 = 2048x2048, 5 = 4096x4096, ..."};
@@ -522,7 +522,7 @@ static void Mod_Q1BSP_FindNonSolidLocation_r_Leaf(findnonsolidlocationinfo_t *in
                surface = info->model->data_surfaces + *mark;
                if (surface->texture->supercontents & SUPERCONTENTS_SOLID)
                {
-                       if(surface->num_bboxstride)
+                       if(surface->num_bboxstride > 0)
                        {
                                int i, cnt, tri;
                                cnt = (surface->num_triangles + surface->num_bboxstride - 1) / surface->num_bboxstride;
@@ -4775,9 +4775,9 @@ static void Mod_Q3BSP_BuildBBoxes(const int *element3i, int num_triangles, const
        int j, k, cnt, tri;
        float *mins, *maxs;
        const float *vert;
+       *collisionstride = stride;
        if(stride > 0)
        {
-               *collisionstride = stride;
                cnt = (num_triangles + stride - 1) / stride;
                *collisionbbox6f = (float *) Mem_Alloc(loadmodel->mempool, sizeof(float[6]) * cnt);
                for(j = 0; j < cnt; ++j)
@@ -4814,10 +4814,7 @@ static void Mod_Q3BSP_BuildBBoxes(const int *element3i, int num_triangles, const
                }
        }
        else
-       {
-               *collisionstride = 0;
                *collisionbbox6f = NULL;
-       }
 }
 
 typedef struct patchtess_s