From 319be16c0333894536f7b724a8f56e00f59b96f5 Mon Sep 17 00:00:00 2001 From: codeimp Date: Mon, 1 Oct 2007 20:57:41 +0000 Subject: [PATCH] drama --- Source/Data/DataLocation.cs | 58 +++++++++++++ Source/Data/DataLocationList.cs | 88 +++++++++++++++++++ Source/Data/DataManager.cs | 82 ++++++++++++++++++ Source/Data/FileImage.cs | 77 +++++++++++++++++ Source/Data/IDataContainer.cs | 41 +++++++++ Source/Data/ImageData.cs | 146 ++++++++++++++++++++++++++++++++ Source/Data/ImagePatch.cs | 64 ++++++++++++++ Source/Data/ImagePatchFormat.cs | 41 +++++++++ Source/Data/TextureImage.cs | 85 +++++++++++++++++++ Source/Data/WADContainer.cs | 101 ++++++++++++++++++++++ 10 files changed, 783 insertions(+) create mode 100644 Source/Data/DataLocation.cs create mode 100644 Source/Data/DataLocationList.cs create mode 100644 Source/Data/DataManager.cs create mode 100644 Source/Data/FileImage.cs create mode 100644 Source/Data/IDataContainer.cs create mode 100644 Source/Data/ImageData.cs create mode 100644 Source/Data/ImagePatch.cs create mode 100644 Source/Data/ImagePatchFormat.cs create mode 100644 Source/Data/TextureImage.cs create mode 100644 Source/Data/WADContainer.cs diff --git a/Source/Data/DataLocation.cs b/Source/Data/DataLocation.cs new file mode 100644 index 00000000..6c132352 --- /dev/null +++ b/Source/Data/DataLocation.cs @@ -0,0 +1,58 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal struct DataLocation + { + // Constants + public const int RESOURCE_WAD = 0; + public const int RESOURCE_DIRECTORY = 1; + + // Members + public int type; + public string location; + public bool textures; + public bool flats; + + // Constructor + public DataLocation(int type, string location, bool textures, bool flats) + { + // Initialize + this.type = type; + this.location = location; + this.textures = textures; + this.flats = flats; + } + + // This displays the struct as string + public override string ToString() + { + // Simply show location + return location; + } + } +} diff --git a/Source/Data/DataLocationList.cs b/Source/Data/DataLocationList.cs new file mode 100644 index 00000000..96ece9e6 --- /dev/null +++ b/Source/Data/DataLocationList.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using CodeImp.DoomBuilder.IO; +using System.Collections.Specialized; + +namespace CodeImp.DoomBuilder.Data +{ + internal class DataLocationList : List + { + #region ================== Constructors + + // This creates a new list + public DataLocationList() + { + } + + // This creates a list from a configuration structure + public DataLocationList(Configuration cfg, string path) + { + IDictionary resinfo, rlinfo; + DataLocation res; + + // Go for all items in the map info + resinfo = cfg.ReadSetting(path, new ListDictionary()); + foreach(DictionaryEntry rl in resinfo) + { + // Item is a structure? + if(rl.Value is IDictionary) + { + // Create resource location + rlinfo = (IDictionary)rl.Value; + res = new DataLocation(); + + // Copy information from Configuration to ResourceLocation + if(rlinfo.Contains("type") && (rlinfo["type"] is int)) res.type = (int)rlinfo["type"]; + if(rlinfo.Contains("location") && (rlinfo["location"] is string)) res.location = (string)rlinfo["location"]; + if(rlinfo.Contains("textures") && (rlinfo["textures"] is bool)) res.textures = (bool)rlinfo["textures"]; + if(rlinfo.Contains("flats") && (rlinfo["flats"] is bool)) res.flats = (bool)rlinfo["flats"]; + + // Add resource + Add(res); + } + } + } + + #endregion + + #region ================== Methods + + // This merges two lists together + public static DataLocationList Combined(DataLocationList a, DataLocationList b) + { + DataLocationList result = new DataLocationList(); + result.AddRange(a); + result.AddRange(b); + return result; + } + + // This writes the list to configuration + public void WriteToConfig(Configuration cfg, string path) + { + IDictionary resinfo, rlinfo; + + // Fill structure + resinfo = new ListDictionary(); + for(int i = 0; i < this.Count; i++) + { + // Create structure for resource + rlinfo = new ListDictionary(); + rlinfo.Add("type", this[i].type); + rlinfo.Add("location", this[i].location); + rlinfo.Add("textures", this[i].textures); + rlinfo.Add("flats", this[i].flats); + + // Add structure + resinfo.Add("resource" + i.ToString(CultureInfo.InvariantCulture), rlinfo); + } + + // Write to config + cfg.WriteSetting(path, resinfo); + } + + #endregion + } +} diff --git a/Source/Data/DataManager.cs b/Source/Data/DataManager.cs new file mode 100644 index 00000000..f1c6df60 --- /dev/null +++ b/Source/Data/DataManager.cs @@ -0,0 +1,82 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal class DataManager : IDisposable + { + #region ================== Constants + + #endregion + + #region ================== Variables + + // Disposing + private bool isdisposed = false; + + #endregion + + #region ================== Properties + + // Disposing + public bool IsDisposed { get { return isdisposed; } } + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public DataManager() + { + // Initialize + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Diposer + public void Dispose() + { + // Not already disposed? + if(!isdisposed) + { + // Clean up + + // Done + isdisposed = true; + } + } + + #endregion + + #region ================== Methods + + #endregion + } +} diff --git a/Source/Data/FileImage.cs b/Source/Data/FileImage.cs new file mode 100644 index 00000000..2169df3c --- /dev/null +++ b/Source/Data/FileImage.cs @@ -0,0 +1,77 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal class FileImage : ImageData + { + #region ================== Variables + + private string filepathname; + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public FileImage(string filepathname) + { + // Initialize + this.filepathname = filepathname; + this.name = Path.GetFileNameWithoutExtension(filepathname); + + // We have no destructor + GC.SuppressFinalize(this); + } + + #endregion + + #region ================== Methods + + // This loads the image + public override void LoadImage() + { + //Bitmap fileimg; + + // Leave when already loaded + if(this.IsLoaded) return; + + // Load file and convert to the right pixel format + //fileimg = (Bitmap)Bitmap.FromFile(filepathname); + //bitmap = fileimg.Clone(new Rectangle(new Point(0, 0), fileimg.Size), PixelFormat.Format32bppArgb); + //fileimg.Dispose(); + bitmap = (Bitmap)Bitmap.FromFile(filepathname); + + // Pass on to base + base.LoadImage(); + } + + #endregion + } +} diff --git a/Source/Data/IDataContainer.cs b/Source/Data/IDataContainer.cs new file mode 100644 index 00000000..7280cc8c --- /dev/null +++ b/Source/Data/IDataContainer.cs @@ -0,0 +1,41 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal interface IDataContainer : IDisposable + { + // Properties + bool IsDisposed { get; } + + // Methods + void Dispose(); + } +} diff --git a/Source/Data/ImageData.cs b/Source/Data/ImageData.cs new file mode 100644 index 00000000..266279fa --- /dev/null +++ b/Source/Data/ImageData.cs @@ -0,0 +1,146 @@ + +#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 SlimDX.Direct3D9; +using System.Drawing.Imaging; +using CodeImp.DoomBuilder.Rendering; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal unsafe abstract class ImageData : IDisposable + { + #region ================== Constants + + #endregion + + #region ================== Variables + + // Properties + protected string name; + + // GDI bitmap + protected Bitmap bitmap; + + // 2D rendering data + private PixelColor* pixeldata; + private uint pixeldatasize; + + // Direct3D texture + protected Texture texture; + + // Disposing + protected bool isdisposed = false; + + #endregion + + #region ================== Properties + + public string Name { get { return name; } } + public PixelColor* PixelData { get { return pixeldata; } } + public Bitmap Bitmap { get { return bitmap; } } + public Texture Texture { get { return texture; } } + public bool IsLoaded { get { return (bitmap == null); } } + public bool IsDisposed { get { return isdisposed; } } + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public ImageData() + { + // Initialize + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Diposer + public virtual void Dispose() + { + // Not already disposed? + if(!isdisposed) + { + // Clean up + if(bitmap != null) bitmap.Dispose(); + if(texture != null) texture.Dispose(); + if(pixeldata != null) General.VirtualFree((void*)pixeldata, new UIntPtr(pixeldatasize), General.MEM_RELEASE); + pixeldata = null; + GC.RemoveMemoryPressure(pixeldatasize); + + // Done + isdisposed = true; + } + } + + #endregion + + #region ================== Management + + // This loads the image resource + public virtual void LoadImage() + { + BitmapData bmpdata; + + // Check if loading worked + if(bitmap != null) + { + /* + // Check if loaded in correct pixel format + if(bitmap.PixelFormat != PixelFormat.Format32bppArgb) + { + // Cannot work with pixel formats any other than A8R8G8B8 + throw new Exception("Image in unsupported pixel format"); + } + */ + + // 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); + 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); + GC.AddMemoryPressure(pixeldatasize); + } + } + + // This creates the Direct3D texture + public void CreateTexture() + { + // TODO: Write to memory stream and read with Texture.FromStream + } + + // This destroys the Direct3D texture + public void ReleaseTexture() + { + // Trash it + if(texture != null) texture.Dispose(); + texture = null; + } + + #endregion + } +} diff --git a/Source/Data/ImagePatch.cs b/Source/Data/ImagePatch.cs new file mode 100644 index 00000000..5848382c --- /dev/null +++ b/Source/Data/ImagePatch.cs @@ -0,0 +1,64 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal class ImagePatch + { + #region ================== Variables + + private int index; + private Point position; + private Size size; + private IDataContainer source; + private ImagePatchFormat format; + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public ImagePatch() + { + // Initialize + + } + + #endregion + + #region ================== Methods + + #endregion + } +} diff --git a/Source/Data/ImagePatchFormat.cs b/Source/Data/ImagePatchFormat.cs new file mode 100644 index 00000000..4c55c4f2 --- /dev/null +++ b/Source/Data/ImagePatchFormat.cs @@ -0,0 +1,41 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal enum ImagePatchFormat : int + { + Unknown = 0, // Not determined yet + Invalid = 1, // Considered invalid + DoomImage = 2, // Doom Image format (column list rendered data) + DoomFlat = 3, // Doom Flat format (raw 8-bit pixel data) + PNG = 4, // Portable Network Graphic + Bitmap_P8 = 5, // Bitmap 8-bit Paletted + Bitmap_B5G6R5 = 6, // Bitmap 16-bit + Bitmap_B8G8R8 = 7, // Bitmap 24-bit + Bitmap_A8B8G8R8 = 8, // Bitmap 32-bit + } +} diff --git a/Source/Data/TextureImage.cs b/Source/Data/TextureImage.cs new file mode 100644 index 00000000..2bc51b8a --- /dev/null +++ b/Source/Data/TextureImage.cs @@ -0,0 +1,85 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal class TextureImage : ImageData + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public TextureImage() + { + // Initialize + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Diposer + public override void Dispose() + { + // Not already disposed? + if(!isdisposed) + { + // Clean up + + // Done + base.Dispose(); + } + } + + #endregion + + #region ================== Methods + + // This loads the image + public override void LoadImage() + { + // Leave when already loaded + if(this.IsLoaded) return; + + + + // Pass on to base + base.LoadImage(); + } + + #endregion + } +} diff --git a/Source/Data/WADContainer.cs b/Source/Data/WADContainer.cs new file mode 100644 index 00000000..64496471 --- /dev/null +++ b/Source/Data/WADContainer.cs @@ -0,0 +1,101 @@ + +#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; + +#endregion + +namespace CodeImp.DoomBuilder.Data +{ + internal class WADContainer : IDataContainer + { + #region ================== Constants + + #endregion + + #region ================== Variables + + // Source + private WAD file; + private bool managefile; + + // Disposing + private bool isdisposed = false; + + #endregion + + #region ================== Properties + + // Disposing + public bool IsDisposed { get { return isdisposed; } } + + #endregion + + #region ================== Constructor / Disposer + + // Constructor + public WADContainer(string filename) + { + // Initialize + file = new WAD(filename, true); + managefile = true; + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Constructor + public WADContainer(WAD wadfile) + { + // Initialize + file = wadfile; + managefile = false; + + // We have no destructor + GC.SuppressFinalize(this); + } + + // Diposer + public void Dispose() + { + // Not already disposed? + if(!isdisposed) + { + // Clean up + if(managefile) file.Dispose(); + + // Done + isdisposed = true; + } + } + + #endregion + + #region ================== Methods + + #endregion + } +}