From 0102cf3166af90fd53b2ed9428c6c3f7a448d02b Mon Sep 17 00:00:00 2001 From: codeimp Date: Fri, 5 Dec 2008 15:38:50 +0000 Subject: [PATCH] working on visual mode --- Source/BuilderModes/BuilderModes.csproj | 2 + .../VisualModes/BaseVisualGeometry.cs | 15 +-- .../VisualModes/BaseVisualGeometrySector.cs | 79 +++++++++++++++ .../VisualModes/BaseVisualGeometrySidedef.cs | 98 +++++++++++++++++++ .../VisualModes/BaseVisualSector.cs | 16 +-- .../BuilderModes/VisualModes/VisualCeiling.cs | 12 +-- .../BuilderModes/VisualModes/VisualFloor.cs | 10 +- .../BuilderModes/VisualModes/VisualLower.cs | 29 +----- .../VisualModes/VisualMiddleDouble.cs | 29 +----- .../VisualModes/VisualMiddleSingle.cs | 29 +----- .../BuilderModes/VisualModes/VisualUpper.cs | 29 +----- Source/VisualModes/VisualGeometry.cs | 6 +- Source/VisualModes/VisualSector.cs | 1 - Source/Windows/MainForm.cs | 3 +- 14 files changed, 231 insertions(+), 127 deletions(-) create mode 100644 Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs create mode 100644 Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs diff --git a/Source/BuilderModes/BuilderModes.csproj b/Source/BuilderModes/BuilderModes.csproj index 17f94098..44b15008 100644 --- a/Source/BuilderModes/BuilderModes.csproj +++ b/Source/BuilderModes/BuilderModes.csproj @@ -103,6 +103,8 @@ + + diff --git a/Source/BuilderModes/VisualModes/BaseVisualGeometry.cs b/Source/BuilderModes/VisualModes/BaseVisualGeometry.cs index f412a594..ec8da14c 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualGeometry.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualGeometry.cs @@ -36,7 +36,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class BaseVisualGeometry : VisualGeometry + internal abstract class BaseVisualGeometry : VisualGeometry { #region ================== Constants @@ -50,22 +50,25 @@ namespace CodeImp.DoomBuilder.BuilderModes #endregion - #region ================== Constructor / Destructor + #region ================== Constructor / Setup // Constructor - public BaseVisualGeometry() : base() + public BaseVisualGeometry(VisualSector vs) : base(vs) { } - + // Constructor for sidedefs - public BaseVisualGeometry(Sidedef sd) : base(sd) + public BaseVisualGeometry(VisualSector vs, Sidedef sd) : base(vs, sd) { } + + // This is for setting up new geometry + public abstract bool Setup(); #endregion #region ================== Methods - + #endregion #region ================== Events diff --git a/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs b/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs new file mode 100644 index 00000000..666cc55b --- /dev/null +++ b/Source/BuilderModes/VisualModes/BaseVisualGeometrySector.cs @@ -0,0 +1,79 @@ + +#region ================== Copyright (c) 2007 Pascal vd Heiden + +/* + * Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com + * This program is released under GNU General Public License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#endregion + +#region ================== Namespaces + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Windows.Forms; +using System.IO; +using System.Reflection; +using CodeImp.DoomBuilder.Windows; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; +using CodeImp.DoomBuilder.Geometry; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.VisualModes; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + internal abstract class BaseVisualGeometrySector : BaseVisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Destructor + + // Constructor + public BaseVisualGeometrySector(VisualSector vs) : base(vs) + { + } + + #endregion + + #region ================== Methods + + #endregion + + #region ================== Events + + // Edit button released + public override void OnEditEnd() + { + List sectors = new List(); + sectors.Add(this.Sector.Sector); + DialogResult result = General.Interface.ShowEditSectors(sectors); + if(result == DialogResult.OK) (this.Sector as BaseVisualSector).Rebuild(); + } + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs b/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs new file mode 100644 index 00000000..bf08ac84 --- /dev/null +++ b/Source/BuilderModes/VisualModes/BaseVisualGeometrySidedef.cs @@ -0,0 +1,98 @@ + +#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.Windows.Forms; +using System.IO; +using System.Reflection; +using CodeImp.DoomBuilder.Windows; +using CodeImp.DoomBuilder.IO; +using CodeImp.DoomBuilder.Map; +using CodeImp.DoomBuilder.Rendering; +using CodeImp.DoomBuilder.Geometry; +using CodeImp.DoomBuilder.Editing; +using CodeImp.DoomBuilder.VisualModes; + +#endregion + +namespace CodeImp.DoomBuilder.BuilderModes +{ + internal abstract class BaseVisualGeometrySidedef : BaseVisualGeometry + { + #region ================== Constants + + #endregion + + #region ================== Variables + + protected float top; + protected float bottom; + + #endregion + + #region ================== Properties + + #endregion + + #region ================== Constructor / Destructor + + // Constructor for sidedefs + public BaseVisualGeometrySidedef(VisualSector vs, Sidedef sd) : base(vs, sd) + { + } + + #endregion + + #region ================== Methods + + // This performs a fast test in object picking + public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) + { + // Check if intersection point is between top and bottom + return (pickintersect.z >= bottom) && (pickintersect.z <= top); + } + + // This performs an accurate test for object picking + public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) + { + // The fast reject pass is already as accurate as it gets, + // so we just return the intersection distance here + u_ray = pickrayu; + return true; + } + + #endregion + + #region ================== Events + + // Edit button released + public override void OnEditEnd() + { + List lines = new List(); + lines.Add(this.Sidedef.Line); + DialogResult result = General.Interface.ShowEditLinedefs(lines); + if(result == DialogResult.OK) (this.Sector as BaseVisualSector).Rebuild(); + } + + #endregion + } +} diff --git a/Source/BuilderModes/VisualModes/BaseVisualSector.cs b/Source/BuilderModes/VisualModes/BaseVisualSector.cs index 971f36a8..2f7f651a 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualSector.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualSector.cs @@ -86,12 +86,12 @@ namespace CodeImp.DoomBuilder.BuilderModes base.ClearGeometry(); // Create floor - VisualFloor vf = new VisualFloor(); - if(vf.Setup(base.Sector)) base.AddGeometry(vf); + VisualFloor vf = new VisualFloor(this); + if(vf.Setup()) base.AddGeometry(vf); // Create ceiling - VisualCeiling vc = new VisualCeiling(); - if(vc.Setup(base.Sector)) base.AddGeometry(vc); + VisualCeiling vc = new VisualCeiling(this); + if(vc.Setup()) base.AddGeometry(vc); // Go for all sidedefs foreach(Sidedef sd in base.Sector.Sidedefs) @@ -100,21 +100,21 @@ namespace CodeImp.DoomBuilder.BuilderModes if(sd.Other != null) { // Create upper part - VisualUpper vu = new VisualUpper(sd); + VisualUpper vu = new VisualUpper(this, sd); if(vu.Setup()) base.AddGeometry(vu); // Create lower part - VisualLower vl = new VisualLower(sd); + VisualLower vl = new VisualLower(this, sd); if(vl.Setup()) base.AddGeometry(vl); // Create middle part - VisualMiddleDouble vm = new VisualMiddleDouble(sd); + VisualMiddleDouble vm = new VisualMiddleDouble(this, sd); if(vm.Setup()) base.AddGeometry(vm); } else { // Create middle part - VisualMiddleSingle vm = new VisualMiddleSingle(sd); + VisualMiddleSingle vm = new VisualMiddleSingle(this, sd); if(vm.Setup()) base.AddGeometry(vm); } } diff --git a/Source/BuilderModes/VisualModes/VisualCeiling.cs b/Source/BuilderModes/VisualModes/VisualCeiling.cs index 1720539d..18184d9d 100644 --- a/Source/BuilderModes/VisualModes/VisualCeiling.cs +++ b/Source/BuilderModes/VisualModes/VisualCeiling.cs @@ -39,7 +39,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class VisualCeiling : BaseVisualGeometry + internal sealed class VisualCeiling : BaseVisualGeometrySector { #region ================== Constants @@ -47,9 +47,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables - private float pickrayu; - private Vector3D pickintersect; - #endregion #region ================== Properties @@ -59,18 +56,19 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Setup // Constructor - public VisualCeiling() + public VisualCeiling(VisualSector vs) : base(vs) { // We have no destructor GC.SuppressFinalize(this); } // This builds the geometry. Returns false when no geometry created. - public bool Setup(Sector s) + public override bool Setup() { WorldVertex[] verts; WorldVertex v; - + Sector s = base.Sector.Sector; + // Load floor texture base.Texture = General.Map.Data.GetFlatImage(s.LongCeilTexture); if(base.Texture == null) base.Texture = General.Map.Data.MissingTexture3D; diff --git a/Source/BuilderModes/VisualModes/VisualFloor.cs b/Source/BuilderModes/VisualModes/VisualFloor.cs index 31bb9714..9eba9cfe 100644 --- a/Source/BuilderModes/VisualModes/VisualFloor.cs +++ b/Source/BuilderModes/VisualModes/VisualFloor.cs @@ -39,7 +39,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class VisualFloor : BaseVisualGeometry + internal sealed class VisualFloor : BaseVisualGeometrySector { #region ================== Constants @@ -47,9 +47,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables - private float pickrayu; - private Vector3D pickintersect; - #endregion #region ================== Properties @@ -59,16 +56,17 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Setup // Constructor - public VisualFloor() + public VisualFloor(VisualSector vs) : base(vs) { // We have no destructor GC.SuppressFinalize(this); } // This builds the geometry. Returns false when no geometry created. - public bool Setup(Sector s) + public override bool Setup() { WorldVertex[] verts; + Sector s = base.Sector.Sector; // Load floor texture base.Texture = General.Map.Data.GetFlatImage(s.LongFloorTexture); diff --git a/Source/BuilderModes/VisualModes/VisualLower.cs b/Source/BuilderModes/VisualModes/VisualLower.cs index fa676aaa..16c51edc 100644 --- a/Source/BuilderModes/VisualModes/VisualLower.cs +++ b/Source/BuilderModes/VisualModes/VisualLower.cs @@ -39,7 +39,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class VisualLower : BaseVisualGeometry + internal sealed class VisualLower : BaseVisualGeometrySidedef { #region ================== Constants @@ -47,9 +47,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables - private float top; - private float bottom; - #endregion #region ================== Properties @@ -59,14 +56,14 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Setup // Constructor - public VisualLower(Sidedef s) : base(s) + public VisualLower(VisualSector vs, Sidedef s) : base(vs, s) { // We have no destructor GC.SuppressFinalize(this); } // This builds the geometry. Returns false when no geometry created. - public bool Setup() + public override bool Setup() { // Calculate size of this wall part float geotop = (float)Sidedef.Other.Sector.FloorHeight; @@ -140,8 +137,8 @@ namespace CodeImp.DoomBuilder.BuilderModes verts[5] = new WorldVertex(v2.x, v2.y, geobottom, pc.ToInt(), t2.x, t2.y); // Keep properties - this.top = geotop; - this.bottom = geobottom; + base.top = geotop; + base.bottom = geobottom; // Apply vertices base.SetVertices(verts); @@ -158,22 +155,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods - // This performs a fast test in object picking - public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) - { - // Check if intersection point is between top and bottom - return (pickintersect.z >= bottom) && (pickintersect.z <= top); - } - - // This performs an accurate test for object picking - public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) - { - // The fast reject pass is already as accurate as it gets, - // so we just return the intersection distance here - u_ray = pickrayu; - return true; - } - #endregion } } diff --git a/Source/BuilderModes/VisualModes/VisualMiddleDouble.cs b/Source/BuilderModes/VisualModes/VisualMiddleDouble.cs index 4f31dcac..7fef404e 100644 --- a/Source/BuilderModes/VisualModes/VisualMiddleDouble.cs +++ b/Source/BuilderModes/VisualModes/VisualMiddleDouble.cs @@ -39,7 +39,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class VisualMiddleDouble : BaseVisualGeometry + internal sealed class VisualMiddleDouble : BaseVisualGeometrySidedef { #region ================== Constants @@ -47,9 +47,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables - private float top; - private float bottom; - #endregion #region ================== Properties @@ -59,7 +56,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Setup // Constructor - public VisualMiddleDouble(Sidedef s) : base(s) + public VisualMiddleDouble(VisualSector vs, Sidedef s) : base(vs, s) { // Set render pass this.RenderPass = RenderPass.Mask; @@ -69,7 +66,7 @@ namespace CodeImp.DoomBuilder.BuilderModes } // This builds the geometry. Returns false when no geometry created. - public bool Setup() + public override bool Setup() { // Calculate size of this wall part float geotop = (float)Math.Min(Sidedef.Sector.CeilHeight, Sidedef.Other.Sector.CeilHeight); @@ -151,8 +148,8 @@ namespace CodeImp.DoomBuilder.BuilderModes verts[5] = new WorldVertex(v2.x, v2.y, texbottom, pc.ToInt(), t2.x, t2.y); // Keep properties - this.top = textop; - this.bottom = texbottom; + base.top = textop; + base.bottom = texbottom; // Apply vertices base.SetVertices(verts); @@ -169,22 +166,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods - // This performs a fast test in object picking - public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) - { - // Check if intersection point is between top and bottom - return (pickintersect.z >= bottom) && (pickintersect.z <= top); - } - - // This performs an accurate test for object picking - public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) - { - // The fast reject pass is already as accurate as it gets, - // so we just return the intersection distance here - u_ray = pickrayu; - return true; - } - #endregion } } diff --git a/Source/BuilderModes/VisualModes/VisualMiddleSingle.cs b/Source/BuilderModes/VisualModes/VisualMiddleSingle.cs index fe19eb0c..23f36e8a 100644 --- a/Source/BuilderModes/VisualModes/VisualMiddleSingle.cs +++ b/Source/BuilderModes/VisualModes/VisualMiddleSingle.cs @@ -39,7 +39,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class VisualMiddleSingle : BaseVisualGeometry + internal sealed class VisualMiddleSingle : BaseVisualGeometrySidedef { #region ================== Constants @@ -47,9 +47,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables - private float top; - private float bottom; - #endregion #region ================== Properties @@ -59,14 +56,14 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Setup // Constructor - public VisualMiddleSingle(Sidedef s) : base(s) + public VisualMiddleSingle(VisualSector vs, Sidedef s) : base(vs, s) { // We have no destructor GC.SuppressFinalize(this); } // This builds the geometry. Returns false when no geometry created. - public bool Setup() + public override bool Setup() { // Calculate size of this wall part float geotop = (float)Sidedef.Sector.CeilHeight; @@ -140,8 +137,8 @@ namespace CodeImp.DoomBuilder.BuilderModes verts[5] = new WorldVertex(v2.x, v2.y, geobottom, pc.ToInt(), t2.x, t2.y); // Keep properties - this.top = geotop; - this.bottom = geobottom; + base.top = geotop; + base.bottom = geobottom; // Apply vertices base.SetVertices(verts); @@ -158,22 +155,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods - // This performs a fast test in object picking - public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) - { - // Check if intersection point is between top and bottom - return (pickintersect.z >= bottom) && (pickintersect.z <= top); - } - - // This performs an accurate test for object picking - public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) - { - // The fast reject pass is already as accurate as it gets, - // so we just return the intersection distance here - u_ray = pickrayu; - return true; - } - #endregion } } diff --git a/Source/BuilderModes/VisualModes/VisualUpper.cs b/Source/BuilderModes/VisualModes/VisualUpper.cs index 6b9be190..0014237e 100644 --- a/Source/BuilderModes/VisualModes/VisualUpper.cs +++ b/Source/BuilderModes/VisualModes/VisualUpper.cs @@ -39,7 +39,7 @@ using CodeImp.DoomBuilder.VisualModes; namespace CodeImp.DoomBuilder.BuilderModes { - internal class VisualUpper : BaseVisualGeometry + internal sealed class VisualUpper : BaseVisualGeometrySidedef { #region ================== Constants @@ -47,9 +47,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Variables - private float top; - private float bottom; - #endregion #region ================== Properties @@ -59,14 +56,14 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constructor / Setup // Constructor - public VisualUpper(Sidedef s) : base(s) + public VisualUpper(VisualSector vs, Sidedef s) : base(vs, s) { // We have no destructor GC.SuppressFinalize(this); } // This builds the geometry. Returns false when no geometry created. - public bool Setup() + public override bool Setup() { // Calculate size of this wall part float geotop = (float)Sidedef.Sector.CeilHeight; @@ -140,8 +137,8 @@ namespace CodeImp.DoomBuilder.BuilderModes verts[5] = new WorldVertex(v2.x, v2.y, geobottom, pc.ToInt(), t2.x, t2.y); // Keep properties - this.top = geotop; - this.bottom = geobottom; + base.top = geotop; + base.bottom = geobottom; // Apply vertices base.SetVertices(verts); @@ -158,22 +155,6 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Methods - // This performs a fast test in object picking - public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) - { - // Check if intersection point is between top and bottom - return (pickintersect.z >= bottom) && (pickintersect.z <= top); - } - - // This performs an accurate test for object picking - public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) - { - // The fast reject pass is already as accurate as it gets, - // so we just return the intersection distance here - u_ray = pickrayu; - return true; - } - #endregion } } diff --git a/Source/VisualModes/VisualGeometry.cs b/Source/VisualModes/VisualGeometry.cs index dfa07312..2bf55d1c 100644 --- a/Source/VisualModes/VisualGeometry.cs +++ b/Source/VisualModes/VisualGeometry.cs @@ -109,16 +109,18 @@ namespace CodeImp.DoomBuilder.VisualModes /// /// This creates sector-global visual geometry. This geometry is always visible when any of the sector is visible. /// - public VisualGeometry() + public VisualGeometry(VisualSector vs) { + this.sector = vs; } /// /// This creates visual geometry that is bound to a sidedef. This geometry is only visible when the sidedef is visible. It is automatically back-face culled during rendering and automatically XY intersection tested as well as back-face culled during object picking. /// /// - public VisualGeometry(Sidedef sd) + public VisualGeometry(VisualSector vs, Sidedef sd) { + this.sector = vs; this.sidedef = sd; } diff --git a/Source/VisualModes/VisualSector.cs b/Source/VisualModes/VisualSector.cs index 8b0806c7..64c5ba2d 100644 --- a/Source/VisualModes/VisualSector.cs +++ b/Source/VisualModes/VisualSector.cs @@ -177,7 +177,6 @@ namespace CodeImp.DoomBuilder.VisualModes public void AddGeometry(VisualGeometry geo) { updategeo = true; - geo.Sector = this; allgeometry.Add(geo); if(geo.Sidedef != null) { diff --git a/Source/Windows/MainForm.cs b/Source/Windows/MainForm.cs index c2eaf09f..91e66a2d 100644 --- a/Source/Windows/MainForm.cs +++ b/Source/Windows/MainForm.cs @@ -977,10 +977,11 @@ namespace CodeImp.DoomBuilder.Windows // Release and show the mouse Cursor.Clip = originalclip; + Cursor.Position = display.PointToScreen(new Point(display.ClientSize.Width / 2, display.ClientSize.Height / 2)); Cursor.Show(); } } - + // This requests exclusive mouse input public void StartExclusiveMouseInput() {