Replace Matrix3 with System.Numerics.Matrix3x2 (#27443)

Replace Matrix3 with Matrix3x2
This commit is contained in:
eoineoineoin
2024-06-02 05:07:41 +01:00
committed by GitHub
parent 21d0b1fd55
commit b44b159431
58 changed files with 236 additions and 215 deletions

View File

@@ -114,7 +114,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var beaconsOnly = EntManager.TryGetComponent(mapUid, out FTLDestinationComponent? destComp) &&
destComp.BeaconsOnly;
var mapTransform = Matrix3.CreateInverseTransform(Offset, Angle.Zero);
var mapTransform = Matrix3Helpers.CreateInverseTransform(Offset, Angle.Zero);
if (beaconsOnly && TryGetBeacon(_beacons, mapTransform, args.RelativePixelPosition, PixelRect, out var foundBeacon, out _))
{
@@ -203,7 +203,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
/// </summary>
/// <param name="mapObjects"></param>
/// <returns></returns>
private List<IMapObject> GetViewportMapObjects(Matrix3 matty, List<IMapObject> mapObjects)
private List<IMapObject> GetViewportMapObjects(Matrix3x2 matty, List<IMapObject> mapObjects)
{
var results = new List<IMapObject>();
var enlargement = new Vector2i((int) (16 * UIScale), (int) (16 * UIScale));
@@ -217,7 +217,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var mapCoords = _shuttles.GetMapCoordinates(mapObj);
var relativePos = matty.Transform(mapCoords.Position);
var relativePos = Vector2.Transform(mapCoords.Position, matty);
relativePos = relativePos with { Y = -relativePos.Y };
var uiPosition = ScalePosition(relativePos);
@@ -250,7 +250,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
DrawParallax(handle);
var viewedMapUid = _mapManager.GetMapEntityId(ViewingMap);
var matty = Matrix3.CreateInverseTransform(Offset, Angle.Zero);
var matty = Matrix3Helpers.CreateInverseTransform(Offset, Angle.Zero);
var realTime = _timing.RealTime;
var viewBox = new Box2(Offset - WorldRangeVector, Offset + WorldRangeVector);
var viewportObjects = GetViewportMapObjects(matty, mapObjects);
@@ -267,7 +267,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var (gridPos, gridRot) = _xformSystem.GetWorldPositionRotation(shuttleXform);
gridPos = Maps.GetGridPosition((gridUid, gridPhysics), gridPos, gridRot);
var gridRelativePos = matty.Transform(gridPos);
var gridRelativePos = Vector2.Transform(gridPos, matty);
gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y };
var gridUiPos = ScalePosition(gridRelativePos);
@@ -296,7 +296,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
continue;
}
var adjustedPos = matty.Transform(mapCoords.Position);
var adjustedPos = Vector2.Transform(mapCoords.Position, matty);
var localPos = ScalePosition(adjustedPos with { Y = -adjustedPos.Y});
handle.DrawCircle(localPos, exclusion.Range * MinimapScale, exclusionColor.WithAlpha(0.05f));
handle.DrawCircle(localPos, exclusion.Range * MinimapScale, exclusionColor, filled: false);
@@ -319,7 +319,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
foreach (var (beaconName, coords, mapO) in GetBeacons(viewportObjects, matty, controlLocalBounds))
{
var localPos = matty.Transform(coords.Position);
var localPos = Vector2.Transform(coords.Position, matty);
localPos = localPos with { Y = -localPos.Y };
var beaconUiPos = ScalePosition(localPos);
var mapObject = GetMapObject(localPos, Angle.Zero, scale: 0.75f, scalePosition: true);
@@ -360,7 +360,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var (gridPos, gridRot) = _xformSystem.GetWorldPositionRotation(grid.Owner);
gridPos = Maps.GetGridPosition((grid, gridPhysics), gridPos, gridRot);
var gridRelativePos = matty.Transform(gridPos);
var gridRelativePos = Vector2.Transform(gridPos, matty);
gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y };
var gridUiPos = ScalePosition(gridRelativePos);
@@ -439,7 +439,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
var color = ftlFree ? Color.LimeGreen : Color.Magenta;
var gridRelativePos = matty.Transform(gridPos);
var gridRelativePos = Vector2.Transform(gridPos, matty);
gridRelativePos = gridRelativePos with { Y = -gridRelativePos.Y };
var gridUiPos = ScalePosition(gridRelativePos);
@@ -512,7 +512,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
/// <summary>
/// Returns the beacons that intersect the viewport.
/// </summary>
private IEnumerable<(string Beacon, MapCoordinates Coordinates, IMapObject MapObject)> GetBeacons(List<IMapObject> mapObjs, Matrix3 mapTransform, UIBox2i area)
private IEnumerable<(string Beacon, MapCoordinates Coordinates, IMapObject MapObject)> GetBeacons(List<IMapObject> mapObjs, Matrix3x2 mapTransform, UIBox2i area)
{
foreach (var mapO in mapObjs)
{
@@ -520,7 +520,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
continue;
var beaconCoords = EntManager.GetCoordinates(beacon.Coordinates).ToMap(EntManager, _xformSystem);
var position = mapTransform.Transform(beaconCoords.Position);
var position = Vector2.Transform(beaconCoords.Position, mapTransform);
var localPos = ScalePosition(position with {Y = -position.Y});
// If beacon not on screen then ignore it.
@@ -557,7 +557,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
return mapObj;
}
private bool TryGetBeacon(IEnumerable<IMapObject> mapObjects, Matrix3 mapTransform, Vector2 mousePos, UIBox2i area, out ShuttleBeaconObject foundBeacon, out Vector2 foundLocalPos)
private bool TryGetBeacon(IEnumerable<IMapObject> mapObjects, Matrix3x2 mapTransform, Vector2 mousePos, UIBox2i area, out ShuttleBeaconObject foundBeacon, out Vector2 foundLocalPos)
{
// In pixels
const float BeaconSnapRange = 32f;
@@ -579,7 +579,7 @@ public sealed partial class ShuttleMapControl : BaseShuttleControl
if (!_shuttles.CanFTLBeacon(beaconObj.Coordinates))
continue;
var position = mapTransform.Transform(beaconCoords.Position);
var position = Vector2.Transform(beaconCoords.Position, mapTransform);
var localPos = ScalePosition(position with {Y = -position.Y});
// If beacon not on screen then ignore it.