(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -34,7 +34,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Text;
|
||||
#if NET_4_0
|
||||
using System.Web.Configuration;
|
||||
@@ -225,7 +225,7 @@ namespace RestSharp.Contrib
|
||||
if (String.IsNullOrEmpty(value))
|
||||
return value;
|
||||
|
||||
MemoryStream result = new MemoryStream();
|
||||
System.IO.MemoryStream result = new System.IO.MemoryStream();
|
||||
int length = value.Length;
|
||||
for (int i = 0; i < length; i++)
|
||||
UrlPathEncodeChar(value[i], result);
|
||||
@@ -248,7 +248,7 @@ namespace RestSharp.Contrib
|
||||
if (count < 0 || count > blen - offset)
|
||||
throw new ArgumentOutOfRangeException("count");
|
||||
|
||||
MemoryStream result = new MemoryStream(count);
|
||||
System.IO.MemoryStream result = new System.IO.MemoryStream(count);
|
||||
int end = offset + count;
|
||||
for (int i = offset; i < end; i++)
|
||||
UrlEncodeChar((char)bytes[i], result, false);
|
||||
@@ -575,7 +575,7 @@ namespace RestSharp.Contrib
|
||||
);
|
||||
}
|
||||
|
||||
internal static void UrlEncodeChar(char c, Stream result, bool isUnicode)
|
||||
internal static void UrlEncodeChar(char c, System.IO.Stream result, bool isUnicode)
|
||||
{
|
||||
if (c > 255)
|
||||
{
|
||||
@@ -632,7 +632,7 @@ namespace RestSharp.Contrib
|
||||
result.WriteByte((byte)c);
|
||||
}
|
||||
|
||||
internal static void UrlPathEncodeChar(char c, Stream result)
|
||||
internal static void UrlPathEncodeChar(char c, System.IO.Stream result)
|
||||
{
|
||||
if (c < 33 || c > 126)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace RestSharp.Contrib
|
||||
|
||||
#region Methods
|
||||
|
||||
/*
|
||||
public static void HtmlAttributeEncode(string s, TextWriter output)
|
||||
{
|
||||
if (output == null)
|
||||
@@ -92,6 +93,7 @@ namespace RestSharp.Contrib
|
||||
output.Write(HttpEncoder.HtmlAttributeEncode(s));
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
public static string HtmlAttributeEncode(string s)
|
||||
{
|
||||
@@ -113,7 +115,7 @@ namespace RestSharp.Contrib
|
||||
return UrlDecode(str, Encoding.UTF8);
|
||||
}
|
||||
|
||||
static char[] GetChars(MemoryStream b, Encoding e)
|
||||
static char[] GetChars(System.IO.MemoryStream b, Encoding e)
|
||||
{
|
||||
return e.GetChars(b.GetBuffer(), 0, (int)b.Length);
|
||||
}
|
||||
@@ -260,7 +262,7 @@ namespace RestSharp.Contrib
|
||||
throw new ArgumentOutOfRangeException("count");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
MemoryStream acc = new MemoryStream();
|
||||
System.IO.MemoryStream acc = new System.IO.MemoryStream();
|
||||
|
||||
int end = count + offset;
|
||||
int xchar;
|
||||
@@ -354,7 +356,7 @@ namespace RestSharp.Contrib
|
||||
if (count < 0 || offset > len - count)
|
||||
throw new ArgumentOutOfRangeException("count");
|
||||
|
||||
MemoryStream result = new MemoryStream();
|
||||
System.IO.MemoryStream result = new System.IO.MemoryStream();
|
||||
int end = offset + count;
|
||||
for (int i = offset; i < end; i++)
|
||||
{
|
||||
@@ -492,7 +494,7 @@ namespace RestSharp.Contrib
|
||||
if (str.Length == 0)
|
||||
return new byte[0];
|
||||
|
||||
MemoryStream result = new MemoryStream(str.Length);
|
||||
System.IO.MemoryStream result = new System.IO.MemoryStream(str.Length);
|
||||
foreach (char c in str)
|
||||
{
|
||||
HttpEncoder.UrlEncodeChar(c, result, true);
|
||||
@@ -525,6 +527,7 @@ namespace RestSharp.Contrib
|
||||
/// </summary>
|
||||
/// <param name="s">The HTML string to decode</param>
|
||||
/// <param name="output">The TextWriter output stream containing the decoded string. </param>
|
||||
/*
|
||||
public static void HtmlDecode(string s, TextWriter output)
|
||||
{
|
||||
if (output == null)
|
||||
@@ -545,6 +548,7 @@ namespace RestSharp.Contrib
|
||||
#endif
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static string HtmlEncode(string s)
|
||||
{
|
||||
@@ -566,6 +570,7 @@ namespace RestSharp.Contrib
|
||||
/// </summary>
|
||||
/// <param name="s">The string to encode. </param>
|
||||
/// <param name="output">The TextWriter output stream containing the encoded string. </param>
|
||||
/*
|
||||
public static void HtmlEncode(string s, TextWriter output)
|
||||
{
|
||||
if (output == null)
|
||||
@@ -586,6 +591,8 @@ namespace RestSharp.Contrib
|
||||
#endif
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#if NET_4_0
|
||||
public static string HtmlEncode (object value)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#if DEBUG
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
@@ -41,7 +41,7 @@ namespace Barotrauma
|
||||
|
||||
if (Directory.Exists(conversationsPath + $"/{languageNoWhitespace}"))
|
||||
{
|
||||
string[] conversationFileArray = Directory.GetFiles(conversationsPath + $"/{languageNoWhitespace}", "*.csv", SearchOption.AllDirectories);
|
||||
IEnumerable<string> conversationFileArray = Directory.GetFiles(conversationsPath + $"/{languageNoWhitespace}", "*.csv", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
if (conversationFileArray != null)
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace Barotrauma
|
||||
|
||||
if (Directory.Exists(infoTextPath + $"/{languageNoWhitespace}"))
|
||||
{
|
||||
string[] infoTextFileArray = Directory.GetFiles(infoTextPath + $"/{languageNoWhitespace}", "*.csv", SearchOption.AllDirectories);
|
||||
IEnumerable<string> infoTextFileArray = Directory.GetFiles(infoTextPath + $"/{languageNoWhitespace}", "*.csv", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
if (infoTextFileArray != null)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ namespace Barotrauma
|
||||
}
|
||||
else if (split[0].Contains(".") && !split[0].Any(char.IsUpper)) // An empty field
|
||||
{
|
||||
xmlContent.Add($"<{split[0]}><!-- No data --></{split[0]}>");
|
||||
xmlContent.Add($"<{split[0]}></{split[0]}>");
|
||||
}
|
||||
else // A header
|
||||
{
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static class Quad
|
||||
{
|
||||
private static VertexBuffer vertexBuffer = null;
|
||||
private static IndexBuffer indexBuffer = null;
|
||||
private static BasicEffect basicEffect = null;
|
||||
private static GraphicsDevice graphicsDevice = null;
|
||||
|
||||
public static void Init(GraphicsDevice graphics)
|
||||
{
|
||||
if (graphicsDevice != null) { return; }
|
||||
|
||||
graphicsDevice = graphics;
|
||||
|
||||
vertexBuffer = new VertexBuffer(graphics, VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly);
|
||||
indexBuffer = new IndexBuffer(graphics, IndexElementSize.SixteenBits, 4, BufferUsage.WriteOnly);
|
||||
|
||||
InitVertexData();
|
||||
indexBuffer.SetData(new ushort[] { 0, 1, 2, 3 });
|
||||
|
||||
basicEffect = new BasicEffect(graphics) { TextureEnabled = true };
|
||||
|
||||
GameMain.Instance.OnResolutionChanged += () =>
|
||||
{
|
||||
InitVertexData();
|
||||
};
|
||||
}
|
||||
|
||||
private static void InitVertexData()
|
||||
{
|
||||
Vector2 halfPixelOffset = Vector2.Zero;
|
||||
#if LINUX || OSX
|
||||
halfPixelOffset = new Vector2(0.5f / GameMain.GraphicsWidth, 0.5f / GameMain.GraphicsHeight);
|
||||
#endif
|
||||
|
||||
VertexPositionTexture[] vertices =
|
||||
{
|
||||
new VertexPositionTexture(new Vector3(-1f, -1f, 1f), new Vector2(0f, 1f) + halfPixelOffset),
|
||||
new VertexPositionTexture(new Vector3(-1f, 1f, 1f), new Vector2(0f, 0f) + halfPixelOffset),
|
||||
new VertexPositionTexture(new Vector3(1f, -1f, 1f), new Vector2(1f, 1f) + halfPixelOffset),
|
||||
new VertexPositionTexture(new Vector3(1f, 1f, 1f), new Vector2(1f, 0f) + halfPixelOffset)
|
||||
};
|
||||
|
||||
vertexBuffer.SetData(vertices);
|
||||
}
|
||||
|
||||
public static void UseBasicEffect(Texture2D texture)
|
||||
{
|
||||
basicEffect.Texture = texture;
|
||||
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
|
||||
public static void Render()
|
||||
{
|
||||
graphicsDevice.SetVertexBuffer(vertexBuffer);
|
||||
graphicsDevice.Indices = indexBuffer;
|
||||
graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Lidgren.Network;
|
||||
using Color = Microsoft.Xna.Framework.Color;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -34,36 +36,186 @@ namespace Barotrauma
|
||||
});
|
||||
}
|
||||
|
||||
public static Texture2D FromFile(string path, bool mipmap=false)
|
||||
private static byte[] CompressDxt5(byte[] data, int width, int height)
|
||||
{
|
||||
path = path.CleanUpPath();
|
||||
try
|
||||
using (System.IO.MemoryStream mstream = new System.IO.MemoryStream())
|
||||
{
|
||||
using (Stream fileStream = File.OpenRead(path))
|
||||
for (int y = 0; y < height; y += 4)
|
||||
{
|
||||
return FromStream(fileStream, path, mipmap);
|
||||
for (int x = 0; x < width; x += 4)
|
||||
{
|
||||
int offset = x * 4 + y * 4 * width;
|
||||
CompressDxt5Block(data, offset, width, mstream);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Loading texture \"" + path + "\" failed!", e);
|
||||
return null;
|
||||
return mstream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static Texture2D FromStream(Stream fileStream, string path=null, bool mipmap=false)
|
||||
private static void CompressDxt5Block(byte[] data, int offset, int width, System.IO.Stream output)
|
||||
{
|
||||
int r1 = 255, g1 = 255, b1 = 255, a1 = 255;
|
||||
int r2 = 0, g2 = 0, b2 = 0, a2 = 0;
|
||||
|
||||
//determine the two colors to interpolate between:
|
||||
//color 1 represents lowest luma, color 2 represents highest luma
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
int pixelOffset = offset + (4 * ((i % 4) + (width * (i >> 2))));
|
||||
int r, g, b, a;
|
||||
r = data[pixelOffset + 0];
|
||||
g = data[pixelOffset + 1];
|
||||
b = data[pixelOffset + 2];
|
||||
a = data[pixelOffset + 3];
|
||||
if (r * 299 + g * 587 + b * 114 < r1 * 299 + g1 * 587 + b1 * 114)
|
||||
{
|
||||
r1 = r; g1 = g; b1 = b;
|
||||
}
|
||||
if (r * 299 + g * 587 + b * 114 > r2 * 299 + g2 * 587 + b2 * 114)
|
||||
{
|
||||
r2 = r; g2 = g; b2 = b;
|
||||
}
|
||||
if (a < a1) { a1 = a; }
|
||||
if (a > a2) { a2 = a; }
|
||||
}
|
||||
|
||||
//convert the colors to rgb565 (16-bit rgb)
|
||||
int r1_565 = (r1 * 0x1f) / 0xff; if (r1_565 > 0x1f) { r1_565 = 0x1f; }
|
||||
int g1_565 = (g1 * 0x3f) / 0xff; if (g1_565 > 0x3f) { g1_565 = 0x3f; }
|
||||
int b1_565 = (b1 * 0x1f) / 0xff; if (b1_565 > 0x1f) { b1_565 = 0x1f; }
|
||||
|
||||
int r2_565 = (r2 * 0x1f) / 0xff; if (r2_565 > 0x1f) { r2_565 = 0x1f; }
|
||||
int g2_565 = (g2 * 0x3f) / 0xff; if (g2_565 > 0x3f) { g2_565 = 0x3f; }
|
||||
int b2_565 = (b2 * 0x1f) / 0xff; if (b2_565 > 0x1f) { b2_565 = 0x1f; }
|
||||
|
||||
//luma is also used to determine which color on the palette
|
||||
//most closely resembles each pixel to compress, so we
|
||||
//calculate this here
|
||||
int y1 = r1 * 299 + g1 * 587 + b1 * 114;
|
||||
int y2 = r2 * 299 + g2 * 587 + b2 * 114;
|
||||
|
||||
byte[] newData = new byte[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
int pixelOffset = offset + (4 * ((i % 4) + (width * (i >> 2))));
|
||||
int r, g, b, a;
|
||||
r = data[pixelOffset + 0];
|
||||
g = data[pixelOffset + 1];
|
||||
b = data[pixelOffset + 2];
|
||||
a = data[pixelOffset + 3];
|
||||
|
||||
if (a1 < a2)
|
||||
{
|
||||
a -= a1;
|
||||
a = (a * 0x7) / (a2 - a1);
|
||||
if (a > 0x7) { a = 0x7; }
|
||||
|
||||
switch (a)
|
||||
{
|
||||
case 0:
|
||||
a = 1;
|
||||
break;
|
||||
case 1:
|
||||
a = 7;
|
||||
break;
|
||||
case 2:
|
||||
a = 6;
|
||||
break;
|
||||
case 3:
|
||||
a = 5;
|
||||
break;
|
||||
case 4:
|
||||
a = 4;
|
||||
break;
|
||||
case 5:
|
||||
a = 3;
|
||||
break;
|
||||
case 6:
|
||||
a = 2;
|
||||
break;
|
||||
case 7:
|
||||
a = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
a = 0;
|
||||
}
|
||||
|
||||
NetBitWriter.WriteUInt32((uint)a, 3, newData, 16 + (i * 3));
|
||||
|
||||
int y = r * 299 + g * 587 + b * 114;
|
||||
|
||||
int max = y2 - y1;
|
||||
int diffY = y - y1;
|
||||
|
||||
int paletteIndex;
|
||||
if (diffY < max / 4)
|
||||
{
|
||||
paletteIndex = 0;
|
||||
}
|
||||
else if (diffY < max / 2)
|
||||
{
|
||||
paletteIndex = 2;
|
||||
}
|
||||
else if (diffY < max * 3 / 4)
|
||||
{
|
||||
paletteIndex = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
paletteIndex = 1;
|
||||
}
|
||||
newData[12 + (i / 4)] |= (byte)(paletteIndex << (2 * (i % 4)));
|
||||
}
|
||||
|
||||
newData[0] = (byte)a2;
|
||||
newData[1] = (byte)a1;
|
||||
|
||||
newData[9] = (byte)((r1_565 << 3) | (g1_565 >> 3));
|
||||
newData[8] = (byte)((g1_565 << 5) | b1_565);
|
||||
newData[11] = (byte)((r2_565 << 3) | (g2_565 >> 3));
|
||||
newData[10] = (byte)((g2_565 << 5) | b2_565);
|
||||
|
||||
output.Write(newData, 0, 16);
|
||||
}
|
||||
|
||||
public static Texture2D FromFile(string path, bool compress = true, bool mipmap = false)
|
||||
{
|
||||
using (FileStream fileStream = File.OpenRead(path))
|
||||
{
|
||||
return FromStream(fileStream, path, compress, mipmap);
|
||||
}
|
||||
}
|
||||
|
||||
public static Texture2D FromStream(System.IO.Stream stream, string path = null, bool compress = true, bool mipmap = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
int width = 0; int height = 0; int channels = 0;
|
||||
path = path.CleanUpPath();
|
||||
byte[] textureData = null;
|
||||
textureData = Texture2D.TextureDataFromStream(fileStream, out width, out height, out channels);
|
||||
textureData = Texture2D.TextureDataFromStream(stream, out int width, out int height, out int channels);
|
||||
|
||||
SurfaceFormat format = SurfaceFormat.Color;
|
||||
if (GameMain.Config.TextureCompressionEnabled && compress)
|
||||
{
|
||||
if (((width & 0x03) == 0) && ((height & 0x03) == 0))
|
||||
{
|
||||
textureData = CompressDxt5(textureData, width, height);
|
||||
format = SurfaceFormat.Dxt5;
|
||||
mipmap = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.NewMessage($"Could not compress a texture because the dimensions are a multiple of 4 (path: {path ?? "null"}, size: {width}x{height})", Color.Orange);
|
||||
}
|
||||
}
|
||||
|
||||
Texture2D tex = null;
|
||||
CrossThread.RequestExecutionOnMainThread(() =>
|
||||
{
|
||||
tex = new Texture2D(_graphicsDevice, width, height, mipmap, SurfaceFormat.Color);
|
||||
tex = new Texture2D(_graphicsDevice, width, height, mipmap, format);
|
||||
tex.SetData(textureData);
|
||||
});
|
||||
return tex;
|
||||
@@ -74,7 +226,8 @@ namespace Barotrauma
|
||||
if (e is SharpDX.SharpDXException) { throw; }
|
||||
#endif
|
||||
|
||||
DebugConsole.ThrowError("Loading texture from stream failed!", e);
|
||||
DebugConsole.ThrowError(string.IsNullOrEmpty(path) ? "Loading texture from stream failed!" :
|
||||
"Loading texture \"" + path + "\" failed!", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user