added a lot

This commit is contained in:
codeimp 2007-10-07 22:21:47 +00:00
parent e16cfb9873
commit a109bf4bfb
40 changed files with 9642 additions and 180 deletions

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -20,6 +20,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -13,6 +13,8 @@ formatinterface = "DoomMapSetIO";
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// No generalized types
generalizedlinedefs = 1;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 1;
// Engine specific features
mixtexturesflats = 1;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

View file

@ -17,6 +17,8 @@ generalizedsectors = 0;
// Engine specific features
mixtexturesflats = 0;
defaulttexturescale = 1.0f;
defaultflatscale = 1.0f;
// Thing number for start position in 3D Mode
start3dmode = 32000;

2388
Documents/Boom_specs.txt Normal file

File diff suppressed because it is too large Load diff

3801
Documents/Doom_specs.txt Normal file

File diff suppressed because it is too large Load diff

2650
Documents/Hexen_specs.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -49,6 +49,7 @@
<Compile Include="Data\DirectoryReader.cs" />
<Compile Include="Data\FileImage.cs" />
<Compile Include="Data\FlatImage.cs" />
<Compile Include="Data\PatchNames.cs" />
<Compile Include="Data\Playpal.cs" />
<Compile Include="Data\SpriteImage.cs" />
<Compile Include="Data\TextureImage.cs" />
@ -68,7 +69,7 @@
<Compile Include="Geometry\Vector3D.cs" />
<Compile Include="Data\TexturePatch.cs" />
<Compile Include="Data\TexturePatchFormat.cs" />
<Compile Include="Data\IDataReader.cs" />
<Compile Include="Data\DataReader.cs" />
<Compile Include="Data\DataLocationList.cs" />
<Compile Include="Data\DataManager.cs" />
<Compile Include="Data\WADReader.cs" />
@ -118,6 +119,7 @@
<Compile Include="General\General.cs" />
<Compile Include="IO\ClippedStream.cs" />
<Compile Include="IO\DoomMapSetIO.cs" />
<Compile Include="IO\DoomPictureReader.cs" />
<Compile Include="IO\Lump.cs" />
<Compile Include="IO\MapSetIO.cs" />
<Compile Include="IO\WAD.cs" />

View file

