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

This reverts commit 046483b9da.
This commit is contained in:
NotAlwaysTrue
2026-04-30 21:59:54 +08:00
parent 02689d0d86
commit 25683dcf39
85 changed files with 2413 additions and 779 deletions
@@ -2,6 +2,7 @@
using FarseerPhysics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using FarseerPhysics.Dynamics;
@@ -14,9 +15,9 @@ namespace Barotrauma.Items.Components
{
partial class Door : Pickable, IDrawableComponent, IServerSerializable
{
private static readonly HashSet<Door> doorList = new HashSet<Door>();
private static readonly ConcurrentDictionary<Door, byte> _doorDict = new ConcurrentDictionary<Door, byte>();
public static IReadOnlyCollection<Door> DoorList { get { return doorList; } }
public static ICollection<Door> DoorList => _doorDict.Keys;
private Gap linkedGap;
private bool isOpen;
@@ -277,7 +278,7 @@ namespace Barotrauma.Items.Components
}
IsActive = true;
doorList.Add(this);
_doorDict.TryAdd(this, 0);
}
public override void OnItemLoaded()
@@ -313,13 +314,21 @@ namespace Barotrauma.Items.Components
public override void Move(Vector2 amount, bool ignoreContacts = false)
{
if (ignoreContacts)
// Defer physics operation if in parallel context (Farseer is not thread-safe)
if (Body != null)
{
Body?.SetTransformIgnoreContacts(Body.SimPosition + ConvertUnits.ToSimUnits(amount), 0.0f);
}
else
{
Body?.SetTransform(Body.SimPosition + ConvertUnits.ToSimUnits(amount), 0.0f);
var capturedBody = Body;
var capturedNewPos = Body.SimPosition + ConvertUnits.ToSimUnits(amount);
if (ignoreContacts)
{
PhysicsBodyQueue.ExecuteOrDefer(() =>
capturedBody.SetTransformIgnoreContacts(capturedNewPos, 0.0f));
}
else
{
PhysicsBodyQueue.ExecuteOrDefer(() =>
capturedBody.SetTransform(capturedNewPos, 0.0f));
}
}
#if CLIENT
UpdateConvexHulls();
@@ -669,7 +678,7 @@ namespace Barotrauma.Items.Components
convexHull2?.Remove();
#endif
doorList.Remove(this);
_doorDict.TryRemove(this, out _);
}
private bool CheckSubmarinesInDoorWay()
@@ -785,13 +794,19 @@ namespace Barotrauma.Items.Components
//immediately teleport it to the correct side
if (Math.Sign(diff) != dir)
{
// Defer physics operation if in parallel context (Farseer is not thread-safe)
var capturedBody = body;
if (IsHorizontal)
{
body.SetTransformIgnoreContacts(new Vector2(body.SimPosition.X, item.SimPosition.Y + dir * doorRectSimSize.Y * 2.0f), body.Rotation);
Vector2 newPos = new Vector2(body.SimPosition.X, item.SimPosition.Y + dir * doorRectSimSize.Y * 2.0f);
float rotation = body.Rotation;
PhysicsBodyQueue.ExecuteOrDefer(() => capturedBody.SetTransformIgnoreContacts(newPos, rotation));
}
else
{
body.SetTransformIgnoreContacts(new Vector2(item.SimPosition.X + dir * doorRectSimSize.X * 1.2f, body.SimPosition.Y), body.Rotation);
Vector2 newPos = new Vector2(item.SimPosition.X + dir * doorRectSimSize.X * 1.2f, body.SimPosition.Y);
float rotation = body.Rotation;
PhysicsBodyQueue.ExecuteOrDefer(() => capturedBody.SetTransformIgnoreContacts(newPos, rotation));
}
}