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>
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
// src/AcDream.Core/Plugins/WorldGameState.cs
|
|
using AcDream.Plugin.Abstractions;
|
|
|
|
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>
|
|
/// 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
|
|
/// server re-sends <c>CreateObject</c> for an entity already known to
|
|
/// acdream — the host deletes the old snapshot before adding the new
|
|
/// one so plugins don't see stale duplicates.
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|