Changeset - 5e28ba3945f7
[Not reviewed]
default
0 1 0
Jason Maltzen - 3 years ago 2021-09-10 00:03:21
jason@hiddenachievement.com
Recipe count is now a ulong instead of an int so it can show values > 2.47 billion. Also, don't allow clearing the recipe list while the recipe generator is running.
1 file changed with 12 insertions and 6 deletions:
0 comments (0 inline, 0 general)
ViewModels/RecipeGeneratorViewModel.cs
Show inline comments
...
 
@@ -87,13 +87,13 @@ namespace DesertPaintCodex.ViewModels
 

	
 
        private DateTime _lastSave = DateTime.Now;
 
        private readonly PlayerProfile _profile;
 
        private uint _minConcentration;
 

	
 
        private readonly ConcurrentQueue<PaintRecipe> _pendingNewRecipes = new();
 
        private volatile int _newRecipeCount;
 
        private ulong _newRecipeCount;
 
        private volatile bool _updatesAvailable;
 
        private readonly DispatcherTimer _updateTimer;
 
        
 
        private bool _ribbonMode;
 
        private bool _unsavedRecipes;
 
        private bool _saving;
...
 
@@ -152,12 +152,14 @@ namespace DesertPaintCodex.ViewModels
 
            if (logGenerator)
 
            {
 
                string logDir = DesertPaintCodex.Util.FileUtils.AppDataPath;
 
                _generator.Log = System.IO.Path.Combine(logDir, "recipe_generator_log.txt");
 
            }
 

	
 
            CanClear = false;
 

	
 
            _generator.BeginRecipeGeneration(
 
                _minConcentration, 
 
                (uint)MaxConcentration, 
 
                1, 
 
                (uint)MaxReagents, 
 
                (uint)FullQuantityDepth, 
...
 
@@ -198,12 +200,13 @@ namespace DesertPaintCodex.ViewModels
 
            if (logGenerator)
 
            {
 
                string logDir = DesertPaintCodex.Util.FileUtils.AppDataPath;
 
                _generator.Log = System.IO.Path.Combine(logDir, "recipe_generator_log.txt");
 
            }
 

	
 
            CanClear = false;
 
            _generator.ResumeRecipeGeneration();
 

	
 
        }
 

	
 
        public async Task Clear()
 
        {
...
 
@@ -296,13 +299,13 @@ namespace DesertPaintCodex.ViewModels
 
            }
 
        }
 

	
 
        #region Event Handlers
 
        private void OnProgress(object? sender, EventArgs args)
 
        {
 
            _newRecipeCount = (int)_generator.RecipeCount;
 
            _newRecipeCount = _generator.RecipeCount;
 
            _updatesAvailable = true;
 
        }
 

	
 
        private void OnNewRecipe(object? sender, NewRecipeEventArgs args)
 
        {
 
            PaintRecipe recipe = new(args.Recipe);
...
 
@@ -310,12 +313,13 @@ namespace DesertPaintCodex.ViewModels
 
            _updatesAvailable = true;
 
        }
 
        
 
        
 
        private void OnGeneratorStopped(object? sender, EventArgs args)
 
        {
 
            Debug.WriteLine($"Generator stopped. Saving = {_saving}");
 
            if (_saving)
 
            {
 
                SaveState();
 

	
 
                _generator.ResumeRecipeGeneration();
 
                _lastSave = DateTime.Now;
...
 
@@ -343,13 +347,14 @@ namespace DesertPaintCodex.ViewModels
 

	
 
            _updatesAvailable = false;
 

	
 
            DateTime now = DateTime.Now;
 

	
 
            // Update test count.
 
            PermutationCount = $"{_newRecipeCount:n0}";
 
            ulong newRecipeCount = _newRecipeCount;
 
            PermutationCount = $"{newRecipeCount:n0}";
 
            
 
            // Pull in new recipes.
 
            if (!_pendingNewRecipes.IsEmpty)
 
            {
 
                GeneratorRecipe? lastRecipe = null;
 
                while (_pendingNewRecipes.TryDequeue(out PaintRecipe? newRecipe))
...
 
@@ -384,18 +389,19 @@ namespace DesertPaintCodex.ViewModels
 
            
 
            // Save if it is time.
 
            if (!((now - _lastSave).TotalMilliseconds > SaveInterval)) return;
 
            
 
            if (_unsavedRecipes)
 
            {
 
                Debug.WriteLine("Saving generator state.");
 
                _saving = true;
 
                _generator.Stop();
 

	
 
                _profile.SaveRecipes();
 
                _unsavedRecipes = false;
 
            }
 

	
 
            _saving = true;
 
            _generator.Stop();
 
        }
 
        
 
        #endregion
 

	
 

	
 
        private void SavePaintSettings()
0 comments (0 inline, 0 general)