From e703935e9ba4deabb7d566641c170343e7e86c82 Mon Sep 17 00:00:00 2001 From: Dabb Date: Mon, 5 Mar 2001 11:49:59 +0000 Subject: [PATCH] Merged duplicate client/server functions (placed into PMOVETST.C). PM/SV_RecursiveHullCheck -> HullCheck PM/SV_InitBoxHull -> InitBoxHull PM/SV_HullForBox -> HullForBox PM/SV_HullPointContents > HullPointContents Client now uses WORLDA.S (renamed func) pmtrace_t replaced by trace_t with ent->entnum change pmplane_t replaced by plane_t --- source/pmove.c | 25 ++--- source/pmovetst.c | 82 ++++++--------- source/world.c | 261 ++-------------------------------------------- 3 files changed, 56 insertions(+), 312 deletions(-) diff --git a/source/pmove.c b/source/pmove.c index 4eec02c..3b1fb47 100644 --- a/source/pmove.c +++ b/source/pmove.c @@ -54,13 +54,13 @@ vec3_t forward, right, up; vec3_t player_mins = { -16, -16, -24 }; vec3_t player_maxs = { 16, 16, 32 }; -void PM_InitBoxHull (void); +extern void InitBoxHull (void); void PM_CategorizePosition (void); void Pmove_Init (void) { - PM_InitBoxHull (); + InitBoxHull (); } void @@ -126,7 +126,7 @@ PM_FlyMove (void) vec3_t planes[MAX_CLIP_PLANES]; vec3_t primal_velocity, original_velocity; int i, j; - pmtrace_t trace; + trace_t trace; vec3_t end; float time_left; int blocked; @@ -161,7 +161,7 @@ PM_FlyMove (void) break; // moved the entire distance // save entity for contact - pmove.touchindex[pmove.numtouch] = trace.ent; + pmove.touchindex[pmove.numtouch] = trace.entnum; pmove.numtouch++; if (trace.plane.normal[2] > 0.7) { @@ -237,7 +237,7 @@ void PM_FlymodeMove (void) { vec3_t start, dest, pmvel, pmtmp; - pmtrace_t trace; + trace_t trace; float pmspeed; pmvel[0] = @@ -280,7 +280,7 @@ void PM_GroundMove (void) { vec3_t start, dest; - pmtrace_t trace; + trace_t trace; vec3_t original, originalvel, down, up, downvel; float downdist, updist; @@ -367,7 +367,7 @@ PM_Friction (void) float friction; float drop; vec3_t start, stop; - pmtrace_t trace; + trace_t trace; if (pmove.waterjumptime) return; @@ -482,7 +482,7 @@ PM_WaterMove (void) float wishspeed; vec3_t wishdir; vec3_t start, dest; - pmtrace_t trace; + trace_t trace; // // user intentions @@ -607,7 +607,7 @@ PM_CategorizePosition (void) { vec3_t point; int cont; - pmtrace_t tr; + trace_t tr; // if the player hull point one unit down is solid, the player // is on ground @@ -623,15 +623,16 @@ PM_CategorizePosition (void) if (tr.plane.normal[2] < 0.7) onground = -1; // too steep else - onground = tr.ent; + onground = tr.entnum; if (onground != -1) { pmove.waterjumptime = 0; if (!tr.startsolid && !tr.allsolid) VectorCopy (tr.endpos, pmove.origin); } // standing on an entity other than the world - if (tr.ent > 0) { - pmove.touchindex[pmove.numtouch] = tr.ent; + + if (tr.entnum > 0) { + pmove.touchindex[pmove.numtouch] = tr.entnum; pmove.numtouch++; } } diff --git a/source/pmovetst.c b/source/pmovetst.c index 4e84c4b..fe42a50 100644 --- a/source/pmovetst.c +++ b/source/pmovetst.c @@ -49,14 +49,16 @@ static mplane_t box_planes[6]; extern vec3_t player_mins; extern vec3_t player_maxs; +int HullPointContents (hull_t *hull, int num, vec3_t p); + /* - PM_InitBoxHull + InitBoxHull Set up the planes and clipnodes so that the six floats of a bounding box can just be stored out and get a proper hull_t structure. */ void -PM_InitBoxHull (void) +InitBoxHull (void) { int i; int side; @@ -85,13 +87,13 @@ PM_InitBoxHull (void) /* - PM_HullForBox + HullForBox To keep everything totally uniform, bounding boxes are turned into small BSP trees instead of being compared directly. */ hull_t * -PM_HullForBox (vec3_t mins, vec3_t maxs) +HullForBox (vec3_t mins, vec3_t maxs) { box_planes[0].dist = maxs[0]; box_planes[1].dist = mins[0]; @@ -104,11 +106,12 @@ PM_HullForBox (vec3_t mins, vec3_t maxs) } +#ifndef USE_INTEL_ASM /* - PM_HullPointContents + HullPointContents */ int -PM_HullPointContents (hull_t *hull, int num, vec3_t p) +HullPointContents (hull_t *hull, int num, vec3_t p) { float d; dclipnode_t *node; @@ -116,7 +119,7 @@ PM_HullPointContents (hull_t *hull, int num, vec3_t p) while (num >= 0) { if (num < hull->firstclipnode || num > hull->lastclipnode) - Sys_Error ("PM_HullPointContents: bad node number"); + Sys_Error ("HullPointContents: bad node number"); node = hull->clipnodes + num; plane = hull->planes + node->planenum; @@ -133,6 +136,7 @@ PM_HullPointContents (hull_t *hull, int num, vec3_t p) return num; } +#endif // !USE_INTEL_ASM /* PM_PointContents @@ -140,34 +144,12 @@ PM_HullPointContents (hull_t *hull, int num, vec3_t p) int PM_PointContents (vec3_t p) { - float d; - dclipnode_t *node; - mplane_t *plane; hull_t *hull; - int num; - + int num; hull = &pmove.physents[0].model->hulls[0]; - num = hull->firstclipnode; - while (num >= 0) { - if (num < hull->firstclipnode || num > hull->lastclipnode) - Sys_Error ("PM_HullPointContents: bad node number"); - - node = hull->clipnodes + num; - plane = hull->planes + node->planenum; - - if (plane->type < 3) - d = p[plane->type] - plane->dist; - else - d = DotProduct (plane->normal, p) - plane->dist; - if (d < 0) - num = node->children[1]; - else - num = node->children[0]; - } - - return num; + return (HullPointContents (hull, num, p)); } /* @@ -178,11 +160,11 @@ PM_PointContents (vec3_t p) #define DIST_EPSILON (0.03125) /* - PM_RecursiveHullCheck + RecursiveHullCheck */ qboolean -PM_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, - vec3_t p2, pmtrace_t *trace) +RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, + vec3_t p2, trace_t *trace) { dclipnode_t *node; mplane_t *plane; @@ -209,7 +191,7 @@ PM_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, // LordHavoc: this can be eliminated by validating in the loader... but // Mercury told me not to bother if (num < hull->firstclipnode || num > hull->lastclipnode) - Sys_Error ("PM_RecursiveHullCheck: bad node number"); + Sys_Error ("RecursiveHullCheck: bad node number"); // find the point distances node = hull->clipnodes + num; @@ -245,22 +227,22 @@ PM_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, mid[i] = p1[i] + frac * (p2[i] - p1[i]); // move up to the node - if (!PM_RecursiveHullCheck (hull, node->children[side], + if (!RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace)) return false; #ifdef PARANOID - if (PM_HullPointContents (pm_hullmodel, mid, node->children[side]) == + if (HullPointContents (pm_hullmodel, mid, node->children[side]) == CONTENTS_SOLID) { Con_Printf ("mid PointInHullSolid\n"); return false; } #endif - if (PM_HullPointContents (hull, node->children[side ^ 1], + if (HullPointContents (hull, node->children[side ^ 1], mid) != CONTENTS_SOLID) { // go past the node - return PM_RecursiveHullCheck (hull, node->children[side ^ 1], midf, p2f, + return RecursiveHullCheck (hull, node->children[side ^ 1], midf, p2f, mid, p2, trace); } @@ -281,7 +263,7 @@ PM_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, trace->plane.dist = -plane->dist; } - while (PM_HullPointContents (hull, hull->firstclipnode, + while (HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID) { // shouldn't really happen, but does occasionally frac -= 0.1; @@ -324,12 +306,12 @@ PM_TestPlayerPosition (vec3_t pos) else { VectorSubtract (pe->mins, player_maxs, mins); VectorSubtract (pe->maxs, player_mins, maxs); - hull = PM_HullForBox (mins, maxs); + hull = HullForBox (mins, maxs); } VectorSubtract (pos, pe->origin, test); - if (PM_HullPointContents (hull, hull->firstclipnode, test) == + if (HullPointContents (hull, hull->firstclipnode, test) == CONTENTS_SOLID) return false; } @@ -339,10 +321,10 @@ PM_TestPlayerPosition (vec3_t pos) /* PM_PlayerMove */ -pmtrace_t +trace_t PM_PlayerMove (vec3_t start, vec3_t end) { - pmtrace_t trace, total; + trace_t trace, total; vec3_t offset; vec3_t start_l, end_l; hull_t *hull; @@ -351,10 +333,10 @@ PM_PlayerMove (vec3_t start, vec3_t end) vec3_t mins, maxs; // fill in a default trace - memset (&total, 0, sizeof (pmtrace_t)); + memset (&total, 0, sizeof (trace_t)); total.fraction = 1; - total.ent = -1; + total.entnum = -1; VectorCopy (end, total.endpos); for (i = 0; i < pmove.numphysent; i++) { @@ -365,7 +347,7 @@ PM_PlayerMove (vec3_t start, vec3_t end) else { VectorSubtract (pe->mins, player_maxs, mins); VectorSubtract (pe->maxs, player_mins, maxs); - hull = PM_HullForBox (mins, maxs); + hull = HullForBox (mins, maxs); } // PM_HullForEntity (ent, mins, maxs, offset); @@ -375,7 +357,7 @@ PM_PlayerMove (vec3_t start, vec3_t end) VectorSubtract (end, offset, end_l); // fill in a default trace - memset (&trace, 0, sizeof (pmtrace_t)); + memset (&trace, 0, sizeof (trace_t)); trace.fraction = 1; trace.allsolid = true; @@ -383,7 +365,7 @@ PM_PlayerMove (vec3_t start, vec3_t end) VectorCopy (end, trace.endpos); // trace a line through the apropriate clipping hull - PM_RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, + RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, &trace); if (trace.allsolid) @@ -396,7 +378,7 @@ PM_PlayerMove (vec3_t start, vec3_t end) // fix trace up by the offset VectorAdd (trace.endpos, offset, trace.endpos); total = trace; - total.ent = i; + total.entnum = i; } } diff --git a/source/world.c b/source/world.c index f42b098..6e0a3be 100644 --- a/source/world.c +++ b/source/world.c @@ -52,7 +52,6 @@ line of sight checks trace->crosscontent, but bullets don't */ - typedef struct { vec3_t boxmins, boxmaxs; // enclose the test object along // entire move @@ -65,73 +64,14 @@ typedef struct { edict_t *passedict; } moveclip_t; +extern qboolean RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, + vec3_t p2, trace_t *trace); -int SV_HullPointContents (hull_t *hull, int num, vec3_t p); - -/* - HULL BOXES -*/ - - -static hull_t box_hull; -static dclipnode_t box_clipnodes[6]; -static mplane_t box_planes[6]; - -/* - SV_InitBoxHull - - Set up the planes and clipnodes so that the six floats of a bounding box - can just be stored out and get a proper hull_t structure. -*/ -void -SV_InitBoxHull (void) -{ - int i; - int side; - - box_hull.clipnodes = box_clipnodes; - box_hull.planes = box_planes; - box_hull.firstclipnode = 0; - box_hull.lastclipnode = 5; - - for (i = 0; i < 6; i++) { - box_clipnodes[i].planenum = i; - - side = i & 1; - - box_clipnodes[i].children[side] = CONTENTS_EMPTY; - if (i != 5) - box_clipnodes[i].children[side ^ 1] = i + 1; - else - box_clipnodes[i].children[side ^ 1] = CONTENTS_SOLID; - - box_planes[i].type = i >> 1; - box_planes[i].normal[i >> 1] = 1; - } - -} - - -/* - SV_HullForBox - - To keep everything totally uniform, bounding boxes are turned into small - BSP trees instead of being compared directly. -*/ -hull_t * -SV_HullForBox (vec3_t mins, vec3_t maxs) -{ - box_planes[0].dist = maxs[0]; - box_planes[1].dist = mins[0]; - box_planes[2].dist = maxs[1]; - box_planes[3].dist = mins[1]; - box_planes[4].dist = maxs[2]; - box_planes[5].dist = mins[2]; - - return &box_hull; -} +extern int HullPointContents (hull_t *hull, int num, vec3_t p); +extern void InitBoxHull (void); +extern hull_t *HullForBox (vec3_t mins, vec3_t maxs); /* SV_HullForEntity @@ -176,7 +116,7 @@ SV_HullForEntity (edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset) VectorSubtract (ent->v.v.mins, maxs, hullmins); VectorSubtract (ent->v.v.maxs, mins, hullmaxs); - hull = SV_HullForBox (hullmins, hullmaxs); + hull = HullForBox (hullmins, hullmaxs); VectorCopy (ent->v.v.origin, offset); } @@ -241,7 +181,7 @@ SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs) void SV_ClearWorld (void) { - SV_InitBoxHull (); + InitBoxHull (); memset (sv_areanodes, 0, sizeof (sv_areanodes)); sv_numareanodes = 0; @@ -425,54 +365,13 @@ SV_LinkEdict (edict_t *ent, qboolean touch_triggers) SV_TouchLinks (ent, sv_areanodes); } - - -/* - POINT TESTING IN HULLS -*/ - -#ifndef USE_INTEL_ASM - -/* - SV_HullPointContents -*/ -int -SV_HullPointContents (hull_t *hull, int num, vec3_t p) -{ - float d; - dclipnode_t *node; - mplane_t *plane; - - while (num >= 0) { - if (num < hull->firstclipnode || num > hull->lastclipnode) - SV_Error ("SV_HullPointContents: bad node number"); - - node = hull->clipnodes + num; - plane = hull->planes + node->planenum; - - if (plane->type < 3) - d = p[plane->type] - plane->dist; - else - d = DotProduct (plane->normal, p) - plane->dist; - if (d < 0) - num = node->children[1]; - else - num = node->children[0]; - } - - return num; -} - -#endif // !USE_INTEL_ASM - - /* SV_PointContents */ int SV_PointContents (vec3_t p) { - return SV_HullPointContents (&sv.worldmodel->hulls[0], 0, p); + return HullPointContents (&sv.worldmodel->hulls[0], 0, p); } //=========================================================================== @@ -498,144 +397,6 @@ SV_TestEntityPosition (edict_t *ent) return NULL; } -/* - LINE TESTING IN HULLS -*/ - -// 1/32 epsilon to keep floating point happy -#define DIST_EPSILON (0.03125) - -/* - SV_RecursiveHullCheck -*/ -qboolean -SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, - vec3_t p2, trace_t *trace) -{ - dclipnode_t *node; - mplane_t *plane; - float t1, t2; - float frac; - int i; - vec3_t mid; - int side; - float midf; - -// check for empty - if (num < 0) { - if (num != CONTENTS_SOLID) { - trace->allsolid = false; - if (num == CONTENTS_EMPTY) - trace->inopen = true; - else - trace->inwater = true; - } else - trace->startsolid = true; - return true; // empty - } - - if (num < hull->firstclipnode || num > hull->lastclipnode) - SV_Error ("SV_RecursiveHullCheck: bad node number"); - -// -// find the point distances -// - node = hull->clipnodes + num; - plane = hull->planes + node->planenum; - - if (plane->type < 3) { - t1 = p1[plane->type] - plane->dist; - t2 = p2[plane->type] - plane->dist; - } else { - t1 = DotProduct (plane->normal, p1) - plane->dist; - t2 = DotProduct (plane->normal, p2) - plane->dist; - } - -#if 1 - if (t1 >= 0 && t2 >= 0) - return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, - trace); - if (t1 < 0 && t2 < 0) - return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, - trace); -#else - if ((t1 >= DIST_EPSILON && t2 >= DIST_EPSILON) || (t2 > t1 && t1 >= 0)) - return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, - trace); - if ((t1 <= -DIST_EPSILON && t2 <= -DIST_EPSILON) || (t2 < t1 && t1 <= 0)) - return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, - trace); -#endif - -// put the crosspoint DIST_EPSILON pixels on the near side - if (t1 < 0) - frac = (t1 + DIST_EPSILON) / (t1 - t2); - else - frac = (t1 - DIST_EPSILON) / (t1 - t2); - if (frac < 0) - frac = 0; - if (frac > 1) - frac = 1; - - midf = p1f + (p2f - p1f) * frac; - for (i = 0; i < 3; i++) - mid[i] = p1[i] + frac * (p2[i] - p1[i]); - - side = (t1 < 0); - -// move up to the node - if (!SV_RecursiveHullCheck - (hull, node->children[side], p1f, midf, p1, mid, trace)) return false; - -#ifdef PARANOID - if (SV_HullPointContents (sv_hullmodel, mid, node->children[side]) - == CONTENTS_SOLID) { - Con_Printf ("mid PointInHullSolid\n"); - return false; - } -#endif - - if (SV_HullPointContents (hull, node->children[side ^ 1], mid) - != CONTENTS_SOLID) -// go past the node - return SV_RecursiveHullCheck (hull, node->children[side ^ 1], midf, p2f, - mid, p2, trace); - - if (trace->allsolid) - return false; // never got out of the solid area - -//================== -// the other side of the node is solid, this is the impact point -//================== - if (!side) { - VectorCopy (plane->normal, trace->plane.normal); - trace->plane.dist = plane->dist; - } else { - VectorSubtract (vec3_origin, plane->normal, trace->plane.normal); - trace->plane.dist = -plane->dist; - } - - while (SV_HullPointContents (hull, hull->firstclipnode, mid) - == CONTENTS_SOLID) { // shouldn't really happen, but does - // occasionally - frac -= 0.1; - if (frac < 0) { - trace->fraction = midf; - VectorCopy (mid, trace->endpos); - Con_Printf ("backup past 0\n"); - return false; - } - midf = p1f + (p2f - p1f) * frac; - for (i = 0; i < 3; i++) - mid[i] = p1[i] + frac * (p2[i] - p1[i]); - } - - trace->fraction = midf; - VectorCopy (mid, trace->endpos); - - return false; -} - /* SV_ClipMoveToEntity @@ -666,7 +427,7 @@ SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, VectorSubtract (end, offset, end_l); // trace a line through the apropriate clipping hull - SV_RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, + RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, &trace); // fix trace up by the offset @@ -844,7 +605,7 @@ SV_TestPlayerPosition (edict_t *ent, vec3_t origin) // check world first hull = &sv.worldmodel->hulls[1]; - if (SV_HullPointContents (hull, hull->firstclipnode, origin) != + if (HullPointContents (hull, hull->firstclipnode, origin) != CONTENTS_EMPTY) return sv.edicts; // check all entities @@ -876,7 +637,7 @@ SV_TestPlayerPosition (edict_t *ent, vec3_t origin) VectorSubtract (origin, offset, offset); // test the point - if (SV_HullPointContents (hull, hull->firstclipnode, offset) != + if (HullPointContents (hull, hull->firstclipnode, offset) != CONTENTS_EMPTY) return check; }