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,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace Barotrauma
@@ -11,4 +12,28 @@ namespace Barotrauma
string FilePath { get; }
ContentPackage ContentPackage { get; }
}
public interface IHasUintIdentifier
{
uint UIntIdentifier { get; set; }
}
public static class PrefabExtensions
{
public static void CalculatePrefabUIntIdentifier<T>(this T prefab, PrefabCollection<T> prefabs) where T : class, IPrefab, IHasUintIdentifier, IDisposable
{
using (MD5 md5 = MD5.Create())
{
prefab.UIntIdentifier = ToolBox.StringToUInt32Hash(prefab.Identifier, md5);
//it's theoretically possible for two different values to generate the same hash, but the probability is astronomically small
var collision = prefabs.Find(p => p != prefab && p.UIntIdentifier == prefab.UIntIdentifier);
if (collision != null)
{
DebugConsole.ThrowError($"Hashing collision when generating uint identifiers for {nameof(T)}: {prefab.Identifier} has the same identifier as {collision.Identifier} ({prefab.UIntIdentifier})");
collision.UIntIdentifier++;
}
}
}
}
}