diff --git a/src/p_spec.c b/src/p_spec.c index 919abf48b..e450aed00 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6092,6 +6092,12 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) I_Error("Make-Your-Own FOF (tag %d) found without a 2nd linedef side!", lines[i].tag); break; + case 271: // Regular sky + //case 272: // Same, only flipped + for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + sectors[s].sky = i | PL_SKYFLAT_LINE; + break; + case 300: // Linedef executor (combines with sector special 974/975) and commands case 302: case 303: diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 68de16478..f28d9cbf7 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -851,11 +851,15 @@ static void R_Subsector(size_t num) || frontsector->floorpic == skyflatnum || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].ceilingpic == skyflatnum)) { - floorplane = R_FindPlane(frontsector->floorheight, frontsector->floorpic, floorlightlevel, - frontsector->floor_xoffs, frontsector->floor_yoffs, frontsector->floorpic_angle, floorcolormap, NULL - , NULL - , frontsector->f_slope - , R_NoEncore(frontsector, false), false, frontsector); + floorplane = R_FindPlane(frontsector->floorheight, + frontsector->floorpic == skyflatnum && // kilough 10/98 + frontsector->sky & PL_SKYFLAT ? frontsector->sky : + frontsector->floorpic, + floorlightlevel, + frontsector->floor_xoffs, frontsector->floor_yoffs, frontsector->floorpic_angle, floorcolormap, NULL + , NULL + , frontsector->f_slope + , R_NoEncore(frontsector, false), false, frontsector); } else floorplane = NULL; @@ -864,12 +868,15 @@ static void R_Subsector(size_t num) || frontsector->ceilingpic == skyflatnum || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].floorpic == skyflatnum)) { - ceilingplane = R_FindPlane(frontsector->ceilingheight, frontsector->ceilingpic, - ceilinglightlevel, frontsector->ceiling_xoffs, frontsector->ceiling_yoffs, frontsector->ceilingpic_angle, - ceilingcolormap, NULL - , NULL - , frontsector->c_slope - , R_NoEncore(frontsector, true), true, frontsector); + ceilingplane = R_FindPlane(frontsector->ceilingheight, + frontsector->ceilingpic == skyflatnum && // kilough 10/98 + frontsector->sky & PL_SKYFLAT ? frontsector->sky : + frontsector->ceilingpic, + ceilinglightlevel, frontsector->ceiling_xoffs, frontsector->ceiling_yoffs, frontsector->ceilingpic_angle, + ceilingcolormap, NULL + , NULL + , frontsector->c_slope + , R_NoEncore(frontsector, true), true, frontsector); } else ceilingplane = NULL; diff --git a/src/r_defs.h b/src/r_defs.h index 680a8a9cc..3df619779 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -326,6 +326,15 @@ typedef struct sector_s pslope_t *f_slope; // floor slope pslope_t *c_slope; // ceiling slope + // killough 10/98: support skies coming from sidedefs. Allows scrolling + // skies and other effects. No "level info" kind of lump is needed, + // because you can use an arbitrary number of skies per level with this + // method. This field only applies when skyflatnum is used for floorpic + // or ceilingpic, because the rest of Doom needs to know which is sky + // and which isn't, etc. + + int sky; + // floor and ceiling texture offsets fixed_t floor_xoffs, floor_yoffs; fixed_t ceiling_xoffs, ceiling_yoffs; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index a6a52fe83..17585fef3 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -506,7 +506,11 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, check->polyobj = polyobj; check->slope = slope; check->noencore = noencore; - check->cyan = levelflats[picnum].cyan; + // sky transfers might mess this up.... + if ((UINT32)picnum < numlevelflats) + check->cyan = levelflats[picnum].cyan; + else + check->cyan = false; memset(check->top, 0xff, sizeof(*check->top) * viewwidth); memset(check->bottom, 0x00, sizeof(*check->bottom) * viewwidth); @@ -762,10 +766,11 @@ void R_DrawSkyPlanes(void) { for (pl = visplanes[i]; pl; pl = pl->next) { - if (pl->picnum != skyflatnum || pl->ffloor || pl->polyobj) + if (pl->ffloor || pl->polyobj) continue; - R_DrawSkyPlane(pl, colfunc, cv_parallelsoftware.value); + if (pl->picnum == skyflatnum || pl->picnum & PL_SKYFLAT) + R_DrawSkyPlane(pl, colfunc, cv_parallelsoftware.value); } } #ifdef HAVE_THREADS @@ -782,13 +787,67 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), if (!(pl->minx <= pl->maxx)) return; + INT32 texture; drawcolumndata_t dc = {}; - const INT32 texture = texturetranslation[skytexture]; + angle_t viewang = pl->viewangle; // Reset column drawer function (note: couldn't we just call colfuncs[BASEDRAWFUNC] directly?) // (that is, unless we'll need to switch drawers in future for some reason) R_SetColumnFunc(BASEDRAWFUNC); + if (pl->picnum & PL_SKYFLAT_LINE) + { + // Sky Linedef + const line_t *l = &lines[pl->picnum & ~PL_SKYFLAT_LINE]; + + // Sky transferred from first sidedef + const side_t *s = *l->sidenum + sides; + + // Texture comes from upper texture of reference sidedef + texture = texturetranslation[s->toptexture]; + + // Horizontal offset is turned into an angle offset, + // 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. + + viewang += s->textureoffset; + + // Vertical offset allows careful sky positioning. + + dc.texturemid = s->rowoffset - 28*FRACUNIT; + + // We sometimes flip the picture horizontally. + // + // Doom always flipped the picture, so we make it optional, + // to make it easier to use the new feature, while to still + // allow old sky textures to be used. + + /* + flip = l->special==272 ? 0u : ~0u; + + if (skystretch) + { + int skyheight = textureheight[texture]>>FRACBITS; + dc.texturemid = (int)((int64_t)dc.texturemid * skyheight / SKYSTRETCH_HEIGHT); + } + */ + } + /* // unused fow now + else if (pl->picnum & PL_SKYFLAT_SECTOR) + { + dc.texturemid = skytexturemid; + texture = pl->picnum & ~PL_SKYFLAT_SECTOR; + //flip = 0; + } + */ + else + { // Normal Doom sky, only one allowed per level + dc.texturemid = skytexturemid; // Default y-offset + texture = texturetranslation[skytexture]; // Default texture + //flip = 0; // Doom flips it + } + // use correct aspect ratio scale dc.iscale = skyscale; @@ -801,7 +860,6 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), if (encoremap) dc.colormap += COLORMAP_REMAPOFFSET; - dc.texturemid = skytexturemid; dc.texheight = textureheight[texture] >>FRACBITS; dc.sourcelength = dc.texheight; @@ -828,7 +886,7 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), continue; } - INT32 angle = (pl->viewangle + xtoviewangle[x + i])>>ANGLETOSKYSHIFT; + INT32 angle = (viewang + xtoviewangle[x + i])>>ANGLETOSKYSHIFT; angle -= (skytextureoffset >> FRACBITS); dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x + i]>>ANGLETOFINESHIFT)); @@ -863,7 +921,7 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*skycolfunc)(drawcolumndata_t*), continue; } - INT32 angle = (pl->viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; + INT32 angle = (viewang + xtoviewangle[x])>>ANGLETOSKYSHIFT; angle -= (skytextureoffset >> FRACBITS); dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); @@ -1016,7 +1074,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle return; // sky flat - if (pl->picnum == skyflatnum) + if (pl->picnum == skyflatnum || pl->picnum & PL_SKYFLAT) { // horrific if (!newview->sky) diff --git a/src/r_plane.h b/src/r_plane.h index c76f9d6c0..2ad3c3a04 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -22,6 +22,10 @@ extern "C" { #include "r_data.h" #include "p_polyobj.h" +#define PL_SKYFLAT_LINE (0x80000000) +#define PL_SKYFLAT_SECTOR (0x40000000) +#define PL_SKYFLAT (PL_SKYFLAT_LINE|PL_SKYFLAT_SECTOR) + //SoM: 3/23/2000: Use Boom visplane hashing. #define VISPLANEHASHBITS 9 #define VISPLANEHASHMASK ((1<