Skip to content

Commit

Permalink
added per-sector sky UDMF properties.
Browse files Browse the repository at this point in the history
(Hardware rendering only, the SW renderer is not in a state where this is easily done.)
  • Loading branch information
coelckers committed Oct 29, 2023
1 parent 9a94472 commit bdee1f3
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 21 deletions.
5 changes: 5 additions & 0 deletions specs/udmf_zdoom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ Note: All <bool> fields default to false unless mentioned otherwise.
friction = <float>; // sets the sector's friction factor. Must be between 0 and 1.
movefactor = <float> // sets the sector's movement acceleration factor. Must be > 0.

skyfloor = <string> // defines lower sky for this sector.
skyceiling = <string> // defines upper sky for this sector.
skyfloor2 = <string> // defines secondary lower sky for this sector. (for lightning or transparent layers)
skyceiling2 = <string> // defines secondary upper sky for this sector.

colormap = <string>; // only provided for backwards compatibility. Do not use in GZDoom projects.

* Note about dropactors
Expand Down
4 changes: 2 additions & 2 deletions src/gamedata/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ struct sector_t
float GlowHeight;
FTextureID Texture;
TextureManipulation TextureFx;
FTextureID skytexture[2];
};


Expand All @@ -690,7 +691,7 @@ struct sector_t

int special; // map-defined sector special type

int sky; // MBF sky transfer info.
int skytransfer; // MBF sky transfer info.
int validcount; // if == validcount, already checked

uint32_t selfmap, bottommap, midmap, topmap; // killough 4/4/98: dynamic colormaps
Expand Down Expand Up @@ -826,7 +827,6 @@ struct sector_t
int CheckSpriteGlow(int lightlevel, const DVector3 &pos);
bool GetWallGlow(float *topglowcolor, float *bottomglowcolor);


