move handling of critical ipc to main thread
This commit is contained in:
@@ -34,6 +34,7 @@ namespace MareSynchronos.Managers
|
|||||||
private readonly ICallGateSubscriber<string, string, Dictionary<string, string>, string, int, int>
|
private readonly ICallGateSubscriber<string, string, Dictionary<string, string>, string, int, int>
|
||||||
_penumbraSetTemporaryMod;
|
_penumbraSetTemporaryMod;
|
||||||
private readonly DalamudUtil _dalamudUtil;
|
private readonly DalamudUtil _dalamudUtil;
|
||||||
|
private readonly Queue<Action> actionQueue = new();
|
||||||
|
|
||||||
public IpcManager(DalamudPluginInterface pi, DalamudUtil dalamudUtil)
|
public IpcManager(DalamudPluginInterface pi, DalamudUtil dalamudUtil)
|
||||||
{
|
{
|
||||||
@@ -78,6 +79,15 @@ namespace MareSynchronos.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._dalamudUtil = dalamudUtil;
|
this._dalamudUtil = dalamudUtil;
|
||||||
|
_dalamudUtil.FrameworkUpdate += HandleActionQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleActionQueue()
|
||||||
|
{
|
||||||
|
while (actionQueue.TryDequeue(out var action))
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event VoidDelegate? PenumbraInitialized;
|
public event VoidDelegate? PenumbraInitialized;
|
||||||
@@ -113,6 +123,9 @@ namespace MareSynchronos.Managers
|
|||||||
{
|
{
|
||||||
Logger.Verbose("Disposing " + nameof(IpcManager));
|
Logger.Verbose("Disposing " + nameof(IpcManager));
|
||||||
|
|
||||||
|
_dalamudUtil.FrameworkUpdate -= HandleActionQueue;
|
||||||
|
actionQueue.Clear();
|
||||||
|
|
||||||
_penumbraDispose.Unsubscribe(PenumbraDispose);
|
_penumbraDispose.Unsubscribe(PenumbraDispose);
|
||||||
_penumbraInit.Unsubscribe(PenumbraInit);
|
_penumbraInit.Unsubscribe(PenumbraInit);
|
||||||
_penumbraObjectIsRedrawn.Unsubscribe(RedrawEvent);
|
_penumbraObjectIsRedrawn.Unsubscribe(RedrawEvent);
|
||||||
@@ -121,25 +134,35 @@ namespace MareSynchronos.Managers
|
|||||||
public void GlamourerApplyAll(string? customization, IntPtr obj)
|
public void GlamourerApplyAll(string? customization, IntPtr obj)
|
||||||
{
|
{
|
||||||
if (!CheckGlamourerApi() || string.IsNullOrEmpty(customization)) return;
|
if (!CheckGlamourerApi() || string.IsNullOrEmpty(customization)) return;
|
||||||
|
actionQueue.Enqueue(() =>
|
||||||
|
{
|
||||||
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
||||||
if (gameObj != null)
|
if (gameObj != null)
|
||||||
{
|
{
|
||||||
|
Logger.Verbose("Glamourer applying for " + gameObj);
|
||||||
_glamourerApplyAll!.InvokeAction(customization, gameObj);
|
_glamourerApplyAll!.InvokeAction(customization, gameObj);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GlamourerApplyOnlyEquipment(string customization, GameObject character)
|
public void GlamourerApplyOnlyEquipment(string customization, GameObject character)
|
||||||
{
|
{
|
||||||
if (!CheckGlamourerApi() || string.IsNullOrEmpty(customization)) return;
|
if (!CheckGlamourerApi() || string.IsNullOrEmpty(customization)) return;
|
||||||
|
actionQueue.Enqueue(() =>
|
||||||
|
{
|
||||||
Logger.Verbose("Glamourer apply only equipment to " + character);
|
Logger.Verbose("Glamourer apply only equipment to " + character);
|
||||||
_glamourerApplyOnlyEquipment!.InvokeAction(customization, character);
|
_glamourerApplyOnlyEquipment!.InvokeAction(customization, character);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GlamourerApplyOnlyCustomization(string customization, GameObject character)
|
public void GlamourerApplyOnlyCustomization(string customization, GameObject character)
|
||||||
{
|
{
|
||||||
if (!CheckGlamourerApi() || string.IsNullOrEmpty(customization)) return;
|
if (!CheckGlamourerApi() || string.IsNullOrEmpty(customization)) return;
|
||||||
|
actionQueue.Enqueue(() =>
|
||||||
|
{
|
||||||
Logger.Verbose("Glamourer apply only customization to " + character);
|
Logger.Verbose("Glamourer apply only customization to " + character);
|
||||||
_glamourerApplyOnlyCustomization!.InvokeAction(customization, character);
|
_glamourerApplyOnlyCustomization!.InvokeAction(customization, character);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GlamourerGetCharacterCustomization(GameObject character)
|
public string GlamourerGetCharacterCustomization(GameObject character)
|
||||||
@@ -163,7 +186,7 @@ namespace MareSynchronos.Managers
|
|||||||
public void GlamourerRevertCharacterCustomization(GameObject character)
|
public void GlamourerRevertCharacterCustomization(GameObject character)
|
||||||
{
|
{
|
||||||
if (!CheckGlamourerApi()) return;
|
if (!CheckGlamourerApi()) return;
|
||||||
_glamourerRevertCustomization!.InvokeAction(character);
|
actionQueue.Enqueue(() => _glamourerRevertCustomization!.InvokeAction(character));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string PenumbraCreateTemporaryCollection(string characterName)
|
public string PenumbraCreateTemporaryCollection(string characterName)
|
||||||
@@ -189,31 +212,37 @@ namespace MareSynchronos.Managers
|
|||||||
public void PenumbraRedraw(IntPtr obj)
|
public void PenumbraRedraw(IntPtr obj)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
|
actionQueue.Enqueue(() =>
|
||||||
|
{
|
||||||
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
||||||
if (gameObj != null)
|
if (gameObj != null)
|
||||||
{
|
{
|
||||||
|
Logger.Verbose("Redrawing " + gameObj);
|
||||||
_penumbraRedrawObject!.InvokeAction(gameObj, 0);
|
_penumbraRedrawObject!.InvokeAction(gameObj, 0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PenumbraRedraw(string actorName)
|
public void PenumbraRedraw(string actorName)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
_penumbraRedraw!.InvokeAction(actorName, 0);
|
actionQueue.Enqueue(() => _penumbraRedraw!.InvokeAction(actorName, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PenumbraRemoveTemporaryCollection(string characterName)
|
public void PenumbraRemoveTemporaryCollection(string characterName)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
|
actionQueue.Enqueue(() =>
|
||||||
|
{
|
||||||
Logger.Verbose("Removing temp collection for " + characterName);
|
Logger.Verbose("Removing temp collection for " + characterName);
|
||||||
_penumbraRemoveTemporaryCollection.InvokeFunc(characterName);
|
_penumbraRemoveTemporaryCollection.InvokeFunc(characterName);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? PenumbraResolvePath(string path)
|
public string? PenumbraResolvePath(string path)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return null;
|
if (!CheckPenumbraApi()) return null;
|
||||||
var resolvedPath = _penumbraResolvePlayer!.InvokeFunc(path);
|
var resolvedPath = _penumbraResolvePlayer!.InvokeFunc(path);
|
||||||
//Logger.Verbose("Resolved " + path + "=>" + string.Join(", ", resolvedPath));
|
|
||||||
return resolvedPath;
|
return resolvedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +254,6 @@ namespace MareSynchronos.Managers
|
|||||||
{
|
{
|
||||||
resolvedPaths = new[] { path };
|
resolvedPaths = new[] { path };
|
||||||
}
|
}
|
||||||
//Logger.Verbose("Reverse Resolved " + path + "=>" + string.Join(", ", resolvedPaths));
|
|
||||||
return resolvedPaths;
|
return resolvedPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,13 +263,12 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
actionQueue.Enqueue(() =>
|
actionQueue.Enqueue(() =>
|
||||||
{
|
{
|
||||||
var ret = _penumbraCreateTemporaryCollection.InvokeFunc("MareSynchronos", characterName, true);
|
Logger.Verbose("Assigning temp mods for " + collectionName);
|
||||||
Logger.Verbose("Assigning temp mods for " + ret.Item2);
|
|
||||||
foreach (var mod in modPaths)
|
foreach (var mod in modPaths)
|
||||||
{
|
{
|
||||||
Logger.Verbose(mod.Key + " => " + mod.Value);
|
Logger.Verbose(mod.Key + " => " + mod.Value);
|
||||||
}
|
}
|
||||||
_penumbraSetTemporaryMod.InvokeFunc("MareSynchronos", ret.Item2, modPaths, manipulationData, 0);
|
_penumbraSetTemporaryMod.InvokeFunc("MareSynchronos", collectionName, modPaths, manipulationData, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,6 +286,7 @@ namespace MareSynchronos.Managers
|
|||||||
private void PenumbraDispose()
|
private void PenumbraDispose()
|
||||||
{
|
{
|
||||||
PenumbraDisposed?.Invoke();
|
PenumbraDisposed?.Invoke();
|
||||||
|
actionQueue.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user