- moved the front layer hack for Hexen's skies to the texture manager.

This commit is contained in:
Christoph Oelckers 2020-04-16 00:33:12 +02:00
parent da873ca8d1
commit 5352682697
10 changed files with 48 additions and 48 deletions

View file

@ -217,32 +217,6 @@ FGameTexture *FGameTexture::GetRawTexture()
return tex->OffsetLess; return tex->OffsetLess;
} }
//==========================================================================
//
// Same shit for a different hack, this time Hexen's front sky layers.
//
//==========================================================================
FGameTexture* FGameTexture::GetFrontSkyLayer()
{
auto tex = GetTexture();
if (tex->FrontSkyLayer) return tex->FrontSkyLayer;
// Reject anything that cannot have been a front layer for the sky in Hexen.
auto image = tex->GetImage();
if (image == nullptr || !image->SupportRemap0() || GetUseType() != ETextureType::Wall || tex->Scale.X != 1 || tex->Scale.Y != 1 || useWorldPanning() || tex->_TopOffset[0] != 0 ||
image->GetWidth() != GetTexelWidth() || image->GetHeight() != GetTexelHeight())
{
tex->FrontSkyLayer = this;
return this;
}
tex->FrontSkyLayer = MakeGameTexture(new FImageTexture(image, ""));
TexMan.AddGameTexture(tex->FrontSkyLayer);
tex->FrontSkyLayer->GetTexture()->bNoRemap0 = true;
return tex->FrontSkyLayer;
}
void FTexture::SetDisplaySize(int fitwidth, int fitheight) void FTexture::SetDisplaySize(int fitwidth, int fitheight)
{ {
Scale.X = double(Width) / fitwidth; Scale.X = double(Width) / fitwidth;

View file

@ -375,7 +375,7 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut
// //
//========================================================================== //==========================================================================
FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohash)
{ {
int bucket; int bucket;
int hash; int hash;
@ -385,7 +385,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture)
// Later textures take precedence over earlier ones // Later textures take precedence over earlier ones
// Textures without name can't be looked for // Textures without name can't be looked for
if (texture->GetName().IsNotEmpty()) if (addtohash && texture->GetName().IsNotEmpty())
{ {
bucket = int(MakeKey (texture->GetName()) % HASH_SIZE); bucket = int(MakeKey (texture->GetName()) % HASH_SIZE);
hash = HashFirst[bucket]; hash = HashFirst[bucket];
@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture)
hash = -1; hash = -1;
} }
TextureHash hasher = { texture, -1, hash }; TextureHash hasher = { texture, -1, -1, hash };
int trans = Textures.Push (hasher); int trans = Textures.Push (hasher);
Translation.Push (trans); Translation.Push (trans);
if (bucket >= 0) HashFirst[bucket] = trans; if (bucket >= 0) HashFirst[bucket] = trans;
@ -1176,6 +1176,38 @@ void FTextureManager::InitPalettedVersions()
} }
} }
//==========================================================================
//
// Same shit for a different hack, this time Hexen's front sky layers.
//
//==========================================================================
FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid)
{
int texidx = texid.GetIndex();
if (texidx >= Textures.Size()) return texid;
if (Textures[texidx].FrontSkyLayer != -1) return FSetTextureID(Textures[texidx].FrontSkyLayer);
// Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches.
auto tex = Textures[texidx].Texture;
auto image = tex->GetTexture()->GetImage();
if (image == nullptr || !image->SupportRemap0() || tex->GetUseType() != ETextureType::Wall || tex->useWorldPanning() || tex->GetTexelTopOffset() != 0 ||
tex->GetTexelWidth() != tex->GetDisplayWidth() || tex->GetTexelHeight() != tex->GetDisplayHeight())
{
Textures[texidx].FrontSkyLayer = texidx;
return texid;
}
// Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load.
auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName()));
FrontSkyLayer->SetUseType(tex->GetUseType());
FrontSkyLayer->GetTexture()->bNoRemap0 = true;
texid = TexMan.AddGameTexture(FrontSkyLayer);
Textures[texidx].FrontSkyLayer = texid.GetIndex();
Textures[texid.GetIndex()].FrontSkyLayer = texid.GetIndex(); // also let it refer to itself as its front sky layer, in case for repeated InitSkyMap calls.
return texid;
}
//========================================================================== //==========================================================================
// //
// //

View file

