Make IsDisabled a method on Actor.
This allows us to cache the disabled traits, which simplifies life for some callers since we relieve them of having to cache it, as well as improving perf for all IsDisabled calls.
This commit is contained in:
@@ -85,6 +85,7 @@ namespace OpenRA
|
||||
|
||||
readonly IRenderModifier[] renderModifiers;
|
||||
readonly IRender[] renders;
|
||||
readonly IDisable[] disables;
|
||||
|
||||
internal Actor(World world, string name, TypeDictionary initDict)
|
||||
{
|
||||
@@ -128,6 +129,7 @@ namespace OpenRA
|
||||
|
||||
renderModifiers = TraitsImplementing<IRenderModifier>().ToArray();
|
||||
renders = TraitsImplementing<IRender>().ToArray();
|
||||
disables = TraitsImplementing<IDisable>().ToArray();
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
@@ -277,6 +279,14 @@ namespace OpenRA
|
||||
health.Value.InflictDamage(this, attacker, health.Value.MaxHP, null, true);
|
||||
}
|
||||
|
||||
public bool IsDisabled()
|
||||
{
|
||||
foreach (var disable in disables)
|
||||
if (disable.Disabled)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#region Scripting interface
|
||||
|
||||
Lazy<ScriptActorInterface> luaInterface;
|
||||
|
||||
Reference in New Issue
Block a user