void SetXOffset(int pos, double o)
{
planes[pos].xform.xOffs = o;
Expand Down
1 change: 0 additions & 1 deletion src/maploader/maploader.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class MapLoader
void CreateScroller(EScroll type, double dx, double dy, sector_t *sect, side_t* side, int accel, EScrollPos scrollpos = EScrollPos::scw_all, int scrollmode = 15/*SCROLL_All*/);
void SpawnScrollers();
void SpawnFriction();
void SpawnUDMFFriction(double friction_factor, double move_factor, sector_t* sec);
void SpawnPushers();
AActor *GetPushThing (int s);
void SpawnPortal(line_t *line, int sectortag, int plane, int bytealpha, int linked);
Expand Down
4 changes: 2 additions & 2 deletions src/maploader/specials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void MapLoader::InitSectorSpecial(sector_t *sector, int special)
break;

case Sky2:
sector->sky = PL_SKYFLAT;
sector->skytransfer = PL_SKYFLAT;
break;

default:
Expand Down Expand Up @@ -872,7 +872,7 @@ void MapLoader::SpawnSpecials ()
{
auto itr = Level->GetSectorTagIterator(line.args[0]);
while ((s = itr.Next()) >= 0)
Level->sectors[s].sky = (line.Index() + 1) | PL_SKYFLAT;
Level->sectors[s].skytransfer = (line.Index() + 1) | PL_SKYFLAT;
break;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/maploader/udmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,22 @@ class UDMFParser : public UDMFParserBase
movefactor = CheckFloat(key);
break;

case NAME_skyfloor:
sec->planes[sector_t::floor].skytexture[0] = TexMan.CheckForTexture(CheckString(key), ETextureType::Wall, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ReturnFirst);
break;

case NAME_skyfloor2:
sec->planes[sector_t::floor].skytexture[1] = TexMan.CheckForTexture(CheckString(key), ETextureType::Wall, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ReturnFirst);
break;

case NAME_skyceiling:
sec->planes[sector_t::ceiling].skytexture[0] = TexMan.CheckForTexture(CheckString(key), ETextureType::Wall, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ReturnFirst);
break;

case NAME_skyceiling2:
sec->planes[sector_t::ceiling].skytexture[1] = TexMan.CheckForTexture(CheckString(key), ETextureType::Wall, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ReturnFirst);
break;

// These two are used by Eternity for something I do not understand.
//case NAME_portal_ceil_useglobaltex:
//case NAME_portal_floor_useglobaltex:
Expand Down
2 changes: 2 additions & 0 deletions src/namedef_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@ xx(thrustlocation)
xx(colormap)
xx(skyfloor)
xx(skyceiling)
xx(skyfloor2)
xx(skyceiling2)
xx(frictionfactor)
xx(movefactor)

Expand Down
2 changes: 1 addition & 1 deletion src/p_saveg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t
("damageinterval", p.damageinterval, def->damageinterval)
("leakydamage", p.leakydamage, def->leakydamage)
("damagetype", p.damagetype, def->damagetype)
("sky", p.sky, def->sky)
("sky", p.skytransfer, def->skytransfer)
("moreflags", p.MoreFlags, def->MoreFlags)
("flags", p.Flags, def->Flags)
.Array("portals", p.Portals, def->Portals, 2, true)
Expand Down
4 changes: 4 additions & 0 deletions src/p_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ static void PrecacheLevel(FLevelLocals *Level)
{
AddToList(hitlist.Data(), Level->sectors[i].GetTexture(sector_t::floor), FTextureManager::HIT_Flat);
AddToList(hitlist.Data(), Level->sectors[i].GetTexture(sector_t::ceiling), FTextureManager::HIT_Flat);
AddToList(hitlist.Data(), Level->sectors[i].planes[0].skytexture[0], FTextureManager::HIT_Wall);
AddToList(hitlist.Data(), Level->sectors[i].planes[0].skytexture[1], FTextureManager::HIT_Wall);
AddToList(hitlist.Data(), Level->sectors[i].planes[1].skytexture[0], FTextureManager::HIT_Wall);
AddToList(hitlist.Data(), Level->sectors[i].planes[1].skytexture[1], FTextureManager::HIT_Wall);
}

for (i = Level->sides.Size() - 1; i >= 0; i--)
Expand Down
1 change: 1 addition & 0 deletions src/playsim/p_sectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,3 +1637,4 @@ void vertex_t::RecalcVertexHeights()
if (numheights <= 2) numheights = 0; // is not in need of any special attention
dirty = false;
}

2 changes: 1 addition & 1 deletion src/rendering/hwrenderer/scene/hw_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ void HWEEHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
sector->GetTexture(sector_t::ceiling) == skyflatnum)
{
HWSkyInfo skyinfo;
skyinfo.init(di, sector->sky, 0);
skyinfo.init(di, sector, sector_t::ceiling, sector->skytransfer, 0);
HWSkyPortal sky(screen->mSkyData, mState, &skyinfo, true);
sky.DrawContents(di, state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/hwrenderer/scene/hw_portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct HWSkyInfo
{
return !!memcmp(this, &inf, sizeof(*this));
}
void init(HWDrawInfo *di, int sky1, PalEntry fadecolor);
void init(HWDrawInfo *di, sector_t* sec, int skypos, int sky1, PalEntry fadecolor);
};

struct HWHorizonInfo
Expand Down
31 changes: 23 additions & 8 deletions src/rendering/hwrenderer/scene/hw_sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,26 @@

CVAR(Bool,gl_noskyboxes, false, 0)

//===========================================================================
//
//
//
//===========================================================================

FTextureID GetSkyTexture(sector_t* sec, int plane, int second)
{
auto tex = sec->planes[plane].skytexture[second];
if (tex.isValid()) return tex;
return second ? sec->Level->skytexture2 : sec->Level->skytexture1;
}

//==========================================================================
//
// Set up the skyinfo struct
//
//==========================================================================

void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor)
void HWSkyInfo::init(HWDrawInfo *di, sector_t* sec, int skypos, int sky1, PalEntry FadeColor)
{
memset(this, 0, sizeof(*this));
if ((sky1 & PL_SKYFLAT) && (sky1 & (PL_SKYFLAT - 1)))
Expand Down Expand Up @@ -73,25 +86,27 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor)
else
{
normalsky:
auto skytex1 = GetSkyTexture(sec, skypos, false);
auto skytex2 = GetSkyTexture(sec, skypos, true);
if (di->Level->flags&LEVEL_DOUBLESKY)
{
auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true);
auto tex1 = TexMan.GetGameTexture(skytex1);
texture[1] = tex1;
x_offset[1] = di->Level->hw_sky1pos;
doublesky = true;
}

