"improving" pair handler clean up and some other stuff
This commit is contained in:
@@ -213,18 +213,25 @@ public sealed class ActorObjectService : IHostedService, IDisposable
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task WaitForFullyLoadedAsync(nint address, CancellationToken cancellationToken = default)
|
||||
public async Task<bool> WaitForFullyLoadedAsync(nint address, CancellationToken cancellationToken = default, int timeOutMs = 30000)
|
||||
{
|
||||
if (address == nint.Zero)
|
||||
throw new ArgumentException("Address cannot be zero.", nameof(address));
|
||||
|
||||
var timeoutAt = timeOutMs > 0 ? Environment.TickCount64 + timeOutMs : long.MaxValue;
|
||||
while (true)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var isLoaded = await _framework.RunOnFrameworkThread(() => IsObjectFullyLoaded(address)).ConfigureAwait(false);
|
||||
if (!IsZoning && isLoaded)
|
||||
return;
|
||||
var loadState = await _framework.RunOnFrameworkThread(() => GetObjectLoadState(address)).ConfigureAwait(false);
|
||||
if (!loadState.IsValid)
|
||||
return false;
|
||||
|
||||
if (!IsZoning && loadState.IsLoaded)
|
||||
return true;
|
||||
|
||||
if (Environment.TickCount64 >= timeoutAt)
|
||||
return false;
|
||||
|
||||
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -1143,6 +1150,18 @@ public sealed class ActorObjectService : IHostedService, IDisposable
|
||||
return results;
|
||||
}
|
||||
|
||||
private LoadState GetObjectLoadState(nint address)
|
||||
{
|
||||
if (address == nint.Zero)
|
||||
return LoadState.Invalid;
|
||||
|
||||
var obj = _objectTable.CreateObjectReference(address);
|
||||
if (obj is null || obj.Address != address)
|
||||
return LoadState.Invalid;
|
||||
|
||||
return new LoadState(true, IsObjectFullyLoaded(address));
|
||||
}
|
||||
|
||||
private static unsafe bool IsObjectFullyLoaded(nint address)
|
||||
{
|
||||
if (address == nint.Zero)
|
||||
@@ -1169,6 +1188,11 @@ public sealed class ActorObjectService : IHostedService, IDisposable
|
||||
return true;
|
||||
}
|
||||
|
||||
private readonly record struct LoadState(bool IsValid, bool IsLoaded)
|
||||
{
|
||||
public static LoadState Invalid => new(false, false);
|
||||
}
|
||||
|
||||
private sealed record OwnedObjectSnapshot(
|
||||
IReadOnlyList<nint> RenderedPlayers,
|
||||
IReadOnlyList<nint> RenderedCompanions,
|
||||
|
||||
Reference in New Issue
Block a user