From 8b0a9a6542e50fefe3678fdb6c7b44c2c39a9216 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Thu, 4 Feb 2016 19:35:36 +0100 Subject: [PATCH] remove threading for ListBox, not functionnal --- src/GraphicObjects/ListBox.cs | 104 +++++++++------------------------- src/Interface.cs | 1 - src/OpenTKGameWindow.cs | 7 --- 3 files changed, 26 insertions(+), 86 deletions(-) diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index a0ab540e..788d835f 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -75,98 +75,46 @@ namespace Crow get { return data; } - set { - if (loadingInProgress) { - thread.Join (); - Interface.LoadingLists.Remove (this); - pendingChildrenAddition = null; - loadingInProgress = false; - } - + set { + data = value; _list.ClearChildren (); if (data == null) return; - - pendingChildrenAddition = new Queue (); - threadedLoadingFinished = false; - Interface.LoadingLists.Add (this); - - thread = new Thread(loadingThread); - loadingInProgress = true; - thread.IsBackground = true; - thread.Start (); - thread.Join (); - } - } -// public override void UpdateLayout (LayoutingType layoutType) -// { -// CheckPendingChildrenAddition (); -// base.UpdateLayout (layoutType); -// } - internal void CheckPendingChildrenAddition() - { - if (!loadingInProgress) - return; - lock (pendingChildrenAddition) { - if (!threadedLoadingFinished && pendingChildrenAddition.Count < 10) - return; - while (pendingChildrenAddition.Count > 0) { - GraphicObject tmp = pendingChildrenAddition.Dequeue (); - tmp.DataSource = tmp.Tag; - tmp.Tag = null; - _list.addChild (tmp); - } - if (threadedLoadingFinished) { - Interface.LoadingLists.Remove (this); - pendingChildrenAddition = null; - loadingInProgress = false; + + #if DEBUG_LOAD_TIME + Stopwatch loadingTime = new Stopwatch (); + loadingTime.Start (); + #endif + + MemoryStream ms = new MemoryStream (); + lock (ItemTemplate) { + using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) + stream.CopyTo (ms); } - } - } - - Queue pendingChildrenAddition; - volatile bool threadedLoadingFinished = false; - volatile bool loadingInProgress = false; - Thread thread; - - void loadingThread() - { - #if DEBUG_LOAD_TIME - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - - MemoryStream ms = new MemoryStream (); - lock (ItemTemplate) { - using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) - stream.CopyTo (ms); - } - Type t = Interface.GetTopContainerOfGOMLStream (ms); + Type t = Interface.GetTopContainerOfGOMLStream (ms); - foreach (var item in data) { - ms.Seek(0,SeekOrigin.Begin); - GraphicObject g = Interface.Load (ms, t); - g.Tag = item; - g.MouseClick += itemClick; - lock (pendingChildrenAddition) { - pendingChildrenAddition.Enqueue (g); + foreach (var item in data) { + ms.Seek(0,SeekOrigin.Begin); + GraphicObject g = Interface.Load (ms, t); + g.DataSource = item; + g.MouseClick += itemClick; + _list.addChild (g); } - } - - ms.Dispose (); - threadedLoadingFinished = true; + ms.Dispose (); - #if DEBUG_LOAD_TIME - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", + #if DEBUG_LOAD_TIME + loadingTime.Stop (); + Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, this.ToString()); - #endif + #endif + + } } void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){ diff --git a/src/Interface.cs b/src/Interface.cs index 6d4d259b..e6be4220 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -53,7 +53,6 @@ namespace Crow /// Threshold to catch borders for sizing public static int BorderThreshold = 5; - public static List LoadingLists= new List(); public static LayoutingQueue LayoutingQueue = new LayoutingQueue (); #region Load/Save diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 587dd968..81bb0258 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -249,13 +249,6 @@ namespace Crow surf = new ImageSurface(bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height,ClientRectangle.Width*4); ctx = new Context(surf); - if (Interface.LoadingLists.Count > 0) { - ListBox[] loadings = new ListBox[Interface.LoadingLists.Count]; - Interface.LoadingLists.CopyTo (loadings, 0); - for (int i = 0; i < loadings.Length; i++) - loadings [i].CheckPendingChildrenAddition (); - } - GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count]; GraphicObjects.CopyTo (invGOList,0); invGOList = invGOList.Reverse ().ToArray (); -- 2.47.3