Unstable v0.1300.0.0 (February 19th 2021)

This commit is contained in:
Joonas Rikkonen
2021-02-25 13:44:23 +02:00
parent b772654326
commit 24cbef485a
441 changed files with 21343 additions and 8562 deletions
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
@@ -11,13 +12,13 @@ namespace Barotrauma
private int maxId;
private List<Point> srcRanges;
private int destOffset;
private readonly List<Point> srcRanges;
private readonly int destOffset;
public IdRemap(XElement parentElement, int offset)
{
destOffset = offset;
if (parentElement != null)
if (parentElement != null && parentElement.HasElements)
{
srcRanges = new List<Point>();
foreach (XElement subElement in parentElement.Elements())
@@ -25,7 +26,7 @@ namespace Barotrauma
int id = subElement.GetAttributeInt("ID", -1);
if (id > 0) { InsertId(id); }
}
maxId = GetOffsetId(srcRanges.Last().Y + 1);
maxId = GetOffsetId(srcRanges.Last().Y) + 1;
}
else
{
@@ -41,7 +42,7 @@ namespace Barotrauma
private void InsertId(int id)
{
for (int i=0;i<srcRanges.Count;i++)
for (int i = 0; i < srcRanges.Count; i++)
{
if (srcRanges[i].X > id)
{
@@ -65,10 +66,10 @@ namespace Barotrauma
if (srcRanges[i].Y == (id - 1))
{
srcRanges[i] = new Point(srcRanges[i].X, id);
if (i < (srcRanges.Count-1) && srcRanges[i].Y == srcRanges[i + 1].X)
if (i < (srcRanges.Count - 1) && srcRanges[i].Y == srcRanges[i + 1].X)
{
srcRanges[i] = new Point(srcRanges[i].X, srcRanges[i + 1].Y);
srcRanges.RemoveAt(i+1);
srcRanges.RemoveAt(i + 1);
}
return;
}
@@ -89,9 +90,9 @@ namespace Barotrauma
if (srcRanges == null) { return (ushort)(id + destOffset); }
int currOffset = destOffset;
for (int i=0;i<srcRanges.Count;i++)
for (int i = 0; i < srcRanges.Count; i++)
{
if (id >= srcRanges[i].X && (id <= srcRanges[i].Y || (i == srcRanges.Count-1)))
if (id >= srcRanges[i].X && id <= srcRanges[i].Y)
{
return (ushort)(id - srcRanges[i].X + 1 + currOffset);
}
@@ -99,5 +100,16 @@ namespace Barotrauma
}
return 0;
}
public static ushort DetermineNewOffset()
{
ushort idOffset = 0;
foreach (Entity e in Entity.GetEntities())
{
if (e.ID > Entity.ReservedIDStart || e is Submarine) { continue; }
idOffset = Math.Max(idOffset, e.ID);
}
return idOffset;
}
}
}
@@ -678,27 +678,11 @@ namespace Barotrauma
public static List<Vector2[]> TriangulateConvexHull(List<Vector2> vertices, Vector2 center)
{
List<Vector2[]> triangles = new List<Vector2[]>();
int triangleCount = vertices.Count - 2;
vertices.Sort(new CompareCCW(center));
int lastIndex = 1;
for (int i = 0; i < triangleCount; i++)
for (int i = 0; i < vertices.Count; i++)
{
Vector2[] triangleVertices = new Vector2[3];
triangleVertices[0] = vertices[0];
int k = 1;
for (int j = lastIndex; j <= lastIndex + 1; j++)
{
triangleVertices[k] = vertices[j];
k++;
}
lastIndex += 1;
triangles.Add(triangleVertices);
triangles.Add(new Vector2[3] { center, vertices[i], vertices[(i + 1) % vertices.Count] });
}
return triangles;
}
@@ -739,7 +723,7 @@ namespace Barotrauma
return wrappedPoints;
}
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int iterations, float offsetAmount)
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int iterations, float offsetAmount, Rectangle? bounds = null)
{
List<Vector2[]> segments = new List<Vector2[]>
{
@@ -761,6 +745,26 @@ namespace Barotrauma
normal = new Vector2(-normal.Y, normal.X);
midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, Rand.RandSync.Server);
if (bounds.HasValue)
{
if (midPoint.X < bounds.Value.X)
{
midPoint.X = bounds.Value.X + (bounds.Value.X - midPoint.X);
}
else if (midPoint.X > bounds.Value.Right)
{
midPoint.X = bounds.Value.Right - (midPoint.X - bounds.Value.Right);
}
if (midPoint.Y < bounds.Value.Y)
{
midPoint.Y = bounds.Value.Y + (bounds.Value.Y - midPoint.Y);
}
else if (midPoint.Y > bounds.Value.Bottom)
{
midPoint.Y = bounds.Value.Bottom - (midPoint.Y - bounds.Value.Bottom);
}
}
segments.Insert(i, new Vector2[] { startSegment, midPoint });
segments.Insert(i + 1, new Vector2[] { midPoint, endSegment });
@@ -916,6 +920,8 @@ namespace Barotrauma
return (float)Math.Pow(f, p);
}
public static float Pow2(float f) => f * f;
/// <summary>
/// Converts the alignment to a vector where -1,-1 is the top-left corner, 0,0 the center and 1,1 bottom-right
/// </summary>
@@ -946,12 +952,10 @@ namespace Barotrauma
/// Modified from:
/// http://www.gamefromscratch.com/post/2012/11/24/GameDev-math-recipes-Rotating-one-point-around-another-point.aspx
/// </summary>
public static Vector2 RotatePointAroundTarget(Vector2 point, Vector2 target, float degrees, bool clockWise = true)
public static Vector2 RotatePointAroundTarget(Vector2 point, Vector2 target, float radians, bool clockWise = true)
{
// (Math.PI / 180) * degrees
var angle = MathHelper.ToRadians(degrees);
var sin = Math.Sin(angle);
var cos = Math.Cos(angle);
var sin = Math.Sin(radians);
var cos = Math.Cos(radians);
if (!clockWise)
{
sin = -sin;
@@ -33,7 +33,7 @@ namespace Barotrauma
int prevIndex = 0;
int currIndex = 0;
for (int i=0;i<segments.Length;i++)
for (int i = 0; i < segments.Length; i++)
{
if (i % 2 == 0)
{
@@ -44,7 +44,7 @@ namespace Barotrauma
else
{
string[] attributes = segments[i].Split(attributeSeparator);
for (int j=0;j<attributes.Length;j++)
for (int j = 0; j < attributes.Length; j++)
{
if (attributes[j].Contains(endDefinition))
{
@@ -482,6 +482,13 @@ namespace Barotrauma
}
}
}
public static void DeleteDownloadedSubs()
{
if (Directory.Exists(SubmarineDownloadFolder))
{
ClearFolder(SubmarineDownloadFolder);
}
}
public static void CleanUnnecessarySaveFiles()
{
@@ -97,7 +97,7 @@ namespace Barotrauma
return !corrected;
}
public static string CorrectFilenameCase(string filename, out bool corrected)
public static string CorrectFilenameCase(string filename, out bool corrected, string directory = "")
{
char[] delimiters = { '/', '\\' };
string[] subDirs = filename.Split(delimiters);
@@ -117,21 +117,32 @@ namespace Barotrauma
return originalFilename; //assume that rooted paths have correct case since these are generated by the game
}
string startPath = directory ?? "";
for (int i = 0; i < subDirs.Length; i++)
{
if (i == subDirs.Length - 1 && string.IsNullOrEmpty(subDirs[i]))
{
break;
}
string enumPath = string.IsNullOrEmpty(filename) ? "./" : filename;
List<string> filePaths = Directory.GetFileSystemEntries(enumPath).Select(s => Path.GetFileName(s)).ToList();
if (filePaths.Any(s => s.Equals(subDirs[i], StringComparison.Ordinal)))
string subDir = subDirs[i].TrimEnd();
string enumPath = Path.Combine(startPath, filename);
if (string.IsNullOrWhiteSpace(filename))
{
filename += subDirs[i];
enumPath = string.IsNullOrWhiteSpace(startPath) ? "./" : startPath;
}
List<string> filePaths = Directory.GetFileSystemEntries(enumPath).Select(Path.GetFileName).ToList();
if (filePaths.Any(s => s.Equals(subDir, StringComparison.Ordinal)))
{
filename += subDir;
}
else
{
IEnumerable<string> correctedPaths = filePaths.Where(s => s.Equals(subDirs[i], StringComparison.OrdinalIgnoreCase));
List<string> correctedPaths = filePaths.Where(s => s.Equals(subDir, StringComparison.OrdinalIgnoreCase)).ToList();
if (correctedPaths.Any())
{
corrected = true;
@@ -152,7 +163,7 @@ namespace Barotrauma
public static string RemoveInvalidFileNameChars(string fileName)
{
var invalidChars = Path.GetInvalidFileNameChars().Concat(new char[] {':', ';'});
var invalidChars = Path.GetInvalidFileNameChars().Concat(new char[] {':', ';', '<', '>', '"', '/', '\\', '|', '?', '*'});
foreach (char invalidChar in invalidChars)
{
fileName = fileName.Replace(invalidChar.ToString(), "");
@@ -438,6 +449,7 @@ namespace Barotrauma
return key;
}
/// <summary>
/// Returns a new instance of the class with all properties and fields copied.
/// </summary>
@@ -572,7 +584,7 @@ namespace Barotrauma
Process.Start(startInfo);
}
public static string CleanUpPathCrossPlatform(this string path, bool correctFilenameCase = true)
public static string CleanUpPathCrossPlatform(this string path, bool correctFilenameCase = true, string directory = "")
{
if (string.IsNullOrEmpty(path)) { return ""; }
@@ -584,7 +596,7 @@ namespace Barotrauma
if (correctFilenameCase)
{
string correctedPath = CorrectFilenameCase(path, out _);
string correctedPath = CorrectFilenameCase(path, out _, directory);
if (!string.IsNullOrEmpty(correctedPath)) { path = correctedPath; }
}