feat: simplified local-space and celestial, removed bubbles
This commit is contained in:
@@ -175,12 +175,12 @@ public sealed partial class SimulationEngine
|
||||
private void UpdateOrbitalState(SimulationWorld world)
|
||||
{
|
||||
var worldTimeSeconds = (float)world.OrbitalTimeSeconds;
|
||||
var spatialNodesById = world.SpatialNodes.ToDictionary(node => node.Id, StringComparer.Ordinal);
|
||||
var celestialsById = world.Celestials.ToDictionary(c => c.Id, StringComparer.Ordinal);
|
||||
|
||||
foreach (var system in world.Systems)
|
||||
{
|
||||
var starNodeId = $"node-{system.Definition.Id}-star";
|
||||
if (spatialNodesById.TryGetValue(starNodeId, out var starNode))
|
||||
if (celestialsById.TryGetValue(starNodeId, out var starNode))
|
||||
{
|
||||
starNode.Position = Vector3.Zero;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ public sealed partial class SimulationEngine
|
||||
{
|
||||
var planet = system.Definition.Planets[planetIndex];
|
||||
var planetNodeId = $"node-{system.Definition.Id}-planet-{planetIndex + 1}";
|
||||
if (!spatialNodesById.TryGetValue(planetNodeId, out var planetNode))
|
||||
if (!celestialsById.TryGetValue(planetNodeId, out var planetNode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public sealed partial class SimulationEngine
|
||||
foreach (var lagrange in EnumeratePlanetLagrangePoints(planetPosition, planet))
|
||||
{
|
||||
var lagrangeId = $"node-{system.Definition.Id}-planet-{planetIndex + 1}-{lagrange.Designation.ToLowerInvariant()}";
|
||||
if (spatialNodesById.TryGetValue(lagrangeId, out var lagrangeNode))
|
||||
if (celestialsById.TryGetValue(lagrangeId, out var lagrangeNode))
|
||||
{
|
||||
lagrangeNode.Position = lagrange.Position;
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public sealed partial class SimulationEngine
|
||||
for (var moonIndex = 0; moonIndex < planet.MoonCount; moonIndex += 1)
|
||||
{
|
||||
var moonId = $"node-{system.Definition.Id}-planet-{planetIndex + 1}-moon-{moonIndex + 1}";
|
||||
if (!spatialNodesById.TryGetValue(moonId, out var moonNode))
|
||||
if (!celestialsById.TryGetValue(moonId, out var moonNode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -221,30 +221,22 @@ public sealed partial class SimulationEngine
|
||||
|
||||
foreach (var station in world.Stations)
|
||||
{
|
||||
if (station.AnchorNodeId is null || !spatialNodesById.TryGetValue(station.AnchorNodeId, out var anchorNode))
|
||||
if (station.CelestialId is null || !celestialsById.TryGetValue(station.CelestialId, out var anchorCelestial))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
station.Position = anchorNode.Position;
|
||||
if (station.NodeId is not null && spatialNodesById.TryGetValue(station.NodeId, out var stationNode))
|
||||
{
|
||||
stationNode.Position = station.Position;
|
||||
}
|
||||
station.Position = anchorCelestial.Position;
|
||||
}
|
||||
|
||||
foreach (var node in world.Nodes)
|
||||
{
|
||||
if (node.AnchorNodeId is null || !spatialNodesById.TryGetValue(node.AnchorNodeId, out var anchorNode))
|
||||
if (node.CelestialId is null || !celestialsById.TryGetValue(node.CelestialId, out var anchorCelestial))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
node.Position = Add(anchorNode.Position, ComputeResourceNodeOffset(node, worldTimeSeconds));
|
||||
if (spatialNodesById.TryGetValue(node.Id, out var resourceNode))
|
||||
{
|
||||
resourceNode.Position = node.Position;
|
||||
}
|
||||
node.Position = Add(anchorCelestial.Position, ComputeResourceNodeOffset(node, worldTimeSeconds));
|
||||
}
|
||||
|
||||
foreach (var ship in world.Ships.Where(ship => ship.DockedStationId is not null))
|
||||
@@ -263,11 +255,6 @@ public sealed partial class SimulationEngine
|
||||
|
||||
private static void SyncSpatialState(SimulationWorld world)
|
||||
{
|
||||
foreach (var bubble in world.LocalBubbles)
|
||||
{
|
||||
bubble.OccupantShipIds.Clear();
|
||||
}
|
||||
|
||||
foreach (var ship in world.Ships)
|
||||
{
|
||||
ship.SpatialState.CurrentSystemId = ship.SystemId;
|
||||
@@ -275,25 +262,17 @@ public sealed partial class SimulationEngine
|
||||
ship.SpatialState.SystemPosition = ship.Position;
|
||||
if (ship.SpatialState.Transit is not null)
|
||||
{
|
||||
ship.SpatialState.CurrentNodeId = null;
|
||||
ship.SpatialState.CurrentBubbleId = null;
|
||||
ship.SpatialState.CurrentCelestialId = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
ship.SpatialState.SpaceLayer = SpaceLayerKinds.LocalSpace;
|
||||
ship.SpatialState.MovementRegime = MovementRegimeKinds.LocalFlight;
|
||||
var nearestNode = world.SpatialNodes
|
||||
var nearestCelestial = world.Celestials
|
||||
.Where(candidate => candidate.SystemId == ship.SystemId)
|
||||
.OrderBy(candidate => candidate.Position.DistanceTo(ship.Position))
|
||||
.FirstOrDefault();
|
||||
ship.SpatialState.CurrentNodeId = nearestNode?.Id;
|
||||
ship.SpatialState.CurrentBubbleId = nearestNode?.BubbleId;
|
||||
|
||||
if (nearestNode is not null)
|
||||
{
|
||||
var nearestBubble = world.LocalBubbles.FirstOrDefault(candidate => candidate.Id == nearestNode.BubbleId);
|
||||
nearestBubble?.OccupantShipIds.Add(ship.Id);
|
||||
}
|
||||
ship.SpatialState.CurrentCelestialId = nearestCelestial?.Id;
|
||||
|
||||
if (ship.DockedStationId is null)
|
||||
{
|
||||
@@ -301,15 +280,10 @@ public sealed partial class SimulationEngine
|
||||
}
|
||||
|
||||
var station = world.Stations.FirstOrDefault(candidate => candidate.Id == ship.DockedStationId);
|
||||
if (station?.BubbleId is null)
|
||||
if (station?.CelestialId is not null)
|
||||
{
|
||||
continue;
|
||||
ship.SpatialState.CurrentCelestialId = station.CelestialId;
|
||||
}
|
||||
|
||||
ship.SpatialState.CurrentNodeId = station.NodeId;
|
||||
ship.SpatialState.CurrentBubbleId = station.BubbleId;
|
||||
var bubble = world.LocalBubbles.FirstOrDefault(candidate => candidate.Id == station.BubbleId);
|
||||
bubble?.OccupantShipIds.Add(ship.Id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user