aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common
diff options
context:
space:
mode:
authorTedd Hansen2007-08-19 10:28:27 +0000
committerTedd Hansen2007-08-19 10:28:27 +0000
commite70cdbc5accc5025ed4e6262ff01ce50bf553141 (patch)
treeb8b74de490ae4d8a03d63458f1ad06730a5e6635 /OpenSim/Region/ScriptEngine/Common
parentMoved script loading from ScriptManager to AppDomainManager. Now increases sc... (diff)
downloadopensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.zip
opensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.tar.gz
opensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.tar.bz2
opensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.tar.xz
Added event method invoke cache to Executor. "Bind once, Invoke multiple times". Will speed up script event execution considerable. But at the cost of some memory (will be optimized later with RuntimeXHandle).
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/Executor.cs44
1 files changed, 37 insertions, 7 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs
index ca6459b..dedf00d 100644
--- a/OpenSim/Region/ScriptEngine/Common/Executor.cs
+++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs
@@ -5,7 +5,7 @@ using System.Reflection;
5 5
6namespace OpenSim.Region.ScriptEngine.Common 6namespace OpenSim.Region.ScriptEngine.Common
7{ 7{
8 public class Executor: MarshalByRefObject 8 public class Executor : MarshalByRefObject
9 { 9 {
10 /* TODO: 10 /* TODO:
11 * 11 *
@@ -16,10 +16,12 @@ namespace OpenSim.Region.ScriptEngine.Common
16 */ 16 */
17 17
18 private IScript m_Script; 18 private IScript m_Script;
19 private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>();
19 20
20 public Executor(IScript Script) 21 public Executor(IScript Script)
21 { 22 {
22 m_Script = Script; 23 m_Script = Script;
24
23 } 25 }
24 public void ExecuteEvent(string FunctionName, object[] args) 26 public void ExecuteEvent(string FunctionName, object[] args)
25 { 27 {
@@ -34,23 +36,51 @@ namespace OpenSim.Region.ScriptEngine.Common
34 //} 36 //}
35 //} 37 //}
36 38
37 Type type = m_Script.GetType();
38 39
39 Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + m_Script.State() + "_event_" + FunctionName + "\"");
40 40
41 string EventName = m_Script.State() + "_event_" + FunctionName;
42
43 //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args);
44
45 Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\"");
46
47 if (Events.ContainsKey(EventName) == false)
48 {
49 // Not found, create
50 Type type = m_Script.GetType();
51 try
52 {
53 MethodInfo mi = type.GetMethod(EventName);
54 Events.Add(EventName, mi);
55 }
56 catch (Exception e)
57 {
58 // Event name not found, cache it as not found
59 Events.Add(EventName, null);
60 }
61 }
62
63 // Get event
64 MethodInfo ev = null;
65 Events.TryGetValue(EventName, out ev);
66
67 if (ev == null) // No event by that name!
68 return;
69
70 // Found
41 try 71 try
42 { 72 {
43 type.InvokeMember(m_Script.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, m_Script, args); 73 // Invoke it
74 ev.Invoke(m_Script, args);
75
44 } 76 }
45 catch (Exception e) 77 catch (Exception e)
46 { 78 {
47 // TODO: Send to correct place 79 // TODO: Send to correct place
48 Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString()); 80 Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
49 } 81 }
50
51
52 } 82 }
53 83
54
55 } 84 }
85
56} 86}