diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index 0316478b6..52b7a1885 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -319,6 +319,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -337,6 +343,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/Subsurface/Content/Characters/Human/fhead5.png b/Subsurface/Content/Characters/Human/fhead5.png new file mode 100644 index 000000000..cdb1d330d Binary files /dev/null and b/Subsurface/Content/Characters/Human/fhead5.png differ diff --git a/Subsurface/Content/Characters/Human/fhead6.png b/Subsurface/Content/Characters/Human/fhead6.png new file mode 100644 index 000000000..101c61040 Binary files /dev/null and b/Subsurface/Content/Characters/Human/fhead6.png differ diff --git a/Subsurface/Content/Characters/Human/head5.png b/Subsurface/Content/Characters/Human/head5.png new file mode 100644 index 000000000..7395e91c1 Binary files /dev/null and b/Subsurface/Content/Characters/Human/head5.png differ diff --git a/Subsurface/Content/Characters/Human/head6.png b/Subsurface/Content/Characters/Human/head6.png new file mode 100644 index 000000000..3d8295cd7 Binary files /dev/null and b/Subsurface/Content/Characters/Human/head6.png differ diff --git a/Subsurface/Content/Characters/Human/human.xml b/Subsurface/Content/Characters/Human/human.xml index b94ee1a85..b9639f525 100644 --- a/Subsurface/Content/Characters/Human/human.xml +++ b/Subsurface/Content/Characters/Human/human.xml @@ -1,5 +1,5 @@  - + diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs index 7000b67a3..21a1fa076 100644 --- a/Subsurface/Source/Characters/AICharacter.cs +++ b/Subsurface/Source/Characters/AICharacter.cs @@ -112,9 +112,7 @@ namespace Barotrauma return true; case NetworkEventType.EntityUpdate: if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; - - message.Write((float)NetTime.Now); - + 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); @@ -127,8 +125,8 @@ namespace Barotrauma return true; } - - public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data) + + public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data) { data = null; Enabled = true; @@ -182,11 +180,9 @@ namespace Barotrauma aiController.ReadNetworkData(message); return; case NetworkEventType.EntityUpdate: - float sendingTime = 0.0f; Vector2 targetMovement = Vector2.Zero; bool targetDir = false; - - sendingTime = message.ReadFloat(); + if (sendingTime <= LastNetworkUpdate) return; Vector2 pos = Vector2.Zero, vel = Vector2.Zero; diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index a4f5c360f..cfacf2c26 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -581,19 +581,7 @@ namespace Barotrauma } } } - - public void CreateUpdateNetworkEvent(bool isClient) - { - //new NetworkEvent(importantUpdateTimer <= 0 ? NetworkEventType.ImportantEntityUpdate : NetworkEventType.EntityUpdate, ID, isClient); - - new NetworkEvent(NetworkEventType.EntityUpdate, ID, isClient); - - - //importantUpdateTimer -= 1; - //if (importantUpdateTimer < 0) importantUpdateTimer = (this is AICharacter) ? 30 : 10; - } - - + public bool HasSelectedItem(Item item) { return selectedItems.Contains(item); @@ -1035,7 +1023,7 @@ namespace Barotrauma health -= attackResult.Damage; if (health <= 0.0f && damageType == DamageType.Burn) Kill(CauseOfDeath.Burn); - bleeding += attackResult.Bleeding; + Bleeding += attackResult.Bleeding; return attackResult; } @@ -1274,9 +1262,6 @@ namespace Barotrauma return true; case NetworkEventType.EntityUpdate: - - message.Write((float)NetTime.Now); - message.Write(keys[(int)InputType.Use].DequeueHeld); bool secondaryHeld = keys[(int)InputType.Aim].DequeueHeld; @@ -1321,7 +1306,7 @@ namespace Barotrauma } } - public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data) + public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data) { Enabled = true; data = null; @@ -1362,7 +1347,7 @@ namespace Barotrauma if (GameMain.Server != null) { Client sender =GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection); - if (sender ==null || sender.Character != this) + if (sender == null || sender.Character != this) throw new Exception("Received a KillCharacter message from someone else than the client controlling the Character!"); } @@ -1390,7 +1375,7 @@ namespace Barotrauma return; case NetworkEventType.InventoryUpdate: if (inventory == null) return; - inventory.ReadNetworkData(NetworkEventType.InventoryUpdate, message); + inventory.ReadNetworkData(NetworkEventType.InventoryUpdate, message, sendingTime); return; case NetworkEventType.ImportantEntityUpdate: @@ -1406,8 +1391,7 @@ namespace Barotrauma Bleeding = message.ReadRangedSingle(0.0f, 5.0f, 8); return; - case NetworkEventType.EntityUpdate: - float sendingTime = 0.0f; + case NetworkEventType.EntityUpdate: Vector2 relativeCursorPos = Vector2.Zero; bool actionKeyState, secondaryKeyState; @@ -1416,8 +1400,6 @@ namespace Barotrauma try { - sendingTime = message.ReadFloat(); - if (sendingTime > LastNetworkUpdate) ClearInputs(); actionKeyState = message.ReadBoolean(); diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index 297d8c7b5..162931585 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -55,7 +55,7 @@ namespace Barotrauma headSpriteId = value; Vector2 spriteRange = headSpriteRange[gender == Gender.Male ? 0 : 1]; - if (headSpriteId < (int)spriteRange.X) headSpriteId = (int)(spriteRange.Y-1); + if (headSpriteId < (int)spriteRange.X) headSpriteId = (int)(spriteRange.Y); if (headSpriteId > (int)spriteRange.Y) headSpriteId = (int)(spriteRange.X); if (headSpriteId != oldId) headSprite = null; diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 0702b12a5..dc3c86612 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -27,10 +27,13 @@ namespace Barotrauma static class DebugConsole { - public static List messages = new List(); + public static List Messages = new List(); static bool isOpen; + + static GUIFrame frame; + static GUIListBox listBox; static GUITextBox textBox; //used for keeping track of the message entered when pressing up/down @@ -42,9 +45,20 @@ namespace Barotrauma } public static void Init(GameWindow window) - { - textBox = new GUITextBox(new Rectangle(30, 480,780, 30), Color.Black, Color.White, Alignment.Left, Alignment.Left); - NewMessage("Press F3 to open/close the debug console", Color.Cyan); + { + int x = 20, y = 20; + int width = 800, height = 500; + + frame = new GUIFrame(new Rectangle(x, y, width, height), new Color(0.4f, 0.4f, 0.4f, 0.5f)); + frame.Color = Color.White * 0.4f; + frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); + + listBox = new GUIListBox(new Rectangle(0,0,0, frame.Rect.Height-40), Color.Black*0.8f, null, frame); + + textBox = new GUITextBox(new Rectangle(0,0,0,20), Color.Black*0.6f, Color.White, Alignment.BottomLeft, Alignment.Left, null, frame); + NewMessage("Press F3 to open/close the debug console", Color.Cyan); + NewMessage("Enter ''help'' for a list of available console commands", Color.Cyan); + } public static void Update(GameMain game, float deltaTime) @@ -81,18 +95,18 @@ namespace Barotrauma if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Enter) && textBox.Text != "") { - messages.Add(new ColoredText(textBox.Text, Color.White)); + NewMessage(textBox.Text, Color.White); ExecuteCommand(textBox.Text, game); textBox.Text = ""; - selectedIndex = messages.Count; + //selectedIndex = messages.Count; } } } private static void SelectMessage(int direction) { - int messageCount = messages.Count; + int messageCount = listBox.children.Count; if (messageCount == 0) return; direction = Math.Min(Math.Max(-1, direction), 1); @@ -101,42 +115,43 @@ namespace Barotrauma if (selectedIndex < 0) selectedIndex = messageCount - 1; selectedIndex = selectedIndex % messageCount; - textBox.Text = messages[selectedIndex].Text; + textBox.Text = (listBox.children[selectedIndex] as GUITextBlock).Text; } public static void Draw(SpriteBatch spriteBatch) { if (!isOpen) return; - int x = 20, y = 20; - int width = 800, height = 500; + frame.Update(1.0f / 60.0f); int margin = 5; - GUI.DrawRectangle(spriteBatch, - new Vector2(x, y), - new Vector2(width, height), - new Color(0.4f, 0.4f, 0.4f, 0.6f), true); + //GUI.DrawRectangle(spriteBatch, + // new Vector2(x, y), + // new Vector2(width, height), + // new Color(0.4f, 0.4f, 0.4f, 0.6f), true); - GUI.DrawRectangle(spriteBatch, - new Vector2(x + margin, y + margin), - new Vector2(width - margin * 2, height - margin * 2), - new Color(0.0f, 0.0f, 0.0f, 0.6f), true); + //GUI.DrawRectangle(spriteBatch, + // new Vector2(x + margin, y + margin), + // new Vector2(width - margin * 2, height - margin * 2), + // new Color(0.0f, 0.0f, 0.0f, 0.6f), true); //remove messages that won't fit on the screen - while (messages.Count() * 20 > height-70) - { - messages.RemoveAt(0); - } + //while (messages.Count() * 20 > height - 70) + //{ + // messages.RemoveAt(0); + //} - Vector2 messagePos = new Vector2(x + margin * 2, y + height - 70 - messages.Count()*20); - foreach (ColoredText message in messages) - { - spriteBatch.DrawString(GUI.Font, message.Text, messagePos, message.Color); - messagePos.Y += 20; - } + //Vector2 messagePos = new Vector2(x + margin * 2, y + height - 70 - messages.Count()*20); + //foreach (ColoredText message in messages) + //{ + // spriteBatch.DrawString(GUI.Font, message.Text, messagePos, message.Color); + // messagePos.Y += 20; + //} - textBox.Draw(spriteBatch); + //textBox.Draw(spriteBatch); + + frame.Draw(spriteBatch); } public static void ExecuteCommand(string command, GameMain game) @@ -154,6 +169,49 @@ namespace Barotrauma switch (commands[0].ToLower()) { + case "help": + NewMessage("menu: go to main menu", Color.Cyan); + NewMessage("game: enter the ''game screen''", Color.Cyan); + NewMessage("edit: switch to submarine editor", Color.Cyan); + NewMessage("load [submarine name]: load a submarine!", Color.Cyan); + NewMessage("save [submarine name]: save the current submarine using the specified name", Color.Cyan); + + NewMessage(" ", Color.Cyan); + + + NewMessage("spawn: spawn a creature at a random spawnpoint", Color.Cyan); + NewMessage("spawn: spawn a creature at a random spawnpoint", Color.Cyan); + + NewMessage(" ", Color.Cyan); + + NewMessage("lights: disable lighting", Color.Cyan); + NewMessage("los: disable the line of sight effect", Color.Cyan); + NewMessage("freecam: detach the camera from the controlled character", Color.Cyan); + NewMessage("control [character name]: start controlling the specified character", Color.Cyan); + + NewMessage(" ", Color.Cyan); + + NewMessage("water: allows adding water into rooms or removing it by holding the left/right mouse buttons", Color.Cyan); + NewMessage("fire: allows putting up fires by left clicking", Color.Cyan); + + NewMessage(" ", Color.Cyan); + + NewMessage("heal: restore the controlled character to full health", Color.Cyan); + + NewMessage(" ", Color.Cyan); + + NewMessage("fixwalls: fixes all the walls", Color.Cyan); + NewMessage("fixitems: fixes every item/device in the sub", Color.Cyan); + NewMessage("oxygen: replenishes the oxygen in every room to 100%", Color.Cyan); + NewMessage("power [amount]: immediately sets the temperature of the reactor to the specified value", Color.Cyan); + + NewMessage(" ", Color.Cyan); + + NewMessage("debugdraw: toggles the ''debug draw mode''", Color.Cyan); + NewMessage("netstats: toggles the visibility of the network statistics panel", Color.Cyan); + + + break; case "createfilelist": UpdaterUtil.SaveFileList("filelist.xml"); break; @@ -264,10 +322,13 @@ namespace Barotrauma Item reactorItem = Item.ItemList.Find(i => i.GetComponent() != null); if (reactorItem == null) return; + float power = 5000.0f; + if (commands.Length>1) float.TryParse(commands[1], out power); + var reactor = reactorItem.GetComponent(); reactor.ShutDownTemp = 7000.0f; reactor.AutoTemp = true; - reactor.Temperature = 5000.0f; + reactor.Temperature = power; break; case "shake": GameMain.GameScreen.Cam.Shake = 10.0f; @@ -357,9 +418,26 @@ namespace Barotrauma public static void NewMessage(string msg, Color color) { if (String.IsNullOrEmpty((msg))) return; - messages.Add(new ColoredText(msg, color)); - if (textBox != null && textBox.Text == "") selectedIndex = messages.Count; + Messages.Add(new ColoredText(msg, color)); + + try + { + var textBlock = new GUITextBlock(new Rectangle(0, 0, 0, 15), msg, GUI.Style, Alignment.TopLeft, Alignment.Left, null, true, GUI.SmallFont); + textBlock.CanBeFocused = false; + textBlock.TextColor = color; + + listBox.AddChild(textBlock); + listBox.BarScroll = 1.0f; + } + catch + { + return; + } + + //messages.Add(new ColoredText(msg, color)); + + if (textBox != null && textBox.Text == "") selectedIndex = listBox.children.Count; } public static void ThrowError(string error, Exception e = null) diff --git a/Subsurface/Source/GUI/GUIListBox.cs b/Subsurface/Source/GUI/GUIListBox.cs index ea5cb8e11..47c9b8310 100644 --- a/Subsurface/Source/GUI/GUIListBox.cs +++ b/Subsurface/Source/GUI/GUIListBox.cs @@ -122,7 +122,7 @@ namespace Barotrauma scrollBarHidden = true; scrollBar = new GUIScrollBar( - new Rectangle(this.rect.X + this.rect.Width-20, this.rect.Y, 20, this.rect.Height), color, 1.0f, style); + new Rectangle(this.rect.X + this.rect.Width-20, this.rect.Y, 20, this.rect.Height), color, 1.0f, GUI.Style); frame = new GUIFrame(Rectangle.Empty, style, this); if (style != null) style.Apply(frame, this); diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 8d9b9d95b..c43a43202 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -203,8 +203,10 @@ namespace Barotrauma } - private Vector2 MeasureText(string text) + private Vector2 MeasureText(string text) { + if (string.IsNullOrEmpty(text) || Font==null) return Vector2.Zero; + Vector2 size = Vector2.Zero; while (size == Vector2.Zero) { diff --git a/Subsurface/Source/GUI/TitleScreen.cs b/Subsurface/Source/GUI/TitleScreen.cs index a79b05e78..64df0902b 100644 --- a/Subsurface/Source/GUI/TitleScreen.cs +++ b/Subsurface/Source/GUI/TitleScreen.cs @@ -99,7 +99,10 @@ namespace Barotrauma graphics.SetRenderTarget(null); - Hull.renderer.RenderBack(spriteBatch, renderTarget, 0.0f); + if (Hull.renderer != null) + { + Hull.renderer.RenderBack(spriteBatch, renderTarget, 0.0f); + } spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied); diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 40c510c6d..ae0f61228 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -181,8 +181,15 @@ namespace Barotrauma sw = new Stopwatch(); + + GUIComponent.Init(Window); + DebugConsole.Init(Window); + yield return CoroutineStatus.Running; + LightManager = new Lights.LightManager(GraphicsDevice); + + Hull.renderer = new WaterRenderer(GraphicsDevice); TitleScreen.LoadState = 1.0f; yield return CoroutineStatus.Running; @@ -235,10 +242,6 @@ namespace Barotrauma ParticleManager = new ParticleManager("Content/Particles/ParticlePrefabs.xml", Cam); yield return CoroutineStatus.Running; - GUIComponent.Init(Window); - DebugConsole.Init(Window); - yield return CoroutineStatus.Running; - LocationType.Init("Content/Map/locationTypes.xml"); MainMenuScreen.Select(); yield return CoroutineStatus.Running; diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 9e722f7d1..95c3fed58 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -475,8 +475,10 @@ namespace Barotrauma return true; } - public override void ReadNetworkData(NetworkEventType type, NetBuffer message) + public override void ReadNetworkData(NetworkEventType type, NetBuffer message, float sendingTime) { + if (sendingTime < lastUpdate) return; + character.ClearInput(InputType.Use); for (int i = 0; i newItemIDs = new List(); byte count = message.ReadByte(); @@ -350,6 +354,8 @@ namespace Barotrauma TryPutItem(item, item.AllowedSlots, false); } + + lastUpdate = sendingTime; } } } diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 99f0188b9..8a09a75c8 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -1249,8 +1249,9 @@ namespace Barotrauma if (componentIndex < 0 || componentIndex >= components.Count) return false; message.Write((byte)componentIndex); - components[componentIndex].FillNetworkData(type, message); - break; + bool sent = components[componentIndex].FillNetworkData(type, message); + if (sent) components[componentIndex].NetworkUpdateSent = true; + return sent; case NetworkEventType.UpdateProperty: var allProperties = GetProperties(); @@ -1292,7 +1293,7 @@ namespace Barotrauma return true; } - public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data) + public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data) { data = null; @@ -1319,7 +1320,7 @@ namespace Barotrauma var itemContainer = GetComponent(); if (itemContainer == null || itemContainer.inventory == null) return; - itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message); + itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message, sendingTime); break; case NetworkEventType.ComponentUpdate: case NetworkEventType.ImportantComponentUpdate: @@ -1328,7 +1329,9 @@ namespace Barotrauma data = componentIndex; if (componentIndex < 0 || componentIndex > components.Count - 1) return; - components[componentIndex].ReadNetworkData(type, message); + + components[componentIndex].NetworkUpdateSent = true; + components[componentIndex].ReadNetworkData(type, message, sendingTime); break; case NetworkEventType.UpdateProperty: string propertyName = ""; diff --git a/Subsurface/Source/Map/Entity.cs b/Subsurface/Source/Map/Entity.cs index 61ab82b0b..c447765c2 100644 --- a/Subsurface/Source/Map/Entity.cs +++ b/Subsurface/Source/Map/Entity.cs @@ -69,7 +69,7 @@ namespace Barotrauma { return false; } - public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data) + public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data) { data = null; } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 36c8dbce2..8d2a10cf4 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -559,7 +559,7 @@ namespace Barotrauma return true; } - public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, out object data) + public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime, out object data) { data = null; diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 56bec7748..718a604e8 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -639,8 +639,6 @@ namespace Barotrauma public override bool FillNetworkData(NetworkEventType type, NetBuffer message, object data) { - message.Write((float)NetTime.Now); - //var updateSections = Array.FindAll(sections, s => s != null && Math.Abs(s.damage - s.lastSentDamage) > 0.01f); //if (updateSections.Length == 0) return false; @@ -662,12 +660,11 @@ namespace Barotrauma return true; } - public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data) + public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data) { data = null; - float updateTime = message.ReadFloat(); - if (updateTime < lastUpdate) return; + if (sendingTime < lastUpdate) return; // int sectionCount = message.ReadByte(); @@ -681,7 +678,7 @@ namespace Barotrauma SetDamage(i, damage); } - lastUpdate = updateTime; + lastUpdate = sendingTime; } } diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index 5289b6029..5b09cdaa8 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -391,7 +391,6 @@ namespace Barotrauma { if (subBody == null) return false; - message.Write((float)NetTime.Now); message.Write(Position.X); message.Write(Position.Y); @@ -401,16 +400,13 @@ namespace Barotrauma return true; } - public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message, out object data) + public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data) { data = null; - float sendingTime; Vector2 newTargetPosition, newSpeed; try { - sendingTime = message.ReadFloat(); - if (sendingTime <= lastNetworkUpdate) return; newTargetPosition = new Vector2(message.ReadFloat(), message.ReadFloat()); diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index dc03390e7..ba08ee4b4 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -195,9 +195,19 @@ namespace Barotrauma Vector2 translateAmount = speed * deltaTime; translateAmount += ConvertUnits.ToDisplayUnits(body.Position) * collisionRigidness; - if (targetPosition != Vector2.Zero && Vector2.Distance(targetPosition, sub.Position) > 50.0f) + if (targetPosition != Vector2.Zero && targetPosition != sub.Position) { - translateAmount += (targetPosition - sub.Position) * 0.01f; + float dist = Vector2.Distance(targetPosition, sub.Position); + + if (dist>1000.0f) + { + sub.SetPosition(targetPosition); + targetPosition = Vector2.Zero; + } + else if (dist>50.0f) + { + translateAmount += (targetPosition - sub.Position) * 0.01f; + } } else { diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index e704debdb..e5fb122e0 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -360,7 +360,7 @@ namespace Barotrauma.Networking } else if (gameStarted) { - myCharacter.CreateUpdateNetworkEvent(true); + new NetworkEvent(NetworkEventType.EntityUpdate, myCharacter.ID, true); } } diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index e58c7b9f2..86acbfe01 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -282,7 +282,7 @@ namespace Barotrauma.Networking { if (gameStarted) { - if (myCharacter != null) myCharacter.CreateUpdateNetworkEvent(false); + if (myCharacter != null) new NetworkEvent(NetworkEventType.EntityUpdate, myCharacter.ID, false); foreach (Character c in Character.CharacterList) { @@ -290,7 +290,7 @@ namespace Barotrauma.Networking if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; - c.CreateUpdateNetworkEvent(false); + new NetworkEvent(NetworkEventType.EntityUpdate, c.ID, false); } } @@ -316,7 +316,9 @@ namespace Barotrauma.Networking foreach (Character c in Character.CharacterList) { - if (c is AICharacter || c.IsDead) continue; + if (c.IsDead) continue; + + if (c is AICharacter && c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false); } @@ -652,8 +654,6 @@ namespace Barotrauma.Networking new NetworkEvent(NetworkEventType.ImportantEntityUpdate, hull.ID, false); } - SendNetworkEvents(new List() { sender }); - foreach (Character c in Character.CharacterList) { new NetworkEvent(NetworkEventType.EntityUpdate, c.ID, false); @@ -661,17 +661,30 @@ namespace Barotrauma.Networking if (c.IsDead) new NetworkEvent(NetworkEventType.KillCharacter, c.ID, false); } - SendNetworkEvents(new List() { sender }); - foreach (Item item in Item.ItemList) { + for (int i = 0; i < item.components.Count; i++) + { + if (!item.components[i].NetworkUpdateSent) continue; + item.NewComponentEvent(item.components[i], false, true); + } + if (item.body == null || item.body.Enabled == false) continue; new NetworkEvent(NetworkEventType.DropItem, item.ID, false); } - SendNetworkEvents(new List() { sender }); + List syncMessages = new List(NetworkEvent.Events); + while (syncMessages.Any()) + { + NetworkEvent.Events = syncMessages.GetRange(0, Math.Min(syncMessages.Count, 5)); + SendNetworkEvents(new List() { sender }); + syncMessages.RemoveRange(0, Math.Min(syncMessages.Count, 5)); + NetworkEvent.Events = existingEvents; + yield return new WaitForSeconds(0.1f); + } + yield return CoroutineStatus.Success; } diff --git a/Subsurface/Source/Networking/NetworkEvent.cs b/Subsurface/Source/Networking/NetworkEvent.cs index 98a5a9519..2d767393f 100644 --- a/Subsurface/Source/Networking/NetworkEvent.cs +++ b/Subsurface/Source/Networking/NetworkEvent.cs @@ -151,6 +151,8 @@ namespace Barotrauma.Networking public static void ReadMessage(NetIncomingMessage message, bool resend=false) { + float sendingTime = message.ReadFloat(); + byte msgCount = message.ReadByte(); long currPos = message.PositionInBytes; @@ -161,7 +163,7 @@ namespace Barotrauma.Networking try { - NetworkEvent.ReadData(message, resend); + NetworkEvent.ReadData(message, sendingTime, resend); } catch { @@ -173,7 +175,7 @@ namespace Barotrauma.Networking } } - public static bool ReadData(NetIncomingMessage message, bool resend=false) + public static bool ReadData(NetIncomingMessage message, float sendingTime, bool resend=false) { NetworkEventType eventType; ushort id; @@ -207,7 +209,7 @@ namespace Barotrauma.Networking try { - e.ReadNetworkData(eventType, message, out data); + e.ReadNetworkData(eventType, message, sendingTime, out data); } catch (Exception exception) { diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index dc58bc30d..b4c7ffde7 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -145,6 +145,8 @@ namespace Barotrauma.Networking NetOutgoingMessage message = netPeer.CreateMessage(); message.Write((byte)PacketTypes.NetworkEvent); + message.Write((float)NetTime.Now); + message.Write((byte)msgBytes.Count); foreach (byte[] msgData in msgBytes) { diff --git a/Subsurface/Source/Program.cs b/Subsurface/Source/Program.cs index dd2d14c37..1da42ebc8 100644 --- a/Subsurface/Source/Program.cs +++ b/Subsurface/Source/Program.cs @@ -58,7 +58,7 @@ namespace Barotrauma sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name); sb.AppendLine("Level seed: "+ ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed)); sb.AppendLine("Loaded submarine: " + ((Submarine.Loaded == null) ? "none" : Submarine.Loaded.Name +" ("+Submarine.Loaded.MD5Hash+")")); - sb.AppendLine("Selected screen: " + Screen.Selected.ToString()); + sb.AppendLine("Selected screen: " + (Screen.Selected == null ? "None" : Screen.Selected.ToString())); if (GameMain.Server != null) { @@ -80,9 +80,9 @@ namespace Barotrauma sb.AppendLine("\n"); sb.AppendLine("Last debug messages:"); - for (int i = DebugConsole.messages.Count - 1; i > 0 && i > DebugConsole.messages.Count - 10; i-- ) + for (int i = DebugConsole.Messages.Count - 1; i > 0 && i > DebugConsole.Messages.Count - 10; i-- ) { - sb.AppendLine(" "+DebugConsole.messages[i].Time+" - "+DebugConsole.messages[i].Text); + sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text); } diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 2bad0af0a..8ecac5e38 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