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 /OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |
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 'OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | 128 |
1 files changed, 54 insertions, 74 deletions
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); |