diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 93e4428c8..e719c3193 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,8 @@ +October 24, 2009 +- Rewrote wide sky texture scaling again. This time, it should work for any + size textures at any scale. I also tried doing sky scrolling on the sky + cylinder, but that didn't look so good, so I left it in screen space. + October 23, 2009 - Fixed: When giving completely new ammo, the backpack did not clamp the amount given to the ammo's max amount. diff --git a/src/r_anim.cpp b/src/r_anim.cpp index 43e3b50a3..c4ed59850 100644 --- a/src/r_anim.cpp +++ b/src/r_anim.cpp @@ -834,6 +834,6 @@ void R_UpdateAnimations (DWORD mstime) // Scroll the sky double ms = (double)mstime * FRACUNIT; - sky1pos = fixed_t(fmod (ms * level.skyspeed1, double(TexMan[sky1texture]->GetScaledWidth() << FRACBITS))); - sky2pos = fixed_t(fmod (ms * level.skyspeed2, double(TexMan[sky2texture]->GetScaledWidth() << FRACBITS))); + sky1pos = ms * level.skyspeed1; + sky2pos = ms * level.skyspeed2; } diff --git a/src/r_plane.cpp b/src/r_plane.cpp index d177241c6..7b263a35c 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -745,8 +745,8 @@ inline void R_MakeSpans (int x, int t1, int b1, int t2, int b2, void (*mapfunc)( static FTexture *frontskytex, *backskytex; static angle_t skyflip; static int frontpos, backpos; -static fixed_t frontxScale, backxScale; static fixed_t frontyScale; +static fixed_t frontcyl, backcyl; int frontiScale; extern fixed_t swall[MAXWIDTH]; @@ -765,15 +765,15 @@ static int skycolplace; static const BYTE *R_GetOneSkyColumn (FTexture *fronttex, int x) { angle_t column = (viewangle + xtoviewangle[x]) ^ skyflip; - return fronttex->GetColumn (MulScale32((column >> sky1shift) + frontpos, frontxScale), NULL); + return fronttex->GetColumn((MulScale16(column, frontcyl) + frontpos) >> FRACBITS, NULL); } // Get a column of sky when there are two overlapping sky textures static const BYTE *R_GetTwoSkyColumns (FTexture *fronttex, int x) { DWORD ang = (viewangle + xtoviewangle[x]) ^ skyflip; - DWORD angle1 = (DWORD)MulScale32((ang >> sky1shift) + frontpos, frontxScale); - DWORD angle2 = (DWORD)MulScale32((ang >> sky2shift) + backpos, backxScale); + DWORD angle1 = (DWORD)((MulScale16(ang, frontcyl) + frontpos) >> FRACBITS); + DWORD angle2 = (DWORD)((MulScale16(ang, backcyl) + backpos) >> FRACBITS); // Check if this column has already been built. If so, there's // no reason to waste time building it again. @@ -848,12 +848,6 @@ static void R_DrawSky (visplane_t *pl) rw_pic = frontskytex; rw_offset = 0; - frontxScale = rw_pic->xScale; - if (backskytex != NULL) - { - backxScale = backskytex->xScale; - } - frontyScale = rw_pic->yScale; dc_texturemid = MulScale16 (skytexturemid/*-viewz*/, frontyScale); @@ -1250,6 +1244,7 @@ ADD_STAT(skyboxes) void R_DrawSkyPlane (visplane_t *pl) { FTextureID sky1tex, sky2tex; + double frontdpos, backdpos; if ((level.flags & LEVEL_SWAPSKIES) && !(level.flags & LEVEL_DOUBLESKY)) { @@ -1272,15 +1267,18 @@ void R_DrawSkyPlane (visplane_t *pl) else backskytex = NULL; skyflip = 0; - frontpos = sky1pos; - backpos = sky2pos; + frontdpos = sky1pos; + backdpos = sky2pos; + frontcyl = sky1cyl; + backcyl = sky2cyl; } else if (pl->sky == PL_SKYFLAT) { // use sky2 frontskytex = TexMan(sky2tex); backskytex = NULL; + frontcyl = sky2cyl; skyflip = 0; - frontpos = sky2pos; + frontdpos = sky2pos; } else { // MBF's linedef-controlled skies @@ -1313,7 +1311,7 @@ void R_DrawSkyPlane (visplane_t *pl) // to allow sky rotation as well as careful positioning. // However, the offset is scaled very small, so that it // allows a long-period of sky rotation. - frontpos = (-s->GetTextureXOffset(pos)) >> 6; + frontdpos = (-s->GetTextureXOffset(pos)) >> 6; // Vertical offset allows careful sky positioning. dc_texturemid = s->GetTextureYOffset(pos) - 28*FRACUNIT; @@ -1324,12 +1322,18 @@ void R_DrawSkyPlane (visplane_t *pl) // to make it easier to use the new feature, while to still // allow old sky textures to be used. skyflip = l->args[2] ? 0u : ~0u; + + frontcyl = MAX(frontskytex->GetWidth(), frontskytex->xScale >> (16 - 10)); + if (skystretch && frontskytex->GetScaledWidth() < 512) + { + frontcyl >>= 1; + } } } -// frontpos = FixedMul(frontpos, frontskytex->xScale/2); + frontpos = int(fmod(frontdpos, double(sky1cyl * 65536.0))); if (backskytex != NULL) { - backpos = FixedMul(backpos, backskytex->xScale); + backpos = int(fmod(backdpos, double(sky2cyl * 65536.0))); } bool fakefixed = false; diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 0ef9b259f..904e80291 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -47,9 +47,8 @@ int skystretch; fixed_t skyheight; fixed_t skyiscale; -int sky1shift, sky2shift; -fixed_t sky1pos=0, sky1speed=0; -fixed_t sky2pos=0, sky2speed=0; +fixed_t sky1cyl, sky2cyl; +double sky1pos, sky2pos; // [RH] Stretch sky texture if not taller than 128 pixels? CUSTOM_CVAR (Bool, r_stretchsky, true, CVAR_ARCHIVE) @@ -114,10 +113,26 @@ void R_InitSkyMap () skyscale = Scale (skyscale, 2048, FieldOfView); } - // The (standard Doom) sky map is 256*128*4 maps. - int swidth = skytex1->GetScaledWidth(); - sky1shift = 22 - 16 + (skystretch && swidth < 512) - (swidth >= 1024 && skytex1->xScale >= 4*FRACUNIT); - swidth = skytex2->GetScaledWidth(); - sky2shift = 22 - 16 + (skystretch && swidth < 512) - (swidth >= 1024 && skytex2->xScale >= 4*FRACUNIT); + // The standard Doom sky texture is 256 pixels wide, repeated 4 times over 360 degrees, + // giving a total sky width of 1024 pixels. So if the sky texture is no wider than 1024, + // we map it to a cylinder with circumfrence 1024. For larger ones, we use the width of + // the texture as the cylinder's circumfrence. + sky1cyl = MAX(skytex1->GetWidth(), skytex1->xScale >> (16 - 10)); + sky2cyl = MAX(skytex2->GetWidth(), skytex2->xScale >> (16 - 10)); + + // If we are stretching short skies, we also stretch them horizontally by halving the + // circumfrence of the sky cylinder, unless the texture is 512 or more pixels wide, + // in which case we only stretch it vertically. + if (skystretch) + { + if (skytex1->GetScaledWidth() < 512) + { + sky1cyl >>= 1; + } + if (skytex2->GetScaledWidth() < 512) + { + sky2cyl >>= 1; + } + } } diff --git a/src/r_sky.h b/src/r_sky.h index b29deb61b..468b9738f 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -24,11 +24,11 @@ #include "textures/textures.h" -extern int sky1shift, sky2shift; extern FTextureID skyflatnum; +extern fixed_t sky1cyl, sky2cyl; extern FTextureID sky1texture, sky2texture; -extern fixed_t sky1pos, sky2pos; +extern double sky1pos, sky2pos; extern fixed_t skytexturemid; extern int skystretch; extern fixed_t skyiscale;