From 678012e3fbea1af64392dc0e243b4e9fc0751fd7 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 21 Jul 2012 05:52:35 +0000 Subject: [PATCH] more Heightmap fixes. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4087 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/r_surf.c | 2 +- engine/gl/gl_heightmap.c | 38 +++++++++++++++++++++----------------- engine/gl/gl_model.c | 2 +- engine/gl/gl_model.h | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/engine/client/r_surf.c b/engine/client/r_surf.c index 502cc7448..cf6cb273d 100644 --- a/engine/client/r_surf.c +++ b/engine/client/r_surf.c @@ -2848,7 +2848,7 @@ void Surf_BuildLightmaps (void) #ifdef TERRAIN if (m->terrain) - Terr_PurgeTerrainModel(m, true); + Terr_PurgeTerrainModel(m, true, false); #endif if (m->type != mod_brush) diff --git a/engine/gl/gl_heightmap.c b/engine/gl/gl_heightmap.c index 591b8fd8d..4e16801bb 100644 --- a/engine/gl/gl_heightmap.c +++ b/engine/gl/gl_heightmap.c @@ -587,10 +587,10 @@ int HeightMap_Save(heightmap_t *hm) return sectionssaved; } -void Terr_DestroySection(heightmap_t *hm, hmsection_t *s) +void Terr_DestroySection(heightmap_t *hm, hmsection_t *s, qboolean lightmapreusable) { #ifndef SERVERONLY - if (hm && s->lightmap >= 0) + if (lightmapreusable && s->lightmap >= 0) { struct lmsect_s *lms; @@ -623,13 +623,14 @@ lightmaps only are purged whenever the client rudely kills lightmaps we'll reload those when its next seen. (lightmaps will already have been destroyed, so no poking them) */ -void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly) +void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly, qboolean lightmapreusable) { heightmap_t *hm = mod->terrain; hmcluster_t *c; hmsection_t *s; int cx, cy; int sx, sy; + for (cy = 0; cy < MAXSECTIONS; cy++) for (cx = 0; cx < MAXSECTIONS; cx++) { @@ -654,7 +655,7 @@ void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly) { c->section[sx+sy*MAXSECTIONS] = NULL; - Terr_DestroySection(NULL, s); + Terr_DestroySection(hm, s, lightmapreusable); } } if (!lightmapsonly) @@ -664,12 +665,15 @@ void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly) } } #ifndef SERVERONLY - while (hm->unusedlmsects) + if (!lightmapreusable) { - struct lmsect_s *lms; - lms = hm->unusedlmsects; - hm->unusedlmsects = lms->next; - free(lms); + while (hm->unusedlmsects) + { + struct lmsect_s *lms; + lms = hm->unusedlmsects; + hm->unusedlmsects = lms->next; + free(lms); + } } #endif } @@ -1262,7 +1266,7 @@ static void Heightmap_Trace_Brush(hmtrace_t *tr, vec4_t *planes, int numplanes) //if we're fully outside any plane, then we cannot possibly enter the brush, skip to the next one if (d1 > 0 && d2 >= d1) - goto nextbrush; + return; if (d1 > 0) startout = true; @@ -1310,8 +1314,6 @@ static void Heightmap_Trace_Brush(hmtrace_t *tr, vec4_t *planes, int numplanes) VectorCopy(enterplane, tr->plane); } } - nextbrush: - ; } //sx,sy are the tile coord @@ -1482,6 +1484,7 @@ qboolean Heightmap_Trace(struct model_s *model, int hulloverride, int frame, vec int x, y; int axis; int breaklimit = 1000; + float wbias; hmtrace_t hmtrace; hmtrace.hm = model->terrain; hmtrace.htilesize = hmtrace.hm->sectionsize / (SECTHEIGHTSIZE-1); @@ -1508,6 +1511,7 @@ qboolean Heightmap_Trace(struct model_s *model, int hulloverride, int frame, vec dir[1] = (hmtrace.end[1] - hmtrace.start[1])/hmtrace.htilesize; pos[0] = (hmtrace.start[0]+CHUNKBIAS*hmtrace.hm->sectionsize)/hmtrace.htilesize; pos[1] = (hmtrace.start[1]+CHUNKBIAS*hmtrace.hm->sectionsize)/hmtrace.htilesize; + wbias = CHUNKBIAS*hmtrace.hm->sectionsize; emins[0] = (mins[0]-1)/hmtrace.htilesize; emins[1] = (mins[1]-1)/hmtrace.htilesize; @@ -1533,14 +1537,14 @@ qboolean Heightmap_Trace(struct model_s *model, int hulloverride, int frame, vec { nudge[axis] = false; npos[axis] = pos[axis] + 1-(pos[axis]-(int)pos[axis]); - frac[axis] = (npos[axis]*hmtrace.htilesize - hmtrace.start[axis])/(hmtrace.end[axis]-hmtrace.start[axis]); + frac[axis] = (npos[axis]*hmtrace.htilesize-wbias - hmtrace.start[axis])/(hmtrace.end[axis]-hmtrace.start[axis]); } else if (dir[axis] < 0) { npos[axis] = pos[axis]; nudge[axis] = (float)(int)pos[axis] == pos[axis]; npos[axis] = (int)npos[axis]; - frac[axis] = (npos[axis]*hmtrace.htilesize - hmtrace.start[axis])/(hmtrace.end[axis]-hmtrace.start[axis]); + frac[axis] = (npos[axis]*hmtrace.htilesize-wbias - hmtrace.start[axis])/(hmtrace.end[axis]-hmtrace.start[axis]); npos[axis] -= nudge[axis]; } else @@ -1571,7 +1575,7 @@ qboolean Heightmap_Trace(struct model_s *model, int hulloverride, int frame, vec //and make sure our position on the other axis is correct, for the next time around the loop if (frac[axis] > hmtrace.frac) break; - pos[!axis] = ((hmtrace.end[!axis] * frac[axis]) + (hmtrace.start[!axis] * (1-frac[axis])))/hmtrace.htilesize; + pos[!axis] = ((hmtrace.end[!axis] * frac[axis]) + (hmtrace.start[!axis] * (1-frac[axis])) + CHUNKBIAS*hmtrace.hm->sectionsize)/hmtrace.htilesize; } trace->plane.dist = hmtrace.plane[3]; @@ -2002,7 +2006,7 @@ void QCBUILTIN PF_terrain_edit(progfuncs_t *prinst, struct globalvars_s *pr_glob switch(action) { case ter_reload: - Terr_PurgeTerrainModel(mod, false); + Terr_PurgeTerrainModel(mod, false, true); break; case ter_save: Con_Printf("%i sections saved\n", HeightMap_Save(hm)); @@ -2299,7 +2303,7 @@ qboolean Terr_LoadTerrainModel (model_t *mod, void *buffer) mod->type = mod_heightmap; - hm = BZ_Malloc(sizeof(*hm)); + hm = Hunk_Alloc(sizeof(*hm)); memset(hm, 0, sizeof(*hm)); COM_FileBase(mod->name, hm->path, sizeof(hm->path)); diff --git a/engine/gl/gl_model.c b/engine/gl/gl_model.c index 5683b9ba4..6c870181c 100644 --- a/engine/gl/gl_model.c +++ b/engine/gl/gl_model.c @@ -401,7 +401,7 @@ void RMod_ClearAll (void) #ifdef TERRAIN if (mod->terrain) { - Terr_PurgeTerrainModel(mod, false); + Terr_PurgeTerrainModel(mod, false, false); mod->terrain = NULL; } #endif diff --git a/engine/gl/gl_model.h b/engine/gl/gl_model.h index baa7e1ba4..628fb3943 100644 --- a/engine/gl/gl_model.h +++ b/engine/gl/gl_model.h @@ -1015,7 +1015,7 @@ qbyte *Mod_LeafPVS (mleaf_t *leaf, model_t *model); #ifdef TERRAIN void Terr_DrawTerrainModel (batch_t **batch, entity_t *e); qboolean Terr_LoadTerrainModel (model_t *mod, void *buffer); -void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly); +void Terr_PurgeTerrainModel(model_t *mod, int 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, struct trace_s *trace); unsigned int Heightmap_PointContents(model_t *model, vec3_t axis[3], vec3_t org);