Sending NetTime at the start of a combined networkevent instead of individual networkevents, syncing itemcomponents for spectators, AICharacter importantentityupdates are sent again, misc bugfixes, some new heads

This commit is contained in:
Regalis
2015-11-20 17:12:33 +02:00
parent 8ec7fd44ff
commit cddf4f1bde
37 changed files with 269 additions and 130 deletions

View File

@@ -319,6 +319,12 @@
<Content Include="Content\Characters\Human\fhead4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\fhead5.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\fhead6.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\firstnames.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -337,6 +343,12 @@
<Content Include="Content\Characters\Human\head4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\head5.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\head6.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\lastnames.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<Character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,4" femaleheadid="1,4" drowningtime="30">
<Character name ="human" humanoid="true" needsair="true" genders="true" maleheadid="1,6" femaleheadid="1,6" drowningtime="30">
<name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" />

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -27,10 +27,13 @@ namespace Barotrauma
static class DebugConsole
{
public static List<ColoredText> messages = new List<ColoredText>();
public static List<ColoredText> Messages = new List<ColoredText>();
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<Reactor>() != null);
if (reactorItem == null) return;
float power = 5000.0f;
if (commands.Length>1) float.TryParse(commands[1], out power);
var reactor = reactorItem.GetComponent<Reactor>();
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)

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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;

View File

@@ -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<capacity; i++)
@@ -496,6 +498,7 @@ namespace Barotrauma
}
}
lastUpdate = sendingTime;
}
}

View File

@@ -263,13 +263,15 @@ namespace Barotrauma.Items.Components
}
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write(item.SimPosition.X);
message.Write(item.SimPosition.Y);
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
Vector2 newPos = Vector2.Zero;

View File

@@ -79,6 +79,8 @@ namespace Barotrauma.Items.Components
get { return updated; }
set { updated = value; }
}
public bool NetworkUpdateSent;
public virtual bool IsActive
{
@@ -701,11 +703,12 @@ namespace Barotrauma.Items.Components
return ic;
}
public virtual void FillNetworkData(NetworkEventType type, NetBuffer message)
public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message)
{
return false;
}
public virtual void ReadNetworkData(NetworkEventType type, NetBuffer message)
public virtual void ReadNetworkData(NetworkEventType type, NetBuffer message, float sendingTime)
{
}
}

View File

@@ -14,6 +14,8 @@ namespace Barotrauma.Items.Components
float? targetLevel;
float lastUpdate;
Hull hull1, hull2;
[HasDefaultValue(0.0f, true)]
@@ -125,12 +127,12 @@ namespace Barotrauma.Items.Components
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "OUT", false))
{
FlowPercentage -= 10.0f;
item.NewComponentEvent(this, true, false);
item.NewComponentEvent(this, true, true);
}
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "IN", false))
{
FlowPercentage += 10.0f;
item.NewComponentEvent(this, true, false);
item.NewComponentEvent(this, true, true);
}
}
@@ -166,18 +168,22 @@ namespace Barotrauma.Items.Components
if (!IsActive) currPowerConsumption = 0.0f;
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.WriteRangedInteger(-10,10,(int)(flowPercentage/10.0f));
message.Write(IsActive);
message.WritePadBits();
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
float newFlow = 0.0f;
bool newActive;
if (sendingTime < lastUpdate) return;
try
{
newFlow = message.ReadRangedInteger(-10,10)*10.0f;
@@ -194,6 +200,8 @@ namespace Barotrauma.Items.Components
FlowPercentage = newFlow;
IsActive = newActive;
lastUpdate = sendingTime;
}
}
}

View File

