diff --git a/Source/BuilderModes/Testing/TriangulatorMode.cs b/Source/BuilderModes/Testing/TriangulatorMode.cs index bf352516..9d565eba 100644 --- a/Source/BuilderModes/Testing/TriangulatorMode.cs +++ b/Source/BuilderModes/Testing/TriangulatorMode.cs @@ -313,7 +313,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing renderer.PlotVerticesSet(General.Map.Map.Vertices); // Go for all triangle vertices - for(int i = 0; i < t.Vertices.Length; i += 3) + for(int i = 0; i < t.Vertices.Count; i += 3) { renderer.PlotLine(t.Vertices[i + 0], t.Vertices[i + 1], General.Colors.Selection); renderer.PlotLine(t.Vertices[i + 1], t.Vertices[i + 2], General.Colors.Selection); diff --git a/Source/BuilderModes/VisualModes/VisualCeiling.cs b/Source/BuilderModes/VisualModes/VisualCeiling.cs index 50b18733..d4deb28e 100644 --- a/Source/BuilderModes/VisualModes/VisualCeiling.cs +++ b/Source/BuilderModes/VisualModes/VisualCeiling.cs @@ -64,8 +64,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing base.Texture = General.Map.Data.GetFlatImage(s.LongCeilTexture); // Make vertices - verts = new WorldVertex[s.Triangles.Vertices.Length]; - for(int i = 0; i < s.Triangles.Vertices.Length; i++) + verts = new WorldVertex[s.Triangles.Vertices.Count]; + for(int i = 0; i < s.Triangles.Vertices.Count; i++) { // Use sector brightness for color shading PixelColor pc = new PixelColor(255, unchecked((byte)s.Brightness), unchecked((byte)s.Brightness), unchecked((byte)s.Brightness)); diff --git a/Source/BuilderModes/VisualModes/VisualFloor.cs b/Source/BuilderModes/VisualModes/VisualFloor.cs index f53cdf16..dbcda0c6 100644 --- a/Source/BuilderModes/VisualModes/VisualFloor.cs +++ b/Source/BuilderModes/VisualModes/VisualFloor.cs @@ -63,8 +63,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing base.Texture = General.Map.Data.GetFlatImage(s.LongFloorTexture); // Make vertices - verts = new WorldVertex[s.Triangles.Vertices.Length]; - for(int i = 0; i < s.Triangles.Vertices.Length; i++) + verts = new WorldVertex[s.Triangles.Vertices.Count]; + for(int i = 0; i < s.Triangles.Vertices.Count; i++) { // Use sector brightness for color shading PixelColor pc = new PixelColor(255, unchecked((byte)s.Brightness), unchecked((byte)s.Brightness), unchecked((byte)s.Brightness)); diff --git a/Source/Geometry/Tools.cs b/Source/Geometry/Tools.cs index c3795dc2..d98ce93c 100644 --- a/Source/Geometry/Tools.cs +++ b/Source/Geometry/Tools.cs @@ -631,7 +631,7 @@ namespace CodeImp.DoomBuilder.Geometry if(triangles != null) { // Go for all islands - for(int island = 0; island < triangles.IslandVertices.Length; island++) + for(int island = 0; island < triangles.IslandVertices.Count; island++) { Dictionary sides = new Dictionary(triangles.IslandVertices[island] >> 1); List candidatelines = new List(triangles.IslandVertices[island] >> 1); @@ -641,7 +641,7 @@ namespace CodeImp.DoomBuilder.Geometry // Make candidate lines that are not along sidedefs // We do this before testing the candidate against the sidedefs so that // we can collect the relevant sidedefs first in the same run - for(int i = 0; i < triangles.Vertices.Length; i += 3) + for(int i = 0; i < triangles.Vertices.Count; i += 3) { Vector2D v1 = triangles.Vertices[i + 2]; for(int k = 0; k < 3; k++) diff --git a/Source/Geometry/Triangulation.cs b/Source/Geometry/Triangulation.cs index f2ea4148..d9785104 100644 --- a/Source/Geometry/Triangulation.cs +++ b/Source/Geometry/Triangulation.cs @@ -26,6 +26,7 @@ using CodeImp.DoomBuilder.Rendering; using SlimDX.Direct3D9; using System.Drawing; using CodeImp.DoomBuilder.Map; +using System.Collections.ObjectModel; #endregion @@ -62,23 +63,23 @@ namespace CodeImp.DoomBuilder.Geometry #region ================== Variables // Number of vertices per island - private int[] islandvertices; + private ReadOnlyCollection islandvertices; // Vertices that result from the triangulation, 3 per triangle. - private Vector2D[] vertices; + private ReadOnlyCollection vertices; // These sidedefs match with the vertices. If a vertex is not the start // along a sidedef, this list contains a null entry for that vertex. - private Sidedef[] sidedefs; + private ReadOnlyCollection sidedefs; #endregion #region ================== Properties - - public int[] IslandVertices { get { return islandvertices; } } - public Vector2D[] Vertices { get { return vertices; } } - public Sidedef[] Sidedefs { get { return sidedefs; } } - + + public ReadOnlyCollection IslandVertices { get { return islandvertices; } } + public ReadOnlyCollection Vertices { get { return vertices; } } + public ReadOnlyCollection Sidedefs { get { return sidedefs; } } + #endregion #region ================== Constructor / Disposer @@ -127,9 +128,9 @@ namespace CodeImp.DoomBuilder.Geometry islandslist.Add(DoEarClip(p, verticeslist, sidedefslist)); // Make arrays - islandvertices = islandslist.ToArray(); - vertices = verticeslist.ToArray(); - sidedefs = sidedefslist.ToArray(); + islandvertices = Array.AsReadOnly(islandslist.ToArray()); + vertices = Array.AsReadOnly(verticeslist.ToArray()); + sidedefs = Array.AsReadOnly(sidedefslist.ToArray()); } #endregion @@ -595,7 +596,7 @@ namespace CodeImp.DoomBuilder.Geometry t = GetTriangle(v); // Add ear as triangle - AddTriangleToList(t, verticeslist, sidedefslist, (verts.Count > 3)); + AddTriangleToList(t, verticeslist, sidedefslist, (verts.Count == 3)); countvertices += 3; // Remove this ear from all lists @@ -694,7 +695,7 @@ namespace CodeImp.DoomBuilder.Geometry verticeslist.Add(triangle[1].Position); sidedefslist.Add(triangle[1].Sidedef); verticeslist.Add(triangle[2].Position); - if(last) sidedefslist.Add(null); else sidedefslist.Add(triangle[2].Sidedef); + if(!last) sidedefslist.Add(null); else sidedefslist.Add(triangle[2].Sidedef); // Modify the first earclipvertex of this triangle, it no longer lies along a sidedef triangle[0].Sidedef = null; diff --git a/Source/Map/Sector.cs b/Source/Map/Sector.cs index 05ab1a62..005fde0c 100644 --- a/Source/Map/Sector.cs +++ b/Source/Map/Sector.cs @@ -229,8 +229,8 @@ namespace CodeImp.DoomBuilder.Map int brightint = brightcolor.ToInt(); // Make vertices - flatvertices = new FlatVertex[triangles.Vertices.Length]; - for(int i = 0; i < triangles.Vertices.Length; i++) + flatvertices = new FlatVertex[triangles.Vertices.Count]; + for(int i = 0; i < triangles.Vertices.Count; i++) { flatvertices[i].x = triangles.Vertices[i].x; flatvertices[i].y = triangles.Vertices[i].y;