Unstable 0.16.1.0

This commit is contained in:
Markus Isberg
2022-01-27 00:30:32 +09:00
parent 7d6421a548
commit b259af5911
161 changed files with 1913 additions and 638 deletions
@@ -148,14 +148,8 @@ namespace Barotrauma
return t;
}
string fullPath = Path.GetFullPath(file);
foreach (Sprite s in LoadedSprites)
{
if (s.FullPath == fullPath && s.texture != null && !s.texture.IsDisposed)
{
reusedSprite = s;
return s.texture;
}
}
reusedSprite = FindMatchingSprite(fullPath, requireTexture: true);
if (reusedSprite != null) { return reusedSprite.texture; }
if (File.Exists(file))
{
@@ -176,6 +170,22 @@ namespace Barotrauma
return null;
}
private static Sprite FindMatchingSprite(string fullPath, bool requireTexture)
{
lock (list)
{
foreach (var wRef in list)
{
if (wRef.TryGetTarget(out Sprite sprite))
{
bool hasTexture = sprite.texture != null && !sprite.texture.IsDisposed;
if (sprite.FullPath == fullPath && (hasTexture || !requireTexture)) { return sprite; }
}
}
}
return null;
}
public void Draw(ISpriteBatch spriteBatch, Vector2 pos, float rotate = 0.0f, float scale = 1.0f, SpriteEffects spriteEffect = SpriteEffects.None)
{
this.Draw(spriteBatch, pos, Color.White, rotate, scale, spriteEffect);
@@ -371,15 +381,9 @@ namespace Barotrauma
//check if another sprite is using the same texture
if (!string.IsNullOrEmpty(FilePath)) //file can be empty if the sprite is created directly from a Texture2D instance
{
lock (list)
{
foreach (Sprite s in LoadedSprites)
{
if (s.FullPath == FullPath) { return; }
}
}
if (FindMatchingSprite(FullPath, requireTexture: false) != null) { return; }
}
//if not, free the texture
if (texture != null)
{