don't call zoning when zoning is not happening, wait for mark offline on players, fixes initial data application after zoning

This commit is contained in:
rootdarkarchon
2023-05-07 02:00:36 +02:00
parent 0a80531836
commit effe6c2839
3 changed files with 41 additions and 22 deletions

View File

@@ -40,6 +40,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
private string _originalGlamourerData = string.Empty; private string _originalGlamourerData = string.Empty;
private CancellationTokenSource _redrawCts = new(); private CancellationTokenSource _redrawCts = new();
private string _penumbraCollection; private string _penumbraCollection;
private CharacterData? _firstTimeInitData;
public CachedPlayer(ILogger<CachedPlayer> logger, OnlineUserIdentDto onlineUser, public CachedPlayer(ILogger<CachedPlayer> logger, OnlineUserIdentDto onlineUser,
GameObjectHandlerFactory gameObjectHandlerFactory, GameObjectHandlerFactory gameObjectHandlerFactory,
@@ -53,6 +54,9 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
_dalamudUtil = dalamudUtil; _dalamudUtil = dalamudUtil;
_lifetime = lifetime; _lifetime = lifetime;
_fileDbManager = fileDbManager; _fileDbManager = fileDbManager;
_penumbraCollection = _ipcManager.PenumbraCreateTemporaryCollection(logger, OnlineUser.User.UID).ConfigureAwait(false).GetAwaiter().GetResult();
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => FrameworkUpdate()); Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => FrameworkUpdate());
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) =>
{ {
@@ -76,10 +80,6 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
ShownPalettePlusWarning = mareConfigService.Current.DisableOptionalPluginWarnings, ShownPalettePlusWarning = mareConfigService.Current.DisableOptionalPluginWarnings,
ShownHonorificWarning = mareConfigService.Current.DisableOptionalPluginWarnings, ShownHonorificWarning = mareConfigService.Current.DisableOptionalPluginWarnings,
}; };
Task.Run(async () =>
{
_penumbraCollection = await _ipcManager.PenumbraCreateTemporaryCollection(logger, OnlineUser.User.UID).ConfigureAwait(false);
});
} }
private enum PlayerChanges private enum PlayerChanges
@@ -106,7 +106,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
{ {
if (_charaHandler == null) if (_charaHandler == null)
{ {
_cachedData = characterData; _firstTimeInitData = characterData;
return; return;
} }
@@ -130,6 +130,11 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
var charaDataToUpdate = CheckUpdatedData(_cachedData?.DeepClone() ?? new(), characterData, forced); var charaDataToUpdate = CheckUpdatedData(_cachedData?.DeepClone() ?? new(), characterData, forced);
if (_charaHandler != null && _firstTimeInitData != null)
{
_firstTimeInitData = null;
}
if (charaDataToUpdate.TryGetValue(ObjectKind.Player, out var playerChanges)) if (charaDataToUpdate.TryGetValue(ObjectKind.Player, out var playerChanges))
{ {
NotifyForMissingPlugins(playerChanges); NotifyForMissingPlugins(playerChanges);
@@ -138,8 +143,6 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
Logger.LogDebug("Downloading and applying character for {name}", this); Logger.LogDebug("Downloading and applying character for {name}", this);
DownloadAndApplyCharacter(characterData.DeepClone(), charaDataToUpdate); DownloadAndApplyCharacter(characterData.DeepClone(), charaDataToUpdate);
_cachedData = characterData;
} }
public override string ToString() public override string ToString()
@@ -162,8 +165,6 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
{ {
base.Dispose(disposing); base.Dispose(disposing);
if (string.IsNullOrEmpty(PlayerName)) return; // already disposed
SetUploading(false); SetUploading(false);
_downloadManager.Dispose(); _downloadManager.Dispose();
var name = PlayerName; var name = PlayerName;
@@ -324,7 +325,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
if (hasNewAndOldFileReplacements) if (hasNewAndOldFileReplacements)
{ {
bool listsAreEqual = oldData.FileReplacements[objectKind].SequenceEqual(newData.FileReplacements[objectKind], Data.FileReplacementDataComparer.Instance); bool listsAreEqual = oldData.FileReplacements[objectKind].SequenceEqual(newData.FileReplacements[objectKind], Data.FileReplacementDataComparer.Instance);
if (!listsAreEqual) if (!listsAreEqual || _firstTimeInitData != null)
{ {
Logger.LogDebug("Updating {object}/{kind} (FileReplacements not equal) => {change}", this, objectKind, PlayerChanges.ModFiles); Logger.LogDebug("Updating {object}/{kind} (FileReplacements not equal) => {change}", this, objectKind, PlayerChanges.ModFiles);
charaDataToUpdate[objectKind].Add(PlayerChanges.ModFiles); charaDataToUpdate[objectKind].Add(PlayerChanges.ModFiles);
@@ -345,7 +346,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
if (objectKind != ObjectKind.Player) continue; if (objectKind != ObjectKind.Player) continue;
bool manipDataDifferent = !string.Equals(oldData.ManipulationData, newData.ManipulationData, StringComparison.Ordinal); bool manipDataDifferent = !string.Equals(oldData.ManipulationData, newData.ManipulationData, StringComparison.Ordinal);
if (manipDataDifferent) if (manipDataDifferent || _firstTimeInitData != null)
{ {
Logger.LogDebug("Updating {object}/{kind} (Diff manip data) => {change}", this, objectKind, PlayerChanges.ModManip); Logger.LogDebug("Updating {object}/{kind} (Diff manip data) => {change}", this, objectKind, PlayerChanges.ModManip);
charaDataToUpdate[objectKind].Add(PlayerChanges.ModManip); charaDataToUpdate[objectKind].Add(PlayerChanges.ModManip);
@@ -492,6 +493,8 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
{ {
Logger.LogWarning(ex, "[{applicationId}] Cancelled", _applicationId); Logger.LogWarning(ex, "[{applicationId}] Cancelled", _applicationId);
} }
_cachedData = charaData;
}, token); }, token);
}, downloadToken); }, downloadToken);
} }
@@ -513,12 +516,12 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
Mediator.Publish(new CachedPlayerVisibleMessage(this)); Mediator.Publish(new CachedPlayerVisibleMessage(this));
Logger.LogTrace("{this} visibility changed, now: {visi}", this, IsVisible); Logger.LogTrace("{this} visibility changed, now: {visi}", this, IsVisible);
_framesSinceNotVisible = 0; _framesSinceNotVisible = 0;
if (_cachedData != null) if (_firstTimeInitData != null)
{ {
Task.Run(async () => Task.Run(async () =>
{ {
_lastGlamourerData = await _ipcManager.GlamourerGetCharacterCustomizationAsync(PlayerCharacter).ConfigureAwait(false); _lastGlamourerData = await _ipcManager.GlamourerGetCharacterCustomizationAsync(PlayerCharacter).ConfigureAwait(false);
ApplyCharacterData(_cachedData, true); ApplyCharacterData(_firstTimeInitData, true);
}); });
} }
} }

