Skip to content

Commit

Permalink
- moved the static sky variables into FLevelLocals and removed the re…
Browse files Browse the repository at this point in the history
…dundant ones for the texture ID.
  • Loading branch information
coelckers committed Jan 10, 2019
1 parent 439c36c commit 1c4e3ae
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 110 deletions.
27 changes: 14 additions & 13 deletions src/c_cmds.cpp
Expand Up @@ -1046,24 +1046,25 @@ CCMD(countitemsnum) // [SP] # of counted items
//-----------------------------------------------------------------------------
CCMD(changesky)
{
const char *sky1name;

if (netgame || argv.argc()<2) return;

sky1name = argv[1];
if (sky1name[0] != 0)
const char *sky1name = argv[1];
ForAllLevels([=](FLevelLocals *Level)
{
FTextureID newsky = TexMan.GetTextureID(sky1name, ETextureType::Wall, FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_ReturnFirst);
if (newsky.Exists())
{
sky1texture = level.skytexture1 = newsky;
}
else
if (sky1name[0] != 0)
{
Printf("changesky: Texture '%s' not found\n", sky1name);
FTextureID newsky = TexMan.GetTextureID(sky1name, ETextureType::Wall, FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_ReturnFirst);
if (newsky.Exists())
{
Level->skytexture1 = newsky;
}
else
{
Printf("changesky: Texture '%s' not found\n", sky1name);
}
}
}
R_InitSkyMap ();
InitSkyMap(Level);
});
}

//-----------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions src/d_main.cpp
Expand Up @@ -361,8 +361,7 @@ CUSTOM_CVAR (Int, dmflags, 0, CVAR_SERVERINFO)
{
// In case DF_NO_FREELOOK was changed, reinitialize the sky
// map. (If no freelook, then no need to stretch the sky.)
if (sky1texture.isValid())
R_InitSkyMap ();
R_InitSkyMap ();

if (self & DF_NO_FREELOOK)
{
Expand Down
4 changes: 2 additions & 2 deletions src/fragglescript/t_load.cpp
Expand Up @@ -143,8 +143,8 @@ void FScriptLoader::ParseInfoCmd(char *line, FString &scriptsrc)
sc.MustGetStringName("=");
sc.MustGetString();

sky2texture = sky1texture = Level->skytexture1 = Level->skytexture2 = TexMan.GetTextureID (sc.String, ETextureType::Wall, FTextureManager::TEXMAN_Overridable|FTextureManager::TEXMAN_ReturnFirst);
R_InitSkyMap ();
Level->skytexture1 = Level->skytexture2 = TexMan.GetTextureID (sc.String, ETextureType::Wall, FTextureManager::TEXMAN_Overridable|FTextureManager::TEXMAN_ReturnFirst);
InitSkyMap (Level);
}
else if (sc.Compare("interpic"))
{
Expand Down
18 changes: 6 additions & 12 deletions src/g_level.cpp
Expand Up @@ -1032,12 +1032,6 @@ void G_DoLoadLevel (int position, bool autosave, bool newGame)
// setting one.
skyflatnum = TexMan.GetTextureID (gameinfo.SkyFlatName, ETextureType::Flat, FTextureManager::TEXMAN_Overridable);

// DOOM determines the sky texture to be used
// depending on the current episode and the game version.
// [RH] Fetch sky parameters from FLevelLocals.
sky1texture = level.skytexture1;
sky2texture = level.skytexture2;

// [RH] Set up details about sky rendering
R_InitSkyMap ();

Expand Down Expand Up @@ -1294,10 +1288,10 @@ void G_WorldDone (FLevelLocals *Level)
}
}

DEFINE_ACTION_FUNCTION(FLevelLocals, WorldDone)
DEFINE_ACTION_FUNCTION(FGameSession, WorldDone)
{
PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals);
G_WorldDone(self);
PARAM_SELF_STRUCT_PROLOGUE(FGameSession);
G_WorldDone(self->Levelinfo[0]);
return 0;
}

