(6eeea9b7c) v0.9.10.0.0
This commit is contained in:
+2
-2
@@ -109,12 +109,12 @@ namespace Barotrauma.SpriteDeformations
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier)
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
|
||||
{
|
||||
deformation = Deformation;
|
||||
multiplier = CustomDeformationParams.Frequency <= 0.0f ?
|
||||
CustomDeformationParams.Amplitude :
|
||||
(float)Math.Sin(phase) * CustomDeformationParams.Amplitude;
|
||||
(float)Math.Sin(inverse ? -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)
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
|
||||
{
|
||||
deformation = this.deformation;
|
||||
multiplier = InflateParams.Frequency <= 0.0f ? InflateParams.Scale : (float)(Math.Sin(phase) + 1.0f) / 2.0f * InflateParams.Scale;
|
||||
|
||||
+1
-1
@@ -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)
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
|
||||
{
|
||||
deformation = Deformation;
|
||||
multiplier = 1.0f;// this.multiplier;
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ namespace Barotrauma.SpriteDeformations
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier)
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
|
||||
{
|
||||
deformation = Deformation;
|
||||
multiplier = NoiseDeformationParams.Amplitude * Params.Strength;
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ namespace Barotrauma.SpriteDeformations
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier)
|
||||
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
|
||||
{
|
||||
deformation = Deformation;
|
||||
multiplier = 1.0f;
|
||||
|
||||
+16
-7
@@ -195,11 +195,12 @@ namespace Barotrauma.SpriteDeformations
|
||||
Deformation = new Vector2[Params.Resolution.X, Params.Resolution.Y];
|
||||
}
|
||||
|
||||
protected abstract void GetDeformation(out Vector2[,] deformation, out float multiplier);
|
||||
protected abstract void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse);
|
||||
|
||||
public abstract void Update(float deltaTime);
|
||||
|
||||
public static Vector2[,] GetDeformation(IEnumerable<SpriteDeformation> animations, Vector2 scale)
|
||||
private static readonly List<int> yValues = new List<int>();
|
||||
public static Vector2[,] GetDeformation(IEnumerable<SpriteDeformation> animations, Vector2 scale, bool inverseY = false)
|
||||
{
|
||||
foreach (SpriteDeformation animation in animations)
|
||||
{
|
||||
@@ -221,8 +222,16 @@ namespace Barotrauma.SpriteDeformations
|
||||
Vector2[,] deformation = new Vector2[resolution.X, resolution.Y];
|
||||
foreach (SpriteDeformation animation in animations)
|
||||
{
|
||||
animation.GetDeformation(out Vector2[,] animDeformation, out float multiplier);
|
||||
|
||||
yValues.Clear();
|
||||
for (int y = 0; y < resolution.Y; y++)
|
||||
{
|
||||
yValues.Add(y);
|
||||
}
|
||||
if (inverseY && animation is CustomDeformation)
|
||||
{
|
||||
yValues.Reverse();
|
||||
}
|
||||
animation.GetDeformation(out Vector2[,] animDeformation, out float multiplier, inverseY);
|
||||
for (int x = 0; x < resolution.X; x++)
|
||||
{
|
||||
for (int y = 0; y < resolution.Y; y++)
|
||||
@@ -230,13 +239,13 @@ namespace Barotrauma.SpriteDeformations
|
||||
switch (animation.Params.BlendMode)
|
||||
{
|
||||
case DeformationBlendMode.Override:
|
||||
deformation[x,y] = animDeformation[x,y] * scale * multiplier;
|
||||
deformation[x, yValues[y]] = animDeformation[x, y] * scale * multiplier;
|
||||
break;
|
||||
case DeformationBlendMode.Add:
|
||||
deformation[x, y] += animDeformation[x, y] * scale * multiplier;
|
||||
deformation[x, yValues[y]] += animDeformation[x, y] * scale * multiplier;
|
||||
break;
|
||||
case DeformationBlendMode.Multiply:
|
||||
deformation[x, y] *= animDeformation[x, y] * multiplier;
|
||||
deformation[x, yValues[y]] *= animDeformation[x, y] * multiplier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,12 @@ namespace Barotrauma
|
||||
get { return effect; }
|
||||
}
|
||||
|
||||
public bool Invert { get; set; }
|
||||
|
||||
private Point spritePos;
|
||||
private Point spriteSize;
|
||||
|
||||
partial void InitProjSpecific(XElement element, int? subdivisionsX, int? subdivisionsY, bool lazyLoad)
|
||||
partial void InitProjSpecific(XElement element, int? subdivisionsX, int? subdivisionsY, bool lazyLoad, bool invert)
|
||||
{
|
||||
if (effect == null)
|
||||
{
|
||||
@@ -47,6 +49,8 @@ namespace Barotrauma
|
||||
effect = GameMain.Instance.Content.Load<Effect>("Effects/deformshader_opengl");
|
||||
#endif
|
||||
}
|
||||
|
||||
Invert = invert;
|
||||
|
||||
//use subdivisions configured in the xml if the arguments passed to the method are null
|
||||
Vector2 subdivisionsInXml = element.GetAttributeVector2("subdivisions", Vector2.One);
|
||||
@@ -121,6 +125,12 @@ namespace Barotrauma
|
||||
uvBottomRight = Vector2.Divide((pos + size).ToVector2(), textureSize);
|
||||
uvTopLeftFlipped = Vector2.Divide(new Vector2(pos.X + size.X, pos.Y), textureSize);
|
||||
uvBottomRightFlipped = Vector2.Divide(new Vector2(pos.X, pos.Y + size.Y), textureSize);
|
||||
if (Invert)
|
||||
{
|
||||
var temp = uvBottomRightFlipped;
|
||||
uvBottomRightFlipped = uvTopLeftFlipped;
|
||||
uvTopLeftFlipped = temp;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
@@ -267,7 +277,7 @@ namespace Barotrauma
|
||||
Matrix.CreateTranslation(pos);
|
||||
}
|
||||
|
||||
public void Draw(Camera cam, Vector3 pos, Vector2 origin, float rotate, Vector2 scale, Color color, bool flip = false, bool mirror = false)
|
||||
public void Draw(Camera cam, Vector3 pos, Vector2 origin, float rotate, Vector2 scale, Color color, bool mirror = false, bool invert = false)
|
||||
{
|
||||
if (Sprite.Texture == null) { return; }
|
||||
if (!initialized) { Init(); }
|
||||
@@ -291,13 +301,13 @@ namespace Barotrauma
|
||||
effect.Parameters["deformArray"].SetValue(deformAmount);
|
||||
effect.Parameters["deformArrayWidth"].SetValue(deformArrayWidth);
|
||||
effect.Parameters["deformArrayHeight"].SetValue(deformArrayHeight);
|
||||
if (mirror)
|
||||
if (invert)
|
||||
{
|
||||
flip = !flip;
|
||||
mirror = !mirror;
|
||||
}
|
||||
effect.Parameters["uvTopLeft"].SetValue(flip ? uvTopLeftFlipped : uvTopLeft);
|
||||
effect.Parameters["uvBottomRight"].SetValue(flip ? uvBottomRightFlipped : uvBottomRight);
|
||||
effect.GraphicsDevice.SetVertexBuffer(flip ? flippedVertexBuffer : vertexBuffer);
|
||||
effect.Parameters["uvTopLeft"].SetValue(mirror ? uvTopLeftFlipped : uvTopLeft);
|
||||
effect.Parameters["uvBottomRight"].SetValue(mirror ? uvBottomRightFlipped : uvBottomRight);
|
||||
effect.GraphicsDevice.SetVertexBuffer(mirror ? flippedVertexBuffer : vertexBuffer);
|
||||
effect.GraphicsDevice.Indices = indexBuffer;
|
||||
effect.CurrentTechnique.Passes[0].Apply();
|
||||
effect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, triangleCount);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Barotrauma
|
||||
|
||||
partial void LoadTexture(ref Vector4 sourceVector, ref bool shouldReturn)
|
||||
{
|
||||
texture = LoadTexture(this.FilePath, out Sprite reusedSprite);
|
||||
texture = LoadTexture(this.FilePath, out Sprite reusedSprite, Compress);
|
||||
if (reusedSprite != null)
|
||||
{
|
||||
FilePath = string.Intern(reusedSprite.FilePath);
|
||||
@@ -70,7 +70,21 @@ namespace Barotrauma
|
||||
|
||||
Vector4 sourceVector = Vector4.Zero;
|
||||
bool temp2 = false;
|
||||
LoadTexture(ref sourceVector, ref temp2);
|
||||
int maxLoadRetries = 3;
|
||||
for (int i = 0; i <= maxLoadRetries; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadTexture(ref sourceVector, ref temp2);
|
||||
}
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
if (i == maxLoadRetries || !File.Exists(FilePath)) { throw; }
|
||||
DebugConsole.NewMessage("Loading sprite \"" + FilePath + "\" failed, retrying in 250 ms...");
|
||||
System.Threading.Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceRect.Width == 0 && sourceRect.Height == 0)
|
||||
{
|
||||
sourceRect = new Rectangle((int)sourceVector.X, (int)sourceVector.Y, (int)sourceVector.Z, (int)sourceVector.W);
|
||||
@@ -90,7 +104,7 @@ namespace Barotrauma
|
||||
public void ReloadTexture(IEnumerable<Sprite> spritesToUpdate)
|
||||
{
|
||||
texture.Dispose();
|
||||
texture = TextureLoader.FromFile(FilePath);
|
||||
texture = TextureLoader.FromFile(FilePath, Compress);
|
||||
foreach (Sprite sprite in spritesToUpdate)
|
||||
{
|
||||
sprite.texture = texture;
|
||||
@@ -107,7 +121,7 @@ namespace Barotrauma
|
||||
return LoadTexture(file, out _);
|
||||
}
|
||||
|
||||
public static Texture2D LoadTexture(string file, out Sprite reusedSprite)
|
||||
public static Texture2D LoadTexture(string file, out Sprite reusedSprite, bool compress = true)
|
||||
{
|
||||
reusedSprite = null;
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
@@ -119,10 +133,10 @@ namespace Barotrauma
|
||||
});
|
||||
return t;
|
||||
}
|
||||
file = Path.GetFullPath(file);
|
||||
string fullPath = Path.GetFullPath(file);
|
||||
foreach (Sprite s in LoadedSprites)
|
||||
{
|
||||
if (s.FullPath == file && s.texture != null && !s.texture.IsDisposed)
|
||||
if (s.FullPath == fullPath && s.texture != null && !s.texture.IsDisposed)
|
||||
{
|
||||
reusedSprite = s;
|
||||
return s.texture;
|
||||
@@ -131,8 +145,13 @@ namespace Barotrauma
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
ToolBox.IsProperFilenameCase(file);
|
||||
return TextureLoader.FromFile(file);
|
||||
if (!ToolBox.IsProperFilenameCase(file))
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Texture file \"" + file + "\" has incorrect case!");
|
||||
#endif
|
||||
}
|
||||
return TextureLoader.FromFile(file, compress);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user