View File

@@ -133,10 +133,19 @@ public class Pair
public void MarkOffline() public void MarkOffline()
{ {
try
{
_creationSemaphore.Wait();
_onlineUserIdentDto = null; _onlineUserIdentDto = null;
LastReceivedCharacterData = null; LastReceivedCharacterData = null;
CachedPlayer?.Dispose(); var player = CachedPlayer;
CachedPlayer = null; CachedPlayer = null;
player?.Dispose();
}
finally
{
_creationSemaphore.Release();
}
} }
public void SetNote(string note) public void SetNote(string note)

View File

@@ -34,6 +34,7 @@ public class DalamudUtilService : IHostedService
private string _lastGlobalBlockPlayer = string.Empty; private string _lastGlobalBlockPlayer = string.Empty;
private Dictionary<string, (string Name, nint Address)> _playerCharas = new(StringComparer.Ordinal); private Dictionary<string, (string Name, nint Address)> _playerCharas = new(StringComparer.Ordinal);
private bool _sentBetweenAreas = false; private bool _sentBetweenAreas = false;
private ushort _lastZone = 0;
public DalamudUtilService(ILogger<DalamudUtilService> logger, ClientState clientState, ObjectTable objectTable, Framework framework, public DalamudUtilService(ILogger<DalamudUtilService> logger, ClientState clientState, ObjectTable objectTable, Framework framework,
GameGui gameGui, Condition condition, Dalamud.Data.DataManager gameData, MareMediator mediator, PerformanceCollectorService performanceCollector) GameGui gameGui, Condition condition, Dalamud.Data.DataManager gameData, MareMediator mediator, PerformanceCollectorService performanceCollector)
@@ -433,6 +434,10 @@ public class DalamudUtilService : IHostedService
if (_condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51]) if (_condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51])
{ {
var zone = _clientState.TerritoryType;
if (_lastZone != zone)
{
_lastZone = zone;
if (!_sentBetweenAreas) if (!_sentBetweenAreas)
{ {
_logger.LogDebug("Zone switch/Gpose start"); _logger.LogDebug("Zone switch/Gpose start");
@@ -440,6 +445,7 @@ public class DalamudUtilService : IHostedService
_mediator.Publish(new ZoneSwitchStartMessage()); _mediator.Publish(new ZoneSwitchStartMessage());
_mediator.Publish(new HaltScanMessage("Zone switch")); _mediator.Publish(new HaltScanMessage("Zone switch"));
} }
}
return; return;
} }
@@ -462,6 +468,7 @@ public class DalamudUtilService : IHostedService
{ {
_logger.LogDebug("Logged in"); _logger.LogDebug("Logged in");
IsLoggedIn = true; IsLoggedIn = true;
_lastZone = _clientState.TerritoryType;
_mediator.Publish(new DalamudLoginMessage()); _mediator.Publish(new DalamudLoginMessage());
} }
else if (localPlayer == null && IsLoggedIn) else if (localPlayer == null && IsLoggedIn)