Skip to content

Commit

Permalink
- support for indexed hightiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers authored and mjr4077au committed Jul 17, 2021
1 parent 77e0463 commit af073ac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
14 changes: 9 additions & 5 deletions source/core/defparser.cpp
Expand Up @@ -45,8 +45,8 @@
#include "mapinfo.h"
#include "hw_voxels.h"

int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor);
int tileSetSkybox(int picnum, int palnum, FString* facenames);
int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor, bool indexed = false);
int tileSetSkybox(int picnum, int palnum, FString* facenames, bool indexed = false);
void tileRemoveReplacement(int num);
void AddUserMapHack(usermaphack_t&);

Expand Down Expand Up @@ -135,7 +135,8 @@ static void parseTexturePaletteBlock(FScanner& sc, int tile)

int pal = -1, xsiz = 0, ysiz = 0;
FString fn;
double alphacut = -1.0, xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0;
float alphacut = -1.0, xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0;
bool indexed = false;

if (!sc.GetNumber(pal, true)) return;

Expand All @@ -151,6 +152,7 @@ static void parseTexturePaletteBlock(FScanner& sc, int tile)
else if (sc.Compare({ "specfactor", "specularfactor", "parallaxbias" })) sc.GetFloat(specfactor, true);
else if (sc.Compare("orig_sizex")) sc.GetNumber(xsiz, true);
else if (sc.Compare("orig_sizey")) sc.GetNumber(ysiz, true);
else if (sc.Compare("indexed")) indexed = true;
};

if ((unsigned)tile < MAXUSERTILES)
Expand All @@ -167,7 +169,7 @@ static void parseTexturePaletteBlock(FScanner& sc, int tile)
xscale = 1.0f / xscale;
yscale = 1.0f / yscale;

tileSetHightileReplacement(tile, pal, fn, alphacut, xscale, yscale, specpower, specfactor);
tileSetHightileReplacement(tile, pal, fn, alphacut, xscale, yscale, specpower, specfactor, indexed);
}
}
}
Expand Down Expand Up @@ -485,6 +487,7 @@ void parseSkybox(FScanner& sc, FScriptPosition& pos)
FString faces[6];
FScanner::SavedPos blockend;
int tile = -1, pal = 0;
bool indexed = false;

if (sc.StartBraces(&blockend)) return;
while (!sc.FoundEndBrace(blockend))
Expand All @@ -498,10 +501,11 @@ void parseSkybox(FScanner& sc, FScriptPosition& pos)
else if (sc.Compare({ "lt", "lf", "left" })) sc.GetString(faces[3]);
else if (sc.Compare({ "up", "ceiling", "top", "ceil" })) sc.GetString(faces[4]);
else if (sc.Compare({ "dn", "floor", "bottom", "down" })) sc.GetString(faces[5]);
else if (sc.Compare("indexed")) indexed = true;
// skip over everything else.
}
if (tile < 0) pos.Message(MSG_ERROR, "skybox: missing tile number");
else tileSetSkybox(tile, pal, faces);
else tileSetSkybox(tile, pal, faces, indexed);
}

//===========================================================================
Expand Down
2 changes: 1 addition & 1 deletion source/core/textures/buildtiles.cpp
Expand Up @@ -60,7 +60,7 @@ enum

BuildTiles TileFiles;

int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor);
int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor, bool indexed = false);

//==========================================================================
//
Expand Down
32 changes: 19 additions & 13 deletions source/core/textures/hightile.cpp
Expand Up @@ -59,6 +59,7 @@ struct HightileReplacement
float alphacut, specpower, specfactor;
uint16_t palnum;
bool issky;
bool indexed;
};

static TMap<int, TArray<HightileReplacement>> tileReplacements;
Expand Down Expand Up @@ -247,7 +248,7 @@ void PostLoadSetup()
//
//==========================================================================

int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor)
int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor, bool indexed)
{
if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1;
if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1;
Expand All @@ -273,6 +274,7 @@ int tileSetHightileReplacement(int picnum, int palnum, const char* filename, flo
replace.specpower = specpower; // currently unused
replace.specfactor = specfactor; // currently unused
replace.issky = 0;
replace.indexed = indexed;
replace.palnum = (uint16_t)palnum;
AddReplacement(picnum, replace);
return 0;
Expand All @@ -285,7 +287,7 @@ int tileSetHightileReplacement(int picnum, int palnum, const char* filename, flo
//
//==========================================================================

int tileSetSkybox(int picnum, int palnum, FString* facenames)
int tileSetSkybox(int picnum, int palnum, FString* facenames, bool indexed)
{
if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1;
if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1;
Expand Down Expand Up @@ -316,6 +318,7 @@ int tileSetSkybox(int picnum, int palnum, FString* facenames)
replace.image = MakeGameTexture(sbtex, "", ETextureType::Override);
TexMan.AddGameTexture(replace.image, false);
replace.issky = 1;
replace.indexed = indexed;
replace.palnum = (uint16_t)palnum;
AddReplacement(picnum, replace);
return 0;
Expand Down Expand Up @@ -347,21 +350,24 @@ bool PickTexture(FRenderState *state, FGameTexture* tex, int paletteid, TextureP
auto rep = (hw_hightile && !(h.tintFlags & TINTF_ALWAYSUSEART)) ? FindReplacement(tex->GetID(), hipalswap, false) : nullptr;
if (rep || tex->GetTexture()->isHardwareCanvas())
{
if (usepalette > 0)
{
// This is a global setting for the entire scene, so let's do it here, right at the start. (Fixme: Store this in a static table instead of reusing the same entry for all palettes.)
auto& hh = lookups.tables[MAXPALOOKUPS - 1];
// This sets a tinting color for global palettes, e.g. water or slime - only used for hires replacements (also an option for low-resource hardware where duplicating the textures may be problematic.)
pick.basepalTint = hh.tintColor;
}

if (rep)
{
tex = rep->image;
}
if (!rep || rep->palnum != hipalswap || (h.tintFlags & TINTF_APPLYOVERALTPAL))
applytint = true;
pick.translation = 0;
if (!rep || !rep->indexed)
{
if (usepalette > 0)
{
// This is a global setting for the entire scene, so let's do it here, right at the start. (Fixme: Store this in a static table instead of reusing the same entry for all palettes.)
auto& hh = lookups.tables[MAXPALOOKUPS - 1];
// This sets a tinting color for global palettes, e.g. water or slime - only used for hires replacements (also an option for low-resource hardware where duplicating the textures may be problematic.)
pick.basepalTint = hh.tintColor;
}

if (!rep || rep->palnum != hipalswap || (h.tintFlags & TINTF_APPLYOVERALTPAL))
applytint = true;
pick.translation = 0;
}
}
else
{
Expand Down

0 comments on commit af073ac

Please sign in to comment.