NetworkEvent optimization (more frequent use of WriteRangedSingle)
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user