(3f75a3756) Minor optimization: removing hudbars don't generate garbage anymore (the collection usually contains only one item and the loop was not evaluated many times, but it still doesn't hurt to fix it, especially when there's a todo note about it).

This commit is contained in:
Joonas Rikkonen
2019-04-08 13:35:18 +03:00
parent f278ff212c
commit 8850d49960

View File

@@ -275,6 +275,7 @@ namespace Barotrauma
DisableControls = false;
}
private List<KeyValuePair<object, HUDProgressBar>> progressBarRemovals = new List<KeyValuePair<object, HUDProgressBar>>();
partial void UpdateControlled(float deltaTime, Camera cam)
{
if (controlled != this) return;
@@ -283,25 +284,22 @@ namespace Barotrauma
Lights.LightManager.ViewTarget = this;
CharacterHUD.Update(deltaTime, this, cam);
bool removeProgressBars = false;
foreach (HUDProgressBar progressBar in hudProgressBars.Values)
if (hudProgressBars.Any())
{
if (progressBar.FadeTimer <= 0.0f)
foreach (var progressBar in hudProgressBars)
{
removeProgressBars = true;
continue;
if (progressBar.Value.FadeTimer <= 0.0f)
{
progressBarRemovals.Add(progressBar);
continue;
}
progressBar.Value.Update(deltaTime);
}
progressBar.Update(deltaTime);
}
if (removeProgressBars)
{
// TODO: this generates garbage, can we fix anything here?
foreach (var pb in hudProgressBars.Where(pb => pb.Value.FadeTimer <= 0.0f).ToList())
if (progressBarRemovals.Any())
{
hudProgressBars.Remove(pb.Key);
progressBarRemovals.ForEach(pb => hudProgressBars.Remove(pb.Key));
progressBarRemovals.Clear();
}
}
}