aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-02-23 14:52:34 +0000
committerUbitUmarov2018-02-23 14:52:34 +0000
commit2129d941acbc5f83aca4dc4c30a62d3226888136 (patch)
treee12f2391978c923ef780f558ee5a32d857ee9124 /OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
parentMerge branch 'master' into httptests (diff)
downloadopensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.zip
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.gz
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.bz2
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.xz
rename XMREngine as Yengine (still not all done), big mess source formating changes, move state files to proper folder, fix a source file locking on errors, more changes for cross platform including from Mike,... yes yes i know a messy commit
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs (renamed from OpenSim/Region/ScriptEngine/XMREngine/XMRInstMisc.cs)237
1 files changed, 133 insertions, 104 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMisc.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
index 6ff486a..8f020ce 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMisc.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
@@ -42,7 +42,7 @@ using OpenSim.Region.ScriptEngine.Interfaces;
42using OpenSim.Region.ScriptEngine.Shared; 42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api; 43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 44using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
45using OpenSim.Region.ScriptEngine.XMREngine; 45using OpenSim.Region.ScriptEngine.Yengine;
46using OpenSim.Region.Framework.Scenes; 46using OpenSim.Region.Framework.Scenes;
47using log4net; 47using log4net;
48 48
@@ -56,7 +56,7 @@ using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
56 56
57// This class exists in the main app domain 57// This class exists in the main app domain
58// 58//
59namespace OpenSim.Region.ScriptEngine.XMREngine 59namespace OpenSim.Region.ScriptEngine.Yengine
60{ 60{
61 public partial class XMRInstance 61 public partial class XMRInstance
62 { 62 {
@@ -80,57 +80,48 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
80 suspendOnCheckRunHold = true; 80 suspendOnCheckRunHold = true;
81 81
82 /* 82 /*
83 * Wait for it to stop executing and prevent it from starting again 83 * Don't send us any more events.
84 * as it can't run without a microthread.
85 */ 84 */
86 lock (m_RunLock) 85 lock(m_RunLock)
87 { 86 {
88 if (microthread != null) 87 if(m_Part != null)
89 { 88 {
90 m_RunOnePhase = "disposing"; 89 m_Part.RemoveScriptEvents(m_ItemID);
91 CheckRunLockInvariants(true); 90 AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID);
92 microthread.Dispose (); 91 m_Part = null;
93 microthread = null;
94 } 92 }
95 } 93 }
96 94
97 /* 95 /*
98 * Don't send us any more events.
99 */
100 if (m_Part != null)
101 {
102 xmrTrapRegionCrossing (0);
103 m_Part.RemoveScriptEvents(m_ItemID);
104 AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID);
105 m_Part = null;
106 }
107
108 /*
109 * Let script methods get garbage collected if no one else is using 96 * Let script methods get garbage collected if no one else is using
110 * them. 97 * them.
111 */ 98 */
112 DecObjCodeRefCount (); 99 DecObjCodeRefCount();
113 } 100 }
114 101
115 private void DecObjCodeRefCount () 102 private void DecObjCodeRefCount()
116 { 103 {
117 if (m_ObjCode != null) { 104 if(m_ObjCode != null)
118 lock (m_CompileLock) { 105 {
106 lock(m_CompileLock)
107 {
119 ScriptObjCode objCode; 108 ScriptObjCode objCode;
120 109
121 if (m_CompiledScriptObjCode.TryGetValue (m_ScriptObjCodeKey, out objCode) && 110 if(m_CompiledScriptObjCode.TryGetValue(m_ScriptObjCodeKey, out objCode) &&
122 (objCode == m_ObjCode) && 111 (objCode == m_ObjCode) &&
123 (-- objCode.refCount == 0)) { 112 (--objCode.refCount == 0))
124 m_CompiledScriptObjCode.Remove (m_ScriptObjCodeKey); 113 {
114 m_CompiledScriptObjCode.Remove(m_ScriptObjCodeKey);
125 } 115 }
126 } 116 }
127 m_ObjCode = null; 117 m_ObjCode = null;
128 } 118 }
129 } 119 }
130 120
131 public void Verbose (string format, params object[] args) 121 public void Verbose(string format, params object[] args)
132 { 122 {
133 if (m_Engine.m_Verbose) m_log.DebugFormat (format, args); 123 if(m_Engine.m_Verbose)
124 m_log.DebugFormat(format, args);
134 } 125 }
135 126
136 // Called by 'xmr top' console command 127 // Called by 'xmr top' console command
@@ -138,37 +129,39 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
138 // Sacha 129 // Sacha
139 public void RunTestTop() 130 public void RunTestTop()
140 { 131 {
141 if (m_InstEHSlice > 0){ 132 if(m_InstEHSlice > 0)
142 Console.WriteLine(m_DescName); 133 {
143 Console.WriteLine(" m_LocalID = " + m_LocalID); 134 Console.WriteLine(m_DescName);
144 Console.WriteLine(" m_ItemID = " + m_ItemID); 135 Console.WriteLine(" m_LocalID = " + m_LocalID);
145 Console.WriteLine(" m_Item.AssetID = " + m_Item.AssetID); 136 Console.WriteLine(" m_ItemID = " + m_ItemID);
146 Console.WriteLine(" m_StartParam = " + m_StartParam); 137 Console.WriteLine(" m_Item.AssetID = " + m_Item.AssetID);
147 Console.WriteLine(" m_PostOnRez = " + m_PostOnRez); 138 Console.WriteLine(" m_StartParam = " + m_StartParam);
148 Console.WriteLine(" m_StateSource = " + m_StateSource); 139 Console.WriteLine(" m_PostOnRez = " + m_PostOnRez);
149 Console.WriteLine(" m_SuspendCount = " + m_SuspendCount); 140 Console.WriteLine(" m_StateSource = " + m_StateSource);
150 Console.WriteLine(" m_SleepUntil = " + m_SleepUntil); 141 Console.WriteLine(" m_SuspendCount = " + m_SuspendCount);
151 Console.WriteLine(" m_IState = " + m_IState.ToString()); 142 Console.WriteLine(" m_SleepUntil = " + m_SleepUntil);
152 Console.WriteLine(" m_StateCode = " + GetStateName(stateCode)); 143 Console.WriteLine(" m_IState = " + m_IState.ToString());
153 Console.WriteLine(" eventCode = " + eventCode.ToString()); 144 Console.WriteLine(" m_StateCode = " + GetStateName(stateCode));
154 Console.WriteLine(" m_LastRanAt = " + m_LastRanAt.ToString()); 145 Console.WriteLine(" eventCode = " + eventCode.ToString());
155 Console.WriteLine(" heapUsed/Limit = " + xmrHeapUsed () + "/" + heapLimit); 146 Console.WriteLine(" m_LastRanAt = " + m_LastRanAt.ToString());
156 Console.WriteLine(" m_InstEHEvent = " + m_InstEHEvent.ToString()); 147 Console.WriteLine(" heapUsed/Limit = " + xmrHeapUsed() + "/" + heapLimit);
157 Console.WriteLine(" m_InstEHSlice = " + m_InstEHSlice.ToString()); 148 Console.WriteLine(" m_InstEHEvent = " + m_InstEHEvent.ToString());
158 } 149 Console.WriteLine(" m_InstEHSlice = " + m_InstEHSlice.ToString());
150 }
159 } 151 }
160 152
161 // Called by 'xmr ls' console command 153 // Called by 'xmr ls' console command
162 // to dump this script's state to console 154 // to dump this script's state to console
163 public string RunTestLs(bool flagFull) 155 public string RunTestLs(bool flagFull)
164 { 156 {
165 if (flagFull) { 157 if(flagFull)
158 {
166 StringBuilder sb = new StringBuilder(); 159 StringBuilder sb = new StringBuilder();
167 sb.AppendLine(m_DescName); 160 sb.AppendLine(m_DescName);
168 sb.AppendLine(" m_LocalID = " + m_LocalID); 161 sb.AppendLine(" m_LocalID = " + m_LocalID);
169 sb.AppendLine(" m_ItemID = " + m_ItemID + " (.state file)"); 162 sb.AppendLine(" m_ItemID = " + m_ItemID + " (.state file)");
170 sb.AppendLine(" m_Item.AssetID = " + m_Item.AssetID); 163 sb.AppendLine(" m_Item.AssetID = " + m_Item.AssetID);
171 sb.AppendLine(" m_Part.WorldPosition = " + m_Part.GetWorldPosition ()); 164 sb.AppendLine(" m_Part.WorldPosition = " + m_Part.GetWorldPosition());
172 sb.AppendLine(" m_ScriptObjCodeKey = " + m_ScriptObjCodeKey + " (source text)"); 165 sb.AppendLine(" m_ScriptObjCodeKey = " + m_ScriptObjCodeKey + " (source text)");
173 sb.AppendLine(" m_StartParam = " + m_StartParam); 166 sb.AppendLine(" m_StartParam = " + m_StartParam);
174 sb.AppendLine(" m_PostOnRez = " + m_PostOnRez); 167 sb.AppendLine(" m_PostOnRez = " + m_PostOnRez);
@@ -185,28 +178,28 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
185 sb.AppendLine(" suspOnCkRunHold = " + suspendOnCheckRunHold); 178 sb.AppendLine(" suspOnCkRunHold = " + suspendOnCheckRunHold);
186 sb.AppendLine(" suspOnCkRunTemp = " + suspendOnCheckRunTemp); 179 sb.AppendLine(" suspOnCkRunTemp = " + suspendOnCheckRunTemp);
187 sb.AppendLine(" m_CheckRunPhase = " + m_CheckRunPhase); 180 sb.AppendLine(" m_CheckRunPhase = " + m_CheckRunPhase);
188 sb.AppendLine(" heapUsed/Limit = " + xmrHeapUsed () + "/" + heapLimit); 181 sb.AppendLine(" heapUsed/Limit = " + xmrHeapUsed() + "/" + heapLimit);
189 sb.AppendLine(" m_InstEHEvent = " + m_InstEHEvent.ToString()); 182 sb.AppendLine(" m_InstEHEvent = " + m_InstEHEvent.ToString());
190 sb.AppendLine(" m_InstEHSlice = " + m_InstEHSlice.ToString()); 183 sb.AppendLine(" m_InstEHSlice = " + m_InstEHSlice.ToString());
191 sb.AppendLine(" m_CPUTime = " + m_CPUTime); 184 sb.AppendLine(" m_CPUTime = " + m_CPUTime);
192 sb.AppendLine(" callMode = " + callMode); 185 sb.AppendLine(" callMode = " + callMode);
193 sb.AppendLine(" captureStackFrames = " + captureStackFrames); 186 lock(m_QueueLock)
194 sb.AppendLine(" stackFramesRestored = " + stackFramesRestored);
195 lock (m_QueueLock)
196 { 187 {
197 sb.AppendLine(" m_Running = " + m_Running); 188 sb.AppendLine(" m_Running = " + m_Running);
198 foreach (EventParams evt in m_EventQueue) 189 foreach(EventParams evt in m_EventQueue)
199 { 190 {
200 sb.AppendLine(" evt.EventName = " + evt.EventName); 191 sb.AppendLine(" evt.EventName = " + evt.EventName);
201 } 192 }
202 } 193 }
203 return sb.ToString(); 194 return sb.ToString();
204 } else { 195 }
205 return String.Format("{0} {1} {2} {3} {4} {5}", 196 else
206 m_ItemID, 197 {
207 m_CPUTime.ToString("F3").PadLeft(9), 198 return String.Format("{0} {1} {2} {3} {4} {5}",
208 m_InstEHEvent.ToString().PadLeft(9), 199 m_ItemID,
209 m_IState.ToString().PadRight(10), 200 m_CPUTime.ToString("F3").PadLeft(9),
201 m_InstEHEvent.ToString().PadLeft(9),
202 m_IState.ToString().PadRight(10),
210 m_Part.GetWorldPosition().ToString().PadRight(32), 203 m_Part.GetWorldPosition().ToString().PadRight(32),
211 m_DescName); 204 m_DescName);
212 } 205 }
@@ -218,16 +211,16 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
218 */ 211 */
219 public int GetStateEventFlags(int stateCode) 212 public int GetStateEventFlags(int stateCode)
220 { 213 {
221 if ((stateCode < 0) || 214 if((stateCode < 0) ||
222 (stateCode >= m_ObjCode.scriptEventHandlerTable.GetLength(0))) 215 (stateCode >= m_ObjCode.scriptEventHandlerTable.GetLength(0)))
223 { 216 {
224 return 0; 217 return 0;
225 } 218 }
226 219
227 int code = 0; 220 int code = 0;
228 for (int i = 0 ; i < 32; i ++) 221 for(int i = 0; i < 32; i++)
229 { 222 {
230 if (m_ObjCode.scriptEventHandlerTable[stateCode, i] != null) 223 if(m_ObjCode.scriptEventHandlerTable[stateCode, i] != null)
231 { 224 {
232 code |= 1 << i; 225 code |= 1 << i;
233 } 226 }
@@ -239,41 +232,47 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
239 /** 232 /**
240 * @brief Get the .state file name. 233 * @brief Get the .state file name.
241 */ 234 */
242 public static string GetStateFileName (string scriptBasePath, UUID itemID) 235 public static string GetStateFileName(string scriptBasePath, UUID itemID)
243 { 236 {
244 return GetScriptFileName (scriptBasePath, itemID.ToString() + ".state"); 237 return GetScriptFileName(scriptBasePath, itemID.ToString() + ".state");
245 } 238 }
246 239
247 public string GetScriptFileName (string filename) 240 public string GetScriptFileName(string filename)
248 { 241 {
249 return GetScriptFileName (m_ScriptBasePath, filename); 242 return GetScriptFileName(m_ScriptBasePath, filename);
250 } 243 }
251 244
252 public static string GetScriptFileName (string scriptBasePath, string filename) 245 public static string GetScriptFileName(string scriptBasePath, string filename)
253 { 246 {
254 /* 247 /*
255 * Get old path, ie, all files lumped in a single huge directory. 248 * Get old path, ie, all files lumped in a single huge directory.
256 */ 249 */
257 string oldPath = Path.Combine (scriptBasePath, filename); 250 string oldPath = Path.Combine(scriptBasePath, filename);
258 251
259 /* 252 /*
260 * Get new path, ie, files split up based on first 2 chars of name. 253 * Get new path, ie, files split up based on first 2 chars of name.
261 */ 254 */
262 string subdir = filename.Substring (0, 2); 255 // string subdir = filename.Substring (0, 2);
263 filename = filename.Substring (2); 256 // filename = filename.Substring (2);
264 scriptBasePath = Path.Combine (scriptBasePath, subdir); 257 string subdir = filename.Substring(0, 1);
265 Directory.CreateDirectory (scriptBasePath); 258 filename = filename.Substring(1);
266 string newPath = Path.Combine (scriptBasePath, filename); 259 scriptBasePath = Path.Combine(scriptBasePath, subdir);
260 Directory.CreateDirectory(scriptBasePath);
261 string newPath = Path.Combine(scriptBasePath, filename);
267 262
268 /* 263 /*
269 * If file exists only in old location, move to new location. 264 * If file exists only in old location, move to new location.
270 * If file exists in both locations, delete old location. 265 * If file exists in both locations, delete old location.
271 */ 266 */
272 if (File.Exists (oldPath)) { 267 if(File.Exists(oldPath))
273 if (File.Exists (newPath)) { 268 {
274 File.Delete (oldPath); 269 if(File.Exists(newPath))
275 } else { 270 {
276 File.Move (oldPath, newPath); 271 File.Delete(oldPath);
272 }
273 else
274 {
275 File.Move(oldPath, newPath);
277 } 276 }
278 } 277 }
279 278
@@ -286,12 +285,15 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
286 /** 285 /**
287 * @brief Decode state code (int) to state name (string). 286 * @brief Decode state code (int) to state name (string).
288 */ 287 */
289 public string GetStateName (int stateCode) 288 public string GetStateName(int stateCode)
290 { 289 {
291 try { 290 try
291 {
292 return m_ObjCode.stateNames[stateCode]; 292 return m_ObjCode.stateNames[stateCode];
293 } catch { 293 }
294 return stateCode.ToString (); 294 catch
295 {
296 return stateCode.ToString();
295 } 297 }
296 } 298 }
297 299
@@ -300,42 +302,66 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
300 */ 302 */
301 public int StartParam 303 public int StartParam
302 { 304 {
303 get { return m_StartParam; } 305 get
304 set { m_StartParam = value; } 306 {
307 return m_StartParam;
308 }
309 set
310 {
311 m_StartParam = value;
312 }
305 } 313 }
306 314
307 public SceneObjectPart SceneObject 315 public SceneObjectPart SceneObject
308 { 316 {
309 get { return m_Part; } 317 get
318 {
319 return m_Part;
320 }
310 } 321 }
311 322
312 public DetectParams[] DetectParams 323 public DetectParams[] DetectParams
313 { 324 {
314 get { return m_DetectParams; } 325 get
315 set { m_DetectParams = value; } 326 {
327 return m_DetectParams;
328 }
329 set
330 {
331 m_DetectParams = value;
332 }
316 } 333 }
317 334
318 public UUID ItemID 335 public UUID ItemID
319 { 336 {
320 get { return m_ItemID; } 337 get
338 {
339 return m_ItemID;
340 }
321 } 341 }
322 342
323 public UUID AssetID 343 public UUID AssetID
324 { 344 {
325 get { return m_Item.AssetID; } 345 get
346 {
347 return m_Item.AssetID;
348 }
326 } 349 }
327 350
328 public bool Running 351 public bool Running
329 { 352 {
330 get { return m_Running; } 353 get
354 {
355 return m_Running;
356 }
331 set 357 set
332 { 358 {
333 lock (m_QueueLock) 359 lock(m_QueueLock)
334 { 360 {
335 m_Running = value; 361 m_Running = value;
336 if (!value) 362 if(!value)
337 { 363 {
338 EmptyEventQueues (); 364 EmptyEventQueues();
339 } 365 }
340 } 366 }
341 } 367 }
@@ -345,26 +371,28 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
345 * @brief Empty out the event queues. 371 * @brief Empty out the event queues.
346 * Assumes caller has the m_QueueLock locked. 372 * Assumes caller has the m_QueueLock locked.
347 */ 373 */
348 public void EmptyEventQueues () 374 public void EmptyEventQueues()
349 { 375 {
350 m_EventQueue.Clear(); 376 m_EventQueue.Clear();
351 for (int i = m_EventCounts.Length; -- i >= 0;) m_EventCounts[i] = 0; 377 for(int i = m_EventCounts.Length; --i >= 0;)
378 m_EventCounts[i] = 0;
352 } 379 }
353 380
354 /** 381 /**
355 * @brief Convert an LSL vector to an Openmetaverse vector. 382 * @brief Convert an LSL vector to an Openmetaverse vector.
356 */ 383 */
357 public static OpenMetaverse.Vector3 LSLVec2OMVec (LSL_Vector lslVec) 384 public static OpenMetaverse.Vector3 LSLVec2OMVec(LSL_Vector lslVec)
358 { 385 {
359 return new OpenMetaverse.Vector3 ((float)lslVec.x, (float)lslVec.y, (float)lslVec.z); 386 return new OpenMetaverse.Vector3((float)lslVec.x, (float)lslVec.y, (float)lslVec.z);
360 } 387 }
361 388
362 /** 389 /**
363 * @brief Extract an integer from an element of an LSL_List. 390 * @brief Extract an integer from an element of an LSL_List.
364 */ 391 */
365 public static int ListInt (object element) 392 public static int ListInt(object element)
366 { 393 {
367 if (element is LSL_Integer) { 394 if(element is LSL_Integer)
395 {
368 return (int)(LSL_Integer)element; 396 return (int)(LSL_Integer)element;
369 } 397 }
370 return (int)element; 398 return (int)element;
@@ -373,9 +401,10 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
373 /** 401 /**
374 * @brief Extract a string from an element of an LSL_List. 402 * @brief Extract a string from an element of an LSL_List.
375 */ 403 */
376 public static string ListStr (object element) 404 public static string ListStr(object element)
377 { 405 {
378 if (element is LSL_String) { 406 if(element is LSL_String)
407 {
379 return (string)(LSL_String)element; 408 return (string)(LSL_String)element;
380 } 409 }
381 return (string)element; 410 return (string)element;