Fixed far-away AI characters staying disabled when switching control to them + minor optimization
This commit is contained in:
@@ -1288,22 +1288,22 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
//disable AI characters that are far away from all clients and the host's character
|
//disable AI characters that are far away from all clients and the host's character and not controlled by anyone
|
||||||
c.Enabled =
|
c.Enabled =
|
||||||
|
c == controlled ||
|
||||||
CharacterList.Any(c2 =>
|
CharacterList.Any(c2 =>
|
||||||
(c2.IsRemotePlayer || c2 == GameMain.Server.Character) &&
|
(c2.IsRemotePlayer || c2 == GameMain.Server.Character) &&
|
||||||
Vector2.Distance(c2.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistance);
|
Vector2.DistanceSquared(c2.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistanceSqr);
|
||||||
}
|
}
|
||||||
else if (Submarine.MainSub != null)
|
else if (Submarine.MainSub != null)
|
||||||
{
|
{
|
||||||
//disable AI characters that are far away from the sub and the controlled character
|
//disable AI characters that are far away from the sub and the controlled character
|
||||||
c.Enabled = Vector2.Distance(Submarine.MainSub.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistance ||
|
c.Enabled = Vector2.DistanceSquared(Submarine.MainSub.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistanceSqr ||
|
||||||
(controlled != null && Vector2.Distance(controlled.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistance);
|
(controlled != null && Vector2.DistanceSquared(controlled.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistanceSqr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < CharacterList.Count; i++)
|
for (int i = 0; i < CharacterList.Count; i++)
|
||||||
{
|
{
|
||||||
CharacterList[i].Update(deltaTime, cam);
|
CharacterList[i].Update(deltaTime, cam);
|
||||||
|
|||||||
@@ -842,7 +842,7 @@ namespace Barotrauma.Networking
|
|||||||
if (!character.Enabled) continue;
|
if (!character.Enabled) continue;
|
||||||
if (c.Character != null &&
|
if (c.Character != null &&
|
||||||
Vector2.DistanceSquared(character.WorldPosition, c.Character.WorldPosition) >=
|
Vector2.DistanceSquared(character.WorldPosition, c.Character.WorldPosition) >=
|
||||||
NetConfig.CharacterIgnoreDistance * NetConfig.CharacterIgnoreDistance)
|
NetConfig.CharacterIgnoreDistanceSqr)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1876,6 +1876,7 @@ namespace Barotrauma.Networking
|
|||||||
newCharacter.LastNetworkUpdateID = client.Character.LastNetworkUpdateID;
|
newCharacter.LastNetworkUpdateID = client.Character.LastNetworkUpdateID;
|
||||||
|
|
||||||
newCharacter.IsRemotePlayer = true;
|
newCharacter.IsRemotePlayer = true;
|
||||||
|
newCharacter.Enabled = true;
|
||||||
client.Character = newCharacter;
|
client.Character = newCharacter;
|
||||||
CreateEntityEvent(newCharacter, new object[] { NetEntityEvent.Type.Control, client });
|
CreateEntityEvent(newCharacter, new object[] { NetEntityEvent.Type.Control, client });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
//if a Character is further than this from the sub, the server will ignore it
|
//if a Character is further than this from the sub, the server will ignore it
|
||||||
//(in display units)
|
//(in display units)
|
||||||
public const float CharacterIgnoreDistance = 20000.0f;
|
public const float CharacterIgnoreDistance = 20000.0f;
|
||||||
|
public const float CharacterIgnoreDistanceSqr = CharacterIgnoreDistance * CharacterIgnoreDistance;
|
||||||
|
|
||||||
//how much the physics body of an item has to move until the server
|
//how much the physics body of an item has to move until the server
|
||||||
//send a position update to clients (in sim units)
|
//send a position update to clients (in sim units)
|
||||||
|
|||||||
Reference in New Issue
Block a user