Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Benchmark/Craftimizer.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.dotTrace" Version="0.15.8" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.15.8" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.264">
<PackageReference Include="Meziantou.Analyzer" Version="3.0.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ObjectLayoutInspector" Version="0.1.4" />
<PackageReference Include="ObjectLayoutInspector" Version="0.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Craftimizer/Craftimizer.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Dalamud.NET.Sdk/14.0.1">
<Project Sdk="Dalamud.NET.Sdk/15.0.0">
<PropertyGroup>
<Authors>Asriel Camora</Authors>
<Version>2.9.1.1</Version>
<Version>2.10.0.0</Version>
<PackageProjectUrl>https://github.com/WorkingRobot/Craftimizer.git</PackageProjectUrl>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
Expand Down Expand Up @@ -33,7 +33,7 @@

<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.264">
<PackageReference Include="Meziantou.Analyzer" Version="3.0.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
108 changes: 73 additions & 35 deletions Craftimizer/ImRaii2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,116 @@ namespace Craftimizer.Plugin;

public static class ImRaii2
{
private struct EndUnconditionally(Action endAction, bool success) : ImRaii.IEndObject, IDisposable
{
private Action EndAction { get; } = endAction;

public bool Success { get; } = success;
// Custom ref structs for each UI element.
// This eliminates the need for allocating 'Action' delegates and boxing.

public bool Disposed { get; private set; } = false;
public ref struct GroupPanelDisposable
{
private bool Disposed;

public void Dispose()
{
if (!Disposed)
{
EndAction();
Disposed = true;
}
if (Disposed) return;
ImGuiUtils.EndGroupPanel();
Disposed = true;
}

public static implicit operator bool(GroupPanelDisposable _) => true;
}

private struct EndConditionally(Action endAction, bool success) : ImRaii.IEndObject, IDisposable
public static GroupPanelDisposable GroupPanel(string name, float width, out float internalWidth)
{
public bool Success { get; } = success;
internalWidth = ImGuiUtils.BeginGroupPanel(name, width);
return new GroupPanelDisposable();
}

public bool Disposed { get; private set; } = false;
public ref struct PlotDisposable
{
public bool Success { get; }
private bool Disposed;

private Action EndAction { get; } = endAction;
public PlotDisposable(bool success)
{
Success = success;
Disposed = false;
}

public void Dispose()
{
if (!Disposed)
if (Disposed) return;
if (Success)
{
if (Success)
{
EndAction();
}

Disposed = true;
ImPlot.EndPlot();
}
Disposed = true;
}

// Allows you to do: using var plot = ImRaii2.Plot(...); if (plot) { ... }
public static implicit operator bool(PlotDisposable d) => d.Success;
}

public static ImRaii.IEndObject GroupPanel(string name, float width, out float internalWidth)
public static PlotDisposable Plot(string title_id, Vector2 size, ImPlotFlags flags)
{
internalWidth = ImGuiUtils.BeginGroupPanel(name, width);
return new EndUnconditionally(ImGuiUtils.EndGroupPanel, true);
return new PlotDisposable(ImPlot.BeginPlot(title_id, size, flags));
}

public static ImRaii.IEndObject Plot(string title_id, Vector2 size, ImPlotFlags flags)
public ref struct ImPlotStyleDisposable
{
return new EndConditionally(new Action(ImPlot.EndPlot), ImPlot.BeginPlot(title_id, size, flags));
private bool Disposed;

public void Dispose()
{
if (Disposed) return;
ImPlot.PopStyleVar();
Disposed = true;
}
}

public static ImRaii.IEndObject PushStyle(ImPlotStyleVar idx, Vector2 val)
public static ImPlotStyleDisposable PushStyle(ImPlotStyleVar idx, Vector2 val)
{
ImPlot.PushStyleVar(idx, val);
return new EndUnconditionally(ImPlot.PopStyleVar, true);
return new ImPlotStyleDisposable();
}

public static ImRaii.IEndObject PushStyle(ImPlotStyleVar idx, float val)
public static ImPlotStyleDisposable PushStyle(ImPlotStyleVar idx, float val)
{
ImPlot.PushStyleVar(idx, val);
return new EndUnconditionally(ImPlot.PopStyleVar, true);
return new ImPlotStyleDisposable();
}

public ref struct ImPlotColorDisposable
{
private bool Disposed;

public void Dispose()
{
if (Disposed) return;
ImPlot.PopStyleColor();
Disposed = true;
}
}

public static ImRaii.IEndObject PushColor(ImPlotCol idx, Vector4 col)
public static ImPlotColorDisposable PushColor(ImPlotCol idx, Vector4 col)
{
ImPlot.PushStyleColor(idx, col);
return new EndUnconditionally(ImPlot.PopStyleColor, true);
return new ImPlotColorDisposable();
}

public ref struct TextWrapPosDisposable
{
private bool Disposed;

public void Dispose()
{
if (Disposed) return;
ImGui.PopTextWrapPos();
Disposed = true;
}
}

public static ImRaii.IEndObject TextWrapPos(float wrap_local_pos_x)
public static TextWrapPosDisposable TextWrapPos(float wrap_local_pos_x)
{
ImGui.PushTextWrapPos(wrap_local_pos_x);
return new EndUnconditionally(ImGui.PopTextWrapPos, true);
return new TextWrapPosDisposable();
}
}
2 changes: 1 addition & 1 deletion Craftimizer/Utils/DynamicBars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static float GetTextSize(IEnumerable<BarData> bars) =>
defaultSize);
});

