From b37d0ba2ead105bbe59166e774ef192eef3c1b61 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Apr 2009 11:10:38 +0000 Subject: [PATCH] - Fixed: Completely empty patches (8 0-bytes) could not be handled by the texture manager. They now get assigned a new FEmptyTexture object that is just a 1x1 pixel transparent texture. - Fixed: Multiple namespace markers of the same type were no longer detected. - Fixed sprite renaming. SVN r1566 (trunk) --- docs/rh-log.txt | 9 ++- src/resourcefiles/file_wad.cpp | 123 ++++++++++++++++++++------------ src/textures/emptytexture.cpp | 125 +++++++++++++++++++++++++++++++++ src/textures/texture.cpp | 2 + src/w_wad.cpp | 95 +++++++++++++------------ src/w_wad.h | 2 +- zdoom.vcproj | 4 ++ 7 files changed, 267 insertions(+), 93 deletions(-) create mode 100644 src/textures/emptytexture.cpp diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 060185b4f..0c25d0202 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,11 @@ -April 29, 2009 +April 30, 2009 (Changes by Graf Zahl) +- Fixed: Completely empty patches (8 0-bytes) could not be handled by the + texture manager. They now get assigned a new FEmptyTexture object + that is just a 1x1 pixel transparent texture. +- Fixed: Multiple namespace markers of the same type were no longer detected. +- Fixed sprite renaming. + +April 29, 2009 - Maps defined with Hexen-style MAPINFOs now run their scripts in the proper order. - Fixed: FWadCollection::CheckNumForName() read the lump each iteration before diff --git a/src/resourcefiles/file_wad.cpp b/src/resourcefiles/file_wad.cpp index 418a080c7..412f2c863 100644 --- a/src/resourcefiles/file_wad.cpp +++ b/src/resourcefiles/file_wad.cpp @@ -147,78 +147,109 @@ inline bool FWadFile::IsMarker(int lump, const char *marker) void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, namespace_t space, bool flathack) { - int start=-1, end=-1; bool warned = false; + int numstartmarkers = 0, numendmarkers = 0; int i; + struct Marker + { + int markertype; + int index; + }; + TArray markers; for(i = 0; i < (int)NumLumps; i++) { if (IsMarker(i, startmarker)) { - start = i; - break; + Marker m = {0, i }; + markers.Push(m); + numstartmarkers++; } - } - if (!flathack && start == -1) return; - - for(i = NumLumps-1; i > start; i--) - { - if (IsMarker(i, endmarker)) + else if (IsMarker(i, endmarker)) { - end = i; - break; + Marker m = {1, i }; + markers.Push(m); + numendmarkers++; } } - if (end == -1) - { - if (start != -1) - { - Printf(TEXTCOLOR_YELLOW"WARNING: %s marker without corresponding %s found.\n", startmarker, endmarker); - } - return; - } - if (start != -1) - { - for(int i = start+1; i < end; i++) - { - if (Lumps[i].Namespace != ns_global) - { - if (!warned) - { - Printf(TEXTCOLOR_YELLOW"WARNING: Overlapping namespaces found.\n"); - } - warned = true; - } - else if (IsMarker(i, startmarker)) - { - Printf(TEXTCOLOR_YELLOW"WARNING: Multiple %s markers found.\n", startmarker); - } - else if (IsMarker(i, endmarker)) - { - Printf(TEXTCOLOR_YELLOW"WARNING: Multiple %s markers found.\n", endmarker); - } - else - { - Lumps[i].Namespace = space; - } - } - } - else + if (numstartmarkers == 0) { + if (numendmarkers == 0) return; // no markers found + Printf(TEXTCOLOR_YELLOW"WARNING: %s marker without corresponding %s found.\n", endmarker, startmarker); + + if (flathack) { + // We have found no F_START but one or more F_END markers. + // mark all lumps before the last F_END marker as potential flats. + int end = markers[markers.Size()-1].index; for(int i = 0; i < end; i++) { if (Lumps[i].LumpSize == 4096) { // We can't add this to the flats namespace but // it needs to be flagged for the texture manager. + DPrintf("Marking %s as potential flat\n", Lumps[i].Name); Lumps[i].Flags |= LUMPF_MAYBEFLAT; } } } + return; + } + + i = 0; + while (i < markers.Size()) + { + int start, end; + if (markers[i].markertype != 0) + { + Printf(TEXTCOLOR_YELLOW"WARNING: %s marker without corresponding %s found.\n", endmarker, startmarker); + i++; + continue; + } + start = i++; + + // skip over subsequent x_START markers + while (i < markers.Size() && markers[i].markertype == 0) + { + Printf(TEXTCOLOR_YELLOW"WARNING: duplicate %s marker found.\n", startmarker); + i++; + continue; + } + // same for x_START markers + while (i < markers.Size()-1 && (markers[i].markertype == 1 && markers[i+1].markertype == 1)) + { + Printf(TEXTCOLOR_YELLOW"WARNING: duplicate %s marker found.\n", endmarker); + i++; + continue; + } + // We found a starting marker but no end marker. Ignore this block. + if (i >= markers.Size()) + { + Printf(TEXTCOLOR_YELLOW"WARNING: %s marker without corresponding %s found.\n", startmarker, endmarker); + return; + } + end = i++; + + // we found a marked block + DPrintf("Found %s block at (%d-%d)\n", startmarker, markers[start].index, markers[end].index); + for(int j = markers[start].index+1; j < markers[end].index; j++) + { + if (Lumps[j].Namespace != ns_global) + { + if (!warned) + { + Printf(TEXTCOLOR_YELLOW"WARNING: Overlapping namespaces found (lump %d.)\n", j); + } + warned = true; + } + else + { + Lumps[j].Namespace = space; + } + } } } diff --git a/src/textures/emptytexture.cpp b/src/textures/emptytexture.cpp new file mode 100644 index 000000000..205c6940d --- /dev/null +++ b/src/textures/emptytexture.cpp @@ -0,0 +1,125 @@ +/* +** flattexture.cpp +** Texture class for empty placeholder textures +** (essentially patches with dimensions and offsets of (0,0) ) +** +**--------------------------------------------------------------------------- +** Copyright 2009 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "doomtype.h" +#include "files.h" +#include "r_data.h" +#include "w_wad.h" + +//========================================================================== +// +// A texture defined between F_START and F_END markers +// +//========================================================================== + +class FEmptyTexture : public FTexture +{ +public: + FEmptyTexture (int lumpnum); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload() {} + +protected: + BYTE Pixels[1]; + Span DummySpans[1]; +}; + + + +//========================================================================== +// +// Since there is no way to detect the validity of a flat +// they can't be used anywhere else but between F_START and F_END +// +//========================================================================== + +FTexture *EmptyTexture_TryCreate(FileReader & file, int lumpnum) +{ + char check[8]; + if (file.GetLength() != 8) return false; + file.Seek(0, SEEK_SET); + if (file.Read(check, 8) != 8) return false; + if (memcmp(check, "\0\0\0\0\0\0\0\0", 8)) return false; + + return new FEmptyTexture(lumpnum); +} + +//========================================================================== +// +// +// +//========================================================================== + +FEmptyTexture::FEmptyTexture (int lumpnum) +: FTexture(NULL, lumpnum) +{ + bMasked = true; + WidthBits = HeightBits = 1; + Width = Height = 1; + WidthMask = 0; + DummySpans[0].TopOffset = 0; + DummySpans[0].Length = 0; + Pixels[0] = 0; +} + +//========================================================================== +// +// +// +//========================================================================== + +const BYTE *FEmptyTexture::GetColumn (unsigned int column, const Span **spans_out) +{ + if (spans_out != NULL) + { + *spans_out = DummySpans; + } + return Pixels; +} + +//========================================================================== +// +// +// +//========================================================================== + +const BYTE *FEmptyTexture::GetPixels () +{ + return Pixels; +} + diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index a899b4f64..026b2a863 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -71,6 +71,7 @@ FTexture *TGATexture_TryCreate(FileReader &, int lumpnum); FTexture *RawPageTexture_TryCreate(FileReader &, int lumpnum); FTexture *FlatTexture_TryCreate(FileReader &, int lumpnum); FTexture *PatchTexture_TryCreate(FileReader &, int lumpnum); +FTexture *EmptyTexture_TryCreate(FileReader &, int lumpnum); FTexture *AutomapTexture_TryCreate(FileReader &, int lumpnum); @@ -88,6 +89,7 @@ FTexture * FTexture::CreateTexture (int lumpnum, int usetype) { RawPageTexture_TryCreate, TEX_MiscPatch }, { FlatTexture_TryCreate, TEX_Flat }, { PatchTexture_TryCreate, TEX_Any }, + { EmptyTexture_TryCreate, TEX_Any }, { AutomapTexture_TryCreate, TEX_MiscPatch }, }; diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 73d45e9b7..6c4dfbd0c 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -189,6 +189,7 @@ void FWadCollection::InitMultipleFiles (wadlist_t **filenames) { I_FatalError ("W_InitMultipleFiles: no files found"); } + RenameSprites(); // [RH] Set up hash table FirstLumpIndex = new DWORD[NumLumps]; @@ -196,6 +197,8 @@ void FWadCollection::InitMultipleFiles (wadlist_t **filenames) FirstLumpIndex_FullName = new DWORD[NumLumps]; NextLumpIndex_FullName = new DWORD[NumLumps]; InitHashChains (); + LumpInfo.ShrinkToFit(); + Files.ShrinkToFit(); } //----------------------------------------------------------------------- @@ -667,7 +670,7 @@ void FWadCollection::InitHashChains (void) // //========================================================================== -void FWadCollection::RenameSprites (int startlump) +void FWadCollection::RenameSprites () { bool renameAll; bool MNTRZfound = false; @@ -739,64 +742,66 @@ void FWadCollection::RenameSprites (int startlump) break; } - renameAll = !!Args->CheckParm ("-oldsprites"); - for (DWORD i = startlump + 1; - i < NumLumps && - *(DWORD *)LumpInfo[i].lump->Name != MAKE_ID('S','_','E','N') && - *(((DWORD *)LumpInfo[i].lump->Name) + 1) != MAKE_ID('D',0,0,0); - ++i) + for (DWORD i=0; i< LumpInfo.Size(); i++) { - if (!strncmp(LumpInfo[i].lump->Name, "MNTRZ", 5)) + // check for full Minotaur animations. If this is not found + // some frames need to be renamed. + if (LumpInfo[i].lump->Namespace == ns_sprites) { - MNTRZfound = true; - break; + if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('M', 'N', 'T', 'R') && LumpInfo[i].lump->Name[4] == 'Z' ) + { + MNTRZfound = true; + break; + } } } - for (DWORD i = startlump + 1; - i < NumLumps && - *(DWORD *)LumpInfo[i].lump->Name != MAKE_ID('S','_','E','N') && - *(((DWORD *)LumpInfo[i].lump->Name) + 1) != MAKE_ID('D',0,0,0); - ++i) + renameAll = !!Args->CheckParm ("-oldsprites"); + + for (DWORD i = 0; i < LumpInfo.Size(); i++) { - // Only sprites in the IWAD normally get renamed - if (renameAll || LumpInfo[i].wadnum == IWAD_FILENUM) + if (LumpInfo[i].lump->Namespace == ns_sprites) { - for (int j = 0; j < numrenames; ++j) + // Only sprites in the IWAD normally get renamed + if (renameAll || LumpInfo[i].wadnum == IWAD_FILENUM) { - if (*(DWORD *)LumpInfo[i].lump->Name == renames[j*2]) + for (int j = 0; j < numrenames; ++j) { - *(DWORD *)LumpInfo[i].lump->Name = renames[j*2+1]; + if (*(DWORD *)LumpInfo[i].lump->Name == renames[j*2]) + { + *(DWORD *)LumpInfo[i].lump->Name = renames[j*2+1]; + } + } + if (gameinfo.gametype == GAME_Hexen) + { + if (CheckLumpName (i, "ARTIINVU")) + { + LumpInfo[i].lump->Name[4]='D'; LumpInfo[i].lump->Name[5]='E'; + LumpInfo[i].lump->Name[6]='F'; LumpInfo[i].lump->Name[7]='N'; + } } } - if (gameinfo.gametype == GAME_Hexen) - { - if (CheckLumpName (i, "ARTIINVU")) - { - LumpInfo[i].lump->Name[4]='D'; LumpInfo[i].lump->Name[5]='E'; - LumpInfo[i].lump->Name[6]='F'; LumpInfo[i].lump->Name[7]='N'; - } - } - } - if (!MNTRZfound) //gameinfo.gametype == GAME_Hexen && LumpInfo[i].wadnum == IWAD_FILENUM) - { - if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('M', 'N', 'T', 'R')) - { - if (LumpInfo[i].lump->Name[4] >= 'F' && LumpInfo[i].lump->Name[4] <= 'K') - { - LumpInfo[i].lump->Name[4] += 'U' - 'F'; - } - } - } - // When not playing Doom rename all BLOD sprites to BLUD so that - // the same blood states can be used everywhere - if (!(gameinfo.gametype & GAME_DoomChex)) - { - if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('B', 'L', 'O', 'D')) + if (!MNTRZfound) { - *(DWORD *)LumpInfo[i].lump->Name = MAKE_ID('B', 'L', 'U', 'D'); + if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('M', 'N', 'T', 'R')) + { + if (LumpInfo[i].lump->Name[4] >= 'F' && LumpInfo[i].lump->Name[4] <= 'K') + { + LumpInfo[i].lump->Name[4] += 'U' - 'F'; + } + } + } + + // When not playing Doom rename all BLOD sprites to BLUD so that + // the same blood states can be used everywhere + if (!(gameinfo.gametype & GAME_DoomChex)) + { + if (*(DWORD *)LumpInfo[i].lump->Name == MAKE_ID('B', 'L', 'O', 'D')) + { + *(DWORD *)LumpInfo[i].lump->Name = MAKE_ID('B', 'L', 'U', 'D'); + } } } } diff --git a/src/w_wad.h b/src/w_wad.h index 10e01ace7..293a328f5 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -232,7 +232,7 @@ protected: void InitHashChains (); // [RH] Set up the lumpinfo hashing private: - void RenameSprites (int startlump); + void RenameSprites (); void DeleteAll(); }; diff --git a/zdoom.vcproj b/zdoom.vcproj index 1e86e8e24..e5c60ec35 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -5213,6 +5213,10 @@ RelativePath=".\src\textures\ddstexture.cpp" > + +