using System; using System.IO; using System.Numerics; using AcDream.Core.Physics; using Xunit; using Xunit.Abstractions; namespace AcDream.Core.Tests.Physics; // TEMPORARY #347 diagnostic — deleted before landing. public sealed class Scratch347DiagTests { private readonly ITestOutputHelper _out; public Scratch347DiagTests(ITestOutputHelper output) => _out = output; [Fact] public void DumpFirstArmingTick() { var heights = new byte[81]; heights[3 * 9 + 4] = 32; var heightTable = new float[256]; for (int i = 0; i < 256; i++) heightTable[i] = i; var engine = new PhysicsEngine(); engine.AddLandblock(0xA9B4FFFFu, new TerrainSurface(heights, heightTable), Array.Empty(), Array.Empty(), 0f, 0f); var body = new PhysicsBody { State = PhysicsStateFlags.Gravity, TransientState = TransientStateFlags.Active | TransientStateFlags.Contact | TransientStateFlags.OnWalkable, }; float dx = 0f, dy = 0.23f; var position = new Vector3(80.4f, 79.8f, 0f); uint cell = TerrainSurface.ComputeOutdoorCellId(0xA9B4FFFFu, 80.4f, 79.8f); PhysicsDiagnostics.DumpTransitFailEnabled = true; var saved = Console.Out; var sw = new StringWriter(); Console.SetOut(sw); try { for (int tick = 0; tick < 3; tick++) { var result = engine.ResolveWithTransition( currentPos: position, targetPos: new Vector3(position.X + dx, position.Y + dy, position.Z), cellId: cell, sphereRadius: 0.47f, sphereHeight: 1.20f, stepUpHeight: 0.60f, stepDownHeight: 1.50f, isOnGround: true, body: body, moverFlags: ObjectInfoState.IsPlayer | ObjectInfoState.EdgeSlide, movingEntityId: 0x5000000Au); position = result.Position; cell = result.CellId; if (tick < 2) sw.GetStringBuilder().Clear(); // keep only the arming tick } } finally { Console.SetOut(saved); PhysicsDiagnostics.DumpTransitFailEnabled = false; } foreach (var line in sw.ToString().Split('\n')) _out.WriteLine(line.TrimEnd()); } }