Fixed another bug in DockingPort that caused entity ID mismatches. Even though the server sent the IDs of the CURRENT hulls and gap of the docking port, they are not necessarily created in the correct order during midround syncing and may end up replacing the ID of another entity or another entity spawned after them may cause their IDs to be replaced. Closes #530
This commit is contained in:
@@ -28,17 +28,13 @@ namespace Barotrauma.Items.Components
|
|||||||
private Joint joint;
|
private Joint joint;
|
||||||
|
|
||||||
private readonly Hull[] hulls = new Hull[2];
|
private readonly Hull[] hulls = new Hull[2];
|
||||||
private ushort?[] hullIds;
|
private Gap gap;
|
||||||
|
|
||||||
private Door door;
|
private Door door;
|
||||||
|
|
||||||
private Body[] bodies;
|
private Body[] bodies;
|
||||||
|
|
||||||
private Body doorBody;
|
private Body doorBody;
|
||||||
|
|
||||||
private Gap gap;
|
|
||||||
private ushort? gapId;
|
|
||||||
|
|
||||||
private bool docked;
|
private bool docked;
|
||||||
|
|
||||||
public int DockingDir
|
public int DockingDir
|
||||||
@@ -115,8 +111,6 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
|
||||||
hullIds = new ushort?[2];
|
|
||||||
|
|
||||||
list.Add(this);
|
list.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,7 +401,7 @@ namespace Barotrauma.Items.Components
|
|||||||
hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition));
|
hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition));
|
||||||
hulls[i] = new Hull(MapEntityPrefab.Find("Hull"), hullRects[i], subs[i]);
|
hulls[i] = new Hull(MapEntityPrefab.Find("Hull"), hullRects[i], subs[i]);
|
||||||
hulls[i].AddToGrid(subs[i]);
|
hulls[i].AddToGrid(subs[i]);
|
||||||
if (hullIds[i] != null) hulls[i].ID = (ushort)hullIds[i];
|
hulls[i].FreeID();
|
||||||
|
|
||||||
for (int j = 0; j < 2; j++)
|
for (int j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
@@ -418,7 +412,6 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
gap = new Gap(new Rectangle(hullRects[0].Right - 2, hullRects[0].Y, 4, hullRects[0].Height), true, subs[0]);
|
gap = new Gap(new Rectangle(hullRects[0].Right - 2, hullRects[0].Y, 4, hullRects[0].Height), true, subs[0]);
|
||||||
if (gapId != null) gap.ID = (ushort)gapId;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -436,25 +429,22 @@ namespace Barotrauma.Items.Components
|
|||||||
hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition));
|
hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition));
|
||||||
hulls[i] = new Hull(MapEntityPrefab.Find("Hull"), hullRects[i], subs[i]);
|
hulls[i] = new Hull(MapEntityPrefab.Find("Hull"), hullRects[i], subs[i]);
|
||||||
hulls[i].AddToGrid(subs[i]);
|
hulls[i].AddToGrid(subs[i]);
|
||||||
if (hullIds[i] != null) hulls[i].ID = (ushort)hullIds[i];
|
hulls[i].FreeID();
|
||||||
}
|
}
|
||||||
|
|
||||||
gap = new Gap(new Rectangle(hullRects[0].X, hullRects[0].Y+2, hullRects[0].Width, 4), false, subs[0]);
|
gap = new Gap(new Rectangle(hullRects[0].X, hullRects[0].Y+2, hullRects[0].Width, 4), false, subs[0]);
|
||||||
if (gapId != null) gap.ID = (ushort)gapId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkHullsToGap();
|
LinkHullsToGap();
|
||||||
|
|
||||||
hullIds[0] = hulls[0].ID;
|
|
||||||
hullIds[1] = hulls[1].ID;
|
|
||||||
hulls[0].ShouldBeSaved = false;
|
hulls[0].ShouldBeSaved = false;
|
||||||
hulls[1].ShouldBeSaved = false;
|
hulls[1].ShouldBeSaved = false;
|
||||||
item.linkedTo.Add(hulls[0]);
|
item.linkedTo.Add(hulls[0]);
|
||||||
item.linkedTo.Add(hulls[1]);
|
item.linkedTo.Add(hulls[1]);
|
||||||
|
|
||||||
|
gap.FreeID();
|
||||||
gap.DisableHullRechecks = true;
|
gap.DisableHullRechecks = true;
|
||||||
gap.ShouldBeSaved = false;
|
gap.ShouldBeSaved = false;
|
||||||
gapId = gap.ID;
|
|
||||||
item.linkedTo.Add(gap);
|
item.linkedTo.Add(gap);
|
||||||
|
|
||||||
foreach (Body body in bodies)
|
foreach (Body body in bodies)
|
||||||
@@ -570,10 +560,6 @@ namespace Barotrauma.Items.Components
|
|||||||
gap = null;
|
gap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
hullIds[0] = null;
|
|
||||||
hullIds[1] = null;
|
|
||||||
gapId = null;
|
|
||||||
|
|
||||||
if (bodies != null)
|
if (bodies != null)
|
||||||
{
|
{
|
||||||
foreach (Body body in bodies)
|
foreach (Body body in bodies)
|
||||||
@@ -636,6 +622,9 @@ namespace Barotrauma.Items.Components
|
|||||||
protected override void RemoveComponentSpecific()
|
protected override void RemoveComponentSpecific()
|
||||||
{
|
{
|
||||||
list.Remove(this);
|
list.Remove(this);
|
||||||
|
hulls[0]?.Remove(); hulls[0] = null;
|
||||||
|
hulls[1]?.Remove(); hulls[1] = null;
|
||||||
|
gap?.Remove(); gap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnMapLoaded()
|
public override void OnMapLoaded()
|
||||||
@@ -725,18 +714,7 @@ namespace Barotrauma.Items.Components
|
|||||||
if (docked)
|
if (docked)
|
||||||
{
|
{
|
||||||
msg.Write(dockingTarget.item.ID);
|
msg.Write(dockingTarget.item.ID);
|
||||||
|
msg.Write(hulls != null && hulls[0] != null && hulls[1] != null && gap != null);
|
||||||
if (hulls != null && hulls[0] != null && hulls[1] != null && gap != null)
|
|
||||||
{
|
|
||||||
msg.Write(true);
|
|
||||||
msg.Write(hulls[0].ID);
|
|
||||||
msg.Write(hulls[1].ID);
|
|
||||||
msg.Write(gap.ID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.Write(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,13 +743,6 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
bool isLocked = msg.ReadBoolean();
|
bool isLocked = msg.ReadBoolean();
|
||||||
|
|
||||||
if (isLocked)
|
|
||||||
{
|
|
||||||
hullIds[0] = msg.ReadUInt16();
|
|
||||||
hullIds[1] = msg.ReadUInt16();
|
|
||||||
gapId = msg.ReadUInt16();
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity targetEntity = Entity.FindEntityByID(dockingTargetID);
|
Entity targetEntity = Entity.FindEntityByID(dockingTargetID);
|
||||||
if (targetEntity == null || !(targetEntity is Item))
|
if (targetEntity == null || !(targetEntity is Item))
|
||||||
{
|
{
|
||||||
@@ -791,10 +762,6 @@ namespace Barotrauma.Items.Components
|
|||||||
if (isLocked)
|
if (isLocked)
|
||||||
{
|
{
|
||||||
Lock(true);
|
Lock(true);
|
||||||
|
|
||||||
hulls[0].ID = (ushort)hullIds[0];
|
|
||||||
hulls[1].ID = (ushort)hullIds[1];
|
|
||||||
gap.ID = (ushort)gapId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ namespace Barotrauma
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IdFreed
|
||||||
|
{
|
||||||
|
get { return idFreed; }
|
||||||
|
}
|
||||||
|
|
||||||
public ushort ID
|
public ushort ID
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -230,7 +235,6 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
dictionary.Remove(ID);
|
dictionary.Remove(ID);
|
||||||
id = 0;
|
|
||||||
idFreed = true;
|
idFreed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ namespace Barotrauma
|
|||||||
if (Math.Abs(lastSentVolume - waterVolume) > Volume * 0.1f ||
|
if (Math.Abs(lastSentVolume - waterVolume) > Volume * 0.1f ||
|
||||||
Math.Abs(lastSentOxygen - OxygenPercentage) > 5f)
|
Math.Abs(lastSentOxygen - OxygenPercentage) > 5f)
|
||||||
{
|
{
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null && !IdFreed)
|
||||||
{
|
{
|
||||||
sendUpdateTimer -= deltaTime;
|
sendUpdateTimer -= deltaTime;
|
||||||
if (sendUpdateTimer < 0.0f)
|
if (sendUpdateTimer < 0.0f)
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
//the ID has been taken by another entity (the original entity has been removed) -> write an empty event
|
//the ID has been taken by another entity (the original entity has been removed) -> write an empty event
|
||||||
if (Entity.FindEntityByID(e.Entity.ID) != e.Entity)
|
else if (Entity.FindEntityByID(e.Entity.ID) != e.Entity || e.Entity.IdFreed)
|
||||||
{
|
{
|
||||||
//technically the clients don't have any use for these, but removing events and shifting the IDs of all
|
//technically the clients don't have any use for these, but removing events and shifting the IDs of all
|
||||||
//consecutive ones is so error-prone that I think this is a safer option
|
//consecutive ones is so error-prone that I think this is a safer option
|
||||||
|
|||||||
Reference in New Issue
Block a user