Revert "OBT1.1.0 Merge branch 'dev_pte' into dev"

This reverts commit 177cf89756, reversing
changes made to 42ba733cd4.
This commit is contained in:
Eero
2025-12-29 11:18:11 +08:00
parent 177cf89756
commit 046483b9da
86 changed files with 800 additions and 2496 deletions
@@ -62,7 +62,7 @@ namespace Barotrauma.Networking
DebugConsole.Log($"Changed client {Name}'s team to {teamID}.");
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.IncrementLastClientListUpdateID();
GameMain.NetworkMember.LastClientListUpdateID++;
}
teamID = value;
}
@@ -86,7 +86,7 @@ namespace Barotrauma.Networking
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.IncrementLastClientListUpdateID();
GameMain.NetworkMember.LastClientListUpdateID++;
if (value != null)
{
CharacterID = value.ID;
@@ -154,7 +154,7 @@ namespace Barotrauma.Networking
#endif
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.IncrementLastClientListUpdateID();
GameMain.NetworkMember.LastClientListUpdateID++;
}
}
}
@@ -178,7 +178,7 @@ namespace Barotrauma.Networking
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
{
GameMain.NetworkMember.IncrementLastClientListUpdateID();
GameMain.NetworkMember.LastClientListUpdateID++;
}
inGame = value;
}
@@ -434,7 +434,7 @@ namespace Barotrauma
if (GameMain.NetworkMember is { IsClient: true }) { return; }
while (spawnOrRemoveQueue.Count > 0)
{
if (!spawnOrRemoveQueue.TryDequeue(out var spawnOrRemove)) { break; }
var spawnOrRemove = spawnOrRemoveQueue.Dequeue();
if (spawnOrRemove.TryGet(out Entity entityToRemove))
{
if (entityToRemove is Item item)
@@ -1,6 +1,5 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
@@ -147,10 +146,10 @@ namespace Barotrauma
}
}
private static readonly ConcurrentDictionary<Type, ImmutableArray<CachedReflectedVariable>> CachedVariables = new ConcurrentDictionary<Type, ImmutableArray<CachedReflectedVariable>>();
private static readonly Dictionary<Type, ImmutableArray<CachedReflectedVariable>> CachedVariables = new Dictionary<Type, ImmutableArray<CachedReflectedVariable>>();
private static readonly ConcurrentDictionary<Type, IReadWriteBehavior> TypeBehaviors
= new ConcurrentDictionary<Type, IReadWriteBehavior>(new Dictionary<Type, IReadWriteBehavior>
private static readonly Dictionary<Type, IReadWriteBehavior> TypeBehaviors
= new Dictionary<Type, IReadWriteBehavior>
{
{ typeof(Boolean), new ReadWriteBehavior<Boolean>(ReadBoolean, WriteBoolean) },
{ typeof(Byte), new ReadWriteBehavior<Byte>(ReadByte, WriteByte) },
@@ -169,7 +168,7 @@ namespace Barotrauma
{ typeof(Vector2), new ReadWriteBehavior<Vector2>(ReadVector2, WriteVector2) },
{ typeof(SerializableDateTime), new ReadWriteBehavior<SerializableDateTime>(ReadSerializableDateTime, WriteSerializableDateTime) },
{ typeof(NetLimitedString), new ReadWriteBehavior<NetLimitedString>(ReadNetLString, WriteNetLString) }
});
};
private static readonly ImmutableDictionary<Predicate<Type>, Func<Type, IReadWriteBehavior>> BehaviorFactories = new Dictionary<Predicate<Type>, Func<Type, IReadWriteBehavior>>
{
@@ -585,11 +584,7 @@ namespace Barotrauma
if (!predicate(type)) { continue; }
behavior = factory(type);
// Use TryAdd for thread-safety; if another thread already added, use that value
if (!TypeBehaviors.TryAdd(type, behavior))
{
behavior = TypeBehaviors[type];
}
TypeBehaviors.Add(type, behavior);
return true;
}
@@ -599,11 +594,8 @@ namespace Barotrauma
public static ImmutableArray<CachedReflectedVariable> GetPropertiesAndFields(Type type)
{
return CachedVariables.GetOrAdd(type, static t => CreateCachedVariables(t));
}
if (CachedVariables.TryGetValue(type, out var cached)) { return cached; }
private static ImmutableArray<CachedReflectedVariable> CreateCachedVariables(Type type)
{
List<CachedReflectedVariable> variables = new List<CachedReflectedVariable>();
IEnumerable<PropertyInfo> propertyInfos = type.GetProperties().Where(HasAttribute).Where(NotStatic);
@@ -641,6 +633,7 @@ namespace Barotrauma
}
ImmutableArray<CachedReflectedVariable> array = variables.All(v => v.HasOwnAttribute) ? variables.OrderBy(v => v.Attribute.OrderKey).ToImmutableArray() : variables.ToImmutableArray();
CachedVariables.Add(type, array);
return array;
bool HasAttribute(MemberInfo info) => (info.GetCustomAttribute<NetworkSerialize>() ?? type.GetCustomAttribute<NetworkSerialize>()) != null;
@@ -881,4 +874,4 @@ namespace Barotrauma
}
}
}
}
}
@@ -1,7 +1,6 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Threading;
namespace Barotrauma.Networking
{
@@ -187,19 +186,10 @@ namespace Barotrauma.Networking
{
protected const int MaxSubNameLengthInErrorMessages = 16;
private int lastClientListUpdateID;
public UInt16 LastClientListUpdateID
{
get => (UInt16)Interlocked.CompareExchange(ref lastClientListUpdateID, 0, 0);
set => Interlocked.Exchange(ref lastClientListUpdateID, value);
}
/// <summary>
/// Thread-safe increment of LastClientListUpdateID
/// </summary>
public void IncrementLastClientListUpdateID()
{
Interlocked.Increment(ref lastClientListUpdateID);
get;
set;
}
public abstract bool IsServer { get; }