Sending the ids of the hulls/gaps in between docking ports to make sure they match between clients, small optimizations to hull networkevents
This commit is contained in:
@@ -31,10 +31,12 @@ namespace Barotrauma.Items.Components
|
|||||||
private Joint joint;
|
private Joint joint;
|
||||||
|
|
||||||
private Hull[] hulls;
|
private Hull[] hulls;
|
||||||
|
private ushort?[] hullIds;
|
||||||
|
|
||||||
private Body[] bodies;
|
private Body[] bodies;
|
||||||
|
|
||||||
private Gap gap;
|
private Gap gap;
|
||||||
|
private ushort? gapId;
|
||||||
|
|
||||||
private bool docked;
|
private bool docked;
|
||||||
|
|
||||||
@@ -106,6 +108,8 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
|
||||||
|
hullIds = new ushort?[2];
|
||||||
|
|
||||||
list.Add(this);
|
list.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +290,8 @@ namespace Barotrauma.Items.Components
|
|||||||
hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), hullRects[i], subs[i]);
|
hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "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];
|
||||||
|
|
||||||
//for (int j = 0; j < 2; j++)
|
//for (int j = 0; j < 2; j++)
|
||||||
//{
|
//{
|
||||||
// bodies[i + j * 2] = BodyFactory.CreateEdge(GameMain.World,
|
// bodies[i + j * 2] = BodyFactory.CreateEdge(GameMain.World,
|
||||||
@@ -295,6 +301,7 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
gap.linkedTo.Clear();
|
gap.linkedTo.Clear();
|
||||||
if (hulls[0].WorldRect.Y > hulls[1].WorldRect.Y)
|
if (hulls[0].WorldRect.Y > hulls[1].WorldRect.Y)
|
||||||
@@ -312,8 +319,12 @@ namespace Barotrauma.Items.Components
|
|||||||
item.linkedTo.Add(hulls[0]);
|
item.linkedTo.Add(hulls[0]);
|
||||||
item.linkedTo.Add(hulls[1]);
|
item.linkedTo.Add(hulls[1]);
|
||||||
|
|
||||||
item.linkedTo.Add(gap);
|
hullIds[0] = hulls[0].ID;
|
||||||
|
hullIds[1] = hulls[1].ID;
|
||||||
|
|
||||||
|
gapId = gap.ID;
|
||||||
|
|
||||||
|
item.linkedTo.Add(gap);
|
||||||
|
|
||||||
foreach (Body body in bodies)
|
foreach (Body body in bodies)
|
||||||
{
|
{
|
||||||
@@ -327,10 +338,12 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Undock()
|
public void Undock()
|
||||||
{
|
{
|
||||||
if (dockingTarget == null || !docked) return;
|
if (dockingTarget == null || !docked) return;
|
||||||
|
|
||||||
|
item.NewComponentEvent(this, false, true);
|
||||||
|
|
||||||
PlaySound(ActionType.OnUse, item.WorldPosition);
|
PlaySound(ActionType.OnUse, item.WorldPosition);
|
||||||
|
|
||||||
dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
|
dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
|
||||||
@@ -380,6 +393,11 @@ 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)
|
||||||
@@ -437,6 +455,8 @@ namespace Barotrauma.Items.Components
|
|||||||
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
|
if (!item.linkedTo.Any(e => e is Hull) && !dockingTarget.item.linkedTo.Any(e => e is Hull))
|
||||||
{
|
{
|
||||||
CreateHull();
|
CreateHull();
|
||||||
|
|
||||||
|
item.NewComponentEvent(this, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f);
|
dockingState = MathHelper.Lerp(dockingState, 0.5f, deltaTime * 10.0f);
|
||||||
@@ -491,7 +511,7 @@ namespace Barotrauma.Items.Components
|
|||||||
drawPos,
|
drawPos,
|
||||||
new Rectangle(
|
new Rectangle(
|
||||||
rect.X, rect.Y + rect.Height/2 + (int)(rect.Height / 2 * (1.0f - dockingState)),
|
rect.X, rect.Y + rect.Height/2 + (int)(rect.Height / 2 * (1.0f - dockingState)),
|
||||||
rect.Width, (int)(rect.Height / 2 * dockingState)), Color.Red);
|
rect.Width, (int)(rect.Height / 2 * dockingState)), Color.White);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -555,8 +575,6 @@ namespace Barotrauma.Items.Components
|
|||||||
Docked = signal != "0";
|
Docked = signal != "0";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.NewComponentEvent(this, false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
|
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
|
||||||
@@ -566,6 +584,10 @@ namespace Barotrauma.Items.Components
|
|||||||
if (docked)
|
if (docked)
|
||||||
{
|
{
|
||||||
message.Write(dockingTarget.item.ID);
|
message.Write(dockingTarget.item.ID);
|
||||||
|
message.Write((ushort)hullIds[0]);
|
||||||
|
message.Write((ushort)hullIds[1]);
|
||||||
|
|
||||||
|
message.Write((ushort)gapId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -593,7 +615,13 @@ namespace Barotrauma.Items.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hullIds[0] = message.ReadUInt16();
|
||||||
|
hullIds[1] = message.ReadUInt16();
|
||||||
|
|
||||||
|
gapId = message.ReadUInt16();
|
||||||
|
|
||||||
Dock(dockingTarget);
|
Dock(dockingTarget);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -807,21 +807,24 @@ namespace Barotrauma
|
|||||||
message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6);
|
message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6);
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8);
|
message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8);
|
||||||
|
|
||||||
message.Write((byte)fireSources.Count, 4);
|
message.Write(fireSources.Count > 0);
|
||||||
for (int i = 0; i < Math.Min(fireSources.Count, 16); i++)
|
if (fireSources.Count > 0)
|
||||||
{
|
{
|
||||||
var fireSource = fireSources[i];
|
message.Write((byte)fireSources.Count);
|
||||||
|
for (int i = 0; i < Math.Min(fireSources.Count, 16); i++)
|
||||||
|
{
|
||||||
|
var fireSource = fireSources[i];
|
||||||
|
|
||||||
Vector2 normalizedPos = new Vector2(
|
Vector2 normalizedPos = new Vector2(
|
||||||
(fireSource.Position.X - rect.X) / rect.Width,
|
(fireSource.Position.X - rect.X) / rect.Width,
|
||||||
(fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height);
|
(fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height);
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 4);
|
message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 4);
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 4);
|
message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 4);
|
||||||
|
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 6);
|
message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lastSentVolume = volume;
|
lastSentVolume = volume;
|
||||||
lastSentOxygen = OxygenPercentage;
|
lastSentOxygen = OxygenPercentage;
|
||||||
|
|
||||||
@@ -854,45 +857,52 @@ namespace Barotrauma
|
|||||||
Volume = newVolume;
|
Volume = newVolume;
|
||||||
OxygenPercentage = newOxygen;
|
OxygenPercentage = newOxygen;
|
||||||
|
|
||||||
int fireSourceCount = message.ReadByte(4);
|
bool hasFireSources = message.ReadBoolean();
|
||||||
|
|
||||||
|
|
||||||
List<FireSource> newFireSources = new List<FireSource>();
|
List<FireSource> newFireSources = new List<FireSource>();
|
||||||
for (int i = 0; i < fireSourceCount; i++)
|
if (hasFireSources)
|
||||||
{
|
{
|
||||||
Vector2 pos = Vector2.Zero;
|
int fireSourceCount = message.ReadByte();
|
||||||
float size = 0.0f;
|
for (int i = 0; i < fireSourceCount; i++)
|
||||||
pos.X = message.ReadRangedSingle(0.0f, 1.0f, 4);
|
|
||||||
pos.Y = message.ReadRangedSingle(0.0f, 1.0f, 4);
|
|
||||||
size = message.ReadRangedSingle(0.0f, 1.0f, 6);
|
|
||||||
if (!MathUtils.IsValid(pos)) continue;
|
|
||||||
|
|
||||||
pos.X = MathHelper.Clamp(pos.X, 0.05f, 0.95f);
|
|
||||||
pos.Y = MathHelper.Clamp(pos.Y, 0.05f, 0.95f);
|
|
||||||
|
|
||||||
pos = new Vector2(rect.X + rect.Width * pos.X, rect.Y - rect.Height + (rect.Height * pos.Y));
|
|
||||||
|
|
||||||
var existingFire = fireSources.Find(fs => fs.Contains(pos));
|
|
||||||
if (existingFire!=null)
|
|
||||||
{
|
{
|
||||||
newFireSources.Add(existingFire);
|
Vector2 pos = Vector2.Zero;
|
||||||
existingFire.Position = pos;
|
float size = 0.0f;
|
||||||
existingFire.Size = new Vector2(
|
pos.X = message.ReadRangedSingle(0.0f, 1.0f, 4);
|
||||||
existingFire.Hull == null ? size : size*existingFire.Hull.rect.Width,
|
pos.Y = message.ReadRangedSingle(0.0f, 1.0f, 4);
|
||||||
existingFire.Size.Y);
|
size = message.ReadRangedSingle(0.0f, 1.0f, 6);
|
||||||
}
|
if (!MathUtils.IsValid(pos)) continue;
|
||||||
else
|
|
||||||
{
|
|
||||||
var newFire = new FireSource(pos + Submarine.Position, this, true);
|
|
||||||
newFire.Size = new Vector2(
|
|
||||||
newFire.Hull == null ? size : size * newFire.Hull.rect.Width,
|
|
||||||
newFire.Size.Y);
|
|
||||||
|
|
||||||
//ignore if the fire wasn't added to this room (invalid position)?
|
pos.X = MathHelper.Clamp(pos.X, 0.05f, 0.95f);
|
||||||
if (!fireSources.Contains(newFire)) continue;
|
pos.Y = MathHelper.Clamp(pos.Y, 0.05f, 0.95f);
|
||||||
newFireSources.Add(newFire);
|
|
||||||
|
pos = new Vector2(rect.X + rect.Width * pos.X, rect.Y - rect.Height + (rect.Height * pos.Y));
|
||||||
|
|
||||||
|
var existingFire = fireSources.Find(fs => fs.Contains(pos));
|
||||||
|
if (existingFire!=null)
|
||||||
|
{
|
||||||
|
newFireSources.Add(existingFire);
|
||||||
|
existingFire.Position = pos;
|
||||||
|
existingFire.Size = new Vector2(
|
||||||
|
existingFire.Hull == null ? size : size*existingFire.Hull.rect.Width,
|
||||||
|
existingFire.Size.Y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var newFire = new FireSource(pos + Submarine.Position, this, true);
|
||||||
|
newFire.Size = new Vector2(
|
||||||
|
newFire.Hull == null ? size : size * newFire.Hull.rect.Width,
|
||||||
|
newFire.Size.Y);
|
||||||
|
|
||||||
|
//ignore if the fire wasn't added to this room (invalid position)?
|
||||||
|
if (!fireSources.Contains(newFire)) continue;
|
||||||
|
newFireSources.Add(newFire);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var toBeRemoved = fireSources.FindAll(fs => !newFireSources.Contains(fs));
|
var toBeRemoved = fireSources.FindAll(fs => !newFireSources.Contains(fs));
|
||||||
for (int i = toBeRemoved.Count - 1; i >= 0; i--)
|
for (int i = toBeRemoved.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user