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:
@@ -68,8 +68,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public EnemyAIController(Character c, string file) : base(c)
|
public EnemyAIController(Character c, string file) : base(c)
|
||||||
{
|
{
|
||||||
if (GameMain.Client != null && GameMain.Server == null) c.Enabled = false;
|
|
||||||
|
|
||||||
targetMemories = new Dictionary<AITarget, AITargetMemory>();
|
targetMemories = new Dictionary<AITarget, AITargetMemory>();
|
||||||
|
|
||||||
XDocument doc = ToolBox.TryLoadXml(file);
|
XDocument doc = ToolBox.TryLoadXml(file);
|
||||||
|
|||||||
@@ -618,7 +618,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
CharacterList.Add(this);
|
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;
|
private static string humanConfigFile;
|
||||||
@@ -1258,12 +1263,31 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public static void UpdateAll(Camera cam, float deltaTime)
|
public static void UpdateAll(Camera cam, float deltaTime)
|
||||||
{
|
{
|
||||||
//if (NewCharacterQueue.Count>0)
|
if (GameMain.Client == null)
|
||||||
//{
|
{
|
||||||
// new Character(NewCharacterQueue.Dequeue(), Vector2.Zero);
|
foreach (Character c in CharacterList)
|
||||||
//}
|
{
|
||||||
|
if (!(c is AICharacter)) continue;
|
||||||
|
|
||||||
for (int i = 0; i<CharacterList.Count; i++)
|
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++)
|
||||||
{
|
{
|
||||||
CharacterList[i].Update(cam, deltaTime);
|
CharacterList[i].Update(cam, deltaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,6 +212,10 @@ namespace Barotrauma
|
|||||||
memInput.RemoveRange(60, memInput.Count - 60);
|
memInput.RemoveRange(60, memInput.Count - 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else //this == Character.Controlled && GameMain.Client == null
|
||||||
|
{
|
||||||
|
AnimController.Frozen = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (networkUpdateSent)
|
if (networkUpdateSent)
|
||||||
{
|
{
|
||||||
@@ -288,6 +292,8 @@ namespace Barotrauma
|
|||||||
UInt16 networkUpdateID = msg.ReadUInt16();
|
UInt16 networkUpdateID = msg.ReadUInt16();
|
||||||
byte inputCount = msg.ReadByte();
|
byte inputCount = msg.ReadByte();
|
||||||
|
|
||||||
|
if (AllowInput) Enabled = true;
|
||||||
|
|
||||||
for (int i = 0; i < inputCount; i++)
|
for (int i = 0; i < inputCount; i++)
|
||||||
{
|
{
|
||||||
InputNetFlags newInput = (InputNetFlags)msg.ReadRangedInteger(0, (int)InputNetFlags.MaxVal);
|
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;
|
return character;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user