"improving" pair handler clean up and some other stuff

This commit is contained in:
2026-01-01 00:33:24 +09:00
parent bbb3375661
commit cfc5c1e0f3
17 changed files with 780 additions and 166 deletions

View File

@@ -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,