X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=world.c;h=31fe0ae4483f2643d22dea9af386528d02b535ce;hp=8e3d3a4fe4b06a42d548955e32cb361acfbf7e7d;hb=b6958185ecd637a78cccd19d9a02e8bbcb1630bd;hpb=5ac4f145047673a64b1658f0ceba1cdb836d7eb8 diff --git a/world.c b/world.c index 8e3d3a4f..31fe0ae4 100644 --- a/world.c +++ b/world.c @@ -30,7 +30,6 @@ line of sight checks trace->inopen and trace->inwater, but bullets don't */ cvar_t sv_debugmove = {CVAR_NOTIFY, "sv_debugmove", "0"}; -cvar_t sv_polygoncollisions = {CVAR_NOTIFY, "sv_polygoncollisions", "0"}; cvar_t sv_areagrid_mingridsize = {CVAR_NOTIFY, "sv_areagrid_mingridsize", "64"}; void SV_AreaStats_f(void); @@ -38,7 +37,6 @@ void SV_AreaStats_f(void); void SV_World_Init(void) { Cvar_RegisterVariable(&sv_debugmove); - Cvar_RegisterVariable(&sv_polygoncollisions); Cvar_RegisterVariable(&sv_areagrid_mingridsize); Cmd_AddCommand("sv_areastats", SV_AreaStats_f); Collision_Init(); @@ -55,9 +53,6 @@ typedef struct // size when clipping against monsters vec3_t mins2, maxs2; - // size when clipping against brush models - vec3_t hullmins, hullmaxs; - // start and end origin of move vec3_t start, end; @@ -347,8 +342,8 @@ void SV_LinkEdict (edict_t *ent, qboolean touch_triggers) if (model != NULL) { Mod_CheckLoaded(model); - if (model->type != mod_brush) - Host_Error("SOLID_BSP with non-BSP model\n"); + if (!model->TraceBox) + Host_Error("SOLID_BSP with non-collidable model\n"); if (ent->v->angles[0] || ent->v->angles[2] || ent->v->avelocity[0] || ent->v->avelocity[2]) { @@ -453,7 +448,7 @@ Handles selection or creation of a clipping hull, and offseting (and eventually rotation) of the end points ================== */ -trace_t SV_ClipMoveToEntity(edict_t *ent, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end) +trace_t SV_ClipMoveToEntity(edict_t *ent, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int movetype) { int i; trace_t trace; @@ -462,49 +457,81 @@ trace_t SV_ClipMoveToEntity(edict_t *ent, const vec3_t start, const vec3_t mins, float tempnormal[3], starttransformed[3], endtransformed[3]; float starttransformedmins[3], starttransformedmaxs[3], endtransformedmins[3], endtransformedmaxs[3]; - if ((int) ent->v->solid == SOLID_BSP) + if ((int) ent->v->solid == SOLID_BSP || movetype == MOVE_HITMODEL) { i = ent->v->modelindex; + // if the modelindex is 0, it shouldn't be SOLID_BSP! + if (i == 0) + { + Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with no model\n", NUM_FOR_EDICT(ent)); + memset(&trace, 0, sizeof(trace)); + return trace; + } if ((unsigned int) i >= MAX_MODELS) - Host_Error("SV_ClipMoveToEntity: invalid modelindex\n"); + { + Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", NUM_FOR_EDICT(ent)); + memset(&trace, 0, sizeof(trace)); + return trace; + } model = sv.models[i]; if (i != 0 && model == NULL) - Host_Error("SV_ClipMoveToEntity: invalid modelindex\n"); + { + Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", NUM_FOR_EDICT(ent)); + memset(&trace, 0, sizeof(trace)); + return trace; + } Mod_CheckLoaded(model); - if (model->type != mod_brush) + if ((int) ent->v->solid == SOLID_BSP) { - Con_Printf ("SV_ClipMoveToEntity: SOLID_BSP with a non bsp model, entity dump:\n"); - ED_Print (ent); - Host_Error ("SV_ClipMoveToEntity: SOLID_BSP with a non bsp model\n"); + if (!model->TraceBox) + { + Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with a non-collidable model\n", NUM_FOR_EDICT(ent)); + memset(&trace, 0, sizeof(trace)); + return trace; + } + if (ent->v->movetype != MOVETYPE_PUSH) + { + Con_Printf("SV_ClipMoveToEntity: edict %i: SOLID_BSP without MOVETYPE_PUSH\n", NUM_FOR_EDICT(ent)); + memset(&trace, 0, sizeof(trace)); + return trace; + } } - if (ent->v->movetype != MOVETYPE_PUSH) - Host_Error ("SV_ClipMoveToEntity: SOLID_BSP without MOVETYPE_PUSH"); + Matrix4x4_CreateFromQuakeEntity(&matrix, ent->v->origin[0], ent->v->origin[1], ent->v->origin[2], ent->v->angles[0], ent->v->angles[1], ent->v->angles[2], 1); } + else + Matrix4x4_CreateTranslate(&matrix, ent->v->origin[0], ent->v->origin[1], ent->v->origin[2]); - Matrix4x4_CreateFromQuakeEntity(&matrix, ent->v->origin[0], ent->v->origin[1], ent->v->origin[2], ent->v->angles[0], ent->v->angles[1], ent->v->angles[2], 1); Matrix4x4_Invert_Simple(&imatrix, &matrix); Matrix4x4_Transform(&imatrix, start, starttransformed); Matrix4x4_Transform(&imatrix, end, endtransformed); - VectorAdd(starttransformed, maxs, starttransformedmaxs); - VectorAdd(endtransformed, maxs, endtransformedmaxs); - VectorAdd(starttransformed, mins, starttransformedmins); - VectorAdd(endtransformed, mins, endtransformedmins); - - // FIXME: the PolygonClipTrace should go away (should all be done in model code) - if (sv_polygoncollisions.integer == 1) - Collision_PolygonClipTrace(&trace, ent, model, vec3_origin, vec3_origin, ent->v->mins, ent->v->maxs, starttransformed, mins, maxs, endtransformed); - else if (model && model->brush.TraceBox) - model->brush.TraceBox(model, &trace, starttransformedmins, starttransformedmaxs, endtransformedmins, endtransformedmaxs); +#if COLLISIONPARANOID >= 3 + Con_Printf("trans(%f %f %f -> %f %f %f, %f %f %f -> %f %f %f)", start[0], start[1], start[2], starttransformed[0], starttransformed[1], starttransformed[2], end[0], end[1], end[2], endtransformed[0], endtransformed[1], endtransformed[2]); +#endif + + if (model && model->TraceBox) + { + int frame; + frame = (int)ent->v->frame; + frame = bound(0, frame, (model->numframes - 1)); + VectorAdd(starttransformed, maxs, starttransformedmaxs); + VectorAdd(endtransformed, maxs, endtransformedmaxs); + VectorAdd(starttransformed, mins, starttransformedmins); + VectorAdd(endtransformed, mins, endtransformedmins); + model->TraceBox(model, frame, &trace, starttransformedmins, starttransformedmaxs, endtransformedmins, endtransformedmaxs, SUPERCONTENTS_SOLID); + } else - Collision_ClipTrace_Box(&trace, ent->v->mins, ent->v->maxs, starttransformed, mins, maxs, endtransformed); + Collision_ClipTrace_Box(&trace, ent->v->mins, ent->v->maxs, starttransformed, mins, maxs, endtransformed, SUPERCONTENTS_SOLID, SUPERCONTENTS_SOLID); - if (trace.fraction < 1 || trace.startsolid) - trace.ent = ent; - VectorLerp(start, trace.fraction, end, trace.endpos); - VectorCopy(trace.plane.normal, tempnormal); - Matrix4x4_Transform3x3(&matrix, tempnormal, trace.plane.normal); - // FIXME: should recalc trace.plane.dist + if (trace.fraction < 1) + { + VectorLerp(start, trace.fraction, end, trace.endpos); + VectorCopy(trace.plane.normal, tempnormal); + Matrix4x4_Transform3x3(&matrix, tempnormal, trace.plane.normal); + // FIXME: should recalc trace.plane.dist + } + else + VectorCopy(end, trace.endpos); return trace; } @@ -527,6 +554,8 @@ void SV_ClipToNode(moveclip_t *clip, link_t *list) touch->e->areagridmarknumber = sv_areagrid_marknumber; sv_areagrid_stats_entitychecks++; + // LordHavoc: this box comparison isn't much use with the high resolution areagrid + /* if (clip->boxmins[0] > touch->v->absmax[0] || clip->boxmaxs[0] < touch->v->absmin[0] || clip->boxmins[1] > touch->v->absmax[1] @@ -534,6 +563,7 @@ void SV_ClipToNode(moveclip_t *clip, link_t *list) || clip->boxmins[2] > touch->v->absmax[2] || clip->boxmaxs[2] < touch->v->absmin[2]) continue; + */ if (clip->type == MOVE_NOMONSTERS && touch->v->solid != SOLID_BSP) continue; @@ -543,6 +573,8 @@ void SV_ClipToNode(moveclip_t *clip, link_t *list) if (clip->passedict) { + if (touch == clip->passedict) + continue; if (!clip->passedict->v->size[0] && !touch->v->size[0]) continue; // points never interact if (PROG_TO_EDICT(touch->v->owner) == clip->passedict) @@ -556,8 +588,6 @@ void SV_ClipToNode(moveclip_t *clip, link_t *list) continue; } - if (touch == clip->passedict) - continue; if (touch->v->solid == SOLID_TRIGGER) { ED_Print(touch); @@ -565,43 +595,32 @@ void SV_ClipToNode(moveclip_t *clip, link_t *list) } // might interact, so do an exact clip - if (touch->v->solid == SOLID_BSP) - trace = SV_ClipMoveToEntity (touch, clip->start, clip->hullmins, clip->hullmaxs, clip->end); - else if ((int)touch->v->flags & FL_MONSTER) - trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end); + if ((int)touch->v->flags & FL_MONSTER) + trace = SV_ClipMoveToEntity(touch, clip->start, clip->mins2, clip->maxs2, clip->end, clip->type); else - trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end); + trace = SV_ClipMoveToEntity(touch, clip->start, clip->mins, clip->maxs, clip->end, clip->type); // LordHavoc: take the 'best' answers from the new trace and combine with existing data if (trace.allsolid) clip->trace.allsolid = true; if (trace.startsolid) { clip->trace.startsolid = true; - if (!clip->trace.ent) - clip->trace.ent = trace.ent; + if (clip->trace.realfraction == 1) + clip->trace.ent = touch; } if (trace.inopen) clip->trace.inopen = true; if (trace.inwater) clip->trace.inwater = true; - if (trace.fraction < clip->trace.fraction) + if (trace.realfraction < clip->trace.realfraction) { clip->trace.fraction = trace.fraction; + clip->trace.realfraction = trace.realfraction; VectorCopy(trace.endpos, clip->trace.endpos); clip->trace.plane = trace.plane; - //clip->trace.endcontents = trace.endcontents; clip->trace.ent = touch; } - // FIXME: the handling of endcontents is really broken but works well enough for point checks - if (trace.endcontents < clip->trace.endcontents || trace.endcontents == CONTENTS_SOLID) - { - // lower numbered (lava is lower than water, for example) - // contents override higher numbered contents, except for - // CONTENTS_SOLID which overrides everything - clip->trace.endcontents = trace.endcontents; - } - if (clip->trace.allsolid) - return; + clip->trace.startsupercontents |= trace.startsupercontents; } } @@ -610,10 +629,14 @@ void SV_ClipToNode(moveclip_t *clip, link_t *list) SV_Move ================== */ +#if COLLISIONPARANOID >= 1 +trace_t SV_Move_(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, edict_t *passedict) +#else trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, edict_t *passedict) +#endif { moveclip_t clip; - vec3_t bigmins, bigmaxs; + vec3_t hullmins, hullmaxs; areagrid_t *grid; int i, igrid[3], igridmins[3], igridmaxs[3]; @@ -623,60 +646,50 @@ trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const VectorCopy(end, clip.end); VectorCopy(mins, clip.mins); VectorCopy(maxs, clip.maxs); + VectorCopy(mins, clip.mins2); + VectorCopy(maxs, clip.maxs2); clip.type = type; clip.passedict = passedict; - - Collision_RoundUpToHullSize(sv.worldmodel, clip.mins, clip.maxs, clip.hullmins, clip.hullmaxs); +#if COLLISIONPARANOID >= 3 + Con_Printf("move(%f %f %f,%f %f %f)", clip.start[0], clip.start[1], clip.start[2], clip.end[0], clip.end[1], clip.end[2]); +#endif // clip to world - clip.trace = SV_ClipMoveToEntity(sv.edicts, clip.start, clip.hullmins, clip.hullmaxs, clip.end); - //if (clip.trace.allsolid) - // return clip.trace; + clip.trace = SV_ClipMoveToEntity(sv.edicts, clip.start, clip.mins, clip.maxs, clip.end, clip.type); + if (clip.trace.startsolid || clip.trace.fraction < 1) + clip.trace.ent = sv.edicts; + if (clip.type == MOVE_WORLDONLY) + return clip.trace; if (clip.type == MOVE_MISSILE) { - // LordHavoc: modified this, was = -15, now = clip.mins[i] - 15 - for (i=0 ; i<3 ; i++) + // LordHavoc: modified this, was = -15, now -= 15 + for (i = 0;i < 3;i++) { - clip.mins2[i] = clip.mins[i] - 15; - clip.maxs2[i] = clip.maxs[i] + 15; + clip.mins2[i] -= 15; + clip.maxs2[i] += 15; } } + + // get adjusted box for bmodel collisions if the world is q1bsp or hlbsp + if (sv.worldmodel && sv.worldmodel->brush.RoundUpToHullSize) + sv.worldmodel->brush.RoundUpToHullSize(sv.worldmodel, clip.mins, clip.maxs, hullmins, hullmaxs); else { - VectorCopy (clip.mins, clip.mins2); - VectorCopy (clip.maxs, clip.maxs2); + VectorCopy(clip.mins, hullmins); + VectorCopy(clip.maxs, hullmaxs); } - bigmins[0] = min(clip.mins2[0], clip.hullmins[0]); - bigmaxs[0] = max(clip.maxs2[0], clip.hullmaxs[0]); - bigmins[1] = min(clip.mins2[1], clip.hullmins[1]); - bigmaxs[1] = max(clip.maxs2[1], clip.hullmaxs[1]); - bigmins[2] = min(clip.mins2[2], clip.hullmins[2]); - bigmaxs[2] = max(clip.maxs2[2], clip.hullmaxs[2]); - // create the bounding box of the entire move - if (!sv_debugmove.integer) + for (i = 0;i < 3;i++) { - int i; - - for (i=0 ; i<3 ; i++) - { - if (clip.trace.endpos[i] > clip.start[i]) - { - clip.boxmins[i] = clip.start[i] + bigmins[i] - 1; - clip.boxmaxs[i] = clip.trace.endpos[i] + bigmaxs[i] + 1; - } - else - { - clip.boxmins[i] = clip.trace.endpos[i] + bigmins[i] - 1; - clip.boxmaxs[i] = clip.start[i] + bigmaxs[i] + 1; - } - } + clip.boxmins[i] = min(clip.start[i], clip.trace.endpos[i]) + min(hullmins[i], clip.mins2[i]) - 1; + clip.boxmaxs[i] = max(clip.start[i], clip.trace.endpos[i]) + max(hullmaxs[i], clip.maxs2[i]) + 1; } - else + + // debug override to test against everything + if (sv_debugmove.integer) { - // debug to test against everything clip.boxmins[0] = clip.boxmins[1] = clip.boxmins[2] = -999999999; clip.boxmaxs[0] = clip.boxmaxs[1] = clip.boxmaxs[2] = 999999999; } @@ -708,14 +721,34 @@ trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const return clip.trace; } -int SV_PointContents(const vec3_t point) +#if COLLISIONPARANOID >= 1 +trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, edict_t *passedict) { -#if 1 - return SV_Move(point, vec3_origin, vec3_origin, point, MOVE_NOMONSTERS, NULL).endcontents; -#else - if (sv.worldmodel && sv.worldmodel->brush.PointContents) - return sv.worldmodel->brush.PointContents(sv.worldmodel, point); - return CONTENTS_SOLID; + int endstuck; + trace_t trace; + vec3_t temp; + trace = SV_Move_(start, mins, maxs, end, type, passedict); + if (passedict) + { + VectorCopy(trace.endpos, temp); + endstuck = SV_Move_(temp, mins, maxs, temp, type, passedict).startsolid; +#if COLLISIONPARANOID < 3 + if (trace.startsolid || endstuck) #endif + Con_Printf("%s{e%i:%f %f %f:%f %f %f:%f:%f %f %f%s%s}\n", (trace.startsolid || endstuck) ? "\002" : "", passedict ? passedict - sv.edicts : -1, passedict->v->origin[0], passedict->v->origin[1], passedict->v->origin[2], end[0] - passedict->v->origin[0], end[1] - passedict->v->origin[1], end[2] - passedict->v->origin[2], trace.fraction, trace.endpos[0] - passedict->v->origin[0], trace.endpos[1] - passedict->v->origin[1], trace.endpos[2] - passedict->v->origin[2], trace.startsolid ? " startstuck" : "", endstuck ? " endstuck" : ""); + } + return trace; } +#endif + +int SV_PointSuperContents(const vec3_t point) +{ + return SV_Move(point, vec3_origin, vec3_origin, point, MOVE_NOMONSTERS, NULL).startsupercontents; +} + +int SV_PointQ1Contents(const vec3_t point) +{ + return Mod_Q1BSP_NativeContentsFromSuperContents(NULL, SV_PointSuperContents(point)); +} +