@@ -301,12 +301,14 @@ namespace Barotrauma.Items.Components
spriteBatch.DrawString(GUI.SmallFont, (int)(dist / 80.0f) + " m", new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen);
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write(IsActive);
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
try
{

View File

@@ -46,6 +46,8 @@ namespace Barotrauma.Items.Components
private float load;
private float lastUpdate;
private PropertyTask powerUpTask;
[Editable, HasDefaultValue(9500.0f, true)]
@@ -445,7 +447,7 @@ namespace Barotrauma.Items.Components
}
}
public override void FillNetworkData(NetworkEventType type, NetBuffer message)
public override bool FillNetworkData(NetworkEventType type, NetBuffer message)
{
message.Write(autoTemp);
message.WriteRangedSingle(temperature, 0.0f, 10000.0f, 16);
@@ -453,10 +455,14 @@ namespace Barotrauma.Items.Components
message.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8);
message.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
return true;
}
public override void ReadNetworkData(NetworkEventType type, NetBuffer message)
public override void ReadNetworkData(NetworkEventType type, NetBuffer message, float sendingTime)
{
if (sendingTime < lastUpdate) return;
bool newAutoTemp;
float newTemperature, newShutDownTemp;
float newCoolingRate, newFissionRate;
@@ -486,6 +492,8 @@ namespace Barotrauma.Items.Components
CoolingRate = newCoolingRate;
FissionRate = newFissionRate;
lastUpdate = sendingTime;
}
}
}

View File

@@ -209,15 +209,17 @@ namespace Barotrauma.Items.Components
}
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write(targetVelocity.X);
message.Write(targetVelocity.Y);
message.Write(autoPilot);
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
Vector2 newTargetVelocity = Vector2.Zero;
bool newAutoPilot = false;

View File

@@ -196,13 +196,15 @@ namespace Barotrauma.Items.Components
}
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.WriteRangedSingle(MathHelper.Clamp(rechargeSpeed/MaxRechargeSpeed, 0.0f, 1.0f), 0.0f, 1.0f, 8);
message.WriteRangedSingle(MathHelper.Clamp(charge/capacity,0.0f, 1.0f), 0.0f, 1.0f, 8);
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
float newRechargeSpeed = 0f;
float newCharge = 0.0f;

View File

@@ -124,7 +124,7 @@ namespace Barotrauma.Items.Components
base.Remove();
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
foreach (Connection c in connections)
{
@@ -135,9 +135,11 @@ namespace Barotrauma.Items.Components
message.Write(wires[i].Item.ID);
}
}
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
System.Diagnostics.Debug.WriteLine("connectionpanel update");
foreach (Connection c in connections)

View File

@@ -428,7 +428,7 @@ namespace Barotrauma.Items.Components
base.Remove();
}
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write((byte)Math.Min(Nodes.Count, 10));
for (int i = 0; i < Math.Min(Nodes.Count,10); i++)
@@ -436,9 +436,11 @@ namespace Barotrauma.Items.Components
message.Write(Nodes[i].X);
message.Write(Nodes[i].Y);
}
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message, float sendingTime)
{
Nodes.Clear();

View File

@@ -16,6 +16,8 @@ namespace Barotrauma
public readonly Entity Owner;
protected float lastUpdate;
private int slotsPerRow;
public int SlotsPerRow
@@ -324,8 +326,10 @@ namespace Barotrauma
return true;
}
public virtual void ReadNetworkData(NetworkEventType type, NetBuffer message)
public virtual void ReadNetworkData(NetworkEventType type, NetBuffer message, float sendingTime)
{
if (sendingTime < lastUpdate) return;
List<ushort> newItemIDs = new List<ushort>();
byte count = message.ReadByte();
@@ -350,6 +354,8 @@ namespace Barotrauma
TryPutItem(item, item.AllowedSlots, false);
}
lastUpdate = sendingTime;
}
}
}

View File

@@ -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<InGameEditable>();
@@ -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<ItemContainer>();
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 = "";

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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());

View File

@@ -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
{

View File

@@ -360,7 +360,7 @@ namespace Barotrauma.Networking
}
else if (gameStarted)
{
myCharacter.CreateUpdateNetworkEvent(true);
new NetworkEvent(NetworkEventType.EntityUpdate, myCharacter.ID, true);
}
}

View File

@@ -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<Client>() { 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<Client>() { 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<Client>() { sender });
List<NetworkEvent> syncMessages = new List<NetworkEvent>(NetworkEvent.Events);
while (syncMessages.Any())
{
NetworkEvent.Events = syncMessages.GetRange(0, Math.Min(syncMessages.Count, 5));
SendNetworkEvents(new List<Client>() { sender });
syncMessages.RemoveRange(0, Math.Min(syncMessages.Count, 5));
NetworkEvent.Events = existingEvents;
yield return new WaitForSeconds(0.1f);
}
yield return CoroutineStatus.Success;
}

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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);
}

Binary file not shown.