aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-02-26 23:07:13 +0000
committerJustin Clark-Casey (justincc)2014-02-26 23:07:13 +0000
commit0e23374aa244bb1e6f949228bf37241296c52209 (patch)
tree248959fe3a45e92b676138d15f66f75c4ef0765e /OpenSim/Region/ScriptEngine/Shared/Api/Implementation
parentImprove regression test TestSetAppearance() (diff)
downloadopensim-SC-0e23374aa244bb1e6f949228bf37241296c52209.zip
opensim-SC-0e23374aa244bb1e6f949228bf37241296c52209.tar.gz
opensim-SC-0e23374aa244bb1e6f949228bf37241296c52209.tar.bz2
opensim-SC-0e23374aa244bb1e6f949228bf37241296c52209.tar.xz
Implement PRIM_ROTATION, PRIM_ROT_LOCAL, PRIM_POSITION and PRIM_POS_LOCAL when manipulating avatars via llSetLinkPrimitiveParams()
Combination of core parts of Freaky's patch at https://github.com/ft-/opensim-patches/blob/master/opensim-llsetlinkprimitive-agent-fix.patch plus further adjustments from myself. Resolves Mantises 6121, 6421, 6573, 6657
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs145
1 files changed, 128 insertions, 17 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 91885b7..25d8c54 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -313,6 +313,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
313 /// <returns> 313 /// <returns>
314 /// The link entity. null if not found. 314 /// The link entity. null if not found.
315 /// </returns> 315 /// </returns>
316 /// <param name='part'></param>
316 /// <param name='linknum'> 317 /// <param name='linknum'>
317 /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4). 318 /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
318 /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned. 319 /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
@@ -323,18 +324,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
323 /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then 324 /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
324 /// null is returned. 325 /// null is returned.
325 /// </param> 326 /// </param>
326 public ISceneEntity GetLinkEntity(int linknum) 327 public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
327 { 328 {
328 if (linknum < 0) 329 if (linknum < 0)
329 { 330 {
330 if (linknum == ScriptBaseClass.LINK_THIS) 331 if (linknum == ScriptBaseClass.LINK_THIS)
331 return m_host; 332 return part;
332 else 333 else
333 return null; 334 return null;
334 } 335 }
335 336
336 int actualPrimCount = m_host.ParentGroup.PrimCount; 337 int actualPrimCount = part.ParentGroup.PrimCount;
337 List<UUID> sittingAvatarIds = m_host.ParentGroup.GetSittingAvatars(); 338 List<UUID> sittingAvatarIds = part.ParentGroup.GetSittingAvatars();
338 int adjustedPrimCount = actualPrimCount + sittingAvatarIds.Count; 339 int adjustedPrimCount = actualPrimCount + sittingAvatarIds.Count;
339 340
340 // Special case for a single prim. In this case the linknum is zero. However, this will not match a single 341 // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
@@ -342,7 +343,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
342 if (linknum == 0) 343 if (linknum == 0)
343 { 344 {
344 if (actualPrimCount == 1 && sittingAvatarIds.Count == 0) 345 if (actualPrimCount == 1 && sittingAvatarIds.Count == 0)
345 return m_host; 346 return part;
346 347
347 return null; 348 return null;
348 } 349 }
@@ -351,7 +352,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
351 else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1) 352 else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
352 { 353 {
353 if (sittingAvatarIds.Count > 0) 354 if (sittingAvatarIds.Count > 0)
354 return m_host.ParentGroup.RootPart; 355 return part.ParentGroup.RootPart;
355 else 356 else
356 return null; 357 return null;
357 } 358 }
@@ -359,7 +360,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
359 { 360 {
360 if (linknum <= actualPrimCount) 361 if (linknum <= actualPrimCount)
361 { 362 {
362 return m_host.ParentGroup.GetLinkNumPart(linknum); 363 return part.ParentGroup.GetLinkNumPart(linknum);
363 } 364 }
364 else 365 else
365 { 366 {
@@ -427,6 +428,57 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
427 } 428 }
428 } 429 }
429 430
431 public List<ISceneEntity> GetLinkEntities(int linkType)
432 {
433 return GetLinkEntities(m_host, linkType);
434 }
435
436 public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
437 {
438 List<ISceneEntity> ret = new List<ISceneEntity>();
439 ret.Add(part);
440
441 switch (linkType)
442 {
443 case ScriptBaseClass.LINK_SET:
444 return new List<ISceneEntity>(part.ParentGroup.Parts);
445
446 case ScriptBaseClass.LINK_ROOT:
447 ret = new List<ISceneEntity>();
448 ret.Add(part.ParentGroup.RootPart);
449 return ret;
450
451 case ScriptBaseClass.LINK_ALL_OTHERS:
452 ret = new List<ISceneEntity>(part.ParentGroup.Parts);
453
454 if (ret.Contains(part))
455 ret.Remove(part);
456
457 return ret;
458
459 case ScriptBaseClass.LINK_ALL_CHILDREN:
460 ret = new List<ISceneEntity>(part.ParentGroup.Parts);
461
462 if (ret.Contains(part.ParentGroup.RootPart))
463 ret.Remove(part.ParentGroup.RootPart);
464 return ret;
465
466 case ScriptBaseClass.LINK_THIS:
467 return ret;
468
469 default:
470 if (linkType < 0)
471 return new List<ISceneEntity>();
472
473 ISceneEntity target = GetLinkEntity(part, linkType);
474 if (target == null)
475 return new List<ISceneEntity>();
476 ret = new List<ISceneEntity>();
477 ret.Add(target);
478 return ret;
479 }
480 }
481
430 //These are the implementations of the various ll-functions used by the LSL scripts. 482 //These are the implementations of the various ll-functions used by the LSL scripts.
431 public LSL_Float llSin(double f) 483 public LSL_Float llSin(double f)
432 { 484 {
@@ -3882,7 +3934,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3882 { 3934 {
3883 m_host.AddScriptLPS(1); 3935 m_host.AddScriptLPS(1);
3884 3936
3885 ISceneEntity entity = GetLinkEntity(linknum); 3937 ISceneEntity entity = GetLinkEntity(m_host, linknum);
3886 3938
3887 if (entity != null) 3939 if (entity != null)
3888 return entity.UUID.ToString(); 3940 return entity.UUID.ToString();
@@ -3933,7 +3985,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3933 { 3985 {
3934 m_host.AddScriptLPS(1); 3986 m_host.AddScriptLPS(1);
3935 3987
3936 ISceneEntity entity = GetLinkEntity(linknum); 3988 ISceneEntity entity = GetLinkEntity(m_host, linknum);
3937 3989
3938 if (entity != null) 3990 if (entity != null)
3939 return entity.Name; 3991 return entity.Name;
@@ -7371,22 +7423,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7371 7423
7372 protected void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc) 7424 protected void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
7373 { 7425 {
7374 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7426 List<ISceneEntity> entities = GetLinkEntities(linknumber);
7375 7427
7376 LSL_List remaining = null; 7428 LSL_List remaining = null;
7377 uint rulesParsed = 0; 7429 uint rulesParsed = 0;
7378 7430
7379 foreach (SceneObjectPart part in parts) 7431 foreach (ISceneEntity entity in entities)
7380 remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed); 7432 {
7433 if (entity is SceneObjectPart)
7434 remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
7435 else
7436 remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
7437 }
7381 7438
7382 while (remaining != null && remaining.Length > 2) 7439 while (remaining != null && remaining.Length > 2)
7383 { 7440 {
7384 linknumber = remaining.GetLSLIntegerItem(0); 7441 linknumber = remaining.GetLSLIntegerItem(0);
7385 rules = remaining.GetSublist(1, -1); 7442 rules = remaining.GetSublist(1, -1);
7386 parts = GetLinkParts(linknumber); 7443 entities = GetLinkEntities(linknumber);
7387 7444
7388 foreach (SceneObjectPart part in parts) 7445 foreach (ISceneEntity entity in entities)
7389 remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed); 7446 {
7447 if (entity is SceneObjectPart)
7448 remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
7449 else
7450 remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
7451 }
7390 } 7452 }
7391 } 7453 }
7392 7454
@@ -7956,6 +8018,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7956 } 8018 }
7957 } 8019 }
7958 } 8020 }
8021
8022 return null;
8023 }
8024
8025 protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
8026 {
8027 int idx = 0;
8028 int idxStart = 0;
8029
8030 try
8031 {
8032 while (idx < rules.Length)
8033 {
8034 ++rulesParsed;
8035 int code = rules.GetLSLIntegerItem(idx++);
8036
8037 int remain = rules.Length - idx;
8038 idxStart = idx;
8039
8040 LSL_Vector v;
8041
8042 switch (code)
8043 {
8044 case (int)ScriptBaseClass.PRIM_POSITION:
8045 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
8046 if (remain < 1)
8047 return null;
8048
8049 sp.OffsetPosition = rules.GetVector3Item(idx++);
8050 break;
8051
8052 case (int)ScriptBaseClass.PRIM_ROTATION:
8053 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
8054 if (remain < 1)
8055 return null;
8056
8057 sp.Rotation = rules.GetQuaternionItem(idx++);
8058
8059 break;
8060 }
8061 }
8062 }
8063 catch (InvalidCastException e)
8064 {
8065 Error(
8066 originFunc,
8067 string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
8068 }
8069
7959 return null; 8070 return null;
7960 } 8071 }
7961 8072
@@ -8225,7 +8336,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8225 8336
8226 int linknumber = remaining.GetLSLIntegerItem(0); 8337 int linknumber = remaining.GetLSLIntegerItem(0);
8227 rules = remaining.GetSublist(1, -1); 8338 rules = remaining.GetSublist(1, -1);
8228 entity = GetLinkEntity(linknumber); 8339 entity = GetLinkEntity(m_host, linknumber);
8229 } 8340 }
8230 } 8341 }
8231 8342
@@ -8240,7 +8351,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8240 { 8351 {
8241 m_host.AddScriptLPS(1); 8352 m_host.AddScriptLPS(1);
8242 8353
8243 return GetEntityParams(GetLinkEntity(linknumber), rules); 8354 return GetEntityParams(GetLinkEntity(m_host, linknumber), rules);
8244 } 8355 }
8245 8356
8246 public LSL_Vector GetAgentSize(ScenePresence sp) 8357 public LSL_Vector GetAgentSize(ScenePresence sp)