diff --git a/Source/Core/Actions/ActionManager.cs b/Source/Core/Actions/ActionManager.cs index ee88257..fc52935 100644 --- a/Source/Core/Actions/ActionManager.cs +++ b/Source/Core/Actions/ActionManager.cs @@ -172,7 +172,6 @@ namespace CodeImp.DoomBuilder.Actions // Done with the resource actionsreader.Dispose(); - actionsdata.Dispose(); break; //mxd. Usually we have a single "Actions.cfg", right? } } diff --git a/Source/Core/Actions/HintsManager.cs b/Source/Core/Actions/HintsManager.cs index 5c4a7fc..c9f5c09 100644 --- a/Source/Core/Actions/HintsManager.cs +++ b/Source/Core/Actions/HintsManager.cs @@ -63,12 +63,11 @@ namespace CodeImp.DoomBuilder.Actions List lines = new List(2); // Get a stream from the resource - using(Stream data = asm.GetManifestResourceStream(rn)) + Stream data = asm.GetManifestResourceStream(rn); + if(data == null) return; + using(StreamReader reader = new StreamReader(data, Encoding.ASCII)) { - using(StreamReader reader = new StreamReader(data, Encoding.ASCII)) - { - while(!reader.EndOfStream) lines.Add(reader.ReadLine()); - } + while(!reader.EndOfStream) lines.Add(reader.ReadLine()); } Dictionary> group = new Dictionary>(StringComparer.Ordinal); @@ -119,7 +118,7 @@ namespace CodeImp.DoomBuilder.Actions //add the last class hints.Add(asmname + classname, ProcessHints(group)); - break; + return; } } } diff --git a/Source/Core/Config/ArgumentInfo.cs b/Source/Core/Config/ArgumentInfo.cs index 7187af1..593a032 100644 --- a/Source/Core/Config/ArgumentInfo.cs +++ b/Source/Core/Config/ArgumentInfo.cs @@ -75,7 +75,7 @@ namespace CodeImp.DoomBuilder.Config if(argdic["enum"] is IDictionary) { // Create anonymous enum - this.enumlist = new EnumList(argdic["enum"] as IDictionary); + this.enumlist = new EnumList((IDictionary)argdic["enum"]); } else { diff --git a/Source/Core/Config/GameConfiguration.cs b/Source/Core/Config/GameConfiguration.cs index 3727e10..2e218e2 100644 --- a/Source/Core/Config/GameConfiguration.cs +++ b/Source/Core/Config/GameConfiguration.cs @@ -793,7 +793,7 @@ namespace CodeImp.DoomBuilder.Config if(de.Value is IDictionary) { // Add option - geneffectoptions.Add(new GeneralizedOption("gen_sectortypes", "", de.Key.ToString(), de.Value as IDictionary)); + geneffectoptions.Add(new GeneralizedOption("gen_sectortypes", "", de.Key.ToString(), (IDictionary)de.Value)); } else { diff --git a/Source/Core/Controls/DockersTabsControl.cs b/Source/Core/Controls/DockersTabsControl.cs index 608b155..929bc03 100644 --- a/Source/Core/Controls/DockersTabsControl.cs +++ b/Source/Core/Controls/DockersTabsControl.cs @@ -194,25 +194,21 @@ namespace CodeImp.DoomBuilder.Controls // Tabs don't process keys protected override void OnKeyDown(KeyEventArgs ke) { - if(this.Parent is DockersControl) - { - // Only absorb the key press when no focused on an input control, otherwise - // the input controls may not receive certain keys such as delete and arrow keys - DockersControl docker = (this.Parent as DockersControl); - if(!docker.IsFocused) ke.Handled = true; - } + DockersControl docker = this.Parent as DockersControl; + + // Only absorb the key press when no focused on an input control, otherwise + // the input controls may not receive certain keys such as delete and arrow keys + if(docker != null && !docker.IsFocused) ke.Handled = true; } - + // Tabs don't process keys protected override void OnKeyUp(KeyEventArgs e) { - if(this.Parent is DockersControl) - { - // Only absorb the key press when no focused on an input control, otherwise - // the input controls may not receive certain keys such as delete and arrow keys - DockersControl docker = (this.Parent as DockersControl); - if(!docker.IsFocused) e.Handled = true; - } + DockersControl docker = this.Parent as DockersControl; + + // Only absorb the key press when no focused on an input control, otherwise + // the input controls may not receive certain keys such as delete and arrow keys + if(docker != null && !docker.IsFocused) e.Handled = true; } #endregion diff --git a/Source/Core/Controls/FieldsEditorControl.cs b/Source/Core/Controls/FieldsEditorControl.cs index dc095c2..19980b2 100644 --- a/Source/Core/Controls/FieldsEditorControl.cs +++ b/Source/Core/Controls/FieldsEditorControl.cs @@ -867,10 +867,10 @@ namespace CodeImp.DoomBuilder.Controls private void ApplyEnums(bool hide) { // Enums combobox shown? - if((enumscombo.Visible) && (enumscombo.Tag is FieldsEditorRow)) + if(enumscombo.Visible && (enumscombo.Tag is FieldsEditorRow)) { // Get the row - FieldsEditorRow frow = (enumscombo.Tag as FieldsEditorRow); + FieldsEditorRow frow = (FieldsEditorRow)enumscombo.Tag; // Take the selected value and apply it ApplyValue(frow, enumscombo.Text); diff --git a/Source/Core/Controls/ScriptDocumentTab.cs b/Source/Core/Controls/ScriptDocumentTab.cs index ba1f0a4..8bced73 100644 --- a/Source/Core/Controls/ScriptDocumentTab.cs +++ b/Source/Core/Controls/ScriptDocumentTab.cs @@ -490,13 +490,13 @@ namespace CodeImp.DoomBuilder.Controls editor.GrabFocus(); } - //mxd - private void functionbar_SelectedIndexChanged(object sender, EventArgs e) - { - if (!preventchanges && editor.FunctionBar.SelectedItem is ScriptItem) - { - ScriptItem si = editor.FunctionBar.SelectedItem as ScriptItem; - editor.EnsureLineVisible(editor.LineFromPosition(si.CursorPosition)); + //mxd + private void functionbar_SelectedIndexChanged(object sender, EventArgs e) + { + if(!preventchanges && editor.FunctionBar.SelectedItem is ScriptItem) + { + ScriptItem si = (ScriptItem)editor.FunctionBar.SelectedItem; + editor.EnsureLineVisible(editor.LineFromPosition(si.CursorPosition)); editor.SelectionStart = si.CursorPosition; editor.SelectionEnd = si.CursorPosition; diff --git a/Source/Core/Controls/ScriptEditorControl.cs b/Source/Core/Controls/ScriptEditorControl.cs index 8c18721..3e1573b 100644 --- a/Source/Core/Controls/ScriptEditorControl.cs +++ b/Source/Core/Controls/ScriptEditorControl.cs @@ -337,7 +337,6 @@ namespace CodeImp.DoomBuilder.Controls // Done with the resource lexersreader.Dispose(); - lexersdata.Dispose(); } //mxd. We are done here diff --git a/Source/Core/Data/DataReader.cs b/Source/Core/Data/DataReader.cs index 60dc482..6691e7d 100644 --- a/Source/Core/Data/DataReader.cs +++ b/Source/Core/Data/DataReader.cs @@ -16,6 +16,7 @@ #region ================== Namespaces +using System; using System.Collections.Generic; using System.IO; using CodeImp.DoomBuilder.Config; @@ -25,7 +26,7 @@ using CodeImp.DoomBuilder.GZBuilder.Data; namespace CodeImp.DoomBuilder.Data { - internal abstract class DataReader + internal abstract class DataReader : IDisposable { #region ================== Constants diff --git a/Source/Core/Data/PreviewManager.cs b/Source/Core/Data/PreviewManager.cs index 47c5e16..f879555 100644 --- a/Source/Core/Data/PreviewManager.cs +++ b/Source/Core/Data/PreviewManager.cs @@ -41,15 +41,16 @@ namespace CodeImp.DoomBuilder.Data #region ================== Variables // Dimensions of a single preview image - private int maxpreviewwidth = 64; - private int maxpreviewheight = 64; + private readonly int maxpreviewwidth; + private readonly int maxpreviewheight; // Images private List images; // Processing private Queue imageque; - + private static object syncroot = new object(); //mxd + // Disposing private bool isdisposed; @@ -196,7 +197,7 @@ namespace CodeImp.DoomBuilder.Data targetpos.Y += (maxpreviewheight - image.Height) >> 1; // Draw from atlas to target - lock(image) + lock(syncroot) { target.DrawImageUnscaled(image, targetpos.X, targetpos.Y); } @@ -211,7 +212,7 @@ namespace CodeImp.DoomBuilder.Data lock(images) { image = images[previewindex]; } // Make a copy - lock(image) + lock(syncroot) { return new Bitmap(image); } diff --git a/Source/Core/Editing/ClassicMode.cs b/Source/Core/Editing/ClassicMode.cs index d5b55b1..ee8c216 100644 --- a/Source/Core/Editing/ClassicMode.cs +++ b/Source/Core/Editing/ClassicMode.cs @@ -119,10 +119,9 @@ namespace CodeImp.DoomBuilder.Editing this.renderer2d = (Renderer2D)General.Map.Renderer2D; // If the current mode is a ClassicMode, copy mouse properties - if(General.Editing.Mode is ClassicMode) + ClassicMode oldmode = General.Editing.Mode as ClassicMode; + if(oldmode != null) { - ClassicMode oldmode = General.Editing.Mode as ClassicMode; - // Copy mouse properties mousepos = oldmode.mousepos; mousemappos = oldmode.mousemappos; diff --git a/Source/Core/Editing/GridSetup.cs b/Source/Core/Editing/GridSetup.cs index fd0eb74..3b1ce05 100644 --- a/Source/Core/Editing/GridSetup.cs +++ b/Source/Core/Editing/GridSetup.cs @@ -30,7 +30,7 @@ using CodeImp.DoomBuilder.Geometry; namespace CodeImp.DoomBuilder.Editing { - public class GridSetup + public class GridSetup : IDisposable { #region ================== Constants @@ -95,12 +95,12 @@ namespace CodeImp.DoomBuilder.Editing } // Disposer - internal void Dispose() + public void Dispose() { if(!isdisposed) { // Dispose image if needed - if(backimage is FileImage) (backimage as FileImage).Dispose(); + if(backimage is FileImage) backimage.Dispose(); // Clean up backimage = null; @@ -208,7 +208,7 @@ namespace CodeImp.DoomBuilder.Editing internal void LinkBackground() { // Dispose image if needed - if(backimage is FileImage) (backimage as FileImage).Dispose(); + if(backimage is FileImage) backimage.Dispose(); // Where to load background from? switch(backsource) diff --git a/Source/Core/Editing/UndoManager.cs b/Source/Core/Editing/UndoManager.cs index aab46cc..be9ab15 100644 --- a/Source/Core/Editing/UndoManager.cs +++ b/Source/Core/Editing/UndoManager.cs @@ -202,20 +202,13 @@ namespace CodeImp.DoomBuilder.Editing ClearRedos(); General.WriteLogLine("All undo and redo levels cleared."); - //mxd - if (ss != null) - { - ss.Dispose(); - ss = null; - } - if (stream != null) - { - stream.Dispose(); - stream = null; - } - - // Done - isdisposed = true; + //mxd + if(snapshot != null) { snapshot.Dispose(); snapshot = null; } + if(ss != null) { ss.Dispose(); ss = null; } + if(stream != null) { stream.Dispose(); stream = null; } + + // Done + isdisposed = true; } } diff --git a/Source/Core/GZBuilder/Windows/TagStatisticsForm.cs b/Source/Core/GZBuilder/Windows/TagStatisticsForm.cs index 6a98084..c25256b 100644 --- a/Source/Core/GZBuilder/Windows/TagStatisticsForm.cs +++ b/Source/Core/GZBuilder/Windows/TagStatisticsForm.cs @@ -193,11 +193,8 @@ namespace CodeImp.DoomBuilder.GZBuilder.Windows area.Inflate(100f, 100f); // Zoom to area - if(General.Editing.Mode is ClassicMode) - { - ClassicMode editmode = (General.Editing.Mode as ClassicMode); - editmode.CenterOnArea(area, 0.6f); - } + ClassicMode mode = General.Editing.Mode as ClassicMode; + if(mode != null) mode.CenterOnArea(area, 0.6f); } #endregion diff --git a/Source/Core/GZBuilder/Windows/ThingStatisticsForm.cs b/Source/Core/GZBuilder/Windows/ThingStatisticsForm.cs index 22eebf0..ed7b1c3 100644 --- a/Source/Core/GZBuilder/Windows/ThingStatisticsForm.cs +++ b/Source/Core/GZBuilder/Windows/ThingStatisticsForm.cs @@ -111,11 +111,8 @@ namespace CodeImp.DoomBuilder.GZBuilder.Windows area.Inflate(100f, 100f); // Zoom to area - if(General.Editing.Mode is ClassicMode) - { - ClassicMode editmode = (General.Editing.Mode as ClassicMode); - editmode.CenterOnArea(area, 0.6f); - } + ClassicMode mode = General.Editing.Mode as ClassicMode; + if(mode != null) mode.CenterOnArea(area, 0.6f); } private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) diff --git a/Source/Core/GZBuilder/md3/ModelReader.cs b/Source/Core/GZBuilder/md3/ModelReader.cs index bc831fe..a015e35 100644 --- a/Source/Core/GZBuilder/md3/ModelReader.cs +++ b/Source/Core/GZBuilder/md3/ModelReader.cs @@ -71,7 +71,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 //done ms.Close(); - ms.Dispose(); break; } } @@ -126,7 +125,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 } ms.Close(); - ms.Dispose(); //got errors? if(!String.IsNullOrEmpty(result.Errors)) @@ -912,7 +910,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 Bitmap bitmap = fir.ReadAsBitmap(ms); ms.Close(); - ms.Dispose(); if(bitmap != null) { @@ -931,7 +928,6 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 texture = Texture.FromStream(device, ms); ms.Close(); - ms.Dispose(); } return texture; diff --git a/Source/Core/General/General.cs b/Source/Core/General/General.cs index 8871af4..91e04a5 100644 --- a/Source/Core/General/General.cs +++ b/Source/Core/General/General.cs @@ -68,22 +68,22 @@ namespace CodeImp.DoomBuilder [DllImport("user32.dll", SetLastError = true)] internal static extern bool MessageBeep(MessageBeepType type); - [DllImport("kernel32.dll")] - internal extern static IntPtr LoadLibrary(string filename); + //[DllImport("kernel32.dll")] + //internal extern static IntPtr LoadLibrary(string filename); - [DllImport("kernel32.dll")] - internal extern static bool FreeLibrary(IntPtr moduleptr); + //[DllImport("kernel32.dll")] + //internal extern static bool FreeLibrary(IntPtr moduleptr); - [DllImport("user32.dll")] - internal static extern IntPtr CreateWindowEx(uint exstyle, string classname, string windowname, uint style, + //[DllImport("user32.dll")] + /*internal static extern IntPtr CreateWindowEx(uint exstyle, string classname, string windowname, uint style, int x, int y, int width, int height, IntPtr parentptr, int menu, - IntPtr instanceptr, string param); + IntPtr instanceptr, string param);*/ - [DllImport("user32.dll")] - internal static extern bool DestroyWindow(IntPtr windowptr); + //[DllImport("user32.dll")] + //internal static extern bool DestroyWindow(IntPtr windowptr); - [DllImport("user32.dll")] - internal static extern int SetWindowPos(IntPtr windowptr, int insertafterptr, int x, int y, int cx, int cy, int flags); + //[DllImport("user32.dll")] + //internal static extern int SetWindowPos(IntPtr windowptr, int insertafterptr, int x, int y, int cx, int cy, int flags); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string longpath, [MarshalAs(UnmanagedType.LPTStr)]StringBuilder shortpath, uint buffersize); @@ -1349,9 +1349,9 @@ namespace CodeImp.DoomBuilder mainwindow.AddHintsDocker(); //mxd //mxd. Center map in screen or on stored coordinates. Done here to avoid the view jerking around when updating the interface. - if(Editing.Mode is ClassicMode) + ClassicMode mode = Editing.Mode as ClassicMode; + if(mode != null) { - ClassicMode mode = Editing.Mode as ClassicMode; if(options != null && options.ViewPosition.IsFinite() && !float.IsNaN(options.ViewScale)) mode.CenterOnCoordinates(options.ViewPosition, options.ViewScale); else diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index 082136a..640fda1 100644 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -536,9 +536,9 @@ namespace CodeImp.DoomBuilder options.ReadSelectionGroups(); // Center map in screen or on stored coordinates - if(General.Editing.Mode is ClassicMode) + ClassicMode mode = General.Editing.Mode as ClassicMode; + if(mode != null) { - ClassicMode mode = General.Editing.Mode as ClassicMode; mode.OnRedoEnd(); if(options.ViewPosition.IsFinite() && !float.IsNaN(options.ViewScale)) diff --git a/Source/Core/General/UpdateChecker.cs b/Source/Core/General/UpdateChecker.cs index 1bd87f6..6b75255 100644 --- a/Source/Core/General/UpdateChecker.cs +++ b/Source/Core/General/UpdateChecker.cs @@ -66,27 +66,25 @@ namespace CodeImp.DoomBuilder // Get remote revision number int remoterev; - using(MemoryStream stream = DownloadWebFile(Path.Combine(url, "Version.txt"))) + MemoryStream stream = DownloadWebFile(Path.Combine(url, "Version.txt")); + if(stream == null) { - if(stream == null) - { - e.Result = "Update check failed: failed to retrieve remote revision info."; - e.Cancel = true; - return; - } + ShowResult("Update check failed: failed to retrieve remote revision info.\nCheck your Internet connection and try again."); + e.Cancel = true; + return; + } - string s; - using(StreamReader reader = new StreamReader(stream)) - { - s = reader.ReadToEnd(); - } + string s; + using(StreamReader reader = new StreamReader(stream)) + { + s = reader.ReadToEnd(); + } - if(!int.TryParse(s, out remoterev)) - { - e.Result = "Update check failed: failed to retrieve remote revision number."; - e.Cancel = true; - return; - } + if(!int.TryParse(s, out remoterev)) + { + ShowResult("Update check failed: failed to retrieve remote revision number."); + e.Cancel = true; + return; } if(remoterev > localrev) diff --git a/Source/Core/IO/ClipboardStreamWriter.cs b/Source/Core/IO/ClipboardStreamWriter.cs index 7c7bce2..c034e75 100644 --- a/Source/Core/IO/ClipboardStreamWriter.cs +++ b/Source/Core/IO/ClipboardStreamWriter.cs @@ -73,7 +73,6 @@ namespace CodeImp.DoomBuilder.IO // Done udmfcfgreader.Dispose(); - udmfcfg.Dispose(); break; } } diff --git a/Source/Core/IO/ClippedStream.cs b/Source/Core/IO/ClippedStream.cs index 2592cea..f974cc1 100644 --- a/Source/Core/IO/ClippedStream.cs +++ b/Source/Core/IO/ClippedStream.cs @@ -222,7 +222,6 @@ namespace CodeImp.DoomBuilder.IO { basestream = null; base.Close(); - this.Dispose(); } // This reads a single byte from the stream diff --git a/Source/Core/IO/UniversalMapSetIO.cs b/Source/Core/IO/UniversalMapSetIO.cs index 105dac5..01faeb5 100644 --- a/Source/Core/IO/UniversalMapSetIO.cs +++ b/Source/Core/IO/UniversalMapSetIO.cs @@ -90,7 +90,6 @@ namespace CodeImp.DoomBuilder.IO // Done udmfcfgreader.Dispose(); - udmfcfg.Dispose(); break; } } diff --git a/Source/Core/IO/UniversalStreamReader.cs b/Source/Core/IO/UniversalStreamReader.cs index c52666a..06298f3 100644 --- a/Source/Core/IO/UniversalStreamReader.cs +++ b/Source/Core/IO/UniversalStreamReader.cs @@ -118,7 +118,6 @@ namespace CodeImp.DoomBuilder.IO // Done udmfcfgreader.Dispose(); - udmfcfg.Dispose(); break; } } @@ -600,8 +599,8 @@ namespace CodeImp.DoomBuilder.IO // Make list foreach(UniversalEntry e in collection) { - if(!(e.Value is UniversalCollection) || (e.Key != entryname)) continue; //mxd - list.Add(e.Value as UniversalCollection); + UniversalCollection uc = e.Value as UniversalCollection; + if(uc != null && e.Key == entryname) list.Add(uc); } return list; diff --git a/Source/Core/IO/UniversalStreamWriter.cs b/Source/Core/IO/UniversalStreamWriter.cs index 947520d..60a866a 100644 --- a/Source/Core/IO/UniversalStreamWriter.cs +++ b/Source/Core/IO/UniversalStreamWriter.cs @@ -97,7 +97,6 @@ namespace CodeImp.DoomBuilder.IO // Done udmfcfgreader.Dispose(); - udmfcfg.Dispose(); break; } } diff --git a/Source/Core/IO/WAD.cs b/Source/Core/IO/WAD.cs index 62302c1..20c2aa3 100644 --- a/Source/Core/IO/WAD.cs +++ b/Source/Core/IO/WAD.cs @@ -342,9 +342,11 @@ namespace CodeImp.DoomBuilder.IO // Close the reader r.Close(); } - - // Close the file - fs.Dispose(); + else + { + // Close the file + fs.Dispose(); + } } // This flushes writing changes diff --git a/Source/Core/Map/MapOptions.cs b/Source/Core/Map/MapOptions.cs index 8553219..3e107da 100644 --- a/Source/Core/Map/MapOptions.cs +++ b/Source/Core/Map/MapOptions.cs @@ -294,16 +294,16 @@ namespace CodeImp.DoomBuilder.Map } } - //mxd. Is that really needed?.. - ~MapOptions() - { - // Clean up - this.resources = null; - this.scriptfilesettings = null; //mxd - this.scriptlumpsettings = null; //mxd - } - - #endregion + //mxd. Is that really needed?.. + /*~MapOptions() + { + // Clean up + this.resources = null; + this.scriptfilesettings = null; //mxd + this.scriptlumpsettings = null; //mxd + }*/ + + #endregion #region ================== Methods diff --git a/Source/Core/Map/MapSet.cs b/Source/Core/Map/MapSet.cs index 52b07f0..ae387ee 100644 --- a/Source/Core/Map/MapSet.cs +++ b/Source/Core/Map/MapSet.cs @@ -1438,7 +1438,7 @@ namespace CodeImp.DoomBuilder.Map string s = groupinfo["vertices"] as string; if(!string.IsNullOrEmpty(s)) { - List indices = GetIndices(groupinfo["vertices"] as string); + List indices = GetIndices(s); foreach(int index in indices) { if(index > vertices.Length) continue; @@ -1452,7 +1452,7 @@ namespace CodeImp.DoomBuilder.Map string s = groupinfo["linedefs"] as string; if(!string.IsNullOrEmpty(s)) { - List indices = GetIndices(groupinfo["linedefs"] as string); + List indices = GetIndices(s); foreach(int index in indices) { if(index > linedefs.Length) continue; @@ -1466,7 +1466,7 @@ namespace CodeImp.DoomBuilder.Map string s = groupinfo["sectors"] as string; if(!string.IsNullOrEmpty(s)) { - List indices = GetIndices(groupinfo["sectors"] as string); + List indices = GetIndices(s); foreach(int index in indices) { if(index > sectors.Length) continue; @@ -1480,7 +1480,7 @@ namespace CodeImp.DoomBuilder.Map string s = groupinfo["things"] as string; if(!string.IsNullOrEmpty(s)) { - List indices = GetIndices(groupinfo["things"] as string); + List indices = GetIndices(s); foreach(int index in indices) { if(index > things.Length) continue; diff --git a/Source/Core/Rendering/ShaderManager.cs b/Source/Core/Rendering/ShaderManager.cs index 5247ee6..f28054a 100644 --- a/Source/Core/Rendering/ShaderManager.cs +++ b/Source/Core/Rendering/ShaderManager.cs @@ -23,7 +23,7 @@ using SlimDX.Direct3D9; namespace CodeImp.DoomBuilder.Rendering { - internal class ShaderManager : ID3DResource + internal class ShaderManager : ID3DResource, IDisposable { #region ================== Constants diff --git a/Source/Core/Rendering/TextFont.cs b/Source/Core/Rendering/TextFont.cs index afc1c91..feb0451 100644 --- a/Source/Core/Rendering/TextFont.cs +++ b/Source/Core/Rendering/TextFont.cs @@ -100,7 +100,6 @@ namespace CodeImp.DoomBuilder.Rendering // Done fontreader.Dispose(); - fontdata.Dispose(); break; } } diff --git a/Source/Core/VisualModes/VisualMode.cs b/Source/Core/VisualModes/VisualMode.cs index 1b23ce8..8c7b116 100644 --- a/Source/Core/VisualModes/VisualMode.cs +++ b/Source/Core/VisualModes/VisualMode.cs @@ -114,7 +114,7 @@ namespace CodeImp.DoomBuilder.VisualModes //mxd. Synch camera position to cursor position or center of the screen in 2d-mode if(General.Settings.GZSynchCameras && General.Editing.Mode is ClassicMode) { - ClassicMode oldmode = General.Editing.Mode as ClassicMode; + ClassicMode oldmode = (ClassicMode)General.Editing.Mode; if(oldmode.IsMouseInside) initialcameraposition = new Vector2D(oldmode.MouseMapPos.x, oldmode.MouseMapPos.y); @@ -483,18 +483,13 @@ namespace CodeImp.DoomBuilder.VisualModes if(target.picked == null) return new Vector2D(float.NaN, float.NaN); - //now find where exactly did we hit - if(target.picked is VisualGeometry) - { - VisualGeometry vg = target.picked as VisualGeometry; - return GetIntersection(start, start + delta, vg.BoundingBox[0], new Vector3D(vg.Vertices[0].nx, vg.Vertices[0].ny, vg.Vertices[0].nz)); - } - - if(target.picked is VisualThing) - { - VisualThing vt = target.picked as VisualThing; - return GetIntersection(start, start + delta, vt.CenterV3D, D3DDevice.V3D(vt.Center - vt.PositionV3)); - } + // Now find where exactly did we hit + VisualGeometry vg = target.picked as VisualGeometry; + if(vg != null) return GetIntersection(start, start + delta, vg.BoundingBox[0], new Vector3D(vg.Vertices[0].nx, vg.Vertices[0].ny, vg.Vertices[0].nz)); + + + VisualThing vt = target.picked as VisualThing; + if(vt != null) return GetIntersection(start, start + delta, vt.CenterV3D, D3DDevice.V3D(vt.Center - vt.PositionV3)); return new Vector2D(float.NaN, float.NaN); } diff --git a/Source/Core/Windows/ActionBrowserForm.cs b/Source/Core/Windows/ActionBrowserForm.cs index 71a890e..a9c14e7 100644 --- a/Source/Core/Windows/ActionBrowserForm.cs +++ b/Source/Core/Windows/ActionBrowserForm.cs @@ -239,10 +239,10 @@ namespace CodeImp.DoomBuilder.Windows if(tabs.SelectedTab == tabactions) { // Action node selected? - if((actions.SelectedNode != null) && (actions.SelectedNode.Tag is LinedefActionInfo)) + if(actions.SelectedNode != null && (actions.SelectedNode.Tag is LinedefActionInfo)) { // Our result - selectedaction = (actions.SelectedNode.Tag as LinedefActionInfo).Index; + selectedaction = ((LinedefActionInfo)actions.SelectedNode.Tag).Index; } } // Generalized action diff --git a/Source/Core/Windows/EffectBrowserForm.cs b/Source/Core/Windows/EffectBrowserForm.cs index e29d2a5..45e94de 100644 --- a/Source/Core/Windows/EffectBrowserForm.cs +++ b/Source/Core/Windows/EffectBrowserForm.cs @@ -201,7 +201,7 @@ namespace CodeImp.DoomBuilder.Windows if((effects.SelectedItems.Count > 0) && (effects.SelectedItems[0].Tag is SectorEffectInfo)) { // Our result - selectedeffect = (effects.SelectedItems[0].Tag as SectorEffectInfo).Index; + selectedeffect = ((SectorEffectInfo)effects.SelectedItems[0].Tag).Index; } } // Generalized action diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 958ac2e..7261854 100644 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -447,9 +447,9 @@ namespace CodeImp.DoomBuilder.Windows this.Update(); if(sender is ToolStripItem) - General.Actions.InvokeAction((sender as ToolStripItem).Tag.ToString()); + General.Actions.InvokeAction(((ToolStripItem)sender).Tag.ToString()); else if(sender is Control) - General.Actions.InvokeAction((sender as Control).Tag.ToString()); + General.Actions.InvokeAction(((Control)sender).Tag.ToString()); else General.Fail("InvokeTaggedAction used on an unexpected control."); @@ -933,13 +933,14 @@ namespace CodeImp.DoomBuilder.Windows if(General.Map != null && General.Editing.Mode is ClassicMode) { // Requested from menu? - if(sender is ToolStripMenuItem) + ToolStripMenuItem item = sender as ToolStripMenuItem; + if(item != null) { // Get integral zoom level - int zoom = int.Parse((sender as ToolStripMenuItem).Tag.ToString(), CultureInfo.InvariantCulture); + int zoom = int.Parse(item.Tag.ToString(), CultureInfo.InvariantCulture); // Zoom now - (General.Editing.Mode as ClassicMode).SetZoom(zoom / 100f); + ((ClassicMode)General.Editing.Mode).SetZoom(zoom / 100f); } } } @@ -949,7 +950,7 @@ namespace CodeImp.DoomBuilder.Windows { // In classic mode? if(General.Map != null && General.Editing.Mode is ClassicMode) - (General.Editing.Mode as ClassicMode).CenterInScreen(); + ((ClassicMode)General.Editing.Mode).CenterInScreen(); } // This changes grid display @@ -968,10 +969,11 @@ namespace CodeImp.DoomBuilder.Windows if(General.Editing.Mode is ClassicMode) { // Requested from menu? - if(sender is ToolStripMenuItem) + ToolStripMenuItem item = sender as ToolStripMenuItem; + if(item != null) { // Get integral zoom level - int size = int.Parse((sender as ToolStripMenuItem).Tag.ToString(), CultureInfo.InvariantCulture); + int size = int.Parse(item.Tag.ToString(), CultureInfo.InvariantCulture); //mxd. Disable automatic grid resizing DisableDynamicGridResize(); @@ -2472,7 +2474,7 @@ namespace CodeImp.DoomBuilder.Windows else if(menuitem.Tag is EditModeInfo) { // Action with this name available? - EditModeInfo modeinfo = (menuitem.Tag as EditModeInfo); + EditModeInfo modeinfo = (EditModeInfo)menuitem.Tag; string actionname = modeinfo.SwitchAction.GetFullActionName(modeinfo.Plugin.Assembly); if(General.Actions.Exists(actionname)) { @@ -2497,11 +2499,11 @@ namespace CodeImp.DoomBuilder.Windows // Tag set for this item? if(item.Tag is string) { - // Check if the tag doe not already begin with the assembly name - if(!(item.Tag as string).StartsWith(plugin.Name + "_", StringComparison.OrdinalIgnoreCase)) + // Check if the tag does not already begin with the assembly name + if(!((string)item.Tag).StartsWith(plugin.Name + "_", StringComparison.OrdinalIgnoreCase)) { // Change the tag to a fully qualified action name - item.Tag = plugin.Name.ToLowerInvariant() + "_" + (item.Tag as string); + item.Tag = plugin.Name.ToLowerInvariant() + "_" + (string)item.Tag; } } @@ -3459,10 +3461,10 @@ namespace CodeImp.DoomBuilder.Windows buttontoggleinfo.Image = Resources.InfoPanelCollapse; //mxd labelcollapsedinfo.Visible = false; itemtoggleinfo.Checked = true; - if(lastinfoobject is Vertex) ShowVertexInfo(lastinfoobject as Vertex); - else if(lastinfoobject is Linedef) ShowLinedefInfo(lastinfoobject as Linedef); - else if(lastinfoobject is Sector) ShowSectorInfo(lastinfoobject as Sector); - else if(lastinfoobject is Thing) ShowThingInfo(lastinfoobject as Thing); + if(lastinfoobject is Vertex) ShowVertexInfo((Vertex)lastinfoobject); + else if(lastinfoobject is Linedef) ShowLinedefInfo((Linedef)lastinfoobject); + else if(lastinfoobject is Sector) ShowSectorInfo((Sector)lastinfoobject); + else if(lastinfoobject is Thing) ShowThingInfo((Thing)lastinfoobject); else HideInfo(); } @@ -3509,19 +3511,19 @@ namespace CodeImp.DoomBuilder.Windows modename.Refresh(); statistics.Visible = showModeName; //mxd - //mxd. let the plugins know + //mxd. Let the plugins know General.Plugins.OnHighlightLost(); } // This refreshes info public void RefreshInfo() { - if(lastinfoobject is Vertex) ShowVertexInfo(lastinfoobject as Vertex); - else if(lastinfoobject is Linedef) ShowLinedefInfo(lastinfoobject as Linedef); - else if(lastinfoobject is Sector) ShowSectorInfo(lastinfoobject as Sector); - else if(lastinfoobject is Thing) ShowThingInfo(lastinfoobject as Thing); + if(lastinfoobject is Vertex) ShowVertexInfo((Vertex)lastinfoobject); + else if(lastinfoobject is Linedef) ShowLinedefInfo((Linedef)lastinfoobject); + else if(lastinfoobject is Sector) ShowSectorInfo((Sector)lastinfoobject); + else if(lastinfoobject is Thing) ShowThingInfo((Thing)lastinfoobject); - //mxd. let the plugins know + //mxd. Let the plugins know General.Plugins.OnHighlightRefreshed(lastinfoobject); } diff --git a/Source/Core/Windows/PreferencesController.cs b/Source/Core/Windows/PreferencesController.cs index f56cebc..d3e95e8 100644 --- a/Source/Core/Windows/PreferencesController.cs +++ b/Source/Core/Windows/PreferencesController.cs @@ -58,12 +58,12 @@ namespace CodeImp.DoomBuilder.Windows } // Destructor - ~PreferencesController() + /*~PreferencesController() { form = null; OnAccept = null; OnCancel = null; - } + }*/ #endregion diff --git a/Source/Core/Windows/ThingsFiltersForm.cs b/Source/Core/Windows/ThingsFiltersForm.cs index a138456..b374af7 100644 --- a/Source/Core/Windows/ThingsFiltersForm.cs +++ b/Source/Core/Windows/ThingsFiltersForm.cs @@ -351,7 +351,7 @@ namespace CodeImp.DoomBuilder.Windows if((filtercategory.SelectedIndex > -1) && (filtercategory.SelectedItem is ThingCategoryData)) { // Set new category name - f.CategoryName = (filtercategory.SelectedItem as ThingCategoryData).Category.Name; //mxd + f.CategoryName = ((ThingCategoryData)filtercategory.SelectedItem).Category.Name; //mxd } else { diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs index b90129a..994f242 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DrawGridMode.cs @@ -157,6 +157,12 @@ namespace CodeImp.DoomBuilder.BuilderModes } } + public override void OnDisengage() + { + if(hintlabel != null) hintlabel.Dispose(); + base.OnDisengage(); + } + private void OptionsPanelOnValueChanged(object sender, EventArgs eventArgs) { triangulate = panel.Triangulate; diff --git a/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs b/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs index eadd604..6f327b6 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/DrawRectangleMode.cs @@ -428,6 +428,12 @@ namespace CodeImp.DoomBuilder.BuilderModes } } + public override void OnDisengage() + { + if(hintlabel != null) hintlabel.Dispose(); + base.OnDisengage(); + } + public override void OnHelp() { General.ShowHelp("/gzdb/features/classic_modes/mode_drawrect.html"); diff --git a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs index 87780cc..866fe7a 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/EditSelectionMode.cs @@ -331,13 +331,13 @@ namespace CodeImp.DoomBuilder.BuilderModes private void Highlight(MapElement h) { // Undraw previous highlight - if((highlighted != null) && !highlighted.IsDisposed) + if(highlighted != null && !highlighted.IsDisposed) { if(highlighted is Vertex) { if(renderer.StartPlotter(false)) { - renderer.PlotVertex((highlighted as Vertex), renderer.DetermineVertexColor((highlighted as Vertex))); + renderer.PlotVertex((Vertex)highlighted, renderer.DetermineVertexColor((Vertex)highlighted)); renderer.Finish(); } } @@ -345,7 +345,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { if(renderer.StartThings(false)) { - renderer.RenderThing((highlighted as Thing), renderer.DetermineThingColor((highlighted as Thing)), Presentation.THINGS_ALPHA); + renderer.RenderThing((Thing)highlighted, renderer.DetermineThingColor((Thing)highlighted), Presentation.THINGS_ALPHA); renderer.Finish(); } } @@ -355,13 +355,13 @@ namespace CodeImp.DoomBuilder.BuilderModes highlighted = h; // Render highlighted item - if((highlighted != null) && !highlighted.IsDisposed) + if(highlighted != null && !highlighted.IsDisposed) { if(highlighted is Vertex) { if(renderer.StartPlotter(false)) { - renderer.PlotVertex((highlighted as Vertex), ColorCollection.HIGHLIGHT); + renderer.PlotVertex((Vertex)highlighted, ColorCollection.HIGHLIGHT); renderer.Finish(); } } @@ -369,7 +369,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { if(renderer.StartThings(false)) { - renderer.RenderThing((highlighted as Thing), General.Colors.Highlight, Presentation.THINGS_ALPHA); + renderer.RenderThing((Thing)highlighted, General.Colors.Highlight, Presentation.THINGS_ALPHA); renderer.Finish(); } } @@ -1564,7 +1564,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { renderer.PlotLinedefSet(General.Map.Map.Linedefs); renderer.PlotVerticesSet(General.Map.Map.Vertices); - if(highlighted is Vertex) renderer.PlotVertex((highlighted as Vertex), ColorCollection.HIGHLIGHT); + if(highlighted is Vertex) renderer.PlotVertex((Vertex)highlighted, ColorCollection.HIGHLIGHT); renderer.Finish(); } @@ -1573,9 +1573,9 @@ namespace CodeImp.DoomBuilder.BuilderModes { renderer.RenderThingSet(General.Map.ThingsFilter.HiddenThings, Presentation.THINGS_HIDDEN_ALPHA); renderer.RenderThingSet(General.Map.ThingsFilter.VisibleThings, Presentation.THINGS_ALPHA); - if(highlighted is Thing) renderer.RenderThing((highlighted as Thing), General.Colors.Highlight, Presentation.THINGS_ALPHA); - renderer.RenderNiGHTSPath(); - renderer.Finish(); + if(highlighted is Thing) renderer.RenderThing((Thing)highlighted, General.Colors.Highlight, Presentation.THINGS_ALPHA); + renderer.RenderNiGHTSPath(); + renderer.Finish(); } // Render selection diff --git a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs index 6303abe..fff0b2b 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/LinedefsMode.cs @@ -466,11 +466,11 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ParallelLinedef); //JBR // Going to EditSelectionMode? - if (General.Editing.NewMode is EditSelectionMode) + EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode; + if(mode != null) { // Not pasting anything? - EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode); - if(!editmode.Pasting) + if(!mode.Pasting) { // No selection made? But we have a highlight! if((General.Map.Map.GetSelectedLinedefs(true).Count == 0) && (highlighted != null)) @@ -1626,7 +1626,7 @@ namespace CodeImp.DoomBuilder.BuilderModes sortedlist.Reverse(); //mxd. Gather our ordered sectors - List sectorslist = new List(sortedlist.Count()); + List sectorslist = new List(sortedlist.Count); sectorslist.AddRange(sortedlist.Select(pair => pair.Key)); //mxd. Flip the lines diff --git a/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs index e7a5446..011ff57 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/SectorsMode.cs @@ -592,11 +592,12 @@ namespace CodeImp.DoomBuilder.BuilderModes } //mxd - public override void SelectMapElement(SelectableElement element) + public override void SelectMapElement(SelectableElement element) { - if(element is Sector) + Sector sector = element as Sector; + if(sector != null) { - SelectSector(element as Sector, true, true); + SelectSector(sector, true, true); // Update overlay UpdateOverlaySurfaces(); @@ -719,11 +720,11 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Map.Map.ClearSelectedLinedefs(); // Going to EditSelectionMode? - if(General.Editing.NewMode is EditSelectionMode) + EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode; + if(mode != null) { // Not pasting anything? - EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode); - if(!editmode.Pasting) + if(!mode.Pasting) { // No selection made? But we have a highlight! if((General.Map.Map.GetSelectedSectors(true).Count == 0) && (highlighted != null)) diff --git a/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs b/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs index 78f8d0d..4b631e2 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/ThingsMode.cs @@ -162,11 +162,11 @@ namespace CodeImp.DoomBuilder.BuilderModes if (highlighted != null) highlighted.Highlighted = false; // Going to EditSelectionMode? - if(General.Editing.NewMode is EditSelectionMode) + EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode; + if(mode != null) { // Not pasting anything? - EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode); - if(!editmode.Pasting) + if(!mode.Pasting) { // No selection made? But we have a highlight! if((General.Map.Map.GetSelectedThings(true).Count == 0) && (highlighted != null)) diff --git a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs index 3426353..145b630 100644 --- a/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs +++ b/Source/Plugins/BuilderModes/ClassicModes/VerticesMode.cs @@ -130,11 +130,11 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ParallelLinedef); //JBR // Going to EditSelectionMode? - if (General.Editing.NewMode is EditSelectionMode) + EditSelectionMode mode = General.Editing.NewMode as EditSelectionMode; + if(mode != null) { // Not pasting anything? - EditSelectionMode editmode = (General.Editing.NewMode as EditSelectionMode); - if(!editmode.Pasting) + if(!mode.Pasting) { // No selection made? But we have a highlight! if((General.Map.Map.GetSelectedVertices(true).Count == 0) && (highlighted != null)) diff --git a/Source/Plugins/BuilderModes/FindReplace/FindReplaceObject.cs b/Source/Plugins/BuilderModes/FindReplace/FindReplaceObject.cs index 5a363d5..929586a 100644 --- a/Source/Plugins/BuilderModes/FindReplace/FindReplaceObject.cs +++ b/Source/Plugins/BuilderModes/FindReplace/FindReplaceObject.cs @@ -70,21 +70,21 @@ namespace CodeImp.DoomBuilder.BuilderModes { if(obj is Vertex) { - points.Add((obj as Vertex).Position); + points.Add(((Vertex)obj).Position); } else if(obj is Linedef) { - points.Add((obj as Linedef).Start.Position); - points.Add((obj as Linedef).End.Position); + points.Add(((Linedef)obj).Start.Position); + points.Add(((Linedef)obj).End.Position); } else if(obj is Sidedef) { - points.Add((obj as Sidedef).Line.Start.Position); - points.Add((obj as Sidedef).Line.End.Position); + points.Add(((Sidedef)obj).Line.Start.Position); + points.Add(((Sidedef)obj).Line.End.Position); } else if(obj is Sector) { - Sector s = (obj as Sector); + Sector s = (Sector)obj; foreach(Sidedef sd in s.Sidedefs) { points.Add(sd.Line.Start.Position); @@ -93,7 +93,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } else if(obj is Thing) { - Thing t = (obj as Thing); + Thing t = (Thing)obj; Vector2D p = t.Position; points.Add(p); points.Add(p + new Vector2D(t.Size * 2.0f, t.Size * 2.0f)); diff --git a/Source/Plugins/BuilderModes/Interface/MenusForm.cs b/Source/Plugins/BuilderModes/Interface/MenusForm.cs index 2b9b6fd..c85a57e 100644 --- a/Source/Plugins/BuilderModes/Interface/MenusForm.cs +++ b/Source/Plugins/BuilderModes/Interface/MenusForm.cs @@ -145,7 +145,7 @@ namespace CodeImp.DoomBuilder.BuilderModes public void Register() { // Add the menus to the core - foreach(ToolStripMenuItem i in menus) + foreach(ToolStripItem i in menus) General.Interface.AddMenu(i); // Add the buttons to the core @@ -153,7 +153,7 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.AddButton(b); //mxd. Export menu - foreach(ToolStripMenuItem i in exportmenuitems) + foreach(ToolStripItem i in exportmenuitems) General.Interface.AddMenu(i, MenuSection.FileExport); //mxd. Copy-paste propserties items @@ -165,7 +165,7 @@ namespace CodeImp.DoomBuilder.BuilderModes public void Unregister() { // Remove the menus from the core - foreach(ToolStripMenuItem i in menus) + foreach(ToolStripItem i in menus) General.Interface.RemoveMenu(i); // Remove the buttons from the core @@ -173,7 +173,7 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.RemoveButton(b); //mxd. Export menu - foreach(ToolStripMenuItem i in exportmenuitems) + foreach(ToolStripItem i in exportmenuitems) General.Interface.RemoveMenu(i); //mxd. Copy-paste propserties items @@ -184,7 +184,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // This hides all menus public void HideAllMenus() { - foreach(ToolStripMenuItem m in menus) m.Visible = false; + foreach(ToolStripItem m in menus) m.Visible = false; } // This hides all except one menu diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs index e7ea6a2..5bfb1c1 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualGeometrySector.cs @@ -281,15 +281,15 @@ namespace CodeImp.DoomBuilder.BuilderModes { if(!(mode.HighlightedObject is BaseVisualSector)) return; - //do we need to align this? (and also grab texture scale while we are at it) + // Do we need to align this? (and also grab texture scale while we are at it) float scaleX, scaleY; bool isFloor = (geometrytype == VisualGeometryType.FLOOR); if(mode.HighlightedTarget is VisualFloor) { - VisualFloor target = mode.HighlightedTarget as VisualFloor; + VisualFloor target = (VisualFloor)mode.HighlightedTarget; - //check texture + // Check texture if(target.Sector.Sector.FloorTexture != (isFloor ? Sector.Sector.FloorTexture : Sector.Sector.CeilTexture)) return; scaleX = target.Sector.Sector.Fields.GetValue("xscalefloor", 1.0f); @@ -297,9 +297,9 @@ namespace CodeImp.DoomBuilder.BuilderModes } else { - VisualCeiling target = mode.HighlightedTarget as VisualCeiling; + VisualCeiling target = (VisualCeiling)mode.HighlightedTarget; - //check texture + // Check texture if(target.Sector.Sector.CeilTexture != (isFloor ? Sector.Sector.FloorTexture : Sector.Sector.CeilTexture)) return; scaleX = target.Sector.Sector.Fields.GetValue("xscaleceiling", 1.0f); diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index f0e09e4..6de6e93 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -147,20 +147,16 @@ namespace CodeImp.DoomBuilder.BuilderModes get { // Geometry picked? - if(target.picked is VisualGeometry) + VisualGeometry vg = target.picked as VisualGeometry; + if(vg != null) { - VisualGeometry pickedgeo = (target.picked as VisualGeometry); - - if(pickedgeo.Sidedef != null) return pickedgeo.Sidedef; - if(pickedgeo.Sector != null) return pickedgeo.Sector; + if(vg.Sidedef != null) return vg.Sidedef; + if(vg.Sector != null) return vg.Sector; return null; } // Thing picked? - if(target.picked is VisualThing) - { - VisualThing pickedthing = (target.picked as VisualThing); - return pickedthing.Thing; - } + VisualThing vt = target.picked as VisualThing; + if(vt != null) return vt.Thing; return null; } @@ -212,12 +208,11 @@ namespace CodeImp.DoomBuilder.BuilderModes // Not already disposed? if(!isdisposed) { - // Clean up - bsp.Dispose(); - bsp = null; - - // Done - base.Dispose(); + // Clean up + selectioninfoupdatetimer.Dispose(); //mxd + + // Done + base.Dispose(); } } @@ -477,18 +472,18 @@ namespace CodeImp.DoomBuilder.BuilderModes // Geometry picked? if(target.picked is VisualGeometry) { - VisualGeometry pickedgeo = (target.picked as VisualGeometry); + VisualGeometry pickedgeo = (VisualGeometry)target.picked; // Sidedef? if(pickedgeo is BaseVisualGeometrySidedef) { - BaseVisualGeometrySidedef pickedsidedef = (pickedgeo as BaseVisualGeometrySidedef); + BaseVisualGeometrySidedef pickedsidedef = (BaseVisualGeometrySidedef)pickedgeo; General.Interface.ShowLinedefInfo(pickedsidedef.GetControlLinedef(), pickedsidedef.Sidedef); //mxd } // Sector? else if(pickedgeo is BaseVisualGeometrySector) { - BaseVisualGeometrySector pickedsector = (pickedgeo as BaseVisualGeometrySector); + BaseVisualGeometrySector pickedsector = (BaseVisualGeometrySector)pickedgeo; bool isceiling = (pickedsector is VisualCeiling); //mxd General.Interface.ShowSectorInfo(pickedsector.Level.sector, isceiling, !isceiling); } @@ -497,14 +492,16 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.HideInfo(); } } + // Thing picked? else if(target.picked is VisualThing) - { // Thing picked? - VisualThing pickedthing = (target.picked as VisualThing); + { + VisualThing pickedthing = (VisualThing)target.picked; General.Interface.ShowThingInfo(pickedthing.Thing); } - else if(target.picked is VisualVertex) //mxd + //mxd. Vertex picked? + else if(target.picked is VisualVertex) { - VisualVertex pickedvert = (target.picked as VisualVertex); + VisualVertex pickedvert = (VisualVertex)target.picked; General.Interface.ShowVertexInfo(pickedvert.Vertex); } } @@ -1715,8 +1712,8 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. As well as geometry... foreach(KeyValuePair group in visiblesectors) { - if(group.Value is BaseVisualSector) - (group.Value as BaseVisualSector).Rebuild(); + BaseVisualSector vs = group.Value as BaseVisualSector; + if(vs != null) vs.Rebuild(); } RebuildSelectedObjectsList(); @@ -1737,7 +1734,8 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd. As well as geometry... foreach(KeyValuePair group in visiblesectors) { - if(group.Value is BaseVisualSector) (group.Value as BaseVisualSector).Rebuild(); + BaseVisualSector vs = group.Value as BaseVisualSector; + if(vs != null) vs.Rebuild(); } RebuildSelectedObjectsList(); @@ -1909,22 +1907,22 @@ namespace CodeImp.DoomBuilder.BuilderModes { List objs = new List(); foreach(IVisualEventReceiver i in selectedobjects) - { - if (includesectors && (i is BaseVisualGeometrySector) /*&& ((BaseVisualGeometrySector)i).Triangles > 0*/) objs.Add(i); - else if (includesidedefs && (i is BaseVisualGeometrySidedef) /*&& ((BaseVisualGeometrySidedef)i).Triangles > 0*/) objs.Add(i); - else if (includethings && (i is BaseVisualThing)) objs.Add(i); - else if (includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd - } + { + if(includesectors && (i is BaseVisualGeometrySector)) objs.Add(i); + else if(includesidedefs && (i is BaseVisualGeometrySidedef)) objs.Add(i); + else if(includethings && (i is BaseVisualThing)) objs.Add(i); + else if(includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd + } // Add highlight? if (selectedobjects.Count == 0) { IVisualEventReceiver i = (target.picked as IVisualEventReceiver); - if (includesectors && (i is BaseVisualGeometrySector) /*&& ((BaseVisualGeometrySector)i).Triangles > 0*/) objs.Add(i); - else if (includesidedefs && (i is BaseVisualGeometrySidedef) /*&& ((BaseVisualGeometrySidedef)i).Triangles > 0*/) objs.Add(i); - else if (includethings && (i is BaseVisualThing)) objs.Add(i); - else if (includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd - } + if(includesectors && (i is BaseVisualGeometrySector)) objs.Add(i); + else if(includesidedefs && (i is BaseVisualGeometrySidedef)) objs.Add(i); + else if(includethings && (i is BaseVisualThing)) objs.Add(i); + else if(includevertices && (i is BaseVisualVertex)) objs.Add(i); //mxd + } return objs; } @@ -1935,22 +1933,21 @@ namespace CodeImp.DoomBuilder.BuilderModes Dictionary processed = new Dictionary(); List result = new List(); - foreach(IVisualEventReceiver obj in objs) + foreach(IVisualEventReceiver i in objs) { - if(!(obj is BaseVisualGeometrySidedef)) + BaseVisualGeometrySidedef sidedef = i as BaseVisualGeometrySidedef; + if(sidedef != null) { - result.Add(obj); - } - else - { - Sidedef side = (obj as BaseVisualGeometrySidedef).Sidedef; - - if(!processed.ContainsKey(side)) + if (!processed.ContainsKey(sidedef.Sidedef)) { - processed.Add(side, false); - result.Add(obj); + processed.Add(sidedef.Sidedef, false); + result.Add(i); } } + else + { + result.Add(i); + } } return result; @@ -1963,21 +1960,18 @@ namespace CodeImp.DoomBuilder.BuilderModes List sectors = new List(); foreach(IVisualEventReceiver i in selectedobjects) { - if(i is BaseVisualGeometrySector) + BaseVisualGeometrySector sector = i as BaseVisualGeometrySector; + if(sector != null && !added.ContainsKey(sector.Level.sector)) { - Sector s = (i as BaseVisualGeometrySector).Level.sector; - if(!added.ContainsKey(s)) - { - sectors.Add(s); - added.Add(s, 0); - } + sectors.Add(sector.Level.sector); + added.Add(sector.Level.sector, 0); } } // Add highlight? if((selectedobjects.Count == 0) && (target.picked is BaseVisualGeometrySector)) { - Sector s = (target.picked as BaseVisualGeometrySector).Level.sector; + Sector s = ((BaseVisualGeometrySector)target.picked).Level.sector; if(!added.ContainsKey(s)) sectors.Add(s); } @@ -1991,9 +1985,10 @@ namespace CodeImp.DoomBuilder.BuilderModes List linedefs = new List(); foreach(IVisualEventReceiver i in selectedobjects) { - if(i is BaseVisualGeometrySidedef) + BaseVisualGeometrySidedef sidedef = i as BaseVisualGeometrySidedef; + if(sidedef != null) { - Linedef l = (i as BaseVisualGeometrySidedef).GetControlLinedef(); //mxd + Linedef l = sidedef.GetControlLinedef(); //mxd if(!added.ContainsKey(l)) { linedefs.Add(l); @@ -2005,7 +2000,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Add highlight? if((selectedobjects.Count == 0) && (target.picked is BaseVisualGeometrySidedef)) { - Linedef l = (target.picked as BaseVisualGeometrySidedef).GetControlLinedef(); //mxd + Linedef l = ((BaseVisualGeometrySidedef)target.picked).GetControlLinedef(); //mxd if(!added.ContainsKey(l)) linedefs.Add(l); } @@ -2019,21 +2014,18 @@ namespace CodeImp.DoomBuilder.BuilderModes List sidedefs = new List(); foreach(IVisualEventReceiver i in selectedobjects) { - if(i is BaseVisualGeometrySidedef) + BaseVisualGeometrySidedef sidedef = i as BaseVisualGeometrySidedef; + if(sidedef != null && !added.ContainsKey(sidedef.Sidedef)) { - Sidedef sd = (i as BaseVisualGeometrySidedef).Sidedef; - if(!added.ContainsKey(sd)) - { - sidedefs.Add(sd); - added.Add(sd, 0); - } + sidedefs.Add(sidedef.Sidedef); + added.Add(sidedef.Sidedef, 0); } } // Add highlight? if((selectedobjects.Count == 0) && (target.picked is BaseVisualGeometrySidedef)) { - Sidedef sd = (target.picked as BaseVisualGeometrySidedef).Sidedef; + Sidedef sd = ((BaseVisualGeometrySidedef)target.picked).Sidedef; if(!added.ContainsKey(sd)) sidedefs.Add(sd); } @@ -2047,21 +2039,18 @@ namespace CodeImp.DoomBuilder.BuilderModes List things = new List(); foreach(IVisualEventReceiver i in selectedobjects) { - if(i is BaseVisualThing) + BaseVisualThing thing = i as BaseVisualThing; + if(thing != null && !added.ContainsKey(thing.Thing)) { - Thing t = (i as BaseVisualThing).Thing; - if(!added.ContainsKey(t)) - { - things.Add(t); - added.Add(t, 0); - } + things.Add(thing.Thing); + added.Add(thing.Thing, 0); } } // Add highlight? if((selectedobjects.Count == 0) && (target.picked is BaseVisualThing)) { - Thing t = (target.picked as BaseVisualThing).Thing; + Thing t = ((BaseVisualThing)target.picked).Thing; if(!added.ContainsKey(t)) things.Add(t); } @@ -2091,9 +2080,8 @@ namespace CodeImp.DoomBuilder.BuilderModes // Add highlight? if((selectedobjects.Count == 0) && (target.picked is BaseVisualVertex)) { - Vertex v = (target.picked as BaseVisualVertex).Vertex; - if(!added.ContainsKey(v)) - verts.Add(v); + Vertex v = ((BaseVisualVertex)target.picked).Vertex; + if(!added.ContainsKey(v)) verts.Add(v); } return verts; diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs index 3bdedec..8f50c9f 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs @@ -294,12 +294,13 @@ namespace CodeImp.DoomBuilder.BuilderModes base.Texture = Sprite; // Determine sprite size and offset - float radius = Sprite.ScaledWidth * 0.5f; - float height = Sprite.ScaledHeight; - if(Sprite is SpriteImage) + float radius = sprite.ScaledWidth * 0.5f; + float height = sprite.ScaledHeight; + SpriteImage spriteimg = sprite as SpriteImage; + if(spriteimg != null) { - offsetx = radius - (Sprite as SpriteImage).OffsetX; - offsety = (Sprite as SpriteImage).OffsetY - height; + offsetx = radius - spriteimg.OffsetX; + offsety = spriteimg.OffsetY - height; } // Scale by thing type/actor scale diff --git a/Source/Plugins/NodesViewer/BuilderPlug.cs b/Source/Plugins/NodesViewer/BuilderPlug.cs index ac70a22..5baff07 100644 --- a/Source/Plugins/NodesViewer/BuilderPlug.cs +++ b/Source/Plugins/NodesViewer/BuilderPlug.cs @@ -67,7 +67,7 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer #region ================== Methods // This returns a unique temp filename - public static string MakeTempFilename(string extension) + /*public static string MakeTempFilename(string extension) { string filename; const string chars = "abcdefghijklmnopqrstuvwxyz1234567890"; @@ -85,7 +85,7 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer // Return the filename return filename; - } + }*/ #endregion } diff --git a/Source/Plugins/NodesViewer/NodesViewerMode.cs b/Source/Plugins/NodesViewer/NodesViewerMode.cs index 45f89e5..9bbde8c 100644 --- a/Source/Plugins/NodesViewer/NodesViewerMode.cs +++ b/Source/Plugins/NodesViewer/NodesViewerMode.cs @@ -129,8 +129,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer nodes[i].leftsubsector = (leftindex & 0x8000) != 0; } nodesreader.Close(); - nodesstream.Close(); - nodesstream.Dispose(); // Add additional properties to nodes nodes[nodes.Length - 1].parent = -1; @@ -161,8 +159,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer segs[i].offset = segsreader.ReadInt16(); } segsreader.Close(); - segsstream.Close(); - segsstream.Dispose(); // Load the vertexes structure MemoryStream vertsstream = General.Map.GetLumpData("VERTEXES"); @@ -185,8 +181,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer verts[i].y = vertsreader.ReadInt16(); } vertsreader.Close(); - vertsstream.Close(); - vertsstream.Dispose(); // Load the subsectors structure MemoryStream ssecstream = General.Map.GetLumpData("SSECTORS"); @@ -209,8 +203,6 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer ssectors[i].firstseg = ssecreader.ReadUInt16(); } ssecreader.Close(); - ssecstream.Close(); - ssecstream.Dispose(); // Link all segs to their subsectors for(int i = 0; i < ssectors.Length; i++) @@ -229,175 +221,175 @@ namespace CodeImp.DoomBuilder.Plugins.NodesViewer private bool LoadZNodes() { List supportedFormats = new List { "XNOD", "XGLN", "XGL2", "XGL3" }; - using(MemoryStream stream = General.Map.GetLumpData("ZNODES")) + MemoryStream stream = General.Map.GetLumpData("ZNODES"); + + //boilerplate... + if(stream.Length < 4) { - //boilerplate... - if(stream.Length < 4) + MessageBox.Show("ZNODES lump is empty.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error); + stream.Close(); + return false; + } + + using(BinaryReader reader = new BinaryReader(stream)) + { + //read signature + nodesformat = new string(reader.ReadChars(4)); + if(!supportedFormats.Contains(nodesformat)) { - MessageBox.Show("ZNODES lump is empty.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("\"" + nodesformat + "\" node format is not supported.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } - using(BinaryReader reader = new BinaryReader(stream)) + uint vertsCount = reader.ReadUInt32(); + uint newVertsCount = reader.ReadUInt32(); + + //boilerplate... + if(vertsCount != General.Map.Map.Vertices.Count) { - //read signature - nodesformat = new string(reader.ReadChars(4)); - if(!supportedFormats.Contains(nodesformat)) - { - MessageBox.Show("\"" + nodesformat + "\" node format is not supported.", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - uint vertsCount = reader.ReadUInt32(); - uint newVertsCount = reader.ReadUInt32(); - - //boilerplate... - if(vertsCount != General.Map.Map.Vertices.Count) - { - MessageBox.Show("Error while reading ZNODES: vertices count in ZNODES lump (" + vertsCount + ") doesn't match with map's vertices count (" + General.Map.Map.Vertices.Count + ")!", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - //add map vertices - verts = new Vector2D[vertsCount + newVertsCount]; - int counter = 0; - foreach(Vertex v in General.Map.Map.Vertices) verts[counter++] = v.Position; - - //read extra vertices - for(int i = counter; i < counter + newVertsCount; i++) - { - verts[i].x = reader.ReadInt32() / 65536.0f; - verts[i].y = reader.ReadInt32() / 65536.0f; - } - - //read subsectors - uint ssecCount = reader.ReadUInt32(); - ssectors = new Subsector[ssecCount]; - - int firstseg = 0; - for(int i = 0; i < ssectors.Length; i++) - { - ssectors[i].numsegs = (int)reader.ReadUInt32(); - ssectors[i].firstseg = firstseg; - firstseg += ssectors[i].numsegs; - } - - //read segments. offset and angle are unused anyway - uint segsCount = reader.ReadUInt32(); - segs = new Seg[segsCount]; - - switch(nodesformat) - { - case "XGLN": - for(int i = 0; i < segs.Length; i++) - { - segs[i].startvertex = (int)reader.ReadUInt32(); - reader.BaseStream.Position += 4; //skip partner - segs[i].lineindex = reader.ReadUInt16(); - segs[i].leftside = reader.ReadBoolean(); - } - break; - - case "XGL3": - case "XGL2": - for(int i = 0; i < segs.Length; i++) - { - segs[i].startvertex = (int)reader.ReadUInt32(); - reader.BaseStream.Position += 4; //skip partner - uint lineindex = reader.ReadUInt32(); - segs[i].lineindex = (lineindex == 0xFFFFFFFF ? -1 : (int)lineindex); - segs[i].leftside = reader.ReadBoolean(); - } - break; - - case "XNOD": - for(int i = 0; i < segs.Length; i++) - { - segs[i].startvertex = (int)reader.ReadUInt32(); - segs[i].endvertex = (int)reader.ReadUInt32(); - segs[i].lineindex = reader.ReadUInt16(); - segs[i].leftside = reader.ReadBoolean(); - } - break; - } - - //set second vertex, angle and reverse segs order - if(nodesformat == "XGLN" || nodesformat == "XGL2" || nodesformat == "XGL3") - { - int index = 0; - foreach(Subsector ss in ssectors) - { - //set the last vert - int lastseg = ss.firstseg + ss.numsegs - 1; - segs[lastseg].endvertex = segs[ss.firstseg].startvertex; - - //set the rest - for(int i = ss.firstseg + 1; i <= lastseg; i++) segs[i - 1].endvertex = segs[i].startvertex; - - //set angle and subsector index - for(int i = ss.firstseg; i <= lastseg; i++) - { - segs[i].angle = Vector2D.GetAngle(verts[segs[i].endvertex], verts[segs[i].startvertex]); - segs[i].ssector = index; - } - - index++; - } - } - - //read nodes - uint nodesCount = reader.ReadUInt32(); - - //boilerplate... - if(nodesCount < 1) - { - MessageBox.Show("The map has only one subsector.", "Why are you doing this, Stanley?..", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - nodes = new Node[nodesCount]; - - for(int i = 0; i < nodes.Length; i++) - { - if(nodesformat == "XGL3") - { - nodes[i].linestart.x = reader.ReadInt32() / 65536.0f; - nodes[i].linestart.y = reader.ReadInt32() / 65536.0f; - nodes[i].linedelta.x = reader.ReadInt32() / 65536.0f; - nodes[i].linedelta.y = reader.ReadInt32() / 65536.0f; - } - else - { - nodes[i].linestart.x = reader.ReadInt16(); - nodes[i].linestart.y = reader.ReadInt16(); - nodes[i].linedelta.x = reader.ReadInt16(); - nodes[i].linedelta.y = reader.ReadInt16(); - } - - float top = reader.ReadInt16(); - float bot = reader.ReadInt16(); - float left = reader.ReadInt16(); - float right = reader.ReadInt16(); - nodes[i].rightbox = new RectangleF(left, top, (right - left), (bot - top)); - - top = reader.ReadInt16(); - bot = reader.ReadInt16(); - left = reader.ReadInt16(); - right = reader.ReadInt16(); - nodes[i].leftbox = new RectangleF(left, top, (right - left), (bot - top)); - - uint rightindex = reader.ReadUInt32(); - uint leftindex = reader.ReadUInt32(); - nodes[i].rightchild = (int)(rightindex & 0x7FFFFFFF); - nodes[i].leftchild = (int)(leftindex & 0x7FFFFFFF); - nodes[i].rightsubsector = (rightindex & 0x80000000) != 0; - nodes[i].leftsubsector = (leftindex & 0x80000000) != 0; - } - - // Add additional properties to nodes - nodes[nodes.Length - 1].parent = -1; - RecursiveSetupNodes(nodes.Length - 1); + MessageBox.Show("Error while reading ZNODES: vertices count in ZNODES lump (" + vertsCount + ") doesn't match with map's vertices count (" + General.Map.Map.Vertices.Count + ")!", "Nodes Viewer mode", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; } + + //add map vertices + verts = new Vector2D[vertsCount + newVertsCount]; + int counter = 0; + foreach(Vertex v in General.Map.Map.Vertices) verts[counter++] = v.Position; + + //read extra vertices + for(int i = counter; i < counter + newVertsCount; i++) + { + verts[i].x = reader.ReadInt32() / 65536.0f; + verts[i].y = reader.ReadInt32() / 65536.0f; + } + + //read subsectors + uint ssecCount = reader.ReadUInt32(); + ssectors = new Subsector[ssecCount]; + + int firstseg = 0; + for(int i = 0; i < ssectors.Length; i++) + { + ssectors[i].numsegs = (int)reader.ReadUInt32(); + ssectors[i].firstseg = firstseg; + firstseg += ssectors[i].numsegs; + } + + //read segments. offset and angle are unused anyway + uint segsCount = reader.ReadUInt32(); + segs = new Seg[segsCount]; + + switch(nodesformat) + { + case "XGLN": + for(int i = 0; i < segs.Length; i++) + { + segs[i].startvertex = (int)reader.ReadUInt32(); + reader.BaseStream.Position += 4; //skip partner + segs[i].lineindex = reader.ReadUInt16(); + segs[i].leftside = reader.ReadBoolean(); + } + break; + + case "XGL3": + case "XGL2": + for(int i = 0; i < segs.Length; i++) + { + segs[i].startvertex = (int)reader.ReadUInt32(); + reader.BaseStream.Position += 4; //skip partner + uint lineindex = reader.ReadUInt32(); + segs[i].lineindex = (lineindex == 0xFFFFFFFF ? -1 : (int)lineindex); + segs[i].leftside = reader.ReadBoolean(); + } + break; + + case "XNOD": + for(int i = 0; i < segs.Length; i++) + { + segs[i].startvertex = (int)reader.ReadUInt32(); + segs[i].endvertex = (int)reader.ReadUInt32(); + segs[i].lineindex = reader.ReadUInt16(); + segs[i].leftside = reader.ReadBoolean(); + } + break; + } + + //set second vertex, angle and reverse segs order + if(nodesformat == "XGLN" || nodesformat == "XGL2" || nodesformat == "XGL3") + { + int index = 0; + foreach(Subsector ss in ssectors) + { + //set the last vert + int lastseg = ss.firstseg + ss.numsegs - 1; + segs[lastseg].endvertex = segs[ss.firstseg].startvertex; + + //set the rest + for(int i = ss.firstseg + 1; i <= lastseg; i++) segs[i - 1].endvertex = segs[i].startvertex; + + //set angle and subsector index + for(int i = ss.firstseg; i <= lastseg; i++) + { + segs[i].angle = Vector2D.GetAngle(verts[segs[i].endvertex], verts[segs[i].startvertex]); + segs[i].ssector = index; + } + + index++; + } + } + + //read nodes + uint nodesCount = reader.ReadUInt32(); + + //boilerplate... + if(nodesCount < 1) + { + MessageBox.Show("The map has only one subsector.", "Why are you doing this, Stanley?..", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + nodes = new Node[nodesCount]; + + for(int i = 0; i < nodes.Length; i++) + { + if(nodesformat == "XGL3") + { + nodes[i].linestart.x = reader.ReadInt32() / 65536.0f; + nodes[i].linestart.y = reader.ReadInt32() / 65536.0f; + nodes[i].linedelta.x = reader.ReadInt32() / 65536.0f; + nodes[i].linedelta.y = reader.ReadInt32() / 65536.0f; + } + else + { + nodes[i].linestart.x = reader.ReadInt16(); + nodes[i].linestart.y = reader.ReadInt16(); + nodes[i].linedelta.x = reader.ReadInt16(); + nodes[i].linedelta.y = reader.ReadInt16(); + } + + float top = reader.ReadInt16(); + float bot = reader.ReadInt16(); + float left = reader.ReadInt16(); + float right = reader.ReadInt16(); + nodes[i].rightbox = new RectangleF(left, top, (right - left), (bot - top)); + + top = reader.ReadInt16(); + bot = reader.ReadInt16(); + left = reader.ReadInt16(); + right = reader.ReadInt16(); + nodes[i].leftbox = new RectangleF(left, top, (right - left), (bot - top)); + + uint rightindex = reader.ReadUInt32(); + uint leftindex = reader.ReadUInt32(); + nodes[i].rightchild = (int)(rightindex & 0x7FFFFFFF); + nodes[i].leftchild = (int)(leftindex & 0x7FFFFFFF); + nodes[i].rightsubsector = (rightindex & 0x80000000) != 0; + nodes[i].leftsubsector = (leftindex & 0x80000000) != 0; + } + + // Add additional properties to nodes + nodes[nodes.Length - 1].parent = -1; + RecursiveSetupNodes(nodes.Length - 1); } return true; diff --git a/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs b/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs index a687aeb..f8cd2e7 100644 --- a/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs +++ b/Source/Plugins/SoundPropagationMode/SoundEnvironmentMode.cs @@ -252,6 +252,7 @@ namespace CodeImp.DoomBuilder.SoundPropagationMode base.OnDisengage(); worker.CancelAsync(); + worker.Dispose(); General.Interface.RemoveButton(BuilderPlug.Me.MenusForm.ColorConfiguration); General.Interface.RemoveDocker(docker);