refactor(app): compose session and player startup
Move streaming, live-session, hydration, local-player, combat, and teleport construction behind the typed Phase-7 boundary. Add exact-owner runtime bindings and focused spawn-claim classification so partial startup rolls back without retaining old session targets while preserving the accepted construction and frame dependencies. Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
parent
3573da12e1
commit
7771c07fb6
31 changed files with 1759 additions and 532 deletions
|
|
@ -0,0 +1,57 @@
|
|||
using AcDream.Content;
|
||||
using DatReaderWriter.DBObjs;
|
||||
|
||||
namespace AcDream.App.Streaming;
|
||||
|
||||
/// <summary>
|
||||
/// Memoized range check for indoor spawn claims. Claims below the indoor-cell
|
||||
/// range are always hydratable; indoor claims are validated against the exact
|
||||
/// landblock's authored cell count.
|
||||
/// </summary>
|
||||
internal sealed class DatSpawnClaimHydrationClassifier
|
||||
{
|
||||
private readonly Func<uint, LandBlockInfo?> _lookup;
|
||||
private (uint Claim, bool Unhydratable)? _memo;
|
||||
|
||||
public DatSpawnClaimHydrationClassifier(
|
||||
IDatReaderWriter dats,
|
||||
object datLock)
|
||||
: this(CreateLookup(dats, datLock))
|
||||
{
|
||||
}
|
||||
|
||||
internal DatSpawnClaimHydrationClassifier(
|
||||
Func<uint, LandBlockInfo?> lookup) =>
|
||||
_lookup = lookup ?? throw new ArgumentNullException(nameof(lookup));
|
||||
|
||||
public bool IsUnhydratable(uint claim)
|
||||
{
|
||||
uint low = claim & 0xFFFFu;
|
||||
if (low < 0x0100u)
|
||||
return false;
|
||||
if (_memo is { } memo && memo.Claim == claim)
|
||||
return memo.Unhydratable;
|
||||
|
||||
LandBlockInfo? info = _lookup((claim & 0xFFFF0000u) | 0xFFFEu);
|
||||
bool unhydratable = info is null
|
||||
|| info.NumCells == 0
|
||||
|| low >= 0x0100u + info.NumCells;
|
||||
_memo = (claim, unhydratable);
|
||||
return unhydratable;
|
||||
}
|
||||
|
||||
public void Reset() => _memo = null;
|
||||
|
||||
private static Func<uint, LandBlockInfo?> CreateLookup(
|
||||
IDatReaderWriter dats,
|
||||
object datLock)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(dats);
|
||||
ArgumentNullException.ThrowIfNull(datLock);
|
||||
return id =>
|
||||
{
|
||||
lock (datLock)
|
||||
return dats.Get<LandBlockInfo>(id);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,17 @@ internal sealed class DeferredLocalPlayerTeleportNetworkSink
|
|||
throw new InvalidOperationException("The local teleport sink is already bound.");
|
||||
}
|
||||
|
||||
public IDisposable BindOwned(ILocalPlayerTeleportNetworkSink inner)
|
||||
{
|
||||
Bind(inner);
|
||||
return new Binding(this, inner);
|
||||
}
|
||||
|
||||
private void Unbind(ILocalPlayerTeleportNetworkSink expected)
|
||||
{
|
||||
_ = Interlocked.CompareExchange(ref _inner, null, expected);
|
||||
}
|
||||
|
||||
public void OnTeleportStarted(uint sequence) => Required().OnTeleportStarted(sequence);
|
||||
|
||||
public void OfferDestination(
|
||||
|
|
@ -53,6 +64,23 @@ internal sealed class DeferredLocalPlayerTeleportNetworkSink
|
|||
private ILocalPlayerTeleportNetworkSink Required() =>
|
||||
_inner ?? throw new InvalidOperationException(
|
||||
"The local teleport sink was used before composition completed.");
|
||||
|
||||
private sealed class Binding : IDisposable
|
||||
{
|
||||
private DeferredLocalPlayerTeleportNetworkSink? _owner;
|
||||
private readonly ILocalPlayerTeleportNetworkSink _expected;
|
||||
|
||||
public Binding(
|
||||
DeferredLocalPlayerTeleportNetworkSink owner,
|
||||
ILocalPlayerTeleportNetworkSink expected)
|
||||
{
|
||||
_owner = owner;
|
||||
_expected = expected;
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Interlocked.Exchange(ref _owner, null)?.Unbind(_expected);
|
||||
}
|
||||
}
|
||||
|
||||
internal interface ILocalPlayerTeleportInputLifetime
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue