From 00b7193b6b24e16bcfb32991297681bfb0199b23 Mon Sep 17 00:00:00 2001 From: Regalis Date: Thu, 6 Apr 2017 21:58:19 +0300 Subject: [PATCH] Minor optimizations: GUITextBlocks don't reposition and wrap the text when only the position of the text block changes (almost killed my laptop by spamming a bit too many messages to the debug console), less unnecessary floor raycasts --- .../Source/Characters/Animation/Ragdoll.cs | 18 ++++++++++++------ Subsurface/Source/GUI/GUITextBlock.cs | 8 +++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 9a18e3aaf..3b4b2ea8a 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -853,13 +853,19 @@ namespace Barotrauma inWater = false; headInWater = false; - float waterSurface = ConvertUnits.ToSimUnits(currentHull.Surface); - - float floorY = GetFloorY(); - - if (currentHull.Volume > currentHull.FullVolume * 0.95f || - (waterSurface - floorY > HeadPosition * 0.95f && Collider.SimPosition.Y < waterSurface)) + inWater = false; + if (inWater = currentHull.Volume > currentHull.FullVolume * 0.95f) + { inWater = true; + } + else + { + float waterSurface = ConvertUnits.ToSimUnits(currentHull.Surface); + if (Collider.SimPosition.Y < waterSurface && waterSurface - GetFloorY() > HeadPosition * 0.95f) + { + inWater = true; + } + } } if (flowForce.LengthSquared() > 0.001f) diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 3a51e6279..2e83251ed 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -43,6 +43,8 @@ namespace Barotrauma get { return text; } set { + if (Text == value) return; + text = value; wrappedText = value; SetTextPos(); @@ -68,8 +70,12 @@ namespace Barotrauma child.Rect = new Rectangle(child.Rect.X + value.X - rect.X, child.Rect.Y + value.Y - rect.Y, child.Rect.Width, child.Rect.Height); } + if (value.Width != rect.Width || value.Height != rect.Height) + { + SetTextPos(); + } + rect = value; - SetTextPos(); } }