# HG changeset patch
# User Jason Maltzen <jason.maltzen@unsanctioned.net>
# Date 2016-01-15 17:25:49
# Node ID c9ad5ae6640aa6b4b9c45ffea8c052a24953dc6e
# Parent  0f6c1ddd4b2a04e688056e9be3cae346dda5b3e0

Add a thread count for paint recipe generation to settings

diff --git a/RecipeGenerator.cs b/RecipeGenerator.cs
--- a/RecipeGenerator.cs
+++ b/RecipeGenerator.cs
@@ -70,6 +70,8 @@ namespace DesertPaintLab
         public uint FullQuantityDepth { get; private set; } // at or equal this number of reagents, ignore ingredient settings for max quantity
         public uint FullQuantity { get; private set; }  // The max number of a reagent to use at full quantity
 
+        public uint MaxThreads { get; set; }
+
         ReactionSet reactions;
         bool running = false;
 
@@ -270,7 +272,7 @@ namespace DesertPaintLab
             }
             runningThreads = 0; // presumably!
 
-            int threadCount = Math.Min(costSortedReagents.Count, searchQueue.Count);
+            int threadCount = Math.Min(Math.Min(costSortedReagents.Count, searchQueue.Count), (int)MaxThreads);
             if (threadCount == 0)
             {
                 if (Finished != null)
@@ -279,9 +281,11 @@ namespace DesertPaintLab
                 }
             }
             generatorThreads.Clear();
+            System.Console.WriteLine("Starting {0} generator threads.", threadCount);
             for (int i = 0; i < threadCount; ++i)
             {
                 Thread thr = new Thread(new ThreadStart(this.Generate));
+                thr.Priority = ThreadPriority.BelowNormal;
                 generatorThreads.Add(thr);
             }
             foreach (Thread thr in generatorThreads)
diff --git a/RecipeGeneratorWindow.cs b/RecipeGeneratorWindow.cs
--- a/RecipeGeneratorWindow.cs
+++ b/RecipeGeneratorWindow.cs
@@ -116,6 +116,10 @@ namespace DesertPaintLab
             pauseForCheckpoint = false;
 
             generator = new RecipeGenerator(profile.Reactions);
+            int threads;
+            DesertPaintLab.Settings.Get("GeneratorThreads", out threads);
+            if (threads <= 0) { threads = 15; }
+            generator.MaxThreads = (uint)threads;
             generator.InitRecipes(profile.Recipes);
 
             generator.Progress += OnProgress;