Expand Down Expand Up @@ -2365,9 +2359,9 @@ DEFINE_ACTION_FUNCTION(FLevelLocals, ChangeSky)
PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals);
PARAM_INT(sky1);
PARAM_INT(sky2);
sky1texture = self->skytexture1 = FSetTextureID(sky1);
sky2texture = self->skytexture2 = FSetTextureID(sky2);
R_InitSkyMap();
self->skytexture1 = FSetTextureID(sky1);
self->skytexture2 = FSetTextureID(sky2);
InitSkyMap(self);
return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions src/g_levellocals.h
Expand Up @@ -215,6 +215,10 @@ struct FLevelLocals : public FLevelData
float skyspeed1; // Scrolling speed of sky textures, in pixels per ms
float skyspeed2;

double sky1pos, sky2pos;
float hw_sky1pos, hw_sky2pos;
bool skystretch;

int total_secrets;
int found_secrets;

Expand Down
18 changes: 9 additions & 9 deletions src/hwrenderer/scene/hw_sky.cpp
Expand Up @@ -72,24 +72,24 @@ void GLSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor)
normalsky:
if (di->Level->flags&LEVEL_DOUBLESKY)
{
texture[1] = FMaterial::ValidateTexture(sky1texture, false, true);
x_offset[1] = hw_sky1pos;
texture[1] = FMaterial::ValidateTexture(di->Level->skytexture1, false, true);
x_offset[1] = di->Level->hw_sky1pos;
doublesky = true;
}

if ((di->Level->flags&LEVEL_SWAPSKIES || (sky1 == PL_SKYFLAT) || (di->Level->flags&LEVEL_DOUBLESKY)) &&
sky2texture != sky1texture) // If both skies are equal use the scroll offset of the first!
di->Level->skytexture2 != di->Level->skytexture1) // If both skies are equal use the scroll offset of the first!
{
texture[0] = FMaterial::ValidateTexture(sky2texture, false, true);
skytexno1 = sky2texture;
texture[0] = FMaterial::ValidateTexture(di->Level->skytexture2, false, true);
skytexno1 = di->Level->skytexture2;
sky2 = true;
x_offset[0] = hw_sky2pos;
x_offset[0] = di->Level->hw_sky2pos;
}
else if (!doublesky)
{
texture[0] = FMaterial::ValidateTexture(sky1texture, false, true);
skytexno1 = sky1texture;
x_offset[0] = hw_sky1pos;
texture[0] = FMaterial::ValidateTexture(di->Level->skytexture1, false, true);
skytexno1 = di->Level->skytexture1;
x_offset[0] = di->Level->hw_sky1pos;
}
}
if (di->Level->skyfog > 0)
Expand Down
6 changes: 3 additions & 3 deletions src/p_acs.cpp
Expand Up @@ -9794,13 +9794,13 @@ int DLevelScript::RunScript ()
sky2name = Level->Behaviors.LookupString (STACK(1));
if (sky1name[0] != 0)
{
sky1texture = Level->skytexture1 = TexMan.GetTextureID(sky1name, ETextureType::Wall, FTextureManager::TEXMAN_Overridable|FTextureManager::TEXMAN_ReturnFirst);
Level->skytexture1 = TexMan.GetTextureID(sky1name, ETextureType::Wall, FTextureManager::TEXMAN_Overridable|FTextureManager::TEXMAN_ReturnFirst);
}
if (sky2name[0] != 0)
{
sky2texture = Level->skytexture2 = TexMan.GetTextureID(sky2name, ETextureType::Wall, FTextureManager::TEXMAN_Overridable|FTextureManager::TEXMAN_ReturnFirst);
Level->skytexture2 = TexMan.GetTextureID(sky2name, ETextureType::Wall, FTextureManager::TEXMAN_Overridable|FTextureManager::TEXMAN_ReturnFirst);
}
R_InitSkyMap ();
InitSkyMap (Level);
sp -= 2;
}
break;
Expand Down
4 changes: 1 addition & 3 deletions src/p_saveg.cpp
Expand Up @@ -956,9 +956,7 @@ void G_SerializeLevel(FSerializer &arc, FLevelLocals *Level, bool hubload)

if (arc.isReading())
{
sky1texture = Level->skytexture1;
sky2texture = Level->skytexture2;
R_InitSkyMap();
InitSkyMap(Level);
}

