acdream/tests/AcDream.Core.Tests/Physics/CellGraphMembershipTests.cs

39 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.Numerics;
using AcDream.Core.Physics;
using AcDream.Core.World.Cells;
using DatReaderWriter.Types;
using Xunit;
using DatEnvCell = DatReaderWriter.DBObjs.EnvCell;
namespace AcDream.Core.Tests.Physics;
public class CellGraphMembershipTests
{
[Fact]
public void ResolveCellId_Resolved_WritesCurrCellTrackingTheResolvedId()
{
var engine = new PhysicsEngine();
var cache = new PhysicsDataCache();
engine.DataCache = cache;
var cs = new CellStruct {
VertexArray = new VertexArray { Vertices = new Dictionary<ushort, SWVertex>() },
Polygons = new Dictionary<ushort, Polygon>(),
PhysicsBSP = null,
};
var dat = new DatEnvCell {
Flags = (DatReaderWriter.Enums.EnvCellFlags)0,
CellPortals = new List<DatReaderWriter.Types.CellPortal>(),
VisibleCells = new List<ushort>(),
};
cache.CacheCellStruct(0xA9B40174u, dat, cs, Matrix4x4.Identity); // registers in the graph (W1)
uint result = engine.ResolveCellId(new Vector3(0, 0, 0), 0.5f, 0xA9B40174u);
// CurrCell tracks whatever id ResolveCellId returned (when that id is in the graph).
Assert.NotNull(cache.CellGraph.CurrCell);
Assert.Equal(result, cache.CellGraph.CurrCell!.Id);
Assert.Equal(0xA9B40174u, cache.CellGraph.CurrCell!.Id);
}
}