diff --git a/Craftimizer/Utils/SimulatedMacro.cs b/Craftimizer/Utils/SimulatedMacro.cs index 7e3f223..6a8aae7 100644 --- a/Craftimizer/Utils/SimulatedMacro.cs +++ b/Craftimizer/Utils/SimulatedMacro.cs @@ -192,12 +192,13 @@ internal sealed class SimulatedMacro state = Macro[i].Recalculate(sim, state); } - public void Enqueue(ActionType action) + public int Enqueue(ActionType action) { lock (QueueLock) { var lastState = QueuedSteps.Count > 0 ? QueuedSteps[^1].State : State; QueuedSteps.Add(new(action, CreateSim(), lastState, out _)); + return QueuedSteps.Count + Macro.Count; } } diff --git a/Craftimizer/Windows/MacroEditor.cs b/Craftimizer/Windows/MacroEditor.cs index 2dab731..ab6d09e 100644 --- a/Craftimizer/Windows/MacroEditor.cs +++ b/Craftimizer/Windows/MacroEditor.cs @@ -1554,7 +1554,7 @@ public sealed class MacroEditor : Window, IDisposable using (SolverObject = new Solver.Solver(config, state) { Token = token }) { SolverObject.OnLog += Log.Debug; - SolverObject.OnNewAction += Macro.Enqueue; + SolverObject.OnNewAction += a => Macro.Enqueue(a); SolverObject.Start(); _ = SolverObject.GetTask().GetAwaiter().GetResult(); } diff --git a/Craftimizer/Windows/Settings.cs b/Craftimizer/Windows/Settings.cs index 4bd3482..715948f 100644 --- a/Craftimizer/Windows/Settings.cs +++ b/Craftimizer/Windows/Settings.cs @@ -155,8 +155,8 @@ public sealed class Settings : Window, IDisposable { DrawTabGeneral(); DrawTabSimulator(); - //if (Config.EnableSynthHelper) - // DrawTabSynthHelper(); + if (Config.EnableSynthHelper) + DrawTabSynthHelper(); DrawTabAbout(); ImGui.EndTabBar(); @@ -173,22 +173,15 @@ public sealed class Settings : Window, IDisposable var isDirty = false; - - using (var g = ImRaii.Group()) - { - using var d = ImRaii.Disabled(); - DrawOption( - "Enable Synthesis Helper", - "Adds a helper next to your synthesis window to help solve for the best craft.\n" + - "Extremely useful for expert recipes, where the condition can greatly affect\n" + - "which actions you take.", - Config.EnableSynthHelper, - v => Config.EnableSynthHelper = v, - ref isDirty - ); - } - if (ImGui.IsItemHovered()) - ImGui.SetTooltip("Disabled temporarily for testing"); + DrawOption( + "Enable Synthesis Helper", + "Adds a helper next to your synthesis window to help solve for the best craft.\n" + + "Extremely useful for expert recipes, where the condition can greatly affect\n" + + "which actions you take.", + Config.EnableSynthHelper, + v => Config.EnableSynthHelper = v, + ref isDirty + ); DrawOption( "Show Only One Macro Stat in Crafting Log", diff --git a/Craftimizer/Windows/SynthHelper.cs b/Craftimizer/Windows/SynthHelper.cs index 66637f9..d5fdc77 100644 --- a/Craftimizer/Windows/SynthHelper.cs +++ b/Craftimizer/Windows/SynthHelper.cs @@ -153,7 +153,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable var pos = new Vector2(unit.X, unit.Y); var size = new Vector2(unit.WindowNode->AtkResNode.Width, unit.WindowNode->AtkResNode.Height) * scale; - var node = unit.GetNodeById(46); var offset = 5; Position = ImGuiHelpers.MainViewport.Pos + pos + new Vector2(size.X, offset * scale); @@ -206,7 +205,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable } if (ImGui.ImageButton(action.GetIcon(RecipeData!.ClassJob).ImGuiHandle, new(imageSize), default, Vector2.One, 0, default, failedAction ? new(1, 1, 1, ImGui.GetStyle().DisabledAlpha) : Vector4.One)) { - Log.Debug($"Clicked {action.GetName(RecipeData.ClassJob)} [{i}]"); if (i == 0) Chat.SendMessage($"/ac \"{action.GetName(RecipeData.ClassJob)}\""); } @@ -220,7 +218,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable lastState = state; } - for (var i = 0; i < 2; ++i) + var rows = (int)Math.Max(1, MathF.Ceiling(Service.Configuration.SynthHelperStepCount / itemsPerRow)); + for (var i = 0; i < rows; ++i) { if (Macro.Count <= i * itemsPerRow) ImGui.Dummy(new(0, imageSize)); @@ -524,7 +523,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable using (HelperTaskObject = new Solver.Solver(config, state) { Token = token }) { HelperTaskObject.OnLog += Log.Debug; - HelperTaskObject.OnNewAction += Macro.Enqueue; + HelperTaskObject.OnNewAction += EnqueueAction; HelperTaskObject.Start(); _ = HelperTaskObject.GetTask().GetAwaiter().GetResult(); } @@ -532,6 +531,12 @@ public sealed unsafe class SynthHelper : Window, IDisposable token.ThrowIfCancellationRequested(); } + private void EnqueueAction(ActionType action) + { + if (Macro.Enqueue(action) >= Service.Configuration.SynthHelperStepCount) + HelperTaskTokenSource?.Cancel(); + } + private static Sim CreateSim(in SimulationState state) => Service.Configuration.ConditionRandomness ? new Sim() { State = state } : new SimNoRandom() { State = state }; diff --git a/Solver/SolverConfig.cs b/Solver/SolverConfig.cs index 65274a9..391ea79 100644 --- a/Solver/SolverConfig.cs +++ b/Solver/SolverConfig.cs @@ -64,9 +64,6 @@ public readonly record struct SolverConfig public static readonly SolverConfig SynthHelperDefault = new SolverConfig() with { - Iterations = 300000, - ForkCount = Environment.ProcessorCount - 1, // Keep one for the game thread - FurcatedActionCount = Environment.ProcessorCount / 2, - Algorithm = SolverAlgorithm.StepwiseForked + // Add properties if necessary }; }