Sending multiple networkevents in one packet, removed limb updates from ImportantEntityUpdate
This commit is contained in:
@@ -1222,21 +1222,21 @@ namespace Barotrauma
|
||||
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
|
||||
int i = 0;
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
//int i = 0;
|
||||
//foreach (Limb limb in AnimController.Limbs)
|
||||
//{
|
||||
// if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
|
||||
message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
// message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
// message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
//message.Write(limb.body.LinearVelocity.X);
|
||||
//message.Write(limb.body.LinearVelocity.Y);
|
||||
// //message.Write(limb.body.LinearVelocity.X);
|
||||
// //message.Write(limb.body.LinearVelocity.Y);
|
||||
|
||||
message.Write(limb.body.Rotation);
|
||||
//message.WriteRangedSingle(MathHelper.Clamp(limb.body.AngularVelocity, -10.0f, 10.0f), -10.0f, 10.0f, 8);
|
||||
i++;
|
||||
}
|
||||
// message.Write(limb.body.Rotation);
|
||||
// //message.WriteRangedSingle(MathHelper.Clamp(limb.body.AngularVelocity, -10.0f, 10.0f), -10.0f, 10.0f, 8);
|
||||
// i++;
|
||||
//}
|
||||
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer,0.0f,60.0f), 0.0f, 60.0f, 8);
|
||||
message.Write((byte)((health/maxHealth)*255.0f));
|
||||
@@ -1366,32 +1366,32 @@ namespace Barotrauma
|
||||
inventory.ReadNetworkData(NetworkEventType.InventoryUpdate, message);
|
||||
return;
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
Vector2 limbPos = limb.SimPosition, vel = Vector2.Zero;
|
||||
float rotation = limb.Rotation;
|
||||
//foreach (Limb limb in AnimController.Limbs)
|
||||
//{
|
||||
// Vector2 limbPos = limb.SimPosition, vel = Vector2.Zero;
|
||||
// float rotation = limb.Rotation;
|
||||
|
||||
try
|
||||
{
|
||||
limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
// try
|
||||
// {
|
||||
// limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
// limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
rotation = message.ReadFloat();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
// rotation = message.ReadFloat();
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (limb.body != null)
|
||||
{
|
||||
limb.body.TargetVelocity = limb.body.LinearVelocity;
|
||||
limb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
|
||||
limb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
|
||||
limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
|
||||
}
|
||||
// if (limb.body != null)
|
||||
// {
|
||||
// limb.body.TargetVelocity = limb.body.LinearVelocity;
|
||||
// limb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
|
||||
// limb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
|
||||
// limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
|
||||
// }
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
float newStunTimer = 0.0f, newHealth = 0.0f, newOxygen = 0.0f;
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (!character.Enabled) return;
|
||||
|
||||
UpdateNetplayerPosition();
|
||||
UpdateNetPlayerPosition();
|
||||
|
||||
Vector2 flowForce = Vector2.Zero;
|
||||
|
||||
@@ -654,7 +654,7 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
private void UpdateNetplayerPosition()
|
||||
private void UpdateNetPlayerPosition()
|
||||
{
|
||||
if (refLimb.body.TargetPosition == Vector2.Zero)
|
||||
{
|
||||
@@ -662,18 +662,13 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
//if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
|
||||
float resetDistance = NetConfig.ResetRagdollDistance;
|
||||
|
||||
//if the limb is closer than alloweddistance, just ignore the difference
|
||||
float allowedDistance = NetConfig.AllowedRagdollDistance * ((inWater) ? 2.0f : 1.0f);
|
||||
|
||||
float dist = Vector2.Distance(refLimb.body.SimPosition, refLimb.body.TargetPosition);
|
||||
bool resetAll = dist > resetDistance;
|
||||
if (resetAll)
|
||||
{
|
||||
if (Limbs.FirstOrDefault(limb => !limb.ignoreCollisions && limb.body.TargetPosition == Vector2.Zero) != null) resetAll = false;
|
||||
}
|
||||
|
||||
//if the limb is further away than resetdistance, all limbs are immediately snapped to their targetpositions
|
||||
bool resetAll = dist > NetConfig.ResetRagdollDistance;
|
||||
|
||||
Vector2 diff = (refLimb.body.TargetPosition - refLimb.body.SimPosition);
|
||||
|
||||
@@ -717,16 +712,16 @@ namespace Barotrauma
|
||||
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
if (limb.body.TargetPosition == Vector2.Zero)
|
||||
{
|
||||
//if (limb.body.TargetPosition == Vector2.Zero)
|
||||
//{
|
||||
limb.body.SetTransform(limb.body.SimPosition + diff, limb.body.Rotation);
|
||||
continue;
|
||||
}
|
||||
//continue;
|
||||
//}
|
||||
|
||||
limb.body.LinearVelocity = limb.body.TargetVelocity;
|
||||
limb.body.AngularVelocity = limb.body.TargetAngularVelocity;
|
||||
//limb.body.LinearVelocity = limb.body.TargetVelocity;
|
||||
//limb.body.AngularVelocity = limb.body.TargetAngularVelocity;
|
||||
|
||||
limb.body.SetTransform(limb.body.TargetPosition, limb.body.TargetRotation);
|
||||
//limb.body.SetTransform(limb.body.TargetPosition, limb.body.TargetRotation);
|
||||
limb.body.TargetPosition = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,7 +474,34 @@ namespace Barotrauma.Networking
|
||||
case (byte)PacketTypes.NetworkEvent:
|
||||
//read the data from the message and update client state accordingly
|
||||
if (!gameStarted) break;
|
||||
NetworkEvent.ReadData(inc);
|
||||
|
||||
byte msgCount = inc.ReadByte();
|
||||
|
||||
long currPos = inc.PositionInBytes;
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("msgcount: " + msgCount + " startpos: " + inc.PositionInBytes);
|
||||
for (int i = 0; i < msgCount; i++ )
|
||||
{
|
||||
|
||||
byte msgLength = inc.ReadByte();
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("msglength: "+msgLength);
|
||||
try
|
||||
{
|
||||
NetworkEvent.ReadData(inc);
|
||||
}
|
||||
catch
|
||||
{
|
||||
int afghj = 1;
|
||||
}
|
||||
//+1 because msgLength is one additional byte
|
||||
currPos += msgLength+1;
|
||||
inc.Position = currPos*8;
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("currpos: " + currPos);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case (byte)PacketTypes.UpdateNetLobby:
|
||||
if (gameStarted) continue;
|
||||
|
||||
@@ -635,21 +635,41 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
if (recipients.Count == 0) return;
|
||||
|
||||
foreach (NetworkEvent networkEvent in NetworkEvent.events)
|
||||
|
||||
for (int i = 0; i<2; i++)
|
||||
{
|
||||
bool important = i==0;
|
||||
|
||||
var unreliableEvents = NetworkEvent.events.FindAll(e => e.IsImportant == important);
|
||||
if (unreliableEvents.Count == 0) continue;
|
||||
|
||||
NetOutgoingMessage message = server.CreateMessage();
|
||||
message.Write((byte)PacketTypes.NetworkEvent);
|
||||
//if (!networkEvent.IsClient) continue;
|
||||
|
||||
if (!networkEvent.FillData(message))
|
||||
|
||||
|
||||
List<byte[]> msgBytes = new List<byte[]>();
|
||||
|
||||
foreach (NetworkEvent unreliableEvent in unreliableEvents)
|
||||
{
|
||||
continue;
|
||||
NetOutgoingMessage tempMessage = server.CreateMessage();
|
||||
if (!unreliableEvent.FillData(tempMessage)) continue;
|
||||
tempMessage.WritePadBits();
|
||||
|
||||
tempMessage.Position = 0;
|
||||
msgBytes.Add(tempMessage.ReadBytes(tempMessage.LengthBytes));
|
||||
}
|
||||
|
||||
//Entity e = Entity.FindEntityByID(networkEvent.ID);
|
||||
//if (e == null) continue;
|
||||
if (networkEvent.IsImportant)
|
||||
message.Write((byte)msgBytes.Count);
|
||||
foreach (byte[] msgData in msgBytes)
|
||||
{
|
||||
if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent ("+msgData.Length+" bytes)");
|
||||
|
||||
message.Write((byte)msgData.Length);
|
||||
message.Write(msgData);
|
||||
}
|
||||
|
||||
if (important)
|
||||
{
|
||||
foreach (Client c in recipients)
|
||||
{
|
||||
@@ -666,8 +686,42 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//foreach (NetworkEvent networkEvent in NetworkEvent.events)
|
||||
//{
|
||||
// if (!networkEvent.IsImportant) co
|
||||
// //if (!networkEvent.IsClient) continue;
|
||||
|
||||
// if (!networkEvent.FillData(message))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //Entity e = Entity.FindEntityByID(networkEvent.ID);
|
||||
// //if (e == null) continue;
|
||||
// if (networkEvent.IsImportant)
|
||||
// {
|
||||
// foreach (Client c in recipients)
|
||||
// {
|
||||
// ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
|
||||
// message.Position = 0;
|
||||
// reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes));
|
||||
|
||||
// c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (server.ConnectionsCount>0)
|
||||
// {
|
||||
// server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
NetworkEvent.events.Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
Entity e = Entity.FindEntityByID(id);
|
||||
System.Diagnostics.Debug.WriteLine(e.ToString());
|
||||
if (e == null)
|
||||
{
|
||||
#if DEBUG
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user