Merge branch 'stable'

* stable:
  light: trace: raise stack depth 128->256 to handle lavabloom_bad.bsp from Pritchard
  light: use Face_TextureName() everywhere we need texture names. Handle negative miplump->dataofs[texnum].
  build: appveyor: use v140_xp toolset for xp compatibility

# Conflicts:
#	appveyor.yml
This commit is contained in:
Eric Wasylishen 2016-07-12 00:25:50 -06:00
commit 7646175048
4 changed files with 55 additions and 62 deletions

View File

@ -332,6 +332,9 @@ extern char mapfilename[1024];
void void
PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp); PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp);
const miptex_t *
Face_Miptex(const bsp2_t *bsp, const bsp2_dface_t *face);
const char * const char *
Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face); Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face);

View File

@ -785,13 +785,20 @@ finds the texture that is meant to be projected.
*/ */
static miptex_t *FindProjectionTexture(const bsp2_t *bsp, const char *texname) static miptex_t *FindProjectionTexture(const bsp2_t *bsp, const char *texname)
{ {
if (!bsp->texdatasize)
return NULL;
dmiptexlump_t *miplump = bsp->dtexdata.header; dmiptexlump_t *miplump = bsp->dtexdata.header;
miptex_t *miptex; miptex_t *miptex;
int texnum; int texnum;
/*outer loop finds the textures*/ /*outer loop finds the textures*/
for (texnum = 0; texnum< miplump->nummiptex; texnum++) for (texnum = 0; texnum< miplump->nummiptex; texnum++)
{ {
miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[texnum]); int offset = miplump->dataofs[texnum];
if (offset < 0)
continue;
miptex = (miptex_t*)(bsp->dtexdata.base + offset);
if (!Q_strcasecmp(miptex->name, texname)) if (!Q_strcasecmp(miptex->name, texname))
return miptex; return miptex;
} }
@ -1696,10 +1703,7 @@ static void SubdividePolygon (const bsp2_dface_t *face, const modelinfo_t *face_
return; return;
} }
const texinfo_t *tex = &bsp->texinfo[face->texinfo]; const char *texname = Face_TextureName(bsp, face);
const int offset = bsp->dtexdata.header->dataofs[tex->miptex];
const miptex_t *miptex = (const miptex_t *)(bsp->dtexdata.base + offset);
const char *texname = miptex->name;
for (i=0; i<num_surfacelight_templates; i++) { for (i=0; i<num_surfacelight_templates; i++) {
if (!Q_strcasecmp(texname, ValueForKey(surfacelight_templates[i], "_surface"))) { if (!Q_strcasecmp(texname, ValueForKey(surfacelight_templates[i], "_surface"))) {
@ -1765,24 +1769,15 @@ static void MakeSurfaceLights(const bsp2_t *bsp)
for (i=0; i<bsp->numleafs; i++) { for (i=0; i<bsp->numleafs; i++) {
const bsp2_dleaf_t *leaf = bsp->dleafs + i; const bsp2_dleaf_t *leaf = bsp->dleafs + i;
const bsp2_dface_t *surf; const bsp2_dface_t *surf;
int ofs;
qboolean underwater = leaf->contents != CONTENTS_EMPTY; qboolean underwater = leaf->contents != CONTENTS_EMPTY;
for (k = 0; k < leaf->nummarksurfaces; k++) { for (k = 0; k < leaf->nummarksurfaces; k++) {
const texinfo_t *info;
const miptex_t *miptex;
const modelinfo_t *face_modelinfo; const modelinfo_t *face_modelinfo;
int facenum = bsp->dmarksurfaces[leaf->firstmarksurface + k]; int facenum = bsp->dmarksurfaces[leaf->firstmarksurface + k];
surf = &bsp->dfaces[facenum]; surf = &bsp->dfaces[facenum];
info = &bsp->texinfo[surf->texinfo]; const char *texname = Face_TextureName(bsp, surf);
/* Don't crash if there are no textuers */
if (!bsp->texdatasize)
continue;
ofs = bsp->dtexdata.header->dataofs[info->miptex];
miptex = (const miptex_t *)(bsp->dtexdata.base + ofs);
face_modelinfo = ModelInfoForFace(bsp, facenum); face_modelinfo = ModelInfoForFace(bsp, facenum);
/* Skip face with no modelinfo */ /* Skip face with no modelinfo */
@ -1791,7 +1786,7 @@ static void MakeSurfaceLights(const bsp2_t *bsp)
/* Ignore the underwater side of liquid surfaces */ /* Ignore the underwater side of liquid surfaces */
// FIXME: Use a Face_TextureName function for this // FIXME: Use a Face_TextureName function for this
if (miptex->name[0] == '*' && underwater) if (texname[0] == '*' && underwater)
continue; continue;
/* Skip if already handled */ /* Skip if already handled */

View File

@ -274,14 +274,13 @@ void
PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp) PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp)
{ {
const texinfo_t *tex = &bsp->texinfo[face->texinfo]; const texinfo_t *tex = &bsp->texinfo[face->texinfo];
const int offset = bsp->dtexdata.header->dataofs[tex->miptex]; const char *texname = Face_TextureName(bsp, face);
const miptex_t *miptex = (const miptex_t *)(bsp->dtexdata.base + offset);
int i; int i;
logprint("face %d, texture %s, %d edges...\n" logprint("face %d, texture %s, %d edges...\n"
" vectors (%3.3f, %3.3f, %3.3f) (%3.3f)\n" " vectors (%3.3f, %3.3f, %3.3f) (%3.3f)\n"
" (%3.3f, %3.3f, %3.3f) (%3.3f)\n", " (%3.3f, %3.3f, %3.3f) (%3.3f)\n",
(int)(face - bsp->dfaces), miptex->name, face->numedges, (int)(face - bsp->dfaces), texname, face->numedges,
tex->vecs[0][0], tex->vecs[0][1], tex->vecs[0][2], tex->vecs[0][3], tex->vecs[0][0], tex->vecs[0][1], tex->vecs[0][2], tex->vecs[0][3],
tex->vecs[1][0], tex->vecs[1][1], tex->vecs[1][2], tex->vecs[1][3]); tex->vecs[1][0], tex->vecs[1][1], tex->vecs[1][2], tex->vecs[1][3]);
@ -365,14 +364,13 @@ CalcFaceExtents(const bsp2_dface_t *face,
surf->texsize[i] = maxs[i] - mins[i]; surf->texsize[i] = maxs[i] - mins[i];
if (surf->texsize[i] >= MAXDIMENSION) { if (surf->texsize[i] >= MAXDIMENSION) {
const dplane_t *plane = bsp->dplanes + face->planenum; const dplane_t *plane = bsp->dplanes + face->planenum;
const int offset = bsp->dtexdata.header->dataofs[tex->miptex]; const char *texname = Face_TextureName(bsp, face);
const miptex_t *miptex = (const miptex_t *)(bsp->dtexdata.base + offset);
Error("Bad surface extents:\n" Error("Bad surface extents:\n"
" surface %d, %s extents = %d, scale = %g\n" " surface %d, %s extents = %d, scale = %g\n"
" texture %s at (%s)\n" " texture %s at (%s)\n"
" surface normal (%s)\n", " surface normal (%s)\n",
(int)(face - bsp->dfaces), i ? "t" : "s", surf->texsize[i], surf->lightmapscale, (int)(face - bsp->dfaces), i ? "t" : "s", surf->texsize[i], surf->lightmapscale,
miptex->name, VecStr(worldpoint), VecStrf(plane->normal)); texname, VecStr(worldpoint), VecStrf(plane->normal));
} }
} }
} }
@ -2087,17 +2085,31 @@ void LightFaceShutdown(struct ltface_ctx *ctx)
free(ctx->lightsurf); free(ctx->lightsurf);
} }
const miptex_t *
Face_Miptex(const bsp2_t *bsp, const bsp2_dface_t *face)
{
if (!bsp->texdatasize)
return NULL;
int texnum = bsp->texinfo[face->texinfo].miptex;
const dmiptexlump_t *miplump = bsp->dtexdata.header;
int offset = miplump->dataofs[texnum];
if (offset < 0)
return NULL; //sometimes the texture just wasn't written. including its name.
const miptex_t *miptex = (miptex_t*)(bsp->dtexdata.base + offset);
return miptex;
}
const char * const char *
Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face) Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face)
{ {
int texnum = bsp->texinfo[face->texinfo].miptex; const miptex_t *miptex = Face_Miptex(bsp, face);
if (!bsp->texdatasize) if (miptex)
return miptex->name;
else
return ""; return "";
const dmiptexlump_t *miplump = bsp->dtexdata.header;
if (!miplump->dataofs[texnum])
return ""; //sometimes the texture just wasn't written. including its name.
const miptex_t *miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[texnum]);
return miptex->name;
} }
/* /*

View File

@ -202,22 +202,18 @@ Face_Contents(const bsp2_t *bsp, const bsp2_dface_t *face)
if (!bsp->texdatasize) if (!bsp->texdatasize)
return CONTENTS_SOLID; // no textures in bsp return CONTENTS_SOLID; // no textures in bsp
int texnum = bsp->texinfo[face->texinfo].miptex; const char *texname = Face_TextureName(bsp, face);
const dmiptexlump_t *miplump = bsp->dtexdata.header;
const miptex_t *miptex; if (texname[0] == '\0')
if (!miplump->dataofs[texnum])
return CONTENTS_SOLID; //sometimes the texture just wasn't written. including its name. return CONTENTS_SOLID; //sometimes the texture just wasn't written. including its name.
miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[texnum]); if (!Q_strncasecmp(texname, "sky", 3))
if (!Q_strncasecmp(miptex->name, "sky", 3))
return CONTENTS_SKY; return CONTENTS_SKY;
else if (!Q_strncasecmp(miptex->name, "*lava", 5)) else if (!Q_strncasecmp(texname, "*lava", 5))
return CONTENTS_LAVA; return CONTENTS_LAVA;
else if (!Q_strncasecmp(miptex->name, "*slime", 6)) else if (!Q_strncasecmp(texname, "*slime", 6))
return CONTENTS_SLIME; return CONTENTS_SLIME;
else if (miptex->name[0] == '*') else if (texname[0] == '*')
return CONTENTS_WATER; return CONTENTS_WATER;
else else
return CONTENTS_SOLID; return CONTENTS_SOLID;
@ -346,18 +342,6 @@ BSP_MakeTnodes(const bsp2_t *bsp)
* ============================================================================ * ============================================================================
*/ */
static miptex_t *
MiptexForFace(const bsp2_dface_t *face, const bsp2_t *bsp)
{
const texinfo_t *tex;
dmiptexlump_t *miplump = bsp->dtexdata.header;
miptex_t *miptex;
tex = &bsp->texinfo[face->texinfo];
miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[tex->miptex]);
return miptex;
}
vec_t fix_coord(vec_t in, int width) vec_t fix_coord(vec_t in, int width)
{ {
if (in > 0) if (in > 0)
@ -377,8 +361,7 @@ SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point)
{ {
vec_t texcoord[2]; vec_t texcoord[2];
const texinfo_t *tex; const texinfo_t *tex;
dmiptexlump_t *miplump = bsp->dtexdata.header; const miptex_t *miptex;
miptex_t *miptex;
int x, y; int x, y;
byte *data; byte *data;
int sample; int sample;
@ -386,16 +369,15 @@ SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point)
if (!bsp->texdatasize) if (!bsp->texdatasize)
return -1; return -1;
miptex = Face_Miptex(bsp, face);
if (miptex == NULL)
return -1;
tex = &bsp->texinfo[face->texinfo]; tex = &bsp->texinfo[face->texinfo];
WorldToTexCoord(point, tex, texcoord); WorldToTexCoord(point, tex, texcoord);
if (miplump->dataofs[tex->miptex] == -1) {
return -1;
}
miptex = (miptex_t*)(bsp->dtexdata.base + miplump->dataofs[tex->miptex]);
x = fix_coord(texcoord[0], miptex->width); x = fix_coord(texcoord[0], miptex->width);
y = fix_coord(texcoord[1], miptex->height); y = fix_coord(texcoord[1], miptex->height);
@ -462,7 +444,7 @@ typedef struct {
* TraceLine * TraceLine
* ============== * ==============
*/ */
#define MAX_TSTACK 128 #define MAX_TSTACK 256
int int
TraceLine(const dmodel_t *model, const int traceflags, TraceLine(const dmodel_t *model, const int traceflags,
const vec3_t start, const vec3_t stop) const vec3_t start, const vec3_t stop)
@ -487,6 +469,7 @@ TraceLine(const dmodel_t *model, const int traceflags,
return TRACE_HIT_NONE; return TRACE_HIT_NONE;
} }
// FIXME: check for stack overflow
// const tracestack_t *const tstack_max = tracestack + MAX_TSTACK; // const tracestack_t *const tstack_max = tracestack + MAX_TSTACK;
if (traceflags <= 0) if (traceflags <= 0)