void SV_TouchAreaGrid(edict_t *ent)
{
- link_t *l, *next;
+ link_t *l;
edict_t *touch;
areagrid_t *grid;
int old_self, old_other, igrid[3], igridmins[3], igridmaxs[3];
+ int i, numtouchedicts;
+ unsigned short touchedictnumbers[MAX_EDICTS];
sv_areagrid_marknumber++;
igridmins[0] = (int) ((ent->v->absmin[0] + sv_areagrid_bias[0]) * sv_areagrid_scale[0]);
igridmaxs[1] = min(AREA_GRID, igridmaxs[1]);
//igridmaxs[2] = min(AREA_GRID, igridmaxs[2]);
- for (l = sv_areagrid_outside.trigger_edicts.next;l != &sv_areagrid_outside.trigger_edicts;l = next)
+ // build a list of edicts to touch, because the link loop can be corrupted
+ // by SV_IncreaseEdicts called during touch functions
+ numtouchedicts = 0;
+ for (l = sv_areagrid_outside.trigger_edicts.next;l != &sv_areagrid_outside.trigger_edicts;l = l->next)
+ touchedictnumbers[numtouchedicts++] = l->entitynumber;
+
+ for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
{
- next = l->next;
- touch = EDICT_NUM(l->entitynumber);
+ grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0];
+ for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
+ for (l = grid->trigger_edicts.next;l != &grid->trigger_edicts;l = l->next)
+ touchedictnumbers[numtouchedicts++] = l->entitynumber;
+ }
+
+ old_self = pr_global_struct->self;
+ old_other = pr_global_struct->other;
+ for (i = 0;i < numtouchedicts && !ent->e->free;i++)
+ {
+ touch = EDICT_NUM_UNSIGNED(touchedictnumbers[i]);
if (ent->v->absmin[0] > touch->v->absmax[0]
|| ent->v->absmax[0] < touch->v->absmin[0]
|| ent->v->absmin[1] > touch->v->absmax[1]
continue;
if (!touch->v->touch || touch->v->solid != SOLID_TRIGGER)
continue;
- old_self = pr_global_struct->self;
- old_other = pr_global_struct->other;
-
pr_global_struct->self = EDICT_TO_PROG(touch);
pr_global_struct->other = EDICT_TO_PROG(ent);
pr_global_struct->time = sv.time;
PR_ExecuteProgram (touch->v->touch, "");
-
- pr_global_struct->self = old_self;
- pr_global_struct->other = old_other;
- }
-
- for (igrid[1] = igridmins[1];igrid[1] < igridmaxs[1];igrid[1]++)
- {
- grid = sv_areagrid + igrid[1] * AREA_GRID + igridmins[0];
- for (igrid[0] = igridmins[0];igrid[0] < igridmaxs[0];igrid[0]++, grid++)
- {
- for (l = grid->trigger_edicts.next;l != &grid->trigger_edicts;l = next)
- {
- next = l->next;
- touch = EDICT_NUM(l->entitynumber);
- if (touch->e->areagridmarknumber == sv_areagrid_marknumber)
- continue;
- touch->e->areagridmarknumber = sv_areagrid_marknumber;
- if (ent->v->absmin[0] > touch->v->absmax[0]
- || ent->v->absmax[0] < touch->v->absmin[0]
- || ent->v->absmin[1] > touch->v->absmax[1]
- || ent->v->absmax[1] < touch->v->absmin[1]
- || ent->v->absmin[2] > touch->v->absmax[2]
- || ent->v->absmax[2] < touch->v->absmin[2])
- continue;
- // LordHavoc: id bug that won't be fixed: triggers do not ignore their owner like solid objects do
- if (touch == ent)
- continue;
- if (!touch->v->touch || touch->v->solid != SOLID_TRIGGER)
- continue;
- old_self = pr_global_struct->self;
- old_other = pr_global_struct->other;
-
- pr_global_struct->self = EDICT_TO_PROG(touch);
- pr_global_struct->other = EDICT_TO_PROG(ent);
- pr_global_struct->time = sv.time;
- PR_ExecuteProgram (touch->v->touch, "");
-
- pr_global_struct->self = old_self;
- pr_global_struct->other = old_other;
- }
- }
}
+ pr_global_struct->self = old_self;
+ pr_global_struct->other = old_other;
}
void SV_LinkEdict_AreaGrid(edict_t *ent)
if (ent->v->solid == SOLID_BSP)
{
- if (ent->v->modelindex < 0 || ent->v->modelindex > MAX_MODELS)
- Host_Error("SOLID_BSP with invalid modelindex!\n");
- model = sv.models[(int) ent->v->modelindex];
+ int modelindex = ent->v->modelindex;
+ if (modelindex < 0 || modelindex > MAX_MODELS)
+ {
+ Con_DPrintf("edict %i: SOLID_BSP with invalid modelindex!\n", NUM_FOR_EDICT(ent));
+ modelindex = 0;
+ }
+ model = sv.models[modelindex];
if (model != NULL)
{
Mod_CheckLoaded(model);
if (!model->TraceBox)
- Host_Error("SOLID_BSP with non-collidable model\n");
+ Con_DPrintf("edict %i: SOLID_BSP with non-collidable model\n", NUM_FOR_EDICT(ent));
if (ent->v->angles[0] || ent->v->angles[2] || ent->v->avelocity[0] || ent->v->avelocity[2])
{
*/
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;
model_t *model = NULL;
matrix4x4_t matrix, imatrix;
float tempnormal[3], starttransformed[3], endtransformed[3];
float starttransformedmins[3], starttransformedmaxs[3], endtransformedmins[3], endtransformedmaxs[3];
+ memset(&trace, 0, sizeof(trace));
+ trace.fraction = trace.realfraction = 1;
+ VectorCopy(end, trace.endpos);
+
if ((int) ent->v->solid == SOLID_BSP || movetype == MOVE_HITMODEL)
{
- i = ent->v->modelindex;
- if ((unsigned int) i >= MAX_MODELS)
- Host_Error("SV_ClipMoveToEntity: invalid modelindex\n");
- model = sv.models[i];
- if (i != 0 && model == NULL)
- Host_Error("SV_ClipMoveToEntity: invalid modelindex\n");
+ unsigned int modelindex = ent->v->modelindex;
+ // if the modelindex is 0, it shouldn't be SOLID_BSP!
+ if (modelindex == 0)
+ {
+ Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with no model\n", NUM_FOR_EDICT(ent));
+ return trace;
+ }
+ if (modelindex >= MAX_MODELS)
+ {
+ Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", NUM_FOR_EDICT(ent));
+ return trace;
+ }
+ model = sv.models[modelindex];
+ if (modelindex != 0 && model == NULL)
+ {
+ Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with invalid modelindex\n", NUM_FOR_EDICT(ent));
+ return trace;
+ }
Mod_CheckLoaded(model);
if ((int) ent->v->solid == SOLID_BSP)
{
if (!model->TraceBox)
{
- Con_Printf("SV_ClipMoveToEntity: SOLID_BSP with a non-collidable model, entity dump:\n");
- ED_Print(ent);
- Host_Error("SV_ClipMoveToEntity: SOLID_BSP with a non-collidable model\n");
+ Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP with a non-collidable model\n", NUM_FOR_EDICT(ent));
+ return trace;
}
- if (ent->v->movetype != MOVETYPE_PUSH)
- Host_Error("SV_ClipMoveToEntity: SOLID_BSP without MOVETYPE_PUSH");
+ //if (ent->v->movetype != MOVETYPE_PUSH)
+ //{
+ // Con_DPrintf("SV_ClipMoveToEntity: edict %i: SOLID_BSP without MOVETYPE_PUSH\n", NUM_FOR_EDICT(ent));
+ // return trace;
+ //}
}
+ 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);
else
Collision_ClipTrace_Box(&trace, ent->v->mins, ent->v->maxs, starttransformed, mins, maxs, endtransformed, SUPERCONTENTS_SOLID, SUPERCONTENTS_SOLID);
- if (trace.fraction < 1 || trace.startsolid)
+ if (trace.fraction < 1)
{
- trace.ent = ent;
VectorLerp(start, trace.fraction, end, trace.endpos);
VectorCopy(trace.plane.normal, tempnormal);
Matrix4x4_Transform3x3(&matrix, tempnormal, trace.plane.normal);
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]
|| 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;
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)
continue;
}
- if (touch == clip->passedict)
- continue;
if (touch->v->solid == SOLID_TRIGGER)
{
ED_Print(touch);
}
// might interact, so do an exact clip
- if (touch->v->solid == SOLID_BSP)
- trace = SV_ClipMoveToEntity(touch, clip->start, clip->mins, clip->maxs, clip->end, clip->type);
- else if ((int)touch->v->flags & FL_MONSTER)
+ 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, clip->type);
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;
+ // don't set this except on the world, because it can easily confuse
+ // monsters underwater if there's a bmodel involved in the trace
+ // (inopen && inwater is how they check water visibility)
+ //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.ent = touch;
}
clip->trace.startsupercontents |= trace.startsupercontents;
- //if (clip->trace.allsolid)
- // return;
}
}
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 hullmins, hullmaxs;
areagrid_t *grid;
int i, igrid[3], igridmins[3], igridmaxs[3];
+ // if the passedict is world, make it NULL (to avoid two checks each time)
+ if (passedict == sv.edicts)
+ passedict = NULL;
+
memset(&clip, 0, sizeof(moveclip_t));
VectorCopy(start, clip.start);
// clip to world
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)
- //if (clip.trace.allsolid)
return clip.trace;
if (clip.type == MOVE_MISSILE)
return clip.trace;
}
+#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)
+{
+ 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;
+ return SV_Move(point, vec3_origin, vec3_origin, point, sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL).startsupercontents;
}
int SV_PointQ1Contents(const vec3_t point)