diff options
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 92 | ||||
-rwxr-xr-x | bin/OpenSimDefaults.ini | 16 |
2 files changed, 106 insertions, 2 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 8359440..d75afb6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Diagnostics; | ||
31 | using System.Drawing; | 32 | using System.Drawing; |
32 | using System.Drawing.Imaging; | 33 | using System.Drawing.Imaging; |
33 | using System.Runtime.Remoting.Lifetime; | 34 | using System.Runtime.Remoting.Lifetime; |
@@ -234,6 +235,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
234 | protected bool m_detectExitsInCastRay = false; | 235 | protected bool m_detectExitsInCastRay = false; |
235 | protected bool m_filterPartsInCastRay = false; | 236 | protected bool m_filterPartsInCastRay = false; |
236 | protected bool m_doAttachmentsInCastRay = false; | 237 | protected bool m_doAttachmentsInCastRay = false; |
238 | protected int m_msThrottleInCastRay = 200; | ||
239 | protected int m_msPerRegionInCastRay = 40; | ||
240 | protected int m_msPerAvatarInCastRay = 10; | ||
241 | protected int m_msMinInCastRay = 2; | ||
242 | protected int m_msMaxInCastRay = 40; | ||
243 | protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>(); | ||
237 | 244 | ||
238 | //An array of HTTP/1.1 headers that are not allowed to be used | 245 | //An array of HTTP/1.1 headers that are not allowed to be used |
239 | //as custom headers by llHTTPRequest. | 246 | //as custom headers by llHTTPRequest. |
@@ -353,6 +360,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
353 | m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay); | 360 | m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay); |
354 | m_filterPartsInCastRay = lslConfig.GetBoolean("FilterPartsInLlCastRay", m_filterPartsInCastRay); | 361 | m_filterPartsInCastRay = lslConfig.GetBoolean("FilterPartsInLlCastRay", m_filterPartsInCastRay); |
355 | m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay); | 362 | m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay); |
363 | m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay); | ||
364 | m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay); | ||
365 | m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay); | ||
366 | m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay); | ||
367 | m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay); | ||
356 | } | 368 | } |
357 | 369 | ||
358 | IConfig smtpConfig = seConfigSource.Configs["SMTP"]; | 370 | IConfig smtpConfig = seConfigSource.Configs["SMTP"]; |
@@ -14058,10 +14070,61 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
14058 | /// </summary> | 14070 | /// </summary> |
14059 | public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options) | 14071 | public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options) |
14060 | { | 14072 | { |
14061 | // Initialize | ||
14062 | m_host.AddScriptLPS(1); | 14073 | m_host.AddScriptLPS(1); |
14063 | List<RayHit> rayHits = new List<RayHit>(); | ||
14064 | LSL_List result = new LSL_List(); | 14074 | LSL_List result = new LSL_List(); |
14075 | |||
14076 | // Prepare throttle data | ||
14077 | int calledMs = Environment.TickCount; | ||
14078 | Stopwatch stopWatch = new Stopwatch(); | ||
14079 | stopWatch.Start(); | ||
14080 | UUID regionId = World.RegionInfo.RegionID; | ||
14081 | UUID userId = UUID.Zero; | ||
14082 | int msAvailable = 0; | ||
14083 | // Throttle per owner when attachment or "vehicle" (sat upon) | ||
14084 | if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatars().Count > 0) | ||
14085 | { | ||
14086 | userId = m_host.OwnerID; | ||
14087 | msAvailable = m_msPerAvatarInCastRay; | ||
14088 | } | ||
14089 | // Throttle per parcel when not attachment or vehicle | ||
14090 | else | ||
14091 | { | ||
14092 | LandData land = World.GetLandData(m_host.GetWorldPosition()); | ||
14093 | if (land != null) | ||
14094 | msAvailable = m_msPerRegionInCastRay * land.Area / 65536; | ||
14095 | } | ||
14096 | // Clamp for "oversized" parcels on varregions | ||
14097 | if (msAvailable > m_msMaxInCastRay) | ||
14098 | msAvailable = m_msMaxInCastRay; | ||
14099 | |||
14100 | // Check throttle data | ||
14101 | int fromCalledMs = calledMs - m_msThrottleInCastRay; | ||
14102 | lock (m_castRayCalls) | ||
14103 | { | ||
14104 | for (int i = m_castRayCalls.Count - 1; i >= 0; i--) | ||
14105 | { | ||
14106 | // Delete old calls from throttle data | ||
14107 | if (m_castRayCalls[i].CalledMs < fromCalledMs) | ||
14108 | m_castRayCalls.RemoveAt(i); | ||
14109 | // Use current region (in multi-region sims) | ||
14110 | else if (m_castRayCalls[i].RegionId == regionId) | ||
14111 | { | ||
14112 | // Reduce available time with recent calls | ||
14113 | if (m_castRayCalls[i].UserId == userId) | ||
14114 | msAvailable -= m_castRayCalls[i].UsedMs; | ||
14115 | } | ||
14116 | } | ||
14117 | } | ||
14118 | |||
14119 | // Return failure if not enough available time | ||
14120 | if (msAvailable < m_msMinInCastRay) | ||
14121 | { | ||
14122 | result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED)); | ||
14123 | return result; | ||
14124 | } | ||
14125 | |||
14126 | // Initialize | ||
14127 | List<RayHit> rayHits = new List<RayHit>(); | ||
14065 | float tol = m_floatToleranceInCastRay; | 14128 | float tol = m_floatToleranceInCastRay; |
14066 | Vector3 pos1Ray = start; | 14129 | Vector3 pos1Ray = start; |
14067 | Vector3 pos2Ray = end; | 14130 | Vector3 pos2Ray = end; |
@@ -14378,6 +14441,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
14378 | result.Add(new LSL_Vector(rayHit.Normal)); | 14441 | result.Add(new LSL_Vector(rayHit.Normal)); |
14379 | } | 14442 | } |
14380 | result.Add(new LSL_Integer(hitCount)); | 14443 | result.Add(new LSL_Integer(hitCount)); |
14444 | |||
14445 | // Add to throttle data | ||
14446 | stopWatch.Stop(); | ||
14447 | CastRayCall castRayCall = new CastRayCall(); | ||
14448 | castRayCall.RegionId = regionId; | ||
14449 | castRayCall.UserId = userId; | ||
14450 | castRayCall.CalledMs = calledMs; | ||
14451 | castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds; | ||
14452 | lock (m_castRayCalls) | ||
14453 | { | ||
14454 | m_castRayCalls.Add(castRayCall); | ||
14455 | } | ||
14456 | |||
14457 | // Return hits | ||
14381 | return result; | 14458 | return result; |
14382 | } | 14459 | } |
14383 | 14460 | ||
@@ -14412,6 +14489,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
14412 | } | 14489 | } |
14413 | 14490 | ||
14414 | /// <summary> | 14491 | /// <summary> |
14492 | /// Struct for llCastRay throttle data. | ||
14493 | /// </summary> | ||
14494 | public struct CastRayCall | ||
14495 | { | ||
14496 | public UUID RegionId; | ||
14497 | public UUID UserId; | ||
14498 | public int CalledMs; | ||
14499 | public int UsedMs; | ||
14500 | } | ||
14501 | |||
14502 | /// <summary> | ||
14415 | /// Helper to check if a ray intersects a shape bounding box. | 14503 | /// Helper to check if a ray intersects a shape bounding box. |
14416 | /// </summary> | 14504 | /// </summary> |
14417 | private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax) | 14505 | private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax) |
diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 489ee53..3db59dc 100755 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini | |||
@@ -1535,6 +1535,22 @@ | |||
1535 | ; Detect attachments in llCastRay V3 if true | 1535 | ; Detect attachments in llCastRay V3 if true |
1536 | DoAttachmentsInLlCastRay = false | 1536 | DoAttachmentsInLlCastRay = false |
1537 | 1537 | ||
1538 | ; Throttle period length in ms before which all old llCastRay use is discarded in llCastRay V3 | ||
1539 | ; The sum of AvailableTimeInMsPerRegionInLlCastRay and all AvailableTimeInMsPerAvatarInLlCastRay should not exceed this | ||
1540 | ThrottleTimeInMsInLlCastRay = 200 | ||
1541 | |||
1542 | ; Available time in ms for llCastRay per throttle period and 65536 m2 land area in llCastRay V3 | ||
1543 | AvailableTimeInMsPerRegionInLlCastRay = 40 | ||
1544 | |||
1545 | ; Available time in ms for llCastRay per throttle period and avatar when script in attachment or vehicle in llCastRay V3 | ||
1546 | AvailableTimeInMsPerAvatarInLlCastRay = 10 | ||
1547 | |||
1548 | ; Required available time in ms left to perform a new llCastRay in llCastRay V3 | ||
1549 | RequiredAvailableTimeInMsInLlCastRay = 2 | ||
1550 | |||
1551 | ; Maximum available time in ms possible in llCastRay V3, not to get too high values with varregions | ||
1552 | MaximumAvailableTimeInMsInLlCastRay = 40 | ||
1553 | |||
1538 | 1554 | ||
1539 | [DataSnapshot] | 1555 | [DataSnapshot] |
1540 | ; The following set of configs pertains to search. | 1556 | ; The following set of configs pertains to search. |