diff options
author | Justin Clark-Casey (justincc) | 2012-03-15 02:02:31 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-03-15 02:02:31 +0000 |
commit | acb1355ff203b55ae2581b5606e251b8fa91b252 (patch) | |
tree | 43f637405b39c42caaf16fe9fcd5dbb822db75dd /OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |
parent | Simplify some logic in the ScriptInstance constructor - running is set to fal... (diff) | |
download | opensim-SC-acb1355ff203b55ae2581b5606e251b8fa91b252.zip opensim-SC-acb1355ff203b55ae2581b5606e251b8fa91b252.tar.gz opensim-SC-acb1355ff203b55ae2581b5606e251b8fa91b252.tar.bz2 opensim-SC-acb1355ff203b55ae2581b5606e251b8fa91b252.tar.xz |
Remove property/field duplication in ScriptInstance where it's unnecessary.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 277 |
1 files changed, 107 insertions, 170 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 8b0dbaa..968351b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -56,43 +56,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
56 | public class ScriptInstance : MarshalByRefObject, IScriptInstance | 56 | public class ScriptInstance : MarshalByRefObject, IScriptInstance |
57 | { | 57 | { |
58 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 58 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
59 | |||
60 | private IScriptEngine m_Engine; | ||
61 | 59 | ||
62 | /// <summary> | 60 | /// <summary> |
63 | /// The current work item if an event for this script is running or waiting to run, | 61 | /// The current work item if an event for this script is running or waiting to run, |
64 | /// </summary> | 62 | /// </summary> |
65 | /// <remarks> | 63 | /// <remarks> |
66 | /// Null if there is no running or waiting to run event. Must be changed only under an m_EventQueue lock. | 64 | /// Null if there is no running or waiting to run event. Must be changed only under an EventQueue lock. |
67 | /// </remarks> | 65 | /// </remarks> |
68 | private IScriptWorkItem m_CurrentWorkItem; | 66 | private IScriptWorkItem m_CurrentWorkItem; |
69 | 67 | ||
70 | private Queue m_EventQueue = new Queue(32); | ||
71 | private UUID m_ItemID; | ||
72 | private uint m_LocalID; | ||
73 | private UUID m_ObjectID; | ||
74 | private UUID m_AssetID; | ||
75 | private IScript m_Script; | 68 | private IScript m_Script; |
76 | private UUID m_AppDomain; | ||
77 | private DetectParams[] m_DetectParams; | 69 | private DetectParams[] m_DetectParams; |
78 | private bool m_TimerQueued; | 70 | private bool m_TimerQueued; |
79 | private DateTime m_EventStart; | 71 | private DateTime m_EventStart; |
80 | private bool m_InEvent; | 72 | private bool m_InEvent; |
81 | private string m_PrimName; | ||
82 | private string m_ScriptName; | ||
83 | private string m_Assembly; | 73 | private string m_Assembly; |
84 | private int m_StartParam; | ||
85 | private string m_CurrentEvent = String.Empty; | 74 | private string m_CurrentEvent = String.Empty; |
86 | private bool m_InSelfDelete; | 75 | private bool m_InSelfDelete; |
87 | private int m_MaxScriptQueue; | 76 | private int m_MaxScriptQueue; |
88 | private bool m_SaveState = true; | 77 | private bool m_SaveState = true; |
89 | private bool m_ShuttingDown; | ||
90 | private int m_ControlEventsInQueue; | 78 | private int m_ControlEventsInQueue; |
91 | private int m_LastControlLevel; | 79 | private int m_LastControlLevel; |
92 | private bool m_CollisionInQueue; | 80 | private bool m_CollisionInQueue; |
93 | private TaskInventoryItem m_thisScriptTask; | 81 | |
94 | // The following is for setting a minimum delay between events | 82 | // The following is for setting a minimum delay between events |
95 | private double m_minEventDelay; | 83 | private double m_minEventDelay; |
84 | |||
96 | private long m_eventDelayTicks; | 85 | private long m_eventDelayTicks; |
97 | private long m_nextEventTimeTicks; | 86 | private long m_nextEventTimeTicks; |
98 | private bool m_startOnInit = true; | 87 | private bool m_startOnInit = true; |
@@ -103,21 +92,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
103 | private UUID m_CurrentStateHash; | 92 | private UUID m_CurrentStateHash; |
104 | private UUID m_RegionID; | 93 | private UUID m_RegionID; |
105 | 94 | ||
106 | private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> | 95 | public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; } |
107 | m_LineMap; | ||
108 | |||
109 | public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> | ||
110 | LineMap | ||
111 | { | ||
112 | get { return m_LineMap; } | ||
113 | set { m_LineMap = value; } | ||
114 | } | ||
115 | 96 | ||
116 | private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); | 97 | private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); |
117 | 98 | ||
118 | // Script state | ||
119 | private string m_State = "default"; | ||
120 | |||
121 | public Object[] PluginData = new Object[0]; | 99 | public Object[] PluginData = new Object[0]; |
122 | 100 | ||
123 | /// <summary> | 101 | /// <summary> |
@@ -156,11 +134,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
156 | 134 | ||
157 | if (wasSuspended && !m_Suspended) | 135 | if (wasSuspended && !m_Suspended) |
158 | { | 136 | { |
159 | lock (m_EventQueue) | 137 | lock (EventQueue) |
160 | { | 138 | { |
161 | // Need to place ourselves back in a work item if there are events to process | 139 | // Need to place ourselves back in a work item if there are events to process |
162 | if ((m_EventQueue.Count > 0) && Running && (!m_ShuttingDown)) | 140 | if (EventQueue.Count > 0 && Running && !ShuttingDown) |
163 | m_CurrentWorkItem = m_Engine.QueueEventHandler(this); | 141 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
164 | } | 142 | } |
165 | } | 143 | } |
166 | } | 144 | } |
@@ -168,79 +146,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
168 | } | 146 | } |
169 | private bool m_Suspended; | 147 | private bool m_Suspended; |
170 | 148 | ||
171 | public bool ShuttingDown | 149 | public bool ShuttingDown { get; set; } |
172 | { | ||
173 | get { return m_ShuttingDown; } | ||
174 | set { m_ShuttingDown = value; } | ||
175 | } | ||
176 | 150 | ||
177 | public string State | 151 | public string State { get; set; } |
178 | { | ||
179 | get { return m_State; } | ||
180 | set { m_State = value; } | ||
181 | } | ||
182 | 152 | ||
183 | public IScriptEngine Engine | 153 | public IScriptEngine Engine { get; private set; } |
184 | { | ||
185 | get { return m_Engine; } | ||
186 | } | ||
187 | 154 | ||
188 | public UUID AppDomain | 155 | public UUID AppDomain { get; set; } |
189 | { | ||
190 | get { return m_AppDomain; } | ||
191 | set { m_AppDomain = value; } | ||
192 | } | ||
193 | 156 | ||
194 | public string PrimName | 157 | public string PrimName { get; private set; } |
195 | { | ||
196 | get { return m_PrimName; } | ||
197 | } | ||
198 | 158 | ||
199 | public string ScriptName | 159 | public string ScriptName { get; private set; } |
200 | { | ||
201 | get { return m_ScriptName; } | ||
202 | } | ||
203 | 160 | ||
204 | public UUID ItemID | 161 | public UUID ItemID { get; private set; } |
205 | { | ||
206 | get { return m_ItemID; } | ||
207 | } | ||
208 | 162 | ||
209 | public UUID ObjectID | 163 | public UUID ObjectID { get; private set; } |
210 | { | ||
211 | get { return m_ObjectID; } | ||
212 | } | ||
213 | 164 | ||
214 | public uint LocalID | 165 | public uint LocalID { get; private set; } |
215 | { | ||
216 | get { return m_LocalID; } | ||
217 | } | ||
218 | 166 | ||
219 | public UUID AssetID | 167 | public UUID AssetID { get; private set; } |
220 | { | ||
221 | get { return m_AssetID; } | ||
222 | } | ||
223 | 168 | ||
224 | public Queue EventQueue | 169 | public Queue EventQueue { get; private set; } |
225 | { | ||
226 | get { return m_EventQueue; } | ||
227 | } | ||
228 | 170 | ||
229 | public void ClearQueue() | 171 | public int StartParam { get; set; } |
230 | { | ||
231 | m_TimerQueued = false; | ||
232 | m_EventQueue.Clear(); | ||
233 | } | ||
234 | 172 | ||
235 | public int StartParam | 173 | public TaskInventoryItem ScriptTask { get; private set; } |
236 | { | ||
237 | get { return m_StartParam; } | ||
238 | set { m_StartParam = value; } | ||
239 | } | ||
240 | 174 | ||
241 | public TaskInventoryItem ScriptTask | 175 | public void ClearQueue() |
242 | { | 176 | { |
243 | get { return m_thisScriptTask; } | 177 | m_TimerQueued = false; |
178 | EventQueue.Clear(); | ||
244 | } | 179 | } |
245 | 180 | ||
246 | public ScriptInstance(IScriptEngine engine, SceneObjectPart part, | 181 | public ScriptInstance(IScriptEngine engine, SceneObjectPart part, |
@@ -249,16 +184,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
249 | int startParam, bool postOnRez, StateSource stateSource, | 184 | int startParam, bool postOnRez, StateSource stateSource, |
250 | int maxScriptQueue) | 185 | int maxScriptQueue) |
251 | { | 186 | { |
252 | m_Engine = engine; | 187 | State = "default"; |
253 | 188 | EventQueue = new Queue(32); | |
254 | m_LocalID = part.LocalId; | 189 | |
255 | m_ObjectID = part.UUID; | 190 | Engine = engine; |
256 | m_ItemID = itemID; | 191 | LocalID = part.LocalId; |
257 | m_AssetID = assetID; | 192 | ObjectID = part.UUID; |
258 | m_PrimName = primName; | 193 | ItemID = itemID; |
259 | m_ScriptName = scriptName; | 194 | AssetID = assetID; |
195 | PrimName = primName; | ||
196 | ScriptName = scriptName; | ||
260 | m_Assembly = assembly; | 197 | m_Assembly = assembly; |
261 | m_StartParam = startParam; | 198 | StartParam = startParam; |
262 | m_MaxScriptQueue = maxScriptQueue; | 199 | m_MaxScriptQueue = maxScriptQueue; |
263 | m_stateSource = stateSource; | 200 | m_stateSource = stateSource; |
264 | m_postOnRez = postOnRez; | 201 | m_postOnRez = postOnRez; |
@@ -269,9 +206,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
269 | { | 206 | { |
270 | lock (part.TaskInventory) | 207 | lock (part.TaskInventory) |
271 | { | 208 | { |
272 | if (part.TaskInventory.ContainsKey(m_ItemID)) | 209 | if (part.TaskInventory.ContainsKey(ItemID)) |
273 | { | 210 | { |
274 | m_thisScriptTask = part.TaskInventory[m_ItemID]; | 211 | ScriptTask = part.TaskInventory[ItemID]; |
275 | } | 212 | } |
276 | } | 213 | } |
277 | } | 214 | } |
@@ -281,7 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
281 | foreach (string api in am.GetApis()) | 218 | foreach (string api in am.GetApis()) |
282 | { | 219 | { |
283 | m_Apis[api] = am.CreateApi(api); | 220 | m_Apis[api] = am.CreateApi(api); |
284 | m_Apis[api].Initialize(engine, part, m_LocalID, itemID); | 221 | m_Apis[api].Initialize(engine, part, LocalID, itemID); |
285 | } | 222 | } |
286 | 223 | ||
287 | try | 224 | try |
@@ -315,7 +252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
315 | 252 | ||
316 | // // m_log.Debug("[Script] Script instance created"); | 253 | // // m_log.Debug("[Script] Script instance created"); |
317 | 254 | ||
318 | part.SetScriptEvents(m_ItemID, | 255 | part.SetScriptEvents(ItemID, |
319 | (int)m_Script.GetStateEventFlags(State)); | 256 | (int)m_Script.GetStateEventFlags(State)); |
320 | } | 257 | } |
321 | catch (Exception e) | 258 | catch (Exception e) |
@@ -330,7 +267,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
330 | m_SaveState = true; | 267 | m_SaveState = true; |
331 | 268 | ||
332 | string savedState = Path.Combine(Path.GetDirectoryName(assembly), | 269 | string savedState = Path.Combine(Path.GetDirectoryName(assembly), |
333 | m_ItemID.ToString() + ".state"); | 270 | ItemID.ToString() + ".state"); |
334 | if (File.Exists(savedState)) | 271 | if (File.Exists(savedState)) |
335 | { | 272 | { |
336 | string xml = String.Empty; | 273 | string xml = String.Empty; |
@@ -354,18 +291,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
354 | 291 | ||
355 | ScriptSerializer.Deserialize(xml, this); | 292 | ScriptSerializer.Deserialize(xml, this); |
356 | 293 | ||
357 | AsyncCommandManager.CreateFromData(m_Engine, | 294 | AsyncCommandManager.CreateFromData(Engine, |
358 | m_LocalID, m_ItemID, m_ObjectID, | 295 | LocalID, ItemID, ObjectID, |
359 | PluginData); | 296 | PluginData); |
360 | 297 | ||
361 | // m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName); | 298 | // m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName); |
362 | 299 | ||
363 | part.SetScriptEvents(m_ItemID, | 300 | part.SetScriptEvents(ItemID, |
364 | (int)m_Script.GetStateEventFlags(State)); | 301 | (int)m_Script.GetStateEventFlags(State)); |
365 | 302 | ||
366 | Running = false; | 303 | Running = false; |
367 | 304 | ||
368 | if (m_ShuttingDown) | 305 | if (ShuttingDown) |
369 | m_startOnInit = false; | 306 | m_startOnInit = false; |
370 | 307 | ||
371 | // we get new rez events on sim restart, too | 308 | // we get new rez events on sim restart, too |
@@ -393,7 +330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
393 | } | 330 | } |
394 | // else | 331 | // else |
395 | // { | 332 | // { |
396 | // ScenePresence presence = m_Engine.World.GetScenePresence(part.OwnerID); | 333 | // ScenePresence presence = Engine.World.GetScenePresence(part.OwnerID); |
397 | 334 | ||
398 | // if (presence != null && (!postOnRez)) | 335 | // if (presence != null && (!postOnRez)) |
399 | // presence.ControllingClient.SendAgentAlertMessage("Compile successful", false); | 336 | // presence.ControllingClient.SendAgentAlertMessage("Compile successful", false); |
@@ -411,7 +348,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
411 | if (m_postOnRez) | 348 | if (m_postOnRez) |
412 | { | 349 | { |
413 | PostEvent(new EventParams("on_rez", | 350 | PostEvent(new EventParams("on_rez", |
414 | new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0])); | 351 | new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0])); |
415 | } | 352 | } |
416 | 353 | ||
417 | if (m_stateSource == StateSource.AttachedRez) | 354 | if (m_stateSource == StateSource.AttachedRez) |
@@ -445,7 +382,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
445 | if (m_postOnRez) | 382 | if (m_postOnRez) |
446 | { | 383 | { |
447 | PostEvent(new EventParams("on_rez", | 384 | PostEvent(new EventParams("on_rez", |
448 | new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0])); | 385 | new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0])); |
449 | } | 386 | } |
450 | 387 | ||
451 | if (m_stateSource == StateSource.AttachedRez) | 388 | if (m_stateSource == StateSource.AttachedRez) |
@@ -459,7 +396,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
459 | 396 | ||
460 | private void ReleaseControls() | 397 | private void ReleaseControls() |
461 | { | 398 | { |
462 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart(m_LocalID); | 399 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
463 | 400 | ||
464 | if (part != null) | 401 | if (part != null) |
465 | { | 402 | { |
@@ -467,18 +404,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
467 | UUID permsGranter; | 404 | UUID permsGranter; |
468 | lock (part.TaskInventory) | 405 | lock (part.TaskInventory) |
469 | { | 406 | { |
470 | if (!part.TaskInventory.ContainsKey(m_ItemID)) | 407 | if (!part.TaskInventory.ContainsKey(ItemID)) |
471 | return; | 408 | return; |
472 | 409 | ||
473 | permsGranter = part.TaskInventory[m_ItemID].PermsGranter; | 410 | permsGranter = part.TaskInventory[ItemID].PermsGranter; |
474 | permsMask = part.TaskInventory[m_ItemID].PermsMask; | 411 | permsMask = part.TaskInventory[ItemID].PermsMask; |
475 | } | 412 | } |
476 | 413 | ||
477 | if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) | 414 | if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) |
478 | { | 415 | { |
479 | ScenePresence presence = m_Engine.World.GetScenePresence(permsGranter); | 416 | ScenePresence presence = Engine.World.GetScenePresence(permsGranter); |
480 | if (presence != null) | 417 | if (presence != null) |
481 | presence.UnRegisterControlEventsToScript(m_LocalID, m_ItemID); | 418 | presence.UnRegisterControlEventsToScript(LocalID, ItemID); |
482 | } | 419 | } |
483 | } | 420 | } |
484 | } | 421 | } |
@@ -486,13 +423,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
486 | public void DestroyScriptInstance() | 423 | public void DestroyScriptInstance() |
487 | { | 424 | { |
488 | ReleaseControls(); | 425 | ReleaseControls(); |
489 | AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); | 426 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
490 | } | 427 | } |
491 | 428 | ||
492 | public void RemoveState() | 429 | public void RemoveState() |
493 | { | 430 | { |
494 | string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly), | 431 | string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly), |
495 | m_ItemID.ToString() + ".state"); | 432 | ItemID.ToString() + ".state"); |
496 | 433 | ||
497 | try | 434 | try |
498 | { | 435 | { |
@@ -505,7 +442,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
505 | 442 | ||
506 | public void VarDump(Dictionary<string, object> vars) | 443 | public void VarDump(Dictionary<string, object> vars) |
507 | { | 444 | { |
508 | // m_log.Info("Variable dump for script "+ m_ItemID.ToString()); | 445 | // m_log.Info("Variable dump for script "+ ItemID.ToString()); |
509 | // foreach (KeyValuePair<string, object> v in vars) | 446 | // foreach (KeyValuePair<string, object> v in vars) |
510 | // { | 447 | // { |
511 | // m_log.Info("Variable: "+v.Key+" = "+v.Value.ToString()); | 448 | // m_log.Info("Variable: "+v.Key+" = "+v.Value.ToString()); |
@@ -514,17 +451,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
514 | 451 | ||
515 | public void Start() | 452 | public void Start() |
516 | { | 453 | { |
517 | lock (m_EventQueue) | 454 | lock (EventQueue) |
518 | { | 455 | { |
519 | if (Running) | 456 | if (Running) |
520 | return; | 457 | return; |
521 | 458 | ||
522 | Running = true; | 459 | Running = true; |
523 | 460 | ||
524 | if (m_EventQueue.Count > 0) | 461 | if (EventQueue.Count > 0) |
525 | { | 462 | { |
526 | if (m_CurrentWorkItem == null) | 463 | if (m_CurrentWorkItem == null) |
527 | m_CurrentWorkItem = m_Engine.QueueEventHandler(this); | 464 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
528 | // else | 465 | // else |
529 | // m_log.Error("[Script] Tried to start a script that was already queued"); | 466 | // m_log.Error("[Script] Tried to start a script that was already queued"); |
530 | } | 467 | } |
@@ -539,7 +476,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
539 | 476 | ||
540 | IScriptWorkItem workItem; | 477 | IScriptWorkItem workItem; |
541 | 478 | ||
542 | lock (m_EventQueue) | 479 | lock (EventQueue) |
543 | { | 480 | { |
544 | if (!Running) | 481 | if (!Running) |
545 | return true; | 482 | return true; |
@@ -569,7 +506,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
569 | return true; | 506 | return true; |
570 | } | 507 | } |
571 | 508 | ||
572 | lock (m_EventQueue) | 509 | lock (EventQueue) |
573 | { | 510 | { |
574 | workItem = m_CurrentWorkItem; | 511 | workItem = m_CurrentWorkItem; |
575 | } | 512 | } |
@@ -588,7 +525,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
588 | workItem.Abort(); | 525 | workItem.Abort(); |
589 | } | 526 | } |
590 | 527 | ||
591 | lock (m_EventQueue) | 528 | lock (EventQueue) |
592 | { | 529 | { |
593 | m_CurrentWorkItem = null; | 530 | m_CurrentWorkItem = null; |
594 | } | 531 | } |
@@ -621,7 +558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
621 | public void PostEvent(EventParams data) | 558 | public void PostEvent(EventParams data) |
622 | { | 559 | { |
623 | // m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}", | 560 | // m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}", |
624 | // m_PrimName, m_ScriptName, data.EventName, m_State); | 561 | // PrimName, ScriptName, data.EventName, State); |
625 | 562 | ||
626 | if (!Running) | 563 | if (!Running) |
627 | return; | 564 | return; |
@@ -636,9 +573,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
636 | m_nextEventTimeTicks = DateTime.Now.Ticks + m_eventDelayTicks; | 573 | m_nextEventTimeTicks = DateTime.Now.Ticks + m_eventDelayTicks; |
637 | } | 574 | } |
638 | 575 | ||
639 | lock (m_EventQueue) | 576 | lock (EventQueue) |
640 | { | 577 | { |
641 | if (m_EventQueue.Count >= m_MaxScriptQueue) | 578 | if (EventQueue.Count >= m_MaxScriptQueue) |
642 | return; | 579 | return; |
643 | 580 | ||
644 | if (data.EventName == "timer") | 581 | if (data.EventName == "timer") |
@@ -682,11 +619,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
682 | m_CollisionInQueue = true; | 619 | m_CollisionInQueue = true; |
683 | } | 620 | } |
684 | 621 | ||
685 | m_EventQueue.Enqueue(data); | 622 | EventQueue.Enqueue(data); |
686 | 623 | ||
687 | if (m_CurrentWorkItem == null) | 624 | if (m_CurrentWorkItem == null) |
688 | { | 625 | { |
689 | m_CurrentWorkItem = m_Engine.QueueEventHandler(this); | 626 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
690 | } | 627 | } |
691 | } | 628 | } |
692 | } | 629 | } |
@@ -710,14 +647,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
710 | 647 | ||
711 | EventParams data = null; | 648 | EventParams data = null; |
712 | 649 | ||
713 | lock (m_EventQueue) | 650 | lock (EventQueue) |
714 | { | 651 | { |
715 | data = (EventParams) m_EventQueue.Dequeue(); | 652 | data = (EventParams)EventQueue.Dequeue(); |
716 | if (data == null) // Shouldn't happen | 653 | if (data == null) // Shouldn't happen |
717 | { | 654 | { |
718 | if (m_EventQueue.Count > 0 && Running && !m_ShuttingDown) | 655 | if (EventQueue.Count > 0 && Running && !ShuttingDown) |
719 | { | 656 | { |
720 | m_CurrentWorkItem = m_Engine.QueueEventHandler(this); | 657 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
721 | } | 658 | } |
722 | else | 659 | else |
723 | { | 660 | { |
@@ -744,28 +681,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
744 | if (data.EventName == "state") // Hardcoded state change | 681 | if (data.EventName == "state") // Hardcoded state change |
745 | { | 682 | { |
746 | // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", | 683 | // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", |
747 | // m_PrimName, m_ScriptName, data.Params[0].ToString()); | 684 | // PrimName, ScriptName, data.Params[0].ToString()); |
748 | m_State = data.Params[0].ToString(); | 685 | State = data.Params[0].ToString(); |
749 | AsyncCommandManager.RemoveScript(m_Engine, | 686 | AsyncCommandManager.RemoveScript(Engine, |
750 | m_LocalID, m_ItemID); | 687 | LocalID, ItemID); |
751 | 688 | ||
752 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart( | 689 | SceneObjectPart part = Engine.World.GetSceneObjectPart( |
753 | m_LocalID); | 690 | LocalID); |
754 | if (part != null) | 691 | if (part != null) |
755 | { | 692 | { |
756 | part.SetScriptEvents(m_ItemID, | 693 | part.SetScriptEvents(ItemID, |
757 | (int)m_Script.GetStateEventFlags(State)); | 694 | (int)m_Script.GetStateEventFlags(State)); |
758 | } | 695 | } |
759 | } | 696 | } |
760 | else | 697 | else |
761 | { | 698 | { |
762 | if (m_Engine.World.PipeEventsForScript(m_LocalID) || | 699 | if (Engine.World.PipeEventsForScript(LocalID) || |
763 | data.EventName == "control") // Don't freeze avies! | 700 | data.EventName == "control") // Don't freeze avies! |
764 | { | 701 | { |
765 | SceneObjectPart part = m_Engine.World.GetSceneObjectPart( | 702 | SceneObjectPart part = Engine.World.GetSceneObjectPart( |
766 | m_LocalID); | 703 | LocalID); |
767 | // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", | 704 | // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", |
768 | // m_PrimName, m_ScriptName, data.EventName, m_State); | 705 | // PrimName, ScriptName, data.EventName, State); |
769 | 706 | ||
770 | try | 707 | try |
771 | { | 708 | { |
@@ -807,7 +744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
807 | 744 | ||
808 | if (text.Length > 1000) | 745 | if (text.Length > 1000) |
809 | text = text.Substring(0, 1000); | 746 | text = text.Substring(0, 1000); |
810 | m_Engine.World.SimChat(Utils.StringToBytes(text), | 747 | Engine.World.SimChat(Utils.StringToBytes(text), |
811 | ChatTypeEnum.DebugChannel, 2147483647, | 748 | ChatTypeEnum.DebugChannel, 2147483647, |
812 | part.AbsolutePosition, | 749 | part.AbsolutePosition, |
813 | part.Name, part.UUID, false); | 750 | part.Name, part.UUID, false); |
@@ -829,13 +766,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
829 | { | 766 | { |
830 | m_InSelfDelete = true; | 767 | m_InSelfDelete = true; |
831 | if (part != null) | 768 | if (part != null) |
832 | m_Engine.World.DeleteSceneObject(part.ParentGroup, false); | 769 | Engine.World.DeleteSceneObject(part.ParentGroup, false); |
833 | } | 770 | } |
834 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) | 771 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) |
835 | { | 772 | { |
836 | m_InSelfDelete = true; | 773 | m_InSelfDelete = true; |
837 | if (part != null) | 774 | if (part != null) |
838 | part.Inventory.RemoveInventoryItem(m_ItemID); | 775 | part.Inventory.RemoveInventoryItem(ItemID); |
839 | } | 776 | } |
840 | } | 777 | } |
841 | } | 778 | } |
@@ -843,11 +780,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
843 | 780 | ||
844 | // If there are more events and we are currently running and not shutting down, then ask the | 781 | // If there are more events and we are currently running and not shutting down, then ask the |
845 | // script engine to run the next event. | 782 | // script engine to run the next event. |
846 | lock (m_EventQueue) | 783 | lock (EventQueue) |
847 | { | 784 | { |
848 | if (m_EventQueue.Count > 0 && Running && (!m_ShuttingDown)) | 785 | if (EventQueue.Count > 0 && Running && !ShuttingDown) |
849 | { | 786 | { |
850 | m_CurrentWorkItem = m_Engine.QueueEventHandler(this); | 787 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
851 | } | 788 | } |
852 | else | 789 | else |
853 | { | 790 | { |
@@ -880,15 +817,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
880 | ReleaseControls(); | 817 | ReleaseControls(); |
881 | 818 | ||
882 | Stop(0); | 819 | Stop(0); |
883 | SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); | 820 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
884 | part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0; | 821 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
885 | part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero; | 822 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; |
886 | AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); | 823 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
887 | m_EventQueue.Clear(); | 824 | EventQueue.Clear(); |
888 | m_Script.ResetVars(); | 825 | m_Script.ResetVars(); |
889 | m_State = "default"; | 826 | State = "default"; |
890 | 827 | ||
891 | part.SetScriptEvents(m_ItemID, | 828 | part.SetScriptEvents(ItemID, |
892 | (int)m_Script.GetStateEventFlags(State)); | 829 | (int)m_Script.GetStateEventFlags(State)); |
893 | if (running) | 830 | if (running) |
894 | Start(); | 831 | Start(); |
@@ -905,16 +842,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
905 | ReleaseControls(); | 842 | ReleaseControls(); |
906 | 843 | ||
907 | m_Script.ResetVars(); | 844 | m_Script.ResetVars(); |
908 | SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); | 845 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
909 | part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0; | 846 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
910 | part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero; | 847 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; |
911 | AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); | 848 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
912 | 849 | ||
913 | m_EventQueue.Clear(); | 850 | EventQueue.Clear(); |
914 | m_Script.ResetVars(); | 851 | m_Script.ResetVars(); |
915 | m_State = "default"; | 852 | State = "default"; |
916 | 853 | ||
917 | part.SetScriptEvents(m_ItemID, | 854 | part.SetScriptEvents(ItemID, |
918 | (int)m_Script.GetStateEventFlags(State)); | 855 | (int)m_Script.GetStateEventFlags(State)); |
919 | 856 | ||
920 | if (m_CurrentEvent != "state_entry") | 857 | if (m_CurrentEvent != "state_entry") |
@@ -969,7 +906,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
969 | return; | 906 | return; |
970 | } | 907 | } |
971 | 908 | ||
972 | PluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID); | 909 | PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID); |
973 | 910 | ||
974 | string xml = ScriptSerializer.Serialize(this); | 911 | string xml = ScriptSerializer.Serialize(this); |
975 | 912 | ||
@@ -981,7 +918,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
981 | { | 918 | { |
982 | try | 919 | try |
983 | { | 920 | { |
984 | FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")); | 921 | FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state")); |
985 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | 922 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); |
986 | Byte[] buf = enc.GetBytes(xml); | 923 | Byte[] buf = enc.GetBytes(xml); |
987 | fs.Write(buf, 0, buf.Length); | 924 | fs.Write(buf, 0, buf.Length); |
@@ -991,7 +928,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
991 | { | 928 | { |
992 | // m_log.Error("Unable to save xml\n"+e.ToString()); | 929 | // m_log.Error("Unable to save xml\n"+e.ToString()); |
993 | } | 930 | } |
994 | //if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"))) | 931 | //if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state"))) |
995 | //{ | 932 | //{ |
996 | // throw new Exception("Completed persistence save, but no file was created"); | 933 | // throw new Exception("Completed persistence save, but no file was created"); |
997 | //} | 934 | //} |
@@ -1008,7 +945,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1008 | 945 | ||
1009 | public override string ToString() | 946 | public override string ToString() |
1010 | { | 947 | { |
1011 | return String.Format("{0} {1} on {2}", m_ScriptName, m_ItemID, m_PrimName); | 948 | return String.Format("{0} {1} on {2}", ScriptName, ItemID, PrimName); |
1012 | } | 949 | } |
1013 | 950 | ||
1014 | string FormatException(Exception e) | 951 | string FormatException(Exception e) |
@@ -1076,7 +1013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1076 | 1013 | ||
1077 | // Force an update of the in-memory plugin data | 1014 | // Force an update of the in-memory plugin data |
1078 | // | 1015 | // |
1079 | PluginData = AsyncCommandManager.GetSerializationData(m_Engine, m_ItemID); | 1016 | PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID); |
1080 | 1017 | ||
1081 | return ScriptSerializer.Serialize(this); | 1018 | return ScriptSerializer.Serialize(this); |
1082 | } | 1019 | } |