]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - collision.c
handle funky ToAscii values (shift/ctrl/alt sometimes produce ascii values for no...
[xonotic/darkplaces.git] / collision.c
index 1c4a4fe6b323149fe10be628f71c5b312c99c416..f6636ba069f33fa9fbe57d296aec4676f1ad61a2 100644 (file)
@@ -2,6 +2,10 @@
 #include "quakedef.h"
 #include "winding.h"
 
+// 1/32 epsilon to keep floating point happy
+#define DIST_EPSILON (0.03125)
+
+#if 0
 typedef struct
 {
        // the hull we're tracing through
@@ -22,9 +26,6 @@ typedef struct
 }
 RecursiveHullCheckTraceInfo_t;
 
-// 1/32 epsilon to keep floating point happy
-#define DIST_EPSILON (0.03125)
-
 #define HULLCHECKSTATE_EMPTY 0
 #define HULLCHECKSTATE_SOLID 1
 #define HULLCHECKSTATE_DONE 2
@@ -48,26 +49,32 @@ loc0:
        // check for empty
        if (num < 0)
        {
-               // translate the fake CONTENTS values in the box bsp tree
-               if (num == CONTENTS_SOLID)
-                       num = t->boxsupercontents;
-               else
-                       num = 0;
+               num = Mod_Q1BSP_SuperContentsFromNativeContents(NULL, num);
                if (!t->trace->startfound)
                {
                        t->trace->startfound = true;
                        t->trace->startsupercontents |= num;
                }
+               if (num & SUPERCONTENTS_LIQUIDSMASK)
+                       t->trace->inwater = true;
+               if (num == 0)
+                       t->trace->inopen = true;
                if (num & t->trace->hitsupercontentsmask)
                {
                        // if the first leaf is solid, set startsolid
                        if (t->trace->allsolid)
                                t->trace->startsolid = true;
+#if COLLISIONPARANOID >= 3
+                       Con_Printf("S");
+#endif
                        return HULLCHECKSTATE_SOLID;
                }
                else
                {
                        t->trace->allsolid = false;
+#if COLLISIONPARANOID >= 3
+                       Con_Printf("E");
+#endif
                        return HULLCHECKSTATE_EMPTY;
                }
        }
@@ -91,6 +98,9 @@ loc0:
        {
                if (t2 < 0)
                {
+#if COLLISIONPARANOID >= 3
+                       Con_Printf("<");
+#endif
                        num = node->children[1];
                        goto loc0;
                }
@@ -100,6 +110,9 @@ loc0:
        {
                if (t2 >= 0)
                {
+#if COLLISIONPARANOID >= 3
+                       Con_Printf(">");
+#endif
                        num = node->children[0];
                        goto loc0;
                }
@@ -108,6 +121,9 @@ loc0:
 
        // the line intersects, find intersection point
        // LordHavoc: this uses the original trace for maximum accuracy
+#if COLLISIONPARANOID >= 3
+       Con_Printf("M");
+#endif
        if (plane->type < 3)
        {
                t1 = t->start[plane->type] - plane->dist;
@@ -153,8 +169,9 @@ loc0:
        midf = t1 / (t1 - t2);
        t->trace->fraction = bound(0.0f, midf, 1.0);
 
-       VectorMA(t->start, t->trace->fraction, t->dist, t->trace->endpos);
-
+#if COLLISIONPARANOID >= 3
+       Con_Printf("D");
+#endif
        return HULLCHECKSTATE_DONE;
 }
 
@@ -203,7 +220,7 @@ static hull_t box_hull;
 static dclipnode_t box_clipnodes[6];
 static mplane_t box_planes[6];
 
-void Collision_Init (void)
+void Mod_Q1BSP_Collision_Init (void)
 {
        int             i;
        int             side;
@@ -258,9 +275,16 @@ void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cm
        VectorCopy(start, rhc.start);
        VectorCopy(end, rhc.end);
        VectorSubtract(rhc.end, rhc.start, rhc.dist);
-       RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
+       Mod_Q1BSP_RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
+       VectorMA(rhc.start, rhc.trace->fraction, rhc.dist, rhc.trace->endpos);
+       if (rhc.trace->startsupercontents)
+               rhc.trace->startsupercontents = boxsupercontents;
 }
+#endif
 
+void Collision_Init (void)
+{
+}
 
 
 
@@ -363,11 +387,11 @@ float furthestplanedist_float(const float *normal, const colpointf_t *points, in
 }
 
 
-colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalplanes, const mplane_t *originalplanes, int supercontents)
+colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalplanes, const mplane_t *originalplanes, int supercontents, winding_t *temp1, winding_t *temp2)
 {
        int j, k, m;
        int numpoints, maxpoints, numplanes, maxplanes, numelements, maxelements, numtriangles, numpolypoints, maxpolypoints;
-       winding_t *w;
+       winding_t *w, *temp, *othertemp;
        colbrushf_t *brush;
        colpointf_t pointsbuf[256];
        colplanef_t planesbuf[256];
@@ -399,19 +423,24 @@ colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalpla
                }
 
                // create a large polygon from the plane
-               w = Winding_NewFromPlane(originalplanes[j].normal[0], originalplanes[j].normal[1], originalplanes[j].normal[2], originalplanes[j].dist);
+               w = temp1;
+               othertemp = temp2;
+               BufWinding_NewFromPlane(w, originalplanes[j].normal[0], originalplanes[j].normal[1], originalplanes[j].normal[2], originalplanes[j].dist);
                // clip it by all other planes
-               for (k = 0;k < numoriginalplanes && w;k++)
+               for (k = 0;k < numoriginalplanes && w->numpoints;k++)
                {
                        if (k != j)
                        {
                                // we want to keep the inside of the brush plane so we flip
                                // the cutting plane
-                               w = Winding_Clip(w, -originalplanes[k].normal[0], -originalplanes[k].normal[1], -originalplanes[k].normal[2], -originalplanes[k].dist, true);
+                               BufWinding_Divide(w, -originalplanes[k].normal[0], -originalplanes[k].normal[1], -originalplanes[k].normal[2], -originalplanes[k].dist, othertemp, NULL, NULL, NULL);
+                               temp = w;
+                               w = othertemp;
+                               othertemp = temp;
                        }
                }
                // if nothing is left, skip it
-               if (!w)
+               if (!w->numpoints)
                        continue;
 
                // copy off the number of points for later when the winding is freed
@@ -456,8 +485,9 @@ colbrushf_t *Collision_NewBrushFromPlanes(mempool_t *mempool, int numoriginalpla
                        // store the index into a buffer
                        polypointbuf[k] = m;
                }
-               Winding_Free(w);
                w = NULL;
+               othertemp = NULL;
+               temp = NULL;
 
                // add the triangles for the polygon
                // (this particular code makes a triangle fan)
@@ -809,9 +839,12 @@ void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const
                                Con_Printf("Collision_TraceLineBrushFloat: degenerate plane!\n");
                                return;
                        }
-                       f = furthestplanedist_float(startplane->normal, thatbrush_start->points, thatbrush_start->numpoints);
-                       if (fabs(f - startplane->dist) > 0.01f)
-                               Con_Printf("startplane->dist %f != calculated %f\n", startplane->dist, f);
+                       if (thatbrush_start->numpoints)
+                       {
+                               f = furthestplanedist_float(startplane->normal, thatbrush_start->points, thatbrush_start->numpoints);
+                               if (fabs(f - startplane->dist) > 0.01f)
+                                       Con_Printf("startplane->dist %f != calculated %f\n", startplane->dist, f);
+                       }
                }
 
                f = d1 - d2;