Project wormholes from daemon zone topology
This commit is contained in:
parent
298dda56b3
commit
c0e60413a2
5 changed files with 170 additions and 15 deletions
|
|
@ -1833,6 +1833,10 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"public static int QueryCompassMarkers(",
|
||||
"public static int[] QueryVisibleEntityIndices(",
|
||||
"public static int QueryVisibleEntityIndices(",
|
||||
"AetheriaRuntimeDaemonWormholeExit",
|
||||
"public static AetheriaRuntimeDaemonWormholeExit[] QueryWormholeExits(",
|
||||
"public static int QueryWormholeExits(",
|
||||
"BuildZoneMap(run)",
|
||||
"BuildEntityMap(zone)"
|
||||
};
|
||||
|
||||
|
|
@ -1952,8 +1956,15 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"ZoneRenderer must query daemon visible entity indices instead of subscribing to mirrored Unity visibility collections.");
|
||||
}
|
||||
|
||||
if (zoneRenderer.Contains("AdjacentZones", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"ZoneRenderer must query daemon wormhole exits instead of enumerating mirrored GalaxyZone adjacency.");
|
||||
}
|
||||
|
||||
var requiredZoneRendererSymbols = new[]
|
||||
{
|
||||
"private AetheriaRuntimeRunCheckpointCommit _daemonRunSnapshot;",
|
||||
"private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;",
|
||||
"private readonly List<AetheriaRuntimeDaemonBodyPose> _daemonBodyPoses",
|
||||
"private readonly Dictionary<string, AetheriaRuntimeDaemonBodyPose> _daemonBodyPosesByBodyKey",
|
||||
|
|
@ -1964,8 +1975,10 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"private readonly List<int> _daemonVisibleEntityIndices",
|
||||
"private readonly HashSet<int> _daemonVisibleEntityIndicesSet",
|
||||
"private readonly HashSet<int> _visibleDaemonEntityIndices",
|
||||
"public void LoadZone(Zone zone, AetheriaRuntimeZoneSnapshotCommit daemonZone = null)",
|
||||
"private readonly List<AetheriaRuntimeDaemonWormholeExit> _daemonWormholeExits",
|
||||
"AetheriaRuntimeRunCheckpointCommit daemonRun = null",
|
||||
"_daemonZoneSnapshot = daemonZone;",
|
||||
"_daemonRunSnapshot = daemonRun;",
|
||||
"AetheriaRuntimeDaemonRenderQueries.EvaluateGravityTerrainHeight(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryGravityTerrainBand(",
|
||||
"private readonly List<AetheriaRuntimeDaemonAsteroidInstancePose> _visibleAsteroidInstancePoses",
|
||||
|
|
@ -1980,6 +1993,7 @@ static void RequireDaemonRenderQueryAuthority(string root)
|
|||
"AetheriaRuntimeDaemonRenderQueries.QueryAsteroidInstancePoses(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryCompassMarkers(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryVisibleEntityIndices(",
|
||||
"AetheriaRuntimeDaemonRenderQueries.QueryWormholeExits(",
|
||||
"_daemonCompassMarkersByEntityIndex.TryGetValue(entityInstance.Entity.DaemonEntityIndex, out var marker)",
|
||||
"_daemonBodyPosesByBodyKey.TryGetValue(planet.Key, out var pose)",
|
||||
"_daemonAsteroidBeltPosesByBodyKey.TryGetValue(key, out var beltPose)",
|
||||
|
|
|
|||
|
|
@ -2046,7 +2046,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
public void PopulateLevel(GalaxyZone galaxyZone, AetheriaRuntimeZoneSnapshotCommit daemonZone = null)
|
||||
public void PopulateLevel(
|
||||
GalaxyZone galaxyZone,
|
||||
AetheriaRuntimeZoneSnapshotCommit daemonZone = null,
|
||||
AetheriaRuntimeRunCheckpointCommit daemonRun = null)
|
||||
{
|
||||
if (galaxyZone == null) throw new ArgumentNullException(nameof(galaxyZone));
|
||||
|
||||
|
|
@ -2067,7 +2070,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
Zone.Log = s => Debug.Log($"Zone: {s}");
|
||||
|
||||
ZoneRenderer.LoadZone(Zone, daemonZone);
|
||||
ZoneRenderer.LoadZone(Zone, daemonZone, daemonRun);
|
||||
|
||||
if (CurrentEntity != null)
|
||||
{
|
||||
|
|
@ -2222,7 +2225,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
if (Zone?.GalaxyZone != targetZone)
|
||||
{
|
||||
PopulateLevel(targetZone, daemonZone);
|
||||
PopulateLevel(targetZone, daemonZone, run);
|
||||
}
|
||||
|
||||
var actionBarBindings = run.ActionBarBindings?
|
||||
|
|
|
|||
|
|
@ -1083,6 +1083,46 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual(11, visible[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonRenderQueriesPublishWormholeExitsFromZoneAdjacency()
|
||||
{
|
||||
var currentZone = new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
ZoneIndex = 0,
|
||||
PositionX = 10,
|
||||
PositionY = 20,
|
||||
AdjacentZoneIndices = new[] { 1, 99 }
|
||||
};
|
||||
var run = new AetheriaRuntimeRunCheckpointCommit
|
||||
{
|
||||
Zones = new[]
|
||||
{
|
||||
currentZone,
|
||||
new AetheriaRuntimeZoneSnapshotCommit
|
||||
{
|
||||
ZoneIndex = 1,
|
||||
PositionX = 13,
|
||||
PositionY = 24
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var exits = new List<AetheriaRuntimeDaemonWormholeExit>();
|
||||
var count = AetheriaRuntimeDaemonRenderQueries.QueryWormholeExits(
|
||||
run,
|
||||
currentZone,
|
||||
100,
|
||||
0.5,
|
||||
exits);
|
||||
|
||||
Assert.AreEqual(1, count);
|
||||
Assert.AreEqual(1, exits[0].TargetZoneIndex);
|
||||
Assert.AreEqual(0.6, exits[0].DirectionX, 0.0001);
|
||||
Assert.AreEqual(0.8, exits[0].DirectionZ, 0.0001);
|
||||
Assert.AreEqual(30, exits[0].PositionX, 0.0001);
|
||||
Assert.AreEqual(40, exits[0].PositionZ, 0.0001);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoaViewIndexRejectsInvalidRenderGroups()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private Entity _perspectiveEntity;
|
||||
private PlanetObject[] _suns;
|
||||
private bool _showAsteroidUI;
|
||||
private AetheriaRuntimeRunCheckpointCommit _daemonRunSnapshot;
|
||||
private AetheriaRuntimeZoneSnapshotCommit _daemonZoneSnapshot;
|
||||
private readonly List<AetheriaRuntimeDaemonBodyPose> _daemonBodyPoses = new List<AetheriaRuntimeDaemonBodyPose>();
|
||||
private readonly Dictionary<string, AetheriaRuntimeDaemonBodyPose> _daemonBodyPosesByBodyKey =
|
||||
|
|
@ -99,6 +100,8 @@ public class ZoneRenderer : MonoBehaviour
|
|||
private readonly List<int> _daemonVisibleEntityIndices = new List<int>();
|
||||
private readonly HashSet<int> _daemonVisibleEntityIndicesSet = new HashSet<int>();
|
||||
private readonly HashSet<int> _visibleDaemonEntityIndices = new HashSet<int>();
|
||||
private readonly List<AetheriaRuntimeDaemonWormholeExit> _daemonWormholeExits =
|
||||
new List<AetheriaRuntimeDaemonWormholeExit>();
|
||||
|
||||
public Dictionary<Wormhole, (GameObject gravity, CompassIcon icon)> WormholeInstances = new Dictionary<Wormhole, (GameObject, CompassIcon)>();
|
||||
private List<ItemPickup> _loot = new List<ItemPickup>();
|
||||
|
|
@ -178,10 +181,14 @@ public class ZoneRenderer : MonoBehaviour
|
|||
_transposer = SceneCamera.GetCinemachineComponent<CinemachineTransposer>();
|
||||
}
|
||||
|
||||
public void LoadZone(Zone zone, AetheriaRuntimeZoneSnapshotCommit daemonZone = null)
|
||||
public void LoadZone(
|
||||
Zone zone,
|
||||
AetheriaRuntimeZoneSnapshotCommit daemonZone = null,
|
||||
AetheriaRuntimeRunCheckpointCommit daemonRun = null)
|
||||
{
|
||||
ClearZone();
|
||||
Zone = zone;
|
||||
_daemonRunSnapshot = daemonRun;
|
||||
_daemonZoneSnapshot = daemonZone;
|
||||
SectorBrushes.localScale = zone.Radius * 2 * Vector3.one;
|
||||
SlimeGravityCamera.orthographicSize = zone.Radius;
|
||||
|
|
@ -217,17 +224,24 @@ public class ZoneRenderer : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
if (zone.GalaxyZone != null)
|
||||
AetheriaRuntimeDaemonRenderQueries.QueryWormholeExits(
|
||||
_daemonRunSnapshot,
|
||||
_daemonZoneSnapshot,
|
||||
zone.Radius,
|
||||
Settings.WormholeDistanceRatio,
|
||||
_daemonWormholeExits);
|
||||
foreach (var exit in _daemonWormholeExits)
|
||||
{
|
||||
foreach (var adjacentZone in zone.GalaxyZone.AdjacentZones)
|
||||
var target = zone.Galaxy != null &&
|
||||
exit.TargetZoneIndex >= 0 &&
|
||||
exit.TargetZoneIndex < zone.Galaxy.Zones.Length
|
||||
? zone.Galaxy.Zones[exit.TargetZoneIndex]
|
||||
: null;
|
||||
AddWormhole(new Wormhole
|
||||
{
|
||||
var dir = normalize(adjacentZone.Position - zone.GalaxyZone.Position);
|
||||
AddWormhole(new Wormhole
|
||||
{
|
||||
Target = adjacentZone,
|
||||
Position = AetheriaMath.ToCult(dir * zone.Radius * Settings.WormholeDistanceRatio)
|
||||
});
|
||||
}
|
||||
Target = target,
|
||||
Position = AetheriaMath.ToCult(new float2((float)exit.PositionX, (float)exit.PositionZ))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -188,6 +188,29 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public bool Hostile { get; }
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeDaemonWormholeExit
|
||||
{
|
||||
public AetheriaRuntimeDaemonWormholeExit(
|
||||
int targetZoneIndex,
|
||||
double directionX,
|
||||
double directionZ,
|
||||
double positionX,
|
||||
double positionZ)
|
||||
{
|
||||
TargetZoneIndex = targetZoneIndex;
|
||||
DirectionX = directionX;
|
||||
DirectionZ = directionZ;
|
||||
PositionX = positionX;
|
||||
PositionZ = positionZ;
|
||||
}
|
||||
|
||||
public int TargetZoneIndex { get; }
|
||||
public double DirectionX { get; }
|
||||
public double DirectionZ { get; }
|
||||
public double PositionX { get; }
|
||||
public double PositionZ { get; }
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeGravityTerrainBand
|
||||
{
|
||||
public AetheriaRuntimeGravityTerrainBand(double startDepth, double depthRange)
|
||||
|
|
@ -488,6 +511,55 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return entityIndices.Count;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonWormholeExit[] QueryWormholeExits(
|
||||
AetheriaRuntimeRunCheckpointCommit? run,
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
double zoneRadius,
|
||||
double wormholeDistanceRatio)
|
||||
{
|
||||
var exits = new List<AetheriaRuntimeDaemonWormholeExit>();
|
||||
QueryWormholeExits(run, zone, zoneRadius, wormholeDistanceRatio, exits);
|
||||
return exits.Count == 0 ? Array.Empty<AetheriaRuntimeDaemonWormholeExit>() : exits.ToArray();
|
||||
}
|
||||
|
||||
public static int QueryWormholeExits(
|
||||
AetheriaRuntimeRunCheckpointCommit? run,
|
||||
AetheriaRuntimeZoneSnapshotCommit? zone,
|
||||
double zoneRadius,
|
||||
double wormholeDistanceRatio,
|
||||
List<AetheriaRuntimeDaemonWormholeExit> exits)
|
||||
{
|
||||
if (exits == null) throw new ArgumentNullException(nameof(exits));
|
||||
exits.Clear();
|
||||
if (run == null || zone == null)
|
||||
return 0;
|
||||
|
||||
var zones = BuildZoneMap(run);
|
||||
var distance = Math.Max(0, zoneRadius) * Math.Max(0, wormholeDistanceRatio);
|
||||
foreach (var targetZoneIndex in zone.AdjacentZoneIndices ?? Array.Empty<int>())
|
||||
{
|
||||
if (!zones.TryGetValue(targetZoneIndex, out var target))
|
||||
continue;
|
||||
|
||||
var deltaX = target.PositionX - zone.PositionX;
|
||||
var deltaZ = target.PositionY - zone.PositionY;
|
||||
var magnitude = Math.Sqrt(deltaX * deltaX + deltaZ * deltaZ);
|
||||
if (magnitude <= 0)
|
||||
continue;
|
||||
|
||||
var directionX = deltaX / magnitude;
|
||||
var directionZ = deltaZ / magnitude;
|
||||
exits.Add(new AetheriaRuntimeDaemonWormholeExit(
|
||||
target.ZoneIndex,
|
||||
directionX,
|
||||
directionZ,
|
||||
directionX * distance,
|
||||
directionZ * distance));
|
||||
}
|
||||
|
||||
return exits.Count;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonRenderGroupDocument[] QueryRenderGroups(
|
||||
AetheriaRuntimeDaemonSoaViewIndex? index,
|
||||
double minX,
|
||||
|
|
@ -606,6 +678,18 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return entities;
|
||||
}
|
||||
|
||||
private static Dictionary<int, AetheriaRuntimeZoneSnapshotCommit> BuildZoneMap(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
var zones = new Dictionary<int, AetheriaRuntimeZoneSnapshotCommit>();
|
||||
foreach (var zone in run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
{
|
||||
if (zone != null && zone.ZoneIndex >= 0)
|
||||
zones[zone.ZoneIndex] = zone;
|
||||
}
|
||||
|
||||
return zones;
|
||||
}
|
||||
|
||||
private static Dictionary<string, AetheriaRuntimeXzPoint> BuildOrbitPositions(AetheriaRuntimeZoneSnapshotCommit zone)
|
||||
{
|
||||
var source = BuildOrbitMap(zone);
|
||||
|
|
|
|||
Loading…
Reference in a new issue