On a Linux/Mono shard the Asset Bridge's item and land art failed: the vendored Art.LoadStatic/LoadLand build a 16bpp Bitmap (Settings.PixelFormat) and libgdiplus 6.1 cannot create one, so every static and land picture threw [GDI+ NotImplemented] before a pixel was read. PR 1 moved the body catalogue off System.Drawing; this finishes the migration for the art plane, so Windows and Linux now share one managed path and the whole Asset Bridge needs no libgdiplus. - BridgeArtMul: a hand-written art.mul static + land decoder to ARGB1555, mirroring Art.LoadStatic's run loop and LoadLand's 44x44 diamond, with the record/canvas bounds the vendored writers lack (no System.Drawing, no Bitmap). - BridgeArt: Render now decodes through BridgeArtMul and hues through BridgeHue (over hues.mul + the tiledata PartialHue flag) into BridgePng, via a shared TryArtPixels helper the parity harness drives. The GDI+ Bitmap/ApplyTo/dispose path, the imaging gate, and the Files.CacheData re-check in TryHue are gone, because a key now decodes its own fresh buffer that nothing else aliases. - BridgeAssets: retire BitmapToPng (its last caller) and the imaging probe/field machinery; assets.sources no longer carries an imaging field. No decode goes through System.Drawing any more, so the NO_IMAGING refusal is retired with the GDI+ it guarded. Files.CacheData stays off, now only so the parity oracle's vendored decode hands back fresh bitmaps. - BridgeArtParity: a [BridgeArtParity] GM command / BRIDGE_ART_PARITY=1 boot run that compares the managed decode+hue against the vendored one pixel for pixel. Overlay-only; no wire change beyond the retired imaging field, no PROTOCOL_VERSION bump. The website tolerates the field's absence (its NO_IMAGING branch is guarded by `sources.imaging &&`); the dead NO_IMAGING UI/model in module-uo and the installer doctor libgdiplus row are removed in a tracked follow-up. Verified on this machine. Windows (vendored GDI+ oracle available): the parity harness compared every served picture and every one is pixel-identical to the vendored decode — 43,433/43,433 (39,189 statics + 4,244 land) with no hue, then 39,189/39,189 again hued in each item's PartialHue mode, 0 mismatched. On WSL2 Ubuntu 24.04 / Mono 6.8 / libgdiplus 6.1 (the live-host match) the vendored oracle threw NotImplemented and the managed path produced all 43,433 + 39,189. dotnet build 0/0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014HJEmcaKvWQ8LsnXHKha5y
226 lines
7.9 KiB
C#
226 lines
7.9 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
using Server;
|
|
using Server.Commands;
|
|
|
|
using Ultima;
|
|
|
|
namespace Server.Custom.Bridge
|
|
{
|
|
/// <summary>
|
|
/// **The #39 merge gate**: the GM command <c>[BridgeAnimParity]</c>, which proves the new
|
|
/// GDI+-free legacy decode (<see cref="BridgeMul"/> + <see cref="BridgeHue"/>, driven by
|
|
/// <see cref="BridgeCatalog.RunAnimParity"/>) is pixel-identical to the vendored
|
|
/// <c>Ultima.Frame</c> path it replaces.
|
|
///
|
|
/// This is the one file left that still touches <c>System.Drawing</c>, and it does so only
|
|
/// to be the <b>oracle</b>: on Windows it runs the vendored <c>GetAnimation</c>, reads the
|
|
/// resulting 16bpp bitmap back to ARGB1555, and hands those pixels to the harness to compare
|
|
/// against the managed decode. On a real Linux/Mono shard the vendored bitmap ctor throws
|
|
/// <c>NotImplemented</c> (the very bug #39 fixes), the oracle reports itself unavailable, and
|
|
/// the harness falls back to confirming the managed path still renders — so the same command
|
|
/// is meaningful on both platforms. It ships in the overlay because it needs both decoders in
|
|
/// one process; it changes nothing the Bridge serves.
|
|
/// </summary>
|
|
public static class BridgeAnimParity
|
|
{
|
|
public static void Initialize()
|
|
{
|
|
CommandSystem.Register("BridgeAnimParity", AccessLevel.Administrator, OnCommand);
|
|
|
|
// Headless gate run (servuo-plugins #39): with BRIDGE_ANIM_PARITY=1 in the environment,
|
|
// run the parity once the world is up and write parity-anim.txt, no client needed. For
|
|
// verification/CI only — it is never set on a production shard.
|
|
if (Environment.GetEnvironmentVariable("BRIDGE_ANIM_PARITY") == "1")
|
|
EventSink.ServerStarted += OnServerStartedParity;
|
|
}
|
|
|
|
private static void OnServerStartedParity()
|
|
{
|
|
Console.WriteLine("[Bridge] anim parity: BRIDGE_ANIM_PARITY=1 — running at boot");
|
|
Run(null);
|
|
}
|
|
|
|
private static void OnCommand(CommandEventArgs e)
|
|
{
|
|
Run(e.Mobile);
|
|
}
|
|
|
|
private static void Run(Mobile from)
|
|
{
|
|
if (from != null)
|
|
from.SendMessage(
|
|
"Running legacy anim GDI+ parity across the catalogue — the shard will pause for a bit.");
|
|
|
|
Console.WriteLine("[Bridge] anim parity: starting");
|
|
|
|
string report;
|
|
|
|
try
|
|
{
|
|
report = BridgeCatalog.RunAnimParity(Oracle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
report = "[Bridge] anim parity crashed: " + ex;
|
|
}
|
|
|
|
Console.WriteLine(report);
|
|
|
|
string path = null;
|
|
|
|
try
|
|
{
|
|
path = Path.Combine(Core.BaseDirectory, "parity-anim.txt");
|
|
File.WriteAllText(path, report);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("[Bridge] anim parity: cannot write file: " + ex.Message);
|
|
path = null;
|
|
}
|
|
|
|
if (from != null)
|
|
{
|
|
from.SendMessage("Anim parity done."
|
|
+ (path != null ? " Report: " + path : " (see the console)"));
|
|
|
|
// The summary head, not the full detail list — the console and the file hold it all.
|
|
string[] lines = report.Split('\n');
|
|
|
|
for (int i = 0; i < lines.Length && i < 6; i++)
|
|
{
|
|
string line = lines[i].TrimEnd();
|
|
|
|
if (line.Length > 0)
|
|
from.SendMessage(line);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The vendored decode for one key, read back to ARGB1555. False with
|
|
/// <paramref name="available"/> still true means "no art here"; false with it set false
|
|
/// means the vendored path cannot run at all on this host (libgdiplus
|
|
/// <c>NotImplemented</c>), which is exactly the #39 fault and tells the harness to stop
|
|
/// asking the oracle.
|
|
/// </summary>
|
|
private static bool Oracle(int body, int action, int direction,
|
|
out ushort[] pixels, out int width, out int height, out bool available)
|
|
{
|
|
pixels = null;
|
|
width = 0;
|
|
height = 0;
|
|
available = true;
|
|
|
|
Bitmap bmp = null;
|
|
|
|
try
|
|
{
|
|
int hue = 0;
|
|
|
|
// Exactly the call the old BridgeCatalog.Decode made: preserveHue false, first
|
|
// frame. The vendored path applies the body.def hue to the bitmap internally, so
|
|
// these pixels are already hued — matching what BridgeHue does on the managed side.
|
|
Frame[] frames = Animations.GetAnimation(body, action, direction, ref hue, false, true);
|
|
|
|
if (frames == null || frames.Length == 0 || frames[0] == null)
|
|
return false;
|
|
|
|
bmp = frames[0].Bitmap;
|
|
|
|
if (bmp == null || bmp.Width <= 0 || bmp.Height <= 0)
|
|
{
|
|
bmp = null; // Frame.Empty / a null bitmap is not ours to dispose.
|
|
return false;
|
|
}
|
|
|
|
width = bmp.Width;
|
|
height = bmp.Height;
|
|
pixels = ToArgb1555(bmp);
|
|
|
|
return pixels != null;
|
|
}
|
|
catch (NotImplementedException)
|
|
{
|
|
// libgdiplus 6.1 cannot create/lock the 16bpp bitmap — the #39 condition itself.
|
|
available = false;
|
|
return false;
|
|
}
|
|
catch (DllNotFoundException)
|
|
{
|
|
// No libgdiplus at all on this host: System.Drawing cannot run. Oracle unavailable.
|
|
available = false;
|
|
return false;
|
|
}
|
|
catch (TypeInitializationException)
|
|
{
|
|
// The System.Drawing static ctor failed (usually wrapping the DllNotFoundException).
|
|
available = false;
|
|
return false;
|
|
}
|
|
catch
|
|
{
|
|
// Any other vendored failure: treat as no art for this key, keep the oracle alive.
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
if (bmp != null)
|
|
{
|
|
try
|
|
{
|
|
bmp.Dispose();
|
|
}
|
|
catch
|
|
{
|
|
// A fresh, uncached bitmap; nothing else holds it.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reads a 16bpp ARGB1555 bitmap into a <c>ushort[]</c> with <c>Marshal.Copy</c> — no
|
|
/// <c>unsafe</c> block, the same read <see cref="BridgeArtParity"/> makes of its oracle.
|
|
/// </summary>
|
|
private static ushort[] ToArgb1555(Bitmap bmp)
|
|
{
|
|
var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
|
|
|
BitmapData data = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
|
|
|
|
try
|
|
{
|
|
int w = bmp.Width;
|
|
int h = bmp.Height;
|
|
|
|
var pixels = new ushort[w * h];
|
|
var line = new short[w];
|
|
|
|
long scan = data.Scan0.ToInt64();
|
|
|
|
for (int y = 0; y < h; y++)
|
|
{
|
|
Marshal.Copy(new IntPtr(scan + ((long)y * data.Stride)), line, 0, w);
|
|
|
|
int rowBase = y * w;
|
|
|
|
for (int x = 0; x < w; x++)
|
|
pixels[rowBase + x] = (ushort)line[x];
|
|
}
|
|
|
|
return pixels;
|
|
}
|
|
finally
|
|
{
|
|
bmp.UnlockBits(data);
|
|
}
|
|
}
|
|
}
|
|
}
|