@ -24,6 +24,7 @@ using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using CodeImp.DoomBuilder.IO;
#endregion
@ -38,8 +39,20 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
// Data containers
private List<IDataReader> containers;
private List<DataReader> containers;
// Palette
private Playpal palette;
// Textures
private Dictionary<long, ImageData> textures;
// Flats
private Dictionary<long, ImageData> flats;
// Sprites
private Dictionary<long, ImageData> sprites;
// Disposing
private bool isdisposed = false;
@ -57,9 +70,6 @@ namespace CodeImp.DoomBuilder.Data
// Constructor
public DataManager()
{
// Initialize
containers = new List<IDataReader>();
// We have no destructor
GC.SuppressFinalize(this);
}
@ -85,32 +95,28 @@ namespace CodeImp.DoomBuilder.Data
// This loads all data resources
public void Load(DataLocationList configlist, DataLocationList maplist, DataLocation maplocation)
{
DataLocationList all;
// Create complete list
all = DataLocationList.Combined(configlist, maplist);
DataLocationList all = DataLocationList.Combined(configlist, maplist);
all.Add(maplocation);
// Load resources
Load(all);
}
// This loads all data resources
public void Load(DataLocationList configlist, DataLocationList maplist)
{
DataLocationList all;
// Create complete list
all = DataLocationList.Combined(configlist, maplist);
// Load resources
DataLocationList all = DataLocationList.Combined(configlist, maplist);
Load(all);
}
// This loads all data resources
public void Load(DataLocationList locations)
{
IDataReader c;
DataReader c;
// Create collections
containers = new List<DataReader>();
textures = new Dictionary<long, ImageData>();
flats = new Dictionary<long, ImageData>();
sprites = new Dictionary<long, ImageData>();
// Go for all locations
foreach(DataLocation dl in locations)
@ -118,6 +124,10 @@ namespace CodeImp.DoomBuilder.Data
// Nothing chosen yet
c = null;
// TODO: Make this work more elegant using reflection.
// Make DataLocation.type of type Type and assign the
// types of the desired reader classes.
// Choose container type
switch(dl.type)
{
@ -132,33 +142,43 @@ namespace CodeImp.DoomBuilder.Data
break;
}
// Container type chosen?
if(c != null)
{
// TODO: Let the container read stuff
// Keep container reference
containers.Add(c);
}
// Add container
if(c != null) containers.Add(c);
}
// Load stuff
General.WriteLogLine("Loading PLAYPAL palette...");
LoadPalette();
General.WriteLogLine("Loading textures...");
LoadTextures();
}
// This unloads all data
public void Unload()
{
// Dispose resources
foreach(KeyValuePair<long, ImageData> i in textures) i.Value.Dispose();
foreach(KeyValuePair<long, ImageData> i in flats) i.Value.Dispose();
foreach(KeyValuePair<long, ImageData> i in sprites) i.Value.Dispose();
palette = null;
// Dispose containers
foreach(IDataReader c in containers) c.Dispose();
foreach(DataReader c in containers) c.Dispose();
containers.Clear();
}
#endregion
#region ================== Suspend / Resume
// This suspends a data resource location
public void SuspendLocation(string location)
{
// Go for all containers
foreach(IDataReader d in containers)
foreach(DataReader d in containers)
{
// Check if this is the location to suspend
if(string.Compare(d.Location, location, true) == 0)
if(string.Compare(d.Location.location, location, true) == 0)
{
// Suspend
General.WriteLogLine("Suspended data resource '" + location + "'");
@ -174,10 +194,10 @@ namespace CodeImp.DoomBuilder.Data
public void ResumeLocation(string location)
{
// Go for all containers
foreach(IDataReader d in containers)
foreach(DataReader d in containers)
{
// Check if this is the location to resume
if(string.Compare(d.Location, location, true) == 0)
if(string.Compare(d.Location.location, location, true) == 0)
{
// Resume
General.WriteLogLine("Resumed data resource '" + location + "'");
@ -190,5 +210,74 @@ namespace CodeImp.DoomBuilder.Data
}
#endregion
#region ================== Palette
// This loads the PLAYPAL palette
private void LoadPalette()
{
// Go for all opened containers
for(int i = containers.Count - 1; i >= 0; i--)
{
// Load palette
palette = containers[i].LoadPalette();
if(palette != null) break;
}
}
#endregion
#region ================== Textures
// This loads the textures
private void LoadTextures()
{
PatchNames pnames;
ICollection<ImageData> images;
// Go for all opened containers
foreach(DataReader dr in containers)
{
// Load PNAMES info
// Note that pnames is NOT set to null in the loop
// because if a container has no pnames, the pnames
// of the previous (higher) container should be used.
pnames = dr.LoadPatchNames();
if(pnames != null)
{
// Load textures
images = dr.LoadTextures(pnames);
if(images != null)
{
// Go for all textures
foreach(ImageData img in images)
{
// Add or replace in textures list
textures.Remove(img.LongName);
textures.Add(img.LongName, img);
}
}
}
}
}
// This returns a specific patch stream
public Stream GetPatchData(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].GetPatchData(pname);
if(patch != null) return patch;
}
// No such patch found
return null;
}
#endregion
}
}

110
Source/Data/DataReader.cs Normal file
View file

@ -0,0 +1,110 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal abstract class DataReader : IDisposable
{
#region ================== Variables
protected DataLocation location;
protected bool issuspended = false;
protected bool isdisposed = false;
#endregion
#region ================== Properties
public DataLocation Location { get { return location; } }
public bool IsDisposed { get { return isdisposed; } }
public bool IsSuspended { get { return issuspended; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public DataReader(DataLocation dl)
{
// Keep information
location = dl;
}
// Disposer
public virtual void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Done
isdisposed = true;
}
}
#endregion
#region ================== Management
// This suspends use of this resource
public virtual void Suspend()
{
issuspended = true;
}
// This resumes use of this resource
public virtual void Resume()
{
issuspended = false;
}
#endregion
#region ================== Palette
// When implemented, this should find and load a PLAYPAL palette
public virtual Playpal LoadPalette() { return null; }
#endregion
#region ================== Textures
// When implemented, this should read the patch names
public virtual PatchNames LoadPatchNames() { return null; }
// When implemented, this returns the patch lump
public virtual Stream GetPatchData(string pname) { return null; }
// When implemented, this loads the textures
public virtual ICollection<ImageData> LoadTextures(PatchNames pnames) { return null; }
#endregion
}
}

View file

