From 584d2776cc130debb4b0dc4d5f3c9b540a0c1126 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 14 Jul 2012 23:17:54 +0000 Subject: [PATCH] Added terrain to q3/rbsp maps too. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4071 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/common/gl_q2bsp.c | 62 ++++++++++++++++++++++++---------------- engine/gl/gl_heightmap.c | 8 ------ engine/gl/glquake.h | 1 + 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/engine/common/gl_q2bsp.c b/engine/common/gl_q2bsp.c index a74fa61b1..84e261e58 100644 --- a/engine/common/gl_q2bsp.c +++ b/engine/common/gl_q2bsp.c @@ -3737,6 +3737,7 @@ cmodel_t *CM_LoadMap (char *name, char *filein, qboolean clientload, unsigned *c static unsigned last_checksum; qboolean noerrors = true; int start; + model_t *im = loadmodel; void (*buildmeshes)(model_t *mod, msurface_t *surf, void *cookie) = NULL; void *buildcookie = NULL; @@ -4178,6 +4179,9 @@ cmodel_t *CM_LoadMap (char *name, char *filein, qboolean clientload, unsigned *c } } +#ifdef TERRAIN + im->terrain = Mod_LoadTerrainInfo(im, loadname); +#endif return &map_cmodels[0]; } @@ -4508,36 +4512,39 @@ int CM_PointContents (model_t *mod, vec3_t p) i = CM_PointLeafnum_r (mod, p, mod->hulls[0].firstclipnode); if (!mapisq3) - return map_leafs[i].contents; //q2 is simple. - - leaf = &map_leafs[i]; - -// if ( leaf->contents & CONTENTS_NODROP ) { -// contents = CONTENTS_NODROP; -// } else { - contents = 0; -// } - - for (i = 0; i < leaf->numleafbrushes; i++) + contents = map_leafs[i].contents; //q2 is simple. + else { - brush = &map_brushes[map_leafbrushes[leaf->firstleafbrush + i]]; + leaf = &map_leafs[i]; - // check if brush actually adds something to contents - if ( (contents & brush->contents) == brush->contents ) { - continue; - } + // if ( leaf->contents & CONTENTS_NODROP ) { + // contents = CONTENTS_NODROP; + // } else { + contents = 0; + // } - brushside = brush->brushside; - for ( j = 0; j < brush->numsides; j++, brushside++ ) + for (i = 0; i < leaf->numleafbrushes; i++) { - if ( PlaneDiff (p, brushside->plane) > 0 ) - break; + brush = &map_brushes[map_leafbrushes[leaf->firstleafbrush + i]]; + + // check if brush actually adds something to contents + if ( (contents & brush->contents) == brush->contents ) { + continue; + } + + brushside = brush->brushside; + for ( j = 0; j < brush->numsides; j++, brushside++ ) + { + if ( PlaneDiff (p, brushside->plane) > 0 ) + break; + } + + if (j == brush->numsides) + contents |= brush->contents; } - - if (j == brush->numsides) - contents |= brush->contents; } - + if (mod->terrain) + contents |= Heightmap_PointContents(mod, NULL, p); return contents; } @@ -5385,6 +5392,13 @@ trace_t CM_BoxTrace (model_t *mod, vec3_t start, vec3_t end, qboolean CM_NativeTrace(model_t *model, int forcehullnum, int frame, vec3_t axis[3], vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, unsigned int contents, trace_t *trace) { *trace = CM_BoxTrace(model, start, end, mins, maxs, contents); + if (model->terrain) + { + trace_t hmt; + Heightmap_Trace(model, forcehullnum, frame, axis, start, end, mins, maxs, contents, &hmt); + if (hmt.fraction < trace->fraction) + *trace = hmt; + } return trace->fraction != 1; } diff --git a/engine/gl/gl_heightmap.c b/engine/gl/gl_heightmap.c index e1f547f6a..8f9a5ce4d 100644 --- a/engine/gl/gl_heightmap.c +++ b/engine/gl/gl_heightmap.c @@ -1895,14 +1895,6 @@ void *Mod_LoadTerrainInfo(model_t *mod, char *loadname) if (!mod->entities) return NULL; - if (!strcmp(loadname, "start")) - { - bounds[0] = 0; - bounds[1] = 4; - bounds[2] = 0; - bounds[3] = 4; - } - Terr_ParseEntityLump(mod->entities, &scale, &bounds[0], &bounds[1], &bounds[2], &bounds[3]); bounds[0] += CHUNKBIAS; diff --git a/engine/gl/glquake.h b/engine/gl/glquake.h index f4996aaaa..fab40ba7a 100644 --- a/engine/gl/glquake.h +++ b/engine/gl/glquake.h @@ -412,6 +412,7 @@ qboolean Terr_LoadTerrainModel (model_t *mod, void *buffer); void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly); void *Mod_LoadTerrainInfo(model_t *mod, char *loadname); //call this after loading a bsp qboolean Heightmap_Trace(model_t *model, int forcehullnum, int frame, vec3_t axis[3], vec3_t start, vec3_t end, vec3_t mins, vec3_t maxs, unsigned int contentmask, trace_t *trace); +unsigned int Heightmap_PointContents(model_t *model, vec3_t axis[3], vec3_t org); #endif //doom