Level->Behaviors.SerializeModuleStates(arc);
Expand Down
15 changes: 4 additions & 11 deletions src/p_setup.cpp
Expand Up @@ -170,20 +170,14 @@ static void PrecacheLevel(FLevelLocals *Level)
AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::bottom), FTextureManager::HIT_Wall);
}

// Sky texture is always present.
// Note that F_SKY1 is the name used to
// indicate a sky floor/ceiling as a flat,
// while the sky texture is stored like
// a wall texture, with an episode dependant
// name.

if (sky1texture.isValid())
if (Level->skytexture1.isValid())
{
AddToList(hitlist.Data(), sky1texture, FTextureManager::HIT_Sky);
AddToList(hitlist.Data(), Level->skytexture1, FTextureManager::HIT_Sky);
}
if (sky2texture.isValid())
if (Level->skytexture2.isValid())
{
AddToList(hitlist.Data(), sky2texture, FTextureManager::HIT_Sky);
AddToList(hitlist.Data(), Level->skytexture2, FTextureManager::HIT_Sky);
}

for (auto n : gameinfo.PrecachedTextures)
Expand Down Expand Up @@ -355,7 +349,6 @@ void P_FreeLevelData ()
// [ZZ] delete per-map event handlers
E_Shutdown(true);
R_FreePastViewers();

level.ClearLevelData();
}

Expand Down
21 changes: 11 additions & 10 deletions src/polyrenderer/scene/poly_sky.cpp
Expand Up @@ -291,9 +291,10 @@ void PolySkySetup::Update()
double skyscale = 0.0;
float skyiscale = 0.0f;
fixed_t sky1cyl = 0, sky2cyl = 0;
auto Level = PolyRenderer::Instance()->Level;

auto skytex1 = TexMan.GetPalettedTexture(sky1texture, true);
auto skytex2 = TexMan.GetPalettedTexture(sky2texture, true);
auto skytex1 = TexMan.GetPalettedTexture(Level->skytexture1, true);
auto skytex2 = TexMan.GetPalettedTexture(Level->skytexture2, true);

if (skytex1)
{
Expand All @@ -307,7 +308,7 @@ void PolySkySetup::Update()
}
else if (skyheight > 200)
{
skytexturemid = (200 - skyheight) * sskytex1->GetScale().Y + ((r_skymode == 2 && !(PolyRenderer::Instance()->Level->flags & LEVEL_FORCETILEDSKY)) ? skytex1->GetSkyOffset() : 0);
skytexturemid = (200 - skyheight) * sskytex1->GetScale().Y + ((r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY)) ? skytex1->GetSkyOffset() : 0);
}

if (viewwidth != 0 && viewheight != 0)
Expand All @@ -319,7 +320,7 @@ void PolySkySetup::Update()
skyscale *= float(90. / r_viewpoint.FieldOfView.Degrees);
}