if ((di->Level->flags&LEVEL_SWAPSKIES || (sky1 == PL_SKYFLAT) || (di->Level->flags&LEVEL_DOUBLESKY)) &&
di->Level->skytexture2 != di->Level->skytexture1) // If both skies are equal use the scroll offset of the first!
skytex2 != skytex1) // If both skies are equal use the scroll offset of the first!
{
texture[0] = TexMan.GetGameTexture(di->Level->skytexture2, true);
skytexno1 = di->Level->skytexture2;
texture[0] = TexMan.GetGameTexture(skytex2, true);
skytexno1 = skytex2;
sky2 = true;
x_offset[0] = di->Level->hw_sky2pos;
}
else if (!doublesky)
{
texture[0] = TexMan.GetGameTexture(di->Level->skytexture1, true);
texture[0] = TexMan.GetGameTexture(skytex1, true);
skytexno1 = di->Level->skytexture1;
x_offset[0] = di->Level->hw_sky1pos;
}
Expand Down Expand Up @@ -125,7 +140,7 @@ void HWWall::SkyPlane(HWWallDispatcher *di, sector_t *sector, int plane, bool al
if (di->di)
{
HWSkyInfo skyinfo;
skyinfo.init(di->di, sector->sky, Colormap.FadeColor);
skyinfo.init(di->di, sector, plane, sector->skytransfer, Colormap.FadeColor);
ptype = PORTALTYPE_SKY;
sky = &skyinfo;
}
Expand Down Expand Up @@ -199,7 +214,7 @@ void HWWall::SkyLine(HWWallDispatcher *di, sector_t *fs, line_t *line)
}
else
{
if (di->di) skyinfo.init(di->di, fs->sky, Colormap.FadeColor);
if (di->di) skyinfo.init(di->di, fs, sector_t::ceiling, fs->skytransfer, Colormap.FadeColor);
ptype = PORTALTYPE_SKY;
sky = &skyinfo;
}
Expand Down
8 changes: 4 additions & 4 deletions src/rendering/swrenderer/scene/r_opaque_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ namespace swrenderer
frontsector->GetAlpha(sector_t::ceiling),
!!(frontsector->GetFlags(sector_t::ceiling) & PLANEF_ADDITIVE),
frontsector->planes[sector_t::ceiling].xform,
frontsector->sky,
frontsector->skytransfer,
portal,
basecolormap,
Fake3DOpaque::Normal,
Expand Down Expand Up @@ -595,7 +595,7 @@ namespace swrenderer
frontsector->GetAlpha(sector_t::floor),
!!(frontsector->GetFlags(sector_t::floor) & PLANEF_ADDITIVE),
frontsector->planes[sector_t::floor].xform,
frontsector->sky,
frontsector->skytransfer,
portal,
basecolormap,
Fake3DOpaque::Normal,
Expand Down Expand Up @@ -732,7 +732,7 @@ namespace swrenderer
tempsec.GetAlpha(sector_t::floor),
!!(clip3d->fakeFloor->fakeFloor->flags & FF_ADDITIVETRANS),
tempsec.planes[position].xform,
tempsec.sky,
tempsec.skytransfer,
nullptr,
basecolormap,
Fake3DOpaque::FakeFloor,
Expand Down Expand Up @@ -800,7 +800,7 @@ namespace swrenderer
tempsec.GetAlpha(sector_t::ceiling),
!!(clip3d->fakeFloor->fakeFloor->flags & FF_ADDITIVETRANS),
tempsec.planes[position].xform,
tempsec.sky,
tempsec.skytransfer,
nullptr,
basecolormap,
Fake3DOpaque::FakeCeiling,
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/vmthunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,7 @@ DEFINE_FIELD_X(Sector, sector_t, SoundTarget)
DEFINE_FIELD_X(Sector, sector_t, special)
DEFINE_FIELD_X(Sector, sector_t, lightlevel)
DEFINE_FIELD_X(Sector, sector_t, seqType)
DEFINE_FIELD_X(Sector, sector_t, sky)
DEFINE_FIELD_NAMED_X(Sector, sector_t, skytransfer, sky)
DEFINE_FIELD_X(Sector, sector_t, SeqName)
DEFINE_FIELD_X(Sector, sector_t, centerspot)
DEFINE_FIELD_X(Sector, sector_t, validcount)
Expand Down

0 comments on commit bdee1f3

Please sign in to comment.