diff --git a/.vs/Subsurface_Solution/v14/.suo b/.vs/Subsurface_Solution/v14/.suo index a395e4ba0..667c418dc 100644 Binary files a/.vs/Subsurface_Solution/v14/.suo and b/.vs/Subsurface_Solution/v14/.suo differ diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index c6fbb5dd9..5dcb56769 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -554,7 +554,7 @@ namespace Barotrauma 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); @@ -594,7 +594,7 @@ namespace Barotrauma try { - newState = (AiState)(message.ReadByte()); + newState = (AiState)message.ReadRangedInteger(0, Enum.GetValues(typeof(AiState)).Length - 1); //bool wallAttack = message.ReadBoolean(); @@ -619,7 +619,15 @@ namespace Barotrauma targetID = message.ReadUInt16(); } - catch { return; } + catch (Exception e) + { +#if DEBUG + DebugConsole.ThrowError("Failed to read enemy ai update message", e); +#endif + + + return; + } //wallAttackPos = newWallAttackPos; diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs index d8b2716be..0da4ed91f 100644 --- a/Subsurface/Source/Characters/AICharacter.cs +++ b/Subsurface/Source/Characters/AICharacter.cs @@ -92,19 +92,11 @@ namespace Barotrauma case NetworkEventType.KillCharacter: return true; 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.SimPosition.Y); - - - message.Write(AnimController.RefLimb.Rotation); - // i++; - //} + message.Write(AnimController.RefLimb.Rotation); message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8); message.Write((byte)((health / maxHealth) * 255.0f)); @@ -115,30 +107,23 @@ namespace Barotrauma aiController.FillNetworkData(message); return true; 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.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(AnimController.RefLimb.SimPosition.X); 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) @@ -152,33 +137,27 @@ namespace Barotrauma Kill(CauseOfDeath.Damage, true); return; case NetworkEventType.ImportantEntityUpdate: - //foreach (Limb limb in AnimController.Limbs) - //{ - // if (limb.ignoreCollisions) continue; - Vector2 limbPos = AnimController.RefLimb.SimPosition; - float rotation = AnimController.RefLimb.Rotation; + Vector2 limbPos = AnimController.RefLimb.SimPosition; + float rotation = AnimController.RefLimb.Rotation; - try - { - limbPos.X = message.ReadFloat(); - limbPos.Y = message.ReadFloat(); + try + { + limbPos.X = message.ReadFloat(); + limbPos.Y = message.ReadFloat(); - rotation = message.ReadFloat(); - } - catch - { - return; - } + rotation = message.ReadFloat(); + } + catch + { + return; + } - if (AnimController.RefLimb.body != null) - { - //AnimController.RefLimb.body.TargetVelocity = limb.body.LinearVelocity; - AnimController.RefLimb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0); - AnimController.RefLimb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0); - //limb.body.TargetAngularVelocity = limb.body.AngularVelocity; - } - //} + if (AnimController.RefLimb.body != null) + { + AnimController.RefLimb.body.TargetPosition = limbPos; + AnimController.RefLimb.body.TargetRotation = rotation; + } float newStunTimer = 0.0f, newHealth = 0.0f, newBleeding = 0.0f; @@ -190,7 +169,14 @@ namespace Barotrauma 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; health = newHealth; @@ -231,9 +217,9 @@ namespace Barotrauma AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left; 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) { diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index a50e7aa1b..e0458869c 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1393,17 +1393,17 @@ namespace Barotrauma if (inventory == null) return false; return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data); case NetworkEventType.ImportantEntityUpdate: - if (health>0.0f) + if (health > 0.0f) { message.Write(Math.Max((byte)((health / maxHealth) * 255.0f), (byte)1)); } else { 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); } @@ -1566,7 +1566,7 @@ namespace Barotrauma 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); } diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index a91ccf3e4..881ba1590 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -449,6 +449,12 @@ namespace Barotrauma 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)) { var logFiles = System.IO.Directory.GetFiles(ServerLog.SavePath); diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index 3a8b59066..8e4f20246 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -46,7 +46,7 @@ namespace Barotrauma.Items.Components autopilotTickBox.Selected = value; maintainPosTickBox.Enabled = autoPilot; - + if (autoPilot) { if (pathFinder==null) pathFinder = new PathFinder(WayPoint.WayPointList, false); @@ -103,7 +103,7 @@ namespace Barotrauma.Items.Components autopilotTickBox.OnSelected = (GUITickBox box) => { AutoPilot = box.Selected; - item.NewComponentEvent(this, true, true); + valueChanged = true; return true; }; @@ -117,22 +117,23 @@ namespace Barotrauma.Items.Components { //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 (autoPilot) { 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"); @@ -277,7 +278,7 @@ namespace Barotrauma.Items.Components private bool ToggleMaintainPosition(GUITickBox tickBox) { - item.NewComponentEvent(this, true, true); + valueChanged = true; if (tickBox.Selected) { diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 23d5ae734..d7af79305 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -567,17 +567,18 @@ namespace Barotrauma } catch (Exception e) { - DebugConsole.ThrowError("Directory ''" + SavePath + "'' not found and creating the directory failed.", e); return; } } - string[] filePaths; + List filePaths; + string[] subDirectories; try { - filePaths = Directory.GetFiles(SavePath); + filePaths = Directory.GetFiles(SavePath).ToList(); + subDirectories = Directory.GetDirectories(SavePath); } catch (Exception e) { @@ -585,6 +586,19 @@ namespace Barotrauma 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) { //Map savedMap = new Map(mapPath); diff --git a/Subsurface/Source/Networking/NetStats.cs b/Subsurface/Source/Networking/NetStats.cs index 8fc3c3ddc..0bc89f864 100644 --- a/Subsurface/Source/Networking/NetStats.cs +++ b/Subsurface/Source/Networking/NetStats.cs @@ -78,7 +78,7 @@ namespace Barotrauma.Networking 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); spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s", diff --git a/Subsurface/Source/Networking/NetworkEvent.cs b/Subsurface/Source/Networking/NetworkEvent.cs index ac7a7438f..35f468f1b 100644 --- a/Subsurface/Source/Networking/NetworkEvent.cs +++ b/Subsurface/Source/Networking/NetworkEvent.cs @@ -132,7 +132,7 @@ namespace Barotrauma.Networking 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); if (e == null) return false; @@ -189,13 +189,13 @@ namespace Barotrauma.Networking 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(); } - catch + catch (Exception exception) { #if DEBUG - DebugConsole.ThrowError("Received invalid network message"); + DebugConsole.ThrowError("Received invalid network message", exception); #endif return false; }