Replace Matrix3 with System.Numerics.Matrix3x2 (#27443)
Replace Matrix3 with Matrix3x2
This commit is contained in:
@@ -14,7 +14,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
|
||||
public MapGridComponent Grid;
|
||||
private bool _needToTransform = false;
|
||||
|
||||
private Matrix3 _matrix = Matrix3.Identity;
|
||||
private Matrix3x2 _matrix = Matrix3x2.Identity;
|
||||
private Vector2 _offset;
|
||||
|
||||
// Tiles which neighbor an exploding tile, but have not yet had the explosion spread to them due to an
|
||||
@@ -44,7 +44,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
|
||||
int typeIndex,
|
||||
Dictionary<Vector2i, NeighborFlag> edgeTiles,
|
||||
EntityUid? referenceGrid,
|
||||
Matrix3 spaceMatrix,
|
||||
Matrix3x2 spaceMatrix,
|
||||
Angle spaceAngle)
|
||||
{
|
||||
Grid = grid;
|
||||
@@ -72,9 +72,10 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
|
||||
var transform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Grid.Owner);
|
||||
var size = (float) Grid.TileSize;
|
||||
|
||||
_matrix.R0C2 = size / 2;
|
||||
_matrix.R1C2 = size / 2;
|
||||
_matrix *= transform.WorldMatrix * Matrix3.Invert(spaceMatrix);
|
||||
_matrix.M31 = size / 2;
|
||||
_matrix.M32 = size / 2;
|
||||
Matrix3x2.Invert(spaceMatrix, out var invSpace);
|
||||
_matrix *= transform.WorldMatrix * invSpace;
|
||||
var relativeAngle = transform.WorldRotation - spaceAngle;
|
||||
_offset = relativeAngle.RotateVec(new Vector2(size / 4, size / 4));
|
||||
}
|
||||
@@ -228,7 +229,7 @@ public sealed class ExplosionGridTileFlood : ExplosionTileFlood
|
||||
return;
|
||||
}
|
||||
|
||||
var center = _matrix.Transform(tile);
|
||||
var center = Vector2.Transform(tile, _matrix);
|
||||
SpaceJump.Add(new((int) MathF.Floor(center.X + _offset.X), (int) MathF.Floor(center.Y + _offset.Y)));
|
||||
SpaceJump.Add(new((int) MathF.Floor(center.X - _offset.Y), (int) MathF.Floor(center.Y + _offset.X)));
|
||||
SpaceJump.Add(new((int) MathF.Floor(center.X - _offset.X), (int) MathF.Floor(center.Y - _offset.Y)));
|
||||
|
||||
@@ -60,7 +60,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
{
|
||||
Dictionary<Vector2i, BlockedSpaceTile> transformedEdges = new();
|
||||
|
||||
var targetMatrix = Matrix3.Identity;
|
||||
var targetMatrix = Matrix3x2.Identity;
|
||||
Angle targetAngle = new();
|
||||
var tileSize = DefaultTileSize;
|
||||
var maxDistanceSq = (int) (maxDistance * maxDistance);
|
||||
@@ -75,9 +75,9 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
tileSize = targetGrid.TileSize;
|
||||
}
|
||||
|
||||
var offsetMatrix = Matrix3.Identity;
|
||||
offsetMatrix.R0C2 = tileSize / 2f;
|
||||
offsetMatrix.R1C2 = tileSize / 2f;
|
||||
var offsetMatrix = Matrix3x2.Identity;
|
||||
offsetMatrix.M31 = tileSize / 2f;
|
||||
offsetMatrix.M32 = tileSize / 2f;
|
||||
|
||||
// Here we can end up with a triple nested for loop:
|
||||
// foreach other grid
|
||||
@@ -106,7 +106,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
var xform = xforms.GetComponent(gridToTransform);
|
||||
var (_, gridWorldRotation, gridWorldMatrix, invGridWorldMatrid) = xform.GetWorldPositionRotationMatrixWithInv(xforms);
|
||||
|
||||
var localEpicentre = (Vector2i) invGridWorldMatrid.Transform(epicentre.Position);
|
||||
var localEpicentre = (Vector2i) Vector2.Transform(epicentre.Position, invGridWorldMatrid);
|
||||
var matrix = offsetMatrix * gridWorldMatrix * targetMatrix;
|
||||
var angle = gridWorldRotation - targetAngle;
|
||||
|
||||
@@ -119,7 +119,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
if (delta.X * delta.X + delta.Y * delta.Y > maxDistanceSq) // no Vector2.Length???
|
||||
continue;
|
||||
|
||||
var center = matrix.Transform(tile);
|
||||
var center = Vector2.Transform(tile, matrix);
|
||||
|
||||
if ((dir & NeighborFlag.Cardinal) == 0)
|
||||
{
|
||||
|
||||
@@ -298,8 +298,8 @@ public sealed partial class ExplosionSystem
|
||||
/// Same as <see cref="ExplodeTile"/>, but for SPAAAAAAACE.
|
||||
/// </summary>
|
||||
internal void ExplodeSpace(BroadphaseComponent lookup,
|
||||
Matrix3 spaceMatrix,
|
||||
Matrix3 invSpaceMatrix,
|
||||
Matrix3x2 spaceMatrix,
|
||||
Matrix3x2 invSpaceMatrix,
|
||||
Vector2i tile,
|
||||
float throwForce,
|
||||
DamageSpecifier damage,
|
||||
@@ -341,7 +341,7 @@ public sealed partial class ExplosionSystem
|
||||
}
|
||||
|
||||
private static bool SpaceQueryCallback(
|
||||
ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state,
|
||||
ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3x2 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state,
|
||||
in EntityUid uid)
|
||||
{
|
||||
if (state.Processed.Contains(uid))
|
||||
@@ -352,7 +352,7 @@ public sealed partial class ExplosionSystem
|
||||
if (xform.ParentUid == state.LookupOwner)
|
||||
{
|
||||
// parented directly to the map, use local position
|
||||
if (state.GridBox.Contains(state.InvSpaceMatrix.Transform(xform.LocalPosition)))
|
||||
if (state.GridBox.Contains(Vector2.Transform(xform.LocalPosition, state.InvSpaceMatrix)))
|
||||
state.List.Add((uid, xform));
|
||||
|
||||
return true;
|
||||
@@ -360,14 +360,14 @@ public sealed partial class ExplosionSystem
|
||||
|
||||
// finally check if it intersects our tile
|
||||
var wpos = state.System.GetWorldPosition(xform);
|
||||
if (state.GridBox.Contains(state.InvSpaceMatrix.Transform(wpos)))
|
||||
if (state.GridBox.Contains(Vector2.Transform(wpos, state.InvSpaceMatrix)))
|
||||
state.List.Add((uid, xform));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool SpaceQueryCallback(
|
||||
ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state,
|
||||
ref (List<(EntityUid, TransformComponent)> List, HashSet<EntityUid> Processed, Matrix3x2 InvSpaceMatrix, EntityUid LookupOwner, EntityQuery<TransformComponent> XformQuery, Box2 GridBox, SharedTransformSystem System) state,
|
||||
in FixtureProxy proxy)
|
||||
{
|
||||
var uid = proxy.Entity;
|
||||
@@ -585,12 +585,12 @@ sealed class Explosion
|
||||
/// <summary>
|
||||
/// The matrix that defines the reference frame for the explosion in space.
|
||||
/// </summary>
|
||||
private readonly Matrix3 _spaceMatrix;
|
||||
private readonly Matrix3x2 _spaceMatrix;
|
||||
|
||||
/// <summary>
|
||||
/// Inverse of <see cref="_spaceMatrix"/>
|
||||
/// </summary>
|
||||
private readonly Matrix3 _invSpaceMatrix;
|
||||
private readonly Matrix3x2 _invSpaceMatrix;
|
||||
|
||||
/// <summary>
|
||||
/// Have all the tiles on all the grids been processed?
|
||||
@@ -656,7 +656,7 @@ sealed class Explosion
|
||||
List<ExplosionGridTileFlood> gridData,
|
||||
List<float> tileSetIntensity,
|
||||
MapCoordinates epicenter,
|
||||
Matrix3 spaceMatrix,
|
||||
Matrix3x2 spaceMatrix,
|
||||
int area,
|
||||
float tileBreakScale,
|
||||
int maxTileBreak,
|
||||
@@ -695,7 +695,7 @@ sealed class Explosion
|
||||
});
|
||||
|
||||
_spaceMatrix = spaceMatrix;
|
||||
_invSpaceMatrix = Matrix3.Invert(spaceMatrix);
|
||||
Matrix3x2.Invert(spaceMatrix, out _invSpaceMatrix);
|
||||
}
|
||||
|
||||
foreach (var grid in gridData)
|
||||
|
||||
@@ -26,7 +26,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
/// <param name="maxIntensity">The maximum intensity that the explosion can have at any given tile. This
|
||||
/// effectively caps the damage that this explosion can do.</param>
|
||||
/// <returns>A list of tile-sets and a list of intensity values which describe the explosion.</returns>
|
||||
private (int, List<float>, ExplosionSpaceTileFlood?, Dictionary<EntityUid, ExplosionGridTileFlood>, Matrix3)? GetExplosionTiles(
|
||||
private (int, List<float>, ExplosionSpaceTileFlood?, Dictionary<EntityUid, ExplosionGridTileFlood>, Matrix3x2)? GetExplosionTiles(
|
||||
MapCoordinates epicenter,
|
||||
string typeID,
|
||||
float totalIntensity,
|
||||
@@ -84,7 +84,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
Dictionary<EntityUid, HashSet<Vector2i>>? previousGridJump;
|
||||
|
||||
// variables for transforming between grid and space-coordinates
|
||||
var spaceMatrix = Matrix3.Identity;
|
||||
var spaceMatrix = Matrix3x2.Identity;
|
||||
var spaceAngle = Angle.Zero;
|
||||
if (referenceGrid != null)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.Explosion;
|
||||
using Content.Shared.Explosion.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -35,7 +36,7 @@ public sealed partial class ExplosionSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Constructor for the shared <see cref="ExplosionEvent"/> using the server-exclusive explosion classes.
|
||||
/// </summary>
|
||||
private EntityUid CreateExplosionVisualEntity(MapCoordinates epicenter, string prototype, Matrix3 spaceMatrix, ExplosionSpaceTileFlood? spaceData, IEnumerable<ExplosionGridTileFlood> gridData, List<float> iterationIntensity)
|
||||
private EntityUid CreateExplosionVisualEntity(MapCoordinates epicenter, string prototype, Matrix3x2 spaceMatrix, ExplosionSpaceTileFlood? spaceData, IEnumerable<ExplosionGridTileFlood> gridData, List<float> iterationIntensity)
|
||||
{
|
||||
var explosionEntity = Spawn(null, MapCoordinates.Nullspace);
|
||||
var comp = AddComp<ExplosionVisualsComponent>(explosionEntity);
|
||||
|
||||
Reference in New Issue
Block a user