diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common')
4 files changed, 161 insertions, 5 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index 8e0d6f1..56baa66 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs | |||
@@ -35,9 +35,48 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
35 | { | 35 | { |
36 | // Cache functions by keeping a reference to them in a dictionary | 36 | // Cache functions by keeping a reference to them in a dictionary |
37 | private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>(); | 37 | private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>(); |
38 | private Dictionary<string, scriptEvents> m_stateEvents = new Dictionary<string, scriptEvents>(); | ||
38 | 39 | ||
39 | public Executor(IScript script) : base(script) | 40 | public Executor(IScript script) : base(script) |
40 | { | 41 | { |
42 | initEventFlags(); | ||
43 | } | ||
44 | |||
45 | |||
46 | protected override scriptEvents DoGetStateEventFlags() | ||
47 | { | ||
48 | // Console.WriteLine("Get event flags for " + m_Script.State); | ||
49 | |||
50 | // Check to see if we've already computed the flags for this state | ||
51 | scriptEvents eventFlags = scriptEvents.None; | ||
52 | if (m_stateEvents.ContainsKey(m_Script.State)) | ||
53 | { | ||
54 | m_stateEvents.TryGetValue(m_Script.State, out eventFlags); | ||
55 | return eventFlags; | ||
56 | } | ||
57 | |||
58 | // Fill in the events for this state, cache the results in the map | ||
59 | foreach (KeyValuePair<string, scriptEvents> kvp in m_eventFlagsMap) | ||
60 | { | ||
61 | string evname = m_Script.State + "_event_" + kvp.Key; | ||
62 | Type type = m_Script.GetType(); | ||
63 | try | ||
64 | { | ||
65 | MethodInfo mi = type.GetMethod(evname); | ||
66 | if (mi != null) | ||
67 | { | ||
68 | // Console.WriteLine("Found handler for " + kvp.Key); | ||
69 | eventFlags |= kvp.Value; | ||
70 | } | ||
71 | } | ||
72 | catch | ||
73 | { | ||
74 | } | ||
75 | } | ||
76 | |||
77 | // Save the flags we just computed and return the result | ||
78 | m_stateEvents.Add(m_Script.State, eventFlags); | ||
79 | return (eventFlags); | ||
41 | } | 80 | } |
42 | 81 | ||
43 | protected override void DoExecuteEvent(string FunctionName, object[] args) | 82 | protected override void DoExecuteEvent(string FunctionName, object[] args) |
diff --git a/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs b/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs index 19fb487..2e35b46 100644 --- a/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs +++ b/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
29 | using System.Runtime.Remoting.Lifetime; | 30 | using System.Runtime.Remoting.Lifetime; |
30 | 31 | ||
31 | namespace OpenSim.Region.ScriptEngine.Common | 32 | namespace OpenSim.Region.ScriptEngine.Common |
@@ -54,10 +55,46 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
54 | public bool Running | 55 | public bool Running |
55 | { | 56 | { |
56 | get { return m_Running; } | 57 | get { return m_Running; } |
57 | set { | 58 | set |
58 | if(!m_Disable) | 59 | { |
59 | m_Running = value; | 60 | if (!m_Disable) |
60 | } | 61 | m_Running = value; |
62 | } | ||
63 | } | ||
64 | |||
65 | protected Dictionary<string, scriptEvents> m_eventFlagsMap = new Dictionary<string, scriptEvents>(); | ||
66 | |||
67 | [Flags] | ||
68 | public enum scriptEvents : int | ||
69 | { | ||
70 | None = 0, | ||
71 | attach = 1, | ||
72 | collision = 15, | ||
73 | collision_end = 32, | ||
74 | collision_start = 64, | ||
75 | control = 128, | ||
76 | dataserver = 256, | ||
77 | email = 512, | ||
78 | http_response = 1024, | ||
79 | land_collision = 2048, | ||
80 | land_collision_end = 4096, | ||
81 | land_collision_start = 8192, | ||
82 | at_target = 16384, | ||
83 | listen = 32768, | ||
84 | money = 65536, | ||
85 | moving_end = 131072, | ||
86 | moving_start = 262144, | ||
87 | not_at_rot_target = 524288, | ||
88 | not_at_target = 1048576, | ||
89 | remote_data = 8388608, | ||
90 | run_time_permissions = 268435456, | ||
91 | state_entry = 1073741824, | ||
92 | state_exit = 2, | ||
93 | timer = 4, | ||
94 | touch = 8, | ||
95 | touch_end = 536870912, | ||
96 | touch_start = 2097152, | ||
97 | object_rez = 4194304 | ||
61 | } | 98 | } |
62 | 99 | ||
63 | /// <summary> | 100 | /// <summary> |
@@ -67,6 +104,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
67 | public ExecutorBase(IScript Script) | 104 | public ExecutorBase(IScript Script) |
68 | { | 105 | { |
69 | m_Script = Script; | 106 | m_Script = Script; |
107 | initEventFlags(); | ||
70 | } | 108 | } |
71 | 109 | ||
72 | /// <summary> | 110 | /// <summary> |
@@ -111,9 +149,21 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
111 | } | 149 | } |
112 | DoExecuteEvent(FunctionName, args); | 150 | DoExecuteEvent(FunctionName, args); |
113 | } | 151 | } |
152 | |||
114 | protected abstract void DoExecuteEvent(string FunctionName, object[] args); | 153 | protected abstract void DoExecuteEvent(string FunctionName, object[] args); |
115 | 154 | ||
116 | /// <summary> | 155 | /// <summary> |
156 | /// Compute the events handled by the current state of the script | ||
157 | /// </summary> | ||
158 | /// <returns>state mask</returns> | ||
159 | public scriptEvents GetStateEventFlags() | ||
160 | { | ||
161 | return DoGetStateEventFlags(); | ||
162 | } | ||
163 | |||
164 | protected abstract scriptEvents DoGetStateEventFlags(); | ||
165 | |||
166 | /// <summary> | ||
117 | /// Stop script from running. Event execution will be ignored. | 167 | /// Stop script from running. Event execution will be ignored. |
118 | /// </summary> | 168 | /// </summary> |
119 | public void StopScript() | 169 | public void StopScript() |
@@ -121,5 +171,48 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
121 | m_Running = false; | 171 | m_Running = false; |
122 | m_Disable = true; | 172 | m_Disable = true; |
123 | } | 173 | } |
174 | |||
175 | protected void initEventFlags() | ||
176 | { | ||
177 | // Initialize the table if it hasn't already been done | ||
178 | if (m_eventFlagsMap.Count > 0) | ||
179 | { | ||
180 | return; | ||
181 | } | ||
182 | |||
183 | m_eventFlagsMap.Add("attach", scriptEvents.attach); | ||
184 | // m_eventFlagsMap.Add("at_rot_target",(long)scriptEvents.at_rot_target); | ||
185 | m_eventFlagsMap.Add("at_target", scriptEvents.at_target); | ||
186 | // m_eventFlagsMap.Add("changed",(long)scriptEvents.changed); | ||
187 | m_eventFlagsMap.Add("collision", scriptEvents.collision); | ||
188 | m_eventFlagsMap.Add("collision_end", scriptEvents.collision_end); | ||
189 | m_eventFlagsMap.Add("collision_start", scriptEvents.collision_start); | ||
190 | m_eventFlagsMap.Add("control", scriptEvents.control); | ||
191 | m_eventFlagsMap.Add("dataserver", scriptEvents.dataserver); | ||
192 | m_eventFlagsMap.Add("email", scriptEvents.email); | ||
193 | m_eventFlagsMap.Add("http_response", scriptEvents.http_response); | ||
194 | m_eventFlagsMap.Add("land_collision", scriptEvents.land_collision); | ||
195 | m_eventFlagsMap.Add("land_collision_end", scriptEvents.land_collision_end); | ||
196 | m_eventFlagsMap.Add("land_collision_start", scriptEvents.land_collision_start); | ||
197 | // m_eventFlagsMap.Add("link_message",scriptEvents.link_message); | ||
198 | m_eventFlagsMap.Add("listen", scriptEvents.listen); | ||
199 | m_eventFlagsMap.Add("money", scriptEvents.money); | ||
200 | m_eventFlagsMap.Add("moving_end", scriptEvents.moving_end); | ||
201 | m_eventFlagsMap.Add("moving_start", scriptEvents.moving_start); | ||
202 | m_eventFlagsMap.Add("not_at_rot_target", scriptEvents.not_at_rot_target); | ||
203 | m_eventFlagsMap.Add("not_at_target", scriptEvents.not_at_target); | ||
204 | // m_eventFlagsMap.Add("no_sensor",(long)scriptEvents.no_sensor); | ||
205 | // m_eventFlagsMap.Add("on_rez",(long)scriptEvents.on_rez); | ||
206 | m_eventFlagsMap.Add("remote_data", scriptEvents.remote_data); | ||
207 | m_eventFlagsMap.Add("run_time_permissions", scriptEvents.run_time_permissions); | ||
208 | // m_eventFlagsMap.Add("sensor",(long)scriptEvents.sensor); | ||
209 | m_eventFlagsMap.Add("state_entry", scriptEvents.state_entry); | ||
210 | m_eventFlagsMap.Add("state_exit", scriptEvents.state_exit); | ||
211 | m_eventFlagsMap.Add("timer", scriptEvents.timer); | ||
212 | m_eventFlagsMap.Add("touch", scriptEvents.touch); | ||
213 | m_eventFlagsMap.Add("touch_end", scriptEvents.touch_end); | ||
214 | m_eventFlagsMap.Add("touch_start", scriptEvents.touch_start); | ||
215 | m_eventFlagsMap.Add("object_rez", scriptEvents.object_rez); | ||
216 | } | ||
124 | } | 217 | } |
125 | } | 218 | } |
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 31ca3f3..419ca8f 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | |||
@@ -92,8 +92,9 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
92 | m_state = value; | 92 | m_state = value; |
93 | try | 93 | try |
94 | { | 94 | { |
95 | int eventFlags = m_ScriptEngine.m_ScriptManager.GetStateEventFlags(m_localID, m_itemID); | ||
96 | m_host.SetScriptEvents(m_itemID, eventFlags); | ||
95 | m_ScriptEngine.m_EventManager.state_entry(m_localID); | 97 | m_ScriptEngine.m_EventManager.state_entry(m_localID); |
96 | |||
97 | } | 98 | } |
98 | catch (AppDomainUnloadedException) | 99 | catch (AppDomainUnloadedException) |
99 | { | 100 | { |
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs index cd2e530..7812c8c 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs | |||
@@ -319,6 +319,29 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
319 | Script.Exec.ExecuteEvent(FunctionName, args); | 319 | Script.Exec.ExecuteEvent(FunctionName, args); |
320 | } | 320 | } |
321 | 321 | ||
322 | public int GetStateEventFlags(uint localID, LLUUID itemID) | ||
323 | { | ||
324 | // Console.WriteLine("GetStateEventFlags for <" + localID + "," + itemID + ">"); | ||
325 | try | ||
326 | { | ||
327 | IScript Script = GetScript(localID, itemID); | ||
328 | if (Script == null) | ||
329 | { | ||
330 | return 0; | ||
331 | } | ||
332 | ExecutorBase.scriptEvents evflags = Script.Exec.GetStateEventFlags(); | ||
333 | return (int)evflags; | ||
334 | } | ||
335 | catch (Exception e) | ||
336 | { | ||
337 | // Console.WriteLine("Failed to get script reference for <" + localID + "," + itemID + ">"); | ||
338 | // Console.WriteLine(e.ToString()); | ||
339 | } | ||
340 | |||
341 | return 0; | ||
342 | } | ||
343 | |||
344 | |||
322 | #endregion | 345 | #endregion |
323 | 346 | ||
324 | #region Internal functions to keep track of script | 347 | #region Internal functions to keep track of script |