Unstable 1.8.4.0

This commit is contained in:
Markus Isberg
2025-03-12 12:56:27 +00:00
parent a4c3e868e4
commit a4a3427e4e
627 changed files with 29860 additions and 10018 deletions
@@ -23,7 +23,9 @@ namespace Barotrauma.SpriteDeformations
class CustomDeformation : SpriteDeformation
{
private List<Vector2[]> deformRows = new List<Vector2[]>();
private readonly List<Vector2[]> deformRows = new List<Vector2[]>();
private readonly Vector2[,] flippedDeformation;
private CustomDeformationParams CustomDeformationParams => Params as CustomDeformationParams;
@@ -81,40 +83,25 @@ namespace Barotrauma.SpriteDeformations
//construct an array for the desired resolution,
//interpolating values if the resolution configured in the xml is smaller
//deformation = new Vector2[Resolution.X, Resolution.Y];
float divX = 1.0f / Resolution.X, divY = 1.0f / Resolution.Y;
int newWidth = Resolution.X, newHeight = Resolution.Y;
Deformation = MathUtils.ResizeVector2Array(configDeformation, newWidth, newHeight);
flippedDeformation = new Vector2[Resolution.X, Resolution.Y];
for (int x = 0; x < Resolution.X; x++)
{
float normalizedX = x / (float)(Resolution.X - 1);
for (int y = 0; y < Resolution.Y; y++)
{
float normalizedY = y / (float)(Resolution.Y - 1);
Point indexTopLeft = new Point(
Math.Min((int)Math.Floor(normalizedX * (configDeformation.GetLength(0) - 1)), configDeformation.GetLength(0) - 1),
Math.Min((int)Math.Floor(normalizedY * (configDeformation.GetLength(1) - 1)), configDeformation.GetLength(1) - 1));
Point indexBottomRight = new Point(
Math.Min(indexTopLeft.X + 1, configDeformation.GetLength(0) - 1),
Math.Min(indexTopLeft.Y + 1, configDeformation.GetLength(1) - 1));
Vector2 deformTopLeft = configDeformation[indexTopLeft.X, indexTopLeft.Y];
Vector2 deformTopRight = configDeformation[indexBottomRight.X, indexTopLeft.Y];
Vector2 deformBottomLeft = configDeformation[indexTopLeft.X, indexBottomRight.Y];
Vector2 deformBottomRight = configDeformation[indexBottomRight.X, indexBottomRight.Y];
Deformation[x, y] = Vector2.Lerp(
Vector2.Lerp(deformTopLeft, deformTopRight, (normalizedX % divX) / divX),
Vector2.Lerp(deformBottomLeft, deformBottomRight, (normalizedX % divX) / divX),
(normalizedY % divY) / divY);
flippedDeformation[x, y] = Deformation[Resolution.X - x - 1, y]; // read the rows from right to left
}
}
}
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool flippedHorizontally, bool inverseY)
{
deformation = Deformation;
deformation = flippedHorizontally ? flippedDeformation : Deformation;
multiplier = CustomDeformationParams.Frequency <= 0.0f ?
CustomDeformationParams.Amplitude :
(float)Math.Sin(inverse ? -phase : phase) * CustomDeformationParams.Amplitude;
(float)Math.Sin(inverseY ? -phase : phase) * CustomDeformationParams.Amplitude;
multiplier *= Params.Strength;
}
@@ -54,7 +54,7 @@ namespace Barotrauma.SpriteDeformations
phase = Rand.Range(0.0f, MathHelper.TwoPi);
}
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool flippedHorizontally, bool inverseY = false)
{
deformation = this.deformation;
multiplier = InflateParams.Frequency <= 0.0f ? InflateParams.Scale : (float)(Math.Sin(phase) + 1.0f) / 2.0f * InflateParams.Scale;
@@ -56,7 +56,7 @@ namespace Barotrauma.SpriteDeformations
public JointBendDeformation(XElement element) : base(element, new JointBendDeformationParams(element)) { }
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool flippedHorizontally, bool inverseY = false)
{
deformation = Deformation;
multiplier = 1.0f;// this.multiplier;
@@ -47,7 +47,7 @@ namespace Barotrauma.SpriteDeformations
}
}
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool flippedHorizontally, bool inverseY = false)
{
deformation = Deformation;
multiplier = NoiseDeformationParams.Amplitude * Params.Strength;
@@ -100,7 +100,7 @@ namespace Barotrauma.SpriteDeformations
}
}
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool flippedHorizontally, bool inverseY)
{
deformation = Deformation;
multiplier = 1.0f;
@@ -104,7 +104,7 @@ namespace Barotrauma.SpriteDeformations
public virtual float Phase { get; set; }
protected Vector2[,] Deformation { get; private set; }
protected Vector2[,] Deformation { get; set; }
public SpriteDeformationParams Params { get; set; }
@@ -141,7 +141,13 @@ namespace Barotrauma.SpriteDeformations
{
typeName = element.GetAttributeString("typename", null) ?? element.GetAttributeString("type", "");
}
var resolution = element.GetAttributePoint(nameof(Resolution), new Point(0, 0));
if (resolution.X < 2|| resolution.Y < 2)
{
DebugConsole.AddWarning($"Potential error in sprite deformation ({parentDebugName}): resolution must be at least 2x2.");
}
SpriteDeformation newDeformation = null;
switch (typeName.ToLowerInvariant())
{
@@ -195,12 +201,14 @@ namespace Barotrauma.SpriteDeformations
Deformation = new Vector2[Params.Resolution.X, Params.Resolution.Y];
}
protected abstract void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse);
/// <param name="flippedHorizontally">Is the sprite flipped horizontally?</param>
/// <param name="inverseY">Should the y-coordinate of customdeformations be inverted? Legacy fix for mirroring deformable light sprites.</param>
protected abstract void GetDeformation(out Vector2[,] deformation, out float multiplier, bool flippedHorizontally, bool inverseY);
public abstract void Update(float deltaTime);
private static readonly List<int> yValues = new List<int>();
public static Vector2[,] GetDeformation(IEnumerable<SpriteDeformation> animations, Vector2 scale, bool inverseY = false)
public static Vector2[,] GetDeformation(IEnumerable<SpriteDeformation> animations, Vector2 scale, bool flippedHorizontally, bool inverseY = false)
{
foreach (SpriteDeformation animation in animations)
{
@@ -231,7 +239,7 @@ namespace Barotrauma.SpriteDeformations
{
yValues.Reverse();
}
animation.GetDeformation(out Vector2[,] animDeformation, out float multiplier, inverseY);
animation.GetDeformation(out Vector2[,] animDeformation, out float multiplier, flippedHorizontally, inverseY);
for (int x = 0; x < resolution.X; x++)
{
for (int y = 0; y < resolution.Y; y++)