Import typed interior hardpoint geometry

This commit is contained in:
Meta Vens 2026-06-13 09:47:25 +01:00
commit e41318916f
151 changed files with 644 additions and 270 deletions

Binary file not shown.

View file

@ -196,6 +196,12 @@ internal static class LegacyCatalogReader
"ControlModule",
"AetherDrive"
]);
private static readonly Dictionary<int, string> ItemRotations = CreateEnumMap([
"None",
"CounterClockwise",
"Reversed",
"Clockwise"
]);
private static readonly Dictionary<int, string> HullTypes = CreateEnumMap(["Ship", "Station", "Turret"]);
private static readonly Dictionary<int, string> WeaponRanges = CreateEnumMap(["Melee", "Short", "Medium", "Long"]);
private static readonly Dictionary<int, string> WeaponCalibers = CreateEnumMap(["Small", "Medium", "Large", "ExtraLarge"]);
@ -305,6 +311,8 @@ internal static class LegacyCatalogReader
var name = GetString(payload, 1);
var description = GetString(payload, 2);
var shape = ReadShape(payload, 5);
var interiorShape = ReadInteriorShape(unionKey, payload, shape);
var hardpoints = unionKey == 3 ? ReadHardpoints(payload, 23) : [];
var behaviorKinds = ReadBehaviorKinds(payload, unionKey == 31 || unionKey is 2 or 3 or 29 or 30 ? 11 : 10);
var summary = new AetheriaLegacyCatalogEntrySummary
{
@ -332,6 +340,11 @@ internal static class LegacyCatalogReader
ShapeHeight = shape.Height,
OccupiedCells = shape.OccupiedCells,
ShapeCells = shape.Cells,
InteriorShapeWidth = interiorShape.Width,
InteriorShapeHeight = interiorShape.Height,
InteriorOccupiedCells = interiorShape.OccupiedCells,
InteriorShapeCells = interiorShape.Cells,
Hardpoints = hardpoints,
HardpointType = GetHardpointType(unionKey, payload),
HullType = unionKey == 3 ? GetEnumName(payload, 25, HullTypes) : "",
BehaviorKinds = behaviorKinds,
@ -589,6 +602,44 @@ internal static class LegacyCatalogReader
return flags.Length == 0 ? "" : string.Join("|", flags);
}
private static AetheriaItemHardpoint[] ReadHardpoints(IReadOnlyDictionary<int, object?> payload, int key)
{
if (!payload.TryGetValue(key, out var value) || value is not object?[] hardpoints)
{
return [];
}
return hardpoints
.Select(ReadHardpoint)
.Where(hardpoint => hardpoint != null)
.Cast<AetheriaItemHardpoint>()
.ToArray();
}
private static AetheriaItemHardpoint? ReadHardpoint(object? value)
{
if (value is not object?[] fields)
{
return null;
}
var position = ReadPoint(fields.ElementAtOrDefault(1));
var shape = ReadShapeValue(fields.ElementAtOrDefault(2));
return new AetheriaItemHardpoint
{
Type = ReadEnumName(fields.ElementAtOrDefault(0), HardpointTypes),
PositionX = position.X,
PositionY = position.Y,
ShapeWidth = shape.Width,
ShapeHeight = shape.Height,
OccupiedCells = shape.OccupiedCells,
ShapeCells = shape.Cells,
Transform = ReadStringValue(fields.ElementAtOrDefault(3)),
Rotation = ReadEnumName(fields.ElementAtOrDefault(4), ItemRotations),
Armor = ReadDoubleValue(fields.ElementAtOrDefault(5))
};
}
private static string[] ReadBehaviorKinds(IReadOnlyDictionary<int, object?> payload, int key)
{
if (!payload.TryGetValue(key, out var value) || value is not object?[] behaviors)
@ -641,6 +692,29 @@ internal static class LegacyCatalogReader
return ShapeFacts.Empty;
}
return ReadShapeValue(value);
}
private static ShapeFacts ReadInteriorShape(
int unionKey,
IReadOnlyDictionary<int, object?> payload,
ShapeFacts itemShape)
{
return unionKey switch
{
3 => itemShape.Shrink(),
29 or 30 => ReadShape(payload, 24),
_ => ShapeFacts.Empty
};
}
private static ShapeFacts ReadShapeValue(object? value)
{
if (value == null)
{
return ShapeFacts.Empty;
}
var matrix = UnwrapShapeMatrix(value);
if (matrix is not object?[] columns)
{
@ -690,6 +764,53 @@ internal static class LegacyCatalogReader
{
return value is object?[] shapeObject && shapeObject.Length == 1 ? shapeObject[0] : value;
}
private static PointFacts ReadPoint(object? value)
{
if (value is not object?[] coordinates)
{
return PointFacts.Empty;
}
return new PointFacts(
ReadIntValue(coordinates.ElementAtOrDefault(0)),
ReadIntValue(coordinates.ElementAtOrDefault(1)));
}
private static string ReadEnumName(object? value, IReadOnlyDictionary<int, string> names)
{
var index = ReadIntValue(value);
return names.TryGetValue(index, out var name) ? name : "";
}
private static int ReadIntValue(object? value)
{
return value switch
{
long integerValue => checked((int) integerValue),
int integerValue => integerValue,
double doubleValue => checked((int) doubleValue),
float floatValue => checked((int) floatValue),
_ => 0
};
}
private static double ReadDoubleValue(object? value)
{
return value switch
{
double doubleValue => doubleValue,
float floatValue => floatValue,
long integerValue => integerValue,
int integerValue => integerValue,
_ => 0
};
}
private static string ReadStringValue(object? value)
{
return value as string ?? "";
}
}
internal sealed record LegacyCatalogEntry(
@ -703,4 +824,39 @@ internal readonly record struct ShapeFacts(int Width, int Height, AetheriaShapeC
public static ShapeFacts Empty { get; } = new(0, 0, []);
public int OccupiedCells => Cells.Length;
public ShapeFacts Shrink()
{
if (Width == 0 || Height == 0 || Cells.Length == 0)
{
return Empty;
}
var occupied = Cells
.Select(cell => (cell.X, cell.Y))
.ToHashSet();
var interior = Cells
.Where(cell =>
IsOccupied(occupied, cell.X - 1, cell.Y - 1) &&
IsOccupied(occupied, cell.X, cell.Y - 1) &&
IsOccupied(occupied, cell.X + 1, cell.Y - 1) &&
IsOccupied(occupied, cell.X - 1, cell.Y) &&
IsOccupied(occupied, cell.X + 1, cell.Y) &&
IsOccupied(occupied, cell.X - 1, cell.Y + 1) &&
IsOccupied(occupied, cell.X, cell.Y + 1) &&
IsOccupied(occupied, cell.X + 1, cell.Y + 1))
.Select(cell => new AetheriaShapeCell { X = cell.X, Y = cell.Y })
.ToArray();
return new ShapeFacts(Width, Height, interior);
}
private static bool IsOccupied(IReadOnlySet<(int X, int Y)> occupied, int x, int y)
{
return occupied.Contains((x, y));
}
}
internal readonly record struct PointFacts(int X, int Y)
{
public static PointFacts Empty { get; } = new(0, 0);
}

View file

@ -38,6 +38,23 @@ if (shaped.ShapeCells.Any(cell => cell.X < 0 || cell.Y < 0 || cell.X >= shaped.S
throw new InvalidOperationException($"Runtime shape mask has out-of-bounds cells for {shaped.Name}.");
}
var interior = catalog.Items.FirstOrDefault(item => item.InteriorShapeCells.Count > 0)
?? throw new InvalidOperationException("Runtime catalog has no typed interior shape masks.");
if (interior.InteriorShapeCells.Count != interior.InteriorOccupiedCells)
{
throw new InvalidOperationException(
$"Runtime interior shape mask count mismatch for {interior.Name}: cells={interior.InteriorShapeCells.Count}, occupied={interior.InteriorOccupiedCells}.");
}
var hardpointHost = catalog.Items.FirstOrDefault(item => item.Hardpoints.Count > 0)
?? throw new InvalidOperationException("Runtime catalog has no typed hardpoints.");
var hardpoint = hardpointHost.Hardpoints.First();
if (hardpoint.ShapeCells.Count != hardpoint.OccupiedCells)
{
throw new InvalidOperationException(
$"Runtime hardpoint shape count mismatch for {hardpointHost.Name}: cells={hardpoint.ShapeCells.Count}, occupied={hardpoint.OccupiedCells}.");
}
var behaviorKind = catalog.Items.SelectMany(item => item.BehaviorKinds).FirstOrDefault()
?? throw new InvalidOperationException("Runtime catalog has no behavior kind fingerprints.");
if (!catalog.FindItemsByBehavior(behaviorKind).Any())
@ -67,5 +84,6 @@ if (surface?.Schema != "gamecult.eve.surface.v1" ||
Console.WriteLine($"Aetheria Unity runtime catalog smoke passed: {statePath}");
Console.WriteLine($"Items/trade/equipment: {catalog.Items.Count}/{catalog.TradeItems.Count}/{catalog.EquipmentItems.Count}");
Console.WriteLine($"Shape mask sample: {shaped.Name} {shaped.ShapeWidth}x{shaped.ShapeHeight}/{shaped.ShapeCells.Count}");
Console.WriteLine($"Interior/hardpoint sample: {interior.Name} {interior.InteriorShapeCells.Count}; {hardpointHost.Name} {hardpoint.Type} {hardpoint.ShapeCells.Count}");
Console.WriteLine($"Behavior sample: {behaviorKind}");
Console.WriteLine($"Eve surface: {surface.Surface.Id}");

View file

@ -108,6 +108,11 @@ public sealed class AetheriaRuntimeCatalogItem
int shapeHeight,
int occupiedCells,
IReadOnlyList<AetheriaRuntimeShapeCell> shapeCells,
int interiorShapeWidth,
int interiorShapeHeight,
int interiorOccupiedCells,
IReadOnlyList<AetheriaRuntimeShapeCell> interiorShapeCells,
IReadOnlyList<AetheriaRuntimeHardpoint> hardpoints,
string hardpointType,
string hullType,
IReadOnlyList<string> behaviorKinds,
@ -131,6 +136,11 @@ public sealed class AetheriaRuntimeCatalogItem
ShapeHeight = shapeHeight;
OccupiedCells = occupiedCells;
ShapeCells = shapeCells;
InteriorShapeWidth = interiorShapeWidth;
InteriorShapeHeight = interiorShapeHeight;
InteriorOccupiedCells = interiorOccupiedCells;
InteriorShapeCells = interiorShapeCells;
Hardpoints = hardpoints;
HardpointType = hardpointType;
HullType = hullType;
BehaviorKinds = behaviorKinds;
@ -155,6 +165,11 @@ public sealed class AetheriaRuntimeCatalogItem
public int ShapeHeight { get; }
public int OccupiedCells { get; }
public IReadOnlyList<AetheriaRuntimeShapeCell> ShapeCells { get; }
public int InteriorShapeWidth { get; }
public int InteriorShapeHeight { get; }
public int InteriorOccupiedCells { get; }
public IReadOnlyList<AetheriaRuntimeShapeCell> InteriorShapeCells { get; }
public IReadOnlyList<AetheriaRuntimeHardpoint> Hardpoints { get; }
public string HardpointType { get; }
public string HullType { get; }
public IReadOnlyList<string> BehaviorKinds { get; }
@ -181,6 +196,11 @@ public sealed class AetheriaRuntimeCatalogItem
item.ShapeHeight,
item.OccupiedCells,
item.ShapeCells.Select(AetheriaRuntimeShapeCell.FromState).ToArray(),
item.InteriorShapeWidth,
item.InteriorShapeHeight,
item.InteriorOccupiedCells,
item.InteriorShapeCells.Select(AetheriaRuntimeShapeCell.FromState).ToArray(),
item.Hardpoints.Select(AetheriaRuntimeHardpoint.FromState).ToArray(),
item.HardpointType,
item.HullType,
item.BehaviorKinds,
@ -212,6 +232,68 @@ public sealed class AetheriaRuntimeShapeCell
}
}
public sealed class AetheriaRuntimeHardpoint
{
public AetheriaRuntimeHardpoint(
string type,
int positionX,
int positionY,
int shapeWidth,
int shapeHeight,
int occupiedCells,
IReadOnlyList<AetheriaRuntimeShapeCell> shapeCells,
string transform,
string rotation,
double armor)
{
Type = type;
PositionX = positionX;
PositionY = positionY;
ShapeWidth = shapeWidth;
ShapeHeight = shapeHeight;
OccupiedCells = occupiedCells;
ShapeCells = shapeCells;
Transform = transform;
Rotation = rotation;
Armor = armor;
}
public string Type { get; }
public int PositionX { get; }
public int PositionY { get; }
public int ShapeWidth { get; }
public int ShapeHeight { get; }
public int OccupiedCells { get; }
public IReadOnlyList<AetheriaRuntimeShapeCell> ShapeCells { get; }
public string Transform { get; }
public string Rotation { get; }
public double Armor { get; }
public static AetheriaRuntimeHardpoint FromState(AetheriaItemHardpoint hardpoint)
{
return new AetheriaRuntimeHardpoint(
hardpoint.Type,
hardpoint.PositionX,
hardpoint.PositionY,
hardpoint.ShapeWidth,
hardpoint.ShapeHeight,
hardpoint.OccupiedCells,
hardpoint.ShapeCells.Select(AetheriaRuntimeShapeCell.FromState).ToArray(),
hardpoint.Transform,
hardpoint.Rotation,
hardpoint.Armor);
}
}
public sealed class AetheriaRuntimeCorporation
{
public AetheriaRuntimeCorporation(

View file

@ -44,6 +44,9 @@ var pricedItems = items.Count(item => item.Price > 0);
var manufacturedItems = items.Count(item => !string.IsNullOrWhiteSpace(item.ManufacturerLegacyId));
var shapedItems = items.Count(item => item.ShapeWidth > 0 && item.ShapeHeight > 0 && item.OccupiedCells > 0);
var shapedMaskItems = items.Count(item => item.ShapeCells.Length > 0);
var interiorShapeItems = items.Count(item => item.InteriorShapeCells.Length > 0);
var hardpointHostItems = items.Count(item => item.Hardpoints.Length > 0);
var hardpointCount = items.Sum(item => item.Hardpoints.Length);
var behaviorItems = items.Count(item => item.BehaviorCount > 0 && item.BehaviorKinds.Length > 0);
var hardpointItems = items.Count(item => !string.IsNullOrWhiteSpace(item.HardpointType));
var hullItems = items.Count(item => !string.IsNullOrWhiteSpace(item.HullType));
@ -89,6 +92,57 @@ foreach (var item in items.Where(item => item.ShapeCells.Length > 0))
}
}
foreach (var item in items.Where(item => item.InteriorShapeCells.Length > 0))
{
if (item.InteriorShapeCells.Length != item.InteriorOccupiedCells)
{
throw new InvalidOperationException(
$"Typed item interior shape mask count mismatch for {item.Name}: cells={item.InteriorShapeCells.Length}, occupied={item.InteriorOccupiedCells}.");
}
if (item.InteriorShapeCells.Any(cell =>
cell.X < 0 || cell.Y < 0 || cell.X >= item.InteriorShapeWidth || cell.Y >= item.InteriorShapeHeight))
{
throw new InvalidOperationException($"Typed item interior shape mask has out-of-bounds cells for {item.Name}.");
}
}
if (interiorShapeItems == 0)
{
throw new InvalidOperationException("Typed item definitions did not import any interior shape masks.");
}
if (hardpointHostItems == 0 || hardpointCount == 0)
{
throw new InvalidOperationException("Typed item definitions did not import any hull hardpoints.");
}
foreach (var item in items.Where(item => item.Hardpoints.Length > 0))
{
foreach (var hardpoint in item.Hardpoints)
{
if (string.IsNullOrWhiteSpace(hardpoint.Type))
{
throw new InvalidOperationException($"Typed item hardpoint has no type for {item.Name}.");
}
if (hardpoint.ShapeCells.Length != hardpoint.OccupiedCells)
{
throw new InvalidOperationException(
$"Typed item hardpoint shape count mismatch for {item.Name}: cells={hardpoint.ShapeCells.Length}, occupied={hardpoint.OccupiedCells}.");
}
if (hardpoint.ShapeCells.Any(cell =>
cell.X < 0 || cell.Y < 0 || cell.X >= hardpoint.ShapeWidth || cell.Y >= hardpoint.ShapeHeight))
{
throw new InvalidOperationException($"Typed item hardpoint shape has out-of-bounds cells for {item.Name}.");
}
// Legacy content includes at least one overhanging hardpoint. Preserve the
// payload faithfully here; content repair belongs to a separate pass.
}
}
if (behaviorItems == 0)
{
throw new InvalidOperationException("Typed item definitions did not import any behavior fingerprints.");
@ -201,6 +255,7 @@ Console.WriteLine($"Catalog fingerprint: {quarantine.CatalogFingerprint}");
Console.WriteLine($"Item definitions: {items.Length}");
Console.WriteLine($"Priced/manufactured/shaped items: {pricedItems}/{manufacturedItems}/{shapedItems}");
Console.WriteLine($"Shape masks: {shapedMaskItems}");
Console.WriteLine($"Interior masks/hardpoint hosts/hardpoints: {interiorShapeItems}/{hardpointHostItems}/{hardpointCount}");
Console.WriteLine($"Behavior/hardpoint/hull/weapon items: {behaviorItems}/{hardpointItems}/{hullItems}/{weaponItems}");
Console.WriteLine($"Typed catalog trade items: {tradeItems.Length}");
Console.WriteLine($"Eve catalog surface: {surface.Surface.Id} ({surface.Surface.Root.Children.Length} root children)");

View file

@ -90,6 +90,21 @@ public sealed class AetheriaItemDefinition
[Key(25)]
public AetheriaShapeCell[] ShapeCells { get; set; } = [];
[Key(26)]
public int InteriorShapeWidth { get; set; }
[Key(27)]
public int InteriorShapeHeight { get; set; }
[Key(28)]
public int InteriorOccupiedCells { get; set; }
[Key(29)]
public AetheriaShapeCell[] InteriorShapeCells { get; set; } = [];
[Key(30)]
public AetheriaItemHardpoint[] Hardpoints { get; set; } = [];
}
[MessagePackObject]
@ -101,3 +116,37 @@ public sealed class AetheriaShapeCell
[Key(1)]
public int Y { get; set; }
}
[MessagePackObject]
public sealed class AetheriaItemHardpoint
{
[Key(0)]
public string Type { get; set; } = "";
[Key(1)]
public int PositionX { get; set; }
[Key(2)]
public int PositionY { get; set; }
[Key(3)]
public int ShapeWidth { get; set; }
[Key(4)]
public int ShapeHeight { get; set; }
[Key(5)]
public int OccupiedCells { get; set; }
[Key(6)]
public AetheriaShapeCell[] ShapeCells { get; set; } = [];
[Key(7)]
public string Transform { get; set; } = "";
[Key(8)]
public string Rotation { get; set; } = "";
[Key(9)]
public double Armor { get; set; }
}

View file

@ -47,7 +47,8 @@ item/faction/name-file documents without compiling Unity's legacy domain model
into `Aetheria.State`. The current checked-in catalog maps to 115 item
definitions, 12 factions, and 12 name files. Typed item definitions include
legacy manufacturer IDs, price, shape dimensions, occupied cell counts, full
shape-cell masks, and
shape-cell masks, interior shape masks for hull/cargo equipment, hull hardpoint
definitions, and
stable equipment facets: hardpoint type, hull type, behavior kind fingerprints,
stack size, durability, and weapon range/caliber/type/fire/modifier
classifications.
@ -75,9 +76,11 @@ Unity UI Toolkit lowering package exists.
It opens `aetheria-world.cc`, emits immutable catalog read models for trade,
equipment, behavior, hardpoint, manufacturer, corporation, and name-file
queries, exposes typed item shape masks for layout and fitting consumers, and
can read the published Eve catalog surface. It does not deserialize legacy
`DatabaseEntry` objects and does not write state. Unity can use this as the
first package boundary once CultLib/Eve runtime packaging is available.
exposes typed interior masks and hardpoints for equipment/cargo layout
consumers, and can read the published Eve catalog surface. It does not
deserialize legacy `DatabaseEntry` objects and does not write state. Unity can
use this as the first package boundary once CultLib/Eve runtime packaging is
available.
`Aetheria.State.Verify` opens a materialized state file and checks that the
typed migration ledger matches the actual item, corporation, and name-file
@ -85,7 +88,9 @@ records in the `.cc` store. It also verifies the canonical legacy-ID lookup API
for one migrated record of each catalog kind and checks that expanded item and
corporation catalog facts survived materialization. The verifier also exercises
the typed catalog snapshot query surface, shape-mask invariants, and the
published Eve catalog surface.
published Eve catalog surface. Legacy content currently includes at least one
overhanging hardpoint; the verifier preserves the payload and checks hardpoint
local masks rather than silently converting content repair into migration.
Use it after import when `GameData/aetheria-world.cc` changes.
`Aetheria.State.Unity.Smoke` opens the materialized state through the runtime

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show more