Remove frame timers, fix underline color

This commit is contained in:
Asriel Camora
2023-07-15 23:09:17 +04:00
parent 5cd9f10917
commit 376a9fe7cb
5 changed files with 46 additions and 61 deletions
+2 -4
View File
@@ -145,17 +145,15 @@ internal static class ImGuiUtils
// https://gist.github.com/dougbinks/ef0962ef6ebe2cadae76c4e9f0586c69#file-imguiutils-h-L228 // https://gist.github.com/dougbinks/ef0962ef6ebe2cadae76c4e9f0586c69#file-imguiutils-h-L228
public static unsafe void Hyperlink(string text, string url) public static unsafe void Hyperlink(string text, string url)
{ {
ImGui.PushStyleColor(ImGuiCol.Text, *ImGui.GetStyleColorVec4(ImGuiCol.ButtonHovered));
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.PopStyleColor();
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ {
if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true }); Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.ButtonHovered)); UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Button));
ImGui.SetTooltip("Open in browser"); ImGui.SetTooltip("Open in browser");
} }
else else
UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Button)); UnderlineLastItem(*ImGui.GetStyleColorVec4(ImGuiCol.Text));
} }
} }
-13
View File
@@ -46,9 +46,6 @@ public unsafe class CraftingLog : Window
private static Food[] MedicineItems { get; } private static Food[] MedicineItems { get; }
private static Random Random { get; } private static Random Random { get; }
private TimeSpan FrameTime { get; set; }
private Stopwatch Stopwatch { get; } = new();
// Set in DrawConditions // Set in DrawConditions
private AddonRecipeNote* Addon { get; set; } private AddonRecipeNote* Addon { get; set; }
private RecipeNote* State { get; set; } private RecipeNote* State { get; set; }
@@ -191,8 +188,6 @@ public unsafe class CraftingLog : Window
DrawGearsets(); DrawGearsets();
ImGui.EndTable(); ImGui.EndTable();
ImGui.TextUnformatted($"{FrameTime.TotalMilliseconds:0.00}ms");
} }
private void DrawCraftInfo() private void DrawCraftInfo()
@@ -474,7 +469,6 @@ public unsafe class CraftingLog : Window
public override unsafe void PreDraw() public override unsafe void PreDraw()
{ {
Stopwatch.Restart();
ref var unit = ref Addon->AtkUnitBase; ref var unit = ref Addon->AtkUnitBase;
var scale = unit.Scale; var scale = unit.Scale;
var pos = new Vector2(unit.X, unit.Y); var pos = new Vector2(unit.X, unit.Y);
@@ -495,13 +489,6 @@ public unsafe class CraftingLog : Window
base.PreDraw(); base.PreDraw();
} }
public override void PostDraw()
{
Stopwatch.Stop();
FrameTime = Stopwatch.Elapsed;
base.PostDraw();
}
private Gearsets.GearsetStats CalculateConsumableBonus(CharacterStats stats) private Gearsets.GearsetStats CalculateConsumableBonus(CharacterStats stats)
{ {
static int CalculateBonus(int param, bool isHq, FoodStat? stat) static int CalculateBonus(int param, bool isHq, FoodStat? stat)
+44 -17
View File
@@ -66,7 +66,8 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Override uncraftability warning", "Override uncraftability warning",
"Allow simulation for crafts that otherwise wouldn't be able to be crafted with your current gear", "Allow simulation for crafts that otherwise wouldn't\n" +
"be able to be crafted with your current gear",
Config.OverrideUncraftability, Config.OverrideUncraftability,
v => Config.OverrideUncraftability = v, v => Config.OverrideUncraftability = v,
ref isDirty ref isDirty
@@ -74,7 +75,8 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Show only learned actions", "Show only learned actions",
"Don't show crafting actions that haven't been learned yet with your current job on the simulator sidebar", "Don't show crafting actions that haven't been\n" +
"learned yet with your current job on the simulator sidebar",
Config.HideUnlearnedActions, Config.HideUnlearnedActions,
v => Config.HideUnlearnedActions = v, v => Config.HideUnlearnedActions = v,
ref isDirty ref isDirty
@@ -113,7 +115,10 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Iterations", "Iterations",
"The total number of iterations to run per crafting step. Higher values require more computational power. Higher values also may decrease variance, so other values should be tweaked as necessary to get a more favorable outcome.", "The total number of iterations to run per crafting step.\n" +
"Higher values require more computational power. Higher values\n" +
"also may decrease variance, so other values should be tweaked\n" +
"as necessary to get a more favorable outcome.",
config.Iterations, config.Iterations,
v => config = config with { Iterations = v }, v => config = config with { Iterations = v },
ref isSolverDirty ref isSolverDirty
@@ -121,7 +126,9 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Score Storage Threshold", "Score Storage Threshold",
"If a craft achieves this certain arbitrary score, the solver will throw away all other possible combinations in favor of that one. Only change this value if you absolutely know what you're doing.", "If a craft achieves this certain arbitrary score, the solver will\n" +
"throw away all other possible combinations in favor of that one.\n" +
"Only change this value if you absolutely know what you're doing.",
config.ScoreStorageThreshold, config.ScoreStorageThreshold,
v => config = config with { ScoreStorageThreshold = v }, v => config = config with { ScoreStorageThreshold = v },
ref isSolverDirty ref isSolverDirty
@@ -129,7 +136,10 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Score Weighting Constant", "Score Weighting Constant",
"A constant ranging from 0 to 1 that configures how the solver scores and picks paths to travel to next. A value of 0 means actions will be chosen based on their average outcome, whereas 1 uses their best outcome achieved so far.", "A constant ranging from 0 to 1 that configures how the solver\n" +
"scores and picks paths to travel to next. A value of 0 means\n" +
"actions will be chosen based on their average outcome, whereas\n" +
"1 uses their best outcome achieved so far.",
config.MaxScoreWeightingConstant, config.MaxScoreWeightingConstant,
v => config = config with { MaxScoreWeightingConstant = v }, v => config = config with { MaxScoreWeightingConstant = v },
ref isSolverDirty ref isSolverDirty
@@ -137,7 +147,9 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Exploration Constant", "Exploration Constant",
"A constant that decides how often the solver will explore new, possibly good paths. If this value is too high, moves will mostly be decided at random.", "A constant that decides how often the solver will explore new,\n" +
"possibly good paths. If this value is too high,\n" +
"moves will mostly be decided at random.",
config.ExplorationConstant, config.ExplorationConstant,
v => config = config with { ExplorationConstant = v }, v => config = config with { ExplorationConstant = v },
ref isSolverDirty ref isSolverDirty
@@ -145,7 +157,11 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Max Step Count", "Max Step Count",
"The maximum number of crafting steps; this is generally the only setting you should change, and it should be set to around 5 steps more than what you'd expect. If this value is too low, the solver won't learn much per iteration; too high and it will waste time on useless extra steps.", "The maximum number of crafting steps; this is generally the only\n" +
"setting you should change, and it should be set to around 5 steps\n" +
"more than what you'd expect. If this value is too low, the solver\n" +
"won't learn much per iteration; too high and it will waste time\n" +
"on useless extra steps.",
config.MaxStepCount, config.MaxStepCount,
v => config = config with { MaxStepCount = v }, v => config = config with { MaxStepCount = v },
ref isSolverDirty ref isSolverDirty
@@ -153,7 +169,9 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Max Rollout Step Count", "Max Rollout Step Count",
"The maximum number of crafting steps every iteration can consider. Decreasing this value can have unintended side effects. Only change this value if you absolutely know what you're doing.", "The maximum number of crafting steps every iteration can consider.\n" +
"Decreasing this value can have unintended side effects. Only change\n" +
"this value if you absolutely know what you're doing.",
config.MaxRolloutStepCount, config.MaxRolloutStepCount,
v => config = config with { MaxRolloutStepCount = v }, v => config = config with { MaxRolloutStepCount = v },
ref isSolverDirty ref isSolverDirty
@@ -161,7 +179,12 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Fork Count", "Fork Count",
$"Split the number of iterations across different solvers. In general, you should increase this value to at least the number of cores in your system (FYI, you have {Environment.ProcessorCount} cores) to attain the most speedup. The higher the number, the more chance you have of finding a better local maximum; this concept similar but not equivalent to the exploration constant.", "Split the number of iterations across different solvers. In general,\n" +
"you should increase this value to at least the number of cores in\n" +
$"your system (FYI, you have {Environment.ProcessorCount} cores) to\n" +
"attain the most speedup. The higher the number, the more chance you\n" +
"have of finding a better local maximum; this concept similar but\n" +
"not equivalent to the exploration constant.",
config.ForkCount, config.ForkCount,
v => config = config with { ForkCount = v }, v => config = config with { ForkCount = v },
ref isSolverDirty ref isSolverDirty
@@ -169,7 +192,9 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Furcated Action Count", "Furcated Action Count",
"On every craft step, pick this many top solutions and use them as the input for the next craft step. For best results, use Fork Count / 2 and add about 1 or 2 more if needed.", "On every craft step, pick this many top solutions and use them as\n" +
"the input for the next craft step. For best results, use Fork Count / 2\n" +
"and add about 1 or 2 more if needed.",
config.FurcatedActionCount, config.FurcatedActionCount,
v => config = config with { FurcatedActionCount = v }, v => config = config with { FurcatedActionCount = v },
ref isSolverDirty ref isSolverDirty
@@ -177,17 +202,16 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Strict Actions", "Strict Actions",
"When finding the next possible actions to execute, use a heuristic to restrict which actions to attempt taking. This results in a much better macro at the cost of not finding an extremely creative one.", "When finding the next possible actions to execute, use a heuristic\n" +
"to restrict which actions to attempt taking. This results in a much\n" +
"better macro at the cost of not finding an extremely creative one.",
config.StrictActions, config.StrictActions,
v => config = config with { StrictActions = v }, v => config = config with { StrictActions = v },
ref isSolverDirty ref isSolverDirty
); );
ImGuiHelpers.ScaledDummy(15); ImGuiUtils.BeginGroupPanel("Score Weights");
ImGui.TextWrapped("All values must add up to 1. Otherwise, the Score Storage Threshold must be changed.");
ImGui.TextUnformatted("Score Weights");
ImGuiHelpers.ScaledDummy(5);
ImGui.TextUnformatted("All values must add up to 1. Otherwise, the Score Storage Threshold must be changed.");
ImGuiHelpers.ScaledDummy(10); ImGuiHelpers.ScaledDummy(10);
DrawOption( DrawOption(
@@ -224,12 +248,15 @@ public class SettingsWindow : Window
DrawOption( DrawOption(
"Steps", "Steps",
"Amount of weight to give to the craft's number of steps. The lower the step count, the higher the score.", "Amount of weight to give to the craft's number of steps. The lower\n" +
"the step count, the higher the score.",
config.ScoreFewerStepsBonus, config.ScoreFewerStepsBonus,
v => config = config with { ScoreFewerStepsBonus = v }, v => config = config with { ScoreFewerStepsBonus = v },
ref isSolverDirty ref isSolverDirty
); );
ImGuiUtils.EndGroupPanel();
if (ImGui.Button("Reset to defaults")) if (ImGui.Button("Reset to defaults"))
{ {
config = new(); config = new();
@@ -54,7 +54,6 @@ public sealed partial class SimulatorWindow : Window, IDisposable
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch); ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
DrawActions(); DrawActions();
ImGui.TextUnformatted($"{FrameTime.TotalMilliseconds:0.00}ms");
ImGui.TableNextColumn(); ImGui.TableNextColumn();
DrawSimulation(); DrawSimulation();
ImGui.EndTable(); ImGui.EndTable();
@@ -1,26 +0,0 @@
using Dalamud.Interface.Windowing;
using System;
using System.Diagnostics;
namespace Craftimizer.Plugin.Windows;
public sealed partial class SimulatorWindow : Window, IDisposable
{
private TimeSpan FrameTime { get; set; }
private Stopwatch Stopwatch { get; } = new();
public override void PreDraw()
{
Stopwatch.Restart();
base.PreDraw();
}
public override void PostDraw()
{
Stopwatch.Stop();
FrameTime = Stopwatch.Elapsed;
base.PostDraw();
}
}