diff --git a/Build/Configurations/Boom.cfg b/Build/Configurations/Boom.cfg index 83f8d54f..92731936 100644 --- a/Build/Configurations/Boom.cfg +++ b/Build/Configurations/Boom.cfg @@ -92,6 +92,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Doom.cfg b/Build/Configurations/Doom.cfg index a0e3ede0..7f40639b 100644 --- a/Build/Configurations/Doom.cfg +++ b/Build/Configurations/Doom.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Doom2.cfg b/Build/Configurations/Doom2.cfg index 22496cb1..71a8e9bc 100644 --- a/Build/Configurations/Doom2.cfg +++ b/Build/Configurations/Doom2.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Edge.cfg b/Build/Configurations/Edge.cfg index 5d6c91fe..a114b988 100644 --- a/Build/Configurations/Edge.cfg +++ b/Build/Configurations/Edge.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Eternity_Doom.cfg b/Build/Configurations/Eternity_Doom.cfg index 06e3436c..436fa3b0 100644 --- a/Build/Configurations/Eternity_Doom.cfg +++ b/Build/Configurations/Eternity_Doom.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Eternity_DoomUDMF.cfg b/Build/Configurations/Eternity_DoomUDMF.cfg index 3bf3d28c..e7e224ab 100644 --- a/Build/Configurations/Eternity_DoomUDMF.cfg +++ b/Build/Configurations/Eternity_DoomUDMF.cfg @@ -92,6 +92,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Heretic.cfg b/Build/Configurations/Heretic.cfg index a93d7ab2..e64129bb 100644 --- a/Build/Configurations/Heretic.cfg +++ b/Build/Configurations/Heretic.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Hexen.cfg b/Build/Configurations/Hexen.cfg index 815749c5..691a6350 100644 --- a/Build/Configurations/Hexen.cfg +++ b/Build/Configurations/Hexen.cfg @@ -97,6 +97,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Legacy.cfg b/Build/Configurations/Legacy.cfg index 8fe542f7..e8e9e36a 100644 --- a/Build/Configurations/Legacy.cfg +++ b/Build/Configurations/Legacy.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Risen3D.cfg b/Build/Configurations/Risen3D.cfg index b8f44ec9..0fa191b7 100644 --- a/Build/Configurations/Risen3D.cfg +++ b/Build/Configurations/Risen3D.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Skulltag_Doom.cfg b/Build/Configurations/Skulltag_Doom.cfg index df572bd5..450266b7 100644 --- a/Build/Configurations/Skulltag_Doom.cfg +++ b/Build/Configurations/Skulltag_Doom.cfg @@ -95,6 +95,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Skulltag_DoomHexen.cfg b/Build/Configurations/Skulltag_DoomHexen.cfg index a8082e39..ba37554b 100644 --- a/Build/Configurations/Skulltag_DoomHexen.cfg +++ b/Build/Configurations/Skulltag_DoomHexen.cfg @@ -105,6 +105,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/Strife.cfg b/Build/Configurations/Strife.cfg index 49b56606..daad7425 100644 --- a/Build/Configurations/Strife.cfg +++ b/Build/Configurations/Strife.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/UltDoom.cfg b/Build/Configurations/UltDoom.cfg index 8de9f69c..a2134507 100644 --- a/Build/Configurations/UltDoom.cfg +++ b/Build/Configurations/UltDoom.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/ZDoom_Doom.cfg b/Build/Configurations/ZDoom_Doom.cfg index 0ba31722..0ba2c5f8 100644 --- a/Build/Configurations/ZDoom_Doom.cfg +++ b/Build/Configurations/ZDoom_Doom.cfg @@ -95,6 +95,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/ZDoom_DoomHexen.cfg b/Build/Configurations/ZDoom_DoomHexen.cfg index 280500f8..57e94069 100644 --- a/Build/Configurations/ZDoom_DoomHexen.cfg +++ b/Build/Configurations/ZDoom_DoomHexen.cfg @@ -106,6 +106,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/ZDoom_DoomUDMF.cfg b/Build/Configurations/ZDoom_DoomUDMF.cfg index e47e274d..c658cb37 100644 --- a/Build/Configurations/ZDoom_DoomUDMF.cfg +++ b/Build/Configurations/ZDoom_DoomUDMF.cfg @@ -116,6 +116,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/ZDoom_HereticHexen.cfg b/Build/Configurations/ZDoom_HereticHexen.cfg index 30430a73..66061560 100644 --- a/Build/Configurations/ZDoom_HereticHexen.cfg +++ b/Build/Configurations/ZDoom_HereticHexen.cfg @@ -105,6 +105,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/ZDoom_Hexen.cfg b/Build/Configurations/ZDoom_Hexen.cfg index 27c08c5d..d0457fef 100644 --- a/Build/Configurations/ZDoom_Hexen.cfg +++ b/Build/Configurations/ZDoom_Hexen.cfg @@ -105,6 +105,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/ZDoom_StrifeHexen.cfg b/Build/Configurations/ZDoom_StrifeHexen.cfg index e72cdd6d..88922e06 100644 --- a/Build/Configurations/ZDoom_StrifeHexen.cfg +++ b/Build/Configurations/ZDoom_StrifeHexen.cfg @@ -105,6 +105,32 @@ textures } } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Build/Configurations/jDoom.cfg b/Build/Configurations/jDoom.cfg index cc89c3e2..0aab56a9 100644 --- a/Build/Configurations/jDoom.cfg +++ b/Build/Configurations/jDoom.cfg @@ -87,6 +87,32 @@ textures { } +// Patch sources +patches +{ + standard1 + { + start = "P_START"; + end = "P_END"; + } + + standard2 + { + start = "PP_START"; + end = "PP_END"; + } +} + +// Sprite sources +sprites +{ + standard1 + { + start = "S_START"; + end = "S_END"; + } +} + // Flat sources flats { diff --git a/Source/Config/GameConfiguration.cs b/Source/Config/GameConfiguration.cs index 2f2d73f0..261aad74 100644 --- a/Source/Config/GameConfiguration.cs +++ b/Source/Config/GameConfiguration.cs @@ -80,6 +80,8 @@ namespace CodeImp.DoomBuilder.Config // Texture/flat sources private IDictionary textureranges; private IDictionary flatranges; + private IDictionary patchranges; + private IDictionary spriteranges; // Things private List defaultthingflags; @@ -156,6 +158,8 @@ namespace CodeImp.DoomBuilder.Config // Texture/flat sources public IDictionary TextureRanges { get { return textureranges; } } public IDictionary FlatRanges { get { return flatranges; } } + public IDictionary PatchRanges { get { return patchranges; } } + public IDictionary SpriteRanges { get { return spriteranges; } } // Things public ICollection DefaultThingFlags { get { return defaultthingflags; } } @@ -264,6 +268,8 @@ namespace CodeImp.DoomBuilder.Config // Get texture and flat sources textureranges = cfg.ReadSetting("textures", new Hashtable()); flatranges = cfg.ReadSetting("flats", new Hashtable()); + patchranges = cfg.ReadSetting("patches", new Hashtable()); + spriteranges = cfg.ReadSetting("sprites", new Hashtable()); // Map lumps LoadMapLumps(); diff --git a/Source/Data/DataManager.cs b/Source/Data/DataManager.cs index 8af4059b..73785b1f 100644 --- a/Source/Data/DataManager.cs +++ b/Source/Data/DataManager.cs @@ -683,6 +683,23 @@ namespace CodeImp.DoomBuilder.Data // No such patch found return null; } + + // This returns a specific texture stream + internal Stream GetTextureData(string pname) + { + Stream patch; + + // Go for all opened containers + for(int i = containers.Count - 1; i >= 0; i--) + { + // This contain provides this patch? + patch = containers[i].GetTextureData(pname); + if(patch != null) return patch; + } + + // No such patch found + return null; + } // This returns an image by string public ImageData GetTextureImage(string name) diff --git a/Source/Data/DataReader.cs b/Source/Data/DataReader.cs index 840a1f00..5bcad366 100644 --- a/Source/Data/DataReader.cs +++ b/Source/Data/DataReader.cs @@ -102,6 +102,9 @@ namespace CodeImp.DoomBuilder.Data // When implemented, this returns the patch lump public virtual Stream GetPatchData(string pname) { return null; } + // When implemented, this returns the texture lump + public virtual Stream GetTextureData(string pname) { return null; } + // When implemented, this loads the textures public virtual ICollection LoadTextures(PatchNames pnames) { return null; } diff --git a/Source/Data/FlatImage.cs b/Source/Data/FlatImage.cs index 839ae6d8..ad0917cd 100644 --- a/Source/Data/FlatImage.cs +++ b/Source/Data/FlatImage.cs @@ -62,7 +62,7 @@ namespace CodeImp.DoomBuilder.Data lock(this) { // Get the lump data stream - lumpdata = General.Map.Data.GetPatchData(Name); + lumpdata = General.Map.Data.GetFlatData(Name); if(lumpdata != null) { // Copy lump data to memory diff --git a/Source/Data/PK3StructuredReader.cs b/Source/Data/PK3StructuredReader.cs index 68182e0d..72a8fb74 100644 --- a/Source/Data/PK3StructuredReader.cs +++ b/Source/Data/PK3StructuredReader.cs @@ -255,6 +255,31 @@ namespace CodeImp.DoomBuilder.Data return null; } + // This finds and returns a textue stream + public override Stream GetTextureData(string pname) + { + // Error when suspended + if(issuspended) throw new Exception("Data reader is suspended"); + + // Find in any of the wad files + // Note the backward order, because the last wad's images have priority + for(int i = wads.Count - 1; i >= 0; i--) + { + Stream data = wads[i].GetTextureData(pname); + if(data != null) return data; + } + + // Find in patches directory + string filename = FindFirstFile(TEXTURES_DIR, pname, true); + if((filename != null) && FileExists(filename)) + { + return LoadFile(filename); + } + + // Nothing found + return null; + } + #endregion #region ================== Flats diff --git a/Source/Data/SimpleTextureImage.cs b/Source/Data/SimpleTextureImage.cs index 5678a31b..28a68730 100644 --- a/Source/Data/SimpleTextureImage.cs +++ b/Source/Data/SimpleTextureImage.cs @@ -81,7 +81,7 @@ namespace CodeImp.DoomBuilder.Data { // Get the patch data stream if(bitmap != null) bitmap.Dispose(); bitmap = null; - patchdata = General.Map.Data.GetPatchData(lumpname); + patchdata = General.Map.Data.GetTextureData(lumpname); if(patchdata != null) { // Copy patch data to memory diff --git a/Source/Data/WADReader.cs b/Source/Data/WADReader.cs index fc8478ea..17f77a21 100644 --- a/Source/Data/WADReader.cs +++ b/Source/Data/WADReader.cs @@ -36,11 +36,27 @@ namespace CodeImp.DoomBuilder.Data #endregion + #region ================== Structures + + private struct LumpRange + { + public int start; + public int end; + } + + #endregion + #region ================== Variables // Source private WAD file; private bool is_iwad; + + // Lump ranges + private List flatranges; + private List patchranges; + private List spriteranges; + private List textureranges; #endregion @@ -60,6 +76,16 @@ namespace CodeImp.DoomBuilder.Data // Initialize file = new WAD(location.location, true); is_iwad = (file.Type == WAD.TYPE_IWAD); + patchranges = new List(); + spriteranges = new List(); + flatranges = new List(); + textureranges = new List(); + + // Find ranges + FindRanges(patchranges, General.Map.Config.PatchRanges, "patches"); + FindRanges(spriteranges, General.Map.Config.SpriteRanges, "sprites"); + FindRanges(flatranges, General.Map.Config.FlatRanges, "flats"); + FindRanges(textureranges, General.Map.Config.TextureRanges, "textures"); // We have no destructor GC.SuppressFinalize(this); @@ -99,6 +125,37 @@ namespace CodeImp.DoomBuilder.Data is_iwad = (file.Type == WAD.TYPE_IWAD); base.Resume(); } + + // This fills a ranges list + private void FindRanges(List ranges, IDictionary rangeinfos, string rangename) + { + foreach(DictionaryEntry r in rangeinfos) + { + // Read start and end + string rangestart = General.Map.Config.ReadSetting(rangename + "." + r.Key + ".start", ""); + string rangeend = General.Map.Config.ReadSetting(rangename + "." + r.Key + ".end", ""); + if((rangestart.Length > 0) && (rangeend.Length > 0)) + { + // Find ranges + int startindex = file.FindLumpIndex(rangestart); + while(startindex > -1) + { + LumpRange range = new LumpRange(); + range.start = startindex; + range.end = file.FindLumpIndex(rangeend, startindex); + if(range.end > -1) + { + ranges.Add(range); + startindex = file.FindLumpIndex(rangestart, range.end); + } + else + { + startindex = -1; + } + } + } + } + } #endregion @@ -147,16 +204,10 @@ namespace CodeImp.DoomBuilder.Data if(lump != null) LoadTextureSet(lump.Stream, ref images, pnames); // Read ranges from configuration - foreach(DictionaryEntry r in General.Map.Config.TextureRanges) + foreach(LumpRange range in textureranges) { - // Read start and end - rangestart = General.Map.Config.ReadSetting("textures." + r.Key + ".start", ""); - rangeend = General.Map.Config.ReadSetting("textures." + r.Key + ".end", ""); - if((rangestart.Length > 0) && (rangeend.Length > 0)) - { - // Load texture range - LoadTexturesRange(rangestart, rangeend, ref images, pnames); - } + // Load texture range + LoadTexturesRange(range.start, range.end, ref images, pnames); } // Return result @@ -164,39 +215,23 @@ namespace CodeImp.DoomBuilder.Data } // This loads a range of textures - private void LoadTexturesRange(string startlump, string endlump, ref List images, PatchNames pnames) + private void LoadTexturesRange(int startindex, int endindex, ref List images, PatchNames pnames) { - int startindex, endindex; - float defaultscale; - SimpleTextureImage image; - // Determine default scale - defaultscale = General.Map.Config.DefaultTextureScale; + float defaultscale = General.Map.Config.DefaultTextureScale; - // Continue until no more start can be found - startindex = file.FindLumpIndex(startlump); - while(startindex > -1) + // Go for all lumps between start and end exclusive + for(int i = startindex + 1; i < endindex; i++) { - // Find end index - endindex = file.FindLumpIndex(endlump, startindex + 1); - if(endindex == -1) endindex = file.Lumps.Count - 1; - - // Go for all lumps between start and end exclusive - for(int i = startindex + 1; i < endindex; i++) + // Lump not zero length? + if(file.Lumps[i].Length > 0) { - // Lump not zero length? - if(file.Lumps[i].Length > 0) - { - // Make the image - image = new SimpleTextureImage(file.Lumps[i].Name, file.Lumps[i].Name, defaultscale, defaultscale); - - // Add image to collection - images.Add(image); - } + // Make the image + SimpleTextureImage image = new SimpleTextureImage(file.Lumps[i].Name, file.Lumps[i].Name, defaultscale, defaultscale); + + // Add image to collection + images.Add(image); } - - // Find the next start - startindex = file.FindLumpIndex(startlump, endindex); } } @@ -319,9 +354,32 @@ namespace CodeImp.DoomBuilder.Data // Error when suspended if(issuspended) throw new Exception("Data reader is suspended"); - // Find the lump - lump = file.FindLump(pname); - if(lump != null) return lump.Stream; else return null; + // Find the lump in ranges + foreach(LumpRange range in patchranges) + { + lump = file.FindLump(pname, range.start, range.end); + if(lump != null) return lump.Stream; + } + + return null; + } + + // This finds and returns a texture stream + public override Stream GetTextureData(string pname) + { + Lump lump; + + // Error when suspended + if(issuspended) throw new Exception("Data reader is suspended"); + + // Find the lump in ranges + foreach(LumpRange range in textureranges) + { + lump = file.FindLump(pname, range.start, range.end); + if(lump != null) return lump.Stream; + } + + return null; } #endregion @@ -400,9 +458,14 @@ namespace CodeImp.DoomBuilder.Data // Error when suspended if(issuspended) throw new Exception("Data reader is suspended"); - // Find the lump - lump = file.FindLump(pname); - if(lump != null) return lump.Stream; else return null; + // Find the lump in ranges + foreach(LumpRange range in flatranges) + { + lump = file.FindLump(pname, range.start, range.end); + if(lump != null) return lump.Stream; + } + + return null; } #endregion @@ -417,9 +480,14 @@ namespace CodeImp.DoomBuilder.Data // Error when suspended if(issuspended) throw new Exception("Data reader is suspended"); - // Find the lump - lump = file.FindLump(pname); - if(lump != null) return lump.Stream; else return null; + // Find the lump in ranges + foreach(LumpRange range in spriteranges) + { + lump = file.FindLump(pname, range.start, range.end); + if(lump != null) return lump.Stream; + } + + return null; } // This checks if the given sprite exists @@ -429,10 +497,15 @@ namespace CodeImp.DoomBuilder.Data // Error when suspended if(issuspended) throw new Exception("Data reader is suspended"); - - // Find the lump - lump = file.FindLump(pname); - return (lump != null); + + // Find the lump in ranges + foreach(LumpRange range in spriteranges) + { + lump = file.FindLump(pname, range.start, range.end); + if(lump != null) return true; + } + + return false; } #endregion