From db4850a0282a71f59dc4b399bfe6a272b5fdbea8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 24 May 2020 10:30:09 +0200 Subject: [PATCH] - 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. --- source/build/src/engine.cpp | 2 +- source/core/textures/buildtiles.cpp | 6 +++++- source/core/textures/buildtiles.h | 16 ++++++++++++++++ source/core/textures/texture.cpp | 2 +- source/glbackend/gl_texture.cpp | 7 ++++--- source/glbackend/hw_draw2d.cpp | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 5c45d02e0..ea29378cc 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -2125,7 +2125,7 @@ int32_t enginePostInit(void) I_FatalError("No translucency table found."); palettePostLoadTables(); - + TileFiles.SetupReverseTileMap(); return 0; } diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index f15911713..dfb1cd4de 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -86,7 +86,8 @@ FBitmap FTileTexture::GetBgraBitmap(const PalEntry* remap, int* ptrans) TArray buffer; bmp.Create(Size.x, Size.y); 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) { // 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; array.Push(tex); tiles[tilenum] = tex; + if (!permap) tilesbak[tilenum] = tex; } @@ -634,6 +636,7 @@ void artClearMapArt(void) { TileFiles.CloseAllMapArt(); 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); TileFiles.LoadArtFile(fullname, true); } + TileFiles.SetupReverseTileMap(); } //========================================================================== diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index bdfeef572..928f4c937 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -232,6 +232,7 @@ struct BuildTiles FTexture* tilesbak[MAXTILES]; TMap textures; TArray addedArt; + TMap TextureToTile; BuildTiles() { @@ -267,6 +268,21 @@ struct BuildTiles { 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); int32_t artLoadFiles(const char* filename); uint8_t* tileMakeWritable(int num); diff --git a/source/core/textures/texture.cpp b/source/core/textures/texture.cpp index 304cee9f0..f01f45f3d 100644 --- a/source/core/textures/texture.cpp +++ b/source/core/textures/texture.cpp @@ -307,7 +307,7 @@ FTextureBuffer FTexture::CreateTexBuffer(const PalEntry * remap, int flags) FBitmap bmp(buffer, W * 4, W, H); - int trans; + int trans = -1; auto Pixels = GetBgraBitmap(remap, &trans); bmp.Blit(0, 0, Pixels); diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index 13816ea62..1bca5f34a 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -230,6 +230,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int auto& h = hictinting[palette]; bool applytint = false; // 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; 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. - if (hw_detailmapping && hw_hightile) + if (hw_detailmapping && hw_hightile && picnum > -1) { float detscalex = detscale, detscaley = detscale; 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)) { @@ -344,7 +345,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int } } #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) { diff --git a/source/glbackend/hw_draw2d.cpp b/source/glbackend/hw_draw2d.cpp index 44d01b112..2aaae3603 100644 --- a/source/glbackend/hw_draw2d.cpp +++ b/source/glbackend/hw_draw2d.cpp @@ -178,7 +178,7 @@ void GLInstance::Draw2D(F2DDrawer *drawer) curbasepal = (cmd.mRemapIndex >> 8) & 0xff; auto savedf = globalflags; 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; globalflags = savedf; }