Merged branch new-netcode into new-netcode
This commit is contained in:
@@ -652,5 +652,62 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(docked);
|
||||||
|
|
||||||
|
if (docked)
|
||||||
|
{
|
||||||
|
msg.Write(dockingTarget.item.ID);
|
||||||
|
|
||||||
|
msg.Write((ushort)hullIds[0]);
|
||||||
|
msg.Write((ushort)hullIds[1]);
|
||||||
|
msg.Write((ushort)gapId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
bool isDocked = msg.ReadBoolean();
|
||||||
|
|
||||||
|
if (isDocked)
|
||||||
|
{
|
||||||
|
ushort dockingTargetID = msg.ReadUInt16();
|
||||||
|
|
||||||
|
hullIds[0] = msg.ReadUInt16();
|
||||||
|
hullIds[1] = msg.ReadUInt16();
|
||||||
|
gapId = msg.ReadUInt16();
|
||||||
|
|
||||||
|
Entity targetEntity = Entity.FindEntityByID(dockingTargetID);
|
||||||
|
if (targetEntity == null || !(targetEntity is Item))
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Invalid docking port network event (can't dock to " + targetEntity.ToString() + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dockingTarget = (targetEntity as Item).GetComponent<DockingPort>();
|
||||||
|
if (dockingTarget == null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Invalid docking port network event (" + targetEntity + " doesn't have a docking port component)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hulls != null)
|
||||||
|
{
|
||||||
|
if (hulls[0] != null) hulls[0].ID = (ushort)hullIds[0];
|
||||||
|
if (hulls[1] != null) hulls[1].ID = (ushort)hullIds[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gap != null) gap.ID = (ushort)gapId;
|
||||||
|
|
||||||
|
Dock(dockingTarget);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Undock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -477,5 +477,17 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(isOpen);
|
||||||
|
msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
SetState(msg.ReadBoolean(), true);
|
||||||
|
Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,5 +195,31 @@ namespace Barotrauma.Items.Components
|
|||||||
if (!IsActive) currPowerConsumption = 0.0f;
|
if (!IsActive) currPowerConsumption = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClientWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
//flowpercentage can only be adjusted at 10% intervals -> no need for more accuracy than this
|
||||||
|
msg.WriteRangedInteger(-10, 10, (int)(flowPercentage / 10.0f));
|
||||||
|
msg.Write(IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
|
||||||
|
IsActive = msg.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
//flowpercentage can only be adjusted at 10% intervals -> no need for more accuracy than this
|
||||||
|
msg.WriteRangedInteger(-10, 10, (int)(flowPercentage / 10.0f));
|
||||||
|
msg.Write(IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
|
||||||
|
IsActive = msg.ReadBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,9 +403,29 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
if (pingCircle!=null) pingCircle.Remove();
|
if (pingCircle!=null) pingCircle.Remove();
|
||||||
if (screenOverlay != null) screenOverlay.Remove();
|
if (screenOverlay != null) screenOverlay.Remove();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClientWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
IsActive = msg.ReadBoolean();
|
||||||
|
isActiveTickBox.Selected = IsActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(IsActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
IsActive = msg.ReadBoolean();
|
||||||
|
isActiveTickBox.Selected = IsActive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RadarBlip
|
class RadarBlip
|
||||||
|
|||||||
@@ -536,5 +536,45 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClientWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(autoTemp);
|
||||||
|
msg.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 8);
|
||||||
|
|
||||||
|
msg.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8);
|
||||||
|
msg.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
autoTemp = msg.ReadBoolean();
|
||||||
|
ShutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 8);
|
||||||
|
|
||||||
|
CoolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
FissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.WriteRangedSingle(temperature, 0.0f, 10000.0f, 16);
|
||||||
|
|
||||||
|
msg.Write(autoTemp);
|
||||||
|
msg.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 8);
|
||||||
|
|
||||||
|
msg.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8);
|
||||||
|
msg.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
Temperature = msg.ReadRangedSingle(0.0f, 10000.0f, 16);
|
||||||
|
|
||||||
|
autoTemp = msg.ReadBoolean();
|
||||||
|
ShutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 8);
|
||||||
|
|
||||||
|
CoolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
FissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,8 +291,6 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
TargetVelocity = targetSpeed/5.0f;
|
TargetVelocity = targetSpeed/5.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ToggleMaintainPosition(GUITickBox tickBox)
|
private bool ToggleMaintainPosition(GUITickBox tickBox)
|
||||||
@@ -330,5 +328,89 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClientWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(autoPilot);
|
||||||
|
|
||||||
|
if (!autoPilot)
|
||||||
|
{
|
||||||
|
//no need to write steering info if autopilot is controlling
|
||||||
|
msg.Write(targetVelocity.X);
|
||||||
|
msg.Write(targetVelocity.Y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.Write(posToMaintain != null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
AutoPilot = msg.ReadBoolean();
|
||||||
|
|
||||||
|
if (!AutoPilot)
|
||||||
|
{
|
||||||
|
targetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool maintainPos = msg.ReadBoolean();
|
||||||
|
if (posToMaintain == null && maintainPos)
|
||||||
|
{
|
||||||
|
posToMaintain = item.Submarine.WorldPosition;
|
||||||
|
maintainPosTickBox.Selected = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
posToMaintain = null;
|
||||||
|
maintainPosTickBox.Selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(autoPilot);
|
||||||
|
|
||||||
|
if (!autoPilot)
|
||||||
|
{
|
||||||
|
//no need to write steering info if autopilot is controlling
|
||||||
|
msg.Write(targetVelocity.X);
|
||||||
|
msg.Write(targetVelocity.Y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.Write(posToMaintain != null);
|
||||||
|
if (posToMaintain != null)
|
||||||
|
{
|
||||||
|
msg.Write(((Vector2)posToMaintain).X);
|
||||||
|
msg.Write(((Vector2)posToMaintain).Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
AutoPilot = msg.ReadBoolean();
|
||||||
|
|
||||||
|
if (!AutoPilot)
|
||||||
|
{
|
||||||
|
targetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool maintainPos = msg.ReadBoolean();
|
||||||
|
if (maintainPos)
|
||||||
|
{
|
||||||
|
posToMaintain = new Vector2(msg.ReadSingle(), msg.ReadSingle());
|
||||||
|
maintainPosTickBox.Selected = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
posToMaintain = null;
|
||||||
|
maintainPosTickBox.Selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
{
|
{
|
||||||
float chargeRate = (float)(Math.Sqrt(charge / capacity));
|
float chargeRatio = (float)(Math.Sqrt(charge / capacity));
|
||||||
float gridPower = 0.0f;
|
float gridPower = 0.0f;
|
||||||
float gridLoad = 0.0f;
|
float gridLoad = 0.0f;
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
//float gridRate = voltage;
|
//float gridRate = voltage;
|
||||||
|
|
||||||
if (chargeRate > 0.0f)
|
if (chargeRatio > 0.0f)
|
||||||
{
|
{
|
||||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
CurrPowerOutput = MathHelper.Lerp(
|
CurrPowerOutput = MathHelper.Lerp(
|
||||||
CurrPowerOutput,
|
CurrPowerOutput,
|
||||||
Math.Min(maxOutput * chargeRate, gridLoad - (gridLoad * outputVoltage)),
|
Math.Min(maxOutput * chargeRatio, gridLoad - (gridLoad * outputVoltage)),
|
||||||
0.05f);
|
0.05f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -246,5 +246,31 @@ namespace Barotrauma.Items.Components
|
|||||||
spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", new Vector2(x + 30, y + 95), Color.White);
|
spriteBatch.DrawString(GUI.Font, "Recharge rate: " + (int)((rechargeSpeed / maxRechargeSpeed) * 100.0f) + " %", new Vector2(x + 30, y + 95), Color.White);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClientWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
float chargeSpeed = MathHelper.Clamp(rechargeSpeed / MaxRechargeSpeed, 0.0f, 1.0f);
|
||||||
|
msg.WriteRangedSingle(chargeSpeed, 0.0f, 1.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
RechargeSpeed = msg.ReadRangedSingle(0.0f, 1.0f, 8) * maxRechargeSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
float chargeSpeed = MathHelper.Clamp(rechargeSpeed / MaxRechargeSpeed, 0.0f, 1.0f);
|
||||||
|
msg.WriteRangedSingle(chargeSpeed, 0.0f, 1.0f, 8);
|
||||||
|
|
||||||
|
float chargeRatio = MathHelper.Clamp(charge / capacity, 0.0f, 1.0f);
|
||||||
|
msg.WriteRangedSingle(chargeRatio, 0.0f, 1.0f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ClientRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
RechargeSpeed = msg.ReadRangedSingle(0.0f, 1.0f, 8) * maxRechargeSpeed;
|
||||||
|
|
||||||
|
Charge = msg.ReadRangedSingle(0.0f, 1.0f, 8) * capacity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -526,5 +526,29 @@ namespace Barotrauma.Items.Components
|
|||||||
base.RemoveComponentSpecific();
|
base.RemoveComponentSpecific();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ClientWrite(Lidgren.Network.NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write((byte)Math.Min(Nodes.Count, 255));
|
||||||
|
for (int i = 0; i < Math.Min(Nodes.Count, 255); i++)
|
||||||
|
{
|
||||||
|
msg.Write(Nodes[i].X);
|
||||||
|
msg.Write(Nodes[i].Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ServerRead(Lidgren.Network.NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
Nodes.Clear();
|
||||||
|
|
||||||
|
int nodeCount = msg.ReadByte();
|
||||||
|
for (int i = 0; i < nodeCount; i++)
|
||||||
|
{
|
||||||
|
Vector2 newNode = new Vector2(msg.ReadFloat(), msg.ReadFloat());
|
||||||
|
if (MathUtils.IsValid(newNode)) Nodes.Add(newNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawable = Nodes.Any();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using FarseerPhysics;
|
using Barotrauma.Networking;
|
||||||
|
using FarseerPhysics;
|
||||||
using FarseerPhysics.Common;
|
using FarseerPhysics.Common;
|
||||||
using FarseerPhysics.Dynamics;
|
using FarseerPhysics.Dynamics;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
@@ -28,7 +29,7 @@ namespace Barotrauma
|
|||||||
HideInMenus = 2
|
HideInMenus = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
class Submarine : Entity
|
class Submarine : Entity, IServerSerializable
|
||||||
{
|
{
|
||||||
|
|
||||||
public static string SavePath = "Submarines";
|
public static string SavePath = "Submarines";
|
||||||
@@ -122,6 +123,15 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ushort netStateID;
|
||||||
|
public ushort NetStateID
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return netStateID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Submarine> Loaded
|
public static List<Submarine> Loaded
|
||||||
{
|
{
|
||||||
get { return loaded; }
|
get { return loaded; }
|
||||||
@@ -951,6 +961,21 @@ namespace Barotrauma
|
|||||||
|
|
||||||
DockedTo.Clear();
|
DockedTo.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ServerWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
msg.Write(subBody.Position.X);
|
||||||
|
msg.Write(subBody.Position.Y);
|
||||||
|
|
||||||
|
msg.Write(Velocity.X);
|
||||||
|
msg.Write(Velocity.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClientRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
subBody.TargetPosition = new Vector2(msg.ReadSingle(), msg.ReadSingle());
|
||||||
|
subBody.Velocity = new Vector2(msg.ReadSingle(), msg.ReadSingle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private Vector2? targetPosition;
|
private Vector2? targetPosition;
|
||||||
|
|
||||||
//private float mass = 10000.0f;
|
|
||||||
|
|
||||||
public Rectangle Borders
|
public Rectangle Borders
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|||||||
Reference in New Issue
Block a user