NetworkEvent optimization (more frequent use of WriteRangedSingle)
This commit is contained in:
BIN
.vs/Subsurface_Solution/v14/.suo
Normal file
BIN
.vs/Subsurface_Solution/v14/.suo
Normal file
Binary file not shown.
BIN
Report20151010-1429.vspx
Normal file
BIN
Report20151010-1429.vspx
Normal file
Binary file not shown.
BIN
Report20151010-1451.vspx
Normal file
BIN
Report20151010-1451.vspx
Normal file
Binary file not shown.
@@ -518,8 +518,8 @@ namespace Barotrauma
|
||||
|
||||
if (wallAttack)
|
||||
{
|
||||
message.Write(wallAttackPos.X);
|
||||
message.Write(wallAttackPos.Y);
|
||||
message.WriteRangedSingle(wallAttackPos.X, -50.0f, 50.0f, 10);
|
||||
message.WriteRangedSingle(wallAttackPos.Y, -50.0f, 50.0f, 10);
|
||||
}
|
||||
|
||||
//message.Write(Velocity.X);
|
||||
@@ -559,7 +559,9 @@ namespace Barotrauma
|
||||
|
||||
if (wallAttack)
|
||||
{
|
||||
newWallAttackPos = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
newWallAttackPos = new Vector2(
|
||||
message.ReadRangedSingle(-50.0f, 50.0f, 10),
|
||||
message.ReadRangedSingle(-50.0f, 50.0f, 10));
|
||||
}
|
||||
|
||||
//newVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
|
||||
@@ -95,8 +95,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (limb.ignoreCollisions) continue;
|
||||
|
||||
message.Write(limb.body.SimPosition.X);
|
||||
message.Write(limb.body.SimPosition.Y);
|
||||
if (limb.SimPosition.Length() > NetConfig.AllowedRagdollDistance) return false;
|
||||
|
||||
message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16);
|
||||
message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16);
|
||||
|
||||
|
||||
message.Write(limb.body.Rotation);
|
||||
i++;
|
||||
@@ -111,14 +114,14 @@ namespace Barotrauma
|
||||
message.Write((float)NetTime.Now);
|
||||
|
||||
message.Write(AnimController.TargetDir == Direction.Right);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 16);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -10.0f, 10.0f), -10.0f, 10.0f, 16);
|
||||
message.WriteRangedSingle(AnimController.TargetMovement.X, -1.0f, 1.0f, 8);
|
||||
message.WriteRangedSingle(AnimController.TargetMovement.Y, -1.0f, 1.0f, 8);
|
||||
|
||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16);
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16);
|
||||
|
||||
message.Write(AnimController.RefLimb.LinearVelocity.X);
|
||||
message.Write(AnimController.RefLimb.LinearVelocity.Y);
|
||||
//message.Write(AnimController.RefLimb.LinearVelocity.X);
|
||||
//message.Write(AnimController.RefLimb.LinearVelocity.Y);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -144,9 +147,9 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
limbPos.X = message.ReadFloat();
|
||||
limbPos.Y = message.ReadFloat();
|
||||
|
||||
limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
rotation = message.ReadFloat();
|
||||
}
|
||||
catch
|
||||
@@ -190,14 +193,14 @@ namespace Barotrauma
|
||||
try
|
||||
{
|
||||
targetDir = message.ReadBoolean();
|
||||
targetMovement.X = message.ReadRangedSingle(-10.0f, 10.0f, 16);
|
||||
targetMovement.Y = message.ReadRangedSingle(-10.0f, 10.0f, 16);
|
||||
targetMovement.X = message.ReadRangedSingle(-1.0f, 1.0f, 8);
|
||||
targetMovement.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8);
|
||||
|
||||
pos.X = message.ReadFloat();
|
||||
pos.Y = message.ReadFloat();
|
||||
pos.X = message.ReadRangedSingle(-1.0f, 1.0f, 8);
|
||||
pos.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8);
|
||||
|
||||
vel.X = message.ReadFloat();
|
||||
vel.Y = message.ReadFloat();
|
||||
//vel.X = message.ReadFloat();
|
||||
//vel.Y = message.ReadFloat();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -1157,11 +1157,14 @@ namespace Barotrauma
|
||||
if (inventory == null) return false;
|
||||
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
|
||||
int i = 0;
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
message.Write(limb.body.SimPosition.X);
|
||||
message.Write(limb.body.SimPosition.Y);
|
||||
if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
|
||||
message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
//message.Write(limb.body.LinearVelocity.X);
|
||||
//message.Write(limb.body.LinearVelocity.Y);
|
||||
@@ -1175,7 +1178,6 @@ namespace Barotrauma
|
||||
message.Write((byte)((health/maxHealth)*255.0f));
|
||||
message.Write((byte)(MathHelper.Clamp(oxygen * 2.55f, 0.0f, 255.0f)));
|
||||
|
||||
|
||||
return true;
|
||||
case NetworkEventType.EntityUpdate:
|
||||
var hasInputs =
|
||||
@@ -1206,16 +1208,20 @@ namespace Barotrauma
|
||||
|
||||
if (secondaryHeld)
|
||||
{
|
||||
message.Write(cursorPosition.X);
|
||||
message.Write(cursorPosition.Y);
|
||||
Vector2 relativeCursorPosition = cursorPosition - Position;
|
||||
|
||||
message.WriteRangedSingle(relativeCursorPosition.X, -2000.0f, 2000.0f, 8);
|
||||
message.WriteRangedSingle(relativeCursorPosition.Y, -2000.0f, 2000.0f, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Write(AnimController.Dir > 0.0f);
|
||||
}
|
||||
|
||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return true;
|
||||
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
return true;
|
||||
default:
|
||||
@@ -1298,9 +1304,9 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
limbPos.X = message.ReadFloat();
|
||||
limbPos.Y = message.ReadFloat();
|
||||
|
||||
limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
rotation = message.ReadFloat();
|
||||
}
|
||||
catch
|
||||
@@ -1335,7 +1341,7 @@ namespace Barotrauma
|
||||
return;
|
||||
case NetworkEventType.EntityUpdate:
|
||||
float sendingTime = 0.0f;
|
||||
Vector2 cursorPos = Vector2.Zero;
|
||||
Vector2 relativeCursorPos = Vector2.Zero;
|
||||
|
||||
bool actionKeyState, secondaryKeyState;
|
||||
bool leftKeyState, rightKeyState, upKeyState, downKeyState;
|
||||
@@ -1390,29 +1396,38 @@ namespace Barotrauma
|
||||
{
|
||||
if (secondaryKeyState)
|
||||
{
|
||||
cursorPos = new Vector2(
|
||||
message.ReadFloat(),
|
||||
message.ReadFloat());
|
||||
relativeCursorPos = new Vector2(
|
||||
message.ReadRangedSingle(-2000.0f, 2000.0f, 8),
|
||||
message.ReadRangedSingle(-2000.0f, 2000.0f, 8));
|
||||
}
|
||||
else
|
||||
{
|
||||
dir = message.ReadBoolean() ? 1.0f : -1.0f;
|
||||
}
|
||||
|
||||
pos.X = message.ReadFloat();
|
||||
pos.Y = message.ReadFloat();
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Failed to read netowkrevent for "+this.ToString());
|
||||
DebugConsole.ThrowError("Failed to read networkevent for "+this.ToString());
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
//failed to read position, character may be further than NetConfig.CharacterIgnoreDistance
|
||||
pos = SimPosition;
|
||||
}
|
||||
|
||||
if (secondaryKeyState)
|
||||
{
|
||||
cursorPosition = MathUtils.IsValid(cursorPos) ? cursorPos : Vector2.Zero;
|
||||
cursorPosition = MathUtils.IsValid(relativeCursorPos) ?
|
||||
ConvertUnits.ToDisplayUnits(pos)+relativeCursorPos : Vector2.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -168,8 +168,9 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
|
||||
{
|
||||
message.Write(Convert.ToByte(flowPercentage+100));
|
||||
message.WriteRangedInteger(-10,10,(int)(flowPercentage/10.0f));
|
||||
message.Write(IsActive);
|
||||
message.WritePadBits();
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
|
||||
@@ -179,7 +180,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
try
|
||||
{
|
||||
newFlow = (float)(message.ReadByte()-100);
|
||||
newFlow = message.ReadRangedInteger(-10,10)*10.0f;
|
||||
newActive = message.ReadBoolean();
|
||||
}
|
||||
|
||||
|
||||
@@ -427,7 +427,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
message.Write(autoTemp);
|
||||
message.WriteRangedSingle(temperature, 0.0f, 10000.0f, 16);
|
||||
message.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 16);
|
||||
message.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 7);
|
||||
|
||||
message.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8);
|
||||
message.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
|
||||
@@ -443,7 +443,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
newAutoTemp = message.ReadBoolean();
|
||||
newTemperature = message.ReadRangedSingle(0.0f, 10000.0f, 16);
|
||||
newShutDownTemp = message.ReadRangedSingle(0.0f, 10000.0f, 16);
|
||||
newShutDownTemp = message.ReadRangedSingle(0.0f, 10000.0f, 7);
|
||||
newShutDownTemp = MathUtils.Round(newShutDownTemp, 100.0f);
|
||||
|
||||
newCoolingRate = message.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||
newFissionRate = message.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||
|
||||
@@ -198,23 +198,25 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
|
||||
{
|
||||
message.Write((byte)((int)(rechargeSpeed/maxRechargeSpeed*255.0f)));
|
||||
message.Write(charge);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(rechargeSpeed/MaxRechargeSpeed, 0.0f, 1.0f), 0.0f, 1.0f, 8);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(charge/capacity,0.0f, 1.0f), 0.0f, 1.0f, 8);
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
|
||||
{
|
||||
byte newRechargeSpeed = 0;
|
||||
float newRechargeSpeed = 0f;
|
||||
float newCharge = 0.0f;
|
||||
|
||||
try
|
||||
{
|
||||
newRechargeSpeed = message.ReadByte();
|
||||
newCharge = message.ReadFloat();
|
||||
newRechargeSpeed = message.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
newRechargeSpeed *= MaxRechargeSpeed;
|
||||
newCharge = message.ReadRangedSingle(0.0f, 1.0f, 8);
|
||||
newCharge *= capacity;
|
||||
}
|
||||
catch { }
|
||||
|
||||
RechargeSpeed = (newRechargeSpeed/255.0f)*maxRechargeSpeed;
|
||||
RechargeSpeed = newRechargeSpeed;
|
||||
Charge = newCharge;
|
||||
}
|
||||
|
||||
|
||||
@@ -471,8 +471,8 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message, object data)
|
||||
{
|
||||
message.Write(volume);
|
||||
{
|
||||
message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -483,7 +483,7 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
newVolume = message.ReadFloat();
|
||||
float newPercentage = message.ReadRangedSingle(0.0f, 1.5f, 6);
|
||||
}
|
||||
|
||||
catch
|
||||
|
||||
@@ -653,7 +653,7 @@ namespace Barotrauma
|
||||
|
||||
message.Write((float)NetTime.Now);
|
||||
message.Write(byteIndex);
|
||||
message.Write(sections[sectionIndex].damage);
|
||||
message.WriteRangedSingle(sections[sectionIndex].damage/Health, 0.0f, 1.0f, 8);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -668,7 +668,7 @@ namespace Barotrauma
|
||||
{
|
||||
updateTime = message.ReadFloat();
|
||||
sectionIndex = message.ReadByte();
|
||||
damage = message.ReadFloat();
|
||||
damage = message.ReadRangedSingle(0.0f, 1.0f, 8) * Health;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -314,7 +314,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (c as AICharacter == null) continue;
|
||||
|
||||
if (c.SimPosition.Length() > 100.0f) continue;
|
||||
if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue;
|
||||
|
||||
c.CreateUpdateNetworkEvent(false);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ namespace Barotrauma.Networking
|
||||
|
||||
public static string MasterServerUrl = GameMain.Config.MasterServerUrl;
|
||||
|
||||
//if a character is further than this from the sub, the server will ignore it
|
||||
//(in sim units)
|
||||
public const float CharacterIgnoreDistance = 100.0f;
|
||||
|
||||
//if a ragdoll is further than this from the correct position, teleport it there
|
||||
//(in sim units)
|
||||
public const float ResetRagdollDistance = 2.0f;
|
||||
|
||||
BIN
UpgradeLog.htm
Normal file
BIN
UpgradeLog.htm
Normal file
Binary file not shown.
BIN
UpgradeLog2.htm
Normal file
BIN
UpgradeLog2.htm
Normal file
Binary file not shown.
Reference in New Issue
Block a user