diff --git a/src/common/engine/palettecontainer.cpp b/src/common/engine/palettecontainer.cpp index e42e60cc8..8d36af246 100644 --- a/src/common/engine/palettecontainer.cpp +++ b/src/common/engine/palettecontainer.cpp @@ -53,6 +53,7 @@ FColorMatcher ColorMatcher; void PaletteContainer::Init(int numslots) // This cannot be a constructor!!! { Clear(); + HasGlobalBrightmap = false; // Make sure that index 0 is always the identity translation. FRemapTable remap; remap.MakeIdentity(); @@ -64,16 +65,17 @@ void PaletteContainer::Init(int numslots) // This cannot be a constructor!!! void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) { + // Initialize all tables to the original palette. // At this point we do not care about the transparent index yet. for (int i = 0; i < 256; i++, colors += 3) { - BaseColors[i] = PalEntry(255, colors[0], colors[1], colors[2]); + uniqueRemaps[0]->Palette[i] = BaseColors[i] = RawColors[i] = PalEntry(255, colors[0], colors[1], colors[2]); Remap[i] = i; } - uniqueRemaps[0]->MakeIdentity(); // update the identity remap. + // If the palette already has a transparent index, clear that color now if (transparent_index >= 0 && transparent_index <= 255) { BaseColors[transparent_index] = 0; @@ -86,8 +88,8 @@ void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) // Find white and black from the original palette so that they can be // used to make an educated guess of the translucency % for a // translucency map. - WhiteIndex = BestColor((uint32_t*)BaseColors, 255, 255, 255, 0, 255); - BlackIndex = BestColor((uint32_t*)BaseColors, 0, 0, 0, 0, 255); + WhiteIndex = BestColor((uint32_t*)RawColors, 255, 255, 255, 0, 255); + BlackIndex = BestColor((uint32_t*)RawColors, 0, 0, 0, 0, 255); } @@ -241,6 +243,41 @@ int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap) return AddTranslation(slot, remap); } +//=========================================================================== +// +// Examines the colormap to see if some of the colors have to be +// considered fullbright all the time. +// +//=========================================================================== + +void PaletteContainer::GenerateGlobalBrightmapFromColormap(const uint8_t *cmapdata, int numlevels) +{ + GlobalBrightmap.MakeIdentity(); + memset(GlobalBrightmap.Remap, WhiteIndex, 256); + for (int i = 0; i < 256; i++) GlobalBrightmap.Palette[i] = PalEntry(255, 255, 255, 255); + for (int j = 0; j < numlevels; j++) + { + for (int i = 0; i < 256; i++) + { + // the palette comparison should be for ==0 but that gives false positives with Heretic + // and Hexen. + uint8_t mappedcolor = cmapdata[i]; // consider colormaps which already remap the base level. + if (cmapdata[i + j * 256] != mappedcolor || (RawColors[mappedcolor].r < 10 && RawColors[mappedcolor].g < 10 && RawColors[mappedcolor].b < 10)) + { + GlobalBrightmap.Remap[i] = BlackIndex; + GlobalBrightmap.Palette[i] = PalEntry(255, 0, 0, 0); + } + } + } + for (int i = 0; i < 256; i++) + { + HasGlobalBrightmap |= GlobalBrightmap.Remap[i] == WhiteIndex; + if (GlobalBrightmap.Remap[i] == WhiteIndex) DPrintf(DMSG_NOTIFY, "Marked color %d as fullbright\n", i); + } +} + + + //---------------------------------------------------------------------------- // // diff --git a/src/common/engine/palettecontainer.h b/src/common/engine/palettecontainer.h index 7b7143bae..0abc00e26 100644 --- a/src/common/engine/palettecontainer.h +++ b/src/common/engine/palettecontainer.h @@ -71,10 +71,15 @@ class PaletteContainer { public: PalEntry BaseColors[256]; // non-gamma corrected palette + PalEntry RawColors[256]; // colors as read from the game data without the transparancy remap applied uint8_t Remap[256]; // remap original palette indices to in-game indices uint8_t WhiteIndex; // white in original palette index uint8_t BlackIndex; // black in original palette index + + bool HasGlobalBrightmap; + FRemapTable GlobalBrightmap; + private: FMemArena remapArena; TArray uniqueRemaps; @@ -90,6 +95,7 @@ public: void CopyTranslation(int dest, int src); int StoreTranslation(int slot, FRemapTable* remap); FRemapTable* TranslationToTable(int translation); + void GenerateGlobalBrightmapFromColormap(const uint8_t* cmapdata, int numlevels); void PushIdentityTable(int slot) { diff --git a/src/doomtype.h b/src/doomtype.h index 6121d1294..a382522c8 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -75,6 +75,7 @@ public: bool operator !=(const FTextureID &other) const { return texnum != other.texnum; } FTextureID operator +(int offset) throw(); int GetIndex() const { return texnum; } // Use this only if you absolutely need the index! + void SetIndex(int index) { texnum = index; } // Use this only if you absolutely need the index! // The switch list needs these to sort the switches by texture index int operator -(FTextureID other) const { return texnum - other.texnum; } diff --git a/src/gamedata/textures/formats/automaptexture.cpp b/src/gamedata/textures/formats/automaptexture.cpp index 87200daf4..f9a4b3112 100644 --- a/src/gamedata/textures/formats/automaptexture.cpp +++ b/src/gamedata/textures/formats/automaptexture.cpp @@ -35,7 +35,6 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "textures/textures.h" diff --git a/src/gamedata/textures/formats/brightmaptexture.cpp b/src/gamedata/textures/formats/brightmaptexture.cpp index a5ed6477a..f7e36d628 100644 --- a/src/gamedata/textures/formats/brightmaptexture.cpp +++ b/src/gamedata/textures/formats/brightmaptexture.cpp @@ -33,12 +33,9 @@ ** */ -#include "doomtype.h" #include "filesystem.h" - -#include "r_data/r_translate.h" +#include "palettecontainer.h" #include "bitmap.h" -#include "v_video.h" #include "image.h" class FBrightmapTexture : public FImageSource @@ -70,11 +67,11 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source) int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion) { - SourcePic->CopyTranslatedPixels(bmp, TexMan.GlobalBrightmap.Palette); + SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette); return 0; } FTexture *CreateBrightmapTexture(FImageSource *tex) { - return new FImageTexture(new FBrightmapTexture(tex)); + return CreateImageTexture(new FBrightmapTexture(tex)); } diff --git a/src/gamedata/textures/formats/buildtexture.cpp b/src/gamedata/textures/formats/buildtexture.cpp index 0c170d7b4..fba5c3493 100644 --- a/src/gamedata/textures/formats/buildtexture.cpp +++ b/src/gamedata/textures/formats/buildtexture.cpp @@ -34,7 +34,6 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "templates.h" @@ -42,7 +41,6 @@ #include "colormatcher.h" #include "bitmap.h" #include "textures/textures.h" -#include "r_data/sprites.h" #include "resourcefile.h" #include "image.h" @@ -101,113 +99,6 @@ int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion) } -//=========================================================================== -// -// AddTiles -// -// Adds all the tiles in an artfile to the texture manager. -// -//=========================================================================== - -void FTextureManager::AddTiles (const FString &pathprefix, const void *tiles, int translation) -{ - -// int numtiles = LittleLong(((uint32_t *)tiles)[1]); // This value is not reliable - int tilestart = LittleLong(((uint32_t *)tiles)[2]); - int tileend = LittleLong(((uint32_t *)tiles)[3]); - const uint16_t *tilesizx = &((const uint16_t *)tiles)[8]; - const uint16_t *tilesizy = &tilesizx[tileend - tilestart + 1]; - const uint32_t *picanm = (const uint32_t *)&tilesizy[tileend - tilestart + 1]; - const uint8_t *tiledata = (const uint8_t *)&picanm[tileend - tilestart + 1]; - - for (int i = tilestart; i <= tileend; ++i) - { - int pic = i - tilestart; - int width = LittleShort(tilesizx[pic]); - int height = LittleShort(tilesizy[pic]); - uint32_t anm = LittleLong(picanm[pic]); - int xoffs = (int8_t)((anm >> 8) & 255) + width/2; - int yoffs = (int8_t)((anm >> 16) & 255) + height/2; - int size = width*height; - FTextureID texnum; - FTexture *tex; - - if (width <= 0 || height <= 0) continue; - - tex = new FImageTexture(new FBuildTexture (pathprefix, i, tiledata, translation, width, height, xoffs, yoffs)); - texnum = AddTexture (tex); - tiledata += size; - tex->Name.Format("%sBTIL%04d", pathprefix.GetChars(), i); - tex->UseType = ETextureType::Override; - - - // reactivate only if the texture counter works here. - //StartScreen->Progress(); - - if ((picanm[pic] & 63) && (picanm[pic] & 192)) - { - int type, speed; - - switch (picanm[pic] & 192) - { - case 64: type = 2; break; - case 128: type = 0; break; - case 192: type = 1; break; - default: type = 0; break; // Won't happen, but GCC bugs me if I don't put this here. - } - - speed = (anm >> 24) & 15; - speed = MAX (1, (1 << speed) * 1000 / 120); // Convert from 120 Hz to 1000 Hz. - - AddSimpleAnim (texnum, picanm[pic] & 63, type, speed); - } - - // Blood's rotation types: - // 0 - Single - // 1 - 5 Full - // 2 - 8 Full - // 3 - Bounce (looks no different from Single; seems to signal bouncy sprites) - // 4 - 5 Half (not used in game) - // 5 - 3 Flat (not used in game) - // 6 - Voxel - // 7 - Spin Voxel - - int rotType = (anm >> 28) & 7; - if (rotType == 1) - { - spriteframe_t rot; - rot.Texture[0] = - rot.Texture[1] = texnum; - for (int j = 1; j < 4; ++j) - { - rot.Texture[j*2] = - rot.Texture[j*2+1] = - rot.Texture[16-j*2] = - rot.Texture[17-j*2] = texnum.GetIndex() + j; - } - rot.Texture[8] = - rot.Texture[9] = texnum.GetIndex() + 4; - rot.Flip = 0x00FC; - rot.Voxel = NULL; - tex->Rotations = SpriteFrames.Push (rot); - } - else if (rotType == 2) - { - spriteframe_t rot; - rot.Texture[0] = - rot.Texture[1] = texnum; - for (int j = 1; j < 8; ++j) - { - rot.Texture[16-j*2] = - rot.Texture[17-j*2] = texnum.GetIndex() + j; - } - rot.Flip = 0; - rot.Voxel = NULL; - tex->Rotations = SpriteFrames.Push (rot); - } - } -} - //=========================================================================== // // CountTiles @@ -284,6 +175,114 @@ static int BuildPaletteTranslation(int lump) } +#include "r_data/sprites.h" +//=========================================================================== +// +// AddTiles +// +// Adds all the tiles in an artfile to the texture manager. +// +//=========================================================================== + +void AddTiles(const FString& pathprefix, const void* tiles, int translation) +{ + + // int numtiles = LittleLong(((uint32_t *)tiles)[1]); // This value is not reliable + int tilestart = LittleLong(((uint32_t*)tiles)[2]); + int tileend = LittleLong(((uint32_t*)tiles)[3]); + const uint16_t* tilesizx = &((const uint16_t*)tiles)[8]; + const uint16_t* tilesizy = &tilesizx[tileend - tilestart + 1]; + const uint32_t* picanm = (const uint32_t*)&tilesizy[tileend - tilestart + 1]; + const uint8_t* tiledata = (const uint8_t*)&picanm[tileend - tilestart + 1]; + + for (int i = tilestart; i <= tileend; ++i) + { + int pic = i - tilestart; + int width = LittleShort(tilesizx[pic]); + int height = LittleShort(tilesizy[pic]); + uint32_t anm = LittleLong(picanm[pic]); + int xoffs = (int8_t)((anm >> 8) & 255) + width / 2; + int yoffs = (int8_t)((anm >> 16) & 255) + height / 2; + int size = width * height; + FTextureID texnum; + FTexture* tex; + + if (width <= 0 || height <= 0) continue; + + FStringf name("%sBTIL%04d", pathprefix.GetChars(), i); + tex = new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, translation, width, height, xoffs, yoffs), name); + texnum = TexMan.AddTexture(tex); + tiledata += size; + tex->SetUseType(ETextureType::Override); + + + // reactivate only if the texture counter works here. + //StartScreen->Progress(); + + if ((picanm[pic] & 63) && (picanm[pic] & 192)) + { + int type, speed; + + switch (picanm[pic] & 192) + { + case 64: type = 2; break; + case 128: type = 0; break; + case 192: type = 1; break; + default: type = 0; break; // Won't happen, but GCC bugs me if I don't put this here. + } + + speed = (anm >> 24) & 15; + speed = MAX(1, (1 << speed) * 1000 / 120); // Convert from 120 Hz to 1000 Hz. + + TexMan.AddSimpleAnim(texnum, picanm[pic] & 63, type, speed); + } + + // Blood's rotation types: + // 0 - Single + // 1 - 5 Full + // 2 - 8 Full + // 3 - Bounce (looks no different from Single; seems to signal bouncy sprites) + // 4 - 5 Half (not used in game) + // 5 - 3 Flat (not used in game) + // 6 - Voxel + // 7 - Spin Voxel + + int rotType = (anm >> 28) & 7; + if (rotType == 1) + { + spriteframe_t rot; + rot.Texture[0] = + rot.Texture[1] = texnum; + for (int j = 1; j < 4; ++j) + { + rot.Texture[j * 2].SetIndex(texnum.GetIndex() + j); + rot.Texture[j * 2 + 1].SetIndex(texnum.GetIndex() + j); + rot.Texture[16 - j * 2].SetIndex(texnum.GetIndex() + j); + rot.Texture[17 - j * 2].SetIndex(texnum.GetIndex() + j); + } + rot.Texture[8].SetIndex(texnum.GetIndex()); + rot.Texture[9].SetIndex(texnum.GetIndex()); + rot.Flip = 0x00FC; + rot.Voxel = NULL; + tex->SetRotations(SpriteFrames.Push(rot)); + } + else if (rotType == 2) + { + spriteframe_t rot; + rot.Texture[0] = + rot.Texture[1] = texnum; + for (int j = 1; j < 8; ++j) + { + rot.Texture[16 - j * 2].SetIndex(texnum.GetIndex() + j); + rot.Texture[17 - j * 2].SetIndex(texnum.GetIndex() + j); + } + rot.Flip = 0; + rot.Voxel = NULL; + tex->SetRotations(SpriteFrames.Push(rot)); + } + } +} + //=========================================================================== // // R_CountBuildTiles @@ -293,7 +292,7 @@ static int BuildPaletteTranslation(int lump) // //=========================================================================== -void FTextureManager::InitBuildTiles() +void InitBuildTiles() { int lumpnum; int numtiles; @@ -312,7 +311,7 @@ void FTextureManager::InitBuildTiles() int numlumps = fileSystem.GetNumEntries(); for (int i = 0; i < numlumps; i++) { - const char *name = fileSystem.GetFileFullName(i); + const char* name = fileSystem.GetFileFullName(i); if (fileSystem.CheckNumForFullName(name) != i) continue; // This palette is hidden by a later one. Do not process FString base = ExtractFileBase(name, true); base.ToLower(); @@ -328,14 +327,13 @@ void FTextureManager::InitBuildTiles() // only read from the same source as the palette. // The entire format here is just too volatile to allow liberal mixing. // An .ART set must be treated as one unit. - lumpnum = fileSystem.CheckNumForFullName(artpath, fileSystem.GetFileContainer(i)); + lumpnum = fileSystem.CheckNumForFullName(artpath, fileSystem.GetFileContainer(i)); if (lumpnum < 0) { break; } - BuildTileData.Reserve(1); - auto &artdata = BuildTileData.Last(); + auto& artdata = TexMan.GetNewBuildTileData(); artdata.Resize(fileSystem.FileLength(lumpnum)); fileSystem.ReadFile(lumpnum, &artdata[0]); diff --git a/src/gamedata/textures/formats/ddstexture.cpp b/src/gamedata/textures/formats/ddstexture.cpp index 6d86ffcb4..64b1b8604 100644 --- a/src/gamedata/textures/formats/ddstexture.cpp +++ b/src/gamedata/textures/formats/ddstexture.cpp @@ -48,11 +48,9 @@ ** the pixel data, it is fairly inefficient to process. */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "bitmap.h" -#include "v_video.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/emptytexture.cpp b/src/gamedata/textures/formats/emptytexture.cpp index 91f22f1a0..108c248e6 100644 --- a/src/gamedata/textures/formats/emptytexture.cpp +++ b/src/gamedata/textures/formats/emptytexture.cpp @@ -35,7 +35,6 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "textures/textures.h" diff --git a/src/gamedata/textures/formats/flattexture.cpp b/src/gamedata/textures/formats/flattexture.cpp index 98321bbd0..ca26d0548 100644 --- a/src/gamedata/textures/formats/flattexture.cpp +++ b/src/gamedata/textures/formats/flattexture.cpp @@ -33,7 +33,6 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "textures/textures.h" diff --git a/src/gamedata/textures/formats/fontchars.cpp b/src/gamedata/textures/formats/fontchars.cpp index 6d54f0412..107080e35 100644 --- a/src/gamedata/textures/formats/fontchars.cpp +++ b/src/gamedata/textures/formats/fontchars.cpp @@ -34,10 +34,7 @@ ** */ -#include "doomtype.h" #include "filesystem.h" -#include "v_palette.h" -#include "v_video.h" #include "bitmap.h" #include "image.h" #include "imagehelpers.h" diff --git a/src/gamedata/textures/formats/imgztexture.cpp b/src/gamedata/textures/formats/imgztexture.cpp index 428a8eaf6..f55fd3b7f 100644 --- a/src/gamedata/textures/formats/imgztexture.cpp +++ b/src/gamedata/textures/formats/imgztexture.cpp @@ -33,10 +33,8 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" -#include "v_video.h" #include "bitmap.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/jpegtexture.cpp b/src/gamedata/textures/formats/jpegtexture.cpp index 5ddcd9ef8..1d98ea85a 100644 --- a/src/gamedata/textures/formats/jpegtexture.cpp +++ b/src/gamedata/textures/formats/jpegtexture.cpp @@ -39,12 +39,10 @@ extern "C" #include } -#include "doomtype.h" #include "files.h" #include "filesystem.h" -#include "v_text.h" +#include "printf.h" #include "bitmap.h" -#include "v_video.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/md5check.cpp b/src/gamedata/textures/formats/md5check.cpp index eb0a188d0..96e14b2f3 100644 --- a/src/gamedata/textures/formats/md5check.cpp +++ b/src/gamedata/textures/formats/md5check.cpp @@ -37,7 +37,7 @@ #include #include "files.h" #include "md5.h" -#include "doomtype.h" +#include "printf.h" struct MD5Check { diff --git a/src/gamedata/textures/formats/multipatchtexture.cpp b/src/gamedata/textures/formats/multipatchtexture.cpp index e7c9a8336..d6f0d2abc 100644 --- a/src/gamedata/textures/formats/multipatchtexture.cpp +++ b/src/gamedata/textures/formats/multipatchtexture.cpp @@ -34,25 +34,11 @@ */ #include -#include "doomtype.h" #include "files.h" #include "filesystem.h" - -#include "gi.h" -#include "st_start.h" -#include "sc_man.h" -#include "templates.h" -#include "r_data/r_translate.h" -#include "bitmap.h" -#include "colormatcher.h" -#include "v_palette.h" -#include "v_video.h" -#include "v_text.h" -#include "cmdlib.h" -#include "imagehelpers.h" #include "image.h" #include "multipatchtexture.h" - +#include "imagehelpers.h" //========================================================================== // diff --git a/src/gamedata/textures/formats/multipatchtexture.h b/src/gamedata/textures/formats/multipatchtexture.h index 8994cf4ce..4aef0c14d 100644 --- a/src/gamedata/textures/formats/multipatchtexture.h +++ b/src/gamedata/textures/formats/multipatchtexture.h @@ -1,5 +1,7 @@ #pragma once #include "sc_man.h" +#include "palettecontainer.h" +#include "textures.h" //========================================================================== // diff --git a/src/gamedata/textures/formats/patchtexture.cpp b/src/gamedata/textures/formats/patchtexture.cpp index efc1766c9..e46bb82fd 100644 --- a/src/gamedata/textures/formats/patchtexture.cpp +++ b/src/gamedata/textures/formats/patchtexture.cpp @@ -33,11 +33,8 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" -#include "v_palette.h" -#include "v_video.h" #include "bitmap.h" #include "image.h" #include "imagehelpers.h" @@ -63,7 +60,7 @@ class FPatchTexture : public FImageSource bool badflag = false; bool isalpha = false; public: - FPatchTexture (int lumpnum, patch_t *header, bool isalphatex); + FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex); TArray CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; void DetectBadPatches(); @@ -127,16 +124,15 @@ static bool CheckIfPatch(FileReader & file, bool &isalpha) FImageSource *PatchImage_TryCreate(FileReader & file, int lumpnum) { - patch_t header; bool isalpha; if (!CheckIfPatch(file, isalpha)) return NULL; file.Seek(0, FileReader::SeekSet); - header.width = file.ReadUInt16(); - header.height = file.ReadUInt16(); - header.leftoffset = file.ReadInt16(); - header.topoffset = file.ReadInt16(); - return new FPatchTexture(lumpnum, &header, isalpha); + int width = file.ReadUInt16(); + int height = file.ReadUInt16(); + int leftoffset = file.ReadInt16(); + int topoffset = file.ReadInt16(); + return new FPatchTexture(lumpnum, width, height, leftoffset, topoffset, isalpha); } //========================================================================== @@ -145,15 +141,15 @@ FImageSource *PatchImage_TryCreate(FileReader & file, int lumpnum) // //========================================================================== -FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex) +FPatchTexture::FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex) : FImageSource(lumpnum) { bUseGamePalette = !isalphatex; isalpha = isalphatex; - Width = header->width; - Height = header->height; - LeftOffset = header->leftoffset; - TopOffset = header->topoffset; + Width = w; + Height = h; + LeftOffset = lo; + TopOffset = to; DetectBadPatches(); } diff --git a/src/gamedata/textures/formats/pcxtexture.cpp b/src/gamedata/textures/formats/pcxtexture.cpp index b2b571d21..b5ad0133b 100644 --- a/src/gamedata/textures/formats/pcxtexture.cpp +++ b/src/gamedata/textures/formats/pcxtexture.cpp @@ -34,11 +34,9 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "bitmap.h" -#include "v_video.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/pngtexture.cpp b/src/gamedata/textures/formats/pngtexture.cpp index 3253d8017..909a62ec8 100644 --- a/src/gamedata/textures/formats/pngtexture.cpp +++ b/src/gamedata/textures/formats/pngtexture.cpp @@ -33,7 +33,6 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "templates.h" diff --git a/src/gamedata/textures/formats/rawpagetexture.cpp b/src/gamedata/textures/formats/rawpagetexture.cpp index e278c3a99..be979e285 100644 --- a/src/gamedata/textures/formats/rawpagetexture.cpp +++ b/src/gamedata/textures/formats/rawpagetexture.cpp @@ -33,10 +33,8 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" -#include "gi.h" #include "bitmap.h" #include "textures/textures.h" #include "imagehelpers.h" @@ -159,7 +157,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum) // Special case hack for Heretic's E2 end pic. This is not going to be exposed as an editing feature because the implications would be horrible. FString Name; fileSystem.GetFileShortName(Name, lumpnum); - if (Name.CompareNoCase("E2END") == 0 && gameinfo.gametype == GAME_Heretic) + if (Name.CompareNoCase("E2END") == 0) { mPaletteLump = fileSystem.CheckNumForName("E2PAL"); if (fileSystem.FileLength(mPaletteLump) < 768) mPaletteLump = -1; diff --git a/src/gamedata/textures/formats/shadertexture.cpp b/src/gamedata/textures/formats/shadertexture.cpp index 5ce85cfc7..683500040 100644 --- a/src/gamedata/textures/formats/shadertexture.cpp +++ b/src/gamedata/textures/formats/shadertexture.cpp @@ -34,8 +34,6 @@ ** */ -#include "doomtype.h" -#include "d_player.h" #include "menu/menu.h" #include "filesystem.h" #include "bitmap.h" diff --git a/src/gamedata/textures/formats/stbtexture.cpp b/src/gamedata/textures/formats/stbtexture.cpp index 1a1c2090d..ab84458cf 100644 --- a/src/gamedata/textures/formats/stbtexture.cpp +++ b/src/gamedata/textures/formats/stbtexture.cpp @@ -45,10 +45,8 @@ #include "stb_image.h" -#include "doomtype.h" #include "files.h" #include "filesystem.h" -#include "v_video.h" #include "bitmap.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/formats/tgatexture.cpp b/src/gamedata/textures/formats/tgatexture.cpp index f23020f24..0cc0d210a 100644 --- a/src/gamedata/textures/formats/tgatexture.cpp +++ b/src/gamedata/textures/formats/tgatexture.cpp @@ -33,12 +33,10 @@ ** */ -#include "doomtype.h" #include "files.h" #include "filesystem.h" #include "templates.h" #include "bitmap.h" -#include "v_video.h" #include "imagehelpers.h" #include "image.h" diff --git a/src/gamedata/textures/image.cpp b/src/gamedata/textures/image.cpp index 8c26a410c..a27319322 100644 --- a/src/gamedata/textures/image.cpp +++ b/src/gamedata/textures/image.cpp @@ -323,7 +323,7 @@ typedef FImageSource * (*CreateFunc)(FileReader & file, int lumpnum); struct TexCreateInfo { CreateFunc TryCreate; - ETextureType usetype; + bool checkflat; }; FImageSource *IMGZImage_TryCreate(FileReader &, int lumpnum); @@ -342,21 +342,21 @@ FImageSource *AutomapImage_TryCreate(FileReader &, int lumpnum); // Examines the lump contents to decide what type of texture to create, // and creates the texture. -FImageSource * FImageSource::GetImage(int lumpnum, ETextureType usetype) +FImageSource * FImageSource::GetImage(int lumpnum, bool isflat) { static TexCreateInfo CreateInfo[] = { - { IMGZImage_TryCreate, ETextureType::Any }, - { PNGImage_TryCreate, ETextureType::Any }, - { JPEGImage_TryCreate, ETextureType::Any }, - { DDSImage_TryCreate, ETextureType::Any }, - { PCXImage_TryCreate, ETextureType::Any }, - { StbImage_TryCreate, ETextureType::Any }, - { TGAImage_TryCreate, ETextureType::Any }, - { RawPageImage_TryCreate, ETextureType::MiscPatch }, - { FlatImage_TryCreate, ETextureType::Flat }, - { PatchImage_TryCreate, ETextureType::Any }, - { EmptyImage_TryCreate, ETextureType::Any }, - { AutomapImage_TryCreate, ETextureType::MiscPatch }, + { IMGZImage_TryCreate, false }, + { PNGImage_TryCreate, false }, + { JPEGImage_TryCreate, false }, + { DDSImage_TryCreate, false }, + { PCXImage_TryCreate, false }, + { StbImage_TryCreate, false }, + { TGAImage_TryCreate, false }, + { RawPageImage_TryCreate, false }, + { FlatImage_TryCreate, true }, // flat detection is not reliable, so only consider this for real flats. + { PatchImage_TryCreate, false }, + { EmptyImage_TryCreate, false }, + { AutomapImage_TryCreate, false }, }; if (lumpnum == -1) return nullptr; @@ -377,7 +377,7 @@ FImageSource * FImageSource::GetImage(int lumpnum, ETextureType usetype) for (size_t i = 0; i < countof(CreateInfo); i++) { - if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == ETextureType::Any)) + if (!CreateInfo[i].checkflat || isflat) { auto image = CreateInfo[i].TryCreate(data, lumpnum); if (image != nullptr) diff --git a/src/gamedata/textures/image.h b/src/gamedata/textures/image.h index 64d9d22c6..afaa96205 100644 --- a/src/gamedata/textures/image.h +++ b/src/gamedata/textures/image.h @@ -2,13 +2,22 @@ #include #include "tarray.h" -#include "textures.h" #include "textures/bitmap.h" #include "memarena.h" class FImageSource; using PrecacheInfo = TMap>; +// Doom patch format header +struct patch_t +{ + int16_t width; // bounding box size + int16_t height; + int16_t leftoffset; // pixels to the left of origin + int16_t topoffset; // pixels below the origin + uint32_t columnofs[1]; // only [width] used +}; + struct PalettedPixels { friend class FImageSource; @@ -80,7 +89,7 @@ public: FBitmap GetCachedBitmap(PalEntry *remap, int conversion, int *trans = nullptr); static void ClearImages() { ImageArena.FreeAll(); ImageForLump.Clear(); NextID = 0; } - static FImageSource * GetImage(int lumpnum, ETextureType usetype); + static FImageSource * GetImage(int lumpnum, bool checkflat); @@ -137,26 +146,6 @@ public: static void RegisterForPrecache(FImageSource *img); }; -//========================================================================== -// -// a TGA texture -// -//========================================================================== - -class FImageTexture : public FTexture -{ - FImageSource *mImage; -public: - FImageTexture (FImageSource *image, const char *name = nullptr); - virtual TArray Get8BitPixels(bool alphatex); - - void SetImage(FImageSource *img) // This is only for the multipatch texture builder! - { - mImage = img; - } - - FImageSource *GetImage() const override { return mImage; } - FBitmap GetBgraBitmap(PalEntry *p, int *trans) override; - -}; +class FTexture; +FTexture* CreateImageTexture(FImageSource* img) noexcept; diff --git a/src/gamedata/textures/imagetexture.cpp b/src/gamedata/textures/imagetexture.cpp index 91711f3c3..1405ac4f7 100644 --- a/src/gamedata/textures/imagetexture.cpp +++ b/src/gamedata/textures/imagetexture.cpp @@ -40,6 +40,7 @@ #include "bitmap.h" #include "v_video.h" #include "image.h" +#include "textures.h" //========================================================================== @@ -48,7 +49,7 @@ // //========================================================================== -FImageTexture::FImageTexture(FImageSource *img, const char *name) +FImageTexture::FImageTexture(FImageSource *img, const char *name) noexcept : FTexture(name, img? img->LumpNum() : 0) { mImage = img; @@ -89,24 +90,9 @@ TArray FImageTexture::Get8BitPixels(bool alpha) return mImage->GetPalettedPixels(alpha? alpha : bNoRemap0 ? FImageSource::noremap0 : FImageSource::normal); } -//========================================================================== -// -// FMultiPatchTexture :: GetRawTexture -// -// Doom ignored all compositing of mid-sided textures on two-sided lines. -// Since these textures had to be single-patch in Doom, that essentially -// means it ignores their Y offsets. -// -// If this texture is composed of only one patch, return that patch. -// Otherwise, return this texture, since Doom wouldn't have been able to -// draw it anyway. -// -//========================================================================== -/* todo: this needs to be reimplemented without assuming that the underlying patch will be usable as-is. -FTexture *FMultiPatchTexture::GetRawTexture() +FTexture* CreateImageTexture(FImageSource* img) noexcept { - return NumParts == 1 && UseType == ETextureType::Wall && bMultiPatch == 1 && Scale == Parts->Texture->Scale ? Parts->Texture : this; + return new FImageTexture(img); } -*/ diff --git a/src/gamedata/textures/texture.cpp b/src/gamedata/textures/texture.cpp index 567ab1630..95bd356f7 100644 --- a/src/gamedata/textures/texture.cpp +++ b/src/gamedata/textures/texture.cpp @@ -94,7 +94,7 @@ FTexture * FTexture::CreateTexture(const char *name, int lumpnum, ETextureType u { if (lumpnum == -1) return nullptr; - auto image = FImageSource::GetImage(lumpnum, usetype); + auto image = FImageSource::GetImage(lumpnum, usetype == ETextureType::Flat); if (image != nullptr) { FTexture *tex = new FImageTexture(image); @@ -415,7 +415,7 @@ void FTexture::CreateDefaultBrightmap() if (!bBrightmapChecked) { // Check for brightmaps - if (GetImage() && GetImage()->UseGamePalette() && TexMan.HasGlobalBrightmap && + if (GetImage() && GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar && Brightmap == NULL && bWarped == 0) { @@ -426,7 +426,7 @@ void FTexture::CreateDefaultBrightmap() int size = GetTexelWidth() * GetTexelHeight(); for (int i = 0; i> 1) + (foo & 1); } + int GetDisplayHeight() { int foo = int((Height * 2) / Scale.Y); return (foo >> 1) + (foo & 1); } + double GetDisplayWidthDouble() { return Width / Scale.X; } + double GetDisplayHeightDouble() { return Height / Scale.Y; } int GetDisplayLeftOffset() { return GetScaledLeftOffset(0); } int GetDisplayTopOffset() { return GetScaledTopOffset(0); } double GetDisplayLeftOffsetDouble() { return GetScaledLeftOffsetDouble(0); } @@ -641,17 +627,24 @@ private: void AdjustSpriteOffsets(); // Build tiles - void AddTiles (const FString &pathprefix, const void *, int translation); //int CountBuildTiles (); - void InitBuildTiles (); // Animation stuff FAnimDef *AddAnim (FAnimDef *anim); void FixAnimations (); void InitAnimated (); void InitAnimDefs (); +public: FAnimDef *AddSimpleAnim (FTextureID picnum, int animcount, uint32_t speedmin, uint32_t speedrange=0); FAnimDef *AddComplexAnim (FTextureID picnum, const TArray &frames); + + TArray& GetNewBuildTileData() + { + BuildTileData.Reserve(1); + return BuildTileData.Last(); + } + +private: void ParseAnim (FScanner &sc, ETextureType usetype); FAnimDef *ParseRangeAnim (FScanner &sc, FTextureID picnum, ETextureType usetype, bool missing); void ParsePicAnim (FScanner &sc, FTextureID picnum, ETextureType usetype, bool missing, TArray &frames); @@ -664,8 +657,7 @@ private: void ParseAnimatedDoor(FScanner &sc); void InitPalettedVersions(); - void GenerateGlobalBrightmapFromColormap(); - + // Switches void InitSwitchList (); @@ -695,8 +687,6 @@ private: public: TArray mAnimations; - bool HasGlobalBrightmap; - FRemapTable GlobalBrightmap; short sintable[2048]; // for texture warping enum { @@ -761,6 +751,24 @@ public: } }; +class FImageTexture : public FTexture +{ + FImageSource* mImage; +public: + FImageTexture(FImageSource* image, const char* name = nullptr) noexcept; + virtual TArray Get8BitPixels(bool alphatex); + + void SetImage(FImageSource* img) // This is only for the multipatch texture builder! + { + mImage = img; + } + + FImageSource* GetImage() const override { return mImage; } + FBitmap GetBgraBitmap(PalEntry* p, int* trans) override; + +}; + + extern FTextureManager TexMan; struct FTexCoordInfo diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index c2f24a2ba..9c1d384e2 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -158,6 +158,18 @@ void InitPalette () GPalette.Init(NUM_TRANSLATION_TABLES); GPalette.SetPalette (pal, 0); + + int lump = fileSystem.CheckNumForName("COLORMAP"); + if (lump == -1) lump = fileSystem.CheckNumForName("COLORMAP", ns_colormaps); + if (lump != -1) + { + FileData cmap = fileSystem.ReadFile(lump); + uint8_t palbuffer[768]; + ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer); + const unsigned char* cmapdata = (const unsigned char*)cmap.GetMem(); + GPalette.GenerateGlobalBrightmapFromColormap(cmapdata, 32); + } + MakeGoodRemap ((uint32_t*)GPalette.BaseColors, GPalette.Remap); ColorMatcher.SetPalette ((uint32_t *)GPalette.BaseColors);