feat(chargen): Campaign CC slice CC6a — index→ObjDesc factory + preview renderer foundation
Delivers the CC6a foundation half of the chargen 3D preview: the missing index->ObjDesc appearance factory the campaign plan's acdream-seams section named, plus a static-pose offscreen renderer following PrivateEntityViewportRenderer's proven paperdoll/appraisal architecture. Page mount, spin/color-wheel controls, and rotate/zoom behavior stay out of scope per the CC4-parallel worktree contract (CC6b, after CC4 merges). Core (src/AcDream.Core/CharGen/, pure, no Chorizite on public surfaces): ChargenAppearanceFactory.TryCompose ports gmCG3DView::Update @0x004EE9D0's ObjDesc rebuild in its exact decompiled order - base body, hair style, clothing in retail's own Headgear/Trousers/Shirt/Footwear order (not the UI tab order or the wire's field order, both of which differ), eyes (bald-aware), nose, mouth, then the unconditional skin subpalette, hair color, eye color. ChargenPalSetMath ports PalSet::GetPaletteID's shade-to-index formula, cross-checked three ways (decomp control flow, ACE's PaletteSet.GetPaletteID "Taken from acclient.c" citation, ACViewer's identical slider math). ChargenPalSet/ChargenClothingTable are pure projections behind IChargenPalSetSource/IChargenClothingTableSource so the factory itself never touches a dat. Content (src/AcDream.Content/CharGen/): ChargenAppearanceCatalog is the cached dat-backed implementation of those two source interfaces, mirroring ChargenTableReader's no-leak discipline. App (src/AcDream.App/Rendering/): ChargenPreviewRenderer is a third facade over PrivateEntityViewportRenderer beside PaperdollViewportRenderer and CreatureAppraisalViewportRenderer - no existing rendering file touched. ChargenPreviewCamera carries the four retail-verbatim per-heritage eye profiles from gmCGAppearancePage::Update @0x0047E8F0 (cross-checked against ZoomIn/ZoomOut's identical literals) plus the recovered rotation (3.0 s/revolution) and zoom-tween (0.6 s, reconstructed from the decompiler's garbled float literals - the plan's own "measure if it matters" note is resolved, not garbled beyond recovery). Rotation applies to the character model, not the camera, per gmCGAppearancePage::DoRotation. ChargenPreviewEntityBuilder resolves Setup/GfxObj/Surface/Animation itself (there is no live entity yet), reusing DatLiveEntityProjectionMaterializer's surface-override algorithm and RetailPaperdollPoseApplicator's held-pose technique, generalized to chargen's per-heritage rest-pose DID. Two register rows filed: TS-83 (the plan-named CC6a static-pose-vs-retail- idle-loop staging, CC6b to retire) and TS-82 (measured, not assumed - the un-ported clothing Setup-substitution fallback chain costs nothing for the 9 standard heritages with clothing UI, but Undead's default gear choices genuinely lack ClothingBaseEffects coverage for Undead's own body Setup). Tests: ChargenPalSetMathTests, ChargenAppearanceFactoryTests (hand-built fixtures), ChargenAppearanceCatalogInstalledDatTests (installed-DAT sweep, all 26 heritage/gender combinations, zero missing PalSet/ClothingTable ids), ChargenPreviewCameraTests, ChargenPreviewEntityBuilderTests (installed-DAT-gated, proves a real 34-part Aluvian mesh resolves). Core.Tests 4767/1 skip, Content.Tests 146/0, App.Tests 5121/6 skips - all pre-existing skips, zero failures, full solution Release build green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
3a6b7e3115
commit
55bfd9ca82
16 changed files with 2131 additions and 2 deletions
110
tests/AcDream.App.Tests/Rendering/ChargenPreviewCameraTests.cs
Normal file
110
tests/AcDream.App.Tests/Rendering/ChargenPreviewCameraTests.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.Rendering;
|
||||
using AcDream.Core.CharGen;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.App.Tests.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Pins <see cref="ChargenPreviewCamera"/>'s retail-verbatim per-heritage
|
||||
/// eye positions (<c>gmCGAppearancePage::Update @ 0x0047E8F0</c>,
|
||||
/// cross-checked against the identical literals in <c>ZoomIn</c>/<c>ZoomOut
|
||||
/// @ 0x0047CF00</c>/<c>0x0047D050</c>) and the zero-yaw/zero-pitch look
|
||||
/// convention DollCameraTests already established for the shared private
|
||||
/// viewport.
|
||||
/// </summary>
|
||||
public class ChargenPreviewCameraTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData((uint)ChargenHeritageGroup.Aluvian, 0f, -0.550000012f, 1.64999998f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.Gharundim, 0f, -0.550000012f, 1.64999998f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.Gearknight, 0f, -0.550000012f, 1.64999998f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.Undead, 0f, -0.550000012f, 1.64999998f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.Tumerok, 0f, -0.850000024f, 1.64999998f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.Olthoi, 0f, -1.85000002f, 1.85000002f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.OlthoiAcid, 0f, -3.04999995f, 2.75f)]
|
||||
public void ResolveDefaultEye_MatchesRetailPerHeritageLiterals(uint heritageId, float x, float y, float z)
|
||||
{
|
||||
Vector3 eye = ChargenPreviewCamera.ResolveDefaultEye(heritageId);
|
||||
Assert.Equal(x, eye.X, 4);
|
||||
Assert.Equal(y, eye.Y, 4);
|
||||
Assert.Equal(z, eye.Z, 4);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData((uint)ChargenHeritageGroup.Aluvian, 0f, -2.5f, 0.95f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.Tumerok, 0f, -2.5f, 0.95f)] // ZoomOut has NO Tumerok special case, unlike the zoomed-in default.
|
||||
[InlineData((uint)ChargenHeritageGroup.Olthoi, 0f, -3.79999995f, 1.14999998f)]
|
||||
[InlineData((uint)ChargenHeritageGroup.OlthoiAcid, 0f, -5.69999981f, 1.64999998f)]
|
||||
public void ResolveZoomedOutEye_MatchesRetailPerHeritageLiterals(uint heritageId, float x, float y, float z)
|
||||
{
|
||||
Vector3 eye = ChargenPreviewCamera.ResolveZoomedOutEye(heritageId);
|
||||
Assert.Equal(x, eye.X, 4);
|
||||
Assert.Equal(y, eye.Y, 4);
|
||||
Assert.Equal(z, eye.Z, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_DefaultsToStandardHeritageEye_ForUnknownHeritageId()
|
||||
{
|
||||
var cam = new ChargenPreviewCamera(heritageId: 0u);
|
||||
Assert.Equal(ChargenPreviewCamera.ResolveDefaultEye(0u), cam.Eye);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetHeritage_UpdatesEyeToTheNewHeritagesProfile()
|
||||
{
|
||||
var cam = new ChargenPreviewCamera((uint)ChargenHeritageGroup.Aluvian);
|
||||
cam.SetHeritage((uint)ChargenHeritageGroup.Olthoi);
|
||||
Assert.Equal(ChargenPreviewCamera.ResolveDefaultEye((uint)ChargenHeritageGroup.Olthoi), cam.Eye);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void View_LooksStraightDownPlusY_ZeroYawZeroPitch()
|
||||
{
|
||||
// Same identity-direction convention DollCameraTests pins for the paperdoll:
|
||||
// retail SetCameraDirection(0,0,0) resets the view frame to IDENTITY.
|
||||
var cam = new ChargenPreviewCamera((uint)ChargenHeritageGroup.Aluvian) { Aspect = 1f };
|
||||
var forward = -new Vector3(cam.View.M13, cam.View.M23, cam.View.M33);
|
||||
Assert.Equal(0f, forward.X, 4);
|
||||
Assert.Equal(1f, forward.Y, 4);
|
||||
Assert.Equal(0f, forward.Z, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Eye_RoundTripsThroughViewMatrixInversion()
|
||||
{
|
||||
var cam = new ChargenPreviewCamera((uint)ChargenHeritageGroup.Olthoi) { Aspect = 1f };
|
||||
Assert.True(Matrix4x4.Invert(cam.View, out var inv));
|
||||
Vector3 eye = inv.Translation;
|
||||
Assert.Equal(cam.Eye.X, eye.X, 3);
|
||||
Assert.Equal(cam.Eye.Y, eye.Y, 3);
|
||||
Assert.Equal(cam.Eye.Z, eye.Z, 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Projection_IsFiniteAndUsesAspect()
|
||||
{
|
||||
var cam = new ChargenPreviewCamera { Aspect = 1.5f };
|
||||
Assert.True(float.IsFinite(cam.Projection.M11));
|
||||
Assert.NotEqual(0f, cam.Projection.M34);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RotationSecondsPerRevolution_IsExactlyThreeSeconds()
|
||||
{
|
||||
// Raw double bits low32=0x00000000, high32=0x40080000 — no
|
||||
// reconstruction needed, the decompiler shows this one cleanly.
|
||||
Assert.Equal(3.0f, ChargenPreviewCamera.RotationSecondsPerRevolution);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ZoomTweenDurationSeconds_IsExactlyZeroPointSix()
|
||||
{
|
||||
// Recovered by reinterpreting the decompiler's garbled float literal
|
||||
// as the raw low-32-bit store and pairing it with the (clean) high
|
||||
// dword; cross-confirmed via the -0.1 sentinel in ZoomIn/ZoomOut
|
||||
// reconstructing to the well-known IEEE-754 bit pattern for -0.1.
|
||||
Assert.Equal(0.6f, ChargenPreviewCamera.ZoomTweenDurationSeconds);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using AcDream.App.Rendering;
|
||||
using AcDream.Content;
|
||||
using AcDream.Content.CharGen;
|
||||
using AcDream.Content.Vfx;
|
||||
using AcDream.Core.CharGen;
|
||||
using DatReaderWriter;
|
||||
using DatReaderWriter.Options;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace AcDream.App.Tests.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Installed-DAT gate for <see cref="ChargenPreviewEntityBuilder"/> —
|
||||
/// mirrors <see cref="CornerFloodReplayTests"/>'s env-gated skip pattern
|
||||
/// (no unit-testable pure surface exists here the way
|
||||
/// <see cref="DollEntityBuilder"/> has one, because THIS builder's whole job
|
||||
/// is resolving Setup/GfxObj/Surface/Animation dat data that
|
||||
/// <see cref="DollEntityBuilder"/> receives pre-resolved).
|
||||
/// </summary>
|
||||
public sealed class ChargenPreviewEntityBuilderTests
|
||||
{
|
||||
private readonly ITestOutputHelper _out;
|
||||
public ChargenPreviewEntityBuilderTests(ITestOutputHelper output) => _out = output;
|
||||
|
||||
[Fact]
|
||||
public void TryBuild_AluvianMaleDefaultSelection_ProducesANonEmptyStaticPoseEntity()
|
||||
{
|
||||
string? datDir = CornerFloodReplayTests.ResolveDatDir();
|
||||
if (datDir is null) { _out.WriteLine("SKIP: dats unavailable"); return; }
|
||||
|
||||
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
||||
using var adapter = new DatCollectionAdapter(dats);
|
||||
|
||||
ChargenOptions options = ChargenTableReader.Load(adapter);
|
||||
Assert.True(options.TryGetHeritage(1u, out ChargenHeritageOptions? aluvian)); // Aluvian.
|
||||
Assert.True(aluvian!.GendersByKey.TryGetValue(1, out ChargenGenderOptions? male));
|
||||
|
||||
var catalog = new ChargenAppearanceCatalog(adapter);
|
||||
ChargenAppearanceSelection selection = ChargenAppearanceSelection.Default with
|
||||
{
|
||||
HairStyle = male!.HairStyles.Count > 0 ? 0u : ChargenAppearanceSelection.Unset,
|
||||
SkinShade = 0.5,
|
||||
};
|
||||
|
||||
bool composed = ChargenAppearanceFactory.TryCompose(
|
||||
options, 1u, 1, selection, catalog, catalog, out ChargenAppearanceResult appearance);
|
||||
Assert.True(composed);
|
||||
Assert.Empty(appearance.MissingPalSetIds);
|
||||
Assert.Empty(appearance.MissingClothingTableIds);
|
||||
|
||||
var animations = new RetailAnimationLoader(adapter);
|
||||
var entity = ChargenPreviewEntityBuilder.TryBuild(
|
||||
adapter, animations, appearance, heritageId: 1u, Quaternion.Identity);
|
||||
|
||||
Assert.NotNull(entity);
|
||||
Assert.NotEmpty(entity!.MeshRefs);
|
||||
Assert.Equal(appearance.SetupId, entity.SourceGfxObjOrSetupId);
|
||||
Assert.Equal(ChargenPreviewEntityBuilder.PreviewServerGuid, entity.ServerGuid);
|
||||
Assert.Equal(ChargenPreviewEntityBuilder.PreviewRenderId, entity.Id);
|
||||
Assert.NotNull(entity.PaletteOverride);
|
||||
Assert.Equal(appearance.BasePaletteId, entity.PaletteOverride!.BasePaletteId);
|
||||
|
||||
_out.WriteLine($"setup=0x{appearance.SetupId:X8} meshRefs={entity.MeshRefs.Count} subPalettes={entity.PaletteOverride.SubPalettes.Count}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryBuild_UnknownSetupId_ReturnsNull()
|
||||
{
|
||||
string? datDir = CornerFloodReplayTests.ResolveDatDir();
|
||||
if (datDir is null) { _out.WriteLine("SKIP: dats unavailable"); return; }
|
||||
|
||||
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
||||
using var adapter = new DatCollectionAdapter(dats);
|
||||
var animations = new RetailAnimationLoader(adapter);
|
||||
|
||||
var bogusAppearance = new ChargenAppearanceResult(
|
||||
SetupId: 0x0200_FFFFu, // Not a real installed Setup id.
|
||||
BasePaletteId: 0u,
|
||||
ObjDesc: ChargenObjDesc.Empty,
|
||||
MissingPalSetIds: [],
|
||||
MissingClothingTableIds: [],
|
||||
ClothingTablesMissingBaseEffectForSetup: []);
|
||||
|
||||
var entity = ChargenPreviewEntityBuilder.TryBuild(
|
||||
adapter, animations, bogusAppearance, heritageId: 1u, Quaternion.Identity);
|
||||
|
||||
Assert.Null(entity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryBuild_OlthoiHeritage_ResolvesADifferentRestPoseDidThanStandardHeritages()
|
||||
{
|
||||
string? datDir = CornerFloodReplayTests.ResolveDatDir();
|
||||
if (datDir is null) { _out.WriteLine("SKIP: dats unavailable"); return; }
|
||||
|
||||
using var dats = new DatCollection(datDir, DatAccessType.Read);
|
||||
using var adapter = new DatCollectionAdapter(dats);
|
||||
|
||||
ChargenOptions options = ChargenTableReader.Load(adapter);
|
||||
Assert.True(options.TryGetHeritage(12u, out ChargenHeritageOptions? olthoi)); // Olthoi.
|
||||
Assert.True(olthoi!.GendersByKey.TryGetValue(1, out ChargenGenderOptions? male)
|
||||
|| olthoi.GendersByKey.TryGetValue(2, out male));
|
||||
Assert.NotNull(male);
|
||||
int genderKey = olthoi.GendersByKey.First(kv => ReferenceEquals(kv.Value, male)).Key;
|
||||
|
||||
var catalog = new ChargenAppearanceCatalog(adapter);
|
||||
var animations = new RetailAnimationLoader(adapter);
|
||||
|
||||
bool composed = ChargenAppearanceFactory.TryCompose(
|
||||
options, 12u, genderKey, ChargenAppearanceSelection.Default with { SkinShade = 0.5 },
|
||||
catalog, catalog, out ChargenAppearanceResult appearance);
|
||||
Assert.True(composed);
|
||||
|
||||
var entity = ChargenPreviewEntityBuilder.TryBuild(
|
||||
adapter, animations, appearance, heritageId: 12u, Quaternion.Identity);
|
||||
|
||||
// Just proves the Olthoi branch doesn't throw / silently fall through to
|
||||
// "no mesh" — the exact pose DID differs internally (0x10000011 vs
|
||||
// 0x10000005) but both should still resolve a drawable mesh from Olthoi's
|
||||
// own Setup.
|
||||
Assert.NotNull(entity);
|
||||
Assert.NotEmpty(entity!.MeshRefs);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue