patches, sprites and flats in WAD files are now only loaded when they are properly enclosed within marker lumps (P_START, P_END, S_START, etc)

This commit is contained in:
codeimp 2009-01-22 23:32:44 +00:00
parent 751cfdb7e8
commit 4bbf14dde9
28 changed files with 721 additions and 51 deletions

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -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<string> 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<string> 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();

View file

@ -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)

View file

@ -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<ImageData> LoadTextures(PatchNames pnames) { return null; }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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<LumpRange> flatranges;
private List<LumpRange> patchranges;
private List<LumpRange> spriteranges;
private List<LumpRange> 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<LumpRange>();
spriteranges = new List<LumpRange>();
flatranges = new List<LumpRange>();
textureranges = new List<LumpRange>();
// 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<LumpRange> 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<ImageData> images, PatchNames pnames)
private void LoadTexturesRange(int startindex, int endindex, ref List<ImageData> 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