Submarine position is synced using the same logic as the characters, AICharacter position syncing

This commit is contained in:
Regalis
2016-10-25 19:01:19 +03:00
parent ac8edb5b2a
commit 07f8c966ab
12 changed files with 234 additions and 256 deletions
+10 -5
View File
@@ -254,10 +254,7 @@ namespace Barotrauma
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
AnimController.TargetMovement = targetMovement;
AnimController.MainLimb.body.TargetPosition = pos;
//AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
if (inSub)
{
Hull newHull = Hull.FindHull(ConvertUnits.ToDisplayUnits(pos), AnimController.CurrentHull, false);
@@ -267,7 +264,15 @@ namespace Barotrauma
Submarine = newHull.Submarine;
}
}
int index = 0;
while (index < memPos.Count && sendingTime > memPos[index].Timestamp)
{
index++;
}
memPos.Insert(index, new PosInfo(pos, (targetDir) ? Direction.Right : Direction.Left, sendingTime));
LastNetworkUpdate = sendingTime;
break;
}
@@ -195,6 +195,8 @@ namespace Barotrauma
for (int i = 0; i < Limbs.Count(); i++)
{
if (Limbs[i].SteerForce <= 0.0f) continue;
Vector2 pullPos = Limbs[i].pullJoint == null ? Limbs[i].SimPosition : Limbs[i].pullJoint.WorldAnchorA;
Limbs[i].body.ApplyForce(movement * Limbs[i].SteerForce * Limbs[i].Mass, pullPos);
+8 -34
View File
@@ -14,33 +14,6 @@ using System.Xml.Linq;
namespace Barotrauma
{
struct PosInfo
{
public readonly Vector2 Position;
public readonly Direction Direction;
public readonly float Timestamp;
public readonly UInt32 ID;
public PosInfo(Vector2 pos, Direction dir, float time)
{
Position = pos;
Direction = dir;
Timestamp = time;
ID = 0;
}
public PosInfo(Vector2 pos, Direction dir, UInt32 ID)
{
Position = pos;
Direction = dir;
this.ID = ID;
Timestamp = 0.0f;
}
}
class Character : Entity, IDamageable, IPropertyObject
{
public static List<Character> CharacterList = new List<Character>();
@@ -53,7 +26,7 @@ namespace Barotrauma
get { return netStateID; }
}
List<PosInfo> memPos = new List<PosInfo>();
protected List<PosInfo> memPos = new List<PosInfo>();
private bool networkUpdateSent;
List<PosInfo> memLocalPos = new List<PosInfo>();
@@ -2148,14 +2121,15 @@ namespace Barotrauma
else
{
cursorPosition = Position + new Vector2(1000.0f, 0.0f) * dir;
//AnimController.TargetDir = dir < 0 ? Direction.Left : Direction.Right;
}
int index = 0;
while (index < memPos.Count && sendingTime > memPos[index].Timestamp)
{
index++;
}
//AnimController.RefLimb.body.TargetPosition =
// AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
memPos.Add(new PosInfo(pos, dir < 0 ? Direction.Left : Direction.Right, sendingTime));
memPos.Insert(index, new PosInfo(pos, dir < 0 ? Direction.Left : Direction.Right, sendingTime));
LastNetworkUpdate = sendingTime;