All characters start disabled in the multiplayer mode, and are enabled when the client starts receiving position updates for the character, OR when the server starts receiving inputs from the client controlling the character, OR if the character is controlled locally. (-> no more floating, frozen characters at the start of a round)

+ the server disables AICharacters that are far away from all players
This commit is contained in:
Regalis
2017-03-25 18:24:09 +02:00
parent 827644b72c
commit aca85c2708
3 changed files with 38 additions and 10 deletions

View File

@@ -68,8 +68,6 @@ namespace Barotrauma
public EnemyAIController(Character c, string file) : base(c)
{
if (GameMain.Client != null && GameMain.Server == null) c.Enabled = false;
targetMemories = new Dictionary<AITarget, AITargetMemory>();
XDocument doc = ToolBox.TryLoadXml(file);

View File

@@ -618,7 +618,12 @@ namespace Barotrauma
CharacterList.Add(this);
Enabled = true;
//characters start disabled in the multiplayer mode, and are enabled if/when
// - controlled by the player
// - client receives a position update from the server
// - server receives an input message from the client controlling the character
// - if an AICharacter, the server enables it when close enough to any of the players
Enabled = GameMain.NetworkMember == null;
}
private static string humanConfigFile;
@@ -1247,7 +1252,7 @@ namespace Barotrauma
c.AnimController.UpdateAnim(deltaTime);
}
}
public static void AddAllToGUIUpdateList()
{
for (int i = 0; i < CharacterList.Count; i++)
@@ -1258,12 +1263,31 @@ namespace Barotrauma
public static void UpdateAll(Camera cam, float deltaTime)
{
//if (NewCharacterQueue.Count>0)
//{
// new Character(NewCharacterQueue.Dequeue(), Vector2.Zero);
//}
if (GameMain.Client == null)
{
foreach (Character c in CharacterList)
{
if (!(c is AICharacter)) continue;
if (GameMain.Server != null)
{
//disable AI characters that are far away from all clients and the host's character
c.Enabled =
CharacterList.Any(c2 =>
(c2.IsRemotePlayer || c2 == GameMain.Server.Character) &&
Vector2.Distance(c2.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistance);
}
else
{
//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 ||
(controlled != null && Vector2.Distance(controlled.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistance);
}
}
}
for (int i = 0; i<CharacterList.Count; i++)
for (int i = 0; i < CharacterList.Count; i++)
{
CharacterList[i].Update(cam, deltaTime);
}

View File

@@ -212,6 +212,10 @@ namespace Barotrauma
memInput.RemoveRange(60, memInput.Count - 60);
}
}
else //this == Character.Controlled && GameMain.Client == null
{
AnimController.Frozen = false;
}
if (networkUpdateSent)
{
@@ -288,6 +292,8 @@ namespace Barotrauma
UInt16 networkUpdateID = msg.ReadUInt16();
byte inputCount = msg.ReadByte();
if (AllowInput) Enabled = true;
for (int i = 0; i < inputCount; i++)
{
InputNetFlags newInput = (InputNetFlags)msg.ReadRangedInteger(0, (int)InputNetFlags.MaxVal);
@@ -763,7 +769,7 @@ namespace Barotrauma
}
}
character.Enabled = enabled;
character.Enabled = Controlled == character || enabled;
return character;
}