Server doesn't send character position updates to far-away clients, clients disable characters if they haven't received position updates in a while

This commit is contained in:
Regalis
2017-02-07 18:59:25 +02:00
parent b98ebe6e21
commit d46207916f
6 changed files with 48 additions and 88 deletions
+5 -5
View File
@@ -33,16 +33,16 @@ namespace Barotrauma
public override void Update(Camera cam, float deltaTime)
{
if (!Enabled) return;
base.Update(cam, deltaTime);
if (!Enabled) return;
float dist = Vector2.Distance(cam.WorldViewCenter, WorldPosition);
if (dist > 8000.0f)
float dist = Vector2.DistanceSquared(cam.WorldViewCenter, WorldPosition);
if (dist > 8000.0f * 8000.0f)
{
AnimController.SimplePhysicsEnabled = true;
}
else if (dist < 7000.0f)
else if (dist < 7000.0f * 7000.0f)
{
AnimController.SimplePhysicsEnabled = false;
}
@@ -1125,14 +1125,14 @@ namespace Barotrauma
public void SetPosition(Vector2 simPosition, bool lerp = false)
{
Vector2 moveAmount = simPosition - Collider.SimPosition;
Vector2 limbMoveAmount = simPosition - MainLimb.SimPosition;
Collider.SetTransform(simPosition, Collider.Rotation);
foreach (Limb limb in Limbs)
{
//check visibility from the new position of the collider to the new position of this limb
Vector2 movePos = limb.SimPosition + moveAmount;
Vector2 movePos = limb.SimPosition + limbMoveAmount;
TrySetLimbPosition(limb, simPosition, movePos, lerp);
}
@@ -1160,7 +1160,7 @@ namespace Barotrauma
if (lerp)
{
limb.body.TargetPosition = movePos;
limb.body.MoveToTargetPosition(Vector2.DistanceSquared(limb.SimPosition, movePos) < 100.0f);
limb.body.MoveToTargetPosition(true);
}
else
{
@@ -1179,7 +1179,7 @@ namespace Barotrauma
protected void CheckDistFromCollider()
{
float allowedDist = Math.Max(Math.Max(Collider.radius, Collider.width), Collider.height) * 2.0f;
float resetDist = allowedDist * 10.0f;
float resetDist = allowedDist * 5.0f;
float distSqrd = Vector2.DistanceSquared(Collider.SimPosition, MainLimb.SimPosition);
+25 -4
View File
@@ -107,7 +107,7 @@ namespace Barotrauma
public UInt16 LastNetworkUpdateID = 0;
//public int LargeUpdateTimer;
protected float lastRecvPositionUpdateTime;
public readonly Dictionary<string, ObjectProperty> Properties;
public Dictionary<string, ObjectProperty> ObjectProperties
@@ -1331,7 +1331,7 @@ namespace Barotrauma
public virtual void Update(Camera cam, float deltaTime)
{
if (GameMain.Client!=null && this==Controlled && !isSynced) return;
if (GameMain.Client != null && this == Controlled && !isSynced) return;
if (!Enabled) return;
@@ -1360,7 +1360,22 @@ namespace Barotrauma
if (this != Character.Controlled)
{
if (GameMain.Server != null && !(this is AICharacter))
if (GameMain.Client != null)
{
//freeze AI characters if more than 1 seconds have passed since last update from the server
if (lastRecvPositionUpdateTime < NetTime.Now - 1.0f)
{
AnimController.Frozen = true;
memPos.Clear();
//hide after 2 seconds
if (lastRecvPositionUpdateTime < NetTime.Now - 2.0f)
{
Enabled = false;
return;
}
}
}
else if (GameMain.Server != null && !(this is AICharacter))
{
if (!AllowInput)
{
@@ -1447,8 +1462,9 @@ namespace Barotrauma
memInput.RemoveRange(60, memInput.Count - 60);
}
}
else //this == Character.Controlled && GameMain.Client == null
else
{
//this == Character.Controlled && GameMain.Client == null
AnimController.Frozen = false;
}
@@ -2247,6 +2263,11 @@ namespace Barotrauma
case ServerNetObject.ENTITY_POSITION:
bool facingRight = AnimController.Dir > 0.0f;
lastRecvPositionUpdateTime = (float)NetTime.Now;
AnimController.Frozen = false;
Enabled = true;
UInt16 networkUpdateID = 0;
if (msg.ReadBoolean())
{