diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 147aa9b89..e931cd1f5 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -7278,6 +7278,30 @@ static void RequireUnitySharedDocumentAccessorErgonomics(string root) string.Join(", ", missingSectorRendererSharedDocumentSymbols)); } + var zoneRenderer = File.ReadAllText(Path.Combine( + root, + "Assets", + "Scripts", + "Zone Display", + "ZoneRenderer.cs")); + var requiredZoneRendererSharedDocumentSymbols = new[] + { + "CultMeshReactiveDocument _catalog", + "ResolveClient().Aetheria().ReactiveCatalog()", + "_catalog?.Dispose()", + "_catalog?.Current", + "private void OnDestroy()" + }; + var missingZoneRendererSharedDocumentSymbols = requiredZoneRendererSharedDocumentSymbols + .Where(symbol => !zoneRenderer.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + if (missingZoneRendererSharedDocumentSymbols.Length > 0) + { + throw new InvalidOperationException( + "ZoneRenderer should bind catalog state through the managed reactive Aetheria catalog document with renderer lifetime disposal: " + + string.Join(", ", missingZoneRendererSharedDocumentSymbols)); + } + var volumeCloudRenderer = File.ReadAllText(Path.Combine( root, "Assets", diff --git a/Assets/Scripts/Zone Display/ZoneRenderer.cs b/Assets/Scripts/Zone Display/ZoneRenderer.cs index 5c58a3998..e1043806f 100644 --- a/Assets/Scripts/Zone Display/ZoneRenderer.cs +++ b/Assets/Scripts/Zone Display/ZoneRenderer.cs @@ -7,6 +7,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using Cinemachine; +using GameCult.Mesh; using GameCult.Aetheria.State.Verse; using UnityEngine; using UnityEngine.Serialization; @@ -118,7 +119,8 @@ public class ZoneRenderer : MonoBehaviour Array.Empty(); private IReadOnlyList _zoneRenderBodies = Array.Empty(); - private AetheriaRuntimeCatalogSnapshot _catalog; + private string _clientStatePath = ""; + private CultMeshReactiveDocument _catalog; public Dictionary WormholeInstances = new Dictionary(); private List _loot = new List(); @@ -1006,7 +1008,7 @@ public class ZoneRenderer : MonoBehaviour private void OnDestroy() { - _catalog = null; + ClearClientCaches(); } private float GetTerrainHeight(float2 position) @@ -1214,26 +1216,39 @@ public class ZoneRenderer : MonoBehaviour private AetheriaRuntimeCatalogSnapshot ResolveCatalog() { if (_catalog != null) - return _catalog; + return _catalog.Current; try { - _catalog = ResolveClient().Aetheria().LatestCatalog(); + _catalog = ResolveClient().Aetheria().ReactiveCatalog(); } catch (Exception ex) { - Debug.LogWarning($"Failed to read Aetheria runtime catalog for zone renderer: {ex.Message}"); + Debug.LogWarning($"Failed to bind Aetheria runtime catalog for zone renderer: {ex.Message}"); } - return _catalog; + return _catalog?.Current; } private AetheriaClient ResolveClient() { + var stateBoot = AetheriaRuntimeStateBoot.Inspect(AetheriaUnityRuntimePaths.GameDataDirectory); + if (!string.Equals(_clientStatePath, stateBoot.StateFilePath, StringComparison.Ordinal)) + { + _clientStatePath = stateBoot.StateFilePath; + ClearClientCaches(); + } + return AetheriaUnityRuntimeClientProvider.ResolveClient( - AetheriaRuntimeStateBoot.Inspect(AetheriaUnityRuntimePaths.GameDataDirectory), + stateBoot, "unity-zone-renderer"); } + + private void ClearClientCaches() + { + _catalog?.Dispose(); + _catalog = null; + } }