From: jpbruyere Date: Thu, 4 Feb 2016 21:45:22 +0000 (+0100) Subject: register LinkedListNode, prevent uneeded cyclic ref X-Git-Tag: 0.3~60 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=a705b3d79e7cbeb887353c4e107e32844b13d7a9;p=jp%2Fcrow.git register LinkedListNode, prevent uneeded cyclic ref --- diff --git a/UnitTest/NUnitCrowWindow.cs b/UnitTest/NUnitCrowWindow.cs index 999639cd..1325dcaf 100644 --- a/UnitTest/NUnitCrowWindow.cs +++ b/UnitTest/NUnitCrowWindow.cs @@ -416,7 +416,7 @@ namespace Crow #region ILayoutable implementation //TODO:uneeded list, should be removed - public List RegisteredLQIs { get; } = new List(); + public List> RegisteredLQINodes { get; } = new List>(); public void RegisterForLayouting (int layoutType) { throw new NotImplementedException (); } public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } public Rectangle ContextCoordinates (Rectangle r) diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index dd27d21a..92e944bb 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -166,7 +166,7 @@ namespace Crow } ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (RegisteredLQIs.Count () <= 0 && bmp==null) + if (RegisteredLQINodes.Count () <= 0 && bmp==null) this.RegisterForRedraw (); }else base.UpdateLayout(layoutType); diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index d96bdf29..b9b142c0 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -91,7 +91,7 @@ namespace Crow #region ILayoutable - public List RegisteredLQIs { get; } = new List(); + public List> RegisteredLQINodes { get; } = new List>(); //TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject // or we could add to the interface the mouse events [XmlIgnore]public ILayoutable Parent { @@ -492,10 +492,10 @@ namespace Crow return Bounds.Size; } void deleteLQI(int lt){ - LayoutingQueueItem[] lqis = this.RegisteredLQIs.Where (lq => (lt & (int)lq.LayoutType) > 0).ToArray (); + LinkedListNode[] lqis = this.RegisteredLQINodes.Where (n => (lt & (int)n.Value.LayoutType) > 0).ToArray (); for (int i = 0; i < lqis.Length; i++) { - Interface.LayoutingQueue.Remove (lqis [i].Node); - lqis [i].DeleteLayoutableRef(); + Interface.LayoutingQueue.Remove (lqis [i]); + RegisteredLQINodes.Remove (lqis [i]); } } /// clear current layoutingQueue items for object and @@ -514,10 +514,10 @@ namespace Crow Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this); else if (Bounds.Width < 0) //fit Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this); - else { - LayoutingQueueItem lqi = new LayoutingQueueItem (LayoutingType.Width, this); - lqi.Node = Interface.LayoutingQueue.AddFirst (lqi); - } + else + RegisteredLQINodes.Add( + Interface.LayoutingQueue.AddFirst ( + new LayoutingQueueItem (LayoutingType.Width, this))); } if ((layoutType & (int)LayoutingType.Height) > 0) { @@ -526,8 +526,10 @@ namespace Crow else if (Bounds.Height < 0) //fit Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Height, this); else{ - LayoutingQueueItem lqi = new LayoutingQueueItem (LayoutingType.Height, this); - lqi.Node = Interface.LayoutingQueue.AddFirst (lqi); + RegisteredLQINodes.Add( + Interface.LayoutingQueue.AddFirst ( + new LayoutingQueueItem (LayoutingType.Height, this))); + } } @@ -707,7 +709,7 @@ namespace Crow break; } //if no layouting remains in queue for item, registre for redraw - if (this.RegisteredLQIs.Count () <= 0 && bmp == null) + if (this.RegisteredLQINodes.Count () <= 0 && bmp == null) this.RegisterForRedraw (); } diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 08241d9c..1981fc60 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -137,7 +137,7 @@ namespace Crow if (layoutType == LayoutingType.PositionChildren) { ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (RegisteredLQIs.Count () <= 0 && bmp==null) + if (RegisteredLQINodes.Count () <= 0 && bmp==null) this.RegisterForRedraw (); }else base.UpdateLayout(layoutType); diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 3a7135e0..7bb30bce 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -13,7 +13,7 @@ namespace Crow IGOLibHost HostContainer { get; } - List RegisteredLQIs { get; } + List> RegisteredLQINodes { get; } void RegisterForLayouting(int layoutType); void UpdateLayout(LayoutingType layoutType); diff --git a/src/LayoutingQueue.cs b/src/LayoutingQueue.cs index 697c59aa..68372bbb 100644 --- a/src/LayoutingQueue.cs +++ b/src/LayoutingQueue.cs @@ -31,32 +31,31 @@ namespace Crow { } public void Enqueue(LayoutingType _lt, ILayoutable _object) - { - LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - lqi.Node = this.AddLast (lqi); + { + _object.RegisteredLQINodes.Add(this.AddLast (new LayoutingQueueItem (_lt, _object))); } - LayoutingQueueItem searchLqi(ILayoutable go, LayoutingType lt){ - return go.RegisteredLQIs.Where(lq => lq.LayoutType == lt).LastOrDefault(); + LinkedListNode searchLqi(ILayoutable go, LayoutingType lt){ + return go.RegisteredLQINodes.Where(n => n.Value.LayoutType == lt).LastOrDefault(); } public void EnqueueAfterParentSizing (LayoutingType _lt, ILayoutable _object) { LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - LayoutingQueueItem parentLqi = searchLqi (_object.Parent, _lt); + LinkedListNode parentLqi = searchLqi (_object.Parent, _lt); if (parentLqi == null) - lqi.Node = this.AddFirst (lqi); + _object.RegisteredLQINodes.Add(this.AddFirst (lqi)); else - lqi.Node = this.AddAfter (parentLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); } public void EnqueueBeforeParentSizing (LayoutingType _lt, ILayoutable _object) { LayoutingQueueItem lqi = new LayoutingQueueItem (_lt, _object); - LayoutingQueueItem parentLqi = searchLqi (_object.Parent, _lt); + LinkedListNode parentLqi = searchLqi (_object.Parent, _lt); if (parentLqi == null) - lqi.Node = this.AddLast (lqi); + _object.RegisteredLQINodes.Add(this.AddLast (lqi)); else - lqi.Node = this.AddBefore (parentLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddBefore (parentLqi, lqi)); } public void EnqueueAfterThisAndParentSizing (LayoutingType _lt, ILayoutable _object) { @@ -66,30 +65,30 @@ namespace Crow if (_lt == LayoutingType.Y) sizing = LayoutingType.Height; - LayoutingQueueItem parentLqi = searchLqi (_object.Parent, sizing); - LayoutingQueueItem thisLqi = searchLqi (_object, sizing); + LinkedListNode parentLqi = searchLqi (_object.Parent, sizing); + LinkedListNode thisLqi = searchLqi (_object, sizing); if (parentLqi == null) { if (thisLqi != null) - lqi.Node = this.AddAfter (thisLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (thisLqi, lqi)); else - lqi.Node = this.AddLast (lqi); + _object.RegisteredLQINodes.Add(this.AddLast (lqi)); } else { if (thisLqi == null) - lqi.Node = this.AddAfter (parentLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); else { switch (sizing) { case LayoutingType.Width: if (_object.Parent.getBounds().Width<0) - lqi.Node = this.AddAfter (parentLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); else - lqi.Node = this.AddAfter (thisLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (thisLqi, lqi)); break; case LayoutingType.Height: if (_object.Parent.getBounds().Height<0) - lqi.Node = this.AddAfter (parentLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (parentLqi, lqi)); else - lqi.Node = this.AddAfter (thisLqi.Node, lqi); + _object.RegisteredLQINodes.Add(this.AddAfter (thisLqi, lqi)); break; } } @@ -98,7 +97,7 @@ namespace Crow public LayoutingQueueItem Dequeue() { LayoutingQueueItem tmp = this.First.Value; - tmp.DeleteLayoutableRef (); + tmp.GraphicObject.RegisteredLQINodes.Remove(this.First); this.RemoveFirst (); return tmp; } diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 816d1923..80d04dc6 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -37,8 +37,7 @@ namespace Crow } public class LayoutingQueueItem - { - public LinkedListNode Node; + { public ILayoutable GraphicObject; public LayoutingType LayoutType; @@ -46,11 +45,8 @@ namespace Crow { LayoutType = _layoutType; GraphicObject = _graphicObject; - GraphicObject.RegisteredLQIs.Add (this); - } - public void DeleteLayoutableRef(){ - GraphicObject.RegisteredLQIs.Remove(this); } + public void ProcessLayouting() { #if DEBUG_LAYOUTING diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index fcd08f95..89df8ee4 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -553,7 +553,7 @@ namespace Crow #region ILayoutable implementation //TODO:uneeded list, should be removed - public List RegisteredLQIs { get; } = new List(); + public List> RegisteredLQINodes { get; } = new List>(); public void RegisterForLayouting (int layoutType) { throw new NotImplementedException (); } public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } public Rectangle ContextCoordinates (Rectangle r)