diff options
author | Tedd Hansen | 2007-08-22 18:09:38 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-22 18:09:38 +0000 |
commit | 5a86fd2c31ce0ede9825657c969ccaa1ef423d5c (patch) | |
tree | 66e62accbaf1b20242b82920537d40d156f0bf00 | |
parent | Added Scene.GetSceneObjectPart(uint localID) (diff) | |
download | opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.zip opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.tar.gz opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.tar.bz2 opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.tar.xz |
(Untested) Scripts are individually loaded into objects (on rez), and event fired likewise. Bugfixes coming in next commit.
Diffstat (limited to '')
8 files changed, 161 insertions, 141 deletions
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index b301bf2..867f16f 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs | |||
@@ -183,8 +183,6 @@ namespace OpenSim | |||
183 | 183 | ||
184 | OpenSim.Region.Environment.Scenes.Scripting.ScriptEngineInterface ScriptEngine = ScriptEngineLoader.LoadScriptEngine("DotNetEngine"); | 184 | OpenSim.Region.Environment.Scenes.Scripting.ScriptEngineInterface ScriptEngine = ScriptEngineLoader.LoadScriptEngine("DotNetEngine"); |
185 | scene.AddScriptEngine(ScriptEngine, m_log); | 185 | scene.AddScriptEngine(ScriptEngine, m_log); |
186 | // TODO: TEMP load default script | ||
187 | ScriptEngine.StartScript(Path.Combine("ScriptEngines", "Default.lsl"), new OpenSim.Region.Environment.Scenes.Scripting.NullScriptHost()); | ||
188 | 186 | ||
189 | //Server side object editing permissions checking | 187 | //Server side object editing permissions checking |
190 | if (m_permissions) | 188 | if (m_permissions) |
diff --git a/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs b/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs index 33021ee..5970fac 100644 --- a/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs +++ b/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs | |||
@@ -38,6 +38,6 @@ namespace OpenSim.Region.Environment.Scenes.Scripting | |||
38 | { | 38 | { |
39 | void InitializeEngine(OpenSim.Region.Environment.Scenes.Scene Sceneworld, OpenSim.Framework.Console.LogBase logger); | 39 | void InitializeEngine(OpenSim.Region.Environment.Scenes.Scene Sceneworld, OpenSim.Framework.Console.LogBase logger); |
40 | void Shutdown(); | 40 | void Shutdown(); |
41 | void StartScript(string ScriptID, IScriptHost ObjectID); | 41 | // void StartScript(string ScriptID, IScriptHost ObjectID); |
42 | } | 42 | } |
43 | } | 43 | } |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs index 2898bee..49f6712 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs | |||
@@ -9,6 +9,7 @@ using OpenSim.Region.Environment.Scenes; | |||
9 | using OpenSim.Region.Environment.Scenes.Scripting; | 9 | using OpenSim.Region.Environment.Scenes.Scripting; |
10 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; | 10 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; |
11 | using OpenSim.Region.ScriptEngine.Common; | 11 | using OpenSim.Region.ScriptEngine.Common; |
12 | using libsecondlife; | ||
12 | 13 | ||
13 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | 14 | namespace OpenSim.Region.ScriptEngine.DotNetEngine |
14 | { | 15 | { |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index ad2717c..9dd274e 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs | |||
@@ -13,39 +13,51 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
13 | { | 13 | { |
14 | private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); | 14 | private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); |
15 | private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); | 15 | private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); |
16 | private int ScriptCompileCounter = 0; | ||
16 | //private ICodeCompiler icc = codeProvider.CreateCompiler(); | 17 | //private ICodeCompiler icc = codeProvider.CreateCompiler(); |
17 | public string Compile(string LSOFileName) | 18 | public string CompileFromFile(string LSOFileName) |
18 | { | 19 | { |
19 | |||
20 | |||
21 | // Output assembly name | ||
22 | string OutFile = Path.Combine("ScriptEngines", Path.GetFileNameWithoutExtension(LSOFileName) + ".dll"); | ||
23 | //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); | ||
24 | |||
25 | Common.SendToDebug("Reading source code into memory"); | ||
26 | // TODO: Add error handling | ||
27 | string CS_Code; | 20 | string CS_Code; |
28 | switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) | 21 | switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) |
29 | { | 22 | { |
30 | case ".txt": | 23 | case ".txt": |
31 | case ".lsl": | 24 | case ".lsl": |
32 | Common.SendToDebug("Source code is LSL, converting to CS"); | 25 | Common.SendToDebug("Source code is LSL, converting to CS"); |
33 | CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName)); | 26 | return CompileFromLSLText(File.ReadAllText(LSOFileName)); |
34 | break; | ||
35 | case ".cs": | 27 | case ".cs": |
36 | Common.SendToDebug("Source code is CS"); | 28 | Common.SendToDebug("Source code is CS"); |
37 | CS_Code = File.ReadAllText(LSOFileName); | 29 | return CompileFromCSText(File.ReadAllText(LSOFileName)); |
38 | break; | ||
39 | default: | 30 | default: |
40 | throw new Exception("Unknown script type."); | 31 | throw new Exception("Unknown script type."); |
41 | } | 32 | } |
33 | } | ||
34 | /// <summary> | ||
35 | /// Converts script from LSL to CS and calls CompileFromCSText | ||
36 | /// </summary> | ||
37 | /// <param name="Script">LSL script</param> | ||
38 | /// <returns>Filename to .dll assembly</returns> | ||
39 | public string CompileFromLSLText(string Script) | ||
40 | { | ||
41 | return CompileFromCSText(LSL_Converter.Convert(Script)); | ||
42 | } | ||
43 | /// <summary> | ||
44 | /// Compile CS script to .Net assembly (.dll) | ||
45 | /// </summary> | ||
46 | /// <param name="Script">CS script</param> | ||
47 | /// <returns>Filename to .dll assembly</returns> | ||
48 | public string CompileFromCSText(string Script) | ||
49 | { | ||
42 | 50 | ||
43 | Common.SendToDebug("Compiling"); | 51 | |
52 | // Output assembly name | ||
53 | ScriptCompileCounter++; | ||
54 | string OutFile = Path.Combine("ScriptEngines", "Script_" + ScriptCompileCounter + ".dll"); | ||
55 | //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); | ||
44 | 56 | ||
45 | // DEBUG - write source to disk | 57 | // DEBUG - write source to disk |
46 | try | 58 | try |
47 | { | 59 | { |
48 | File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(LSOFileName) + ".cs"), CS_Code); | 60 | File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script); |
49 | } | 61 | } |
50 | catch { } | 62 | catch { } |
51 | 63 | ||
@@ -68,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
68 | //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); | 80 | //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); |
69 | parameters.GenerateExecutable = false; | 81 | parameters.GenerateExecutable = false; |
70 | parameters.OutputAssembly = OutFile; | 82 | parameters.OutputAssembly = OutFile; |
71 | CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, CS_Code); | 83 | CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script); |
72 | 84 | ||
73 | // Go through errors | 85 | // Go through errors |
74 | // TODO: Return errors to user somehow | 86 | // TODO: Return errors to user somehow |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs index 32353ce..92afcf3 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs | |||
@@ -42,7 +42,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
42 | class EventManager | 42 | class EventManager |
43 | { | 43 | { |
44 | private ScriptEngine myScriptEngine; | 44 | private ScriptEngine myScriptEngine; |
45 | public IScriptHost TEMP_OBJECT_ID; | 45 | //public IScriptHost TEMP_OBJECT_ID; |
46 | public EventManager(ScriptEngine _ScriptEngine) | 46 | public EventManager(ScriptEngine _ScriptEngine) |
47 | { | 47 | { |
48 | myScriptEngine = _ScriptEngine; | 48 | myScriptEngine = _ScriptEngine; |
@@ -51,19 +51,47 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
51 | // TODO: ADD SERVER HOOK TO LOAD A SCRIPT THROUGH myScriptEngine.ScriptManager | 51 | // TODO: ADD SERVER HOOK TO LOAD A SCRIPT THROUGH myScriptEngine.ScriptManager |
52 | 52 | ||
53 | // Hook up a test event to our test form | 53 | // Hook up a test event to our test form |
54 | myScriptEngine.Log.Verbose("ScriptEngine", "EventManager Hooking up dummy-event: touch_start"); | 54 | //myScriptEngine.Log.Verbose("ScriptEngine", "EventManager Hooking up to server events"); |
55 | // TODO: REPLACE THIS WITH A REAL TOUCH_START EVENT IN SERVER | ||
56 | myScriptEngine.World.EventManager.OnObjectGrab += new OpenSim.Region.Environment.Scenes.EventManager.ObjectGrabDelegate(touch_start); | 55 | myScriptEngine.World.EventManager.OnObjectGrab += new OpenSim.Region.Environment.Scenes.EventManager.ObjectGrabDelegate(touch_start); |
57 | //myScriptEngine.World.touch_start += new TempWorldInterfaceEventDelegates.touch_start(touch_start); | 56 | myScriptEngine.World.EventManager.OnRezScript += new OpenSim.Region.Environment.Scenes.EventManager.NewRezScript(OnRezScript); |
57 | |||
58 | } | 58 | } |
59 | 59 | ||
60 | public void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient) | 60 | public void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient) |
61 | { | 61 | { |
62 | // Add to queue for all scripts in ObjectID object | 62 | // Add to queue for all scripts in ObjectID object |
63 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventManager Event: touch_start"); | 63 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventManager Event: touch_start"); |
64 | myScriptEngine.myEventQueueManager.AddToObjectQueue(TEMP_OBJECT_ID, "touch_start", new object[] { (int)0 }); | 64 | myScriptEngine.myEventQueueManager.AddToObjectQueue(localID, "touch_start", new object[] { (int)1 }); |
65 | } | 65 | } |
66 | public void OnRezScript(uint localID, LLUUID itemID, string script) | ||
67 | { | ||
68 | // TODO: Add code to compile script and wire up script to object | ||
69 | // Either the script is a stand-alone entity with a reference to public host, | ||
70 | // Or the host has a reference to the script because it was in its inventory. | ||
66 | 71 | ||
72 | //myScriptEngine.myScriptManager.StartScript( | ||
73 | // Path.Combine("ScriptEngines", "Default.lsl"), | ||
74 | // new OpenSim.Region.Environment.Scenes.Scripting.NullScriptHost() | ||
75 | //); | ||
76 | myScriptEngine.myScriptManager.StartScript( | ||
77 | localID, | ||
78 | itemID, | ||
79 | script | ||
80 | ); | ||
81 | |||
82 | } | ||
83 | public void OnDeRezScript(uint localID, LLUUID itemID) | ||
84 | { | ||
85 | //myScriptEngine.myScriptManager.StartScript( | ||
86 | // Path.Combine("ScriptEngines", "Default.lsl"), | ||
87 | // new OpenSim.Region.Environment.Scenes.Scripting.NullScriptHost() | ||
88 | //); | ||
89 | myScriptEngine.myScriptManager.StopScript( | ||
90 | localID, | ||
91 | itemID | ||
92 | ); | ||
93 | |||
94 | } | ||
67 | 95 | ||
68 | // TODO: Replace placeholders below | 96 | // TODO: Replace placeholders below |
69 | // These needs to be hooked up to OpenSim during init of this class | 97 | // These needs to be hooked up to OpenSim during init of this class |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs index c2a4b88..3ef21db 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs | |||
@@ -32,6 +32,7 @@ using System.Text; | |||
32 | using System.Threading; | 32 | using System.Threading; |
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using OpenSim.Region.Environment.Scenes.Scripting; | 34 | using OpenSim.Region.Environment.Scenes.Scripting; |
35 | using libsecondlife; | ||
35 | 36 | ||
36 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | 37 | namespace OpenSim.Region.ScriptEngine.DotNetEngine |
37 | { | 38 | { |
@@ -64,16 +65,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
64 | /// </summary> | 65 | /// </summary> |
65 | private struct QueueItemStruct | 66 | private struct QueueItemStruct |
66 | { | 67 | { |
67 | public IScriptHost ObjectID; | 68 | public uint localID; |
68 | public string ScriptID; | 69 | public LLUUID itemID; |
69 | public string FunctionName; | 70 | public string FunctionName; |
70 | public object[] param; | 71 | public object[] param; |
71 | } | 72 | } |
72 | 73 | ||
73 | /// <summary> | 74 | /// <summary> |
74 | /// List of ObjectID locks for mutex processing of script events | 75 | /// List of localID locks for mutex processing of script events |
75 | /// </summary> | 76 | /// </summary> |
76 | private List<IScriptHost> ObjectLocks = new List<IScriptHost>(); | 77 | private List<uint> ObjectLocks = new List<uint>(); |
77 | private object TryLockLock = new object(); // Mutex lock object | 78 | private object TryLockLock = new object(); // Mutex lock object |
78 | 79 | ||
79 | private ScriptEngine myScriptEngine; | 80 | private ScriptEngine myScriptEngine; |
@@ -140,7 +141,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
140 | else | 141 | else |
141 | { | 142 | { |
142 | // Something in queue, process | 143 | // Something in queue, process |
143 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for ObjectID: " + QIS.ObjectID + ", ScriptID: " + QIS.ScriptID + ", FunctionName: " + QIS.FunctionName); | 144 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName); |
144 | 145 | ||
145 | // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD | 146 | // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD |
146 | lock (QueueLock) | 147 | lock (QueueLock) |
@@ -152,7 +153,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
152 | QIS = EventQueue.Dequeue(); | 153 | QIS = EventQueue.Dequeue(); |
153 | 154 | ||
154 | // Check if object is being processed by someone else | 155 | // Check if object is being processed by someone else |
155 | if (TryLock(QIS.ObjectID) == false) | 156 | if (TryLock(QIS.localID) == false) |
156 | { | 157 | { |
157 | // Object is already being processed, requeue it | 158 | // Object is already being processed, requeue it |
158 | EventQueue.Enqueue(QIS); | 159 | EventQueue.Enqueue(QIS); |
@@ -169,8 +170,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
169 | if (GotItem == true) | 170 | if (GotItem == true) |
170 | { | 171 | { |
171 | // Execute function | 172 | // Execute function |
172 | myScriptEngine.myScriptManager.ExecuteEvent(QIS.ObjectID, QIS.ScriptID, QIS.FunctionName, QIS.param); | 173 | try |
173 | ReleaseLock(QIS.ObjectID); | 174 | { |
175 | myScriptEngine.myScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.FunctionName, QIS.param); | ||
176 | } | ||
177 | finally | ||
178 | { | ||
179 | ReleaseLock(QIS.localID); | ||
180 | } | ||
174 | } | 181 | } |
175 | 182 | ||
176 | } // Something in queue | 183 | } // Something in queue |
@@ -183,37 +190,37 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
183 | } | 190 | } |
184 | 191 | ||
185 | /// <summary> | 192 | /// <summary> |
186 | /// Try to get a mutex lock on ObjectID | 193 | /// Try to get a mutex lock on localID |
187 | /// </summary> | 194 | /// </summary> |
188 | /// <param name="ObjectID"></param> | 195 | /// <param name="localID"></param> |
189 | /// <returns></returns> | 196 | /// <returns></returns> |
190 | private bool TryLock(IScriptHost ObjectID) | 197 | private bool TryLock(uint localID) |
191 | { | 198 | { |
192 | lock (TryLockLock) | 199 | lock (TryLockLock) |
193 | { | 200 | { |
194 | if (ObjectLocks.Contains(ObjectID) == true) | 201 | if (ObjectLocks.Contains(localID) == true) |
195 | { | 202 | { |
196 | return false; | 203 | return false; |
197 | } | 204 | } |
198 | else | 205 | else |
199 | { | 206 | { |
200 | ObjectLocks.Add(ObjectID); | 207 | ObjectLocks.Add(localID); |
201 | return true; | 208 | return true; |
202 | } | 209 | } |
203 | } | 210 | } |
204 | } | 211 | } |
205 | 212 | ||
206 | /// <summary> | 213 | /// <summary> |
207 | /// Release mutex lock on ObjectID | 214 | /// Release mutex lock on localID |
208 | /// </summary> | 215 | /// </summary> |
209 | /// <param name="ObjectID"></param> | 216 | /// <param name="localID"></param> |
210 | private void ReleaseLock(IScriptHost ObjectID) | 217 | private void ReleaseLock(uint localID) |
211 | { | 218 | { |
212 | lock (TryLockLock) | 219 | lock (TryLockLock) |
213 | { | 220 | { |
214 | if (ObjectLocks.Contains(ObjectID) == true) | 221 | if (ObjectLocks.Contains(localID) == true) |
215 | { | 222 | { |
216 | ObjectLocks.Remove(ObjectID); | 223 | ObjectLocks.Remove(localID); |
217 | } | 224 | } |
218 | } | 225 | } |
219 | } | 226 | } |
@@ -221,26 +228,26 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
221 | /// <summary> | 228 | /// <summary> |
222 | /// Add event to event execution queue | 229 | /// Add event to event execution queue |
223 | /// </summary> | 230 | /// </summary> |
224 | /// <param name="ObjectID"></param> | 231 | /// <param name="localID"></param> |
225 | /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> | 232 | /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> |
226 | /// <param name="param">Array of parameters to match event mask</param> | 233 | /// <param name="param">Array of parameters to match event mask</param> |
227 | public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param) | 234 | public void AddToObjectQueue(uint localID, string FunctionName, object[] param) |
228 | { | 235 | { |
229 | // Determine all scripts in Object and add to their queue | 236 | // Determine all scripts in Object and add to their queue |
230 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Adding ObjectID: " + ObjectID + ", FunctionName: " + FunctionName); | 237 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Adding localID: " + localID + ", FunctionName: " + FunctionName); |
231 | 238 | ||
232 | lock (QueueLock) | 239 | lock (QueueLock) |
233 | { | 240 | { |
234 | 241 | ||
235 | foreach (string ScriptID in myScriptEngine.myScriptManager.GetScriptKeys(ObjectID)) | 242 | foreach (LLUUID itemID in myScriptEngine.myScriptManager.GetScriptKeys(localID)) |
236 | { | 243 | { |
237 | // Add to each script in that object | 244 | // Add to each script in that object |
238 | // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? | 245 | // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? |
239 | 246 | ||
240 | // Create a structure and add data | 247 | // Create a structure and add data |
241 | QueueItemStruct QIS = new QueueItemStruct(); | 248 | QueueItemStruct QIS = new QueueItemStruct(); |
242 | QIS.ObjectID = ObjectID; | 249 | QIS.localID = localID; |
243 | QIS.ScriptID = ScriptID; | 250 | QIS.itemID = itemID; |
244 | QIS.FunctionName = FunctionName; | 251 | QIS.FunctionName = FunctionName; |
245 | QIS.param = param; | 252 | QIS.param = param; |
246 | 253 | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs index 2786943..77bd409 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs | |||
@@ -64,9 +64,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
64 | 64 | ||
65 | public void InitializeEngine(OpenSim.Region.Environment.Scenes.Scene Sceneworld, OpenSim.Framework.Console.LogBase logger) | 65 | public void InitializeEngine(OpenSim.Region.Environment.Scenes.Scene Sceneworld, OpenSim.Framework.Console.LogBase logger) |
66 | { | 66 | { |
67 | |||
67 | World = Sceneworld; | 68 | World = Sceneworld; |
68 | m_log = logger; | 69 | m_log = logger; |
69 | 70 | ||
71 | Log.Verbose("ScriptEngine", "DotNet & LSL ScriptEngine initializing"); | ||
72 | |||
70 | //m_logger.Status("ScriptEngine", "InitializeEngine"); | 73 | //m_logger.Status("ScriptEngine", "InitializeEngine"); |
71 | 74 | ||
72 | // Create all objects we'll be using | 75 | // Create all objects we'll be using |
@@ -78,30 +81,21 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
78 | // Should we iterate the region for scripts that needs starting? | 81 | // Should we iterate the region for scripts that needs starting? |
79 | // Or can we assume we are loaded before anything else so we can use proper events? | 82 | // Or can we assume we are loaded before anything else so we can use proper events? |
80 | 83 | ||
81 | // Event hook for when scripts are dragged to script inventory | ||
82 | World.EventManager.OnRezScript += NewRezScriptHandler; | ||
83 | 84 | ||
84 | } | 85 | } |
85 | 86 | ||
86 | private void NewRezScriptHandler(uint localID, LLUUID itemID, string script) | ||
87 | { | ||
88 | // TODO: Add code to compile script and wire up script to object | ||
89 | // Either the script is a stand-alone entity with a reference to public host, | ||
90 | // Or the host has a reference to the script because it was in its inventory. | ||
91 | } | ||
92 | |||
93 | public void Shutdown() | 87 | public void Shutdown() |
94 | { | 88 | { |
95 | // We are shutting down | 89 | // We are shutting down |
96 | } | 90 | } |
97 | 91 | ||
98 | // !!!FOR DEBUGGING ONLY!!! (for executing script directly from test app) | 92 | //// !!!FOR DEBUGGING ONLY!!! (for executing script directly from test app) |
99 | [Obsolete("!!!FOR DEBUGGING ONLY!!!")] | 93 | //[Obsolete("!!!FOR DEBUGGING ONLY!!!")] |
100 | public void StartScript(string ScriptID, IScriptHost ObjectID) | 94 | //public void StartScript(string ScriptID, IScriptHost ObjectID) |
101 | { | 95 | //{ |
102 | this.myEventManager.TEMP_OBJECT_ID = ObjectID; | 96 | // this.myEventManager.TEMP_OBJECT_ID = ObjectID; |
103 | Log.Status("ScriptEngine", "DEBUG FUNCTION: StartScript: " + ScriptID); | 97 | // Log.Status("ScriptEngine", "DEBUG FUNCTION: StartScript: " + ScriptID); |
104 | myScriptManager.StartScript(ScriptID, ObjectID); | 98 | // myScriptManager.StartScript(ScriptID, ObjectID); |
105 | } | 99 | //} |
106 | } | 100 | } |
107 | } | 101 | } |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 2be65e3..b7a4aca 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |||
@@ -37,6 +37,7 @@ using OpenSim.Region.Environment.Scenes.Scripting; | |||
37 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler; | 37 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler; |
38 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; | 38 | using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; |
39 | using OpenSim.Region.ScriptEngine.Common; | 39 | using OpenSim.Region.ScriptEngine.Common; |
40 | using libsecondlife; | ||
40 | 41 | ||
41 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | 42 | namespace OpenSim.Region.ScriptEngine.DotNetEngine |
42 | { | 43 | { |
@@ -53,7 +54,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
53 | public ScriptManager(ScriptEngine scriptEngine) | 54 | public ScriptManager(ScriptEngine scriptEngine) |
54 | { | 55 | { |
55 | m_scriptEngine = scriptEngine; | 56 | m_scriptEngine = scriptEngine; |
56 | m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager Start"); | ||
57 | AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); | 57 | AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); |
58 | } | 58 | } |
59 | 59 | ||
@@ -69,7 +69,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
69 | // Object<string, Script<string, script>> | 69 | // Object<string, Script<string, script>> |
70 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. | 70 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. |
71 | // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! | 71 | // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! |
72 | internal Dictionary<IScriptHost, Dictionary<string, LSL_BaseClass>> Scripts = new Dictionary<IScriptHost, Dictionary<string, LSL_BaseClass>>(); | 72 | internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>(); |
73 | public Scene World | 73 | public Scene World |
74 | { | 74 | { |
75 | get | 75 | get |
@@ -79,75 +79,75 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | internal Dictionary<string, LSL_BaseClass>.KeyCollection GetScriptKeys(IScriptHost ObjectID) | 82 | internal Dictionary<LLUUID, LSL_BaseClass>.KeyCollection GetScriptKeys(uint localID) |
83 | { | 83 | { |
84 | if (Scripts.ContainsKey(ObjectID) == false) | 84 | if (Scripts.ContainsKey(localID) == false) |
85 | return null; | 85 | return null; |
86 | 86 | ||
87 | Dictionary<string, LSL_BaseClass> Obj; | 87 | Dictionary<LLUUID, LSL_BaseClass> Obj; |
88 | Scripts.TryGetValue(ObjectID, out Obj); | 88 | Scripts.TryGetValue(localID, out Obj); |
89 | 89 | ||
90 | return Obj.Keys; | 90 | return Obj.Keys; |
91 | 91 | ||
92 | } | 92 | } |
93 | 93 | ||
94 | internal LSL_BaseClass GetScript(IScriptHost ObjectID, string ScriptID) | 94 | internal LSL_BaseClass GetScript(uint localID, LLUUID itemID) |
95 | { | 95 | { |
96 | if (Scripts.ContainsKey(ObjectID) == false) | 96 | if (Scripts.ContainsKey(localID) == false) |
97 | return null; | 97 | return null; |
98 | 98 | ||
99 | Dictionary<string, LSL_BaseClass> Obj; | 99 | Dictionary<LLUUID, LSL_BaseClass> Obj; |
100 | Scripts.TryGetValue(ObjectID, out Obj); | 100 | Scripts.TryGetValue(localID, out Obj); |
101 | if (Obj.ContainsKey(ScriptID) == false) | 101 | if (Obj.ContainsKey(itemID) == false) |
102 | return null; | 102 | return null; |
103 | 103 | ||
104 | // Get script | 104 | // Get script |
105 | LSL_BaseClass Script; | 105 | LSL_BaseClass Script; |
106 | Obj.TryGetValue(ScriptID, out Script); | 106 | Obj.TryGetValue(itemID, out Script); |
107 | 107 | ||
108 | return Script; | 108 | return Script; |
109 | 109 | ||
110 | } | 110 | } |
111 | internal void SetScript(IScriptHost ObjectID, string ScriptID, LSL_BaseClass Script) | 111 | internal void SetScript(uint localID, LLUUID itemID, LSL_BaseClass Script) |
112 | { | 112 | { |
113 | // Create object if it doesn't exist | 113 | // Create object if it doesn't exist |
114 | if (Scripts.ContainsKey(ObjectID) == false) | 114 | if (Scripts.ContainsKey(localID) == false) |
115 | { | 115 | { |
116 | Scripts.Add(ObjectID, new Dictionary<string, LSL_BaseClass>()); | 116 | Scripts.Add(localID, new Dictionary<LLUUID, LSL_BaseClass>()); |
117 | } | 117 | } |
118 | 118 | ||
119 | // Delete script if it exists | 119 | // Delete script if it exists |
120 | Dictionary<string, LSL_BaseClass> Obj; | 120 | Dictionary<LLUUID, LSL_BaseClass> Obj; |
121 | Scripts.TryGetValue(ObjectID, out Obj); | 121 | Scripts.TryGetValue(localID, out Obj); |
122 | if (Obj.ContainsKey(ScriptID) == true) | 122 | if (Obj.ContainsKey(itemID) == true) |
123 | Obj.Remove(ScriptID); | 123 | Obj.Remove(itemID); |
124 | 124 | ||
125 | // Add to object | 125 | // Add to object |
126 | Obj.Add(ScriptID, Script); | 126 | Obj.Add(itemID, Script); |
127 | 127 | ||
128 | } | 128 | } |
129 | internal void RemoveScript(IScriptHost ObjectID, string ScriptID) | 129 | internal void RemoveScript(uint localID, LLUUID itemID) |
130 | { | 130 | { |
131 | // Don't have that object? | 131 | // Don't have that object? |
132 | if (Scripts.ContainsKey(ObjectID) == false) | 132 | if (Scripts.ContainsKey(localID) == false) |
133 | return; | 133 | return; |
134 | 134 | ||
135 | // Delete script if it exists | 135 | // Delete script if it exists |
136 | Dictionary<string, LSL_BaseClass> Obj; | 136 | Dictionary<LLUUID, LSL_BaseClass> Obj; |
137 | Scripts.TryGetValue(ObjectID, out Obj); | 137 | Scripts.TryGetValue(localID, out Obj); |
138 | if (Obj.ContainsKey(ScriptID) == true) | 138 | if (Obj.ContainsKey(itemID) == true) |
139 | Obj.Remove(ScriptID); | 139 | Obj.Remove(itemID); |
140 | 140 | ||
141 | } | 141 | } |
142 | /// <summary> | 142 | /// <summary> |
143 | /// Fetches, loads and hooks up a script to an objects events | 143 | /// Fetches, loads and hooks up a script to an objects events |
144 | /// </summary> | 144 | /// </summary> |
145 | /// <param name="ScriptID"></param> | 145 | /// <param name="itemID"></param> |
146 | /// <param name="ObjectID"></param> | 146 | /// <param name="localID"></param> |
147 | public void StartScript(string ScriptID, IScriptHost ObjectID) | 147 | public void StartScript(uint localID, LLUUID itemID, string Script) |
148 | { | 148 | { |
149 | //IScriptHost root = host.GetRoot(); | 149 | //IScriptHost root = host.GetRoot(); |
150 | m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager StartScript: ScriptID: " + ScriptID + ", ObjectID: " + ObjectID); | 150 | m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); |
151 | 151 | ||
152 | // We will initialize and start the script. | 152 | // We will initialize and start the script. |
153 | // It will be up to the script itself to hook up the correct events. | 153 | // It will be up to the script itself to hook up the correct events. |
@@ -157,59 +157,39 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
157 | { | 157 | { |
158 | 158 | ||
159 | 159 | ||
160 | // * Fetch script from server | 160 | // Create a new instance of the compiler (currently we don't want reuse) |
161 | // DEBUG - ScriptID is an actual filename during debug | 161 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); |
162 | // (therefore we can also check type by looking at extension) | 162 | // Compile (We assume LSL) |
163 | FileName = ScriptID; | 163 | FileName = LSLCompiler.CompileFromLSLText(Script); |
164 | 164 | m_scriptEngine.Log.Verbose("ScriptEngine", "Compilation of " + FileName + " done"); | |
165 | // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) | ||
166 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Script extension: " + System.IO.Path.GetExtension(FileName).ToLower()); | ||
167 | switch (System.IO.Path.GetExtension(FileName).ToLower()) | ||
168 | { | ||
169 | case ".txt": | ||
170 | case ".lsl": | ||
171 | case ".cs": | ||
172 | m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager Script is CS/LSL, compiling to .Net Assembly"); | ||
173 | // Create a new instance of the compiler (currently we don't want reuse) | ||
174 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); | ||
175 | // Compile | ||
176 | FileName = LSLCompiler.Compile(FileName); | ||
177 | break; | ||
178 | default: | ||
179 | throw new Exception("Unknown script type."); | ||
180 | } | ||
181 | |||
182 | |||
183 | |||
184 | m_scriptEngine.Log.Verbose("ScriptEngine", "Compilation done"); | ||
185 | // * Insert yield into code | 165 | // * Insert yield into code |
186 | FileName = ProcessYield(FileName); | 166 | FileName = ProcessYield(FileName); |
187 | 167 | ||
188 | 168 | ||
189 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); | 169 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); |
190 | 170 | ||
191 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); | 171 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, localID); |
192 | long before; | 172 | long before; |
193 | before = GC.GetTotalMemory(true); | 173 | before = GC.GetTotalMemory(true); |
194 | LSL_BaseClass Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); | 174 | LSL_BaseClass CompiledScript = m_scriptEngine.myAppDomainManager.LoadScript(FileName); |
195 | Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); | 175 | Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); |
196 | before = GC.GetTotalMemory(true); | 176 | before = GC.GetTotalMemory(true); |
197 | Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); | 177 | //Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); |
198 | Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); | 178 | //Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); |
199 | //before = GC.GetTotalMemory(true); | 179 | //before = GC.GetTotalMemory(true); |
200 | //Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); | 180 | //Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); |
201 | //Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); | 181 | //Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); |
202 | 182 | ||
203 | 183 | ||
204 | // Add it to our temporary active script keeper | 184 | // Add it to our temporary active script keeper |
205 | //Scripts.Add(FullScriptID, Script); | 185 | //Scripts.Add(FullitemID, Script); |
206 | SetScript(ObjectID, ScriptID, Script); | 186 | SetScript(localID, itemID, CompiledScript); |
207 | // We need to give (untrusted) assembly a private instance of BuiltIns | 187 | // We need to give (untrusted) assembly a private instance of BuiltIns |
208 | // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. | 188 | // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. |
209 | LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(this, ObjectID); | 189 | LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(this, World.GetSceneObjectPart(localID)); |
210 | 190 | ||
211 | // Start the script - giving it BuiltIns | 191 | // Start the script - giving it BuiltIns |
212 | Script.Start(LSLB); | 192 | CompiledScript.Start(LSLB); |
213 | 193 | ||
214 | } | 194 | } |
215 | catch (Exception e) | 195 | catch (Exception e) |
@@ -219,16 +199,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
219 | 199 | ||
220 | 200 | ||
221 | } | 201 | } |
222 | public void StopScript(string ScriptID, IScriptHost ObjectID) | 202 | public void StopScript(uint localID, LLUUID itemID) |
223 | { | 203 | { |
224 | // Stop script | 204 | // Stop script |
225 | 205 | ||
226 | // Get AppDomain | 206 | // Get AppDomain |
227 | AppDomain ad = GetScript(ObjectID, ScriptID).Exec.GetAppDomain(); | 207 | AppDomain ad = GetScript(localID, itemID).Exec.GetAppDomain(); |
228 | // Tell script not to accept new requests | 208 | // Tell script not to accept new requests |
229 | GetScript(ObjectID, ScriptID).Exec.StopScript(); | 209 | GetScript(localID, itemID).Exec.StopScript(); |
230 | // Remove from internal structure | 210 | // Remove from internal structure |
231 | RemoveScript(ObjectID, ScriptID); | 211 | RemoveScript(localID, itemID); |
232 | // Tell AppDomain that we have stopped script | 212 | // Tell AppDomain that we have stopped script |
233 | m_scriptEngine.myAppDomainManager.StopScript(ad); | 213 | m_scriptEngine.myAppDomainManager.StopScript(ad); |
234 | } | 214 | } |
@@ -244,16 +224,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
244 | /// <summary> | 224 | /// <summary> |
245 | /// Execute a LL-event-function in Script | 225 | /// Execute a LL-event-function in Script |
246 | /// </summary> | 226 | /// </summary> |
247 | /// <param name="ObjectID">Object the script is located in</param> | 227 | /// <param name="localID">Object the script is located in</param> |
248 | /// <param name="ScriptID">Script ID</param> | 228 | /// <param name="itemID">Script ID</param> |
249 | /// <param name="FunctionName">Name of function</param> | 229 | /// <param name="FunctionName">Name of function</param> |
250 | /// <param name="args">Arguments to pass to function</param> | 230 | /// <param name="args">Arguments to pass to function</param> |
251 | internal void ExecuteEvent(IScriptHost ObjectID, string ScriptID, string FunctionName, object[] args) | 231 | internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args) |
252 | { | 232 | { |
253 | 233 | ||
254 | // Execute a function in the script | 234 | // Execute a function in the script |
255 | m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); | 235 | m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); |
256 | LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); | 236 | LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(localID, itemID); |
257 | 237 | ||
258 | // Must be done in correct AppDomain, so leaving it up to the script itself | 238 | // Must be done in correct AppDomain, so leaving it up to the script itself |
259 | Script.Exec.ExecuteEvent(FunctionName, args); | 239 | Script.Exec.ExecuteEvent(FunctionName, args); |