(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user