move handling of critical ipc to main thread
This commit is contained in:
@@ -34,6 +34,7 @@ namespace MareSynchronos.Managers
|
|||||||
_penumbraSetTemporaryMod;
|
_penumbraSetTemporaryMod;
|
||||||
private readonly ICallGateSubscriber<IntPtr, string, string, object?> _penumbraGameObjectResourcePathResolved;
|
private readonly ICallGateSubscriber<IntPtr, string, string, object?> _penumbraGameObjectResourcePathResolved;
|
||||||
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)
|
||||||
{
|
{
|
||||||
@@ -80,6 +81,15 @@ namespace MareSynchronos.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._dalamudUtil = dalamudUtil;
|
this._dalamudUtil = dalamudUtil;
|
||||||
|
_dalamudUtil.FrameworkUpdate += HandleActionQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleActionQueue()
|
||||||
|
{
|
||||||
|
while (actionQueue.TryDequeue(out var action))
|
||||||
|
{
|
||||||
|
action();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResourceLoaded(IntPtr ptr, string arg1, string arg2)
|
private void ResourceLoaded(IntPtr ptr, string arg1, string arg2)
|
||||||
@@ -125,6 +135,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);
|
||||||
@@ -134,26 +147,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;
|
||||||
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
actionQueue.Enqueue(() =>
|
||||||
if (gameObj != null)
|
|
||||||
{
|
{
|
||||||
Logger.Verbose("Glamourer applying for " + gameObj);
|
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
||||||
_glamourerApplyAll!.InvokeAction(customization, gameObj);
|
if (gameObj != null)
|
||||||
}
|
{
|
||||||
|
Logger.Verbose("Glamourer applying for " + 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;
|
||||||
Logger.Verbose("Glamourer apply only equipment to " + character);
|
actionQueue.Enqueue(() =>
|
||||||
_glamourerApplyOnlyEquipment!.InvokeAction(customization, character);
|
{
|
||||||
|
Logger.Verbose("Glamourer apply only equipment to " + 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;
|
||||||
Logger.Verbose("Glamourer apply only customization to " + character);
|
actionQueue.Enqueue(() =>
|
||||||
_glamourerApplyOnlyCustomization!.InvokeAction(customization, character);
|
{
|
||||||
|
Logger.Verbose("Glamourer apply only customization to " + character);
|
||||||
|
_glamourerApplyOnlyCustomization!.InvokeAction(customization, character);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GlamourerGetCharacterCustomization(GameObject character)
|
public string GlamourerGetCharacterCustomization(GameObject character)
|
||||||
@@ -177,7 +199,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)
|
||||||
@@ -203,32 +225,37 @@ namespace MareSynchronos.Managers
|
|||||||
public void PenumbraRedraw(IntPtr obj)
|
public void PenumbraRedraw(IntPtr obj)
|
||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
actionQueue.Enqueue(() =>
|
||||||
if (gameObj != null)
|
|
||||||
{
|
{
|
||||||
Logger.Verbose("Redrawing " + gameObj);
|
var gameObj = _dalamudUtil.CreateGameObject(obj);
|
||||||
_penumbraRedrawObject!.InvokeAction(gameObj, 0);
|
if (gameObj != null)
|
||||||
}
|
{
|
||||||
|
Logger.Verbose("Redrawing " + gameObj);
|
||||||
|
_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;
|
||||||
Logger.Verbose("Removing temp collection for " + characterName);
|
actionQueue.Enqueue(() =>
|
||||||
_penumbraRemoveTemporaryCollection.InvokeFunc(characterName);
|
{
|
||||||
|
Logger.Verbose("Removing temp collection for " + 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +267,6 @@ namespace MareSynchronos.Managers
|
|||||||
{
|
{
|
||||||
resolvedPaths = new[] { path };
|
resolvedPaths = new[] { path };
|
||||||
}
|
}
|
||||||
//Logger.Verbose("Reverse Resolved " + path + "=>" + string.Join(", ", resolvedPaths));
|
|
||||||
return resolvedPaths;
|
return resolvedPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,12 +274,15 @@ namespace MareSynchronos.Managers
|
|||||||
{
|
{
|
||||||
if (!CheckPenumbraApi()) return;
|
if (!CheckPenumbraApi()) return;
|
||||||
|
|
||||||
Logger.Verbose("Assigning temp mods for " + collectionName);
|
actionQueue.Enqueue(() =>
|
||||||
foreach (var mod in modPaths)
|
|
||||||
{
|
{
|
||||||
Logger.Verbose(mod.Key + " => " + mod.Value);
|
Logger.Verbose("Assigning temp mods for " + collectionName);
|
||||||
}
|
foreach (var mod in modPaths)
|
||||||
var ret = _penumbraSetTemporaryMod.InvokeFunc("MareSynchronos", collectionName, modPaths, manipulationData, 0);
|
{
|
||||||
|
Logger.Verbose(mod.Key + " => " + mod.Value);
|
||||||
|
}
|
||||||
|
_penumbraSetTemporaryMod.InvokeFunc("MareSynchronos", collectionName, modPaths, manipulationData, 0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RedrawEvent(IntPtr objectAddress, int objectTableIndex)
|
private void RedrawEvent(IntPtr objectAddress, int objectTableIndex)
|
||||||
@@ -270,6 +299,7 @@ namespace MareSynchronos.Managers
|
|||||||
private void PenumbraDispose()
|
private void PenumbraDispose()
|
||||||
{
|
{
|
||||||
PenumbraDisposed?.Invoke();
|
PenumbraDisposed?.Invoke();
|
||||||
|
actionQueue.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user