Make DtrBar more threadsafe (#1978)

* Changed DtrBar to use ReaderWriterLockSlim so that there exists only one storage of entries, preventing possible desync.
* DtrBarEntry will now hold a reference to the LocalPlugin that created the entry, so that DtrBarPluginScoped can defer plugin related handling to the main service.
* Marked DtrBarEntry class itself to be turned internal in API 11.
* Made IDtrBar.Entries return an immutable copy of underlying list of DtrBar entries, that will be freshly created whenever the list changes.
This commit is contained in:
srkizer 2024-07-28 21:14:37 +09:00 committed by GitHub
parent a7ab3b9def
commit c25f13261d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 385 additions and 207 deletions

View file

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using CheapLoc;
using Dalamud.Configuration.Internal;
@ -45,6 +46,10 @@ public class SettingsTabDtr : SettingsTab
}
var isOrderChange = false;
Span<Vector2> upButtonCenters = stackalloc Vector2[order.Count];
Span<Vector2> downButtonCenters = stackalloc Vector2[order.Count];
scoped Span<Vector2> moveMouseTo = default;
var moveMouseToIndex = -1;
for (var i = 0; i < order.Count; i++)
{
var title = order[i];
@ -65,9 +70,13 @@ public class SettingsTabDtr : SettingsTab
{
(order[i], order[i - 1]) = (order[i - 1], order[i]);
isOrderChange = true;
moveMouseToIndex = i - 1;
moveMouseTo = upButtonCenters;
}
}
upButtonCenters[i] = (ImGui.GetItemRectMin() + ImGui.GetItemRectMax()) / 2;
ImGui.SameLine();
var arrowDownText = $"{FontAwesomeIcon.ArrowDown.ToIconString()}##{title}";
@ -81,9 +90,13 @@ public class SettingsTabDtr : SettingsTab
{
(order[i], order[i + 1]) = (order[i + 1], order[i]);
isOrderChange = true;
moveMouseToIndex = i + 1;
moveMouseTo = downButtonCenters;
}
}
downButtonCenters[i] = (ImGui.GetItemRectMin() + ImGui.GetItemRectMax()) / 2;
ImGui.PopFont();
ImGui.SameLine();
@ -107,6 +120,12 @@ public class SettingsTabDtr : SettingsTab
// }
}
if (moveMouseToIndex >= 0 && moveMouseToIndex < moveMouseTo.Length)
{
ImGui.GetIO().WantSetMousePos = true;
ImGui.GetIO().MousePos = moveMouseTo[moveMouseToIndex];
}
configuration.DtrOrder = order.Concat(orderLeft).ToList();
configuration.DtrIgnore = ignore.Concat(ignoreLeft).ToList();