@ -75,6 +75,7 @@ public:
bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum);
void FlushAll(); void FlushAll();
FTextureID GetFrontSkyLayer(FTextureID);
enum enum
@ -113,7 +114,7 @@ public:
void AddLocalizedVariants(); void AddLocalizedVariants();
FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture
FTextureID AddGameTexture(FGameTexture* texture); FTextureID AddGameTexture(FGameTexture* texture, bool addtohash = true);
FTextureID GetDefaultTexture() const { return DefaultTexture; } FTextureID GetDefaultTexture() const { return DefaultTexture; }
void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build); void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build);
@ -171,6 +172,7 @@ private:
{ {
FGameTexture* Texture; FGameTexture* Texture;
int Paletted; // redirection to paletted variant int Paletted; // redirection to paletted variant
int FrontSkyLayer;
int HashNext; int HashNext;
bool HasLocalization; bool HasLocalization;
}; };

View file

@ -719,7 +719,6 @@ public:
// These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place.
FGameTexture* GetRawTexture(); FGameTexture* GetRawTexture();
FGameTexture* GetFrontSkyLayer();
// Glowing is a pure material property that should not filter down to the actual texture objects. // Glowing is a pure material property that should not filter down to the actual texture objects.
void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } void GetGlowColor(float* data) { wrapped.GetGlowColor(data); }

View file

@ -75,7 +75,6 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor)
if (di->Level->flags&LEVEL_DOUBLESKY) if (di->Level->flags&LEVEL_DOUBLESKY)
{ {
auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true); auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true);
if (tex1) tex1 = tex1->GetFrontSkyLayer();
texture[1] = tex1; texture[1] = tex1;
x_offset[1] = di->Level->hw_sky1pos; x_offset[1] = di->Level->hw_sky1pos;
doublesky = true; doublesky = true;

View file

@ -75,6 +75,11 @@ void InitSkyMap(FLevelLocals *Level)
{ {
Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any); Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
} }
if (Level->flags & LEVEL_DOUBLESKY)
{
Level->skytexture1 = TexMan.GetFrontSkyLayer(Level->skytexture1);
}
skytex1 = TexMan.GetGameTexture(Level->skytexture1, false); skytex1 = TexMan.GetGameTexture(Level->skytexture1, false);
skytex2 = TexMan.GetGameTexture(Level->skytexture2, false); skytex2 = TexMan.GetGameTexture(Level->skytexture2, false);
@ -82,10 +87,6 @@ void InitSkyMap(FLevelLocals *Level)
if (skytex1 == nullptr) if (skytex1 == nullptr)
return; return;
if (Level->flags & LEVEL_DOUBLESKY)
{
skytex1 = skytex1->GetFrontSkyLayer();
}
if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight()) if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight())
{ {

View file

@ -91,7 +91,7 @@ namespace swrenderer
auto viewport = Thread->Viewport.get(); auto viewport = Thread->Viewport.get();
Clip3DFloors *clip3d = Thread->Clip3D.get(); Clip3DFloors *clip3d = Thread->Clip3D.get();
auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, curline->GetLevel()); auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, !!(curline->GetLevel()->i_compatflags & COMPATF_MASKEDMIDTEX));
const short *mfloorclip = ds->drawsegclip.sprbottomclip; const short *mfloorclip = ds->drawsegclip.sprbottomclip;
const short *mceilingclip = ds->drawsegclip.sprtopclip; const short *mceilingclip = ds->drawsegclip.sprtopclip;

View file

@ -71,7 +71,7 @@ namespace swrenderer
Thread = thread; Thread = thread;
auto Level = Thread->Viewport->Level(); auto Level = Thread->Viewport->Level();
auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true, !!(Level->flags & LEVEL_DOUBLESKY)); auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true);
auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true); auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true);
if (sskytex1 == nullptr) if (sskytex1 == nullptr)

View file

@ -612,19 +612,12 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL)
R_InitSkyMap(); R_InitSkyMap();
} }
FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull, bool frontsky) FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat, bool allownull)
{ {
bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor();
auto tex = TexMan.GetPalettedTexture(texid, true, needpal); auto tex = TexMan.GetPalettedTexture(texid, true, needpal);
if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr;
if (frontsky) if (checkcompat) tex = tex->GetRawTexture();
{
tex = tex->GetFrontSkyLayer();
}
else if (checkcompat && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX)
{
tex = tex->GetRawTexture();
}
return GetSoftwareTexture(tex); return GetSoftwareTexture(tex);
} }

View file

@ -193,4 +193,4 @@ public:
}; };
FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex); FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex);
FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat = nullptr, bool allownull = false, bool frontsky = false); FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat = false, bool allownull = false);