diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 9 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 17 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 151 |
3 files changed, 122 insertions, 55 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index ec7fde0..012ba90 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -467,13 +467,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
467 | 467 | ||
468 | public LSL_Vector llVecNorm(LSL_Vector v) | 468 | public LSL_Vector llVecNorm(LSL_Vector v) |
469 | { | 469 | { |
470 | m_host.AddScriptLPS(1); | 470 | m_host.AddScriptLPS(1); |
471 | double mag = LSL_Vector.Mag(v); | 471 | return LSL_Vector.Norm(v); |
472 | LSL_Vector nor = new LSL_Vector(); | ||
473 | nor.x = v.x / mag; | ||
474 | nor.y = v.y / mag; | ||
475 | nor.z = v.z / mag; | ||
476 | return nor; | ||
477 | } | 472 | } |
478 | 473 | ||
479 | public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b) | 474 | public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 1ea52c5..326f327 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -257,12 +257,17 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
257 | public static double Mag(Vector3 v) | 257 | public static double Mag(Vector3 v) |
258 | { | 258 | { |
259 | return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); | 259 | return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); |
260 | } | 260 | } |
261 | 261 | ||
262 | public static Vector3 Norm(Vector3 vector) | 262 | public static Vector3 Norm(Vector3 vector) |
263 | { | 263 | { |
264 | double mag = Mag(vector); | 264 | double mag = Mag(vector); |
265 | return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag); | 265 | if (mag > 0.0) |
266 | { | ||
267 | double invMag = 1.0 / mag; | ||
268 | return vector * invMag; | ||
269 | } | ||
270 | return new Vector3(0, 0, 0); | ||
266 | } | 271 | } |
267 | 272 | ||
268 | #endregion | 273 | #endregion |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 35d57d8..3bdbdfb 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -125,6 +125,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
125 | 125 | ||
126 | private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue(); | 126 | private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue(); |
127 | IWorkItemResult m_CurrentCompile = null; | 127 | IWorkItemResult m_CurrentCompile = null; |
128 | private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); | ||
128 | 129 | ||
129 | private void lockScriptsForRead(bool locked) | 130 | private void lockScriptsForRead(bool locked) |
130 | { | 131 | { |
@@ -555,11 +556,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
555 | 556 | ||
556 | if (stateSource == (int)StateSource.ScriptedRez) | 557 | if (stateSource == (int)StateSource.ScriptedRez) |
557 | { | 558 | { |
559 | lock (m_CompileDict) | ||
560 | { | ||
561 | m_CompileDict[itemID] = 0; | ||
562 | } | ||
563 | |||
558 | DoOnRezScript(parms); | 564 | DoOnRezScript(parms); |
559 | } | 565 | } |
560 | else | 566 | else |
561 | { | 567 | { |
562 | m_CompileQueue.Enqueue(parms); | 568 | m_CompileQueue.Enqueue(parms); |
569 | lock (m_CompileDict) | ||
570 | { | ||
571 | m_CompileDict[itemID] = 0; | ||
572 | } | ||
563 | 573 | ||
564 | if (m_CurrentCompile == null) | 574 | if (m_CurrentCompile == null) |
565 | { | 575 | { |
@@ -622,6 +632,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
622 | bool postOnRez = (bool)p[4]; | 632 | bool postOnRez = (bool)p[4]; |
623 | StateSource stateSource = (StateSource)p[5]; | 633 | StateSource stateSource = (StateSource)p[5]; |
624 | 634 | ||
635 | lock(m_CompileDict) | ||
636 | { | ||
637 | if (!m_CompileDict.ContainsKey(itemID)) | ||
638 | return false; | ||
639 | m_CompileDict.Remove(itemID); | ||
640 | } | ||
641 | |||
625 | // Get the asset ID of the script, so we can check if we | 642 | // Get the asset ID of the script, so we can check if we |
626 | // already have it. | 643 | // already have it. |
627 | 644 | ||
@@ -868,9 +885,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
868 | 885 | ||
869 | public void OnRemoveScript(uint localID, UUID itemID) | 886 | public void OnRemoveScript(uint localID, UUID itemID) |
870 | { | 887 | { |
871 | lockScriptsForRead(true); | 888 | // If it's not yet been compiled, make sure we don't try |
872 | // Do we even have it? | 889 | lock (m_CompileDict) |
873 | if (!m_Scripts.ContainsKey(itemID)) | 890 | { |
891 | if (m_CompileDict.ContainsKey(itemID)) | ||
892 | m_CompileDict.Remove(itemID); | ||
893 | } | ||
894 | |||
895 | lock (m_Scripts) | ||
874 | { | 896 | { |
875 | lockScriptsForRead(false); | 897 | lockScriptsForRead(false); |
876 | return; | 898 | return; |
@@ -1375,10 +1397,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1375 | 1397 | ||
1376 | try | 1398 | try |
1377 | { | 1399 | { |
1378 | FileStream tfs = File.Open(assemName + ".text", | 1400 | using (FileStream tfs = File.Open(assemName + ".text", |
1379 | FileMode.Open, FileAccess.Read); | 1401 | FileMode.Open, FileAccess.Read)) |
1380 | tfs.Read(tdata, 0, tdata.Length); | 1402 | { |
1381 | tfs.Close(); | 1403 | tfs.Read(tdata, 0, tdata.Length); |
1404 | tfs.Close(); | ||
1405 | } | ||
1382 | 1406 | ||
1383 | assem = new System.Text.ASCIIEncoding().GetString(tdata); | 1407 | assem = new System.Text.ASCIIEncoding().GetString(tdata); |
1384 | } | 1408 | } |
@@ -1398,9 +1422,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1398 | 1422 | ||
1399 | try | 1423 | try |
1400 | { | 1424 | { |
1401 | FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read); | 1425 | using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read)) |
1402 | fs.Read(data, 0, data.Length); | 1426 | { |
1403 | fs.Close(); | 1427 | fs.Read(data, 0, data.Length); |
1428 | fs.Close(); | ||
1429 | } | ||
1404 | 1430 | ||
1405 | assem = System.Convert.ToBase64String(data); | 1431 | assem = System.Convert.ToBase64String(data); |
1406 | } | 1432 | } |
@@ -1416,13 +1442,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1416 | 1442 | ||
1417 | if (File.Exists(fn + ".map")) | 1443 | if (File.Exists(fn + ".map")) |
1418 | { | 1444 | { |
1419 | FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read); | 1445 | using (FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read)) |
1420 | StreamReader msr = new StreamReader(mfs); | 1446 | { |
1421 | 1447 | using (StreamReader msr = new StreamReader(mfs)) | |
1422 | map = msr.ReadToEnd(); | 1448 | { |
1423 | 1449 | map = msr.ReadToEnd(); | |
1424 | msr.Close(); | 1450 | msr.Close(); |
1425 | mfs.Close(); | 1451 | } |
1452 | mfs.Close(); | ||
1453 | } | ||
1426 | } | 1454 | } |
1427 | 1455 | ||
1428 | XmlElement assemblyData = doc.CreateElement("", "Assembly", ""); | 1456 | XmlElement assemblyData = doc.CreateElement("", "Assembly", ""); |
@@ -1510,30 +1538,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1510 | { | 1538 | { |
1511 | Byte[] filedata = Convert.FromBase64String(base64); | 1539 | Byte[] filedata = Convert.FromBase64String(base64); |
1512 | 1540 | ||
1513 | FileStream fs = File.Create(path); | 1541 | try |
1514 | fs.Write(filedata, 0, filedata.Length); | 1542 | { |
1515 | fs.Close(); | 1543 | using (FileStream fs = File.Create(path)) |
1516 | 1544 | { | |
1517 | fs = File.Create(path + ".text"); | 1545 | fs.Write(filedata, 0, filedata.Length); |
1518 | StreamWriter sw = new StreamWriter(fs); | 1546 | fs.Close(); |
1519 | 1547 | } | |
1520 | sw.Write(base64); | 1548 | } |
1521 | 1549 | catch (IOException ex) | |
1522 | sw.Close(); | 1550 | { |
1523 | fs.Close(); | 1551 | // if there already exists a file at that location, it may be locked. |
1552 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); | ||
1553 | } | ||
1554 | try | ||
1555 | { | ||
1556 | using (FileStream fs = File.Create(path + ".text")) | ||
1557 | { | ||
1558 | using (StreamWriter sw = new StreamWriter(fs)) | ||
1559 | { | ||
1560 | sw.Write(base64); | ||
1561 | sw.Close(); | ||
1562 | } | ||
1563 | fs.Close(); | ||
1564 | } | ||
1565 | } | ||
1566 | catch (IOException ex) | ||
1567 | { | ||
1568 | // if there already exists a file at that location, it may be locked. | ||
1569 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); | ||
1570 | } | ||
1524 | } | 1571 | } |
1525 | } | 1572 | } |
1526 | 1573 | ||
1527 | string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); | 1574 | string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); |
1528 | statepath = Path.Combine(statepath, itemID.ToString() + ".state"); | 1575 | statepath = Path.Combine(statepath, itemID.ToString() + ".state"); |
1529 | 1576 | ||
1530 | FileStream sfs = File.Create(statepath); | 1577 | try |
1531 | StreamWriter ssw = new StreamWriter(sfs); | 1578 | { |
1532 | 1579 | using (FileStream sfs = File.Create(statepath)) | |
1533 | ssw.Write(stateE.OuterXml); | 1580 | { |
1534 | 1581 | using (StreamWriter ssw = new StreamWriter(sfs)) | |
1535 | ssw.Close(); | 1582 | { |
1536 | sfs.Close(); | 1583 | ssw.Write(stateE.OuterXml); |
1584 | ssw.Close(); | ||
1585 | } | ||
1586 | sfs.Close(); | ||
1587 | } | ||
1588 | } | ||
1589 | catch (IOException ex) | ||
1590 | { | ||
1591 | // if there already exists a file at that location, it may be locked. | ||
1592 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); | ||
1593 | } | ||
1537 | 1594 | ||
1538 | XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); | 1595 | XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); |
1539 | if (mapL.Count > 0) | 1596 | if (mapL.Count > 0) |
@@ -1543,13 +1600,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1543 | string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); | 1600 | string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); |
1544 | mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); | 1601 | mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); |
1545 | 1602 | ||
1546 | FileStream mfs = File.Create(mappath); | 1603 | try |
1547 | StreamWriter msw = new StreamWriter(mfs); | 1604 | { |
1548 | 1605 | using (FileStream mfs = File.Create(mappath)) | |
1549 | msw.Write(mapE.InnerText); | 1606 | { |
1550 | 1607 | using (StreamWriter msw = new StreamWriter(mfs)) | |
1551 | msw.Close(); | 1608 | { |
1552 | mfs.Close(); | 1609 | msw.Write(mapE.InnerText); |
1610 | msw.Close(); | ||
1611 | } | ||
1612 | mfs.Close(); | ||
1613 | } | ||
1614 | } | ||
1615 | catch (IOException ex) | ||
1616 | { | ||
1617 | // if there already exists a file at that location, it may be locked. | ||
1618 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); | ||
1619 | } | ||
1553 | } | 1620 | } |
1554 | 1621 | ||
1555 | return true; | 1622 | return true; |