(5a377a8ee) Unstable v0.9.1000.0

This commit is contained in:
Juan Pablo Arce
2020-05-13 12:55:42 -03:00
parent b143329701
commit a1ca41aa5d
426 changed files with 14384 additions and 5708 deletions
@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using SpriteParams = Barotrauma.RagdollParams.SpriteParams;
namespace Barotrauma
{
@@ -64,6 +63,14 @@ namespace Barotrauma
}
}
private float scale;
[Serialize(1.0f, true), Editable]
public float Scale
{
get { return scale; }
private set { scale = MathHelper.Clamp(value, 0.0f, 10.0f); }
}
[Serialize(AnimationType.None, false), Editable]
public AnimationType RotationAnim { get; private set; }
@@ -73,6 +80,9 @@ namespace Barotrauma
[Serialize(0, false, description: "If > 0, only one sprite of the same group is used (chosen randomly)"), Editable(ReadOnly = true)]
public int RandomGroupID { get; private set; }
[Serialize("1.0,1.0,1.0,1.0", true), Editable()]
public Color Color { get; set; }
/// <summary>
/// The sprite is only drawn if these conditions are fulfilled
/// </summary>
@@ -158,7 +168,7 @@ namespace Barotrauma
{
foreach (int spriteGroup in spriteGroups.Keys)
{
for (int i = 0; i < spriteGroups.Count; i++)
for (int i = 0; i < spriteGroups[spriteGroup].Count; i++)
{
var decorativeSprite = spriteGroups[spriteGroup][i];
if (decorativeSprite == null) { continue; }
@@ -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;
@@ -21,6 +21,11 @@ namespace Barotrauma
}
}
public bool Loaded
{
get { return texture != null && !cannotBeLoaded; }
}
public Sprite(Texture2D texture, Rectangle? sourceRectangle, Vector2? newOffset, float newRotation = 0.0f)
{
this.texture = texture;
@@ -42,7 +47,12 @@ namespace Barotrauma
partial void LoadTexture(ref Vector4 sourceVector, ref bool shouldReturn)
{
texture = LoadTexture(this.FilePath);
texture = LoadTexture(this.FilePath, out Sprite reusedSprite, Compress);
if (reusedSprite != null)
{
FilePath = string.Intern(reusedSprite.FilePath);
FullPath = string.Intern(reusedSprite.FullPath);
}
if (texture == null)
{
@@ -56,11 +66,25 @@ namespace Barotrauma
public void EnsureLazyLoaded()
{
if (!lazyLoad || texture != null || cannotBeLoaded) { return; }
if (!LazyLoad || texture != null || cannotBeLoaded) { return; }
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);
@@ -69,11 +93,6 @@ namespace Barotrauma
size.Y *= sourceRect.Height;
RelativeOrigin = SourceElement.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
}
foreach (Sprite s in LoadedSprites)
{
if (s == this) { continue; }
if (s.FullPath == FullPath && s.texture != null) { s.texture = texture; }
}
if (texture == null)
{
cannotBeLoaded = true;
@@ -85,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;
@@ -99,6 +118,12 @@ namespace Barotrauma
public static Texture2D LoadTexture(string file)
{
return LoadTexture(file, out _);
}
public static Texture2D LoadTexture(string file, out Sprite reusedSprite, bool compress = true)
{
reusedSprite = null;
if (string.IsNullOrWhiteSpace(file))
{
Texture2D t = null;
@@ -111,13 +136,17 @@ namespace Barotrauma
file = Path.GetFullPath(file);
foreach (Sprite s in LoadedSprites)
{
if (s.FullPath == file && s.texture != null && !s.texture.IsDisposed) { return s.texture; }
if (s.FullPath == file && s.texture != null && !s.texture.IsDisposed)
{
reusedSprite = s;
return s.texture;
}
}
if (File.Exists(file))
{
ToolBox.IsProperFilenameCase(file);
return TextureLoader.FromFile(file);
return TextureLoader.FromFile(file, compress);
}
else
{