aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
parent* Deleted .user file (diff)
downloadopensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs101
1 files changed, 51 insertions, 50 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
index 381fd8c..54a5ef5 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
@@ -28,19 +28,14 @@
28/* Original code: Tedd Hansen */ 28/* Original code: Tedd Hansen */
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.IO;
32using System.Threading;
33using System.Reflection; 32using System.Reflection;
34using System.Runtime.Remoting;
35using System.Runtime.Serialization;
36using System.Runtime.Serialization.Formatters.Binary; 33using System.Runtime.Serialization.Formatters.Binary;
34using System.Threading;
35using libsecondlife;
37using OpenSim.Region.Environment.Scenes; 36using OpenSim.Region.Environment.Scenes;
38using OpenSim.Region.Environment.Scenes.Scripting;
39using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler; 37using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler;
40using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; 38using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL;
41using OpenSim.Region.ScriptEngine.Common;
42using libsecondlife;
43
44 39
45namespace OpenSim.Region.ScriptEngine.DotNetEngine 40namespace OpenSim.Region.ScriptEngine.DotNetEngine
46{ 41{
@@ -53,16 +48,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
53 public class ScriptManager 48 public class ScriptManager
54 { 49 {
55 #region Declares 50 #region Declares
51
56 private Thread scriptLoadUnloadThread; 52 private Thread scriptLoadUnloadThread;
57 private int scriptLoadUnloadThread_IdleSleepms = 100; 53 private int scriptLoadUnloadThread_IdleSleepms = 100;
58 private Queue<LoadStruct> loadQueue = new Queue<LoadStruct>(); 54 private Queue<LoadStruct> loadQueue = new Queue<LoadStruct>();
59 private Queue<UnloadStruct> unloadQueue = new Queue<UnloadStruct>(); 55 private Queue<UnloadStruct> unloadQueue = new Queue<UnloadStruct>();
56
60 private struct LoadStruct 57 private struct LoadStruct
61 { 58 {
62 public uint localID; 59 public uint localID;
63 public LLUUID itemID; 60 public LLUUID itemID;
64 public string script; 61 public string script;
65 } 62 }
63
66 private struct UnloadStruct 64 private struct UnloadStruct
67 { 65 {
68 public uint localID; 66 public uint localID;
@@ -72,17 +70,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
72 // Object<string, Script<string, script>> 70 // Object<string, Script<string, script>>
73 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. 71 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
74 // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! 72 // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
75 internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>(); 73 internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts =
74 new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>();
75
76 public Scene World 76 public Scene World
77 { 77 {
78 get 78 get { return m_scriptEngine.World; }
79 {
80 return m_scriptEngine.World;
81 }
82 } 79 }
83#endregion 80
81 #endregion
82
84 #region Object init/shutdown 83 #region Object init/shutdown
84
85 private ScriptEngine m_scriptEngine; 85 private ScriptEngine m_scriptEngine;
86
86 public ScriptManager(ScriptEngine scriptEngine) 87 public ScriptManager(ScriptEngine scriptEngine)
87 { 88 {
88 m_scriptEngine = scriptEngine; 89 m_scriptEngine = scriptEngine;
@@ -92,9 +93,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
92 scriptLoadUnloadThread.IsBackground = true; 93 scriptLoadUnloadThread.IsBackground = true;
93 scriptLoadUnloadThread.Priority = ThreadPriority.BelowNormal; 94 scriptLoadUnloadThread.Priority = ThreadPriority.BelowNormal;
94 scriptLoadUnloadThread.Start(); 95 scriptLoadUnloadThread.Start();
95
96 } 96 }
97 ~ScriptManager () 97
98 ~ScriptManager()
98 { 99 {
99 // Abort load/unload thread 100 // Abort load/unload thread
100 try 101 try
@@ -112,8 +113,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
112 { 113 {
113 } 114 }
114 } 115 }
116
115 #endregion 117 #endregion
118
116 #region Load / Unload scripts (Thread loop) 119 #region Load / Unload scripts (Thread loop)
120
117 private void ScriptLoadUnloadThreadLoop() 121 private void ScriptLoadUnloadThreadLoop()
118 { 122 {
119 try 123 try
@@ -134,9 +138,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
134 UnloadStruct item = unloadQueue.Dequeue(); 138 UnloadStruct item = unloadQueue.Dequeue();
135 _StopScript(item.localID, item.itemID); 139 _StopScript(item.localID, item.itemID);
136 } 140 }
137
138
139
140 } 141 }
141 } 142 }
142 catch (ThreadAbortException tae) 143 catch (ThreadAbortException tae)
@@ -145,21 +146,22 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
145 a = ""; 146 a = "";
146 // Expected 147 // Expected
147 } 148 }
148
149 } 149 }
150
150 #endregion 151 #endregion
152
151 #region Helper functions 153 #region Helper functions
154
152 private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 155 private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
153 { 156 {
154
155 //Console.WriteLine("ScriptManager.CurrentDomain_AssemblyResolve: " + args.Name); 157 //Console.WriteLine("ScriptManager.CurrentDomain_AssemblyResolve: " + args.Name);
156 return Assembly.GetExecutingAssembly().FullName == args.Name ? Assembly.GetExecutingAssembly() : null; 158 return Assembly.GetExecutingAssembly().FullName == args.Name ? Assembly.GetExecutingAssembly() : null;
157
158 } 159 }
159 160
160
161 #endregion 161 #endregion
162
162 #region Internal functions to keep track of script 163 #region Internal functions to keep track of script
164
163 internal Dictionary<LLUUID, LSL_BaseClass>.KeyCollection GetScriptKeys(uint localID) 165 internal Dictionary<LLUUID, LSL_BaseClass>.KeyCollection GetScriptKeys(uint localID)
164 { 166 {
165 if (Scripts.ContainsKey(localID) == false) 167 if (Scripts.ContainsKey(localID) == false)
@@ -169,7 +171,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
169 Scripts.TryGetValue(localID, out Obj); 171 Scripts.TryGetValue(localID, out Obj);
170 172
171 return Obj.Keys; 173 return Obj.Keys;
172
173 } 174 }
174 175
175 internal LSL_BaseClass GetScript(uint localID, LLUUID itemID) 176 internal LSL_BaseClass GetScript(uint localID, LLUUID itemID)
@@ -187,8 +188,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
187 Obj.TryGetValue(itemID, out Script); 188 Obj.TryGetValue(itemID, out Script);
188 189
189 return Script; 190 return Script;
190
191 } 191 }
192
192 internal void SetScript(uint localID, LLUUID itemID, LSL_BaseClass Script) 193 internal void SetScript(uint localID, LLUUID itemID, LSL_BaseClass Script)
193 { 194 {
194 // Create object if it doesn't exist 195 // Create object if it doesn't exist
@@ -205,8 +206,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
205 206
206 // Add to object 207 // Add to object
207 Obj.Add(itemID, Script); 208 Obj.Add(itemID, Script);
208
209 } 209 }
210
210 internal void RemoveScript(uint localID, LLUUID itemID) 211 internal void RemoveScript(uint localID, LLUUID itemID)
211 { 212 {
212 // Don't have that object? 213 // Don't have that object?
@@ -218,10 +219,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
218 Scripts.TryGetValue(localID, out Obj); 219 Scripts.TryGetValue(localID, out Obj);
219 if (Obj.ContainsKey(itemID) == true) 220 if (Obj.ContainsKey(itemID) == true)
220 Obj.Remove(itemID); 221 Obj.Remove(itemID);
221
222 } 222 }
223
223 #endregion 224 #endregion
225
224 #region Start/Stop/Reset script 226 #region Start/Stop/Reset script
227
225 /// <summary> 228 /// <summary>
226 /// Fetches, loads and hooks up a script to an objects events 229 /// Fetches, loads and hooks up a script to an objects events
227 /// </summary> 230 /// </summary>
@@ -235,6 +238,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
235 ls.script = Script; 238 ls.script = Script;
236 loadQueue.Enqueue(ls); 239 loadQueue.Enqueue(ls);
237 } 240 }
241
238 /// <summary> 242 /// <summary>
239 /// Disables and unloads a script 243 /// Disables and unloads a script
240 /// </summary> 244 /// </summary>
@@ -247,6 +251,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
247 ls.itemID = itemID; 251 ls.itemID = itemID;
248 unloadQueue.Enqueue(ls); 252 unloadQueue.Enqueue(ls);
249 } 253 }
254
250 public void ResetScript(uint localID, LLUUID itemID) 255 public void ResetScript(uint localID, LLUUID itemID)
251 { 256 {
252 string script = GetScript(localID, itemID).SourceCode; 257 string script = GetScript(localID, itemID).SourceCode;
@@ -267,12 +272,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
267 272
268 try 273 try
269 { 274 {
270
271
272
273
274 // Create a new instance of the compiler (currently we don't want reuse) 275 // Create a new instance of the compiler (currently we don't want reuse)
275 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); 276 Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler();
276 // Compile (We assume LSL) 277 // Compile (We assume LSL)
277 ScriptSource = LSLCompiler.CompileFromLSLText(Script); 278 ScriptSource = LSLCompiler.CompileFromLSLText(Script);
278 //Console.WriteLine("Compilation of " + FileName + " done"); 279 //Console.WriteLine("Compilation of " + FileName + " done");
@@ -289,10 +290,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
289 CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); 290 CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource);
290 291
291#if DEBUG 292#if DEBUG
292 Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); 293 Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before);
293#endif 294#endif
294 295
295 CompiledScript.SourceCode = ScriptSource; 296 CompiledScript.SourceCode = ScriptSource;
296 // Add it to our script memstruct 297 // Add it to our script memstruct
297 SetScript(localID, itemID, CompiledScript); 298 SetScript(localID, itemID, CompiledScript);
298 299
@@ -306,9 +307,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
306 CompiledScript.Start(LSLB); 307 CompiledScript.Start(LSLB);
307 308
308 // Fire the first start-event 309 // Fire the first start-event
309 m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { }); 310 m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] {});
310
311
312 } 311 }
313 catch (Exception e) 312 catch (Exception e)
314 { 313 {
@@ -326,9 +325,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
326 m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); 325 m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString());
327 } 326 }
328 } 327 }
329
330
331
332 } 328 }
333 329
334 private void _StopScript(uint localID, LLUUID itemID) 330 private void _StopScript(uint localID, LLUUID itemID)
@@ -359,19 +355,24 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
359 // Tell AppDomain that we have stopped script 355 // Tell AppDomain that we have stopped script
360 m_scriptEngine.m_AppDomainManager.StopScript(ad); 356 m_scriptEngine.m_AppDomainManager.StopScript(ad);
361 } 357 }
362 catch(Exception e) 358 catch (Exception e)
363 { 359 {
364 Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() + ": " + e.ToString()); 360 Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() +
361 ": " + e.ToString());
365 } 362 }
366 } 363 }
367 private string ProcessYield(string FileName) 364
365 private string ProcessYield(string FileName)
368 { 366 {
369 // TODO: Create a new assembly and copy old but insert Yield Code 367 // TODO: Create a new assembly and copy old but insert Yield Code
370 //return TempDotNetMicroThreadingCodeInjector.TestFix(FileName); 368 //return TempDotNetMicroThreadingCodeInjector.TestFix(FileName);
371 return FileName; 369 return FileName;
372 } 370 }
371
373 #endregion 372 #endregion
373
374 #region Perform event execution in script 374 #region Perform event execution in script
375
375 /// <summary> 376 /// <summary>
376 /// Execute a LL-event-function in Script 377 /// Execute a LL-event-function in Script
377 /// </summary> 378 /// </summary>
@@ -381,7 +382,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
381 /// <param name="args">Arguments to pass to function</param> 382 /// <param name="args">Arguments to pass to function</param>
382 internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args) 383 internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args)
383 { 384 {
384
385 // Execute a function in the script 385 // Execute a function in the script
386 //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); 386 //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName);
387 LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID); 387 LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID);
@@ -390,28 +390,29 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
390 390
391 // Must be done in correct AppDomain, so leaving it up to the script itself 391 // Must be done in correct AppDomain, so leaving it up to the script itself
392 Script.Exec.ExecuteEvent(FunctionName, args); 392 Script.Exec.ExecuteEvent(FunctionName, args);
393
394 } 393 }
394
395 #endregion 395 #endregion
396 396
397 #region Script serialization/deserialization 397 #region Script serialization/deserialization
398
398 public void GetSerializedScript(uint localID, LLUUID itemID) 399 public void GetSerializedScript(uint localID, LLUUID itemID)
399 { 400 {
400 // Serialize the script and return it 401 // Serialize the script and return it
401 // Should not be a problem 402 // Should not be a problem
402 System.IO.FileStream fs = System.IO.File.Create("SERIALIZED_SCRIPT_" + itemID); 403 FileStream fs = File.Create("SERIALIZED_SCRIPT_" + itemID);
403 BinaryFormatter b = new BinaryFormatter(); 404 BinaryFormatter b = new BinaryFormatter();
404 b.Serialize(fs, GetScript(localID,itemID)); 405 b.Serialize(fs, GetScript(localID, itemID));
405 fs.Close(); 406 fs.Close();
406
407
408 } 407 }
408
409 public void PutSerializedScript(uint localID, LLUUID itemID) 409 public void PutSerializedScript(uint localID, LLUUID itemID)
410 { 410 {
411 // Deserialize the script and inject it into an AppDomain 411 // Deserialize the script and inject it into an AppDomain
412 412
413 // How to inject into an AppDomain? 413 // How to inject into an AppDomain?
414 } 414 }
415
415 #endregion 416 #endregion
416 } 417 }
417} 418} \ No newline at end of file