private static ImRaii.Color? PushCollectableColor(this in BarData bar, float collectability, bool colorUnmetThreshold = true)
private static ImRaii.ColorDisposable? PushCollectableColor(this in BarData bar, float collectability, bool colorUnmetThreshold = true)
{
if (bar.Collectability is not { } collectabilities)
return null;
Expand Down
2 changes: 1 addition & 1 deletion Craftimizer/Utils/SynthesisValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Component.GUI;
using System;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.AtkValueType;

namespace Craftimizer.Utils;

Expand Down
9 changes: 5 additions & 4 deletions Craftimizer/Windows/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public void SelectTab(string label)
SelectedTab = label;
}

private ImRaii.IEndObject TabItem(string label)
private ImRaii.TabItemDisposable TabItem(string label)
{
var isSelected = string.Equals(SelectedTab, label, StringComparison.Ordinal);
if (isSelected)
{
SelectedTab = null;
var open = true;
return ImRaii.TabItem(label, ref open, ImGuiTabItemFlags.SetSelected);
// Use the overload that takes flags directly without the 'ref bool'
return ImRaii.TabItem(label, ImGuiTabItemFlags.SetSelected);
}
return ImRaii.TabItem(label);
}
Expand Down Expand Up @@ -122,9 +122,10 @@ private static void DrawOption(string label, string tooltip, string value, Actio
private static void DrawOption<T>(string label, string tooltip, Func<T, string> getName, Func<T, string> getTooltip, T value, Action<T> setter, ref bool isDirty, params T[] excludedValues) where T : struct, Enum
{
ImGui.SetNextItemWidth(OptionWidth);
// ImRaii.Combo returns a ComboDisposable ref struct
using (var combo = ImRaii.Combo(label, getName(value)))
{
if (combo)
if (combo) // Uses the implicit bool operator
{
foreach (var type in Enum.GetValues<T>())
{
Expand Down
30 changes: 15 additions & 15 deletions Craftimizer/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"net10.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[14.0.1, )",
"resolved": "14.0.1",
"contentHash": "y0WWyUE6dhpGdolK3iKgwys05/nZaVf4ZPtIjpLhJBZvHxkkiE23zYRo7K7uqAgoK/QvK5cqF6l3VG5AbgC6KA=="
"requested": "[15.0.0, )",
"resolved": "15.0.0",
"contentHash": "411vwC8/X8Z/sQ2TI6v3SvOn66xFPeOjFn3Zn+h0d3Ox2t1kFm66AhDvmx/qcMwVrR+Hidxj0dadpQ2dgyXMBQ=="
},
"DotNet.ReproducibleBuilds": {
"type": "Direct",
"requested": "[1.2.39, )",
"resolved": "1.2.39",
"contentHash": "fcFN01tDTIQqDuTwr1jUQK/geofiwjG5DycJQOnC72i1SsLAk1ELe+apBOuZ11UMQG8YKFZG1FgvjZPbqHyatg=="
"requested": "[2.0.2, )",
"resolved": "2.0.2",
"contentHash": "VaHoEN6YHp0jXucxm67vfuRy8zo9ufiKSuaZ4ZudRi8xmWcEFMKxfCsg2nvYNvdISFTURDu+IHqADGh53+Bamw=="
},
"MathNet.Numerics": {
"type": "Direct",
Expand All @@ -22,16 +22,16 @@
},
"Meziantou.Analyzer": {
"type": "Direct",
"requested": "[2.0.264, )",
"resolved": "2.0.264",
"contentHash": "zRG13RDG446rZNdd/YjKRd4utpbjleRDUqNQSrX0etMnH8Rz9NBlXUpS5aR2ExoOokhNfkdOW8HpLzjLj5x0hQ=="
"requested": "[3.0.61, )",
"resolved": "3.0.61",
"contentHash": "Ed/5bKmY38QbQJgL9wmWnweX4mq3WaNYNq8kp4Hk/WPIFuLuK/P/dEB/ZnenQius+NNDXxTIiCXFPmQdLrHWMg=="
},
"DotNext": {
"type": "Transitive",
"resolved": "5.26.1",
"contentHash": "rcy6Yrpb64B7qYm/+D+4sfBUzwX/IOGeJBYReDL8/TAIp8aZrZPtXx8nwkYjWCuakYn2tBppwefIM6pd/cOnMw==",
"resolved": "6.1.0",
"contentHash": "oUvq/a1Fydh1dC2QtGp+opiG9XjzJNRctigtC60+PlKiqdVr3TOgkBIYy/U/Q3PfzmLudpsI2i1OdVSho9wbSQ==",
"dependencies": {
"System.IO.Hashing": "8.0.0"
"System.IO.Hashing": "10.0.3"
}
},
"Raphael.Net": {
Expand All @@ -41,8 +41,8 @@
},
"System.IO.Hashing": {
"type": "Transitive",
"resolved": "8.0.0",
"contentHash": "ne1843evDugl0md7Fjzy6QjJrzsjh46ZKbhf8GwBXb5f/gw97J4bxMs0NQKifDuThh/f0bZ0e62NPl1jzTuRqA=="
"resolved": "10.0.3",
"contentHash": "La6ICwsdTKhVX+LKN+pvFjQRR3LhLwq3uKdi2knjLzRyPYBSydF4cjXidYxIiTcDD6XVYdsBWQEI8ZxiZ/OdIg=="
},
"craftimizer.simulator": {
"type": "Project"
Expand All @@ -51,7 +51,7 @@
"type": "Project",
"dependencies": {
"Craftimizer.Simulator": "[1.0.0, )",
"DotNext": "[5.26.1, )",
"DotNext": "[6.1.0, )",
"Raphael.Net": "[4.1.0, )"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Simulator/Craftimizer.Simulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.264">
<PackageReference Include="Meziantou.Analyzer" Version="3.0.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Solver/Craftimizer.Solver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNext" Version="5.26.1" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.264">
<PackageReference Include="DotNext" Version="6.1.0" />
<PackageReference Include="Meziantou.Analyzer" Version="3.0.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions Test/Craftimizer.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.199">
<PackageReference Include="Meziantou.Analyzer" Version="3.0.61">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.8.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.8.3" />
<PackageReference Include="MSTest.TestAdapter" Version="4.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="4.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down