Carry typed orbit keys through zone construction
This commit is contained in:
parent
397f3aff5a
commit
4217394cc2
6 changed files with 136 additions and 18 deletions
Binary file not shown.
|
|
@ -20,6 +20,7 @@ RequireTypedOrbitConsumerKeys(root);
|
|||
RequireKeyedOrbitRuntimeWrappers(root);
|
||||
RequireNativeZoneKeyResolution(root);
|
||||
RequireTypedZoneRuntimeCollections(root);
|
||||
RequireTypedZoneConstructionKeys(root);
|
||||
RequireTypedAsteroidZoneApi(root);
|
||||
RequireTypedFactionShellLinks(root);
|
||||
RequireFactionKeyIdentity(root);
|
||||
|
|
@ -1010,8 +1011,8 @@ static void RequireTypedOrbitalEntityOrbitKeys(string root)
|
|||
},
|
||||
[Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneGenerator.cs")] = new[]
|
||||
{
|
||||
"turret.OrbitKey = Zone.OrbitKey(turretOrbit.ID);",
|
||||
"station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);"
|
||||
"turret.OrbitKey = turretOrbit.OrbitKey;",
|
||||
"station.OrbitKey = lagrangeOrbit.OrbitKey;"
|
||||
},
|
||||
[Path.Combine(root, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs")] = new[]
|
||||
{
|
||||
|
|
@ -1152,7 +1153,7 @@ static void RequireKeyedOrbitRuntimeWrappers(string root)
|
|||
{
|
||||
"public Orbit Orbit;",
|
||||
"public Orbit Orbit { get; }",
|
||||
"var runtimeBelt = new AsteroidBelt(belt, Orbits[OrbitKey(belt.Orbit)]);",
|
||||
"var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);",
|
||||
"AsteroidBelts[runtimeBelt.BodyKey] = runtimeBelt;",
|
||||
"belt.NewOrbitPosition = GetOrbitPosition(belt.Orbit.ParentOrbitKey);",
|
||||
"public AsteroidBelt(AsteroidBeltConstructionData data, Orbit orbit)",
|
||||
|
|
@ -1261,7 +1262,14 @@ static void RequireNativeZoneKeyResolution(string root)
|
|||
"if (_asteroidBeltsById.TryGetValue(bodyId, out var belt))",
|
||||
"var parentPosition = string.IsNullOrWhiteSpace(orbit.ParentOrbitKey)",
|
||||
": GetOrbitPosition(orbit.ParentOrbitKey);",
|
||||
"return TryGetOrbit(orbitKey, out var orbit) ? orbit.Velocity : float2.zero;"
|
||||
"return TryGetOrbit(orbitKey, out var orbit) ? orbit.Velocity : float2.zero;",
|
||||
"var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);",
|
||||
"var runtimeSun = new Sun(settings, sun, Orbits[planet.OrbitKey]);",
|
||||
"var runtimeGas = new GasGiant(settings, gas, Orbits[planet.OrbitKey]);",
|
||||
"var runtimePlanet = new Planet(settings, planet, Orbits[planet.OrbitKey]);",
|
||||
"BodyKey = data.BodyKey ?? \"\";",
|
||||
"OrbitKey = data.OrbitKey ?? \"\";",
|
||||
"ParentOrbitKey = data.ParentOrbitKey ?? \"\";"
|
||||
};
|
||||
var missingSymbols = requiredSymbols
|
||||
.Where(symbol => !zoneSource.Contains(symbol, StringComparison.Ordinal))
|
||||
|
|
@ -1355,6 +1363,92 @@ static void RequireTypedZoneRuntimeCollections(string root)
|
|||
}
|
||||
}
|
||||
|
||||
static void RequireTypedZoneConstructionKeys(string root)
|
||||
{
|
||||
var checkedFiles = new[]
|
||||
{
|
||||
Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneConstructionData.cs"),
|
||||
Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneGenerator.cs"),
|
||||
Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs")
|
||||
};
|
||||
|
||||
var forbiddenSymbols = new[]
|
||||
{
|
||||
"var runtimeBelt = new AsteroidBelt(belt, Orbits[OrbitKey(belt.Orbit)]);",
|
||||
"var runtimeSun = new Sun(settings, sun, Orbits[OrbitKey(planet.Orbit)]);",
|
||||
"var runtimeGas = new GasGiant(settings, gas, Orbits[OrbitKey(planet.Orbit)]);",
|
||||
"var runtimePlanet = new Planet(settings, planet, Orbits[OrbitKey(planet.Orbit)]);",
|
||||
"turret.OrbitKey = Zone.OrbitKey(turretOrbit.ID);",
|
||||
"station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);"
|
||||
};
|
||||
|
||||
var hits = checkedFiles
|
||||
.Where(File.Exists)
|
||||
.SelectMany(path => File.ReadLines(path)
|
||||
.Select((line, index) => new { Path = path, LineNumber = index + 1, Line = line }))
|
||||
.Where(line => forbiddenSymbols.Any(symbol => line.Line.Contains(symbol, StringComparison.Ordinal)))
|
||||
.Select(line => $"{Path.GetRelativePath(root, line.Path)}:{line.LineNumber}: {line.Line.Trim()}")
|
||||
.ToArray();
|
||||
|
||||
if (hits.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Zone construction and generation must hand orbit/body identity through typed key fields instead of recomputing runtime authority from legacy GUID refs: " +
|
||||
string.Join("; ", hits));
|
||||
}
|
||||
|
||||
var requiredSymbols = new Dictionary<string, string[]>
|
||||
{
|
||||
[Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneConstructionData.cs")] = new[]
|
||||
{
|
||||
"public string BodyKey = \"\";",
|
||||
"public string OrbitKey = \"\";",
|
||||
"public string ParentOrbitKey = \"\";"
|
||||
},
|
||||
[Path.Combine(root, "Assets", "Scripts", "ServerShared", "ZoneGenerator.cs")] = new[]
|
||||
{
|
||||
"data.OrbitKey = Zone.OrbitKey(data.ID);",
|
||||
"data.ParentOrbitKey = orbitInverseMap[data].Parent != null",
|
||||
"planetData.BodyKey = Zone.BodyKey(planetData.ID);",
|
||||
"planetData.OrbitKey = orbitMap[planet].OrbitKey;",
|
||||
"lagrangeOrbit.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);",
|
||||
"ParentOrbitKey = baseOrbit.ParentOrbitKey,",
|
||||
"turretOrbit.OrbitKey = Zone.OrbitKey(turretOrbit.ID);",
|
||||
"ParentOrbitKey = orbit.ParentOrbitKey,",
|
||||
"turret.OrbitKey = turretOrbit.OrbitKey;",
|
||||
"station.OrbitKey = lagrangeOrbit.OrbitKey;"
|
||||
},
|
||||
[Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs")] = new[]
|
||||
{
|
||||
"var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);",
|
||||
"var runtimeSun = new Sun(settings, sun, Orbits[planet.OrbitKey]);",
|
||||
"var runtimeGas = new GasGiant(settings, gas, Orbits[planet.OrbitKey]);",
|
||||
"var runtimePlanet = new Planet(settings, planet, Orbits[planet.OrbitKey]);",
|
||||
"BodyKey = data.BodyKey ?? \"\";",
|
||||
"OrbitKey = data.OrbitKey ?? \"\";",
|
||||
"ParentOrbitKey = data.ParentOrbitKey ?? \"\";"
|
||||
}
|
||||
};
|
||||
|
||||
var missingSymbols = requiredSymbols
|
||||
.Where(pair => !File.Exists(pair.Key) || pair.Value.Any(symbol => !File.ReadAllText(pair.Key).Contains(symbol, StringComparison.Ordinal)))
|
||||
.SelectMany(pair =>
|
||||
{
|
||||
var text = File.Exists(pair.Key) ? File.ReadAllText(pair.Key) : "";
|
||||
return pair.Value
|
||||
.Where(symbol => !text.Contains(symbol, StringComparison.Ordinal))
|
||||
.Select(symbol => $"{Path.GetRelativePath(root, pair.Key)}: missing {symbol}");
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
if (missingSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Zone construction inputs and generator seams must retain typed orbit/body keys as the handoff authority: " +
|
||||
string.Join("; ", missingSymbols));
|
||||
}
|
||||
}
|
||||
|
||||
static void RequireTypedAsteroidZoneApi(string root)
|
||||
{
|
||||
var zoneSourcePath = Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs");
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ needs actual allegiance weights, not only display counts. Runtime checkpoints
|
|||
now persist session faction relationships into typed run state, and runtime
|
||||
sessions publish typed state-host liveness. Zone checkpoints persist generated
|
||||
orbit/body rows into `AetheriaZoneState`, so `ZoneConstructionBlueprint` is a
|
||||
one-shot construction input rather than the retained surface carrying celestial graph facts. Entity checkpoints
|
||||
one-shot construction input carrying typed orbit/body keys rather than the retained surface carrying celestial graph facts. Entity checkpoints
|
||||
persist hull simulation grids into `AetheriaEntitySnapshot`, so
|
||||
`EntityConstructionBlueprint` is no longer the only surface carrying those live
|
||||
values. Run checkpoints project the flattened live entity graph, including
|
||||
|
|
|
|||
|
|
@ -70,22 +70,22 @@ public class Zone
|
|||
switch (planet)
|
||||
{
|
||||
case AsteroidBeltConstructionData belt:
|
||||
var runtimeBelt = new AsteroidBelt(belt, Orbits[OrbitKey(belt.Orbit)]);
|
||||
var runtimeBelt = new AsteroidBelt(belt, Orbits[belt.OrbitKey]);
|
||||
AsteroidBelts[runtimeBelt.BodyKey] = runtimeBelt;
|
||||
_asteroidBeltsById[runtimeBelt.ID] = runtimeBelt;
|
||||
break;
|
||||
case SunConstructionData sun:
|
||||
var runtimeSun = new Sun(settings, sun, Orbits[OrbitKey(planet.Orbit)]);
|
||||
var runtimeSun = new Sun(settings, sun, Orbits[planet.OrbitKey]);
|
||||
PlanetInstances[runtimeSun.BodyKey] = runtimeSun;
|
||||
_planetsById[runtimeSun.ID] = runtimeSun;
|
||||
break;
|
||||
case GasGiantConstructionData gas:
|
||||
var runtimeGas = new GasGiant(settings, gas, Orbits[OrbitKey(planet.Orbit)]);
|
||||
var runtimeGas = new GasGiant(settings, gas, Orbits[planet.OrbitKey]);
|
||||
PlanetInstances[runtimeGas.BodyKey] = runtimeGas;
|
||||
_planetsById[runtimeGas.ID] = runtimeGas;
|
||||
break;
|
||||
default:
|
||||
var runtimePlanet = new Planet(settings, planet, Orbits[OrbitKey(planet.Orbit)]);
|
||||
var runtimePlanet = new Planet(settings, planet, Orbits[planet.OrbitKey]);
|
||||
PlanetInstances[runtimePlanet.BodyKey] = runtimePlanet;
|
||||
_planetsById[runtimePlanet.ID] = runtimePlanet;
|
||||
break;
|
||||
|
|
@ -439,9 +439,9 @@ public class Planet
|
|||
Settings = settings;
|
||||
Orbit = orbit;
|
||||
ID = data.ID;
|
||||
BodyKey = Zone.BodyKey(data.ID);
|
||||
BodyKey = data.BodyKey ?? "";
|
||||
Name = data.Name ?? "";
|
||||
OrbitKey = Zone.OrbitKey(data.Orbit);
|
||||
OrbitKey = data.OrbitKey ?? "";
|
||||
Mass = data.Mass;
|
||||
Resources = data.Resources;
|
||||
BodyRadiusMultiplier = data.BodyRadiusMultiplier;
|
||||
|
|
@ -552,9 +552,9 @@ public class AsteroidBelt
|
|||
_asteroids = data.Asteroids;
|
||||
Orbit = orbit;
|
||||
ID = data.ID;
|
||||
BodyKey = Zone.BodyKey(data.ID);
|
||||
BodyKey = data.BodyKey ?? "";
|
||||
Name = data.Name ?? "";
|
||||
OrbitKey = Zone.OrbitKey(data.Orbit);
|
||||
OrbitKey = data.OrbitKey ?? "";
|
||||
Mass = data.Mass;
|
||||
Resources = data.Resources;
|
||||
BodyRadiusMultiplier = data.BodyRadiusMultiplier;
|
||||
|
|
@ -596,8 +596,8 @@ public class Orbit
|
|||
public Orbit(PlanetSettings settings, OrbitConstructionData data)
|
||||
{
|
||||
ID = data.ID;
|
||||
OrbitKey = Zone.OrbitKey(data.ID);
|
||||
ParentOrbitKey = Zone.OrbitKey(data.Parent);
|
||||
OrbitKey = data.OrbitKey ?? "";
|
||||
ParentOrbitKey = data.ParentOrbitKey ?? "";
|
||||
Distance = data.Distance;
|
||||
Phase = data.Phase;
|
||||
FixedPosition = data.FixedPosition;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,14 @@ public abstract class BodyConstructionData : INamedEntry
|
|||
{
|
||||
public Guid ID = Guid.NewGuid();
|
||||
|
||||
public string BodyKey = "";
|
||||
|
||||
public string Name = "";
|
||||
|
||||
public Guid Orbit;
|
||||
|
||||
public string OrbitKey = "";
|
||||
|
||||
public float Mass = 0;
|
||||
|
||||
public Dictionary<string, float> Resources = new Dictionary<string, float>();
|
||||
|
|
@ -107,8 +111,12 @@ public class OrbitConstructionData
|
|||
{
|
||||
public Guid ID = Guid.NewGuid();
|
||||
|
||||
public string OrbitKey = "";
|
||||
|
||||
public Guid Parent;
|
||||
|
||||
public string ParentOrbitKey = "";
|
||||
|
||||
public float Distance;
|
||||
|
||||
public float Phase;
|
||||
|
|
|
|||
|
|
@ -102,11 +102,14 @@ public static class ZoneGenerator
|
|||
{
|
||||
var data = new OrbitConstructionData
|
||||
{
|
||||
OrbitKey = "",
|
||||
ParentOrbitKey = "",
|
||||
FixedPosition = planet.FixedPosition,
|
||||
Distance = planet.Distance,
|
||||
//Period = planet.Period,
|
||||
Phase = planet.Phase
|
||||
};
|
||||
data.OrbitKey = Zone.OrbitKey(data.ID);
|
||||
orbitMap[planet] = data;
|
||||
orbitInverseMap[data] = planet;
|
||||
return data;
|
||||
|
|
@ -114,9 +117,14 @@ public static class ZoneGenerator
|
|||
|
||||
// Link orbit construction parents to generated orbit IDs.
|
||||
foreach (var data in blueprint.Orbits)
|
||||
{
|
||||
data.Parent = orbitInverseMap[data].Parent != null
|
||||
? orbitMap[orbitInverseMap[data].Parent].ID
|
||||
: Guid.Empty;
|
||||
data.ParentOrbitKey = orbitInverseMap[data].Parent != null
|
||||
? orbitMap[orbitInverseMap[data].Parent].OrbitKey
|
||||
: "";
|
||||
}
|
||||
|
||||
// Cache resource densities
|
||||
// var resourceMaps = mapLayers.Values
|
||||
|
|
@ -159,8 +167,10 @@ public static class ZoneGenerator
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
planetData.BodyKey = Zone.BodyKey(planetData.ID);
|
||||
planetData.Mass = planet.Mass;
|
||||
planetData.Orbit = orbitMap[planet].ID;
|
||||
planetData.OrbitKey = orbitMap[planet].OrbitKey;
|
||||
// planetData.Resources = planetResources;
|
||||
planetData.Name = planetData.ID.ToString().Substring(0, 8);
|
||||
if (planetData is AsteroidBeltConstructionData beltData)
|
||||
|
|
@ -255,10 +265,13 @@ public static class ZoneGenerator
|
|||
var lagrangeOrbit = new OrbitConstructionData
|
||||
{
|
||||
ID = Guid.NewGuid(),
|
||||
OrbitKey = "",
|
||||
Parent = baseOrbit.Parent,
|
||||
ParentOrbitKey = baseOrbit.ParentOrbitKey,
|
||||
Distance = baseOrbit.Distance,
|
||||
Phase = baseOrbit.Phase + PI / 3 * sign(random.NextFloat() - .5f)
|
||||
};
|
||||
lagrangeOrbit.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);
|
||||
blueprint.Orbits.Add(lagrangeOrbit);
|
||||
return lagrangeOrbit;
|
||||
}
|
||||
|
|
@ -270,14 +283,17 @@ public static class ZoneGenerator
|
|||
var turretOrbit = new OrbitConstructionData
|
||||
{
|
||||
ID = Guid.NewGuid(),
|
||||
OrbitKey = "",
|
||||
Parent = orbit.Parent,
|
||||
ParentOrbitKey = orbit.ParentOrbitKey,
|
||||
Distance = orbit.Distance,
|
||||
Phase = orbit.Phase + phase
|
||||
};
|
||||
turretOrbit.OrbitKey = Zone.OrbitKey(turretOrbit.ID);
|
||||
blueprint.Orbits.Add(turretOrbit);
|
||||
var turret = loadoutGenerator.GenerateTurretLoadout();
|
||||
if (turret == null) return;
|
||||
turret.OrbitKey = Zone.OrbitKey(turretOrbit.ID);
|
||||
turret.OrbitKey = turretOrbit.OrbitKey;
|
||||
blueprint.Entities.Add(turret);
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +313,7 @@ public static class ZoneGenerator
|
|||
var orbit = selectedStationOrbits[i];
|
||||
var lagrangeOrbit = CreateLagrangeOrbit(orbit);
|
||||
var station = GetLoadoutGenerator(story.Faction).GenerateStationLoadout();
|
||||
station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);
|
||||
station.OrbitKey = lagrangeOrbit.OrbitKey;
|
||||
station.SecurityLevel = story.Security;
|
||||
station.SecurityRadius = blueprint.Radius;
|
||||
station.Story = i;
|
||||
|
|
@ -314,7 +330,7 @@ public static class ZoneGenerator
|
|||
var lagrangeOrbit = CreateLagrangeOrbit(orbit);
|
||||
var station = GetLoadoutGenerator(nearestFaction).GenerateStationLoadout();
|
||||
if (station == null) continue;
|
||||
station.OrbitKey = Zone.OrbitKey(lagrangeOrbit.ID);
|
||||
station.OrbitKey = lagrangeOrbit.OrbitKey;
|
||||
station.SecurityLevel = security;
|
||||
station.SecurityRadius = blueprint.Radius;
|
||||
blueprint.Entities.Add(station);
|
||||
|
|
|
|||
Loading…
Reference in a new issue