Implement synthhelper settings

This commit is contained in:
Asriel Camora
2023-11-15 03:50:25 -08:00
parent a1cdbdf5fc
commit 976df3cbae
5 changed files with 24 additions and 28 deletions
+2 -1
View File
@@ -192,12 +192,13 @@ internal sealed class SimulatedMacro
state = Macro[i].Recalculate(sim, state); state = Macro[i].Recalculate(sim, state);
} }
public void Enqueue(ActionType action) public int Enqueue(ActionType action)
{ {
lock (QueueLock) lock (QueueLock)
{ {
var lastState = QueuedSteps.Count > 0 ? QueuedSteps[^1].State : State; var lastState = QueuedSteps.Count > 0 ? QueuedSteps[^1].State : State;
QueuedSteps.Add(new(action, CreateSim(), lastState, out _)); QueuedSteps.Add(new(action, CreateSim(), lastState, out _));
return QueuedSteps.Count + Macro.Count;
} }
} }
+1 -1
View File
@@ -1554,7 +1554,7 @@ public sealed class MacroEditor : Window, IDisposable
using (SolverObject = new Solver.Solver(config, state) { Token = token }) using (SolverObject = new Solver.Solver(config, state) { Token = token })
{ {
SolverObject.OnLog += Log.Debug; SolverObject.OnLog += Log.Debug;
SolverObject.OnNewAction += Macro.Enqueue; SolverObject.OnNewAction += a => Macro.Enqueue(a);
SolverObject.Start(); SolverObject.Start();
_ = SolverObject.GetTask().GetAwaiter().GetResult(); _ = SolverObject.GetTask().GetAwaiter().GetResult();
} }
+11 -18
View File
@@ -155,8 +155,8 @@ public sealed class Settings : Window, IDisposable
{ {
DrawTabGeneral(); DrawTabGeneral();
DrawTabSimulator(); DrawTabSimulator();
//if (Config.EnableSynthHelper) if (Config.EnableSynthHelper)
// DrawTabSynthHelper(); DrawTabSynthHelper();
DrawTabAbout(); DrawTabAbout();
ImGui.EndTabBar(); ImGui.EndTabBar();
@@ -173,22 +173,15 @@ public sealed class Settings : Window, IDisposable
var isDirty = false; var isDirty = false;
DrawOption(
using (var g = ImRaii.Group()) "Enable Synthesis Helper",
{ "Adds a helper next to your synthesis window to help solve for the best craft.\n" +
using var d = ImRaii.Disabled(); "Extremely useful for expert recipes, where the condition can greatly affect\n" +
DrawOption( "which actions you take.",
"Enable Synthesis Helper", Config.EnableSynthHelper,
"Adds a helper next to your synthesis window to help solve for the best craft.\n" + v => Config.EnableSynthHelper = v,
"Extremely useful for expert recipes, where the condition can greatly affect\n" + ref isDirty
"which actions you take.", );
Config.EnableSynthHelper,
v => Config.EnableSynthHelper = v,
ref isDirty
);
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Disabled temporarily for testing");
DrawOption( DrawOption(
"Show Only One Macro Stat in Crafting Log", "Show Only One Macro Stat in Crafting Log",
+9 -4
View File
@@ -153,7 +153,6 @@ public sealed unsafe class SynthHelper : Window, IDisposable
var pos = new Vector2(unit.X, unit.Y); var pos = new Vector2(unit.X, unit.Y);
var size = new Vector2(unit.WindowNode->AtkResNode.Width, unit.WindowNode->AtkResNode.Height) * scale; var size = new Vector2(unit.WindowNode->AtkResNode.Width, unit.WindowNode->AtkResNode.Height) * scale;
var node = unit.GetNodeById(46);
var offset = 5; var offset = 5;
Position = ImGuiHelpers.MainViewport.Pos + pos + new Vector2(size.X, offset * scale); 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)) 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) if (i == 0)
Chat.SendMessage($"/ac \"{action.GetName(RecipeData.ClassJob)}\""); Chat.SendMessage($"/ac \"{action.GetName(RecipeData.ClassJob)}\"");
} }
@@ -220,7 +218,8 @@ public sealed unsafe class SynthHelper : Window, IDisposable
lastState = state; 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) if (Macro.Count <= i * itemsPerRow)
ImGui.Dummy(new(0, imageSize)); 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 }) using (HelperTaskObject = new Solver.Solver(config, state) { Token = token })
{ {
HelperTaskObject.OnLog += Log.Debug; HelperTaskObject.OnLog += Log.Debug;
HelperTaskObject.OnNewAction += Macro.Enqueue; HelperTaskObject.OnNewAction += EnqueueAction;
HelperTaskObject.Start(); HelperTaskObject.Start();
_ = HelperTaskObject.GetTask().GetAwaiter().GetResult(); _ = HelperTaskObject.GetTask().GetAwaiter().GetResult();
} }
@@ -532,6 +531,12 @@ public sealed unsafe class SynthHelper : Window, IDisposable
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
} }
private void EnqueueAction(ActionType action)
{
if (Macro.Enqueue(action) >= Service.Configuration.SynthHelperStepCount)
HelperTaskTokenSource?.Cancel();
}
private static Sim CreateSim(in SimulationState state) => private static Sim CreateSim(in SimulationState state) =>
Service.Configuration.ConditionRandomness ? new Sim() { State = state } : new SimNoRandom() { State = state }; Service.Configuration.ConditionRandomness ? new Sim() { State = state } : new SimNoRandom() { State = state };
+1 -4
View File
@@ -64,9 +64,6 @@ public readonly record struct SolverConfig
public static readonly SolverConfig SynthHelperDefault = new SolverConfig() with public static readonly SolverConfig SynthHelperDefault = new SolverConfig() with
{ {
Iterations = 300000, // Add properties if necessary
ForkCount = Environment.ProcessorCount - 1, // Keep one for the game thread
FurcatedActionCount = Environment.ProcessorCount / 2,
Algorithm = SolverAlgorithm.StepwiseForked
}; };
} }