InnerScene.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using Axiom.Math;
  31. using libsecondlife;
  32. using libsecondlife.Packets;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Environment.Types;
  36. using OpenSim.Region.Physics.Manager;
  37. namespace OpenSim.Region.Environment.Scenes
  38. {
  39. public delegate void PhysicsCrash();
  40. public class InnerScene
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. #region Events
  44. protected internal event PhysicsCrash UnRecoverableError;
  45. private PhysicsCrash handlerPhysicsCrash = null;
  46. #endregion
  47. #region Fields
  48. protected internal Dictionary<LLUUID, ScenePresence> ScenePresences = new Dictionary<LLUUID, ScenePresence>();
  49. // SceneObjects is not currently populated or used.
  50. //public Dictionary<LLUUID, SceneObjectGroup> SceneObjects;
  51. protected internal Dictionary<LLUUID, EntityBase> Entities = new Dictionary<LLUUID, EntityBase>();
  52. protected internal Dictionary<LLUUID, ScenePresence> RestorePresences = new Dictionary<LLUUID, ScenePresence>();
  53. protected internal BasicQuadTreeNode QuadTree;
  54. protected RegionInfo m_regInfo;
  55. protected Scene m_parentScene;
  56. protected List<EntityBase> m_updateList = new List<EntityBase>();
  57. protected int m_numRootAgents = 0;
  58. protected int m_numPrim = 0;
  59. protected int m_numChildAgents = 0;
  60. protected int m_physicalPrim = 0;
  61. protected int m_activeScripts = 0;
  62. protected int m_scriptLPS = 0;
  63. protected internal object m_syncRoot = new object();
  64. protected internal PhysicsScene _PhyScene;
  65. #endregion
  66. protected internal InnerScene(Scene parent, RegionInfo regInfo)
  67. {
  68. m_parentScene = parent;
  69. m_regInfo = regInfo;
  70. QuadTree = new BasicQuadTreeNode(null, "/0/", 0, 0, (short)Constants.RegionSize, (short)Constants.RegionSize);
  71. QuadTree.Subdivide();
  72. QuadTree.Subdivide();
  73. }
  74. public PhysicsScene PhysicsScene
  75. {
  76. get { return _PhyScene; }
  77. set
  78. {
  79. // If we're not doing the initial set
  80. // Then we've got to remove the previous
  81. // event handler
  82. try
  83. {
  84. _PhyScene.OnPhysicsCrash -= physicsBasedCrash;
  85. }
  86. catch (NullReferenceException)
  87. {
  88. // This occurs when storing to _PhyScene the first time.
  89. // Is there a better way to check the event handler before
  90. // getting here
  91. // This can be safely ignored. We're setting the first inital
  92. // there are no event handler's registered.
  93. }
  94. _PhyScene = value;
  95. _PhyScene.OnPhysicsCrash += physicsBasedCrash;
  96. }
  97. }
  98. protected internal void Close()
  99. {
  100. lock (ScenePresences)
  101. {
  102. ScenePresences.Clear();
  103. }
  104. //SceneObjects.Clear();
  105. lock (Entities)
  106. {
  107. Entities.Clear();
  108. }
  109. }
  110. #region Update Methods
  111. protected internal void UpdatePreparePhysics()
  112. {
  113. // If we are using a threaded physics engine
  114. // grab the latest scene from the engine before
  115. // trying to process it.
  116. // PhysX does this (runs in the background).
  117. if (_PhyScene.IsThreaded)
  118. {
  119. _PhyScene.GetResults();
  120. }
  121. }
  122. protected internal void UpdateEntities()
  123. {
  124. List<EntityBase> updateEntities = GetEntities();
  125. foreach (EntityBase entity in updateEntities)
  126. {
  127. entity.Update();
  128. }
  129. }
  130. protected internal void UpdatePresences()
  131. {
  132. List<ScenePresence> updateScenePresences = GetScenePresences();
  133. foreach (ScenePresence pres in updateScenePresences)
  134. {
  135. pres.Update();
  136. }
  137. }
  138. protected internal float UpdatePhysics(double elapsed)
  139. {
  140. lock (m_syncRoot)
  141. {
  142. return _PhyScene.Simulate((float)elapsed);
  143. }
  144. }
  145. protected internal void UpdateEntityMovement()
  146. {
  147. List<EntityBase> moveEntities = GetEntities();
  148. foreach (EntityBase entity in moveEntities)
  149. {
  150. //cfk. This throws occaisional exceptions on a heavily used region
  151. //and I added this null check to try to preclude the exception.
  152. if (entity != null)
  153. entity.UpdateMovement();
  154. }
  155. }
  156. #endregion
  157. #region Entity Methods
  158. /// <summary>
  159. /// Add an object into the scene that has come from storage
  160. /// </summary>
  161. /// <param name="sceneObject"></param>
  162. /// <param name="attachToBackup">
  163. /// If true, changes to the object will be reflected in its persisted data
  164. /// If false, the persisted data will not be changed even if the object in the scene is changed
  165. /// </param>
  166. /// <param name="alreadyPersisted">
  167. /// If true, we won't persist this object until it changes
  168. /// If false, we'll persist this object immediately
  169. /// </param>
  170. /// <returns>
  171. /// true if the object was added, false if an object with the same uuid was already in the scene
  172. /// </returns>
  173. protected internal bool AddRestoredSceneObject(
  174. SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
  175. {
  176. sceneObject.RegionHandle = m_regInfo.RegionHandle;
  177. sceneObject.SetScene(m_parentScene);
  178. foreach (SceneObjectPart part in sceneObject.Children.Values)
  179. {
  180. part.LocalId = m_parentScene.PrimIDAllocate();
  181. }
  182. sceneObject.UpdateParentIDs();
  183. if (!alreadyPersisted)
  184. {
  185. sceneObject.ForceInventoryPersistence();
  186. sceneObject.HasGroupChanged = true;
  187. }
  188. return AddSceneObject(sceneObject, attachToBackup);
  189. }
  190. /// <summary>
  191. /// Add a newly created object to the scene. This will both update the scene, and send information about the
  192. /// new object to all clients interested in the scene.
  193. /// </summary>
  194. /// <param name="sceneObject"></param>
  195. /// <param name="attachToBackup">
  196. /// If true, the object is made persistent into the scene.
  197. /// If false, the object will not persist over server restarts
  198. /// </param>
  199. /// <returns>
  200. /// true if the object was added, false if an object with the same uuid was already in the scene
  201. /// </returns>
  202. protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup)
  203. {
  204. // Ensure that we persist this new scene object
  205. sceneObject.HasGroupChanged = true;
  206. return AddSceneObject(sceneObject, attachToBackup);
  207. }
  208. /// <summary>
  209. /// Add an object to the scene. This will both update the scene, and send information about the
  210. /// new object to all clients interested in the scene.
  211. /// </summary>
  212. /// <param name="sceneObject"></param>
  213. /// <param name="attachToBackup">
  214. /// If true, the object is made persistent into the scene.
  215. /// If false, the object will not persist over server restarts
  216. /// </param>
  217. /// <returns>true if the object was added, false if an object with the same uuid was already in the scene
  218. /// </returns>
  219. protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup)
  220. {
  221. sceneObject.ApplyPhysics(m_parentScene.m_physicalPrim);
  222. sceneObject.ScheduleGroupForFullUpdate();
  223. lock (Entities)
  224. {
  225. if (!Entities.ContainsKey(sceneObject.UUID))
  226. {
  227. // QuadTree.AddSceneObject(sceneObject);
  228. Entities.Add(sceneObject.UUID, sceneObject);
  229. m_numPrim += sceneObject.Children.Count;
  230. if (attachToBackup)
  231. sceneObject.AttachToBackup();
  232. return true;
  233. }
  234. return false;
  235. }
  236. }
  237. /// <summary>
  238. /// Delete an object from the scene
  239. /// </summary>
  240. /// <param name="sceneObject"></param>
  241. /// <returns>true if the object was deleted, false if there was no object to delete</returns>
  242. protected internal bool DeleteSceneObject(LLUUID uuid, bool resultOfObjectLinked)
  243. {
  244. lock (Entities)
  245. {
  246. if (Entities.ContainsKey(uuid))
  247. {
  248. if (!resultOfObjectLinked)
  249. {
  250. m_numPrim -= ((SceneObjectGroup)Entities[uuid]).Children.Count;
  251. }
  252. Entities.Remove(uuid);
  253. return true;
  254. }
  255. }
  256. return false;
  257. }
  258. /// <summary>
  259. /// Add an entity to the list of prims to process on the next update
  260. /// </summary>
  261. /// <param name="obj">
  262. /// A <see cref="EntityBase"/>
  263. /// </param>
  264. protected internal void AddToUpdateList(EntityBase obj)
  265. {
  266. lock (m_updateList)
  267. {
  268. if (!m_updateList.Contains(obj))
  269. {
  270. m_updateList.Add(obj);
  271. }
  272. }
  273. }
  274. /// <summary>
  275. /// Process all pending updates
  276. /// </summary>
  277. protected internal void ProcessUpdates()
  278. {
  279. lock (m_updateList)
  280. {
  281. for (int i = 0; i < m_updateList.Count; i++)
  282. {
  283. EntityBase entity = m_updateList[i];
  284. // Don't abort the whole update if one entity happens to give us an exception.
  285. try
  286. {
  287. // Check that the group was not deleted before the scheduled update
  288. // FIXME: This is merely a temporary measure to reduce the incidence of failure, when
  289. // an object has been deleted from a scene before update was processed.
  290. // A more fundamental overhaul of the update mechanism is required to eliminate all
  291. // the race conditions.
  292. if (!entity.IsDeleted)
  293. {
  294. m_updateList[i].Update();
  295. }
  296. }
  297. catch (Exception e)
  298. {
  299. m_log.ErrorFormat(
  300. "[INNER SCENE]: Failed to update {0}, {1} - {2}", entity.Name, entity.UUID, e);
  301. }
  302. }
  303. m_updateList.Clear();
  304. }
  305. }
  306. protected internal void AddPhysicalPrim(int number)
  307. {
  308. m_physicalPrim++;
  309. }
  310. protected internal void RemovePhysicalPrim(int number)
  311. {
  312. m_physicalPrim--;
  313. }
  314. protected internal void AddToScriptLPS(int number)
  315. {
  316. m_scriptLPS += number;
  317. }
  318. protected internal void AddActiveScripts(int number)
  319. {
  320. m_activeScripts += number;
  321. }
  322. protected internal void DetachObject(uint objectLocalID, IClientAPI remoteClient)
  323. {
  324. List<EntityBase> EntityList = GetEntities();
  325. foreach (EntityBase obj in EntityList)
  326. {
  327. if (obj is SceneObjectGroup)
  328. {
  329. if (((SceneObjectGroup)obj).LocalId == objectLocalID)
  330. {
  331. SceneObjectGroup group = (SceneObjectGroup)obj;
  332. //group.DetachToGround();
  333. DetachSingleAttachmentToInv(group.GetFromAssetID(),remoteClient);
  334. }
  335. }
  336. }
  337. }
  338. protected internal void HandleUndo(IClientAPI remoteClient, LLUUID primId)
  339. {
  340. if (primId != LLUUID.Zero)
  341. {
  342. SceneObjectPart part = m_parentScene.GetSceneObjectPart(primId);
  343. if (part != null)
  344. part.Undo();
  345. }
  346. }
  347. protected internal void HandleObjectGroupUpdate(
  348. IClientAPI remoteClient, LLUUID GroupID, uint objectLocalID, LLUUID Garbage)
  349. {
  350. List<EntityBase> EntityList = GetEntities();
  351. foreach (EntityBase obj in EntityList)
  352. {
  353. if (obj is SceneObjectGroup)
  354. {
  355. if (((SceneObjectGroup)obj).LocalId == objectLocalID)
  356. {
  357. SceneObjectGroup group = (SceneObjectGroup)obj;
  358. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  359. group.SetGroup(GroupID, remoteClient);
  360. else
  361. remoteClient.SendAgentAlertMessage("You don't have permission to set the group", false);
  362. }
  363. }
  364. }
  365. }
  366. /// <summary>
  367. /// Event Handling routine for Attach Object
  368. /// </summary>
  369. /// <param name="remoteClient"></param>
  370. /// <param name="objectLocalID"></param>
  371. /// <param name="AttachmentPt"></param>
  372. /// <param name="rot"></param>
  373. protected internal void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot)
  374. {
  375. // Calls attach with a Zero position
  376. AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, LLVector3.Zero);
  377. }
  378. protected internal void RezSingleAttachment(
  379. IClientAPI remoteClient, LLUUID itemID, uint AttachmentPt,uint ItemFlags, uint NextOwnerMask)
  380. {
  381. SceneObjectGroup objatt = m_parentScene.RezObject(remoteClient, itemID, LLVector3.Zero, LLVector3.Zero, LLUUID.Zero, (byte)1, true,
  382. (uint)(PermissionMask.Copy | PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer),
  383. (uint)(PermissionMask.Copy | PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer),
  384. (uint)(PermissionMask.Copy | PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer),
  385. ItemFlags, false, false, remoteClient.AgentId, true);
  386. if (objatt != null)
  387. {
  388. AttachObject(remoteClient,objatt.LocalId,AttachmentPt,new LLQuaternion(0,0,0,1),objatt.AbsolutePosition);
  389. objatt.ScheduleGroupForFullUpdate();
  390. }
  391. }
  392. // What makes this method odd and unique is it tries to detach using an LLUUID.... Yay for standards.
  393. // To LocalId or LLUUID, *THAT* is the question. How now Brown LLUUID??
  394. protected internal void DetachSingleAttachmentToInv(LLUUID itemID, IClientAPI remoteClient)
  395. {
  396. if (itemID == LLUUID.Zero) // If this happened, someone made a mistake....
  397. return;
  398. List<EntityBase> EntityList = GetEntities();
  399. foreach (EntityBase obj in EntityList)
  400. {
  401. if (obj is SceneObjectGroup)
  402. {
  403. if (((SceneObjectGroup)obj).GetFromAssetID() == itemID)
  404. {
  405. SceneObjectGroup group = (SceneObjectGroup)obj;
  406. group.DetachToInventoryPrep();
  407. m_log.Debug("[DETACH]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString());
  408. m_parentScene.updateKnownAsset(remoteClient, group, group.GetFromAssetID(), group.OwnerID);
  409. m_parentScene.DeleteSceneObject(group);
  410. }
  411. }
  412. }
  413. }
  414. protected internal void AttachObject(
  415. IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, LLQuaternion rot, LLVector3 attachPos)
  416. {
  417. List<EntityBase> EntityList = GetEntities();
  418. foreach (EntityBase obj in EntityList)
  419. {
  420. if (obj is SceneObjectGroup)
  421. {
  422. if (((SceneObjectGroup)obj).LocalId == objectLocalID)
  423. {
  424. SceneObjectGroup group = (SceneObjectGroup)obj;
  425. if (m_parentScene.ExternalChecks.ExternalChecksCanTakeObject(obj.UUID, remoteClient.AgentId))
  426. {
  427. // If the attachment point isn't the same as the one previously used
  428. // set it's offset position = 0 so that it appears on the attachment point
  429. // and not in a weird location somewhere unknown.
  430. if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint())
  431. {
  432. attachPos = LLVector3.Zero;
  433. }
  434. // AttachmentPt 0 means the client chose to 'wear' the attachment.
  435. if (AttachmentPt == 0)
  436. {
  437. // Check object for stored attachment point
  438. AttachmentPt = (uint)group.GetAttachmentPoint();
  439. }
  440. // if we still didn't find a suitable attachment point.......
  441. if (AttachmentPt == 0)
  442. {
  443. // Stick it on left hand with Zero Offset from the attachment point.
  444. AttachmentPt = (uint)AttachmentPoint.LeftHand;
  445. attachPos = LLVector3.Zero;
  446. }
  447. m_log.Debug("[ATTACH]: Using attachpoint: " + AttachmentPt.ToString());
  448. // Saves and gets assetID
  449. if (group.GetFromAssetID() == LLUUID.Zero)
  450. {
  451. LLUUID newAssetID = m_parentScene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId);
  452. // sets assetID so client can show asset as 'attached' in inventory
  453. group.SetFromAssetID(newAssetID);
  454. }
  455. group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos);
  456. }
  457. else
  458. {
  459. remoteClient.SendAgentAlertMessage("You don't have sufficient permissions to attach this object", false);
  460. }
  461. }
  462. }
  463. }
  464. }
  465. protected internal ScenePresence CreateAndAddScenePresence(IClientAPI client, bool child, AvatarAppearance appearance)
  466. {
  467. ScenePresence newAvatar = null;
  468. newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance);
  469. newAvatar.IsChildAgent = child;
  470. AddScenePresence(newAvatar);
  471. return newAvatar;
  472. }
  473. /// <summary>
  474. /// Add a presence to the scene
  475. /// </summary>
  476. /// <param name="presence"></param>
  477. protected internal void AddScenePresence(ScenePresence presence)
  478. {
  479. bool child = presence.IsChildAgent;
  480. if (child)
  481. {
  482. m_numChildAgents++;
  483. m_log.Info("[SCENE]" + m_regInfo.RegionName + ": Creating new child agent.");
  484. }
  485. else
  486. {
  487. m_numRootAgents++;
  488. m_log.Info("[SCENE] " + m_regInfo.RegionName + ": Creating new root agent.");
  489. m_log.Info("[SCENE] " + m_regInfo.RegionName + ": Adding Physical agent.");
  490. presence.AddToPhysicalScene();
  491. }
  492. lock (Entities)
  493. {
  494. Entities[presence.UUID] = presence;
  495. }
  496. lock (ScenePresences)
  497. {
  498. ScenePresences[presence.UUID] = presence;
  499. }
  500. }
  501. /// <summary>
  502. /// Remove a presence from the scene
  503. /// </summary>
  504. protected internal void RemoveScenePresence(LLUUID agentID)
  505. {
  506. lock (Entities)
  507. {
  508. if (Entities.Remove(agentID))
  509. {
  510. //m_log.InfoFormat("[SCENE] Removed scene presence {0} from entities list", agentID);
  511. }
  512. else
  513. {
  514. m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene Entities list", agentID);
  515. }
  516. }
  517. lock (ScenePresences)
  518. {
  519. if (ScenePresences.Remove(agentID))
  520. {
  521. //m_log.InfoFormat("[SCENE] Removed scene presence {0}", agentID);
  522. }
  523. else
  524. {
  525. m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
  526. }
  527. }
  528. }
  529. protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
  530. {
  531. if (direction_RC_CR_T_F)
  532. {
  533. m_numRootAgents--;
  534. m_numChildAgents++;
  535. }
  536. else
  537. {
  538. m_numChildAgents--;
  539. m_numRootAgents++;
  540. }
  541. }
  542. protected internal void removeUserCount(bool TypeRCTF)
  543. {
  544. if (TypeRCTF)
  545. {
  546. m_numRootAgents--;
  547. }
  548. else
  549. {
  550. m_numChildAgents--;
  551. }
  552. }
  553. public int GetChildAgentCount()
  554. {
  555. // some network situations come in where child agents get closed twice.
  556. if (m_numChildAgents < 0)
  557. {
  558. m_numChildAgents = 0;
  559. }
  560. return m_numChildAgents;
  561. }
  562. public int GetRootAgentCount()
  563. {
  564. return m_numRootAgents;
  565. }
  566. public int GetTotalObjectsCount()
  567. {
  568. return m_numPrim;
  569. }
  570. public int GetActiveObjectsCount()
  571. {
  572. return m_physicalPrim;
  573. }
  574. public int GetActiveScriptsCount()
  575. {
  576. return m_activeScripts;
  577. }
  578. public int GetScriptLPS()
  579. {
  580. int returnval = m_scriptLPS;
  581. m_scriptLPS = 0;
  582. return returnval;
  583. }
  584. #endregion
  585. #region Get Methods
  586. /// <summary>
  587. /// Request a List of all scene presences in this scene. This is a new list, so no
  588. /// locking is required to iterate over it.
  589. /// </summary>
  590. /// <returns></returns>
  591. protected internal List<ScenePresence> GetScenePresences()
  592. {
  593. return new List<ScenePresence>(ScenePresences.Values);
  594. }
  595. protected internal List<ScenePresence> GetAvatars()
  596. {
  597. List<ScenePresence> result =
  598. GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
  599. return result;
  600. }
  601. /// <summary>
  602. /// Get the controlling client for the given avatar, if there is one.
  603. ///
  604. /// FIXME: The only user of the method right now is Caps.cs, in order to resolve a client API since it can't
  605. /// use the ScenePresence. This could be better solved in a number of ways - we could establish an
  606. /// OpenSim.Framework.IScenePresence, or move the caps code into a region package (which might be the more
  607. /// suitable solution).
  608. /// </summary>
  609. /// <param name="agentId"></param>
  610. /// <returns>null if either the avatar wasn't in the scene, or they do not have a controlling client</returns>
  611. protected internal IClientAPI GetControllingClient(LLUUID agentId)
  612. {
  613. ScenePresence presence = GetScenePresence(agentId);
  614. if (presence != null)
  615. {
  616. return presence.ControllingClient;
  617. }
  618. return null;
  619. }
  620. /// <summary>
  621. /// Request a filtered list of m_scenePresences in this World
  622. /// </summary>
  623. /// <returns></returns>
  624. protected internal List<ScenePresence> GetScenePresences(FilterAvatarList filter)
  625. {
  626. // No locking of scene presences here since we're passing back a list...
  627. List<ScenePresence> result = new List<ScenePresence>();
  628. List<ScenePresence> ScenePresencesList = GetScenePresences();
  629. foreach (ScenePresence avatar in ScenePresencesList)
  630. {
  631. if (filter(avatar))
  632. {
  633. result.Add(avatar);
  634. }
  635. }
  636. return result;
  637. }
  638. /// <summary>
  639. /// Request a scene presence by UUID
  640. /// </summary>
  641. /// <param name="avatarID"></param>
  642. /// <returns>null if the agent was not found</returns>
  643. protected internal ScenePresence GetScenePresence(LLUUID agentID)
  644. {
  645. ScenePresence sp;
  646. ScenePresences.TryGetValue(agentID, out sp);
  647. return sp;
  648. }
  649. /// <summary>
  650. /// Get a scene object group that contains the prim with the given local id
  651. /// </summary>
  652. /// <param name="localID"></param>
  653. /// <returns>null if no scene object group containing that prim is found</returns>
  654. private SceneObjectGroup GetGroupByPrim(uint localID)
  655. {
  656. List<EntityBase> EntityList = GetEntities();
  657. foreach (EntityBase ent in EntityList)
  658. {
  659. if (ent is SceneObjectGroup)
  660. {
  661. if (((SceneObjectGroup)ent).HasChildPrim(localID))
  662. return (SceneObjectGroup)ent;
  663. }
  664. }
  665. return null;
  666. }
  667. /// <summary>
  668. /// Get a scene object group that contains the prim with the given uuid
  669. /// </summary>
  670. /// <param name="fullID"></param>
  671. /// <returns>null if no scene object group containing that prim is found</returns>
  672. private SceneObjectGroup GetGroupByPrim(LLUUID fullID)
  673. {
  674. List<EntityBase> EntityList = GetEntities();
  675. foreach (EntityBase ent in EntityList)
  676. {
  677. if (ent is SceneObjectGroup)
  678. {
  679. if (((SceneObjectGroup)ent).HasChildPrim(fullID))
  680. return (SceneObjectGroup)ent;
  681. }
  682. }
  683. return null;
  684. }
  685. protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
  686. {
  687. // Primitive Ray Tracing
  688. float closestDistance = 280f;
  689. EntityIntersection returnResult = new EntityIntersection();
  690. List<EntityBase> EntityList = GetEntities();
  691. foreach (EntityBase ent in EntityList)
  692. {
  693. if (ent is SceneObjectGroup)
  694. {
  695. SceneObjectGroup reportingG = (SceneObjectGroup)ent;
  696. EntityIntersection result = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
  697. if (result.HitTF)
  698. {
  699. if (result.distance < closestDistance)
  700. {
  701. closestDistance = result.distance;
  702. returnResult = result;
  703. }
  704. }
  705. }
  706. }
  707. return returnResult;
  708. }
  709. /// <summary>
  710. /// Get a part contained in this scene.
  711. /// </summary>
  712. /// <param name="localID"></param>
  713. /// <returns>null if the part was not found</returns>
  714. protected internal SceneObjectPart GetSceneObjectPart(uint localID)
  715. {
  716. SceneObjectGroup group = GetGroupByPrim(localID);
  717. if (group != null)
  718. return group.GetChildPart(localID);
  719. else
  720. return null;
  721. }
  722. /// <summary>
  723. /// Get a part contained in this scene.
  724. /// </summary>
  725. /// <param name="fullID"></param>
  726. /// <returns>null if the part was not found</returns>
  727. protected internal SceneObjectPart GetSceneObjectPart(LLUUID fullID)
  728. {
  729. SceneObjectGroup group = GetGroupByPrim(fullID);
  730. if (group != null)
  731. return group.GetChildPart(fullID);
  732. else
  733. return null;
  734. }
  735. protected internal bool TryGetAvatar(LLUUID avatarId, out ScenePresence avatar)
  736. {
  737. ScenePresence presence;
  738. if (ScenePresences.TryGetValue(avatarId, out presence))
  739. {
  740. if (!presence.IsChildAgent)
  741. {
  742. avatar = presence;
  743. return true;
  744. }
  745. else
  746. {
  747. m_log.WarnFormat(
  748. "[INNER SCENE]: Requested avatar {0} could not be found in scene {1} since it is only registered as a child agent!",
  749. avatarId, m_parentScene.RegionInfo.RegionName);
  750. }
  751. }
  752. avatar = null;
  753. return false;
  754. }
  755. protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
  756. {
  757. lock (ScenePresences)
  758. {
  759. foreach (ScenePresence presence in ScenePresences.Values)
  760. {
  761. if (!presence.IsChildAgent)
  762. {
  763. string name = presence.ControllingClient.Name;
  764. if (String.Compare(avatarName, name, true) == 0)
  765. {
  766. avatar = presence;
  767. return true;
  768. }
  769. }
  770. }
  771. }
  772. avatar = null;
  773. return false;
  774. }
  775. /// <summary>
  776. /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over
  777. /// it
  778. /// </summary>
  779. /// <returns></returns>
  780. protected internal List<EntityBase> GetEntities()
  781. {
  782. lock (Entities)
  783. {
  784. return new List<EntityBase>(Entities.Values);
  785. }
  786. }
  787. protected internal Dictionary<uint, float> GetTopScripts()
  788. {
  789. Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
  790. List<EntityBase> EntityList = GetEntities();
  791. int limit = 0;
  792. foreach (EntityBase ent in EntityList)
  793. {
  794. if (ent is SceneObjectGroup)
  795. {
  796. SceneObjectGroup grp = (SceneObjectGroup)ent;
  797. if ((grp.RootPart.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Scripted) != 0)
  798. {
  799. if (grp.scriptScore >= 0.01)
  800. {
  801. topScripts.Add(grp.LocalId, grp.scriptScore);
  802. limit++;
  803. if (limit >= 100)
  804. {
  805. break;
  806. }
  807. }
  808. grp.scriptScore = 0;
  809. }
  810. }
  811. }
  812. return topScripts;
  813. }
  814. #endregion
  815. #region Other Methods
  816. protected internal void physicsBasedCrash()
  817. {
  818. handlerPhysicsCrash = UnRecoverableError;
  819. if (handlerPhysicsCrash != null)
  820. {
  821. handlerPhysicsCrash();
  822. }
  823. }
  824. protected internal LLUUID ConvertLocalIDToFullID(uint localID)
  825. {
  826. SceneObjectGroup group = GetGroupByPrim(localID);
  827. if (group != null)
  828. return group.GetPartsFullID(localID);
  829. else
  830. return LLUUID.Zero;
  831. }
  832. protected internal void SendAllSceneObjectsToClient(ScenePresence presence)
  833. {
  834. List<EntityBase> EntityList = GetEntities();
  835. foreach (EntityBase ent in EntityList)
  836. {
  837. if (ent is SceneObjectGroup)
  838. {
  839. // Only send child agents stuff in their draw distance.
  840. // This will need to be done for every agent once we figure out
  841. // what we're going to use to store prim that agents already got
  842. // the initial update for and what we'll use to limit the
  843. // space we check for new objects on movement.
  844. if (presence.IsChildAgent && m_parentScene.m_seeIntoRegionFromNeighbor)
  845. {
  846. LLVector3 oLoc = ((SceneObjectGroup)ent).AbsolutePosition;
  847. float distResult = (float)Util.GetDistanceTo(presence.AbsolutePosition, oLoc);
  848. //m_log.Info("[DISTANCE]: " + distResult.ToString());
  849. if (distResult < presence.DrawDistance)
  850. {
  851. // Send Only if we don't already know about it.
  852. // KnownPrim also makes the prim known when called.
  853. if (!presence.KnownPrim(((SceneObjectGroup)ent).UUID))
  854. ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence);
  855. }
  856. }
  857. else
  858. {
  859. ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence);
  860. }
  861. }
  862. }
  863. }
  864. protected internal void ForEachClient(Action<IClientAPI> action)
  865. {
  866. lock (ScenePresences)
  867. {
  868. foreach (ScenePresence presence in ScenePresences.Values)
  869. {
  870. action(presence.ControllingClient);
  871. }
  872. }
  873. }
  874. #endregion
  875. #region Client Event handlers
  876. /// <summary>
  877. ///
  878. /// </summary>
  879. /// <param name="localID"></param>
  880. /// <param name="scale"></param>
  881. /// <param name="remoteClient"></param>
  882. protected internal void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
  883. {
  884. SceneObjectGroup group = GetGroupByPrim(localID);
  885. if (group != null)
  886. {
  887. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  888. {
  889. group.Resize(scale, localID);
  890. }
  891. }
  892. }
  893. protected internal void UpdatePrimGroupScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
  894. {
  895. SceneObjectGroup group = GetGroupByPrim(localID);
  896. if (group != null)
  897. {
  898. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  899. {
  900. group.GroupResize(scale, localID);
  901. }
  902. }
  903. }
  904. /// <summary>
  905. /// This handles the nifty little tool tip that you get when you drag your mouse over an object
  906. /// Send to the Object Group to process. We don't know enough to service the request
  907. /// </summary>
  908. /// <param name="remoteClient"></param>
  909. /// <param name="AgentID"></param>
  910. /// <param name="RequestFlags"></param>
  911. /// <param name="ObjectID"></param>
  912. protected internal void RequestObjectPropertiesFamily(
  913. IClientAPI remoteClient, LLUUID AgentID, uint RequestFlags, LLUUID ObjectID)
  914. {
  915. SceneObjectGroup group = GetGroupByPrim(ObjectID);
  916. if (group != null)
  917. {
  918. group.ServiceObjectPropertiesFamilyRequest(remoteClient, AgentID, RequestFlags);
  919. }
  920. }
  921. /// <summary>
  922. ///
  923. /// </summary>
  924. /// <param name="localID"></param>
  925. /// <param name="rot"></param>
  926. /// <param name="remoteClient"></param>
  927. protected internal void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
  928. {
  929. SceneObjectGroup group = GetGroupByPrim(localID);
  930. if (group != null)
  931. {
  932. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))
  933. {
  934. group.UpdateSingleRotation(rot, localID);
  935. }
  936. }
  937. }
  938. /// <summary>
  939. ///
  940. /// </summary>
  941. /// <param name="localID"></param>
  942. /// <param name="rot"></param>
  943. /// <param name="remoteClient"></param>
  944. protected internal void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
  945. {
  946. SceneObjectGroup group = GetGroupByPrim(localID);
  947. if (group != null)
  948. {
  949. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))
  950. {
  951. group.UpdateGroupRotation(rot);
  952. }
  953. }
  954. }
  955. /// <summary>
  956. ///
  957. /// </summary>
  958. /// <param name="localID"></param>
  959. /// <param name="pos"></param>
  960. /// <param name="rot"></param>
  961. /// <param name="remoteClient"></param>
  962. protected internal void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
  963. {
  964. SceneObjectGroup group = GetGroupByPrim(localID);
  965. if (group != null)
  966. {
  967. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))
  968. {
  969. group.UpdateGroupRotation(pos, rot);
  970. }
  971. }
  972. }
  973. /// <summary>
  974. /// Update the position of the given part
  975. /// </summary>
  976. /// <param name="localID"></param>
  977. /// <param name="pos"></param>
  978. /// <param name="remoteClient"></param>
  979. protected internal void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
  980. {
  981. SceneObjectGroup group = GetGroupByPrim(localID);
  982. if (group != null)
  983. {
  984. // LLVector3 oldPos = group.AbsolutePosition;
  985. if (!m_parentScene.ExternalChecks.ExternalChecksCanObjectEntry(group.UUID,pos) && !group.RootPart.m_IsAttachment)
  986. {
  987. group.SendGroupTerseUpdate();
  988. return;
  989. }
  990. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId) || group.RootPart.m_IsAttachment)
  991. {
  992. group.UpdateSinglePosition(pos, localID);
  993. }
  994. }
  995. }
  996. /// <summary>
  997. /// Update the position of the given part
  998. /// </summary>
  999. /// <param name="localID"></param>
  1000. /// <param name="pos"></param>
  1001. /// <param name="remoteClient"></param>
  1002. protected internal void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
  1003. {
  1004. SceneObjectGroup group = GetGroupByPrim(localID);
  1005. if (group != null)
  1006. {
  1007. // LLVector3 oldPos = group.AbsolutePosition;
  1008. if (group.RootPart.m_IsAttachment)
  1009. {
  1010. group.UpdateGroupPosition(pos);
  1011. }
  1012. else
  1013. {
  1014. if (!m_parentScene.ExternalChecks.ExternalChecksCanObjectEntry(group.UUID,pos) && !group.RootPart.m_IsAttachment)
  1015. {
  1016. group.SendGroupTerseUpdate();
  1017. return;
  1018. }
  1019. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId) || group.RootPart.m_IsAttachment)
  1020. {
  1021. group.UpdateGroupPosition(pos);
  1022. }
  1023. }
  1024. }
  1025. }
  1026. /// <summary>
  1027. ///
  1028. /// </summary>
  1029. /// <param name="localID"></param>
  1030. /// <param name="texture"></param>
  1031. /// <param name="remoteClient"></param>
  1032. protected internal void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
  1033. {
  1034. SceneObjectGroup group = GetGroupByPrim(localID);
  1035. if (group != null)
  1036. {
  1037. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID,remoteClient.AgentId))
  1038. {
  1039. group.UpdateTextureEntry(localID, texture);
  1040. }
  1041. }
  1042. }
  1043. /// <summary>
  1044. ///
  1045. /// </summary>
  1046. /// <param name="localID"></param>
  1047. /// <param name="packet"></param>
  1048. /// <param name="remoteClient"></param>
  1049. protected internal void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
  1050. {
  1051. SceneObjectGroup group = GetGroupByPrim(localID);
  1052. if (group != null)
  1053. {
  1054. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  1055. {
  1056. group.UpdatePrimFlags(localID, (ushort)packet.Type, true, packet.ToBytes());
  1057. }
  1058. }
  1059. }
  1060. /// <summary>
  1061. /// Move the given object
  1062. /// </summary>
  1063. /// <param name="objectID"></param>
  1064. /// <param name="offset"></param>
  1065. /// <param name="pos"></param>
  1066. /// <param name="remoteClient"></param>
  1067. protected internal void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
  1068. {
  1069. SceneObjectGroup group = GetGroupByPrim(objectID);
  1070. if (group != null)
  1071. {
  1072. if (m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
  1073. {
  1074. group.GrabMovement(offset, pos, remoteClient);
  1075. }
  1076. // This is outside the above permissions condition
  1077. // so that if the object is locked the client moving the object
  1078. // get's it's position on the simulator even if it was the same as before
  1079. // This keeps the moving user's client in sync with the rest of the world.
  1080. group.SendGroupTerseUpdate();
  1081. }
  1082. }
  1083. /// <summary>
  1084. ///
  1085. /// </summary>
  1086. /// <param name="primLocalID"></param>
  1087. /// <param name="description"></param>
  1088. protected internal void PrimName(IClientAPI remoteClient, uint primLocalID, string name)
  1089. {
  1090. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1091. if (group != null)
  1092. {
  1093. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  1094. {
  1095. group.SetPartName(Util.CleanString(name), primLocalID);
  1096. }
  1097. }
  1098. }
  1099. /// <summary>
  1100. ///
  1101. /// </summary>
  1102. /// <param name="primLocalID"></param>
  1103. /// <param name="description"></param>
  1104. protected internal void PrimDescription(IClientAPI remoteClient, uint primLocalID, string description)
  1105. {
  1106. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1107. if (group != null)
  1108. {
  1109. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID, remoteClient.AgentId))
  1110. {
  1111. group.SetPartDescription(Util.CleanString(description), primLocalID);
  1112. }
  1113. }
  1114. }
  1115. protected internal void UpdateExtraParam(LLUUID agentID, uint primLocalID, ushort type, bool inUse, byte[] data)
  1116. {
  1117. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1118. if (group != null)
  1119. {
  1120. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.UUID,agentID))
  1121. {
  1122. group.UpdateExtraParam(primLocalID, type, inUse, data);
  1123. }
  1124. }
  1125. }
  1126. /// <summary>
  1127. ///
  1128. /// </summary>
  1129. /// <param name="primLocalID"></param>
  1130. /// <param name="shapeBlock"></param>
  1131. protected internal void UpdatePrimShape(LLUUID agentID, uint primLocalID, UpdateShapeArgs shapeBlock)
  1132. {
  1133. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1134. if (group != null)
  1135. {
  1136. if (m_parentScene.ExternalChecks.ExternalChecksCanEditObject(group.GetPartsFullID(primLocalID), agentID))
  1137. {
  1138. ObjectShapePacket.ObjectDataBlock shapeData = new ObjectShapePacket.ObjectDataBlock();
  1139. shapeData.ObjectLocalID = shapeBlock.ObjectLocalID;
  1140. shapeData.PathBegin = shapeBlock.PathBegin;
  1141. shapeData.PathCurve = shapeBlock.PathCurve;
  1142. shapeData.PathEnd = shapeBlock.PathEnd;
  1143. shapeData.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  1144. shapeData.PathRevolutions = shapeBlock.PathRevolutions;
  1145. shapeData.PathScaleX = shapeBlock.PathScaleX;
  1146. shapeData.PathScaleY = shapeBlock.PathScaleY;
  1147. shapeData.PathShearX = shapeBlock.PathShearX;
  1148. shapeData.PathShearY = shapeBlock.PathShearY;
  1149. shapeData.PathSkew = shapeBlock.PathSkew;
  1150. shapeData.PathTaperX = shapeBlock.PathTaperX;
  1151. shapeData.PathTaperY = shapeBlock.PathTaperY;
  1152. shapeData.PathTwist = shapeBlock.PathTwist;
  1153. shapeData.PathTwistBegin = shapeBlock.PathTwistBegin;
  1154. shapeData.ProfileBegin = shapeBlock.ProfileBegin;
  1155. shapeData.ProfileCurve = shapeBlock.ProfileCurve;
  1156. shapeData.ProfileEnd = shapeBlock.ProfileEnd;
  1157. shapeData.ProfileHollow = shapeBlock.ProfileHollow;
  1158. group.UpdateShape(shapeData, primLocalID);
  1159. }
  1160. }
  1161. }
  1162. /// <summary>
  1163. /// Initial method invoked when we receive a link objects request from the client.
  1164. /// </summary>
  1165. /// <param name="client"></param>
  1166. /// <param name="parentPrim"></param>
  1167. /// <param name="childPrims"></param>
  1168. protected internal void LinkObjects(IClientAPI client, uint parentPrim, List<uint> childPrims)
  1169. {
  1170. List<EntityBase> EntityList = GetEntities();
  1171. SceneObjectGroup parenPrim = null;
  1172. foreach (EntityBase ent in EntityList)
  1173. {
  1174. if (ent is SceneObjectGroup)
  1175. {
  1176. if (((SceneObjectGroup)ent).LocalId == parentPrim)
  1177. {
  1178. parenPrim = (SceneObjectGroup)ent;
  1179. break;
  1180. }
  1181. }
  1182. }
  1183. List<SceneObjectGroup> children = new List<SceneObjectGroup>();
  1184. if (parenPrim != null)
  1185. {
  1186. for (int i = 0; i < childPrims.Count; i++)
  1187. {
  1188. foreach (EntityBase ent in EntityList)
  1189. {
  1190. if (ent is SceneObjectGroup)
  1191. {
  1192. if (((SceneObjectGroup)ent).LocalId == childPrims[i])
  1193. {
  1194. children.Add((SceneObjectGroup)ent);
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }
  1200. foreach (SceneObjectGroup sceneObj in children)
  1201. {
  1202. parenPrim.LinkToGroup(sceneObj);
  1203. }
  1204. // We need to explicitly resend the newly link prim's object properties since no other actions
  1205. // occur on link to invoke this elsewhere (such as object selection)
  1206. parenPrim.GetProperties(client);
  1207. }
  1208. /// <summary>
  1209. /// Delink a linkset
  1210. /// </summary>
  1211. /// <param name="prims"></param>
  1212. protected internal void DelinkObjects(List<uint> primIds)
  1213. {
  1214. SceneObjectGroup parenPrim = null;
  1215. // Need a list of the SceneObjectGroup local ids
  1216. // XXX I'm anticipating that building this dictionary once is more efficient than
  1217. // repeated scanning of the Entity.Values for a large number of primIds. However, it might
  1218. // be more efficient yet to keep this dictionary permanently on hand.
  1219. Dictionary<uint, SceneObjectGroup> sceneObjects = new Dictionary<uint, SceneObjectGroup>();
  1220. List<EntityBase> EntityList = GetEntities();
  1221. foreach (EntityBase ent in EntityList)
  1222. {
  1223. if (ent is SceneObjectGroup)
  1224. {
  1225. SceneObjectGroup obj = (SceneObjectGroup)ent;
  1226. sceneObjects.Add(obj.LocalId, obj);
  1227. }
  1228. }
  1229. // Find the root prim among the prim ids we've been given
  1230. for (int i = 0; i < primIds.Count; i++)
  1231. {
  1232. if (sceneObjects.ContainsKey(primIds[i]))
  1233. {
  1234. parenPrim = sceneObjects[primIds[i]];
  1235. primIds.RemoveAt(i);
  1236. break;
  1237. }
  1238. }
  1239. if (parenPrim != null)
  1240. {
  1241. foreach (uint childPrimId in primIds)
  1242. {
  1243. parenPrim.DelinkFromGroup(childPrimId);
  1244. }
  1245. }
  1246. else
  1247. {
  1248. // If the first scan failed, we need to do a /deep/ scan of the linkages. This is /really/ slow
  1249. // We know that this is not the root prim now essentially, so we don't have to worry about remapping
  1250. // which one is the root prim
  1251. bool delinkedSomething = false;
  1252. for (int i = 0; i < primIds.Count; i++)
  1253. {
  1254. foreach (SceneObjectGroup grp in sceneObjects.Values)
  1255. {
  1256. SceneObjectPart gPart = grp.GetChildPart(primIds[i]);
  1257. if (gPart != null)
  1258. {
  1259. grp.DelinkFromGroup(primIds[i]);
  1260. delinkedSomething = true;
  1261. }
  1262. }
  1263. }
  1264. if (!delinkedSomething)
  1265. {
  1266. m_log.InfoFormat("[SCENE]: " +
  1267. "DelinkObjects(): Could not find a root prim out of {0} as given to a delink request!",
  1268. primIds);
  1269. }
  1270. }
  1271. }
  1272. protected internal void MakeObjectSearchable(IClientAPI remoteClient, bool IncludeInSearch, uint localID)
  1273. {
  1274. LLUUID user = remoteClient.AgentId;
  1275. LLUUID objid = null;
  1276. SceneObjectPart obj = null;
  1277. List<EntityBase> EntityList = GetEntities();
  1278. foreach (EntityBase ent in EntityList)
  1279. {
  1280. if (ent is SceneObjectGroup)
  1281. {
  1282. foreach (KeyValuePair<LLUUID, SceneObjectPart> subent in ((SceneObjectGroup)ent).Children)
  1283. {
  1284. if (subent.Value.LocalId == localID)
  1285. {
  1286. objid = subent.Key;
  1287. obj = subent.Value;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. //Protip: In my day, we didn't call them searchable objects, we called them limited point-to-point joints
  1293. //aka ObjectFlags.JointWheel = IncludeInSearch
  1294. //Permissions model: Object can be REMOVED from search IFF:
  1295. // * User owns object
  1296. //use CanEditObject
  1297. //Object can be ADDED to search IFF:
  1298. // * User owns object
  1299. // * Asset/DRM permission bit "modify" is enabled
  1300. //use CanEditObjectPosition
  1301. if (IncludeInSearch && m_parentScene.ExternalChecks.ExternalChecksCanEditObject(objid, user))
  1302. {
  1303. obj.ParentGroup.RootPart.AddFlag(LLObject.ObjectFlags.JointWheel);
  1304. }
  1305. else if (!IncludeInSearch && m_parentScene.ExternalChecks.ExternalChecksCanMoveObject(objid,user))
  1306. {
  1307. obj.ParentGroup.RootPart.RemFlag(LLObject.ObjectFlags.JointWheel);
  1308. }
  1309. }
  1310. /// <summary>
  1311. /// Duplicate the given object, Fire and Forget, No rotation, no return wrapper
  1312. /// </summary>
  1313. /// <param name="originalPrim"></param>
  1314. /// <param name="offset"></param>
  1315. /// <param name="flags"></param>
  1316. protected internal void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags, LLUUID AgentID, LLUUID GroupID)
  1317. {
  1318. //m_log.DebugFormat("[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", originalPrim, offset, AgentID);
  1319. // SceneObjectGroup dupe = DuplicateObject(originalPrim, offset, flags, AgentID, GroupID, Quaternion.Zero);
  1320. DuplicateObject(originalPrim, offset, flags, AgentID, GroupID, Quaternion.Zero);
  1321. }
  1322. /// <summary>
  1323. /// Duplicate the given object.
  1324. /// </summary>
  1325. /// <param name="originalPrim"></param>
  1326. /// <param name="offset"></param>
  1327. /// <param name="flags"></param>
  1328. protected internal SceneObjectGroup DuplicateObject(uint originalPrim, LLVector3 offset, uint flags, LLUUID AgentID, LLUUID GroupID, Quaternion rot)
  1329. {
  1330. //m_log.DebugFormat("[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", originalPrim, offset, AgentID);
  1331. List<EntityBase> EntityList = GetEntities();
  1332. SceneObjectGroup originPrim = null;
  1333. foreach (EntityBase ent in EntityList)
  1334. {
  1335. if (ent is SceneObjectGroup)
  1336. {
  1337. if (((SceneObjectGroup)ent).LocalId == originalPrim)
  1338. {
  1339. originPrim = (SceneObjectGroup)ent;
  1340. break;
  1341. }
  1342. }
  1343. }
  1344. if (originPrim != null)
  1345. {
  1346. if (m_parentScene.ExternalChecks.ExternalChecksCanDuplicateObject(originPrim.Children.Count, originPrim.UUID, AgentID, originPrim.AbsolutePosition))
  1347. {
  1348. SceneObjectGroup copy = originPrim.Copy(AgentID, GroupID, true);
  1349. copy.AbsolutePosition = copy.AbsolutePosition + offset;
  1350. copy.ResetIDs();
  1351. lock (Entities)
  1352. {
  1353. Entities.Add(copy.UUID, copy);
  1354. }
  1355. // Since we copy from a source group that is in selected
  1356. // state, but the copy is shown deselected in the viewer,
  1357. // We need to clear the selection flag here, else that
  1358. // prim never gets persisted at all. The client doesn't
  1359. // think it's selected, so it will never send a deselect...
  1360. copy.IsSelected = false;
  1361. m_numPrim += copy.Children.Count;
  1362. if (rot != Quaternion.Zero)
  1363. {
  1364. copy.UpdateGroupRotation(new LLQuaternion(rot.x, rot.y, rot.z, rot.w));
  1365. }
  1366. copy.CreateScriptInstances(0, false);
  1367. copy.HasGroupChanged = true;
  1368. copy.ScheduleGroupForFullUpdate();
  1369. return copy;
  1370. }
  1371. }
  1372. else
  1373. {
  1374. m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
  1375. }
  1376. return null;
  1377. }
  1378. /// <summary>
  1379. /// Calculates the distance between two Vector3s
  1380. /// </summary>
  1381. /// <param name="v1"></param>
  1382. /// <param name="v2"></param>
  1383. /// <returns></returns>
  1384. protected internal float Vector3Distance(Vector3 v1, Vector3 v2)
  1385. {
  1386. // We don't really need the double floating point precision...
  1387. // so casting it to a single
  1388. return
  1389. (float)
  1390. Math.Sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y) + (v1.z - v2.z) * (v1.z - v2.z));
  1391. }
  1392. #endregion
  1393. }
  1394. }