fix(rendering): bound portal resource lifetime

Separate logical ownership, render publication, and GPU retirement across live entities, landblocks, particles, textures, mesh arenas, portal/UI teardown, and per-frame scratch storage. Add bounded DAT/texture caches, upload budgets, three-frame fence retirement, exact-incarnation appearance reconciliation, frame pacing, and extensive lifetime conformance coverage.\n\nThe seven-destination connected route now cuts peak working/private memory roughly in half, returns Caul to 125-153 FPS locally, and produces no WER or AMD reset.\n\nCo-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-18 21:35:16 +02:00
parent 3971997689
commit 749e8ceeb1
225 changed files with 29107 additions and 3914 deletions

View file

@ -50,6 +50,7 @@ internal sealed class ProjectileController
private readonly ShadowObjectRegistry _shadows;
private readonly Func<uint, Setup?> _setupResolver;
private readonly Action<WorldEntity> _publishRootPose;
private readonly List<LiveEntityRecord> _spatialProjectileSnapshot = new();
private double _lastFiniteGameTime;
internal ProjectileController(
@ -64,6 +65,7 @@ internal sealed class ProjectileController
_shadows = physicsEngine.ShadowObjects;
_setupResolver = setupResolver ?? (_ => null);
_publishRootPose = publishRootPose ?? (_ => { });
_liveEntities.ProjectionVisibilityChanged += OnProjectionVisibilityChanged;
}
internal Action<string>? DiagnosticSink { get; set; }
@ -483,9 +485,11 @@ internal sealed class ProjectileController
return false;
}
internal bool LeaveWorld(uint serverGuid)
internal bool LeaveWorld(LiveEntityRecord record)
{
if (!TryGetCurrent(serverGuid, out LiveEntityRecord record, out Runtime runtime)
ArgumentNullException.ThrowIfNull(record);
if (record.ProjectileRuntime is not Runtime runtime
|| runtime.Generation != record.Generation
|| record.WorldEntity is not { } entity)
return false;
SuspendOutsideWorld(runtime, entity.Id);
@ -505,10 +509,12 @@ internal sealed class ProjectileController
}
_lastFiniteGameTime = currentTime;
foreach (LiveEntityRecord record in _liveEntities.Records.ToArray())
_liveEntities.CopySpatialProjectileRecordsTo(_spatialProjectileSnapshot);
foreach (LiveEntityRecord record in _spatialProjectileSnapshot)
{
if (record.ProjectileRuntime is not Runtime runtime
|| runtime.Generation != record.Generation
|| !_liveEntities.IsCurrentSpatialProjectile(record, runtime)
|| record.WorldEntity is not { } entity)
continue;
@ -668,6 +674,25 @@ internal sealed class ProjectileController
}
}
private void OnProjectionVisibilityChanged(LiveEntityRecord record, bool visible)
{
if (visible
|| record.ProjectileRuntime is not Runtime runtime
|| record.WorldEntity is not { } entity
|| !_liveEntities.TryGetRecord(record.ServerGuid, out LiveEntityRecord current)
|| !ReferenceEquals(current, record)
|| !ReferenceEquals(current.ProjectileRuntime, runtime))
{
return;
}
// Pending/cell-less records retain their logical projectile runtime,
// but retail exit_world removes them from active physics and collision
// immediately. They are absent from the frame workset after this edge,
// so suspension belongs on the authoritative residency transition.
SuspendOutsideWorld(runtime, entity.Id);
}
private static bool HasVisibleCell(LiveEntityRecord record) =>
record.IsSpatiallyProjected
&& record.IsSpatiallyVisible