(7e43eae73) Optimized Item.ApplyStatusEffects & ItemComponent.PlaySound: check if the item has effects/sounds of the correct type from a bool array instead of doing a dictionary lookup. A small thing, but the methods are called so frequently that it adds up to a lot.

This commit is contained in:
Joonas Rikkonen
2019-04-18 12:05:11 +03:00
parent 1a3184dbad
commit b0580a9050
5 changed files with 57 additions and 21 deletions
@@ -122,10 +122,12 @@ namespace Barotrauma.Items.Components
foreach (Item subItem in containedSubItems)
{
projectile = subItem.GetComponent<Projectile>();
//apply OnUse statuseffects to the container in case it has to react to it somehow
//(play a sound, spawn more projectiles, reduce condition...)
subItem.GetComponent<ItemContainer>()?.Item.ApplyStatusEffects(ActionType.OnUse, deltaTime);
if (subItem.Condition > 0.0f)
{
subItem.GetComponent<ItemContainer>()?.Item.ApplyStatusEffects(ActionType.OnUse, deltaTime);
}
if (projectile != null) break;
}
}
@@ -219,6 +219,7 @@ namespace Barotrauma.Items.Components
requiredSkills = new List<Skill>();
#if CLIENT
hasSoundsOfType = new bool[Enum.GetValues(typeof(ActionType)).Length];
sounds = new Dictionary<ActionType, List<ItemSound>>();
#endif
@@ -133,6 +133,7 @@ namespace Barotrauma.Items.Components
set
{
if (base.IsActive == value) { return; }
base.IsActive = value;
#if CLIENT
if (light == null) return;