if (skystretch)
if (Level->skystretch)
{
skyscale *= (double)SKYSTRETCH_HEIGHT / skyheight;
skyiscale *= skyheight / (float)SKYSTRETCH_HEIGHT;
Expand All @@ -339,13 +340,13 @@ void PolySkySetup::Update()

if ((PolyRenderer::Instance()->Level->flags & LEVEL_SWAPSKIES) && !(PolyRenderer::Instance()->Level->flags & LEVEL_DOUBLESKY))
{
sky1tex = sky2texture;
sky1tex = Level->skytexture2;
}
else
{
sky1tex = sky1texture;
sky1tex = Level->skytexture1;
}
sky2tex = sky2texture;
sky2tex = Level->skytexture2;
skymid = skytexturemid;
skyangle = 0;

Expand All @@ -360,8 +361,8 @@ void PolySkySetup::Update()
else
backskytex = nullptr;
skyflip = false;
frontdpos = sky1pos;
backdpos = sky2pos;
frontdpos = Level->sky1pos;
backdpos = Level->sky2pos;
frontcyl = sky1cyl;
backcyl = sky2cyl;
}
Expand All @@ -371,7 +372,7 @@ void PolySkySetup::Update()
backskytex = nullptr;
frontcyl = sky2cyl;
skyflip = false;
frontdpos = sky2pos;
frontdpos = Level->sky2pos;
}
else
{ // MBF's linedef-controlled skies
Expand Down
55 changes: 30 additions & 25 deletions src/r_sky.cpp
Expand Up @@ -43,10 +43,6 @@
// sky mapping
//
FTextureID skyflatnum;
FTextureID sky1texture, sky2texture;
double sky1pos, sky2pos;
float hw_sky1pos, hw_sky2pos;
bool skystretch;

// [RH] Stretch sky texture if not taller than 128 pixels?
// Also now controls capped skies. 0 = normal, 1 = stretched, 2 = capped
Expand All @@ -65,31 +61,32 @@ CVAR(Float, skyoffset, 0, 0) // for testing
//
//==========================================================================

void R_InitSkyMap()
void InitSkyMap(FLevelLocals *Level)
{
int skyheight;
FTexture *skytex1, *skytex2;

// Do not allow the null texture which has no bitmap and will crash.
if (sky1texture.isNull())
if (Level->skytexture1.isNull())
{
sky1texture = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
Level->skytexture1 = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
}
if (sky2texture.isNull())
if (Level->skytexture2.isNull())
{
sky2texture = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
}

skytex1 = TexMan.GetTexture(sky1texture, false);
skytex2 = TexMan.GetTexture(sky2texture, false);
skytex1 = TexMan.GetTexture(Level->skytexture1, false);
skytex2 = TexMan.GetTexture(Level->skytexture2, false);

if (skytex1 == nullptr)
return;

if ((level.flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight())
if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight())
{
Printf(TEXTCOLOR_BOLD "Both sky textures must be the same height." TEXTCOLOR_NORMAL "\n");
sky2texture = sky1texture;
Level->flags &= ~LEVEL_DOUBLESKY;
Level->skytexture1 = Level->skytexture2;
}

// There are various combinations for sky rendering depending on how tall the sky is:
Expand All @@ -109,14 +106,20 @@ void R_InitSkyMap()

if (skyheight >= 128 && skyheight < 200)
{
skystretch = (r_skymode == 1
Level->skystretch = (r_skymode == 1
&& skyheight >= 128
&& level.IsFreelookAllowed()
&& !(level.flags & LEVEL_FORCETILEDSKY)) ? 1 : 0;
&& Level->IsFreelookAllowed()
&& !(Level->flags & LEVEL_FORCETILEDSKY)) ? 1 : 0;
}
else skystretch = false;
else Level->skystretch = false;
}

void R_InitSkyMap()
{
ForAllLevels(InitSkyMap);
}


//==========================================================================
//
// R_UpdateSky
Expand All @@ -127,14 +130,16 @@ void R_InitSkyMap()

void R_UpdateSky (uint64_t mstime)
{
// Scroll the sky
double ms = (double)mstime * FRACUNIT;
sky1pos = ms * level.skyspeed1;
sky2pos = ms * level.skyspeed2;

// The hardware renderer uses a different value range and clamps it to a single rotation
hw_sky1pos = (float)(fmod((double(mstime) * level.skyspeed1), 1024.) * (90. / 256.));
hw_sky2pos = (float)(fmod((double(mstime) * level.skyspeed2), 1024.) * (90. / 256.));

ForAllLevels([=](FLevelLocals *Level)
{
// Scroll the sky
Level->sky1pos = ms * level.skyspeed1;
Level->sky2pos = ms * level.skyspeed2;

// The hardware renderer uses a different value range and clamps it to a single rotation
Level->hw_sky1pos = (float)(fmod((double(mstime) * level.skyspeed1), 1024.) * (90. / 256.));
Level->hw_sky2pos = (float)(fmod((double(mstime) * level.skyspeed2), 1024.) * (90. / 256.));
});
}

7 changes: 3 additions & 4 deletions src/r_sky.h
Expand Up @@ -30,16 +30,15 @@

#include "textures/textures.h"

struct FLevelLocals;

extern FTextureID skyflatnum;
extern FTextureID sky1texture, sky2texture;
extern double sky1pos, sky2pos;
extern float hw_sky1pos, hw_sky2pos;
extern bool skystretch;
extern int freelookviewheight;

#define SKYSTRETCH_HEIGHT 228

// Called whenever the sky changes.
void InitSkyMap(FLevelLocals *Level);
void R_InitSkyMap ();
void R_UpdateSky (uint64_t mstime);

Expand Down

0 comments on commit 1c4e3ae

Please sign in to comment.