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

@ -6,11 +6,25 @@ namespace AcDream.Core.Plugins;
public sealed class WorldGameState : IGameState
{
private readonly List<WorldEntitySnapshot> _entities = new();
private readonly Dictionary<uint, int> _indexById = new();
public IReadOnlyList<WorldEntitySnapshot> Entities => _entities;
/// <summary>Called by the host as each entity is hydrated.</summary>
public void Add(WorldEntitySnapshot snapshot) => _entities.Add(snapshot);
/// <summary>
/// Publish the current projection for an entity. Re-hydration replaces the
/// prior snapshot instead of turning the current-state API into history.
/// </summary>
public void Add(WorldEntitySnapshot snapshot)
{
if (_indexById.TryGetValue(snapshot.Id, out int index))
{
_entities[index] = snapshot;
return;
}
_indexById.Add(snapshot.Id, _entities.Count);
_entities.Add(snapshot);
}
/// <summary>
/// Remove any snapshot with the given local <c>Id</c>. Used when the
@ -18,5 +32,25 @@ public sealed class WorldGameState : IGameState
/// acdream — the host deletes the old snapshot before adding the new
/// one so plugins don't see stale duplicates.
/// </summary>
public void RemoveById(uint id) => _entities.RemoveAll(e => e.Id == id);
public bool RemoveById(uint id)
{
if (!_indexById.Remove(id, out int index))
return false;
int lastIndex = _entities.Count - 1;
if (index != lastIndex)
{
WorldEntitySnapshot moved = _entities[lastIndex];
_entities[index] = moved;
_indexById[moved.Id] = index;
}
_entities.RemoveAt(lastIndex);
return true;
}
public void Clear()
{
_entities.Clear();
_indexById.Clear();
}
}