- added a reverse tile map so that the tile manager can retrieve special info even when a tile texture is passed by object to the render code and not by index.

This commit is contained in:
Christoph Oelckers 2020-05-24 10:30:09 +02:00
parent cbeb481d59
commit db4850a028
6 changed files with 28 additions and 7 deletions

View File

@ -2125,7 +2125,7 @@ int32_t enginePostInit(void)
I_FatalError("No translucency table found."); I_FatalError("No translucency table found.");
palettePostLoadTables(); palettePostLoadTables();
TileFiles.SetupReverseTileMap();
return 0; return 0;
} }

View File

@ -86,7 +86,8 @@ FBitmap FTileTexture::GetBgraBitmap(const PalEntry* remap, int* ptrans)
TArray<uint8_t> buffer; TArray<uint8_t> buffer;
bmp.Create(Size.x, Size.y); bmp.Create(Size.x, Size.y);
const uint8_t* ppix = Get8BitPixels(); const uint8_t* ppix = Get8BitPixels();
if (!remap) remap = GPalette.BaseColors; // no remap was passed but this code needs a color table, so use the base. if (!remap)
remap = GPalette.BaseColors; // no remap was passed but this code needs a color table, so use the base.
if (!ppix) if (!ppix)
{ {
// This is needed for tiles with a palette remap. // This is needed for tiles with a palette remap.
@ -133,6 +134,7 @@ void BuildTiles::AddTile(int tilenum, FTexture* tex, bool permap)
auto& array = permap ? AllMapTiles : AllTiles; auto& array = permap ? AllMapTiles : AllTiles;
array.Push(tex); array.Push(tex);
tiles[tilenum] = tex; tiles[tilenum] = tex;
if (!permap) tilesbak[tilenum] = tex; if (!permap) tilesbak[tilenum] = tex;
} }
@ -634,6 +636,7 @@ void artClearMapArt(void)
{ {
TileFiles.CloseAllMapArt(); TileFiles.CloseAllMapArt();
memcpy(TileFiles.tiles, TileFiles.tilesbak, sizeof(TileFiles.tiles)); memcpy(TileFiles.tiles, TileFiles.tilesbak, sizeof(TileFiles.tiles));
TileFiles.SetupReverseTileMap();
} }
//========================================================================== //==========================================================================
@ -658,6 +661,7 @@ void artSetupMapArt(const char* filename)
FStringf fullname("%s_%02d.art", filename, i); FStringf fullname("%s_%02d.art", filename, i);
TileFiles.LoadArtFile(fullname, true); TileFiles.LoadArtFile(fullname, true);
} }
TileFiles.SetupReverseTileMap();
} }
//========================================================================== //==========================================================================

View File

@ -232,6 +232,7 @@ struct BuildTiles
FTexture* tilesbak[MAXTILES]; FTexture* tilesbak[MAXTILES];
TMap<FString, FTexture*> textures; TMap<FString, FTexture*> textures;
TArray<FString> addedArt; TArray<FString> addedArt;
TMap<FTexture*, int> TextureToTile;
BuildTiles() BuildTiles()
{ {
@ -267,6 +268,21 @@ struct BuildTiles
{ {
addedArt = std::move(art); addedArt = std::move(art);
} }
int GetTileIndex(FTexture* tex)
{
auto p = TextureToTile.CheckKey(tex);
return p ? *p : -1;
}
void SetupReverseTileMap()
{
TextureToTile.Clear();
for (int i = 0; i < MAXTILES; i++)
{
if (tiles[i] != nullptr) TextureToTile.Insert(tiles[i], i);
}
}
FTexture* ValidateCustomTile(int tilenum, int type); FTexture* ValidateCustomTile(int tilenum, int type);
int32_t artLoadFiles(const char* filename); int32_t artLoadFiles(const char* filename);
uint8_t* tileMakeWritable(int num); uint8_t* tileMakeWritable(int num);

View File

@ -307,7 +307,7 @@ FTextureBuffer FTexture::CreateTexBuffer(const PalEntry * remap, int flags)
FBitmap bmp(buffer, W * 4, W, H); FBitmap bmp(buffer, W * 4, W, H);
int trans; int trans = -1;
auto Pixels = GetBgraBitmap(remap, &trans); auto Pixels = GetBgraBitmap(remap, &trans);
bmp.Blit(0, 0, Pixels); bmp.Blit(0, 0, Pixels);

View File

@ -230,6 +230,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
auto& h = hictinting[palette]; auto& h = hictinting[palette];
bool applytint = false; bool applytint = false;
// Canvas textures must be treated like hightile replacements in the following code. // Canvas textures must be treated like hightile replacements in the following code.
if (picnum < 0) picnum = TileFiles.GetTileIndex(tex); // Allow getting replacements also when the texture is not passed by its tile number.
auto rep = (picnum >= 0 && hw_hightile && !(h.f & HICTINT_ALWAYSUSEART)) ? TileFiles.FindReplacement(picnum, palette) : nullptr; auto rep = (picnum >= 0 && hw_hightile && !(h.f & HICTINT_ALWAYSUSEART)) ? TileFiles.FindReplacement(picnum, palette) : nullptr;
if (rep || tex->GetUseType() == FTexture::Canvas) if (rep || tex->GetUseType() == FTexture::Canvas)
{ {
@ -292,7 +293,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
} }
// Also load additional layers needed for this texture. // Also load additional layers needed for this texture.
if (hw_detailmapping && hw_hightile) if (hw_detailmapping && hw_hightile && picnum > -1)
{ {
float detscalex = detscale, detscaley = detscale; float detscalex = detscale, detscaley = detscale;
if (!(method & DAMETH_MODEL)) if (!(method & DAMETH_MODEL))
@ -325,7 +326,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
*/ */
} }
} }
if (hw_glowmapping && hw_hightile) if (hw_glowmapping && hw_hightile && picnum > -1)
{ {
if (!(method & DAMETH_MODEL)) if (!(method & DAMETH_MODEL))
{ {
@ -344,7 +345,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int
} }
} }
#if 1 #if 1
if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap]) if (!(tex->PicAnim.sf & PICANM_NOFULLBRIGHT_BIT) && !(globalflags & GLOBAL_NO_GL_FULLBRIGHT) && !tex->NoBrightmapFlag[usepalswap] && picnum > -1)
{ {
if (TextureType == TT_HICREPLACE) if (TextureType == TT_HICREPLACE)
{ {

View File

@ -178,7 +178,7 @@ void GLInstance::Draw2D(F2DDrawer *drawer)
curbasepal = (cmd.mRemapIndex >> 8) & 0xff; curbasepal = (cmd.mRemapIndex >> 8) & 0xff;
auto savedf = globalflags; auto savedf = globalflags;
if (curbasepal > 0) globalflags |= GLOBAL_NO_GL_FULLBRIGHT; // temp. hack to disable brightmaps. if (curbasepal > 0) globalflags |= GLOBAL_NO_GL_FULLBRIGHT; // temp. hack to disable brightmaps.
SetTexture(0, tex, cmd.mRemapIndex & 0xff, 4/*DAMETH_CLAMPED*/, cmd.mFlags & F2DDrawer::DTF_Wrap ? SamplerRepeat : SamplerClampXY); SetTexture(-1, tex, cmd.mRemapIndex & 0xff, 4/*DAMETH_CLAMPED*/, cmd.mFlags & F2DDrawer::DTF_Wrap ? SamplerRepeat : SamplerClampXY);
curbasepal = saved; curbasepal = saved;
globalflags = savedf; globalflags = savedf;
} }