light: use Face_TextureName() everywhere we need texture names. Handle negative miplump->dataofs[texnum].
This commit is contained in:
parent
e3ff06318d
commit
992b2e51bc
|
|
@ -310,6 +310,9 @@ extern char mapfilename[1024];
|
|||
void
|
||||
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 *
|
||||
Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face);
|
||||
|
||||
|
|
|
|||
|
|
@ -815,13 +815,20 @@ finds the texture that is meant to be projected.
|
|||
*/
|
||||
static miptex_t *FindProjectionTexture(const bsp2_t *bsp, const char *texname)
|
||||
{
|
||||
if (!bsp->texdatasize)
|
||||
return NULL;
|
||||
|
||||
dmiptexlump_t *miplump = bsp->dtexdata.header;
|
||||
miptex_t *miptex;
|
||||
int texnum;
|
||||
/*outer loop finds the textures*/
|
||||
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))
|
||||
return miptex;
|
||||
}
|
||||
|
|
@ -1657,10 +1664,7 @@ static void SubdividePolygon (const bsp2_dface_t *face, const modelinfo_t *face_
|
|||
return;
|
||||
}
|
||||
|
||||
const texinfo_t *tex = &bsp->texinfo[face->texinfo];
|
||||
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;
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
|
||||
for (i=0; i<num_surfacelight_templates; i++) {
|
||||
if (!Q_strcasecmp(texname, ValueForKey(surfacelight_templates[i], "_surface"))) {
|
||||
|
|
@ -1726,24 +1730,15 @@ static void MakeSurfaceLights(const bsp2_t *bsp)
|
|||
for (i=0; i<bsp->numleafs; i++) {
|
||||
const bsp2_dleaf_t *leaf = bsp->dleafs + i;
|
||||
const bsp2_dface_t *surf;
|
||||
int ofs;
|
||||
qboolean underwater = leaf->contents != CONTENTS_EMPTY;
|
||||
|
||||
for (k = 0; k < leaf->nummarksurfaces; k++) {
|
||||
const texinfo_t *info;
|
||||
const miptex_t *miptex;
|
||||
const modelinfo_t *face_modelinfo;
|
||||
int facenum = bsp->dmarksurfaces[leaf->firstmarksurface + k];
|
||||
|
||||
surf = &bsp->dfaces[facenum];
|
||||
info = &bsp->texinfo[surf->texinfo];
|
||||
|
||||
/* 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);
|
||||
const char *texname = Face_TextureName(bsp, surf);
|
||||
|
||||
face_modelinfo = ModelInfoForFace(bsp, facenum);
|
||||
|
||||
/* Skip face with no modelinfo */
|
||||
|
|
@ -1752,7 +1747,7 @@ static void MakeSurfaceLights(const bsp2_t *bsp)
|
|||
|
||||
/* Ignore the underwater side of liquid surfaces */
|
||||
// FIXME: Use a Face_TextureName function for this
|
||||
if (miptex->name[0] == '*' && underwater)
|
||||
if (texname[0] == '*' && underwater)
|
||||
continue;
|
||||
|
||||
/* Skip if already handled */
|
||||
|
|
|
|||
|
|
@ -273,14 +273,13 @@ void
|
|||
PrintFaceInfo(const bsp2_dface_t *face, const bsp2_t *bsp)
|
||||
{
|
||||
const texinfo_t *tex = &bsp->texinfo[face->texinfo];
|
||||
const int offset = bsp->dtexdata.header->dataofs[tex->miptex];
|
||||
const miptex_t *miptex = (const miptex_t *)(bsp->dtexdata.base + offset);
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
int i;
|
||||
|
||||
logprint("face %d, texture %s, %d edges...\n"
|
||||
" vectors (%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[1][0], tex->vecs[1][1], tex->vecs[1][2], tex->vecs[1][3]);
|
||||
|
||||
|
|
@ -364,14 +363,13 @@ CalcFaceExtents(const bsp2_dface_t *face,
|
|||
surf->texsize[i] = maxs[i] - mins[i];
|
||||
if (surf->texsize[i] >= MAXDIMENSION) {
|
||||
const dplane_t *plane = bsp->dplanes + face->planenum;
|
||||
const int offset = bsp->dtexdata.header->dataofs[tex->miptex];
|
||||
const miptex_t *miptex = (const miptex_t *)(bsp->dtexdata.base + offset);
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
Error("Bad surface extents:\n"
|
||||
" surface %d, %s extents = %d, scale = %g\n"
|
||||
" texture %s at (%s)\n"
|
||||
" surface normal (%s)\n",
|
||||
(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2091,17 +2089,31 @@ void LightFaceShutdown(struct ltface_ctx *ctx)
|
|||
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 *
|
||||
Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face)
|
||||
{
|
||||
int texnum = bsp->texinfo[face->texinfo].miptex;
|
||||
if (!bsp->texdatasize)
|
||||
const miptex_t *miptex = Face_Miptex(bsp, face);
|
||||
if (miptex)
|
||||
return miptex->name;
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -202,22 +202,18 @@ Face_Contents(const bsp2_t *bsp, const bsp2_dface_t *face)
|
|||
if (!bsp->texdatasize)
|
||||
return CONTENTS_SOLID; // no textures in bsp
|
||||
|
||||
int texnum = bsp->texinfo[face->texinfo].miptex;
|
||||
const dmiptexlump_t *miplump = bsp->dtexdata.header;
|
||||
const miptex_t *miptex;
|
||||
|
||||
if (!miplump->dataofs[texnum])
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
|
||||
if (texname[0] == '\0')
|
||||
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(miptex->name, "sky", 3))
|
||||
if (!Q_strncasecmp(texname, "sky", 3))
|
||||
return CONTENTS_SKY;
|
||||
else if (!Q_strncasecmp(miptex->name, "*lava", 5))
|
||||
else if (!Q_strncasecmp(texname, "*lava", 5))
|
||||
return CONTENTS_LAVA;
|
||||
else if (!Q_strncasecmp(miptex->name, "*slime", 6))
|
||||
else if (!Q_strncasecmp(texname, "*slime", 6))
|
||||
return CONTENTS_SLIME;
|
||||
else if (miptex->name[0] == '*')
|
||||
else if (texname[0] == '*')
|
||||
return CONTENTS_WATER;
|
||||
else
|
||||
return CONTENTS_SOLID;
|
||||
|
|
@ -346,18 +342,6 @@ 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)
|
||||
{
|
||||
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];
|
||||
const texinfo_t *tex;
|
||||
dmiptexlump_t *miplump = bsp->dtexdata.header;
|
||||
miptex_t *miptex;
|
||||
const miptex_t *miptex;
|
||||
int x, y;
|
||||
byte *data;
|
||||
int sample;
|
||||
|
|
@ -386,16 +369,15 @@ SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point)
|
|||
if (!bsp->texdatasize)
|
||||
return -1;
|
||||
|
||||
miptex = Face_Miptex(bsp, face);
|
||||
|
||||
if (miptex == NULL)
|
||||
return -1;
|
||||
|
||||
tex = &bsp->texinfo[face->texinfo];
|
||||
|
||||
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);
|
||||
y = fix_coord(texcoord[1], miptex->height);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue