added logging and classes for data reading

This commit is contained in:
codeimp 2007-10-04 18:16:05 +00:00
parent 319be16c03
commit 418ec9033b
18 changed files with 485 additions and 83 deletions

View file

@ -46,6 +46,12 @@
<ItemGroup>
<Compile Include="Controls\ActionAttribute.cs" />
<Compile Include="Controls\KeyControl.cs" />
<Compile Include="Data\DirectoryReader.cs" />
<Compile Include="Data\FileImage.cs" />
<Compile Include="Data\FlatImage.cs" />
<Compile Include="Data\Playpal.cs" />
<Compile Include="Data\SpriteImage.cs" />
<Compile Include="Data\TextureImage.cs" />
<Compile Include="Editing\EditMode.cs" />
<Compile Include="Editing\FrozenOverviewMode.cs" />
<Compile Include="Editing\ViewClassicMode.cs" />
@ -60,12 +66,12 @@
<Compile Include="Geometry\Line2D.cs" />
<Compile Include="Geometry\Vector2D.cs" />
<Compile Include="Geometry\Vector3D.cs" />
<Compile Include="Data\ImagePatch.cs" />
<Compile Include="Data\ImagePatchFormat.cs" />
<Compile Include="Data\IDataContainer.cs" />
<Compile Include="Data\TexturePatch.cs" />
<Compile Include="Data\TexturePatchFormat.cs" />
<Compile Include="Data\IDataReader.cs" />
<Compile Include="Data\DataLocationList.cs" />
<Compile Include="Data\DataManager.cs" />
<Compile Include="Data\WADContainer.cs" />
<Compile Include="Data\WADReader.cs" />
<Compile Include="Interface\AboutForm.cs">
<SubType>Form</SubType>
</Compile>
@ -136,7 +142,6 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Rendering\D3DGraphics.cs" />
<Compile Include="Data\FileImage.cs" />
<Compile Include="Data\ImageData.cs" />
<Compile Include="Rendering\IResource.cs" />
<Compile Include="Rendering\PixelColor.cs" />
@ -144,7 +149,6 @@
<Compile Include="Rendering\Renderer.cs" />
<Compile Include="Rendering\Renderer2D.cs" />
<Compile Include="Rendering\Renderer3D.cs" />
<Compile Include="Data\TextureImage.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="SlimDX, Version=1.0.2813.30005, Culture=neutral, PublicKeyToken=b1b0c32fd1ffe4f9, processorArchitecture=x86" />

View file

@ -70,6 +70,11 @@ namespace CodeImp.DoomBuilder.Controls
MethodInfo[] methods;
ActionAttribute[] attrs;
ActionDelegate del;
if(obj == null)
General.WriteLogLine("Binding static action methods for class " + type.Name + "...");
else
General.WriteLogLine("Binding action methods for " + type.Name + " object...");
// Go for all methods on obj
methods = type.GetMethods();
@ -111,6 +116,11 @@ namespace CodeImp.DoomBuilder.Controls
ActionAttribute[] attrs;
ActionDelegate del;
if(obj == null)
General.WriteLogLine("Unbinding static action methods for class " + type.Name + "...");
else
General.WriteLogLine("Unbinding action methods for " + type.Name + " object...");
// Go for all methods on obj
methods = type.GetMethods();
foreach(MethodInfo m in methods)

View file

@ -59,6 +59,7 @@ namespace CodeImp.DoomBuilder.Controls
public ActionManager()
{
// Initialize
General.WriteLogLine("Starting action manager...");
actions = new Dictionary<string, Action>();
// Load all actions

View file

@ -37,6 +37,9 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
// Data containers
private List<IDataReader> containers;
// Disposing
private bool isdisposed = false;
@ -55,12 +58,13 @@ namespace CodeImp.DoomBuilder.Data
public DataManager()
{
// Initialize
containers = new List<IDataReader>();
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
// Disposer
public void Dispose()
{
// Not already disposed?
@ -75,8 +79,52 @@ namespace CodeImp.DoomBuilder.Data
#endregion
#region ================== Methods
#region ================== Loading / Unloading
// This loads all data resources
public void Load(DataLocationList locations)
{
IDataReader c;
// Go for all locations
foreach(DataLocation dl in locations)
{
// Nothing chosen yet
c = null;
// Choose container type
switch(dl.type)
{
// WAD file container
case DataLocation.RESOURCE_WAD:
c = new WADReader(dl);
break;
// Directory container
case DataLocation.RESOURCE_DIRECTORY:
c = new DirectoryReader(dl);
break;
}
// Container type chosen?
if(c != null)
{
// TODO: Let the container read stuff
// Keep container reference
containers.Add(c);
}
}
}
// This unloads all data
public void Unload()
{
// Dispose containers
foreach(IDataReader c in containers) c.Dispose();
containers.Clear();
}
#endregion
}
}

View file

@ -0,0 +1,91 @@
#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 DirectoryReader : IDataReader
{
#region ================== Constants
#endregion
#region ================== Variables
// Source
private string path;
private bool readtextures;
private bool readflats;
// Disposing
private bool isdisposed = false;
#endregion
#region ================== Properties
// Disposing
public bool IsDisposed { get { return isdisposed; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public DirectoryReader(DataLocation dl)
{
// Initialize
this.path = dl.location;
this.readtextures = dl.textures;
this.readflats = dl.flats;
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
// Done
isdisposed = true;
}
}
#endregion
#region ================== Textures
#endregion
}
}

View file

@ -44,7 +44,7 @@ namespace CodeImp.DoomBuilder.Data
{
// Initialize
this.filepathname = filepathname;
this.name = Path.GetFileNameWithoutExtension(filepathname);
SetName(Path.GetFileNameWithoutExtension(filepathname));
// We have no destructor
GC.SuppressFinalize(this);
@ -57,15 +57,10 @@ namespace CodeImp.DoomBuilder.Data
// 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();
// Load file
bitmap = (Bitmap)Bitmap.FromFile(filepathname);
// Pass on to base

71
Source/Data/FlatImage.cs Normal file
View file

@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace CodeImp.DoomBuilder.Data
{
internal class FlatImage : ImageData
{
#region ================== Constants
#endregion
#region ================== Variables
private IDataReader source;
private int lumpindex;
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor
public FlatImage(string name, IDataReader source, int lumpindex)
{
// Initialize
this.source = source;
this.lumpindex = lumpindex;
SetName(name);
// 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
}
}

View file

@ -25,12 +25,13 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal interface IDataContainer : IDisposable
internal unsafe interface IDataReader : IDisposable
{
// Properties
bool IsDisposed { get; }

View file

@ -30,16 +30,17 @@ using CodeImp.DoomBuilder.Rendering;
namespace CodeImp.DoomBuilder.Data
{
internal unsafe abstract class ImageData : IDisposable
internal abstract unsafe class ImageData : IDisposable
{
#region ================== Constants
#endregion
#region ================== Variables
// Properties
protected string name;
private string name;
private long longname;
// GDI bitmap
protected Bitmap bitmap;
@ -49,7 +50,7 @@ namespace CodeImp.DoomBuilder.Data
private uint pixeldatasize;
// Direct3D texture
protected Texture texture;
private Texture texture;
// Disposing
protected bool isdisposed = false;
@ -72,13 +73,11 @@ namespace CodeImp.DoomBuilder.Data
// Constructor
public ImageData()
{
// Initialize
// We have no destructor
GC.SuppressFinalize(this);
}
// Diposer
// Disposer
public virtual void Dispose()
{
// Not already disposed?
@ -100,7 +99,14 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Management
// This loads the image resource
// This sets the name
protected void SetName(string name)
{
this.name = name;
this.longname = General.GetTextureLongName(name);
}
// This requests loading the image
public virtual void LoadImage()
{
BitmapData bmpdata;
@ -108,15 +114,6 @@ namespace CodeImp.DoomBuilder.Data
// 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);

45
Source/Data/Playpal.cs Normal file
View file

@ -0,0 +1,45 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.Rendering;
namespace CodeImp.DoomBuilder.Data
{
internal class Playpal
{
#region ================== Constants
#endregion
#region ================== Variables
private PixelColor[] colors;
#endregion
#region ================== Properties
public PixelColor this[int a] { get { return colors[a]; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public Playpal(IDataReader source, int lumpindex)
{
// Initialize
// We have no destructor
GC.SuppressFinalize(this);
}
#endregion
#region ================== Methods
#endregion
}
}

View file

@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace CodeImp.DoomBuilder.Data
{
internal class SpriteImage : ImageData
{
#region ================== Constants
#endregion
#region ================== Variables
private IDataReader source;
private int lumpindex;
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor
public SpriteImage(string name, IDataReader source, int lumpindex)
{
// Initialize
this.source = source;
this.lumpindex = lumpindex;
SetName(name);
// 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
}
}

View file

@ -34,6 +34,8 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Variables
private List<TexturePatch> patches;
#endregion
#region ================== Properties
@ -43,10 +45,12 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Constructor / Disposer
// Constructor
public TextureImage()
public TextureImage(string name)
{
// Initialize
this.patches = new List<TexturePatch>();
SetName(name);
// We have no destructor
GC.SuppressFinalize(this);
}
@ -68,6 +72,13 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Methods
// This adds a patch to the texture
public void AddPatch(TexturePatch patch)
{
// Add it
patches.Add(patch);
}
// This loads the image
public override void LoadImage()
{

View file

@ -30,35 +30,11 @@ using CodeImp.DoomBuilder.IO;
namespace CodeImp.DoomBuilder.Data
{
internal class ImagePatch
internal struct TexturePatch
{
#region ================== Variables
private int index;
private IDataReader source;
private int lumpindex;
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
}
}

View file

@ -26,7 +26,7 @@ using System.Text;
namespace CodeImp.DoomBuilder.Data
{
internal enum ImagePatchFormat : int
internal enum TexturePatchFormat : int
{
Unknown = 0, // Not determined yet
Invalid = 1, // Considered invalid

View file

@ -30,7 +30,7 @@ using CodeImp.DoomBuilder.IO;
namespace CodeImp.DoomBuilder.Data
{
internal class WADContainer : IDataContainer
internal class WADReader : IDataReader
{
#region ================== Constants
@ -57,10 +57,10 @@ namespace CodeImp.DoomBuilder.Data
#region ================== Constructor / Disposer
// Constructor
public WADContainer(string filename)
public WADReader(DataLocation dl)
{
// Initialize
file = new WAD(filename, true);
file = new WAD(dl.location, true);
managefile = true;
// We have no destructor
@ -68,7 +68,7 @@ namespace CodeImp.DoomBuilder.Data
}
// Constructor
public WADContainer(WAD wadfile)
public WADReader(WAD wadfile)
{
// Initialize
file = wadfile;

View file

@ -30,6 +30,7 @@ using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Geometry;
using System.Runtime.InteropServices;
using CodeImp.DoomBuilder.Controls;
using System.Diagnostics;
#endregion
@ -81,6 +82,7 @@ namespace CodeImp.DoomBuilder
// Files and Folders
private const string SETTINGS_CONFIG_FILE = "Builder.cfg";
private const string LOG_FILE = "Builder.log";
private const string GAME_CONFIGS_DIR = "Configurations";
private const string COMPILERS_DIR = "Compilers";
@ -90,6 +92,7 @@ namespace CodeImp.DoomBuilder
// Files and Folders
private static string apppath;
private static string logfile;
private static string temppath;
private static string configspath;
private static string compilerspath;
@ -148,6 +151,7 @@ namespace CodeImp.DoomBuilder
public static Configuration LoadGameConfiguration(string filename)
{
Configuration cfg;
string message;
// Make the full filepathname
string filepathname = Path.Combine(configspath, filename);
@ -162,18 +166,22 @@ namespace CodeImp.DoomBuilder
if(cfg.ErrorResult != 0)
{
// Error in configuration
MessageBox.Show(mainwindow, "Unable to load the game configuration file \"" + filename + "\".\n" +
"Error near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription,
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
message = "Unable to load the game configuration file \"" + filename + "\".\n" +
"Error near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription;
General.WriteLogLine(message);
MessageBox.Show(mainwindow, message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
// Check if this is a Doom Builder 2 config
else if(cfg.ReadSetting("type", "") != "Doom Builder 2 Game Configuration")
{
// Old configuration
MessageBox.Show(mainwindow, "Unable to load the game configuration file \"" + filename + "\".\n" +
"This configuration is not a Doom Builder 2 game configuration.",
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
message = "Unable to load the game configuration file \"" + filename + "\".\n" +
"This configuration is not a Doom Builder 2 game configuration.";
General.WriteLogLine(message);
MessageBox.Show(mainwindow, message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
else
@ -185,8 +193,10 @@ namespace CodeImp.DoomBuilder
catch(Exception)
{
// Unable to load configuration
MessageBox.Show(mainwindow, "Unable to load the game configuration file \"" + filename + "\".",
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
message = "Unable to load the game configuration file \"" + filename + "\".";
General.WriteLogLine(message);
MessageBox.Show(mainwindow, message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
@ -230,6 +240,7 @@ namespace CodeImp.DoomBuilder
{
Configuration cfg;
string[] filenames;
string message;
// Display status
mainwindow.DisplayStatus("Loading nodebuilder configurations...");
@ -250,9 +261,11 @@ namespace CodeImp.DoomBuilder
if(cfg.ErrorResult != 0)
{
// Error in configuration
MessageBox.Show(mainwindow, "Unable to load the nodebuilder configuration file \"" + filepath + "\".\n" +
"Error near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription,
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
message = "Unable to load the nodebuilder configuration file \"" + filepath + "\".\n" +
"Error near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription;
General.WriteLogLine(message);
MessageBox.Show(mainwindow, message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
@ -263,8 +276,10 @@ namespace CodeImp.DoomBuilder
catch(Exception)
{
// Unable to load configuration
MessageBox.Show(mainwindow, "Unable to load the nodebuilder configuration file \"" + filepath + "\".",
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
message = "Unable to load the nodebuilder configuration file \"" + filepath + "\".";
General.WriteLogLine(message);
MessageBox.Show(mainwindow, message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@ -281,20 +296,32 @@ namespace CodeImp.DoomBuilder
public static void Main(string[] args)
{
Uri localpath;
Version thisversion;
// Get a reference to this assembly
thisasm = Assembly.GetExecutingAssembly();
thisversion = thisasm.GetName().Version;
// Find application path
localpath = new Uri(Path.GetDirectoryName(thisasm.GetName().CodeBase));
apppath = Uri.UnescapeDataString(localpath.AbsolutePath);
// Setup directories
logfile = Path.Combine(apppath, LOG_FILE);
temppath = Path.GetTempPath();
configspath = Path.Combine(apppath, GAME_CONFIGS_DIR);
compilerspath = Path.Combine(apppath, COMPILERS_DIR);
// Remove the previous log file and start logging
File.Delete(logfile);
General.WriteLogLine("Doom Builder " + thisversion.Major + "." + thisversion.Minor + " startup");
General.WriteLogLine("Application path: " + apppath);
General.WriteLogLine("Temporary path: " + temppath);
General.WriteLogLine("Configurations path: " + configspath);
General.WriteLogLine("Compilers path: " + compilerspath);
// Load configuration
General.WriteLogLine("Loading program configuration...");
if(!File.Exists(Path.Combine(apppath, SETTINGS_CONFIG_FILE))) throw (new FileNotFoundException("Unable to find the program configuration \"" + SETTINGS_CONFIG_FILE + "\"."));
settings = new Configuration(Path.Combine(apppath, SETTINGS_CONFIG_FILE), true);
@ -305,20 +332,25 @@ namespace CodeImp.DoomBuilder
ActionAttribute.BindMethods(typeof(General));
// Create main window
General.WriteLogLine("Loading main interface window...");
mainwindow = new MainForm();
mainwindow.UpdateMenus();
// Show main window
General.WriteLogLine("Showing main interface window...");
mainwindow.Show();
mainwindow.Update();
// Load game configurations
General.WriteLogLine("Loading game configurations...");
FindGameConfigurations();
// Load nodebuilder configurations
General.WriteLogLine("Loading nodebuilder configurations...");
FindNodebuilderConfigurations();
// Run application from the main window
General.WriteLogLine("Startup done");
mainwindow.DisplayReady();
Application.Run(mainwindow);
}
@ -330,6 +362,8 @@ namespace CodeImp.DoomBuilder
// This terminates the program
public static void Terminate()
{
General.WriteLogLine("Termination requested");
// Unbind static methods from actions
ActionAttribute.UnbindMethods(typeof(General));
@ -344,9 +378,11 @@ namespace CodeImp.DoomBuilder
foreach(ConfigurationInfo ci in configs) ci.SaveSettings();
// Save settings configuration
General.WriteLogLine("Saving program configuration...");
settings.SaveConfiguration(Path.Combine(apppath, SETTINGS_CONFIG_FILE));
// Application ends here and now
General.WriteLogLine("Termination done");
Application.Exit();
}
@ -511,7 +547,31 @@ namespace CodeImp.DoomBuilder
}
#endregion
#region ================== Debug
// This outputs log information
public static void WriteLogLine(string line)
{
// Output to console
Console.WriteLine(line);
// Write to log file
File.AppendAllText(logfile, line + Environment.NewLine);
}
// This outputs log information
public static void WriteLog(string text)
{
// Output to console
Console.Write(text);
// Write to log file
File.AppendAllText(logfile, text);
}
#endregion
#region ================== Tools
// This returns a unique temp filename
@ -536,6 +596,22 @@ 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

@ -148,6 +148,11 @@ namespace CodeImp.DoomBuilder.Interface
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
int windowstate;
General.WriteLogLine("Closing main interface window...");
// Unbind methods
ActionAttribute.UnbindMethods(this);
// Determine window state to save
if(this.WindowState != FormWindowState.Minimized)

View file

@ -30,4 +30,4 @@ using System.Runtime.InteropServices;
// Revision
//
[assembly: AssemblyVersion("2.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("2.0")]