}
}
-void Collision_TracePointBrushFloat(trace_t *trace, const vec3_t point, const colbrushf_t *thatbrush)
+qboolean Collision_PointInsideBrushFloat(const vec3_t point, const colbrushf_t *brush)
{
int nplane;
const colplanef_t *plane;
- for (nplane = 0, plane = thatbrush->planes;nplane < thatbrush->numplanes;nplane++, plane++)
+ if (!BoxesOverlap(point, point, brush->mins, brush->maxs))
+ return false;
+ for (nplane = 0, plane = brush->planes;nplane < brush->numplanes;nplane++, plane++)
if (DotProduct(plane->normal, point) > plane->dist)
- return;
+ return false;
+ return true;
+}
+
+void Collision_TracePointBrushFloat(trace_t *trace, const vec3_t point, const colbrushf_t *thatbrush)
+{
+ if (!Collision_PointInsideBrushFloat(point, thatbrush))
+ return;
trace->startsupercontents |= thatbrush->supercontents;
if (trace->hitsupercontentsmask & thatbrush->supercontents)
void Collision_TraceLinePolygonFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numpoints, const float *points, int supercontents);
void Collision_TraceLineTriangleMeshFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numtriangles, const int *element3i, const float *vertex3f, int supercontents, int q3surfaceflags, texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs);
void Collision_TracePointBrushFloat(trace_t *trace, const vec3_t point, const colbrushf_t *thatbrush);
+qboolean Collision_PointInsideBrushFloat(const vec3_t point, const colbrushf_t *brush);
void Collision_TraceBrushPolygonTransformFloat(trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, int numpoints, const float *points, const matrix4x4_t *polygonmatrixstart, const matrix4x4_t *polygonmatrixend, int supercontents, int q3surfaceflags, texture_t *texture);
loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
loadmodel->DrawLight = R_Q1BSP_DrawLight;
loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox;
+ loadmodel->PointSuperContents = NULL;
loadmodel->num_surfaces = 1;
loadmodel->nummodelsurfaces = loadmodel->num_surfaces;
loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
loadmodel->DrawLight = R_Q1BSP_DrawLight;
loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox;
+ loadmodel->PointSuperContents = NULL;
if (LittleLong(pinmodel->num_tris) < 1 || LittleLong(pinmodel->num_tris) > 65536)
Host_Error ("%s has invalid number of triangles: %i", loadmodel->name, LittleLong(pinmodel->num_tris));
loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
loadmodel->DrawLight = R_Q1BSP_DrawLight;
loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox;
+ loadmodel->PointSuperContents = NULL;
loadmodel->synctype = ST_RAND;
// convert model flags to EF flags (MF_ROCKET becomes EF_ROCKET, etc)
i = LittleLong (pinmodel->flags);
loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
loadmodel->DrawLight = R_Q1BSP_DrawLight;
loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox;
+ loadmodel->PointSuperContents = NULL;
loadmodel->numframes = pheader->numscenes;
loadmodel->num_surfaces = pheader->numshaders;
loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
loadmodel->DrawLight = R_Q1BSP_DrawLight;
loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox;
+ loadmodel->PointSuperContents = NULL;
// model bbox
for (i = 0;i < 3;i++)
loadmodel->DrawShadowVolume = R_Q1BSP_DrawShadowVolume;
loadmodel->DrawLight = R_Q1BSP_DrawLight;
loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox;
+ loadmodel->PointSuperContents = NULL;
loadmodel->synctype = ST_RAND;
FS_StripExtension(loadmodel->name, animname, sizeof(animname));
//#if COLLISIONPARANOID < 2
static int Mod_Q1BSP_RecursiveHullCheckPoint(RecursiveHullCheckTraceInfo_t *t, int num)
{
+ mplane_t *plane;
+ mclipnode_t *nodes = t->hull->clipnodes;
+ mplane_t *planes = t->hull->planes;
+ vec3_t point;
+ VectorCopy(t->start, point);
while (num >= 0)
- num = t->hull->clipnodes[num].children[(t->hull->planes[t->hull->clipnodes[num].planenum].type < 3 ? t->start[t->hull->planes[t->hull->clipnodes[num].planenum].type] : DotProduct(t->hull->planes[t->hull->clipnodes[num].planenum].normal, t->start)) < t->hull->planes[t->hull->clipnodes[num].planenum].dist];
+ {
+ plane = planes + nodes[num].planenum;
+ num = nodes[num].children[(plane->type < 3 ? point[plane->type] : DotProduct(plane->normal, point)) < plane->dist];
+ }
num = Mod_Q1BSP_SuperContentsFromNativeContents(NULL, num);
t->trace->startsupercontents |= num;
if (num & SUPERCONTENTS_LIQUIDSMASK)
#endif
}
+static int Mod_Q1BSP_PointSuperContents(struct model_s *model, int frame, const vec3_t point)
+{
+ int num = 0;
+ mplane_t *plane;
+ mclipnode_t *nodes = model->brushq1.hulls[0].clipnodes;
+ mplane_t *planes = model->brushq1.hulls[0].planes;
+ while (num >= 0)
+ {
+ plane = planes + nodes[num].planenum;
+ num = nodes[num].children[(plane->type < 3 ? point[plane->type] : DotProduct(plane->normal, point)) < plane->dist];
+ }
+ return Mod_Q1BSP_SuperContentsFromNativeContents(NULL, num);
+}
+
void Collision_ClipTrace_Box(trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int boxsupercontents, int boxq3surfaceflags, texture_t *boxtexture)
{
#if 1
mod->soundfromcenter = true;
mod->TraceBox = Mod_Q1BSP_TraceBox;
+ mod->PointSuperContents = Mod_Q1BSP_PointSuperContents;
mod->brush.TraceLineOfSight = Mod_Q1BSP_TraceLineOfSight;
mod->brush.SuperContentsFromNativeContents = Mod_Q1BSP_SuperContentsFromNativeContents;
mod->brush.NativeContentsFromSuperContents = Mod_Q1BSP_NativeContentsFromSuperContents;
colbrushf_t *brush;
// find which leaf the point is in
while (node->plane)
- node = node->children[DotProduct(point, node->plane->normal) < node->plane->dist];
+ node = node->children[(node->plane->type < 3 ? point[node->plane->type] : DotProduct(point, node->plane->normal)) < node->plane->dist];
// point trace the brushes
leaf = (mleaf_t *)node;
for (i = 0;i < leaf->numleafbrushes;i++)
}
}
+static int Mod_Q3BSP_PointSuperContents(struct model_s *model, int frame, const vec3_t point)
+{
+ int i;
+ int supercontents = 0;
+ q3mbrush_t *brush;
+ // test if the point is inside each brush
+ if (model->brush.submodel)
+ {
+ // submodels are effectively one leaf
+ for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
+ if (brush->colbrushf && Collision_PointInsideBrushFloat(point, brush->colbrushf))
+ supercontents |= brush->colbrushf->supercontents;
+ }
+ else
+ {
+ mnode_t *node = model->brush.data_nodes;
+ mleaf_t *leaf;
+ // find which leaf the point is in
+ while (node->plane)
+ node = node->children[(node->plane->type < 3 ? point[node->plane->type] : DotProduct(point, node->plane->normal)) < node->plane->dist];
+ leaf = (mleaf_t *)node;
+ // now check the brushes in the leaf
+ for (i = 0;i < leaf->numleafbrushes;i++)
+ {
+ brush = model->brush.data_brushes + leaf->firstleafbrush[i];
+ if (brush->colbrushf && Collision_PointInsideBrushFloat(point, brush->colbrushf))
+ supercontents |= brush->colbrushf->supercontents;
+ }
+ }
+ return supercontents;
+}
+
static int Mod_Q3BSP_SuperContentsFromNativeContents(model_t *model, int nativecontents)
{
int supercontents = 0;
mod->soundfromcenter = true;
mod->TraceBox = Mod_Q3BSP_TraceBox;
+ mod->PointSuperContents = Mod_Q3BSP_PointSuperContents;
mod->brush.TraceLineOfSight = Mod_Q1BSP_TraceLineOfSight;
mod->brush.SuperContentsFromNativeContents = Mod_Q3BSP_SuperContentsFromNativeContents;
mod->brush.NativeContentsFromSuperContents = Mod_Q3BSP_NativeContentsFromSuperContents;
void(*DrawLight)(struct entity_render_s *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs);
// trace a box against this model
void (*TraceBox)(struct model_s *model, int frame, struct trace_s *trace, const vec3_t start, const vec3_t boxmins, const vec3_t boxmaxs, const vec3_t end, int hitsupercontentsmask);
+ // find the supercontents value at a point in this model
+ int (*PointSuperContents)(struct model_s *model, int frame, const vec3_t point);
// fields belonging to some types of model
model_sprite_t sprite;
model_brush_t brush;
// traces a box move against worldmodel and all entities in the specified area
trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask);
-#define SV_PointSuperContents(point) (SV_Move((point), vec3_origin, vec3_origin, (point), sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL, 0).startsupercontents)
+int SV_PointSuperContents(const vec3_t point);
void SV_FlushBroadcastMessages(void);
void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
}
#endif
+int SV_PointSuperContents(const vec3_t point)
+{
+ int supercontents = 0;
+ int i;
+ prvm_edict_t *touch;
+ vec3_t transformed;
+ // matrices to transform into/out of other entity's space
+ matrix4x4_t matrix, imatrix;
+ // model of other entity
+ model_t *model;
+ unsigned int modelindex;
+ int frame;
+ // list of entities to test for collisions
+ int numtouchedicts;
+ prvm_edict_t *touchedicts[MAX_EDICTS];
+
+ // get world supercontents at this point
+ if (sv.worldmodel && sv.worldmodel->PointSuperContents)
+ supercontents = sv.worldmodel->PointSuperContents(sv.worldmodel, 0, point);
+
+ // if sv_gameplayfix_swiminbmodels is off we're done
+ if (!sv_gameplayfix_swiminbmodels.integer)
+ return supercontents;
+
+ // get list of entities at this point
+ numtouchedicts = World_EntitiesInBox(&sv.world, point, point, MAX_EDICTS, touchedicts);
+ if (numtouchedicts > MAX_EDICTS)
+ {
+ // this never happens
+ Con_Printf("SV_EntitiesInBox returned %i edicts, max was %i\n", numtouchedicts, MAX_EDICTS);
+ numtouchedicts = MAX_EDICTS;
+ }
+ for (i = 0;i < numtouchedicts;i++)
+ {
+ touch = touchedicts[i];
+
+ // we only care about SOLID_BSP for pointcontents
+ if (touch->fields.server->solid != SOLID_BSP)
+ continue;
+
+ // might interact, so do an exact clip
+ modelindex = (unsigned int)touch->fields.server->modelindex;
+ if (modelindex >= MAX_MODELS)
+ continue;
+ model = sv.models[(int)touch->fields.server->modelindex];
+ if (!model || !model->PointSuperContents)
+ continue;
+ Matrix4x4_CreateFromQuakeEntity(&matrix, touch->fields.server->origin[0], touch->fields.server->origin[1], touch->fields.server->origin[2], touch->fields.server->angles[0], touch->fields.server->angles[1], touch->fields.server->angles[2], 1);
+ Matrix4x4_Invert_Simple(&imatrix, &matrix);
+ Matrix4x4_Transform(&imatrix, point, transformed);
+ frame = (int)touch->fields.server->frame;
+ supercontents |= model->PointSuperContents(model, bound(0, frame, (model->numframes - 1)), transformed);
+ }
+
+ return supercontents;
+}
+
/*
===============================================================================