// This returns the patch names from the PNAMES lump // A directory resource does not support this lump, but the wads in the directory may contain this lump public override PatchNames LoadPatchNames() { PatchNames pnames; // Error when suspended if (issuspended) { throw new Exception("Data reader is suspended"); } // Load from wad files // Note the backward order, because the last wad's images have priority for (int i = wads.Count - 1; i >= 0; i--) { pnames = wads[i].LoadPatchNames(); if (pnames != null) { return(pnames); } } // If none of the wads provides patch names, let's see if we can string pnamesfile = FindFirstFile("PNAMES", false); if ((pnamesfile != null) && FileExists(pnamesfile)) { MemoryStream pnamesdata = LoadFile(pnamesfile); pnames = new PatchNames(pnamesdata); pnamesdata.Dispose(); return(pnames); } return(null); }
// This loads the textures public override ICollection <ImageData> LoadTextures(PatchNames pnames) { List <ImageData> images = new List <ImageData>(); //string rangestart, rangeend; int lumpindex; Lump lump; // Error when suspended if (issuspended) { throw new Exception("Data reader is suspended"); } // Load two sets of textures, if available lump = file.FindLump("TEXTURE1"); if (lump != null) { LoadTextureSet("TEXTURE1", lump.Stream, ref images, pnames); } lump = file.FindLump("TEXTURE2"); if (lump != null) { LoadTextureSet("TEXTURE2", lump.Stream, ref images, pnames); } // Read ranges from configuration foreach (LumpRange range in textureranges) { // Load texture range LoadTexturesRange(range.start, range.end, ref images, pnames); } // Load TEXTURES lump file lumpindex = file.FindLumpIndex("TEXTURES"); while (lumpindex > -1) { MemoryStream filedata = new MemoryStream(file.Lumps[lumpindex].Stream.ReadAllBytes()); WADReader.LoadHighresTextures(filedata, "TEXTURES", ref images, null, null); filedata.Dispose(); // Find next lumpindex = file.FindLumpIndex("TEXTURES", lumpindex + 1); } // Add images to the container-specific texture set foreach (ImageData img in images) { textureset.AddTexture(img); } // Return result return(images); }
// When implemented, this loads the textures public abstract IEnumerable <ImageData> LoadTextures(PatchNames pnames, Dictionary <string, TexturesParser> cachedparsers);
// When implemented, this loads the textures public virtual ICollection <ImageData> LoadTextures(PatchNames pnames) { return(null); }
// This loads a set of textures public static void LoadTextureSet(string sourcename, Stream texturedata, ref List <ImageData> images, PatchNames pnames) { BinaryReader reader = new BinaryReader(texturedata); int flags, width, height, patches, px, py, pi; uint numtextures; byte scalebytex, scalebytey; float scalex, scaley, defaultscale; byte[] namebytes; TextureImage image = null; bool strifedata; if (texturedata.Length == 0) { return; } // Determine default scale defaultscale = General.Map.Config.DefaultTextureScale; // Get number of textures texturedata.Seek(0, SeekOrigin.Begin); numtextures = reader.ReadUInt32(); // Skip offset bytes (we will read all textures sequentially) texturedata.Seek(4 * numtextures, SeekOrigin.Current); // Go for all textures defined in this lump for (uint i = 0; i < numtextures; i++) { // Read texture properties namebytes = reader.ReadBytes(8); flags = reader.ReadUInt16(); scalebytex = reader.ReadByte(); scalebytey = reader.ReadByte(); width = reader.ReadInt16(); height = reader.ReadInt16(); patches = reader.ReadInt16(); // Check for doom or strife data format if (patches == 0) { // Ignore 2 bytes and then read number of patches texturedata.Seek(2, SeekOrigin.Current); patches = reader.ReadInt16(); strifedata = false; } else { // Texture data is in strife format strifedata = true; } // Determine actual scales if (scalebytex == 0) { scalex = defaultscale; } else { scalex = 1f / ((float)scalebytex / 8f); } if (scalebytey == 0) { scaley = defaultscale; } else { scaley = 1f / ((float)scalebytey / 8f); } // Validate data if ((width > 0) && (height > 0) && (patches > 0) && (scalex != 0) || (scaley != 0)) { string texname = Lump.MakeNormalName(namebytes, WAD.ENCODING); if (texname.Length > 0) { // Make the image object image = new TextureImage(Lump.MakeNormalName(namebytes, WAD.ENCODING), width, height, scalex, scaley); } else { // Can't load image without name General.ErrorLogger.Add(ErrorType.Error, "Can't load an unnamed texture from \"" + sourcename + "\". Please consider giving names to your resources."); } // Go for all patches in texture for (int p = 0; p < patches; p++) { // Read patch properties px = reader.ReadInt16(); py = reader.ReadInt16(); pi = reader.ReadUInt16(); if (!strifedata) { texturedata.Seek(4, SeekOrigin.Current); } // Validate data if ((pi >= 0) && (pi < pnames.Length)) { if (pnames[pi].Length > 0) { // Create patch on image if (image != null) { image.AddPatch(new TexturePatch(pnames[pi], px, py)); } } else { // Can't load image without name General.ErrorLogger.Add(ErrorType.Error, "Can't use an unnamed patch referenced in \"" + sourcename + "\". Please consider giving names to your resources."); } } } // Add image to collection images.Add(image); } else { // Skip patches data texturedata.Seek(6 * patches, SeekOrigin.Current); if (!strifedata) { texturedata.Seek(4 * patches, SeekOrigin.Current); } } } }
// This loads a range of textures private void LoadTexturesRange(int startindex, int endindex, ref List <ImageData> images, PatchNames pnames) { // Determine default scale float defaultscale = General.Map.Config.DefaultTextureScale; // 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) { // Make the image SimpleTextureImage image = new SimpleTextureImage(file.Lumps[i].Name, file.Lumps[i].Name, defaultscale, defaultscale); // Add image to collection images.Add(image); } else { // Can't load image without name General.ErrorLogger.Add(ErrorType.Error, "Can't load an unnamed texture from lump index " + i + ". Please consider giving names to your resources."); } } }
// This loads the textures public override IEnumerable <ImageData> LoadTextures(PatchNames pnames, Dictionary <string, TexturesParser> cachedparsers) { // Error when suspended if (issuspended) { throw new Exception("Data reader is suspended"); } Dictionary <long, ImageData> images = new Dictionary <long, ImageData>(); IEnumerable <ImageData> collection; // Load from wad files (NOTE: backward order, because the last wad's images have priority) for (int i = wads.Count - 1; i >= 0; i--) { PatchNames wadpnames = wads[i].LoadPatchNames(); //mxd collection = wads[i].LoadTextures((wadpnames != null && wadpnames.Length > 0) ? wadpnames : pnames, cachedparsers); //mxd AddImagesToList(images, collection); } // Should we load the images in this directory as textures? if (roottextures) { collection = LoadDirectoryImages("", ImageDataFormat.DOOMPICTURE, false); AddImagesToList(images, collection); } // Load TEXTURE1 lump file List <ImageData> imgset = new List <ImageData>(); string texture1file = FindFirstFile("TEXTURE1", false); if ((texture1file != null) && FileExists(texture1file)) { MemoryStream filedata = LoadFile(texture1file); WADReader.LoadTextureSet("TEXTURE1", filedata, ref imgset, pnames); filedata.Dispose(); } // Load TEXTURE2 lump file string texture2file = FindFirstFile("TEXTURE2", false); if ((texture2file != null) && FileExists(texture2file)) { MemoryStream filedata = LoadFile(texture2file); WADReader.LoadTextureSet("TEXTURE2", filedata, ref imgset, pnames); filedata.Dispose(); } // Add images from TEXTURE1 and TEXTURE2 lump files AddImagesToList(images, imgset); // Load TEXTURES lump files imgset.Clear(); string[] alltexturefiles = GetAllFilesWhichTitleStartsWith("", "TEXTURES", false); //mxd foreach (string texturesfile in alltexturefiles) { //mxd. Added TexturesParser caching string fullpath = Path.Combine(this.location.location, texturesfile); if (cachedparsers.ContainsKey(fullpath)) { // Make the textures foreach (TextureStructure t in cachedparsers[fullpath].Textures) { imgset.Add(t.MakeImage()); } } else { MemoryStream filedata = LoadFile(texturesfile); TextResourceData data = new TextResourceData(this, filedata, texturesfile, true); //mxd cachedparsers.Add(fullpath, WADReader.LoadTEXTURESTextures(data, ref imgset)); //mxd filedata.Dispose(); } } // Add images from TEXTURES lump file AddImagesToList(images, imgset); //mxd. Add images from texture directory. Textures defined in TEXTURES override ones in "textures" folder collection = LoadDirectoryImages(TEXTURES_DIR, ImageDataFormat.DOOMPICTURE, true); AddImagesToList(images, collection); // Add images to the container-specific texture set foreach (ImageData img in images.Values) { textureset.AddTexture(img); } return(new List <ImageData>(images.Values)); }
// This loads the textures public override ICollection <ImageData> LoadTextures(PatchNames pnames) { Dictionary <long, ImageData> images = new Dictionary <long, ImageData>(); ICollection <ImageData> collection; List <ImageData> imgset = new List <ImageData>(); // Error when suspended if (issuspended) { throw new Exception("Data reader is suspended"); } // Load from wad files (NOTE: backward order, because the last wad's images have priority) for (int i = wads.Count - 1; i >= 0; i--) { collection = wads[i].LoadTextures(pnames); AddImagesToList(images, collection); } // Should we load the images in this directory as textures? if (roottextures) { collection = LoadDirectoryImages("", ImageDataFormat.DOOMPICTURE, false); AddImagesToList(images, collection); } // Add images from texture directory collection = LoadDirectoryImages(TEXTURES_DIR, ImageDataFormat.DOOMPICTURE, true); AddImagesToList(images, collection); // Load TEXTURE1 lump file imgset.Clear(); string texture1file = FindFirstFile("TEXTURE1", false); if ((texture1file != null) && FileExists(texture1file)) { MemoryStream filedata = LoadFile(texture1file); WADReader.LoadTextureSet("TEXTURE1", filedata, ref imgset, pnames); filedata.Dispose(); } // Load TEXTURE2 lump file string texture2file = FindFirstFile("TEXTURE2", false); if ((texture2file != null) && FileExists(texture2file)) { MemoryStream filedata = LoadFile(texture2file); WADReader.LoadTextureSet("TEXTURE2", filedata, ref imgset, pnames); filedata.Dispose(); } // Add images from TEXTURE1 and TEXTURE2 lump files AddImagesToList(images, imgset); // Load TEXTURES lump file imgset.Clear(); string[] alltexturefiles = GetAllFilesWithTitle("", "TEXTURES", false); foreach (string texturesfile in alltexturefiles) { MemoryStream filedata = LoadFile(texturesfile); WADReader.LoadHighresTextures(filedata, texturesfile, ref imgset, images, null); filedata.Dispose(); } // Add images from TEXTURES lump file AddImagesToList(images, imgset); // Add images to the container-specific texture set foreach (ImageData img in images.Values) { textureset.AddTexture(img); } return(new List <ImageData>(images.Values)); }
// This loads the textures public override ICollection <ImageData> LoadTextures(PatchNames pnames) { Dictionary <long, ImageData> images = new Dictionary <long, ImageData>(); ICollection <ImageData> collection; List <ImageData> imgset = new List <ImageData>(); // Error when suspended if (issuspended) { throw new Exception("Data reader is suspended"); } subtexturesets = new Dictionary <string, ResourceTextureSet>(); // Load from wad files (NOTE: backward order, because the last wad's images have priority) for (int i = wads.Count - 1; i >= 0; i--) { collection = wads[i].LoadTextures(pnames); ResourceTextureSet wadTextureSet = new ResourceTextureSet(wads[i].GetTitle(), location); // ano - moved this loop out from AddImagesToList // because we need to add the images to a // wad-specific list foreach (ImageData src in collection) { // Check if exists in target list if (!images.ContainsKey(src.LongName)) { images.Add(src.LongName, src); wadTextureSet.AddTexture(src); } } // foreach subtexturesets.Add(wadTextureSet.Name, wadTextureSet); } // for(wads) // Should we load the images in this directory as textures? if (roottextures) { collection = LoadDirectoryImages("", ImageDataFormat.DOOMPICTURE, false); AddImagesToList(images, collection); } // Add images from texture directory collection = LoadDirectoryImagesAndCategorize(TEXTURES_DIR, ImageDataFormat.DOOMPICTURE, images, false); // Load TEXTURE1 lump file imgset.Clear(); string texture1file = FindFirstFile("TEXTURE1", false); if ((texture1file != null) && FileExists(texture1file)) { MemoryStream filedata = LoadFile(texture1file); WADReader.LoadTextureSet("TEXTURE1", filedata, ref imgset, pnames); filedata.Dispose(); } // Load TEXTURE2 lump file string texture2file = FindFirstFile("TEXTURE2", false); if ((texture2file != null) && FileExists(texture2file)) { MemoryStream filedata = LoadFile(texture2file); WADReader.LoadTextureSet("TEXTURE2", filedata, ref imgset, pnames); filedata.Dispose(); } // Add images from TEXTURE1 and TEXTURE2 lump files AddImagesToList(images, imgset); // Load TEXTURES lump file imgset.Clear(); string[] alltexturefiles = GetAllFilesWithTitle("", "TEXTURES", false); foreach (string texturesfile in alltexturefiles) { MemoryStream filedata = LoadFile(texturesfile); WADReader.LoadHighresTextures(filedata, texturesfile, ref imgset, images, null); filedata.Dispose(); } // Add images from TEXTURES lump file AddImagesToList(images, imgset); // Add images to the container-specific texture set foreach (ImageData img in images.Values) { textureset.AddTexture(img); } return(new List <ImageData>(images.Values)); }
// This loads the textures public override ICollection <ImageData> LoadTextures(PatchNames pnames) { List <ImageData> images = new List <ImageData>(); string rangestart, rangeend; int lumpindex; Lump lump; // Error when suspended if (issuspended) { throw new Exception("Data reader is suspended"); } // Load two sets of textures, if available lump = file.FindLump("TEXTURE1"); if (lump != null) { LoadTextureSet("TEXTURE1", lump.Stream, ref images, pnames); } lump = file.FindLump("TEXTURE2"); if (lump != null) { LoadTextureSet("TEXTURE2", lump.Stream, ref images, pnames); } // Read ranges from configuration foreach (LumpRange range in textureranges) { // Load texture range LoadTexturesRange(range.start, range.end, ref images, pnames); } foreach (Sector s in General.Map.Map.Sectors) { for (int j = 0; j < General.Map.TextureHashKey.Count; j++) { if (s.HashFloor == General.Map.TextureHashKey[j]) { s.SetFloorTexture(General.Map.TextureHashName[j]); break; } } for (int j = 0; j < General.Map.TextureHashKey.Count; j++) { if (s.HashCeiling == General.Map.TextureHashKey[j]) { s.SetCeilTexture(General.Map.TextureHashName[j]); break; } } } foreach (Sidedef sd in General.Map.Map.Sidedefs) { for (int j = 0; j < General.Map.TextureHashKey.Count; j++) { if (sd.HashTexHigh == General.Map.TextureHashKey[j]) { if (j == 0) { sd.SetTextureHigh("-"); break; } sd.SetTextureHigh(General.Map.TextureHashName[j]); break; } } for (int j = 0; j < General.Map.TextureHashKey.Count; j++) { if (sd.HashTexMid == General.Map.TextureHashKey[j]) { if (j == 0) { sd.SetTextureMid("-"); break; } sd.SetTextureMid(General.Map.TextureHashName[j]); break; } } for (int j = 0; j < General.Map.TextureHashKey.Count; j++) { if (sd.HashTexLow == General.Map.TextureHashKey[j]) { if (j == 0) { sd.SetTextureLow("-"); break; } sd.SetTextureLow(General.Map.TextureHashName[j]); break; } } } // Load TEXTURES lump file lumpindex = file.FindLumpIndex("TEXTURES"); while (lumpindex > -1) { MemoryStream filedata = new MemoryStream(file.Lumps[lumpindex].Stream.ReadAllBytes()); WADReader.LoadHighresTextures(filedata, "TEXTURES", ref images, null, null); filedata.Dispose(); // Find next lumpindex = file.FindLumpIndex("TEXTURES", lumpindex + 1); } // Add images to the container-specific texture set foreach (ImageData img in images) { textureset.AddTexture(img); } // Return result return(images); }