-
-/*
-===============
-SV_LinkEdict
-
-===============
-*/
-void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
-{
- areanode_t *node;
-
- if (ent->area.prev)
- SV_UnlinkEdict (ent); // unlink from old position
-
- if (ent == sv.edicts)
- return; // don't add the world
-
- if (ent->free)
- return;
-
-// set the abs box
-
-// LordHavoc: enabling rotating bmodels
- if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
- {
- // expand for rotation
- float max, v;
- int i;
-
- max = DotProduct(ent->v.mins, ent->v.mins);
- v = DotProduct(ent->v.maxs, ent->v.maxs);
- if (max < v)
- max = v;
- max = sqrt(max);
- /*
- max = 0;
- for (i=0 ; i<3 ; i++)
- {
- v = fabs(ent->v.mins[i]);
- if (max < v)
- max = v;
- v = fabs(ent->v.maxs[i]);
- if (max < v)
- max = v;
- }
- */
- for (i=0 ; i<3 ; i++)
- {
- ent->v.absmin[i] = ent->v.origin[i] - max;
- ent->v.absmax[i] = ent->v.origin[i] + max;
- }
- }
- else
- {
- VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
- VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
- }
-
-//
-// to make items easier to pick up and allow them to be grabbed off
-// of shelves, the abs sizes are expanded
-//
- if ((int)ent->v.flags & FL_ITEM)
- {
- ent->v.absmin[0] -= 15;
- ent->v.absmin[1] -= 15;
- ent->v.absmax[0] += 15;
- ent->v.absmax[1] += 15;
- }
- else
- {
- // because movement is clipped an epsilon away from an actual edge,
- // we must fully check even when bounding boxes don't quite touch
- ent->v.absmin[0] -= 1;
- ent->v.absmin[1] -= 1;
- ent->v.absmin[2] -= 1;
- ent->v.absmax[0] += 1;
- ent->v.absmax[1] += 1;
- ent->v.absmax[2] += 1;
- }
-
- if (ent->v.solid == SOLID_NOT)
- return;
-
-// find the first node that the ent's box crosses
- node = sv_areanodes;
- while (1)
- {
- if (node->axis == -1)
- break;
- if (ent->v.absmin[node->axis] > node->dist)
- node = node->children[0];
- else if (ent->v.absmax[node->axis] < node->dist)
- node = node->children[1];
- else
- break; // crosses the node
- }
-
-// link it in
-
- if (ent->v.solid == SOLID_TRIGGER)
- InsertLinkBefore (&ent->area, &node->trigger_edicts);
- else
- InsertLinkBefore (&ent->area, &node->solid_edicts);
-
-// if touch_triggers, touch all entities at this node and descend for more
- if (touch_triggers)
- SV_TouchLinks ( ent, sv_areanodes );
-}
-
-
-
-/*
-===============================================================================
-
-POINT TESTING IN HULLS
-
-===============================================================================
-*/
-
-/*
-==================
-SV_HullPointContents
-
-==================
-*/
-int SV_HullPointContents (hull_t *hull, int num, vec3_t p)
-{
- while (num >= 0)
- num = hull->clipnodes[num].children[(hull->planes[hull->clipnodes[num].planenum].type < 3 ? p[hull->planes[hull->clipnodes[num].planenum].type] : DotProduct (hull->planes[hull->clipnodes[num].planenum].normal, p)) < hull->planes[hull->clipnodes[num].planenum].dist];
-
- return num;
-}
-
-/*
-============
-SV_TestEntityPosition
-
-This could be a lot more efficient...
-============
-*/
-edict_t *SV_TestEntityPosition (edict_t *ent)
-{
- trace_t trace;
-
- trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, MOVE_NORMAL, ent);
-
- if (trace.startsolid)
- return sv.edicts;
-
- return NULL;
-}
-
-
-/*
-===============================================================================
-
-LINE TESTING IN HULLS
-
-===============================================================================
-*/
-
-// 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
-
-// LordHavoc: FIXME: this is not thread safe, if threading matters here, pass
-// this as a struct to RecursiveHullCheck, RecursiveHullCheck_Impact, etc...
-RecursiveHullCheckTraceInfo_t RecursiveHullCheckInfo;
-#define RHC RecursiveHullCheckInfo
-
-void SV_RecursiveHullCheck_Impact (mplane_t *plane, int side)
-{
- // LordHavoc: using doubles for extra accuracy
- double t1, t2, frac;
-
- // LordHavoc: now that we have found the impact, recalculate the impact
- // point from scratch for maximum accuracy, with an epsilon bias on the
- // surface distance
- frac = plane->dist;
- if (side)
- {
- frac -= DIST_EPSILON;
- VectorNegate (plane->normal, RHC.trace->plane.normal);
- RHC.trace->plane.dist = -plane->dist;
- }
- else
- {
- frac += DIST_EPSILON;
- VectorCopy (plane->normal, RHC.trace->plane.normal);
- RHC.trace->plane.dist = plane->dist;
- }
-
- if (plane->type < 3)
- {
- t1 = RHC.start[plane->type] - frac;
- t2 = RHC.start[plane->type] + RHC.dist[plane->type] - frac;
- }
- else
- {
- t1 = plane->normal[0] * RHC.start[0] + plane->normal[1] * RHC.start[1] + plane->normal[2] * RHC.start[2] - frac;
- t2 = plane->normal[0] * (RHC.start[0] + RHC.dist[0]) + plane->normal[1] * (RHC.start[1] + RHC.dist[1]) + plane->normal[2] * (RHC.start[2] + RHC.dist[2]) - frac;
- }
-
- frac = t1 / (t1 - t2);
- frac = bound(0.0f, frac, 1.0);
-
- RHC.trace->fraction = frac;
- RHC.trace->endpos[0] = RHC.start[0] + frac * RHC.dist[0];
- RHC.trace->endpos[1] = RHC.start[1] + frac * RHC.dist[1];
- RHC.trace->endpos[2] = RHC.start[2] + frac * RHC.dist[2];
-}
-
-int SV_RecursiveHullCheck (int num, double p1f, double p2f, double p1[3], double p2[3])