feat(O-T7): drop WB project references; complete extraction

End of Phase O extraction. Final cleanup:

- Dropped <ProjectReference> entries to WorldBuilder.Shared and
  Chorizite.OpenGLSDLBackend from both AcDream.App.csproj and
  AcDream.Core.csproj.
- Added Chorizite.Core NuGet PackageReference to AcDream.Core.csproj
  (needed by Core.Rendering.Wb.TextureHelpers for TextureFormat enum;
  previously transitive through the WB project ref).
- Added BCnEncoder.Net.ImageSharp (1.1.2) + SixLabors.ImageSharp (3.1.12)
  as direct PackageReferences to AcDream.App.csproj — previously transitive
  via Chorizite.OpenGLSDLBackend project; used directly by ObjectMeshManager.

Item A (BaseObjectRenderManager static fields):
- Inlined CurrentAtlas/CurrentVAO/CurrentIBO into a new RenderStateCache.cs
  static class (AcDream.App.Rendering.Wb namespace) — the 4 consumers
  (ManagedGLIndexBuffer, ManagedGLTexture, ManagedGLTextureArray, ParticleBatcher)
  all reference RenderStateCache.* instead of BaseObjectRenderManager.*.
- Dropped using Chorizite.OpenGLSDLBackend.Lib from all 4 consumers and from
  WbDrawDispatcher (which had it only as a dead import).

Item B (ActiveParticleEmitter.ObjectLandblock):
- ObjectLandblock? erased to object?; WorldBuilder.Shared.Models.ObjectId? erased
  to ulong? — both fields are stored but never read by any consumer in our codebase.
- Dropped both WB using directives from ActiveParticleEmitter.cs.

Item C (IDatReaderWriter / IDatDatabase):
- Verbatim copy of both interfaces into IDatReaderWriter.cs in
  AcDream.App.Rendering.Wb namespace — DatCollectionAdapter and ObjectMeshManager
  already live in that namespace, so no using changes needed.
- Dropped using WorldBuilder.Shared.Services from DatCollectionAdapter.cs and
  ObjectMeshManager.cs.

Additional extractions required by the reference drop:
- GeometryUtils.cs: verbatim copy of WorldBuilder.Shared.Lib.GeometryUtils
  (float-precision overloads only; Vector3d double-precision overloads omitted —
  ObjectMeshManager uses only the float versions).
- Dropped using WorldBuilder.Shared.Lib from ObjectMeshManager.cs.

WbMeshAdapter.cs cleanup (spec O-D12):
- Deleted _wbDats (DefaultDatReaderWriter) field + ctor init + Dispose call.
- Deleted the [indoor-upload] NULL_RESULT diagnostic block (lines ~205-262) —
  its Phase 2 cell-resolution investigation is complete; its _wbDats.ResolveId
  dependency goes with this commit.
- Deleted _pendingEnvCellRequests field + isPendingEnvCell tracking in Tick().
- Simplified Tick() to a clean drain loop.

Deleted SplitFormulaDivergenceTest.cs — one-time N.5b data-collection sweep;
job done.

Verified acceptance criteria:
- Zero <ProjectReference> to WorldBuilder.* / Chorizite.OpenGLSDLBackend.* in any csproj.
- Zero 'using WorldBuilder.*' / 'using Chorizite.OpenGLSDLBackend.*' in src/.
- DefaultDatReaderWriter referenced in zero places in src/ (comments only).

Build green (0 warnings, 0 errors).
Tests: 1154 total (-1 from deleted SplitFormulaDivergenceTest), 1146 pass,
8 pre-existing failures (unchanged from baseline — physics/input tests
unrelated to this change).

Spec: docs/superpowers/specs/2026-05-21-phase-o-dat-path-unification-design.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-05-21 17:17:33 +02:00
parent a9ccc5acf5
commit dc722e70bd
15 changed files with 312 additions and 328 deletions

View file

@ -0,0 +1,114 @@
using DatReaderWriter;
using DatReaderWriter.Enums;
using DatReaderWriter.Lib.IO;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
// Phase O-T7: verbatim copy of WorldBuilder.Shared.Services.IDatReaderWriter +
// IDatDatabase into the AcDream.App.Rendering.Wb namespace so the
// WorldBuilder.Shared project reference can be dropped.
// The only consumer of IDatReaderWriter in acdream is DatCollectionAdapter +
// ObjectMeshManager, both already in this namespace.
namespace AcDream.App.Rendering.Wb;
/// <summary>
/// Interface for the dat reader/writer
/// </summary>
public interface IDatReaderWriter : IDisposable {
/// <summary>
/// Gets the source directory of the DAT files.
/// </summary>
string SourceDirectory { get; }
/// <summary>
/// Tries to get the raw bytes of a file from a specific region database.
/// </summary>
bool TryGetFileBytes(uint regionId, uint fileId, ref byte[] bytes, out int bytesRead);
/// <summary>
/// The portal database
/// </summary>
IDatDatabase Portal { get; }
/// <summary>
/// The cell region databases. Each key is a cell region ID
/// </summary>
ReadOnlyDictionary<uint, IDatDatabase> CellRegions { get; }
/// <summary>
/// The high res database
/// </summary>
IDatDatabase HighRes { get; }
/// <summary>
/// The language database
/// </summary>
IDatDatabase Language { get; }
/// <summary>
/// A mapping of region ids to region dat file entry ids. key: region id, value: region dat file entry
/// </summary>
ReadOnlyDictionary<uint, uint> RegionFileMap { get; }
/// <summary>
/// Gets the current portal iteration.
/// </summary>
int PortalIteration { get; }
/// <summary>
/// Gets the current cell iteration (from the first cell region).
/// </summary>
int CellIteration { get; }
/// <summary>
/// Gets the current high res iteration.
/// </summary>
int HighResIteration { get; }
/// <summary>
/// Gets the current language iteration.
/// </summary>
int LanguageIteration { get; }
/// <summary>Attempts to save a database object to the appropriate DAT.</summary>
bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj;
/// <summary>Attempts to save a database object to the appropriate DAT for a specific region.</summary>
bool TrySave<T>(uint regionId, T obj, int iteration = 0) where T : IDBObj;
/// <summary>
/// Resolution of a data ID to a database and type
/// </summary>
public record IdResolution(IDatDatabase Database, DBObjType Type);
/// <summary>
/// Resolves a data ID to all possible databases and types.
/// </summary>
public IEnumerable<IdResolution> ResolveId(uint id);
}
/// <summary>
/// Interface for a dat database, providing methods to retrieve files and objects.
/// </summary>
public interface IDatDatabase : IDisposable {
DatDatabase Db { get; }
/// <summary>Retrieves the current iteration of the database.</summary>
int Iteration { get; }
/// <summary>Retrieves all file IDs of a specific type.</summary>
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj;
/// <summary>Attempts to retrieve a database object by its file ID.</summary>
public bool TryGet<T>(uint fileId, [MaybeNullWhen(false)] out T value) where T : IDBObj;
/// <summary>Attempts to retrieve the raw bytes of a file by its ID.</summary>
bool TryGetFileBytes(uint fileId, [MaybeNullWhen(false)] out byte[] value);
/// <summary>Attempts to retrieve the raw bytes of a file by its ID into a provided buffer.</summary>
bool TryGetFileBytes(uint fileId, ref byte[] bytes, out int bytesRead);
/// <summary>Attempts to save a database object.</summary>
bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj;
}