(7cc515e57) SpriteDeformation optimization: don't update deformations on disabled or SimplePhysics characters, don't check if resolution has changed in the SpriteDeformation.Resolution getter because it's called very frequently

This commit is contained in:
Joonas Rikkonen
2019-04-18 12:05:27 +03:00
parent b0580a9050
commit c77c30fda7
3 changed files with 16 additions and 33 deletions

View File

@@ -363,6 +363,8 @@ namespace Barotrauma
partial void UpdateProjSpecific(float deltaTime)
{
if (!character.Enabled || SimplePhysicsEnabled) { return; }
LimbJoints.ForEach(j => j.UpdateDeformations(deltaTime));
foreach (var deformation in SpriteDeformations)
{

View File

@@ -104,14 +104,7 @@ namespace Barotrauma.SpriteDeformations
public Point Resolution
{
get
{
if (deformationParams.Resolution.X != Deformation.GetLength(0) || deformationParams.Resolution.Y != Deformation.GetLength(1))
{
Deformation = new Vector2[deformationParams.Resolution.X, deformationParams.Resolution.Y];
}
return deformationParams.Resolution;
}
get { return deformationParams.Resolution; }
set { SetResolution(value); }
}
@@ -202,6 +195,15 @@ namespace Barotrauma.SpriteDeformations
public static Vector2[,] GetDeformation(IEnumerable<SpriteDeformation> animations, Vector2 scale)
{
foreach (SpriteDeformation animation in animations)
{
if (animation.deformationParams.Resolution.X != animation.Deformation.GetLength(0) ||
animation.deformationParams.Resolution.Y != animation.Deformation.GetLength(1))
{
animation.Deformation = new Vector2[animation.deformationParams.Resolution.X, animation.deformationParams.Resolution.Y];
}
}
Point resolution = animations.First().Resolution;
if (animations.Any(a => a.Resolution != resolution))
{
@@ -211,7 +213,6 @@ namespace Barotrauma.SpriteDeformations
}
Vector2[,] deformation = new Vector2[resolution.X, resolution.Y];
foreach (SpriteDeformation animation in animations)
{
animation.GetDeformation(out Vector2[,] animDeformation, out float multiplier);

View File

@@ -1128,6 +1128,10 @@ namespace Barotrauma
{
ApplyStatusEffects(!waterProof && inWater ? ActionType.InWater : ActionType.NotInWater, deltaTime);
}
if (!broken)
{
ApplyStatusEffects(!waterProof && inWater ? ActionType.InWater : ActionType.NotInWater, deltaTime);
}
ApplyStatusEffects(!waterProof && inWater ? ActionType.InWater : ActionType.NotInWater, deltaTime);
if (body == null || !body.Enabled || !inWater || ParentInventory != null || Removed) { return; }
@@ -1164,30 +1168,6 @@ namespace Barotrauma
}
}
FindHull();
if (Submarine == null && prevSub != null)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub == null)
{
body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation);
}
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
if (Math.Abs(body.LinearVelocity.X) > NetConfig.MaxPhysicsBodyVelocity ||
Math.Abs(body.LinearVelocity.Y) > NetConfig.MaxPhysicsBodyVelocity)
{
body.LinearVelocity = new Vector2(
MathHelper.Clamp(body.LinearVelocity.X, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity),
MathHelper.Clamp(body.LinearVelocity.Y, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity));
}
}
/// <summary>
/// Applies buoyancy, drag and angular drag caused by water
/// </summary>