1
0
Fork 0
forked from fte/fteqw

more Heightmap fixes.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4087 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2012-07-21 05:52:35 +00:00
parent e6f3e0d019
commit 678012e3fb
4 changed files with 24 additions and 20 deletions

View file

@ -2848,7 +2848,7 @@ void Surf_BuildLightmaps (void)
#ifdef TERRAIN #ifdef TERRAIN
if (m->terrain) if (m->terrain)
Terr_PurgeTerrainModel(m, true); Terr_PurgeTerrainModel(m, true, false);
#endif #endif
if (m->type != mod_brush) if (m->type != mod_brush)

View file

@ -587,10 +587,10 @@ int HeightMap_Save(heightmap_t *hm)
return sectionssaved; return sectionssaved;
} }
void Terr_DestroySection(heightmap_t *hm, hmsection_t *s) void Terr_DestroySection(heightmap_t *hm, hmsection_t *s, qboolean lightmapreusable)
{ {
#ifndef SERVERONLY #ifndef SERVERONLY
if (hm && s->lightmap >= 0) if (lightmapreusable && s->lightmap >= 0)
{ {
struct lmsect_s *lms; 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. we'll reload those when its next seen.
(lightmaps will already have been destroyed, so no poking them) (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; heightmap_t *hm = mod->terrain;
hmcluster_t *c; hmcluster_t *c;
hmsection_t *s; hmsection_t *s;
int cx, cy; int cx, cy;
int sx, sy; int sx, sy;
for (cy = 0; cy < MAXSECTIONS; cy++) for (cy = 0; cy < MAXSECTIONS; cy++)
for (cx = 0; cx < MAXSECTIONS; cx++) for (cx = 0; cx < MAXSECTIONS; cx++)
{ {
@ -654,7 +655,7 @@ void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly)
{ {
c->section[sx+sy*MAXSECTIONS] = NULL; c->section[sx+sy*MAXSECTIONS] = NULL;
Terr_DestroySection(NULL, s); Terr_DestroySection(hm, s, lightmapreusable);
} }
} }
if (!lightmapsonly) if (!lightmapsonly)
@ -664,12 +665,15 @@ void Terr_PurgeTerrainModel(model_t *mod, qboolean lightmapsonly)
} }
} }
#ifndef SERVERONLY #ifndef SERVERONLY
while (hm->unusedlmsects) if (!lightmapreusable)
{ {
struct lmsect_s *lms; while (hm->unusedlmsects)
lms = hm->unusedlmsects; {
hm->unusedlmsects = lms->next; struct lmsect_s *lms;
free(lms); lms = hm->unusedlmsects;
hm->unusedlmsects = lms->next;
free(lms);
}
} }
#endif #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 we're fully outside any plane, then we cannot possibly enter the brush, skip to the next one
if (d1 > 0 && d2 >= d1) if (d1 > 0 && d2 >= d1)
goto nextbrush; return;
if (d1 > 0) if (d1 > 0)
startout = true; startout = true;
@ -1310,8 +1314,6 @@ static void Heightmap_Trace_Brush(hmtrace_t *tr, vec4_t *planes, int numplanes)
VectorCopy(enterplane, tr->plane); VectorCopy(enterplane, tr->plane);
} }
} }
nextbrush:
;
} }
//sx,sy are the tile coord //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 x, y;
int axis; int axis;
int breaklimit = 1000; int breaklimit = 1000;
float wbias;
hmtrace_t hmtrace; hmtrace_t hmtrace;
hmtrace.hm = model->terrain; hmtrace.hm = model->terrain;
hmtrace.htilesize = hmtrace.hm->sectionsize / (SECTHEIGHTSIZE-1); 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; dir[1] = (hmtrace.end[1] - hmtrace.start[1])/hmtrace.htilesize;
pos[0] = (hmtrace.start[0]+CHUNKBIAS*hmtrace.hm->sectionsize)/hmtrace.htilesize; pos[0] = (hmtrace.start[0]+CHUNKBIAS*hmtrace.hm->sectionsize)/hmtrace.htilesize;
pos[1] = (hmtrace.start[1]+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[0] = (mins[0]-1)/hmtrace.htilesize;
emins[1] = (mins[1]-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; nudge[axis] = false;
npos[axis] = pos[axis] + 1-(pos[axis]-(int)pos[axis]); 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) else if (dir[axis] < 0)
{ {
npos[axis] = pos[axis]; npos[axis] = pos[axis];
nudge[axis] = (float)(int)pos[axis] == pos[axis]; nudge[axis] = (float)(int)pos[axis] == pos[axis];
npos[axis] = (int)npos[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]; npos[axis] -= nudge[axis];
} }
else 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 //and make sure our position on the other axis is correct, for the next time around the loop
if (frac[axis] > hmtrace.frac) if (frac[axis] > hmtrace.frac)
break; 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]; 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) switch(action)
{ {
case ter_reload: case ter_reload:
Terr_PurgeTerrainModel(mod, false); Terr_PurgeTerrainModel(mod, false, true);
break; break;
case ter_save: case ter_save:
Con_Printf("%i sections saved\n", HeightMap_Save(hm)); 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; mod->type = mod_heightmap;
hm = BZ_Malloc(sizeof(*hm)); hm = Hunk_Alloc(sizeof(*hm));
memset(hm, 0, sizeof(*hm)); memset(hm, 0, sizeof(*hm));
COM_FileBase(mod->name, hm->path, sizeof(hm->path)); COM_FileBase(mod->name, hm->path, sizeof(hm->path));

View file

@ -401,7 +401,7 @@ void RMod_ClearAll (void)
#ifdef TERRAIN #ifdef TERRAIN
if (mod->terrain) if (mod->terrain)
{ {
Terr_PurgeTerrainModel(mod, false); Terr_PurgeTerrainModel(mod, false, false);
mod->terrain = NULL; mod->terrain = NULL;
} }
#endif #endif

View file

@ -1015,7 +1015,7 @@ qbyte *Mod_LeafPVS (mleaf_t *leaf, model_t *model);
#ifdef TERRAIN #ifdef TERRAIN
void Terr_DrawTerrainModel (batch_t **batch, entity_t *e); void Terr_DrawTerrainModel (batch_t **batch, entity_t *e);
qboolean Terr_LoadTerrainModel (model_t *mod, void *buffer); 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 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); 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); unsigned int Heightmap_PointContents(model_t *model, vec3_t axis[3], vec3_t org);