@ -30,7 +30,7 @@ using CodeImp.DoomBuilder.IO;
namespace CodeImp.DoomBuilder.Data
{
internal class DirectoryReader : IDataReader
internal class DirectoryReader : DataReader
{
#region ================== Constants
@ -39,72 +39,61 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
// Source
private string path;
private bool readtextures;
private bool readflats;
private bool issuspended = false;
private bool isdisposed = false;
#endregion
#region ================== Properties
public string Location { get { return path; } }
public bool IsDisposed { get { return isdisposed; } }
public bool IsSuspended { get { return issuspended; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public DirectoryReader(DataLocation dl)
public DirectoryReader(DataLocation dl) : base(dl)
{
// Initialize
this.path = dl.location;
this.readtextures = dl.textures;
this.readflats = dl.flats;
General.WriteLogLine("Opening directory resource '" + dl.location + "'");
General.WriteLogLine("Opening directory resource '" + location.location + "'");
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public void Dispose()
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
General.WriteLogLine("Closing directory resource '" + path + "'");
General.WriteLogLine("Closing directory resource '" + location.location + "'");
// Clean up
// Done
isdisposed = true;
base.Dispose();
}
}
#endregion
#region ================== Management
#region ================== Palette
// This suspends use of this resource
public void Suspend()
// This loads the PLAYPAL palette
public override Playpal LoadPalette()
{
issuspended = true;
}
// This resumes use of this resource
public void Resume()
{
issuspended = false;
// Error when suspended
if(issuspended) throw new Exception("Data reader is suspended");
// Not yet implemented
return null;
}
#endregion
#region ================== Textures
#endregion

View file

@ -14,7 +14,7 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
private IDataReader source;
private DataReader source;
private string lumpname;
#endregion
@ -26,7 +26,7 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Constructor / Disposer
// Constructor
public FlatImage(string name, IDataReader source, string lumpname)
public FlatImage(string name, DataReader source, string lumpname)
{
// Initialize
this.source = source;

View file

@ -1,46 +0,0 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal unsafe interface IDataReader : IDisposable
{
// Properties
string Location { get; }
bool IsDisposed { get; }
bool IsSuspended { get; }
// Methods
void Dispose();
void Suspend();
void Resume();
}
}

View file

@ -25,6 +25,7 @@ using System.Drawing;
using SlimDX.Direct3D9;
using System.Drawing.Imaging;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.IO;
#endregion
@ -41,7 +42,7 @@ namespace CodeImp.DoomBuilder.Data
// Properties
private string name;
private long longname;
// GDI bitmap
protected Bitmap bitmap;
@ -60,6 +61,7 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Properties
public string Name { get { return name; } }
public long LongName { get { return longname; } }
public PixelColor* PixelData { get { return pixeldata; } }
public Bitmap Bitmap { get { return bitmap; } }
public Texture Texture { get { return texture; } }
@ -103,7 +105,7 @@ namespace CodeImp.DoomBuilder.Data
protected void SetName(string name)
{
this.name = name;
this.longname = General.GetTextureLongName(name);
this.longname = Lump.MakeLongName(name);
}
// This requests loading the image
@ -116,7 +118,7 @@ namespace CodeImp.DoomBuilder.Data
{
// Make a data copy of the bits for the 2D renderer
bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Size.Width, bitmap.Size.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
pixeldatasize = (uint)(bmpdata.Width * bmpdata.Height);
pixeldatasize = (uint)(bmpdata.Width * bmpdata.Height * sizeof(PixelColor));
pixeldata = (PixelColor*)General.VirtualAlloc(IntPtr.Zero, new UIntPtr(pixeldatasize), General.MEM_COMMIT, General.PAGE_READWRITE);
General.CopyMemory((void*)pixeldata, bmpdata.Scan0.ToPointer(), new UIntPtr(pixeldatasize));
bitmap.UnlockBits(bmpdata);

79
Source/Data/PatchNames.cs Normal file
View file

@ -0,0 +1,79 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using CodeImp.DoomBuilder.IO;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal class PatchNames
{
#region ================== Constants
#endregion
#region ================== Variables
private string[] pnames;
#endregion
#region ================== Properties
public string this[int index] { get { return pnames[index]; } }
public int Length { get { return pnames.Length; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public PatchNames(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
uint length;
// Read length of array
stream.Seek(0, SeekOrigin.Begin);
length = reader.ReadUInt32();
// Create array
pnames = new string[length];
// Read all patch names
for(uint i = 0; i < length; i++)
{
byte[] bytes = reader.ReadBytes(8);
pnames[i] = Lump.MakeNormalName(bytes, WAD.ENCODING);
}
}
#endregion
#region ================== Methods
#endregion
}
}

View file

@ -1,10 +1,31 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal class Playpal
@ -21,19 +42,30 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Properties
public PixelColor this[int a] { get { return colors[a]; } }
public PixelColor this[int index] { get { return colors[index]; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public Playpal(IDataReader source, int lumpindex)
public Playpal(Stream stream)
{
// Initialize
BinaryReader reader = new BinaryReader(stream);
// Create array
colors = new PixelColor[256];
// We have no destructor
GC.SuppressFinalize(this);
// Read all palette entries
stream.Seek(0, SeekOrigin.Begin);
for(int i = 0; i < 256; i++)
{
// Read colors
colors[i].r = reader.ReadByte();
colors[i].g = reader.ReadByte();
colors[i].b = reader.ReadByte();
colors[i].a = 255;
}
}
#endregion

View file

@ -14,7 +14,7 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
private IDataReader source;
private DataReader source;
private string lumpname;
#endregion
@ -26,7 +26,7 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Constructor / Disposer
// Constructor
public SpriteImage(string name, IDataReader source, string lumpname)
public SpriteImage(string name, DataReader source, string lumpname)
{
// Initialize
this.source = source;

View file

@ -35,7 +35,11 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
private List<TexturePatch> patches;
private int width;
private int height;
private float scalex;
private float scaley;
#endregion
#region ================== Properties
@ -45,9 +49,13 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Constructor / Disposer
// Constructor
public TextureImage(string name)
public TextureImage(string name, int width, int height, float scalex, float scaley)
{
// Initialize
this.width = width;
this.height = height;
this.scalex = scalex;
this.scaley = scaley;
this.patches = new List<TexturePatch>();
SetName(name);
@ -86,7 +94,6 @@ namespace CodeImp.DoomBuilder.Data
if(this.IsLoaded) return;
// Pass on to base
base.LoadImage();
}

View file

@ -32,9 +32,17 @@ namespace CodeImp.DoomBuilder.Data
{
internal struct TexturePatch
{
private IDataReader source;
private string lumpname;
private Point position;
private Size size;
private int x;
private int y;
// Constructor
public TexturePatch(string lumpname, int x, int y)
{
// Initialize
this.lumpname = lumpname;
this.x = x;
this.y = y;
}
}
}

View file

@ -30,7 +30,7 @@ using CodeImp.DoomBuilder.IO;
namespace CodeImp.DoomBuilder.Data
{
internal class WADReader : IDataReader
internal class WADReader : DataReader
{
#region ================== Constants
@ -40,64 +40,40 @@ namespace CodeImp.DoomBuilder.Data
// Source
private WAD file;
private string location;
private bool managefile;
private bool issuspended = false;
private bool isdisposed = false;
#endregion
#region ================== Properties
public string Location { get { return location; } }
public bool IsDisposed { get { return isdisposed; } }
public bool IsSuspended { get { return issuspended; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public WADReader(DataLocation dl)
public WADReader(DataLocation dl) : base(dl)
{
// Initialize
this.location = dl.location;
file = new WAD(location, true);
managefile = true;
file = new WAD(location.location, true);
General.WriteLogLine("Opening WAD resource '" + file.Filename + "'");
// We have no destructor
GC.SuppressFinalize(this);
}
// Constructor
public WADReader(WAD wadfile)
{
// Initialize
file = wadfile;
managefile = false;
General.WriteLogLine("Opening WAD resource '" + file.Filename + "' (file already open)");
General.WriteLogLine("Opening WAD resource '" + location.location + "'");
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
public void Dispose()
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
General.WriteLogLine("Closing WAD resource '" + file.Filename + "'");
General.WriteLogLine("Closing WAD resource '" + location.location + "'");
// Clean up
if(managefile) file.Dispose();
file.Dispose();
// Done
isdisposed = true;
base.Dispose();
}
}
@ -106,23 +82,186 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Management
// This suspends use of this resource
public void Suspend()
public override void Suspend()
{
issuspended = true;
if(managefile) file.Dispose();
file.Dispose();
base.Suspend();
}
// This resumes use of this resource
public void Resume()
public override void Resume()
{
issuspended = false;
if(managefile) file = new WAD(location, true);
file = new WAD(location.location, true);
base.Resume();
}
#endregion
#region ================== Palette
// This loads the PLAYPAL palette
public override Playpal LoadPalette()
{
Lump lump;
// Error when suspended
if(issuspended) throw new Exception("Data reader is suspended");
// Look for a lump named PLAYPAL
lump = file.FindLump("PLAYPAL");
if(lump != null)
{
// Read the PLAYPAL from stream
return new Playpal(lump.Stream);
}
else
{
// No palette
return null;
}
}
#endregion
#region ================== Textures
// This loads the textures
public override ICollection<ImageData> LoadTextures(PatchNames pnames)
{
List<ImageData> images = new List<ImageData>();
Lump lump;
// Load two sets of textures, if available
lump = file.FindLump("TEXTURE1");
if(lump != null) LoadTextureSet(lump.Stream, ref images, pnames);
lump = file.FindLump("TEXTURE2");
if(lump != null) LoadTextureSet(lump.Stream, ref images, pnames);
// Return result
return images;
}
// This loads a set of textures
private void LoadTextureSet(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;
bool strifedata;
// Determine default scale
defaultscale = General.Map.Configuration.ReadSetting("defaulttexturescale", 1.0f);
// 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))
{
// Make the image object
image = new TextureImage(Lump.MakeNormalName(namebytes, WAD.ENCODING),
width, height, scalex, scaley);
// 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) && (pnames[pi].Length > 0))
{
// Create patch on image
image.AddPatch(new TexturePatch(pnames[pi], px, py));
}
}
// 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 returns the patch names from the PNAMES lump
public override PatchNames LoadPatchNames()
{
Lump lump;
// Error when suspended
if(issuspended) throw new Exception("Data reader is suspended");
// Look for a lump named PNAMES
lump = file.FindLump("PNAMES");
if(lump != null)
{
// Read the PNAMES from stream
return new PatchNames(lump.Stream);
}
else
{
// No palette
return null;
}
}
// This finds and returns a patch stream
public override Stream GetPatchData(string pname)
{
Lump lump;
// Find the lump
lump = file.FindLump(pname);
if(lump != null) return lump.Stream; else return null;
}
#endregion
}
}

View file

@ -677,22 +677,6 @@ namespace CodeImp.DoomBuilder
return filename;
}
// This returns the long value for a 8 byte texture name
public static unsafe long GetTextureLongName(string name)
{
long value = 0;
byte[] namebytes = Encoding.ASCII.GetBytes(name);
uint bytes = (uint)namebytes.Length;
if(bytes > 8) bytes = 8;
fixed(void* bp = namebytes)
{
CopyMemory(&value, bp, new UIntPtr(bytes));
}
return value;
}
#endregion
}
}

View file

@ -73,9 +73,11 @@ namespace CodeImp.DoomBuilder
public MapOptions Options { get { return options; } }
public MapSet Map { get { return map; } }
public EditMode Mode { get { return mode; } }
public DataManager Data { get { return data; } }
public bool IsChanged { get { return changed; } set { changed = value; } }
public bool IsDisposed { get { return isdisposed; } }
public D3DGraphics Graphics { get { return graphics; } }
public Configuration Configuration { get { return config; } }
#endregion

View file

@ -0,0 +1,159 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.IO
{
internal unsafe class DoomPictureReader
{
#region ================== Constants
#endregion
#region ================== Variables
// Palette to use
private Playpal palette;
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor
public DoomPictureReader(Playpal palette)
{
// Initialize
this.palette = palette;
}
#endregion
#region ================== Methods
// This creates a Bitmap from the given data
public Bitmap ReadAsBitmap(Stream stream)
{
// TODO: Read as pixel data and copy pixels
return null;
}
// This draws the picture to the given pixel color data
public void DrawToPixelData(Stream stream, PixelColor* target, int targetwidth, int targetheight, int x, int y)
{
// TODO: Read as pixel data and copy pixels
}
// This creates pixel color data from the given data
public PixelColor* ReadAsPixelData(Stream stream, out int width, out int height, out int offsetx, out int offsety)
{
BinaryReader reader = new BinaryReader(stream);
PixelColor* pixeldata = null;
uint datalength = 0;
int y, count, p;
// Initialize
width = 0;
height = 0;
offsetx = 0;
offsety = 0;
// Need at least 4 bytes
if((stream.Length - stream.Position) < 4) return null;
try
{
// Read size and offset
width = reader.ReadInt16();
height = reader.ReadInt16();
offsetx = reader.ReadInt16();
offsety = reader.ReadInt16();
// Skip the column addresses
stream.Seek(4 * width, SeekOrigin.Current);
// Allocate memory
datalength = (uint)(sizeof(PixelColor) * width * height);
pixeldata = (PixelColor*)General.VirtualAlloc(IntPtr.Zero, new UIntPtr(datalength), General.MEM_COMMIT, General.PAGE_READWRITE);
General.ZeroMemory(new IntPtr(pixeldata), (int)datalength);
// Go for all columns
for(int x = 0; x < width; x++)
{
// Read first post start
y = reader.ReadByte();
// Continue while not end of column reached
while(y < 255)
{
// Read number of pixels in post
count = reader.ReadByte();
// Skip unused pixel
stream.Seek(1, SeekOrigin.Current);
// Draw post
for(int yo = 0; yo < count; yo++)
{
// Read pixel color index
p = reader.ReadByte();
// Draw pixel
pixeldata[(y + yo) * width + x] = palette[p];
}
// Skip unused pixel
stream.Seek(1, SeekOrigin.Current);
// Read next post start
y = reader.ReadByte();
}
}
// Return pointer
return pixeldata;
}
catch(Exception)
{
// Free memory if allocated
if(datalength > 0) General.VirtualFree((void*)pixeldata, new UIntPtr(datalength), General.MEM_RELEASE);
// Return nothing
return null;
}
}
#endregion
}
}

View file

@ -39,6 +39,7 @@ namespace CodeImp.DoomBuilder.IO
// Data info
private string name;
private long longname;
private byte[] fixedname;
private int offset;
private int length;
@ -52,6 +53,7 @@ namespace CodeImp.DoomBuilder.IO
public WAD Owner { get { return owner; } }
public string Name { get { return name; } }
public long LongName { get { return longname; } }
public byte[] FixedName { get { return fixedname; } }
public int Offset { get { return offset; } }
public int Length { get { return length; } }
@ -72,9 +74,10 @@ namespace CodeImp.DoomBuilder.IO
this.offset = offset;
this.length = length;
// Make uppercase name
// Make name
this.name = MakeNormalName(fixedname, WAD.ENCODING).ToUpperInvariant();
this.fixedname = MakeFixedName(name, WAD.ENCODING);
this.longname = MakeLongName(name);
// We have no destructor
GC.SuppressFinalize(this);
@ -98,6 +101,22 @@ namespace CodeImp.DoomBuilder.IO
#endregion
#region ================== Methods
// This returns the long value for a 8 byte texture name
public static unsafe long MakeLongName(string name)
{
long value = 0;
byte[] namebytes = Encoding.ASCII.GetBytes(name);
uint bytes = (uint)namebytes.Length;
if(bytes > 8) bytes = 8;
fixed(void* bp = namebytes)
{
General.CopyMemory(&value, bp, new UIntPtr(bytes));
}
return value;
}
// This makes the normal name from fixed name
public static string MakeNormalName(byte[] fixedname, Encoding encoding)
@ -108,7 +127,7 @@ namespace CodeImp.DoomBuilder.IO
while((length < fixedname.Length) && (fixedname[length] != 0)) length++;
// Make normal name
return encoding.GetString(fixedname, 0, length);
return encoding.GetString(fixedname, 0, length).Trim();
}
// This makes the fixed name from normal name
@ -118,7 +137,7 @@ namespace CodeImp.DoomBuilder.IO
byte[] fixedname = new byte[8];
// Write the name in bytes
encoding.GetBytes(name, 0, name.Length, fixedname, 0);
encoding.GetBytes(name.Trim(), 0, name.Length, fixedname, 0);
// Return result
return fixedname;

View file

@ -359,7 +359,8 @@ namespace CodeImp.DoomBuilder.IO
public int FindLumpIndex(string name, int start, int end)
{
byte[] fixedname;
long longname = Lump.MakeLongName(name);
// Fix end when it exceeds length
if(end > (lumps.Count - 1)) end = lumps.Count - 1;
@ -372,6 +373,7 @@ namespace CodeImp.DoomBuilder.IO
// Loop through the lumps
for(int i = start; i <= end; i++)
{
/*
// Check if first byte matches
if(lumps[i].FixedName[0] == fixedname[0])
{
@ -382,6 +384,14 @@ namespace CodeImp.DoomBuilder.IO
return i;
}
}
*/
// Check if the lump name matches
if(lumps[i].LongName == longname)
{
// Found the lump!
return i;
}
}
// Nothing found