aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-10-05 12:08:56 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-10-05 12:08:57 +0200
commit4c15030701964aee1c1dc908d6fa4dcdbec16a12 (patch)
treeabc69bdd9cd0713d795a924d329b4466e31bbac6 /src
parent8dcac53903c37878d54d59066eb7f80da1d62bc7 (diff)
threaded combo, Monodevelop addin improve
Diffstat (limited to 'src')
-rw-r--r--src/CompilerServices/CompilerServices.cs1
-rw-r--r--src/GraphicObjects/Combobox.cs86
-rw-r--r--src/GraphicObjects/GenericStack.cs2
-rw-r--r--src/GraphicObjects/GraphicObject.cs59
-rw-r--r--src/GraphicObjects/ListBox.cs76
-rw-r--r--src/Interface.cs2
-rw-r--r--src/LayoutingQueueItem.cs1
-rwxr-xr-xsrc/OpenTKGameWindow.cs16
8 files changed, 164 insertions, 79 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs
index 22585f95..4b3a4448 100644
--- a/src/CompilerServices/CompilerServices.cs
+++ b/src/CompilerServices/CompilerServices.cs
@@ -426,7 +426,6 @@ namespace go
FieldInfo fiRefs = typeof(Interface).GetField("References");
il.Emit(OpCodes.Ldsfld, fiRefs);
il.Emit(OpCodes.Ldc_I4, dstIdx);
-
MethodInfo miGetRef = Interface.References.GetType().GetMethod("get_Item");
il.Emit(OpCodes.Callvirt, miGetRef);
il.Emit(OpCodes.Isinst, dstType);
diff --git a/src/GraphicObjects/Combobox.cs b/src/GraphicObjects/Combobox.cs
index c9781f71..02040570 100644
--- a/src/GraphicObjects/Combobox.cs
+++ b/src/GraphicObjects/Combobox.cs
@@ -16,6 +16,7 @@ using System.ComponentModel;
using System.Xml;
using System.IO;
using System.Collections;
+using System.Threading;
namespace go
{
@@ -146,40 +147,75 @@ namespace go
_list.registerForGraphicUpdate ();
if (data == null)
return;
+ if (SelectedIndex < 0)
+ return;
- #if DEBUG_LOAD_TIME
- Stopwatch loadingTime = new Stopwatch ();
- loadingTime.Start ();
- #endif
+ //force raise of changes
+ SelectedIndex = SelectedIndex;
- MemoryStream ms = new MemoryStream ();
- using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
- stream.CopyTo (ms);
+ pendingChildrenAddition = new Queue<GraphicObject> ();
+ threadedLoadingFinished = false;
- Type t = Interface.GetTopContainerOfGOMLStream (ms);
+ Thread t = new Thread (loadingThread);
+ t.Start ();
- foreach (var item in data) {
- ms.Seek(0,SeekOrigin.Begin);
- GraphicObject g = Interface.Load (ms, t, item);
- g.MouseClick += itemClick;
- _list.addChild(g);
- }
+ }
+ }
+ public override void UpdateLayout (LayoutingType layoutType)
+ {
+ CheckPendingChildrenAddition ();
+ base.UpdateLayout (layoutType);
+ }
+ internal void CheckPendingChildrenAddition()
+ {
+ if (pendingChildrenAddition == null)
+ return;
+ lock (pendingChildrenAddition) {
+ if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50)
+ return;
+ while (pendingChildrenAddition.Count > 0)
+ _list.addChild (pendingChildrenAddition.Dequeue ());
+ }
+ }
- ms.Dispose ();
+ volatile Queue<GraphicObject> pendingChildrenAddition;
+ volatile bool threadedLoadingFinished = false;
- if (SelectedIndex < 0)
- return;
+ void loadingThread()
+ {
+ #if DEBUG_LOAD_TIME
+ Stopwatch loadingTime = new Stopwatch ();
+ loadingTime.Start ();
+ #endif
- //force raise of changes
- SelectedIndex = SelectedIndex;
+ MemoryStream ms = new MemoryStream ();
+ lock (ItemTemplate) {
+ using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
+ stream.CopyTo (ms);
+ }
+
+ Type t = Interface.GetTopContainerOfGOMLStream (ms);
- #if DEBUG_LOAD_TIME
- loadingTime.Stop ();
- Debug.WriteLine("Listbox Loading: {0} ticks \t, {1} ms",
- loadingTime.ElapsedTicks,
- loadingTime.ElapsedMilliseconds);
- #endif
+ foreach (var item in data) {
+ ms.Seek(0,SeekOrigin.Begin);
+ GraphicObject g = Interface.Load (ms, t, item);
+ g.MouseClick += itemClick;
+
+ lock (pendingChildrenAddition) {
+ pendingChildrenAddition.Enqueue (g);
+ }
}
+
+ ms.Dispose ();
+
+ threadedLoadingFinished = true;
+
+ #if DEBUG_LOAD_TIME
+ loadingTime.Stop ();
+ Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
+ loadingTime.ElapsedTicks,
+ loadingTime.ElapsedMilliseconds, this.ToString());
+ #endif
}
public GraphicObject Overlay {
get { return _overlay; }
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs
index c6260c6b..f50a4427 100644
--- a/src/GraphicObjects/GenericStack.cs
+++ b/src/GraphicObjects/GenericStack.cs
@@ -100,6 +100,8 @@ namespace go
public override void RegisterForLayouting (int layoutType)
{
+ if (Parent == null)
+ return;
base.RegisterForLayouting (layoutType);
if ((layoutType & (int)LayoutingType.PositionChildren) > 0)
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 63d10122..0617e927 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -452,46 +452,46 @@ namespace go
{
if (Parent == null)
return;
-
- Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0);
+ lock (Interface.LayoutingQueue) {
+ Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this && (layoutType & (int)lq.LayoutType) > 0);
- if ((layoutType & (int)LayoutingType.Width) > 0) {
+ if ((layoutType & (int)LayoutingType.Width) > 0) {
- //force sizing to fit if parent is sizing on children and
- //this object has stretched size
- if (Parent.getBounds ().Width < 0 && Width == 0)
- Width = -1;
+ //force sizing to fit if parent is sizing on children and
+ //this object has stretched size
+ if (Parent.getBounds ().Width < 0 && Width == 0)
+ Width = -1;
- if (Bounds.Width == 0) //stretch in parent
+ if (Bounds.Width == 0) //stretch in parent
Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this);
- else if (Bounds.Width < 0) //fit
- Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this);
- else
- Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));
- }
+ else if (Bounds.Width < 0) //fit
+ Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this);
+ else
+ Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));
+ }
- if ((layoutType & (int)LayoutingType.Height) > 0) {
+ if ((layoutType & (int)LayoutingType.Height) > 0) {
- //force sizing to fit if parent is sizing on children
- if (Parent.getBounds ().Height < 0 && Height == 0)
- Height = -1;
+ //force sizing to fit if parent is sizing on children
+ if (Parent.getBounds ().Height < 0 && Height == 0)
+ Height = -1;
- if (Bounds.Height == 0) //stretch in parent
+ if (Bounds.Height == 0) //stretch in parent
Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this);
- else if (Bounds.Height < 0) //fit
+ else if (Bounds.Height < 0) //fit
Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Height, this);
- else
- Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));
- }
+ else
+ Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));
+ }
- if ((layoutType & (int)LayoutingType.X) > 0)
+ if ((layoutType & (int)LayoutingType.X) > 0)
//for x positionning, sizing of parent and this have to be done
Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.X, this);
- if ((layoutType & (int)LayoutingType.Y) > 0)
+ if ((layoutType & (int)LayoutingType.Y) > 0)
//for x positionning, sizing of parent and this have to be done
Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this);
-
+ }
}
/// <summary> trigger dependant sizing component update </summary>
@@ -629,10 +629,11 @@ namespace go
LastSlots.Height = Slot.Height;
break;
}
-
- //if no layouting remains in queue for item, registre for redraw
- if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null)
- this.RegisterForRedraw ();
+ lock (Interface.LayoutingQueue) {
+ //if no layouting remains in queue for item, registre for redraw
+ if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null)
+ this.RegisterForRedraw ();
+ }
}
/// <summary> This is the common overridable drawing routine to create new widget </summary>
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 9435ffbe..9f408b5a 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -26,6 +26,8 @@ using System.ComponentModel;
using System.IO;
using System.Diagnostics;
using System.Xml;
+using System.Collections.Generic;
+using System.Threading;
namespace go
{
@@ -84,33 +86,65 @@ namespace go
if (data == null)
return;
- #if DEBUG_LOAD_TIME
- Stopwatch loadingTime = new Stopwatch ();
- loadingTime.Start ();
- #endif
+ pendingChildrenAddition = new Queue<GraphicObject> ();
+ threadedLoadingFinished = false;
- MemoryStream ms = new MemoryStream ();
- using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
+ Thread t = new Thread (loadingThread);
+ t.Start ();
+
+ }
+ }
+
+ internal void CheckPendingChildrenAddition()
+ {
+ if (pendingChildrenAddition == null)
+ return;
+ lock (pendingChildrenAddition) {
+ if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50)
+ return;
+ while (pendingChildrenAddition.Count > 0)
+ _list.addChild (pendingChildrenAddition.Dequeue ());
+ }
+ }
+
+ volatile Queue<GraphicObject> pendingChildrenAddition;
+ volatile bool threadedLoadingFinished = false;
+
+ 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);
+ }
- foreach (var item in data) {
- ms.Seek(0,SeekOrigin.Begin);
- GraphicObject g = Interface.Load (ms, t, item);
- g.MouseClick += itemClick;
- _list.addChild(g);
- }
+ Type t = Interface.GetTopContainerOfGOMLStream (ms);
- ms.Dispose ();
+ foreach (var item in data) {
+ ms.Seek(0,SeekOrigin.Begin);
+ GraphicObject g = Interface.Load (ms, t, item);
+ g.MouseClick += itemClick;
- #if DEBUG_LOAD_TIME
- loadingTime.Stop ();
- Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
- loadingTime.ElapsedTicks,
- loadingTime.ElapsedMilliseconds, this.ToString());
- #endif
+ lock (pendingChildrenAddition) {
+ pendingChildrenAddition.Enqueue (g);
+ }
}
+
+ ms.Dispose ();
+
+ threadedLoadingFinished = true;
+
+ #if DEBUG_LOAD_TIME
+ loadingTime.Stop ();
+ Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
+ loadingTime.ElapsedTicks,
+ loadingTime.ElapsedMilliseconds, this.ToString());
+ #endif
}
void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){
diff --git a/src/Interface.cs b/src/Interface.cs
index 7712b577..9dccd969 100644
--- a/src/Interface.cs
+++ b/src/Interface.cs
@@ -424,6 +424,8 @@ namespace go
CurrentGOMLPath = "";
}
+
+
public static GraphicObject Load (Stream stream, Type type, object hostClass = null, bool resolve = true)
{
#if DEBUG_LOAD_TIME
diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs
index b028fb83..417a70ff 100644
--- a/src/LayoutingQueueItem.cs
+++ b/src/LayoutingQueueItem.cs
@@ -31,6 +31,7 @@ namespace go
Height = 0x08,
Sizing = 0x0C,
PositionChildren = 0x10,
+ ChildAddition = 0x20,
All = 0xFF
}
diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs
index ebe3735e..fc6f9916 100755
--- a/src/OpenTKGameWindow.cs
+++ b/src/OpenTKGameWindow.cs
@@ -260,9 +260,19 @@ namespace go
invGOList = invGOList.Reverse ().ToArray ();
//Debug.WriteLine ("======= Layouting queue start =======");
- while (Interface.LayoutingQueue.Count > 0) {
- LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
- lqi.ProcessLayouting ();
+ lock (Interface.LayoutingQueue) {
+ while (Interface.LayoutingQueue.Count > 0) {
+// Stopwatch lqiProcTime = new Stopwatch ();
+// lqiProcTime.Start ();
+ LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();
+ lqi.ProcessLayouting ();
+// lqiProcTime.Stop ();
+// if (lqiProcTime.ElapsedMilliseconds > 10) {
+// Debug.WriteLine("lqi {2}: {0} ticks \t, {1} ms",
+// updateTime.ElapsedTicks,
+// updateTime.ElapsedMilliseconds, lqi.ToString());
+// }
+ }
}
//Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");