Use dedicated CreateSim to create new Sims

This commit is contained in:
Asriel Camora
2023-11-13 22:26:00 -08:00
parent 0db552fe8a
commit ecf3a1a952
+12 -9
View File
@@ -21,8 +21,8 @@ using System.Numerics;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using RandomSim = Craftimizer.Simulator.Simulator; using Sim = Craftimizer.Simulator.Simulator;
using Sim = Craftimizer.Simulator.SimulatorNoRandom; using SimNoRandom = Craftimizer.Simulator.SimulatorNoRandom;
namespace Craftimizer.Windows; namespace Craftimizer.Windows;
@@ -143,7 +143,7 @@ public sealed class MacroEditor : Window, IDisposable
for (var i = 0; i < iterCount; ++i) for (var i = 0; i < iterCount; ++i)
{ {
var sim = new RandomSim(startState); var sim = new Sim(startState);
var (_, state, _) = sim.ExecuteMultiple(startState, actions); var (_, state, _) = sim.ExecuteMultiple(startState, actions);
Progress.Add(state.Progress); Progress.Add(state.Progress);
Quality.Add(state.Quality); Quality.Add(state.Quality);
@@ -1003,7 +1003,7 @@ public sealed class MacroEditor : Window, IDisposable
private void DrawActionHotbars() private void DrawActionHotbars()
{ {
var sim = new Sim(State); var sim = CreateSim(State);
var imageSize = ImGui.GetFrameHeight() * 2; var imageSize = ImGui.GetFrameHeight() * 2;
var spacing = ImGui.GetStyle().ItemSpacing.Y; var spacing = ImGui.GetStyle().ItemSpacing.Y;
@@ -1248,7 +1248,7 @@ public sealed class MacroEditor : Window, IDisposable
} }
if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled))
{ {
var sim = new Sim(lastState); var sim = CreateSim(lastState);
ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n{actionBase.GetTooltip(sim, true)}"); ImGui.SetTooltip($"{action.GetName(RecipeData!.ClassJob)}\n{actionBase.GetTooltip(sim, true)}");
} }
lastState = state; lastState = state;
@@ -1601,12 +1601,15 @@ public sealed class MacroEditor : Window, IDisposable
private void RecalculateState() private void RecalculateState()
{ {
InitialState = new SimulationState(new(CharacterStats, RecipeData.RecipeInfo, StartingQuality)); InitialState = new SimulationState(new(CharacterStats, RecipeData.RecipeInfo, StartingQuality));
var sim = new Sim(InitialState); var sim = CreateSim(InitialState);
var lastState = InitialState; var lastState = InitialState;
for (var i = 0; i < Macro.Count; i++) for (var i = 0; i < Macro.Count; i++)
lastState = Macro[i].Recalculate(sim, lastState); lastState = Macro[i].Recalculate(sim, lastState);
} }
private Sim CreateSim(in SimulationState state) =>
Service.Configuration.ConditionRandomness ? new Sim(state) : new SimNoRandom(state);
private void AddStep(ActionType action, int index = -1, bool isSolver = false) private void AddStep(ActionType action, int index = -1, bool isSolver = false)
{ {
if (index < -1 || index >= Macro.Count) if (index < -1 || index >= Macro.Count)
@@ -1618,13 +1621,13 @@ public sealed class MacroEditor : Window, IDisposable
if (index == -1) if (index == -1)
{ {
var sim = new Sim(State); var sim = CreateSim(State);
Macro.Add(new(action, sim, State, out _)); Macro.Add(new(action, sim, State, out _));
} }
else else
{ {
var state = index == 0 ? InitialState : Macro[index - 1].State; var state = index == 0 ? InitialState : Macro[index - 1].State;
var sim = new Sim(state); var sim = CreateSim(state);
Macro.Insert(index, new(action, sim, state, out state)); Macro.Insert(index, new(action, sim, state, out state));
for (var i = index + 1; i < Macro.Count; i++) for (var i = index + 1; i < Macro.Count; i++)
@@ -1643,7 +1646,7 @@ public sealed class MacroEditor : Window, IDisposable
Macro.RemoveAt(index); Macro.RemoveAt(index);
var state = index == 0 ? InitialState : Macro[index - 1].State; var state = index == 0 ? InitialState : Macro[index - 1].State;
var sim = new Sim(state); var sim = CreateSim(state);
for (var i = index; i < Macro.Count; i++) for (var i = index; i < Macro.Count; i++)
state = Macro[i].Recalculate(sim, state); state = Macro[i].Recalculate(sim, state);
} }