AICharacte syncing bugfixes, cleanbuild removes the temp save folder, minor networkevent optimizations (enum max value == GetValues().Length-1)
This commit is contained in:
Binary file not shown.
@@ -554,7 +554,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public override void FillNetworkData(NetBuffer message)
|
public override void FillNetworkData(NetBuffer message)
|
||||||
{
|
{
|
||||||
message.Write((byte)state);
|
message.WriteRangedInteger(0, Enum.GetValues(typeof(AiState)).Length-1, (int)state);
|
||||||
|
|
||||||
bool wallAttack = (wallAttackPos != Vector2.Zero && state == AiState.Attack);
|
bool wallAttack = (wallAttackPos != Vector2.Zero && state == AiState.Attack);
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ namespace Barotrauma
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
newState = (AiState)(message.ReadByte());
|
newState = (AiState)message.ReadRangedInteger(0, Enum.GetValues(typeof(AiState)).Length - 1);
|
||||||
|
|
||||||
//bool wallAttack = message.ReadBoolean();
|
//bool wallAttack = message.ReadBoolean();
|
||||||
|
|
||||||
@@ -619,7 +619,15 @@ namespace Barotrauma
|
|||||||
targetID = message.ReadUInt16();
|
targetID = message.ReadUInt16();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch { return; }
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
DebugConsole.ThrowError("Failed to read enemy ai update message", e);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//wallAttackPos = newWallAttackPos;
|
//wallAttackPos = newWallAttackPos;
|
||||||
|
|
||||||
|
|||||||
@@ -92,19 +92,11 @@ namespace Barotrauma
|
|||||||
case NetworkEventType.KillCharacter:
|
case NetworkEventType.KillCharacter:
|
||||||
return true;
|
return true;
|
||||||
case NetworkEventType.ImportantEntityUpdate:
|
case NetworkEventType.ImportantEntityUpdate:
|
||||||
//foreach (Limb limb in AnimController.Limbs)
|
|
||||||
//{
|
|
||||||
//if (RefLimb.ignoreCollisions) continue;
|
|
||||||
|
|
||||||
//if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
|
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||||
|
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||||
|
|
||||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
message.Write(AnimController.RefLimb.Rotation);
|
||||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
|
||||||
|
|
||||||
|
|
||||||
message.Write(AnimController.RefLimb.Rotation);
|
|
||||||
// i++;
|
|
||||||
//}
|
|
||||||
|
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8);
|
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8);
|
||||||
message.Write((byte)((health / maxHealth) * 255.0f));
|
message.Write((byte)((health / maxHealth) * 255.0f));
|
||||||
@@ -115,30 +107,23 @@ namespace Barotrauma
|
|||||||
aiController.FillNetworkData(message);
|
aiController.FillNetworkData(message);
|
||||||
return true;
|
return true;
|
||||||
case NetworkEventType.EntityUpdate:
|
case NetworkEventType.EntityUpdate:
|
||||||
//if (Submarine == null)
|
|
||||||
//{
|
|
||||||
// if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
|
|
||||||
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
message.Write(AnimController.TargetDir == Direction.Right);
|
message.Write(AnimController.TargetDir == Direction.Right);
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
||||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
||||||
|
|
||||||
message.Write(Submarine != null);
|
message.Write(Submarine != null);
|
||||||
|
|
||||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
default:
|
||||||
|
#if DEBUG
|
||||||
|
DebugConsole.ThrowError("AICharacter network event had a wrong type ("+type+")");
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
||||||
@@ -152,33 +137,27 @@ namespace Barotrauma
|
|||||||
Kill(CauseOfDeath.Damage, true);
|
Kill(CauseOfDeath.Damage, true);
|
||||||
return;
|
return;
|
||||||
case NetworkEventType.ImportantEntityUpdate:
|
case NetworkEventType.ImportantEntityUpdate:
|
||||||
//foreach (Limb limb in AnimController.Limbs)
|
|
||||||
//{
|
|
||||||
// if (limb.ignoreCollisions) continue;
|
|
||||||
|
|
||||||
Vector2 limbPos = AnimController.RefLimb.SimPosition;
|
Vector2 limbPos = AnimController.RefLimb.SimPosition;
|
||||||
float rotation = AnimController.RefLimb.Rotation;
|
float rotation = AnimController.RefLimb.Rotation;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
limbPos.X = message.ReadFloat();
|
limbPos.X = message.ReadFloat();
|
||||||
limbPos.Y = message.ReadFloat();
|
limbPos.Y = message.ReadFloat();
|
||||||
|
|
||||||
rotation = message.ReadFloat();
|
rotation = message.ReadFloat();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AnimController.RefLimb.body != null)
|
if (AnimController.RefLimb.body != null)
|
||||||
{
|
{
|
||||||
//AnimController.RefLimb.body.TargetVelocity = limb.body.LinearVelocity;
|
AnimController.RefLimb.body.TargetPosition = limbPos;
|
||||||
AnimController.RefLimb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
|
AnimController.RefLimb.body.TargetRotation = rotation;
|
||||||
AnimController.RefLimb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
|
}
|
||||||
//limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
|
|
||||||
float newStunTimer = 0.0f, newHealth = 0.0f, newBleeding = 0.0f;
|
float newStunTimer = 0.0f, newHealth = 0.0f, newBleeding = 0.0f;
|
||||||
|
|
||||||
@@ -190,7 +169,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
newBleeding = message.ReadRangedSingle(0.0f, 5.0f, 8);
|
newBleeding = message.ReadRangedSingle(0.0f, 5.0f, 8);
|
||||||
}
|
}
|
||||||
catch { return; }
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
DebugConsole.ThrowError("Failed to read AICharacter update message", e);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AnimController.StunTimer = newStunTimer;
|
AnimController.StunTimer = newStunTimer;
|
||||||
health = newHealth;
|
health = newHealth;
|
||||||
@@ -231,9 +217,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
|
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
|
||||||
AnimController.TargetMovement = targetMovement;
|
AnimController.TargetMovement = targetMovement;
|
||||||
|
|
||||||
AnimController.TargetMovement = AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
|
AnimController.RefLimb.body.TargetPosition =
|
||||||
|
AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
|
||||||
|
|
||||||
if (inSub)
|
if (inSub)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1393,17 +1393,17 @@ namespace Barotrauma
|
|||||||
if (inventory == null) return false;
|
if (inventory == null) return false;
|
||||||
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||||
case NetworkEventType.ImportantEntityUpdate:
|
case NetworkEventType.ImportantEntityUpdate:
|
||||||
if (health>0.0f)
|
if (health > 0.0f)
|
||||||
{
|
{
|
||||||
message.Write(Math.Max((byte)((health / maxHealth) * 255.0f), (byte)1));
|
message.Write(Math.Max((byte)((health / maxHealth) * 255.0f), (byte)1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
message.Write((byte)0);
|
message.Write((byte)0);
|
||||||
message.WriteRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length, (int)lastAttackCauseOfDeath);
|
message.WriteRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length-1, (int)lastAttackCauseOfDeath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AnimController.StunTimer<=0.0f && bleeding<=0.0f && oxygen>99.0f)
|
if (AnimController.StunTimer <= 0.0f && bleeding <= 0.0f && oxygen > 99.0f)
|
||||||
{
|
{
|
||||||
message.Write(true);
|
message.Write(true);
|
||||||
}
|
}
|
||||||
@@ -1566,7 +1566,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (health == 0.0f)
|
if (health == 0.0f)
|
||||||
{
|
{
|
||||||
causeOfDeath = (CauseOfDeath)message.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length);
|
causeOfDeath = (CauseOfDeath)message.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length-1);
|
||||||
Kill(causeOfDeath, true);
|
Kill(causeOfDeath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -449,6 +449,12 @@ namespace Barotrauma
|
|||||||
DebugConsole.NewMessage("Deleted "+saveFile, Color.Green);
|
DebugConsole.NewMessage("Deleted "+saveFile, Color.Green);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (System.IO.Directory.Exists(System.IO.Path.Combine(SaveUtil.SaveFolder, "temp")))
|
||||||
|
{
|
||||||
|
System.IO.Directory.Delete(System.IO.Path.Combine(SaveUtil.SaveFolder, "temp"), true);
|
||||||
|
DebugConsole.NewMessage("Deleted temp save folder", Color.Green);
|
||||||
|
}
|
||||||
|
|
||||||
if (System.IO.Directory.Exists(ServerLog.SavePath))
|
if (System.IO.Directory.Exists(ServerLog.SavePath))
|
||||||
{
|
{
|
||||||
var logFiles = System.IO.Directory.GetFiles(ServerLog.SavePath);
|
var logFiles = System.IO.Directory.GetFiles(ServerLog.SavePath);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace Barotrauma.Items.Components
|
|||||||
autopilotTickBox.Selected = value;
|
autopilotTickBox.Selected = value;
|
||||||
|
|
||||||
maintainPosTickBox.Enabled = autoPilot;
|
maintainPosTickBox.Enabled = autoPilot;
|
||||||
|
|
||||||
if (autoPilot)
|
if (autoPilot)
|
||||||
{
|
{
|
||||||
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
|
if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false);
|
||||||
@@ -103,7 +103,7 @@ namespace Barotrauma.Items.Components
|
|||||||
autopilotTickBox.OnSelected = (GUITickBox box) =>
|
autopilotTickBox.OnSelected = (GUITickBox box) =>
|
||||||
{
|
{
|
||||||
AutoPilot = box.Selected;
|
AutoPilot = box.Selected;
|
||||||
item.NewComponentEvent(this, true, true);
|
valueChanged = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -117,22 +117,23 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
//base.Update(deltaTime, cam);
|
//base.Update(deltaTime, cam);
|
||||||
|
|
||||||
|
if (valueChanged)
|
||||||
|
{
|
||||||
|
networkUpdateTimer -= deltaTime;
|
||||||
|
if (networkUpdateTimer <= 0.0f)
|
||||||
|
{
|
||||||
|
item.NewComponentEvent(this, true, false);
|
||||||
|
networkUpdateTimer = 0.5f;
|
||||||
|
valueChanged = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (voltage < minVoltage) return;
|
if (voltage < minVoltage) return;
|
||||||
|
|
||||||
if (autoPilot)
|
if (autoPilot)
|
||||||
{
|
{
|
||||||
UpdateAutoPilot(deltaTime);
|
UpdateAutoPilot(deltaTime);
|
||||||
}
|
}
|
||||||
else if (valueChanged)
|
|
||||||
{
|
|
||||||
networkUpdateTimer -= deltaTime;
|
|
||||||
if (networkUpdateTimer<=0.0f)
|
|
||||||
{
|
|
||||||
item.NewComponentEvent(this, true, false);
|
|
||||||
networkUpdateTimer = 1.0f;
|
|
||||||
valueChanged = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item.SendSignal(targetVelocity.X.ToString(CultureInfo.InvariantCulture), "velocity_x_out");
|
item.SendSignal(targetVelocity.X.ToString(CultureInfo.InvariantCulture), "velocity_x_out");
|
||||||
|
|
||||||
@@ -277,7 +278,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
private bool ToggleMaintainPosition(GUITickBox tickBox)
|
private bool ToggleMaintainPosition(GUITickBox tickBox)
|
||||||
{
|
{
|
||||||
item.NewComponentEvent(this, true, true);
|
valueChanged = true;
|
||||||
|
|
||||||
if (tickBox.Selected)
|
if (tickBox.Selected)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -567,17 +567,18 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
||||||
DebugConsole.ThrowError("Directory ''" + SavePath + "'' not found and creating the directory failed.", e);
|
DebugConsole.ThrowError("Directory ''" + SavePath + "'' not found and creating the directory failed.", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] filePaths;
|
List<string> filePaths;
|
||||||
|
string[] subDirectories;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
filePaths = Directory.GetFiles(SavePath);
|
filePaths = Directory.GetFiles(SavePath).ToList();
|
||||||
|
subDirectories = Directory.GetDirectories(SavePath);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -585,6 +586,19 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (string subDirectory in subDirectories)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
filePaths.AddRange(Directory.GetDirectories(subDirectory));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Couldn't open subdirectory ''" + subDirectory + "''!", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (string path in filePaths)
|
foreach (string path in filePaths)
|
||||||
{
|
{
|
||||||
//Map savedMap = new Map(mapPath);
|
//Map savedMap = new Map(mapPath);
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.SmallFont, "Peak sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].LargestValue()) + "/s " +
|
spriteBatch.DrawString(GUI.SmallFont, "Peak sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].LargestValue()) + "/s " +
|
||||||
"Avg sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].Average()) + " bytes/s",
|
"Avg sent: " + MathUtils.GetBytesReadable((int)graphs[(int)NetStatType.SentBytes].Average()) + "/s",
|
||||||
new Vector2(rect.X + 10, rect.Y + 30), Color.Orange);
|
new Vector2(rect.X + 10, rect.Y + 30), Color.Orange);
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s",
|
spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s",
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public bool FillData(NetBuffer message)
|
public bool FillData(NetBuffer message)
|
||||||
{
|
{
|
||||||
message.WriteRangedInteger(0, Enum.GetValues(typeof(NetworkEventType)).Length, (int)eventType);
|
message.WriteRangedInteger(0, Enum.GetValues(typeof(NetworkEventType)).Length-1, (int)eventType);
|
||||||
|
|
||||||
Entity e = Entity.FindEntityByID(id);
|
Entity e = Entity.FindEntityByID(id);
|
||||||
if (e == null) return false;
|
if (e == null) return false;
|
||||||
@@ -189,13 +189,13 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
eventType = (NetworkEventType)message.ReadRangedInteger(0, Enum.GetValues(typeof(NetworkEventType)).Length);
|
eventType = (NetworkEventType)message.ReadRangedInteger(0, Enum.GetValues(typeof(NetworkEventType)).Length-1);
|
||||||
id = message.ReadUInt16();
|
id = message.ReadUInt16();
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
DebugConsole.ThrowError("Received invalid network message");
|
DebugConsole.ThrowError("Received invalid network message", exception);
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user