From 93bce2dbe64b734e74d721164369943fffe7e397 Mon Sep 17 00:00:00 2001 From: havoc Date: Sat, 19 Jul 2003 17:53:04 +0000 Subject: [PATCH] added SV_PointContents moved PointContents and FindNonSolidLocation function pointers into brush from brushq1 added TraceBox function pointer to brush (but no implementations of it yet) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3291 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_collision.c | 18 ++++++++++++------ model_brush.c | 6 +++--- model_shared.h | 11 ++++++++--- pr_cmds.c | 2 +- sv_main.c | 25 ++++++++++++++++++++----- sv_move.c | 4 ++-- sv_phys.c | 8 ++++---- world.c | 12 +++++++++++- world.h | 2 ++ 9 files changed, 63 insertions(+), 25 deletions(-) diff --git a/cl_collision.c b/cl_collision.c index dfbc0b80..5b85035f 100644 --- a/cl_collision.c +++ b/cl_collision.c @@ -42,7 +42,10 @@ float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t if (hitent) *hitent = NULL; Mod_CheckLoaded(cl.worldmodel); - Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end); + if (cl.worldmodel && cl.worldmodel->brush.TraceBox) + cl.worldmodel->brush.TraceBox(cl.worldmodel, vec3_origin, vec3_origin, &trace, NULL, start, vec3_origin, vec3_origin, end); + else + Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end); if (impact) VectorCopy (trace.endpos, impact); @@ -71,7 +74,10 @@ float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2]) continue; - Collision_ClipTrace(&trace, ent, ent->model, ent->origin, ent->angles, ent->mins, ent->maxs, start, vec3_origin, vec3_origin, end); + if (ent->model && ent->model->brush.TraceBox) + ent->model->brush.TraceBox(ent->model, ent->origin, ent->angles, &trace, NULL, start, vec3_origin, vec3_origin, end); + else + Collision_ClipTrace(&trace, ent, ent->model, ent->origin, ent->angles, ent->mins, ent->maxs, start, vec3_origin, vec3_origin, end); if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac) { @@ -93,15 +99,15 @@ float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius) { // FIXME: check multiple brush models - if (cl.worldmodel && cl.worldmodel->brushq1.FindNonSolidLocation) - cl.worldmodel->brushq1.FindNonSolidLocation(cl.worldmodel, in, out, radius); + if (cl.worldmodel && cl.worldmodel->brush.FindNonSolidLocation) + cl.worldmodel->brush.FindNonSolidLocation(cl.worldmodel, in, out, radius); } int CL_PointContents(const vec3_t p) { // FIXME: check multiple brush models - if (cl.worldmodel && cl.worldmodel->brushq1.PointContents) - return cl.worldmodel->brushq1.PointContents(cl.worldmodel, p); + if (cl.worldmodel && cl.worldmodel->brush.PointContents) + return cl.worldmodel->brush.PointContents(cl.worldmodel, p); return CONTENTS_EMPTY; } diff --git a/model_brush.c b/model_brush.c index a0a3a5b3..1e170420 100644 --- a/model_brush.c +++ b/model_brush.c @@ -2678,9 +2678,9 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer) Host_Error("Mod_Q1BSP_Load: %s has wrong version number(%i should be %i(Quake) or 30(HalfLife))", mod->name, i, BSPVERSION); mod->brushq1.ishlbsp = i == 30; - mod->brushq1.FindNonSolidLocation = Mod_Q1BSP_FindNonSolidLocation; + mod->brush.FindNonSolidLocation = Mod_Q1BSP_FindNonSolidLocation; + mod->brush.PointContents = Mod_Q1BSP_PointContents; mod->brushq1.PointInLeaf = Mod_Q1BSP_PointInLeaf; - mod->brushq1.PointContents = Mod_Q1BSP_PointContents; mod->brushq1.LeafPVS = Mod_Q1BSP_LeafPVS; mod->brushq1.BuildPVSTextureChains = Mod_Q1BSP_BuildPVSTextureChains; @@ -3548,7 +3548,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l) && out->type != Q3FACETYPE_MESH && out->type != Q3FACETYPE_FLARE) { - Con_Printf("Mod_Q3BSP_LoadFaces: face #%i: unknown face type %i\n", i, n); + Con_Printf("Mod_Q3BSP_LoadFaces: face #%i: unknown face type %i\n", i, out->type); out->type = 0; // error continue; } diff --git a/model_shared.h b/model_shared.h index e9027c9e..d3f12f95 100644 --- a/model_shared.h +++ b/model_shared.h @@ -124,7 +124,10 @@ model_sprite_t; typedef struct model_brush_s { - char *entities; + char *entities; + void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius); + int (*PointContents)(struct model_s *model, const float *p); + void (*TraceBox)(struct model_s *model, const vec3_t corigin, const vec3_t cangles, void *trace, const void *cent, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end); } model_brush_t; @@ -216,18 +219,18 @@ typedef struct model_brushq1_s int light_scalebit; float light_ambient; - void (*FindNonSolidLocation)(struct model_s *model, const vec3_t in, vec3_t out, vec_t radius); mleaf_t *(*PointInLeaf)(struct model_s *model, const float *p); - int (*PointContents)(struct model_s *model, const float *p); qbyte *(*LeafPVS)(struct model_s *model, mleaf_t *leaf); void (*BuildPVSTextureChains)(struct model_s *model); } model_brushq1_t; +/* MSVC can't compile empty structs, so this is commented out for now typedef struct model_brushq2_s { } model_brushq2_t; +*/ typedef struct q3mtexture_s { @@ -464,7 +467,9 @@ typedef struct model_s model_sprite_t sprite; model_brush_t brush; model_brushq1_t brushq1; + /* MSVC can't handle an empty struct, so this is commented out for now model_brushq2_t brushq2; + */ model_brushq3_t brushq3; } model_t; diff --git a/pr_cmds.c b/pr_cmds.c index 07159201..f49b2d20 100644 --- a/pr_cmds.c +++ b/pr_cmds.c @@ -1497,7 +1497,7 @@ PF_pointcontents */ void PF_pointcontents (void) { - G_FLOAT(OFS_RETURN) = sv.worldmodel->brushq1.PointContents(sv.worldmodel, G_VECTOR(OFS_PARM0)); + G_FLOAT(OFS_RETURN) = SV_PointContents(G_VECTOR(OFS_PARM0)); } /* diff --git a/sv_main.c b/sv_main.c index e4492815..74fd70ba 100644 --- a/sv_main.c +++ b/sv_main.c @@ -605,7 +605,10 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) testorigin[1] = lhrandom(entmins[1], entmaxs[1]); testorigin[2] = lhrandom(entmins[2], entmaxs[2]); - Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); + if (sv.worldmodel && sv.worldmodel->brush.TraceBox) + sv.worldmodel->brush.TraceBox(sv.worldmodel, vec3_origin, vec3_origin, &trace, testeye, vec3_origin, vec3_origin, testorigin); + else + Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); if (trace.fraction == 1) client->visibletime[e] = realtime + 1; @@ -616,7 +619,10 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) testorigin[1] = bound(entmins[1], testeye[1], entmaxs[1]); testorigin[2] = bound(entmins[2], testeye[2], entmaxs[2]); - Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); + if (sv.worldmodel && sv.worldmodel->brush.TraceBox) + sv.worldmodel->brush.TraceBox(sv.worldmodel, vec3_origin, vec3_origin, &trace, testeye, vec3_origin, vec3_origin, testorigin); + else + Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); if (trace.fraction == 1) client->visibletime[e] = realtime + 1; @@ -982,7 +988,10 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) testorigin[0] = (entmins[0] + entmaxs[0]) * 0.5f; testorigin[1] = (entmins[1] + entmaxs[1]) * 0.5f; testorigin[2] = (entmins[2] + entmaxs[2]) * 0.5f; - Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); + if (sv.worldmodel && sv.worldmodel->brush.TraceBox) + sv.worldmodel->brush.TraceBox(sv.worldmodel, vec3_origin, vec3_origin, &trace, NULL, testeye, vec3_origin, vec3_origin, testorigin); + else + Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); if (trace.fraction == 1) client->visibletime[e] = realtime + 1; else @@ -991,7 +1000,10 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) testorigin[0] = lhrandom(entmins[0], entmaxs[0]); testorigin[1] = lhrandom(entmins[1], entmaxs[1]); testorigin[2] = lhrandom(entmins[2], entmaxs[2]); - Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); + if (sv.worldmodel && sv.worldmodel->brush.TraceBox) + sv.worldmodel->brush.TraceBox(sv.worldmodel, vec3_origin, vec3_origin, &trace, NULL, testeye, vec3_origin, vec3_origin, testorigin); + else + Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); if (trace.fraction == 1) client->visibletime[e] = realtime + 1; else @@ -1002,7 +1014,10 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) testorigin[0] = lhrandom(lightmins[0], lightmaxs[0]); testorigin[1] = lhrandom(lightmins[1], lightmaxs[1]); testorigin[2] = lhrandom(lightmins[2], lightmaxs[2]); - Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); + if (sv.worldmodel && sv.worldmodel->brush.TraceBox) + sv.worldmodel->brush.TraceBox(sv.worldmodel, vec3_origin, vec3_origin, &trace, NULL, testeye, vec3_origin, vec3_origin, testorigin); + else + Collision_ClipTrace(&trace, NULL, sv.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, testeye, vec3_origin, vec3_origin, testorigin); if (trace.fraction == 1) client->visibletime[e] = realtime + 1; else diff --git a/sv_move.c b/sv_move.c index 88e4ce6c..8bb9b75b 100644 --- a/sv_move.c +++ b/sv_move.c @@ -51,7 +51,7 @@ qboolean SV_CheckBottom (edict_t *ent) { start[0] = x ? maxs[0] : mins[0]; start[1] = y ? maxs[1] : mins[1]; - if (sv.worldmodel->brushq1.PointContents(sv.worldmodel, start) != CONTENTS_SOLID) + if (SV_PointContents(start) != CONTENTS_SOLID) goto realcheck; } @@ -138,7 +138,7 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink) if (trace.fraction == 1) { VectorCopy(trace.endpos, traceendpos); - if ( ((int)ent->v->flags & FL_SWIM) && sv.worldmodel->brushq1.PointContents(sv.worldmodel, traceendpos) == CONTENTS_EMPTY ) + if (((int)ent->v->flags & FL_SWIM) && SV_PointContents(traceendpos) == CONTENTS_EMPTY ) return false; // swim monster left water VectorCopy (traceendpos, ent->v->origin); diff --git a/sv_phys.c b/sv_phys.c index ad5aa985..76959a5b 100644 --- a/sv_phys.c +++ b/sv_phys.c @@ -854,18 +854,18 @@ qboolean SV_CheckWater (edict_t *ent) ent->v->waterlevel = 0; ent->v->watertype = CONTENTS_EMPTY; - cont = sv.worldmodel->brushq1.PointContents(sv.worldmodel, point); + cont = SV_PointContents(point); if (cont <= CONTENTS_WATER) { ent->v->watertype = cont; ent->v->waterlevel = 1; point[2] = ent->v->origin[2] + (ent->v->mins[2] + ent->v->maxs[2])*0.5; - cont = sv.worldmodel->brushq1.PointContents(sv.worldmodel, point); + cont = SV_PointContents(point); if (cont <= CONTENTS_WATER) { ent->v->waterlevel = 2; point[2] = ent->v->origin[2] + ent->v->view_ofs[2]; - cont = sv.worldmodel->brushq1.PointContents(sv.worldmodel, point); + cont = SV_PointContents(point); if (cont <= CONTENTS_WATER) ent->v->waterlevel = 3; } @@ -1136,7 +1136,7 @@ SV_CheckWaterTransition void SV_CheckWaterTransition (edict_t *ent) { int cont; - cont = sv.worldmodel->brushq1.PointContents(sv.worldmodel, ent->v->origin); + cont = SV_PointContents(ent->v->origin); if (!ent->v->watertype) { // just spawned here diff --git a/world.c b/world.c index 7af2672b..defb53c3 100644 --- a/world.c +++ b/world.c @@ -479,7 +479,10 @@ trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t max Host_Error ("SV_ClipMoveToEntity: SOLID_BSP without MOVETYPE_PUSH"); } - if (sv_polygoncollisions.integer && (mins[0] != maxs[0] || mins[1] != maxs[1] || mins[2] != maxs[2])) + if (model && model->brush.TraceBox) + model->brush.TraceBox(model, ent->v->origin, ent->v->angles, &trace, ent, start, mins, maxs, end); + // FIXME: these should go away + else if (sv_polygoncollisions.integer && (mins[0] != maxs[0] || mins[1] != maxs[1] || mins[2] != maxs[2])) Collision_PolygonClipTrace(&trace, ent, model, ent->v->origin, ent->v->angles, ent->v->mins, ent->v->maxs, start, mins, maxs, end); else Collision_ClipTrace(&trace, ent, model, ent->v->origin, ent->v->angles, ent->v->mins, ent->v->maxs, start, mins, maxs, end); @@ -704,3 +707,10 @@ trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, e return clip.trace; } +int SV_PointContents(const vec3_t point) +{ + if (sv.worldmodel && sv.worldmodel->brush.PointContents) + return sv.worldmodel->brush.PointContents(sv.worldmodel, point); + return CONTENTS_SOLID; +} + diff --git a/world.h b/world.h index eaea6224..10419be7 100644 --- a/world.h +++ b/world.h @@ -56,5 +56,7 @@ int SV_TestEntityPosition (edict_t *ent); // passedict is explicitly excluded from clipping checks (normally NULL) trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict); +int SV_PointContents(const vec3_t point); + #endif -- 2.39.2