Render entities from daemon frame identity
This commit is contained in:
parent
26138bab80
commit
ff02979056
4 changed files with 37 additions and 19 deletions
|
|
@ -1914,9 +1914,18 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"ZoneRenderer frame updates must read asteroid belt pose and radius from daemon belt poses instead of mirrored Unity asteroid belts.");
|
||||
}
|
||||
|
||||
if (zoneRenderer.Contains("_zoneSubscriptions", StringComparison.Ordinal) ||
|
||||
zoneRenderer.Contains("zone.Entities.ObserveAdd()", StringComparison.Ordinal) ||
|
||||
zoneRenderer.Contains("zone.Entities.ObserveRemove()", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"ZoneRenderer must reconcile rendered entities from daemon frame snapshots instead of subscribing to mirrored Unity entity collection mutations.");
|
||||
}
|
||||
|
||||
var requiredZoneRendererSymbols = new[]
|
||||
{
|
||||
"private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;",
|
||||
"private readonly Dictionary<string, EntityInstance> _entityInstancesByDaemonKey",
|
||||
"private readonly List<AetheriaRuntimeDaemonBodyPose> _daemonBodyPoses",
|
||||
"private readonly Dictionary<string, AetheriaRuntimeDaemonBodyPose> _daemonBodyPosesByBodyKey",
|
||||
"private readonly List<AetheriaRuntimeDaemonAsteroidBeltPose> _daemonAsteroidBeltPoses",
|
||||
|
|
@ -1927,6 +1936,9 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"foreach (var pose in _daemonBodyPoses)",
|
||||
"zone.PlanetInstances.TryGetValue(pose.BodyKey, out var planet)",
|
||||
"zone.AsteroidBelts.TryGetValue(pose.BodyKey, out var belt)",
|
||||
"foreach (var entitySnapshot in daemonZone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())",
|
||||
"entitiesByDaemonIndex.TryGetValue(entitySnapshot.EntityIndex, out var entity)",
|
||||
"foreach (var entity in EntityInstances.Keys.ToArray())",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryBodyPoses(_daemonZoneSnapshot, _daemonBodyPoses);",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryAsteroidBeltPoses(_daemonZoneSnapshot, _daemonAsteroidBeltPoses);",
|
||||
"_daemonBodyPosesByBodyKey.TryGetValue(planet.Key, out var pose)",
|
||||
|
|
|
|||
|
|
@ -2693,6 +2693,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (!_authoritativeDaemonEntities.TryGetValue(entitySnapshot.RecordKey, out var entity))
|
||||
continue;
|
||||
|
||||
entity.DaemonRecordKey = entitySnapshot.RecordKey ?? "";
|
||||
entity.DaemonEntityIndex = EntityIndexFromRecordKey(entitySnapshot.RecordKey);
|
||||
entity.Name = entitySnapshot.Name ?? "";
|
||||
entity.CultPosition = new CultMath.float3((float)entitySnapshot.PositionX, (float)entitySnapshot.PositionY, (float)entitySnapshot.PositionZ);
|
||||
entity.CultDirection = new CultMath.float2((float)entitySnapshot.DirectionX, (float)entitySnapshot.DirectionY);
|
||||
|
|
@ -2766,6 +2768,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
entity.OverrideShutdown = entitySnapshot.OverrideShutdown;
|
||||
entity.TractorPower = (float)entitySnapshot.TractorPower;
|
||||
entity.RestoreActiveState(entitySnapshot.IsActive);
|
||||
entity.DaemonRecordKey = entitySnapshot.RecordKey ?? "";
|
||||
entity.DaemonEntityIndex = EntityIndexFromRecordKey(entitySnapshot.RecordKey);
|
||||
entity.Zone = Zone;
|
||||
Zone.Entities.Add(entity);
|
||||
restoredEntities[entitySnapshot.RecordKey] = entity;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ public abstract class Entity
|
|||
public Faction Faction;
|
||||
public EquippableItem Hull;
|
||||
public EquippedItem EquippedHull;
|
||||
public string DaemonRecordKey = "";
|
||||
public int DaemonEntityIndex = -1;
|
||||
|
||||
public float3 Position;
|
||||
public float2 Direction = new float2(0,1);
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ public class ZoneRenderer : MonoBehaviour
|
|||
[HideInInspector] public Dictionary<Entity, EntityInstance> EntityInstances = new Dictionary<Entity, EntityInstance>();
|
||||
[HideInInspector] public Dictionary<string, PlanetObject> Planets = new Dictionary<string, PlanetObject>(StringComparer.Ordinal);
|
||||
|
||||
private readonly Dictionary<string, EntityInstance> _entityInstancesByDaemonKey =
|
||||
new Dictionary<string, EntityInstance>(StringComparer.Ordinal);
|
||||
private Dictionary<string, AsteroidBeltUI> _beltObjects = new Dictionary<string, AsteroidBeltUI>(StringComparer.Ordinal);
|
||||
private Dictionary<string, InstancedMesh[]> _beltMeshes = new Dictionary<string, InstancedMesh[]>(StringComparer.Ordinal);
|
||||
private Dictionary<string, Matrix4x4[][]> _beltMatrices = new Dictionary<string, Matrix4x4[][]>(StringComparer.Ordinal);
|
||||
|
|
@ -82,7 +84,6 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private bool _rootFound;
|
||||
private Entity _perspectiveEntity;
|
||||
private IDisposable[] _perspectiveSubscriptions = new IDisposable[2];
|
||||
private List<IDisposable> _zoneSubscriptions = new List<IDisposable>();
|
||||
private PlanetObject[] _suns;
|
||||
private bool _showAsteroidUI;
|
||||
private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;
|
||||
|
|
@ -212,22 +213,21 @@ public class ZoneRenderer : MonoBehaviour
|
|||
|
||||
_suns = Planets.Values.Where(p => p is SunObject).ToArray();
|
||||
|
||||
var entitiesByDaemonIndex = new Dictionary<int, Entity>();
|
||||
foreach (var entity in zone.Entities)
|
||||
{
|
||||
Debug.Log($"Loading entity {entity.Name} from existing zone entity collection");
|
||||
LoadEntity(entity);
|
||||
if (entity != null && entity.DaemonEntityIndex >= 0)
|
||||
entitiesByDaemonIndex[entity.DaemonEntityIndex] = entity;
|
||||
}
|
||||
|
||||
_zoneSubscriptions.Add(zone.Entities.ObserveAdd().Subscribe(e =>
|
||||
foreach (var entitySnapshot in daemonZone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
|
||||
{
|
||||
//Debug.Log($"Loading entity {e.Value.Name} from zone add event");
|
||||
LoadEntity(e.Value);
|
||||
}));
|
||||
_zoneSubscriptions.Add(zone.Entities.ObserveRemove().Subscribe(e =>
|
||||
{
|
||||
//Debug.Log($"Unloading entity {e.Value.Name} from zone remove event");
|
||||
UnloadEntity(e.Value);
|
||||
}));
|
||||
if (entitySnapshot != null &&
|
||||
entitiesByDaemonIndex.TryGetValue(entitySnapshot.EntityIndex, out var entity))
|
||||
{
|
||||
Debug.Log($"Loading entity {entity.Name} from daemon entity snapshot {entitySnapshot.EntityIndex}");
|
||||
LoadEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
if (zone.GalaxyZone != null)
|
||||
{
|
||||
|
|
@ -262,17 +262,13 @@ public class ZoneRenderer : MonoBehaviour
|
|||
}
|
||||
WormholeInstances.Clear();
|
||||
|
||||
foreach (var subscription in _zoneSubscriptions)
|
||||
subscription.Dispose();
|
||||
_zoneSubscriptions.Clear();
|
||||
|
||||
foreach(var gridObject in _loot)
|
||||
if(gridObject) Destroy(gridObject.gameObject);
|
||||
_loot.Clear();
|
||||
|
||||
foreach (var entity in Zone.Entities)
|
||||
foreach (var entity in EntityInstances.Keys.ToArray())
|
||||
{
|
||||
Debug.Log($"Unloading entity {entity.Name} from entities remaining during clear!");
|
||||
Debug.Log($"Unloading entity {entity.Name} from rendered entity instances during clear.");
|
||||
UnloadEntity(entity);
|
||||
}
|
||||
|
||||
|
|
@ -333,6 +329,8 @@ public class ZoneRenderer : MonoBehaviour
|
|||
instance.SetEntity(this, entity);
|
||||
|
||||
EntityInstances.Add(entity, instance);
|
||||
if (!string.IsNullOrWhiteSpace(entity.DaemonRecordKey))
|
||||
_entityInstancesByDaemonKey[entity.DaemonRecordKey] = instance;
|
||||
}
|
||||
|
||||
public void UnloadEntity(Entity entity)
|
||||
|
|
@ -351,6 +349,8 @@ public class ZoneRenderer : MonoBehaviour
|
|||
|
||||
Destroy(instance.gameObject);
|
||||
EntityInstances.Remove(entity);
|
||||
if (!string.IsNullOrWhiteSpace(entity.DaemonRecordKey))
|
||||
_entityInstancesByDaemonKey.Remove(entity.DaemonRecordKey);
|
||||
}
|
||||
|
||||
void LoadAsteroidBelt(AsteroidBelt runtimeBelt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue