Networking optimization/bugfixes (hull water volumes & wall damage are synced, more reliable inventory updates, AICharacter sync changes), proper particle collisions with walls

This commit is contained in:
Regalis
2015-09-25 18:56:39 +03:00
parent 3587b4a4bb
commit 53e729ea11
27 changed files with 50344 additions and 273 deletions
@@ -487,10 +487,17 @@ namespace Subsurface
message.Write(wallAttackPos.Y);
}
//message.Write(Velocity.X);
//message.Write(Velocity.Y);
//message.Write(Character.AnimController.RefLimb.SimPosition.X);
//message.Write(Character.AnimController.RefLimb.SimPosition.Y);
message.Write(MathUtils.AngleToByte(steeringManager.WanderAngle));
message.WriteRangedSingle(MathHelper.Clamp(updateTargetsTimer,0.0f, UpdateTargetsInterval), 0.0f, UpdateTargetsInterval, 8);
message.WriteRangedSingle(MathHelper.Clamp(raycastTimer, 0.0f, RaycastInterval), 0.0f, RaycastInterval, 8);
message.WriteRangedSingle(MathHelper.Clamp(coolDownTimer, 0.0f, attackCoolDown * 2.0f), 0.0f, attackCoolDown * 2.0f, 8);
//message.WriteRangedSingle(MathHelper.Clamp(updateTargetsTimer,0.0f, UpdateTargetsInterval), 0.0f, UpdateTargetsInterval, 8);
//message.WriteRangedSingle(MathHelper.Clamp(raycastTimer, 0.0f, RaycastInterval), 0.0f, RaycastInterval, 8);
//message.WriteRangedSingle(MathHelper.Clamp(coolDownTimer, 0.0f, attackCoolDown * 2.0f), 0.0f, attackCoolDown * 2.0f, 8);
message.Write(targetEntity==null ? -1 : (targetEntity as Entity).ID);
}
@@ -502,6 +509,10 @@ namespace Subsurface
float wanderAngle;
float updateTargetsTimer, raycastTimer, coolDownTimer;
Vector2 newVelocity = Vector2.Zero;
Vector2 targetPosition = Vector2.Zero;
int targetID;
try
@@ -516,10 +527,14 @@ namespace Subsurface
newWallAttackPos = new Vector2(message.ReadFloat(), message.ReadFloat());
}
//newVelocity = new Vector2(message.ReadFloat(), message.ReadFloat());
//targetPosition = new Vector2(message.ReadFloat(), message.ReadFloat());
wanderAngle = MathUtils.ByteToAngle(message.ReadByte());
updateTargetsTimer = message.ReadRangedSingle(0.0f, UpdateTargetsInterval, 8);
raycastTimer = message.ReadRangedSingle(0.0f, RaycastInterval, 8);
coolDownTimer = message.ReadRangedSingle(0.0f, attackCoolDown*2.0f, 8);
//updateTargetsTimer = message.ReadRangedSingle(0.0f, UpdateTargetsInterval, 8);
//raycastTimer = message.ReadRangedSingle(0.0f, RaycastInterval, 8);
//coolDownTimer = message.ReadRangedSingle(0.0f, attackCoolDown*2.0f, 8);
targetID = message.ReadInt32();
}
@@ -529,9 +544,9 @@ namespace Subsurface
wallAttackPos = newWallAttackPos;
steeringManager.WanderAngle = wanderAngle;
this.updateTargetsTimer = updateTargetsTimer;
this.raycastTimer = raycastTimer;
this.coolDownTimer = coolDownTimer;
//this.updateTargetsTimer = updateTargetsTimer;
//this.raycastTimer = raycastTimer;
//this.coolDownTimer = coolDownTimer;
if (targetID > -1)
targetEntity = Entity.FindEntityByID(targetID) as IDamageable;
+11 -6
View File
@@ -59,9 +59,9 @@ namespace Subsurface
aiController.Update(deltaTime);
}
public override AttackResult AddDamage(IDamageable attacker, Vector2 position, Attack attack, bool playSound = false)
public override AttackResult AddDamage(IDamageable attacker, Vector2 position, Attack attack, float deltaTime, bool playSound = false)
{
AttackResult result = base.AddDamage(attacker, position, attack, playSound);
AttackResult result = base.AddDamage(attacker, position, attack, deltaTime, playSound);
aiController.OnAttacked(attacker, (result.Damage + result.Bleeding)/Math.Max(health,1.0f));
@@ -107,6 +107,9 @@ namespace Subsurface
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
message.Write(AnimController.RefLimb.LinearVelocity.X);
message.Write(AnimController.RefLimb.LinearVelocity.Y);
LargeUpdateTimer = Math.Max(0, LargeUpdateTimer - 1);
}
}
@@ -201,19 +204,21 @@ namespace Subsurface
}
else
{
Vector2 pos = Vector2.Zero;
Vector2 pos = Vector2.Zero, vel = Vector2.Zero;
try
{
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
vel.X = message.ReadFloat();
vel.Y = message.ReadFloat();
}
catch { return; }
Limb torso = AnimController.GetLimb(LimbType.Torso);
if (torso == null) torso = AnimController.GetLimb(LimbType.Head);
torso.body.TargetPosition = pos;
AnimController.RefLimb.body.TargetPosition = pos;
AnimController.RefLimb.body.TargetVelocity = vel;
LargeUpdateTimer = 0;
}
+25 -13
View File
@@ -39,9 +39,9 @@ namespace Subsurface
public readonly DamageType DamageType;
public readonly float StructureDamage;
public readonly float Damage;
public readonly float BleedingDamage;
private readonly float structureDamage;
private readonly float damage;
private readonly float bleedingDamage;
private Sound sound;
@@ -51,6 +51,21 @@ namespace Subsurface
private float priority;
public float GetDamage(float deltaTime)
{
return (Duration == 0.0f) ? damage : damage * deltaTime;
}
public float GetBleedingDamage(float deltaTime)
{
return (Duration == 0.0f) ? bleedingDamage : bleedingDamage * deltaTime;
}
public float GetStructureDamage(float deltaTime)
{
return (Duration == 0.0f) ? structureDamage : structureDamage * deltaTime;
}
//public Attack(AttackType type, float range,)
//{
@@ -78,9 +93,9 @@ namespace Subsurface
}
Damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f);
StructureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f);
BleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f);
damage = ToolBox.GetAttributeFloat(element, "damage", 0.0f);
structureDamage = ToolBox.GetAttributeFloat(element, "structuredamage", 0.0f);
bleedingDamage = ToolBox.GetAttributeFloat(element, "bleedingdamage", 0.0f);
Stun = ToolBox.GetAttributeFloat(element, "stun", 0.0f);
@@ -110,28 +125,25 @@ namespace Subsurface
if (target as Character == null)
{
damageAmount = StructureDamage;
damageAmount = structureDamage;
}
else
{
damageAmount = Damage;
damageAmount = damage;
}
if (Duration > 0.0f) damageAmount *= deltaTime;
float bleedingAmount = (Duration == 0.0f) ? BleedingDamage : BleedingDamage * deltaTime;
if (particleEmitterPrefab != null)
{
particleEmitterPrefab.Emit(position);
}
if (sound!=null)
if (sound != null)
{
sound.Play(1.0f, 500.0f, position);
}
return target.AddDamage(attacker, position, this, playSound);
return target.AddDamage(attacker, position, this, deltaTime, playSound);
}
}
+2 -3
View File
@@ -844,9 +844,9 @@ namespace Subsurface
}
}
public virtual AttackResult AddDamage(IDamageable attacker, Vector2 simPosition, Attack attack, bool playSound = false)
public virtual AttackResult AddDamage(IDamageable attacker, Vector2 simPosition, Attack attack, float deltaTime, bool playSound = false)
{
return AddDamage(simPosition, attack.DamageType, attack.Damage, attack.BleedingDamage, attack.Stun, playSound);
return AddDamage(simPosition, attack.DamageType, attack.GetDamage(deltaTime), attack.GetBleedingDamage(deltaTime), attack.Stun, playSound);
}
public AttackResult AddDamage(Vector2 simPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound)
@@ -855,7 +855,6 @@ namespace Subsurface
if (controlled == this) CharacterHUD.TakeDamage();
Limb closestLimb = null;
float closestDistance = 0.0f;
foreach (Limb limb in AnimController.Limbs)
+7 -5
View File
@@ -629,12 +629,14 @@ namespace Subsurface
{
if (inWater)
{
foreach (Limb limb in Limbs)
{
if (limb.body.TargetPosition == Vector2.Zero) continue;
//foreach (Limb limb in Limbs)
//{
// if (limb.body.TargetPosition == Vector2.Zero) continue;
limb.body.SetTransform(limb.SimPosition + newMovement * 0.1f, limb.Rotation);
}
// limb.body.SetTransform(limb.SimPosition + newMovement * 0.1f, limb.Rotation);
//}
correctionMovement = Vector2.Normalize(newMovement) * Math.Min(0.1f + dist, 3.0f);
}
else
{