Cache self.ToLuaValue in ScriptTriggers.
When making an Lua function call, any LuaCustomClrObject must be introspected via reflection in order to determine what to expose in Lua code. In OpenRA, we use these for any types that implement IScriptBindable, such as Actor. Previously, we would need to pay the cost of this reflection for every individual Lua call an Actor used in its ScriptTriggers trait where it passed `self` as a parameter. This would be repeated every time. For performance, we now cache self.ToLuaValue in the trait and use that for all calls so we only pay the reflection cost once on trait construction. This removes a significant overhead in the Lua bridging code.
This commit is contained in:
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"only contain alive actors.")]
|
||||
public bool Build(string[] actorTypes, LuaFunction actionFunc = null)
|
||||
{
|
||||
if (triggers.Triggers[Trigger.OnProduction].Any())
|
||||
if (triggers.HasAnyCallbacksFor(Trigger.OnProduction))
|
||||
return false;
|
||||
|
||||
var queue = queues.Where(q => actorTypes.All(t => GetBuildableInfo(t).Queue.Contains(q.Info.Type)))
|
||||
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
"Note: it does not check whether this particular type of actor is being produced.")]
|
||||
public bool IsProducing(string actorType)
|
||||
{
|
||||
if (triggers.Triggers[Trigger.OnProduction].Any())
|
||||
if (triggers.HasAnyCallbacksFor(Trigger.OnProduction))
|
||||
return true;
|
||||
|
||||
return queues.Where(q => GetBuildableInfo(actorType).Queue.Contains(q.Info.Type))
|
||||
|
||||
Reference in New Issue
Block a user