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
@@ -12,6 +12,7 @@ namespace Barotrauma
{
public float RotationState;
public float OffsetState;
public float ScaleState;
public Vector2 RandomOffsetMultiplier = new Vector2(Rand.Range(-1.0f, 1.0f), Rand.Range(-1.0f, 1.0f));
public float RandomRotationFactor = Rand.Range(0.0f, 1.0f);
public float RandomScaleFactor = Rand.Range(0.0f, 1.0f);
@@ -27,7 +28,8 @@ namespace Barotrauma
{
None,
Sine,
Noise
Noise,
Circle
}
[Serialize(0.0f, IsPropertySaveable.Yes), Editable]
@@ -47,6 +49,15 @@ namespace Barotrauma
[Serialize(0.0f, IsPropertySaveable.Yes), Editable]
public float OffsetAnimSpeed { get; private set; }
[Serialize(AnimationType.None, IsPropertySaveable.No), Editable]
public AnimationType ScaleAnim { get; private set; }
[Serialize("0,0", IsPropertySaveable.Yes), Editable]
public Vector2 ScaleAnimAmount { get; private set; }
[Serialize(0.0f, IsPropertySaveable.Yes), Editable]
public float ScaleAnimSpeed { get; private set; }
private float rotationSpeedRadians;
private float absRotationSpeedRadians;
@@ -136,7 +147,7 @@ namespace Barotrauma
foreach (var subElement in element.Elements())
{
//choose which list the new conditional should be placed to
List<PropertyConditional> conditionalList = null;
List<PropertyConditional> conditionalList;
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "conditional":
@@ -162,15 +173,14 @@ namespace Barotrauma
{
case AnimationType.Sine:
offsetState %= (MathHelper.TwoPi / OffsetAnimSpeed);
offset *= (float)Math.Sin(offsetState * OffsetAnimSpeed);
offset *= MathF.Sin(offsetState * OffsetAnimSpeed);
break;
case AnimationType.Circle:
offsetState %= (MathHelper.TwoPi / OffsetAnimSpeed);
offset *= new Vector2(MathF.Cos(offsetState * OffsetAnimSpeed), MathF.Sin(offsetState * OffsetAnimSpeed));
break;
case AnimationType.Noise:
offsetState %= 1.0f / (OffsetAnimSpeed * 0.1f);
float t = offsetState * 0.1f * OffsetAnimSpeed;
offset = new Vector2(
offset.X * (PerlinNoise.GetPerlin(t, t) - 0.5f),
offset.Y * (PerlinNoise.GetPerlin(t + 0.5f, t + 0.5f) - 0.5f));
offset *= GetNoiseVector(ref offsetState, OffsetAnimSpeed);
break;
}
}
@@ -192,7 +202,7 @@ namespace Barotrauma
case AnimationType.Sine:
rotationState %= MathHelper.TwoPi / absRotationSpeedRadians;
return
rotationRadians * (float)Math.Sin(rotationState * rotationSpeedRadians)
rotationRadians * MathF.Sin(rotationState * rotationSpeedRadians)
+ MathHelper.Lerp(randomRotationRadians.X, randomRotationRadians.Y, randomRotationFactor);
case AnimationType.Noise:
rotationState %= 1.0f / absRotationSpeedRadians;
@@ -207,13 +217,40 @@ namespace Barotrauma
}
}
public float GetScale(float randomScaleModifier)
public Vector2 GetScale(ref float scaleState, float randomScaleModifier)
{
if (RandomScale == Vector2.Zero)
{
return scale;
}
return MathHelper.Lerp(RandomScale.X, RandomScale.Y, randomScaleModifier);
Vector2 currentScale = Vector2.One *
(RandomScale == Vector2.Zero ? scale : MathHelper.Lerp(RandomScale.X, RandomScale.Y, randomScaleModifier));
if (ScaleAnimSpeed > 0.0f)
{
switch (ScaleAnim)
{
case AnimationType.Sine:
scaleState %= (MathHelper.TwoPi / ScaleAnimSpeed);
currentScale *= Vector2.One + ScaleAnimAmount * MathF.Sin(scaleState * ScaleAnimSpeed);
break;
case AnimationType.Noise:
currentScale *= Vector2.One + ScaleAnimAmount * GetNoiseVector(ref scaleState, ScaleAnimSpeed);
break;
}
}
return currentScale;
}
private static Vector2 GetNoiseVector(ref float state, float speed)
{
//multiply speed by a magic constant, because otherwise a speed of 1 would already be very fast (looping through the noise texture once per second)
//just makes the values more intuitive / closer to what constitutes as "fast" on the other types of animations
float modifiedSpeed = speed * 0.1f;
// wrap around the edge of the noise (t == 1)
state %= 1.0f / modifiedSpeed;
float t = state * modifiedSpeed;
Vector2 noiseValue = new Vector2(
PerlinNoise.GetPerlin(t, t),
//sample the y coordinate from a different position in the noise texture
PerlinNoise.GetPerlin(t + 0.5f, t + 0.5f));
//move the value so it's in the range of -0.5 and 0.5, as opposed to 0-1.
return noiseValue - new Vector2(0.5f, 0.5f);
}
public static void UpdateSpriteStates(ImmutableDictionary<int, ImmutableArray<DecorativeSprite>> spriteGroups, Dictionary<DecorativeSprite, State> animStates,
@@ -264,6 +301,7 @@ namespace Barotrauma
if (!checkConditional(conditional)) { animate = false; break; }
}
if (!animate) { continue; }
spriteState.ScaleState += deltaTime;
spriteState.OffsetState += deltaTime;
spriteState.RotationState += deltaTime;
}
@@ -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++)
@@ -33,8 +33,11 @@ namespace Barotrauma
get { return effect; }
}
public Point Subdivisions => new Point(subDivX, subDivY);
public bool Invert { get; set; }
private Point spritePos;
private Point spriteSize;
@@ -48,7 +51,7 @@ namespace Barotrauma
Invert = invert;
//use subdivisions configured in the xml if the arguments passed to the method are null
Vector2 subdivisionsInXml = element.GetAttributeVector2("subdivisions", Vector2.One);
Vector2 subdivisionsInXml = element.GetAttributeVector2("subdivisions", element.GetAttributeVector2("resolution", Vector2.One));
subDivX = subdivisionsX ?? (int)subdivisionsInXml.X;
subDivY = subdivisionsY ?? (int)subdivisionsInXml.Y;
@@ -1,4 +1,4 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Barotrauma.IO;
@@ -10,7 +10,19 @@ namespace Barotrauma
{
public partial class Sprite
{
public Identifier Identifier { get; private set; }
private Identifier identifier;
public Identifier Identifier
{
get
{
if (identifier.IsEmpty)
{
identifier = GetIdentifier(SourceElement);
}
return identifier;
}
}
public static IEnumerable<Sprite> LoadedSprites
{
get
@@ -71,8 +83,6 @@ namespace Barotrauma
}
}
private string disposeStackTrace;
public bool Loaded
{
get { return texture != null && !cannotBeLoaded; }
@@ -288,24 +298,27 @@ namespace Barotrauma
/// Last version of the game that had broken handling of sprites that were scaled, flipped and offset
/// </summary>
public static readonly Version LastBrokenTiledSpriteGameVersion = new Version(major: 1, minor: 2, build: 7, revision: 0);
public void DrawTiled(ISpriteBatch spriteBatch, Vector2 position, Vector2 targetSize, float rotation = 0f, Vector2? origin = null, Color? color = null, Vector2? startOffset = null, Vector2? textureScale = null, float? depth = null)
{
DrawTiled(spriteBatch, position, targetSize, effects, rotation, origin, color, startOffset, textureScale, depth);
}
public void DrawTiled(ISpriteBatch spriteBatch,
Vector2 position,
Vector2 targetSize,
SpriteEffects spriteEffects,
float rotation = 0f,
Vector2? origin = null,
Color? color = null,
Vector2? startOffset = null,
Vector2? textureScale = null,
float? depth = null,
SpriteEffects? spriteEffects = null)
float? depth = null)
{
if (Texture == null) { return; }
spriteEffects ??= effects;
bool flipHorizontal = spriteEffects.Value.HasFlag(SpriteEffects.FlipHorizontally);
bool flipVertical = spriteEffects.Value.HasFlag(SpriteEffects.FlipVertically);
bool flipHorizontal = (spriteEffects & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; // optimized from spriteEffects.HasFlag(SpriteEffects.FlipHorizontally)
bool flipVertical = (spriteEffects & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; // optimized from spriteEffects.HasFlag(SpriteEffects.FlipVertically)
float addedRotation = rotation + this.rotation;
if (flipHorizontal != flipVertical) { addedRotation = -addedRotation; }
@@ -344,7 +357,7 @@ namespace Barotrauma
rotation: addedRotation,
origin: Vector2.Zero,
scale: scale,
effects: spriteEffects.Value,
effects: spriteEffects,
layerDepth: depth ?? this.depth);
}
@@ -419,7 +432,6 @@ namespace Barotrauma
partial void DisposeTexture()
{
disposeStackTrace = Environment.StackTrace;
if (texture != null)
{
//check if another sprite is using the same texture