diff --git a/Source/Core/Map/Sector.cs b/Source/Core/Map/Sector.cs index d6cf0ba1..a6759cca 100755 --- a/Source/Core/Map/Sector.cs +++ b/Source/Core/Map/Sector.cs @@ -87,6 +87,7 @@ namespace CodeImp.DoomBuilder.Map //mxd. Rendering private Color4 fogcolor; private SectorFogMode fogmode; + private int lastProcessed; //mxd. Slopes private Vector3D floorslope; @@ -142,6 +143,7 @@ namespace CodeImp.DoomBuilder.Map public float FloorSlopeOffset { get { return flooroffset; } set { BeforePropsChange(); flooroffset = value; updateneeded = true; } } public Vector3D CeilSlope { get { return ceilslope; } set { BeforePropsChange(); ceilslope = value; updateneeded = true; } } public float CeilSlopeOffset { get { return ceiloffset; } set { BeforePropsChange(); ceiloffset = value; updateneeded = true; } } + internal int LastProcessed { get { return lastProcessed; } set { lastProcessed = value; } } #endregion diff --git a/Source/Core/Map/Sidedef.cs b/Source/Core/Map/Sidedef.cs index 63e07abf..35d1adba 100755 --- a/Source/Core/Map/Sidedef.cs +++ b/Source/Core/Map/Sidedef.cs @@ -57,6 +57,9 @@ namespace CodeImp.DoomBuilder.Map // Clone private int serializedindex; + + // Rendering + private int lastProcessed; #endregion @@ -78,6 +81,7 @@ namespace CodeImp.DoomBuilder.Map public long LongMiddleTexture { get { return longtexnamemid; } } public long LongLowTexture { get { return longtexnamelow; } } internal int SerializedIndex { get { return serializedindex; } set { serializedindex = value; } } + internal int LastProcessed { get { return lastProcessed; } set { lastProcessed = value; } } #endregion diff --git a/Source/Core/Map/Thing.cs b/Source/Core/Map/Thing.cs index 8b650093..660fa26b 100755 --- a/Source/Core/Map/Thing.cs +++ b/Source/Core/Map/Thing.cs @@ -86,11 +86,14 @@ namespace CodeImp.DoomBuilder.Map private bool fixedsize; private bool directional; //mxd. If true, we need to render an arrow - #endregion + // Rendering + private int lastProcessed; - #region ================== Properties + #endregion - public MapSet Map { get { return map; } } + #region ================== Properties + + public MapSet Map { get { return map; } } public int Type { get { return type; } set { BeforePropsChange(); type = value; } } //mxd public GZGeneral.LightData DynamicLightType { get { return dynamiclighttype; } internal set { BeforePropsChange(); dynamiclighttype = value; } } public Vector3D Position { get { return pos; } } @@ -116,13 +119,14 @@ namespace CodeImp.DoomBuilder.Map public ThingRenderMode RenderMode { get { return rendermode; } } //mxd public bool IsDirectional { get { return directional; } } //mxd public bool Highlighted { get { return highlighted; } set { highlighted = value; } } //mxd + internal int LastProcessed { get { return lastProcessed; } set { lastProcessed = value; } } - #endregion + #endregion - #region ================== Constructor / Disposer + #region ================== Constructor / Disposer - // Constructor - internal Thing(MapSet map, int listindex) + // Constructor + internal Thing(MapSet map, int listindex) { // Initialize this.elementtype = MapElementType.THING; //mxd diff --git a/Source/Core/VisualModes/VisualMode.cs b/Source/Core/VisualModes/VisualMode.cs index 16ddbc9d..049eb8f9 100755 --- a/Source/Core/VisualModes/VisualMode.cs +++ b/Source/Core/VisualModes/VisualMode.cs @@ -73,8 +73,8 @@ namespace CodeImp.DoomBuilder.VisualModes protected Dictionary allthings; protected Dictionary allsectors; protected List visibleblocks; - protected Dictionary visiblethings; - protected Dictionary visiblesectors; + protected List visiblethings; + protected List visiblesectors; protected List visiblegeometry; #endregion @@ -104,9 +104,9 @@ namespace CodeImp.DoomBuilder.VisualModes this.allsectors = new Dictionary(General.Map.Map.Sectors.Count); this.allthings = new Dictionary(General.Map.Map.Things.Count); this.visibleblocks = new List(); - this.visiblesectors = new Dictionary(50); + this.visiblesectors = new List(50); this.visiblegeometry = new List(200); - this.visiblethings = new Dictionary(100); + this.visiblethings = new List(100); this.processgeometry = true; this.processthings = true; this.vertices = new Dictionary(); //mxd @@ -518,9 +518,9 @@ namespace CodeImp.DoomBuilder.VisualModes Vector2D campos2d = General.Map.VisualCamera.Position; // Make collections - visiblesectors = new Dictionary(visiblesectors.Count); - visiblegeometry = new List(visiblegeometry.Capacity); - visiblethings = new Dictionary(visiblethings.Count); + visiblesectors = new List(visiblesectors.Count * 2); + visiblegeometry = new List(visiblegeometry.Count * 2); + visiblethings = new List(visiblethings.Count * 2); // Get the blocks within view range visibleblocks = blockmap.GetFrustumRange(renderer.Frustum2D); @@ -534,7 +534,7 @@ namespace CodeImp.DoomBuilder.VisualModes foreach(Linedef ld in block.Lines) { // Line not already processed? - if (ld.LastProcessed != lastProcessed)//if(!visiblelines.Contains(ld)) + if (ld.LastProcessed != lastProcessed) { // Add line if not added yet ld.LastProcessed = lastProcessed; @@ -560,6 +560,10 @@ namespace CodeImp.DoomBuilder.VisualModes // Things foreach(Thing t in block.Things) { + if (t.LastProcessed == lastProcessed) continue; + + t.LastProcessed = lastProcessed; + // Not filtered out? if(!General.Map.ThingsFilter.IsThingVisible(t)) continue; @@ -575,9 +579,9 @@ namespace CodeImp.DoomBuilder.VisualModes allthings[t] = vt; } - if(vt != null && !visiblethings.ContainsKey(vt.Thing)) + if(vt != null) { - visiblethings[vt.Thing] = vt; + visiblethings.Add(vt); } } } @@ -630,7 +634,13 @@ namespace CodeImp.DoomBuilder.VisualModes // This finds and adds visible sectors private void ProcessSidedefCulling(Sidedef sd) { - VisualSector vs; + // Do nothing if we already added it. + if (sd.LastProcessed == lastProcessed) + return; + + sd.LastProcessed = lastProcessed; + + VisualSector vs; // Find the visualsector and make it if needed if(allsectors.ContainsKey(sd.Sector)) @@ -647,12 +657,12 @@ namespace CodeImp.DoomBuilder.VisualModes if(vs != null) { - // Add to visible sectors if not added yet - if(!visiblesectors.ContainsKey(sd.Sector)) - { - visiblesectors.Add(sd.Sector, vs); - visiblegeometry.AddRange(vs.FixedGeometry); - } + if (sd.Sector.LastProcessed != lastProcessed) + { + sd.Sector.LastProcessed = lastProcessed; + visiblesectors.Add(vs); + visiblegeometry.AddRange(vs.FixedGeometry); + } // Add sidedef geometry visiblegeometry.AddRange(vs.GetSidedefGeometry(sd)); @@ -805,7 +815,7 @@ namespace CodeImp.DoomBuilder.VisualModes } // Add all the visible things - foreach(VisualThing vt in visiblethings.Values) pickables.Add(vt); + foreach(VisualThing vt in visiblethings) pickables.Add(vt); //mxd. And all visual vertices if(General.Map.UDMF && General.Settings.GZShowVisualVertices) diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index 05a49bb9..01d1f065 100755 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -1340,7 +1340,7 @@ namespace CodeImp.DoomBuilder.BuilderModes renderer.DrawThingCages = ((BuilderPlug.Me.ShowVisualThings & 2) != 0); // Render all visible things - foreach(VisualThing t in visiblethings.Values) + foreach(VisualThing t in visiblethings) renderer.AddThingGeometry(t); } @@ -1551,9 +1551,9 @@ namespace CodeImp.DoomBuilder.BuilderModes if(sectordata != null && sectordata.Count > 0) RebuildElementData(); //mxd. As well as geometry... - foreach(KeyValuePair group in visiblesectors) + foreach(VisualSector sector in visiblesectors) { - BaseVisualSector vs = (BaseVisualSector)group.Value; + BaseVisualSector vs = (BaseVisualSector)sector; if(vs != null) vs.Rebuild(); } @@ -1572,9 +1572,9 @@ namespace CodeImp.DoomBuilder.BuilderModes if(sectordata != null && sectordata.Count > 0) RebuildElementData(); //mxd. As well as geometry... - foreach(KeyValuePair group in visiblesectors) + foreach(VisualSector sector in visiblesectors) { - BaseVisualSector vs = (BaseVisualSector)group.Value; + BaseVisualSector vs = (BaseVisualSector)sector; if(vs != null) vs.Rebuild(); } @@ -3264,7 +3264,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach (IVisualEventReceiver i in objs) { if (i is BaseVisualThing) - visiblethings.Remove(((BaseVisualThing)i).Thing); // [ZZ] if any + visiblethings.Remove((BaseVisualThing)i); // [ZZ] if any i.OnDelete(); } PostAction(); @@ -3305,7 +3305,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(IVisualEventReceiver i in objs) { BaseVisualThing thing = (BaseVisualThing)i; - visiblethings.Remove(thing.Thing); // [ZZ] if any + visiblethings.Remove(thing); // [ZZ] if any thing.Thing.Fields.BeforeFieldsChange(); thing.Thing.Dispose(); thing.Dispose();