diff --git a/src/r_data.c b/src/r_data.c index ca73e7e42..7ac8ffe2d 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -649,6 +649,7 @@ void R_LoadTextures(void) M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->width = SHORT(patchlump->width); texture->height = SHORT(patchlump->height); + texture->type = TEXTURETYPE_SINGLEPATCH; texture->patchcount = 1; texture->holes = false; @@ -915,19 +916,22 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) // Left Curly Brace texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where open curly brace for texture \"%s\" should be",newTextureName); } + if (strcmp(texturesToken,"{")==0) { if (actuallyLoadTexture) { // Allocate memory for a zero-patch texture. Obviously, we'll be adding patches momentarily. - resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t),PU_STATIC,NULL); + resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t), PU_STATIC, NULL); M_Memcpy(resultTexture->name, newTextureName, 8); resultTexture->width = newTextureWidth; resultTexture->height = newTextureHeight; + resultTexture->type = TEXTURETYPE_COMPOSITE; } Z_Free(texturesToken); texturesToken = M_GetToken(NULL); diff --git a/src/r_data.h b/src/r_data.h index 45f7ee484..c3abab0c1 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -37,6 +37,14 @@ typedef struct UINT16 wad, lump; } texpatch_t; +// texture type +enum +{ + TEXTURETYPE_UNKNOWN, + TEXTURETYPE_SINGLEPATCH, + TEXTURETYPE_COMPOSITE, +}; + // A maptexturedef_t describes a rectangular texture, // which is composed of one or more mappatch_t structures // that arrange graphic patches. @@ -44,6 +52,7 @@ typedef struct { // Keep name for switch changing, etc. char name[8]; + UINT8 type; // TEXTURETYPE_ INT16 width, height; boolean holes; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 81e02c370..b46912b2f 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -839,6 +839,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b } INT32 angle = (pl->viewangle + xtoviewangle[x + i])>>ANGLETOSKYSHIFT; + angle -= (skytextureoffset >> FRACBITS); + dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x + i]>>ANGLETOFINESHIFT)); dc.x = x + i; dc.source = diff --git a/src/r_sky.c b/src/r_sky.c index 1ed47d43b..8cbdd3a59 100644 --- a/src/r_sky.c +++ b/src/r_sky.c @@ -41,6 +41,10 @@ INT32 skytexture; */ INT32 skytexturemid; +/** \brief the x offset of the sky texture + */ +INT32 skytextureoffset; + /** \brief the scale of the sky */ fixed_t skyscale; @@ -50,6 +54,7 @@ fixed_t skyscale; INT32 levelskynum; INT32 globallevelskynum; + /** \brief The R_SetupSkyDraw function Called at loadlevel after skytexture is set, or when sky texture changes. @@ -61,8 +66,20 @@ INT32 globallevelskynum; */ void R_SetupSkyDraw(void) { - // the horizon line in a 256x128 sky texture - skytexturemid = (textures[skytexture]->height/2)<height / 2) << FRACBITS; + skytextureoffset = 0; + + if (textures[skytexture]->type == TEXTURETYPE_SINGLEPATCH) + { + // Sal: Allow for sky offsets + texpatch_t *const tex_patch = &textures[skytexture]->patches[0]; + patch_t *patch = W_CachePatchNumPwad(tex_patch->wad, tex_patch->lump, PU_CACHE); + + skytexturemid += (patch->topoffset << FRACBITS); + skytextureoffset += (patch->leftoffset << FRACBITS); + } + R_SetSkyScale(); } @@ -74,5 +91,7 @@ void R_SetupSkyDraw(void) */ void R_SetSkyScale(void) { - skyscale = FixedDiv(fovtan, FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT)); + //skyscale = FixedDiv(fovtan, FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT)); + fixed_t difference = vid.fdupx-(vid.dupx<