ScenePresence.cs 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339
  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 System.Runtime.Serialization;
  31. using System.Security.Permissions;
  32. using Axiom.Math;
  33. using libsecondlife;
  34. using libsecondlife.Packets;
  35. using log4net;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Environment.Types;
  38. using OpenSim.Region.Physics.Manager;
  39. namespace OpenSim.Region.Environment.Scenes
  40. {
  41. [Serializable]
  42. public class ScenePresence : EntityBase, ISerializable
  43. {
  44. // ~ScenePresence()
  45. // {
  46. // System.Console.WriteLine("[ScenePresence] Destructor called");
  47. // }
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. public static AvatarAnimations Animations = new AvatarAnimations();
  50. public static byte[] DefaultTexture;
  51. public LLUUID currentParcelUUID = LLUUID.Zero;
  52. private List<LLUUID> m_animations = new List<LLUUID>();
  53. private List<int> m_animationSeqs = new List<int>();
  54. public Vector3 lastKnownAllowedPosition = new Vector3();
  55. public bool sentMessageAboutRestrictedParcelFlyingDown = false;
  56. private bool m_updateflag = false;
  57. private byte m_movementflag = 0;
  58. private readonly List<NewForce> m_forcesList = new List<NewForce>();
  59. private short m_updateCount = 0;
  60. private uint m_requestedSitTargetID = 0;
  61. private LLVector3 m_requestedSitOffset = new LLVector3();
  62. private float m_sitAvatarHeight = 2.0f;
  63. private float m_godlevel = 0;
  64. private LLVector3 m_LastChildAgentUpdatePosition = new LLVector3();
  65. private int m_perfMonMS = 0;
  66. private bool m_setAlwaysRun = false;
  67. private Quaternion m_bodyRot;
  68. public bool IsRestrictedToRegion = false;
  69. public string JID = string.Empty;
  70. // Agent moves with a PID controller causing a force to be exerted.
  71. private bool m_newForce = false;
  72. private bool m_newCoarseLocations = true;
  73. private bool m_gotAllObjectsInScene = false;
  74. private LLVector3 m_lastVelocity = LLVector3.Zero;
  75. // Default AV Height
  76. private float m_avHeight = 127.0f;
  77. protected RegionInfo m_regionInfo;
  78. protected ulong crossingFromRegion = 0;
  79. private readonly Vector3[] Dir_Vectors = new Vector3[6];
  80. private LLVector3 lastPhysPos = new LLVector3();
  81. // Position of agent's camera in world (region cordinates)
  82. protected Vector3 m_CameraCenter = new Vector3(0, 0, 0);
  83. // Use these three vectors to figure out what the agent is looking at
  84. // Convert it to a Matrix and/or Quaternion
  85. protected Vector3 m_CameraAtAxis = new Vector3(0, 0, 0);
  86. protected Vector3 m_CameraLeftAxis = new Vector3(0, 0, 0);
  87. protected Vector3 m_CameraUpAxis = new Vector3(0, 0, 0);
  88. private uint m_AgentControlFlags = (uint) 0;
  89. private LLQuaternion m_headrotation = new LLQuaternion();
  90. private byte m_state = (byte) 0;
  91. //Reuse the LLVector3 instead of creating a new one on the UpdateMovement method
  92. private LLVector3 movementvector = new LLVector3();
  93. private List<LLUUID> m_knownPrimUUID = new List<LLUUID>();
  94. // Agent's Draw distance.
  95. protected float m_DrawDistance = 0f;
  96. protected AvatarAppearance m_appearance;
  97. protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
  98. //neighbouring regions we have enabled a child agent in
  99. private readonly List<ulong> m_knownChildRegions = new List<ulong>();
  100. private SignificantClientMovement handlerSignificantClientMovement = null; //OnSignificantClientMovement;
  101. /// <summary>
  102. /// Implemented Control Flags
  103. /// </summary>
  104. private enum Dir_ControlFlags
  105. {
  106. DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS,
  107. DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG,
  108. DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS,
  109. DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG,
  110. DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
  111. DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
  112. DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
  113. }
  114. /// <summary>
  115. /// Position at which a significant movement was made
  116. /// </summary>
  117. private LLVector3 posLastSignificantMove = new LLVector3();
  118. public delegate void SignificantClientMovement(IClientAPI remote_client);
  119. public event SignificantClientMovement OnSignificantClientMovement;
  120. private UpdateQueue m_partsUpdateQueue = new UpdateQueue();
  121. private Dictionary<LLUUID, ScenePartUpdate> m_updateTimes = new Dictionary<LLUUID, ScenePartUpdate>();
  122. #region Properties
  123. /// <summary>
  124. /// Physical scene representation of this Avatar.
  125. /// </summary>
  126. public PhysicsActor PhysicsActor
  127. {
  128. set { m_physicsActor = value; }
  129. get { return m_physicsActor; }
  130. }
  131. public byte MovementFlag
  132. {
  133. set { m_movementflag = value; }
  134. get { return m_movementflag; }
  135. }
  136. public bool KnownPrim(LLUUID primID)
  137. {
  138. if (m_knownPrimUUID.Contains(primID))
  139. {
  140. return true;
  141. }
  142. m_knownPrimUUID.Add(primID);
  143. return false;
  144. }
  145. public bool Updated
  146. {
  147. set { m_updateflag = value; }
  148. get { return m_updateflag; }
  149. }
  150. private readonly ulong m_regionHandle;
  151. public ulong RegionHandle
  152. {
  153. get { return m_regionHandle; }
  154. }
  155. public Vector3 CameraPosition
  156. {
  157. get { return m_CameraCenter; }
  158. }
  159. private readonly string m_firstname;
  160. public string Firstname
  161. {
  162. get { return m_firstname; }
  163. }
  164. private readonly string m_lastname;
  165. public string Lastname
  166. {
  167. get { return m_lastname; }
  168. }
  169. public float DrawDistance
  170. {
  171. get { return m_DrawDistance; }
  172. }
  173. protected bool m_allowMovement = true;
  174. public bool AllowMovement
  175. {
  176. get { return m_allowMovement; }
  177. set { m_allowMovement = value; }
  178. }
  179. /// <summary>
  180. /// This works out to be the ClientView object associated with this avatar, or it's UDP connection manager
  181. /// </summary>
  182. private IClientAPI m_controllingClient;
  183. protected PhysicsActor m_physicsActor;
  184. public IClientAPI ControllingClient
  185. {
  186. get { return m_controllingClient; }
  187. set { m_controllingClient = value; }
  188. }
  189. protected LLVector3 m_parentPosition = new LLVector3();
  190. /// <summary>
  191. /// Absolute position of this avatar in 'region cordinates'
  192. /// </summary>
  193. public override LLVector3 AbsolutePosition
  194. {
  195. get
  196. {
  197. if (m_physicsActor != null)
  198. {
  199. m_pos.X = m_physicsActor.Position.X;
  200. m_pos.Y = m_physicsActor.Position.Y;
  201. m_pos.Z = m_physicsActor.Position.Z;
  202. }
  203. return m_parentPosition + m_pos;
  204. }
  205. set
  206. {
  207. if (m_physicsActor != null)
  208. {
  209. try
  210. {
  211. lock (m_scene.SyncRoot)
  212. {
  213. m_physicsActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  214. }
  215. }
  216. catch (Exception e)
  217. {
  218. Console.WriteLine(e.Message);
  219. }
  220. }
  221. m_pos = value;
  222. m_parentPosition=new LLVector3(0, 0, 0);
  223. }
  224. }
  225. /// <summary>
  226. /// Current Velocity of the avatar.
  227. /// </summary>
  228. public override LLVector3 Velocity
  229. {
  230. get
  231. {
  232. if (m_physicsActor != null)
  233. {
  234. m_velocity.X = m_physicsActor.Velocity.X;
  235. m_velocity.Y = m_physicsActor.Velocity.Y;
  236. m_velocity.Z = m_physicsActor.Velocity.Z;
  237. }
  238. return m_velocity;
  239. }
  240. set
  241. {
  242. if (m_physicsActor != null)
  243. {
  244. try
  245. {
  246. lock (m_scene.SyncRoot)
  247. {
  248. m_physicsActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
  249. }
  250. }
  251. catch (Exception e)
  252. {
  253. Console.WriteLine(e.Message);
  254. }
  255. }
  256. m_velocity = value;
  257. }
  258. }
  259. /// <summary>
  260. /// If this is true, agent doesn't have a representation in this scene.
  261. /// this is an agent 'looking into' this scene from a nearby scene(region)
  262. ///
  263. /// if False, this agent has a representation in this scene
  264. /// </summary>
  265. private bool m_isChildAgent = true;
  266. public bool IsChildAgent
  267. {
  268. get { return m_isChildAgent; }
  269. set { m_isChildAgent = value; }
  270. }
  271. private uint m_parentID = 0;
  272. public uint ParentID
  273. {
  274. get { return m_parentID; }
  275. set { m_parentID = value; }
  276. }
  277. /// <summary>
  278. /// These are the region handles known by the avatar.
  279. /// </summary>
  280. public List<ulong> KnownChildRegions
  281. {
  282. get { return m_knownChildRegions; }
  283. }
  284. #endregion
  285. #region Constructor(s)
  286. private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo)
  287. {
  288. m_regionHandle = reginfo.RegionHandle;
  289. m_controllingClient = client;
  290. m_firstname = m_controllingClient.FirstName;
  291. m_lastname = m_controllingClient.LastName;
  292. m_scene = world;
  293. m_uuid = client.AgentId;
  294. m_regionInfo = reginfo;
  295. m_localId = m_scene.NextLocalId;
  296. AbsolutePosition = m_controllingClient.StartPos;
  297. // Move them into an object to (hopefully) avoid threading issues.
  298. try
  299. {
  300. SetMovementAnimation(Animations.AnimsLLUUID["STAND"]);
  301. }
  302. catch (KeyNotFoundException)
  303. {
  304. m_log.Warn("[AVATAR]: KeyNotFound Exception playing avatar stand animation");
  305. }
  306. RegisterToEvents();
  307. SetDirectionVectors();
  308. m_scene.LandChannel.sendLandUpdate(this, true);
  309. }
  310. public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams,
  311. AvatarWearable[] wearables)
  312. : this(client, world, reginfo)
  313. {
  314. m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams);
  315. }
  316. public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance)
  317. : this(client, world, reginfo)
  318. {
  319. m_appearance = appearance;
  320. }
  321. public void RegisterToEvents()
  322. {
  323. m_controllingClient.OnRequestWearables += SendOwnAppearance;
  324. m_controllingClient.OnSetAppearance += SetAppearance;
  325. m_controllingClient.OnCompleteMovementToRegion += CompleteMovement;
  326. m_controllingClient.OnCompleteMovementToRegion += SendInitialData;
  327. m_controllingClient.OnAgentUpdate += HandleAgentUpdate;
  328. m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit;
  329. m_controllingClient.OnAgentSit += HandleAgentSit;
  330. m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
  331. m_controllingClient.OnStartAnim += HandleStartAnim;
  332. m_controllingClient.OnStopAnim += HandleStopAnim;
  333. // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
  334. // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
  335. }
  336. private void SetDirectionVectors()
  337. {
  338. Dir_Vectors[0] = new Vector3(1, 0, 0); //FORWARD
  339. Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK
  340. Dir_Vectors[2] = new Vector3(0, 1, 0); //LEFT
  341. Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT
  342. Dir_Vectors[4] = new Vector3(0, 0, 1); //UP
  343. Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN
  344. Dir_Vectors[5] = new Vector3(0, 0, -0.5f); //DOWN_Nudge
  345. }
  346. #endregion
  347. /// <summary>
  348. /// Add the part to the queue of parts for which we need to send an update to the client
  349. /// </summary>
  350. /// <param name="part"></param>
  351. public void QueuePartForUpdate(SceneObjectPart part)
  352. {
  353. //if (InterestList.Contains(part.ParentGroup))
  354. //{
  355. lock (m_partsUpdateQueue)
  356. {
  357. m_partsUpdateQueue.Enqueue(part);
  358. }
  359. // }
  360. }
  361. public uint GenerateClientFlags(LLUUID ObjectID)
  362. {
  363. return m_scene.PermissionsMngr.GenerateClientFlags(m_uuid, ObjectID);
  364. }
  365. /// <summary>
  366. /// Send updates to the client about prims which have been placed on the update queue. We don't
  367. /// necessarily send updates for all the parts on the queue, e.g. if an updates with a more recent
  368. /// timestamp has already been sent.
  369. /// </summary>
  370. public void SendPrimUpdates()
  371. {
  372. // if (m_scene.QuadTree.GetNodeID(this.AbsolutePosition.X, this.AbsolutePosition.Y) != m_currentQuadNode)
  373. //{
  374. // this.UpdateQuadTreeNode();
  375. //this.RefreshQuadObject();
  376. //}
  377. m_perfMonMS = System.Environment.TickCount;
  378. if (!m_gotAllObjectsInScene)
  379. {
  380. if (!m_isChildAgent || m_scene.m_seeIntoRegionFromNeighbor)
  381. {
  382. m_scene.SendAllSceneObjectsToClient(this);
  383. m_gotAllObjectsInScene = true;
  384. }
  385. }
  386. if (m_partsUpdateQueue.Count > 0)
  387. {
  388. bool runUpdate = true;
  389. int updateCount = 0;
  390. while (runUpdate)
  391. {
  392. SceneObjectPart part = m_partsUpdateQueue.Dequeue();
  393. if (m_updateTimes.ContainsKey(part.UUID))
  394. {
  395. ScenePartUpdate update = m_updateTimes[part.UUID];
  396. // We deal with the possibility that two updates occur at the same unix time
  397. // at the update point itself.
  398. if (update.LastFullUpdateTime < part.TimeStampFull)
  399. {
  400. // m_log.DebugFormat(
  401. // "[SCENE PRESENCE]: Fully updating prim {0}, {1} - part timestamp {2}",
  402. // part.Name, part.UUID, part.TimeStampFull);
  403. part.SendFullUpdate(ControllingClient, GenerateClientFlags(part.UUID));
  404. // We'll update to the part's timestamp rather than the current time to
  405. // avoid the race condition whereby the next tick occurs while we are
  406. // doing this update. If this happened, then subsequent updates which occurred
  407. // on the same tick or the next tick of the last update would be ignored.
  408. update.LastFullUpdateTime = part.TimeStampFull;
  409. updateCount++;
  410. }
  411. else if (update.LastTerseUpdateTime <= part.TimeStampTerse)
  412. {
  413. // m_log.DebugFormat(
  414. // "[SCENE PRESENCE]: Tersely updating prim {0}, {1} - part timestamp {2}",
  415. // part.Name, part.UUID, part.TimeStampTerse);
  416. part.SendTerseUpdate(ControllingClient);
  417. update.LastTerseUpdateTime = part.TimeStampTerse;
  418. updateCount++;
  419. }
  420. }
  421. else
  422. {
  423. //never been sent to client before so do full update
  424. part.SendFullUpdate(ControllingClient, GenerateClientFlags(part.UUID));
  425. ScenePartUpdate update = new ScenePartUpdate();
  426. update.FullID = part.UUID;
  427. update.LastFullUpdateTime = part.TimeStampFull;
  428. m_updateTimes.Add(part.UUID, update);
  429. updateCount++;
  430. }
  431. if (m_partsUpdateQueue.Count < 1 || updateCount > 60)
  432. {
  433. runUpdate = false;
  434. }
  435. }
  436. }
  437. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  438. }
  439. public void forceAvatarMovement(Vector3 position, Quaternion rotation)
  440. {
  441. AddNewMovement(position, rotation);
  442. }
  443. #region Status Methods
  444. /// <summary>
  445. /// This turns a child agent, into a root agent
  446. /// This is called when an agent teleports into a region, or if an
  447. /// agent crosses into this region from a neighbor over the border
  448. /// </summary>
  449. public void MakeRootAgent(LLVector3 pos, bool isFlying)
  450. {
  451. // m_log.DebugFormat(
  452. // "[SCENEPRESENCE]: Upgrading child agent {0}, {1} to a root agent in {2}",
  453. // Name, UUID, m_scene.RegionInfo.RegionName);
  454. m_isChildAgent = false;
  455. AbsolutePosition = pos;
  456. AddToPhysicalScene();
  457. m_physicsActor.Flying = isFlying;
  458. SendAnimPack();
  459. m_scene.SwapRootAgentCount(false);
  460. m_scene.CommsManager.UserProfileCacheService.RequestInventoryForUser(m_uuid);
  461. m_scene.AddCapsHandler(m_uuid);
  462. //if (!m_gotAllObjectsInScene)
  463. //{
  464. m_scene.SendAllSceneObjectsToClient(this);
  465. m_scene.LandChannel.sendLandUpdate(this, true);
  466. //m_gotAllObjectsInScene = true;
  467. //}
  468. }
  469. /// <summary>
  470. /// This turns a root agent into a child agent
  471. /// when an agent departs this region for a neighbor, this gets called.
  472. ///
  473. /// It doesn't get called for a teleport. Reason being, an agent that
  474. /// teleports out may not be anywhere near this region
  475. /// </summary>
  476. public void MakeChildAgent()
  477. {
  478. if(m_animations.Count > 0)
  479. {
  480. LLUUID movement=m_animations[0];
  481. m_animations.Clear();
  482. m_animationSeqs.Clear();
  483. SetMovementAnimation(movement);
  484. }
  485. // m_log.DebugFormat(
  486. // "[SCENEPRESENCE]: Downgrading child agent {0}, {1} to a root agent in {2}",
  487. // Name, UUID, m_scene.RegionInfo.RegionName);
  488. Velocity = new LLVector3(0, 0, 0);
  489. m_isChildAgent = true;
  490. m_scene.SwapRootAgentCount(true);
  491. RemoveFromPhysicalScene();
  492. m_scene.EventManager.TriggerOnMakeChildAgent(this);
  493. //this.Pos = new LLVector3(128, 128, 70);
  494. }
  495. /// <summary>
  496. /// Removes physics plugin scene representation of this agent if it exists.
  497. /// </summary>
  498. private void RemoveFromPhysicalScene()
  499. {
  500. if (PhysicsActor != null)
  501. {
  502. m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
  503. m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
  504. m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
  505. PhysicsActor = null;
  506. }
  507. }
  508. /// <summary>
  509. ///
  510. /// </summary>
  511. /// <param name="pos"></param>
  512. public void Teleport(LLVector3 pos)
  513. {
  514. RemoveFromPhysicalScene();
  515. Velocity = new LLVector3(0, 0, 0);
  516. AbsolutePosition = pos;
  517. AddToPhysicalScene();
  518. SendTerseUpdateToAllClients();
  519. }
  520. /// <summary>
  521. ///
  522. /// </summary>
  523. public void StopMovement()
  524. {
  525. }
  526. public void StopFlying()
  527. {
  528. // It turns out to get the agent to stop flying, you have to feed it stop flying velocities
  529. // and send a full object update.
  530. // There's no message to send the client to tell it to stop flying
  531. // Add 1/6 the avatar's height to it's position so it doesn't shoot into the air
  532. // when the avatar stands up
  533. if (m_avHeight != 127.0f)
  534. {
  535. AbsolutePosition = AbsolutePosition + new LLVector3(0, 0, (m_avHeight / 6));
  536. }
  537. else
  538. {
  539. AbsolutePosition = AbsolutePosition + new LLVector3(0, 0, (1.56f / 6));
  540. }
  541. SetMovementAnimation(Animations.AnimsLLUUID["LAND"]);
  542. SendFullUpdateToAllClients();
  543. }
  544. public void AddNeighbourRegion(ulong regionHandle)
  545. {
  546. if (!m_knownChildRegions.Contains(regionHandle))
  547. {
  548. m_knownChildRegions.Add(regionHandle);
  549. }
  550. }
  551. public void RemoveNeighbourRegion(ulong regionHandle)
  552. {
  553. if (!m_knownChildRegions.Contains(regionHandle))
  554. {
  555. m_knownChildRegions.Remove(regionHandle);
  556. }
  557. }
  558. public List<ulong> GetKnownRegionList()
  559. {
  560. return m_knownChildRegions;
  561. }
  562. #endregion
  563. #region Event Handlers
  564. /// <summary>
  565. /// Sets avatar height in the phyiscs plugin
  566. /// </summary>
  567. internal void SetHeight(float height)
  568. {
  569. m_avHeight = height;
  570. if (PhysicsActor != null)
  571. {
  572. PhysicsVector SetSize = new PhysicsVector(0.45f, 0.6f, m_avHeight);
  573. PhysicsActor.Size = SetSize;
  574. }
  575. }
  576. /// <summary>
  577. /// Complete Avatar's movement into the region
  578. /// </summary>
  579. public void CompleteMovement()
  580. {
  581. LLVector3 look = Velocity;
  582. if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
  583. {
  584. look = new LLVector3(0.99f, 0.042f, 0);
  585. }
  586. m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look);
  587. if (m_isChildAgent)
  588. {
  589. m_isChildAgent = false;
  590. //this.m_scene.SendAllSceneObjectsToClient(this.ControllingClient);
  591. MakeRootAgent(AbsolutePosition, false);
  592. }
  593. }
  594. /// <summary>
  595. /// This is the event handler for client movement. If a client is moving, this event is triggering.
  596. /// </summary>
  597. public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdatePacket agentData)
  598. {
  599. //if (m_isChildAgent)
  600. //{
  601. // // Console.WriteLine("DEBUG: HandleAgentUpdate: child agent");
  602. // return;
  603. //}
  604. // Must check for standing up even when PhysicsActor is null,
  605. // since sitting currently removes avatar from physical scene
  606. m_perfMonMS = System.Environment.TickCount;
  607. uint flags = agentData.AgentData.ControlFlags;
  608. LLQuaternion bodyRotation = agentData.AgentData.BodyRotation;
  609. // Camera location in world. We'll need to raytrace
  610. // from this location from time to time.
  611. m_CameraCenter.x = agentData.AgentData.CameraCenter.X;
  612. m_CameraCenter.y = agentData.AgentData.CameraCenter.Y;
  613. m_CameraCenter.z = agentData.AgentData.CameraCenter.Z;
  614. // Use these three vectors to figure out what the agent is looking at
  615. // Convert it to a Matrix and/or Quaternion
  616. m_CameraAtAxis.x = agentData.AgentData.CameraAtAxis.X;
  617. m_CameraAtAxis.y = agentData.AgentData.CameraAtAxis.Y;
  618. m_CameraAtAxis.z = agentData.AgentData.CameraAtAxis.Z;
  619. m_CameraLeftAxis.x = agentData.AgentData.CameraLeftAxis.X;
  620. m_CameraLeftAxis.y = agentData.AgentData.CameraLeftAxis.Y;
  621. m_CameraLeftAxis.z = agentData.AgentData.CameraLeftAxis.Z;
  622. m_CameraUpAxis.x = agentData.AgentData.CameraUpAxis.X;
  623. m_CameraUpAxis.y = agentData.AgentData.CameraUpAxis.Y;
  624. m_CameraUpAxis.z = agentData.AgentData.CameraUpAxis.Z;
  625. // The Agent's Draw distance setting
  626. m_DrawDistance = agentData.AgentData.Far;
  627. if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0)
  628. {
  629. StandUp();
  630. }
  631. if (PhysicsActor == null)
  632. {
  633. return;
  634. }
  635. if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
  636. {
  637. // TODO: This doesn't quite work yet -- probably a parent ID problem
  638. // m_parentID = (what should this be?)
  639. SetMovementAnimation(Animations.AnimsLLUUID["SIT_GROUND"]);
  640. }
  641. // In the future, these values might need to go global.
  642. // Here's where you get them.
  643. // m_AgentControlFlags = flags;
  644. // m_headrotation = agentData.AgentData.HeadRotation;
  645. // m_state = agentData.AgentData.State;
  646. if (m_allowMovement)
  647. {
  648. int i = 0;
  649. bool update_movementflag = false;
  650. bool update_rotation = false;
  651. bool DCFlagKeyPressed = false;
  652. Vector3 agent_control_v3 = new Vector3(0, 0, 0);
  653. Quaternion q = new Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z);
  654. bool oldflying = PhysicsActor.Flying;
  655. PhysicsActor.Flying = ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
  656. if (PhysicsActor.Flying != oldflying)
  657. {
  658. update_movementflag = true;
  659. }
  660. if (q != m_bodyRot)
  661. {
  662. m_bodyRot = q;
  663. update_rotation = true;
  664. }
  665. if (m_parentID == 0)
  666. {
  667. foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags)))
  668. {
  669. if ((flags & (uint) DCF) != 0)
  670. {
  671. DCFlagKeyPressed = true;
  672. try
  673. {
  674. agent_control_v3 += Dir_Vectors[i];
  675. }
  676. catch (IndexOutOfRangeException)
  677. {
  678. // Why did I get this?
  679. }
  680. if ((m_movementflag & (uint) DCF) == 0)
  681. {
  682. m_movementflag += (byte) (uint) DCF;
  683. update_movementflag = true;
  684. }
  685. }
  686. else
  687. {
  688. if ((m_movementflag & (uint) DCF) != 0)
  689. {
  690. m_movementflag -= (byte) (uint) DCF;
  691. update_movementflag = true;
  692. }
  693. }
  694. i++;
  695. }
  696. }
  697. // Cause the avatar to stop flying if it's colliding
  698. // with something with the down arrow pressed.
  699. // Skip if there's no physicsactor
  700. if (m_physicsActor != null)
  701. {
  702. // Only do this if we're flying
  703. if (m_physicsActor.Flying)
  704. {
  705. // Are the landing controls requirements filled?
  706. bool controlland = (((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
  707. ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
  708. // Are the collision requirements fulfilled?
  709. bool colliding = (m_physicsActor.IsColliding == true);
  710. if (m_physicsActor.Flying && colliding && controlland)
  711. {
  712. StopFlying();
  713. }
  714. }
  715. }
  716. if ((update_movementflag) || (update_rotation && DCFlagKeyPressed))
  717. {
  718. AddNewMovement(agent_control_v3, q);
  719. UpdateMovementAnimations(update_movementflag);
  720. }
  721. }
  722. m_scene.EventManager.TriggerOnClientMovement(this);
  723. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  724. }
  725. /// <summary>
  726. /// Perform the logic necessary to stand the client up. This method also executes
  727. /// the stand animation.
  728. /// </summary>
  729. public void StandUp()
  730. {
  731. if (m_parentID != 0)
  732. {
  733. SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
  734. if (part != null)
  735. {
  736. // Reset sit target.
  737. if (part.GetAvatarOnSitTarget() == UUID)
  738. part.SetAvatarOnSitTarget(LLUUID.Zero);
  739. m_parentPosition = part.GetWorldPosition();
  740. }
  741. if (m_physicsActor == null)
  742. {
  743. AddToPhysicalScene();
  744. }
  745. m_pos += m_parentPosition + new LLVector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight);
  746. m_parentPosition = new LLVector3();
  747. m_parentID = 0;
  748. SendFullUpdateToAllClients();
  749. if (m_physicsActor != null)
  750. {
  751. SetHeight(m_avHeight);
  752. }
  753. }
  754. SetMovementAnimation(Animations.AnimsLLUUID["STAND"]);
  755. }
  756. private void SendSitResponse(IClientAPI remoteClient, LLUUID targetID, LLVector3 offset)
  757. {
  758. AvatarSitResponsePacket avatarSitResponse = new AvatarSitResponsePacket();
  759. avatarSitResponse.SitObject.ID = targetID;
  760. bool autopilot = true;
  761. LLVector3 pos = new LLVector3();
  762. LLQuaternion sitOrientation = new LLQuaternion(0, 0, 0, 1);
  763. SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
  764. if (part != null)
  765. {
  766. // TODO: determine position to sit at based on scene geometry; don't trust offset from client
  767. // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
  768. // Is a sit target available?
  769. Vector3 avSitOffSet = part.GetSitTargetPosition();
  770. Quaternion avSitOrientation = part.GetSitTargetOrientation();
  771. LLUUID avOnTargetAlready = part.GetAvatarOnSitTarget();
  772. bool SitTargetUnOccupied = (!(avOnTargetAlready != LLUUID.Zero));
  773. bool SitTargetisSet =
  774. (!(avSitOffSet.x == 0 && avSitOffSet.y == 0 && avSitOffSet.z == 0 && avSitOrientation.w == 0 &&
  775. avSitOrientation.x == 0 && avSitOrientation.y == 0 && avSitOrientation.z == 1));
  776. if (SitTargetisSet && SitTargetUnOccupied)
  777. {
  778. part.SetAvatarOnSitTarget(UUID);
  779. offset = new LLVector3(avSitOffSet.x, avSitOffSet.y, avSitOffSet.z);
  780. sitOrientation =
  781. new LLQuaternion(avSitOrientation.w, avSitOrientation.x, avSitOrientation.y, avSitOrientation.z);
  782. autopilot = false;
  783. }
  784. pos = part.AbsolutePosition + offset;
  785. if (m_physicsActor != null)
  786. {
  787. // If we're not using the client autopilot, we're immediately warping the avatar to the location
  788. // We can remove the physicsActor until they stand up.
  789. m_sitAvatarHeight = m_physicsActor.Size.Z;
  790. if (autopilot)
  791. {
  792. if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5)
  793. {
  794. autopilot = false;
  795. RemoveFromPhysicalScene();
  796. AbsolutePosition = pos + new LLVector3(0.0f, 0.0f, m_sitAvatarHeight);
  797. }
  798. }
  799. else
  800. {
  801. RemoveFromPhysicalScene();
  802. }
  803. }
  804. }
  805. avatarSitResponse.SitTransform.AutoPilot = autopilot;
  806. avatarSitResponse.SitTransform.SitPosition = offset;
  807. avatarSitResponse.SitTransform.SitRotation = sitOrientation;
  808. remoteClient.OutPacket(avatarSitResponse, ThrottleOutPacketType.Task);
  809. // This calls HandleAgentSit twice, once from here, and the client calls
  810. // HandleAgentSit itself after it gets to the location
  811. // It doesn't get to the location until we've moved them there though
  812. // which happens in HandleAgentSit :P
  813. if (!autopilot)
  814. HandleAgentSit(remoteClient, UUID);
  815. }
  816. public void HandleAgentRequestSit(IClientAPI remoteClient, LLUUID agentID, LLUUID targetID, LLVector3 offset)
  817. {
  818. if (m_parentID != 0)
  819. {
  820. StandUp();
  821. }
  822. SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
  823. if (part != null)
  824. {
  825. m_requestedSitTargetID = part.LocalId;
  826. m_requestedSitOffset = offset;
  827. }
  828. else
  829. {
  830. m_log.Warn("Sit requested on unknown object: " + targetID.ToString());
  831. }
  832. SendSitResponse(remoteClient, targetID, offset);
  833. }
  834. public void HandleAgentSit(IClientAPI remoteClient, LLUUID agentID)
  835. {
  836. SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
  837. if (part != null)
  838. {
  839. if (part.GetAvatarOnSitTarget() == UUID)
  840. {
  841. Vector3 sitTargetPos = part.GetSitTargetPosition();
  842. Quaternion sitTargetOrient = part.GetSitTargetOrientation();
  843. //Quaternion vq = new Quaternion(sitTargetPos.x, sitTargetPos.y+0.2f, sitTargetPos.z+0.2f, 0);
  844. //Quaternion nq = new Quaternion(sitTargetOrient.w, -sitTargetOrient.x, -sitTargetOrient.y, -sitTargetOrient.z);
  845. //Quaternion result = (sitTargetOrient * vq) * nq;
  846. m_pos = new LLVector3(sitTargetPos.x, sitTargetPos.y, sitTargetPos.z);
  847. m_bodyRot = sitTargetOrient;
  848. //Rotation = sitTargetOrient;
  849. m_parentPosition = part.AbsolutePosition;
  850. //SendTerseUpdateToAllClients();
  851. }
  852. else
  853. {
  854. m_pos -= part.AbsolutePosition;
  855. m_parentPosition = part.AbsolutePosition;
  856. }
  857. }
  858. m_parentID = m_requestedSitTargetID;
  859. Velocity = new LLVector3(0, 0, 0);
  860. RemoveFromPhysicalScene();
  861. SetMovementAnimation(Animations.AnimsLLUUID["SIT"]);
  862. SendFullUpdateToAllClients();
  863. // This may seem stupid, but Our Full updates don't send avatar rotation :P
  864. // So we're also sending a terse update (which has avatar rotation)
  865. SendTerseUpdateToAllClients();
  866. }
  867. /// <summary>
  868. /// Event handler for the 'Always run' setting on the client
  869. /// Tells the physics plugin to increase speed of movement.
  870. /// </summary>
  871. public void HandleSetAlwaysRun(IClientAPI remoteClient, bool SetAlwaysRun)
  872. {
  873. m_setAlwaysRun = SetAlwaysRun;
  874. if (PhysicsActor != null)
  875. {
  876. PhysicsActor.SetAlwaysRun = SetAlwaysRun;
  877. }
  878. }
  879. public void AddAnimation(LLUUID animID)
  880. {
  881. if(m_isChildAgent)
  882. return;
  883. // Don't let this animation become the movement animation
  884. if(m_animations.Count < 1)
  885. SetMovementAnimation(Animations.AnimsLLUUID["STAND"]);
  886. if (!m_animations.Contains(animID))
  887. {
  888. m_animations.Add(animID);
  889. m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber);
  890. SendAnimPack();
  891. }
  892. }
  893. public void RemoveAnimation(LLUUID animID)
  894. {
  895. if(m_isChildAgent)
  896. return;
  897. if (m_animations.Contains(animID))
  898. {
  899. if (m_animations[0] == animID)
  900. {
  901. SetMovementAnimation(Animations.AnimsLLUUID["STAND"]);
  902. }
  903. else
  904. {
  905. // What a HACK!! Anim list really needs to be an object!
  906. int idx;
  907. for(idx=0;idx < m_animations.Count;idx++)
  908. {
  909. if(m_animations[idx] == animID)
  910. {
  911. int seq=m_animationSeqs[idx];
  912. m_animations.Remove(animID);
  913. m_animationSeqs.Remove(seq);
  914. SendAnimPack();
  915. break;
  916. }
  917. }
  918. }
  919. }
  920. }
  921. public void HandleStartAnim(IClientAPI remoteClient, LLUUID animID)
  922. {
  923. AddAnimation(animID);
  924. }
  925. public void HandleStopAnim(IClientAPI remoteClient, LLUUID animID)
  926. {
  927. RemoveAnimation(animID);
  928. }
  929. /// <summary>
  930. /// The movement animation is the first element of the animation list,
  931. /// reserved for "main" animations that are mutually exclusive,
  932. /// like flying and sitting, for example.
  933. /// </summary>
  934. protected void SetMovementAnimation(LLUUID anim)
  935. {
  936. if(m_animations.Count < 1)
  937. {
  938. m_animations.Add(Animations.AnimsLLUUID["STAND"]);
  939. m_animationSeqs.Add(1);
  940. SendAnimPack();
  941. }
  942. else
  943. {
  944. try
  945. {
  946. if (m_animations[0] != anim)
  947. {
  948. m_animations[0] = anim;
  949. m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber;
  950. }
  951. SendAnimPack();
  952. }
  953. catch
  954. {
  955. m_log.Warn("[AVATAR]: SetMovementAnimation for avatar failed. Attempting recovery...");
  956. m_animations[0] = anim;
  957. m_animationSeqs[0] = m_controllingClient.NextAnimationSequenceNumber;
  958. SendAnimPack();
  959. }
  960. }
  961. }
  962. /// <summary>
  963. /// This method handles agent movement related animations
  964. /// </summary>
  965. protected void UpdateMovementAnimations(bool update_movementflag)
  966. {
  967. if (update_movementflag)
  968. {
  969. // Are we moving?
  970. if (m_movementflag != 0)
  971. {
  972. // We are moving
  973. if (m_physicsActor.Flying)
  974. {
  975. // We are flying
  976. SetMovementAnimation(Animations.AnimsLLUUID["FLY"]);
  977. }
  978. else if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) &&
  979. PhysicsActor.IsColliding)
  980. {
  981. // Client is pressing the page down button and moving and is colliding with something
  982. SetMovementAnimation(Animations.AnimsLLUUID["CROUCHWALK"]);
  983. }
  984. else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6)
  985. {
  986. // Client is moving and falling at a velocity greater then 6 meters per unit
  987. SetMovementAnimation(Animations.AnimsLLUUID["FALLDOWN"]);
  988. }
  989. else if (!PhysicsActor.IsColliding && Velocity.Z > 0 &&
  990. (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
  991. {
  992. // Client is moving, and colliding and pressing the page up button but isn't flying
  993. try
  994. {
  995. SetMovementAnimation(Animations.AnimsLLUUID["JUMP"]);
  996. }
  997. catch (KeyNotFoundException)
  998. { }
  999. }
  1000. else if (m_setAlwaysRun)
  1001. {
  1002. // We are running
  1003. try
  1004. {
  1005. SetMovementAnimation(Animations.AnimsLLUUID["RUN"]);
  1006. }
  1007. catch (KeyNotFoundException)
  1008. { }
  1009. }
  1010. else
  1011. {
  1012. // We're moving, but we're not doing anything else.. so play the stand animation
  1013. try
  1014. {
  1015. SetMovementAnimation(Animations.AnimsLLUUID["WALK"]);
  1016. }
  1017. catch (KeyNotFoundException)
  1018. { }
  1019. }
  1020. }
  1021. else
  1022. {
  1023. // Not moving
  1024. if (((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) &&
  1025. PhysicsActor.IsColliding)
  1026. {
  1027. // Client pressing the page down button
  1028. SetMovementAnimation(Animations.AnimsLLUUID["CROUCH"]);
  1029. }
  1030. else if (!PhysicsActor.IsColliding && m_physicsActor.Velocity.Z < -6 && !m_physicsActor.Flying)
  1031. {
  1032. // Not colliding and not flying, and we're falling at high speed
  1033. SetMovementAnimation(Animations.AnimsLLUUID["FALLDOWN"]);
  1034. }
  1035. else if (!PhysicsActor.IsColliding && Velocity.Z > 0 && !m_physicsActor.Flying &&
  1036. (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
  1037. {
  1038. // This is the standing jump
  1039. SetMovementAnimation(Animations.AnimsLLUUID["JUMP"]);
  1040. }
  1041. else if (m_physicsActor.Flying)
  1042. {
  1043. // We're flying but not moving
  1044. SetMovementAnimation(Animations.AnimsLLUUID["HOVER"]);
  1045. }
  1046. else
  1047. {
  1048. // We're not moving.. and we're not doing anything.. so play the stand animation
  1049. try
  1050. {
  1051. SetMovementAnimation(Animations.AnimsLLUUID["STAND"]);
  1052. }
  1053. catch (KeyNotFoundException)
  1054. { }
  1055. }
  1056. }
  1057. }
  1058. }
  1059. /// <summary>
  1060. /// Adds a new movement
  1061. /// </summary>
  1062. protected void AddNewMovement(Vector3 vec, Quaternion rotation)
  1063. {
  1064. if (m_isChildAgent)
  1065. {
  1066. Console.WriteLine("DEBUG: AddNewMovement: child agent");
  1067. return;
  1068. }
  1069. m_perfMonMS = System.Environment.TickCount;
  1070. m_rotation = rotation;
  1071. NewForce newVelocity = new NewForce();
  1072. Vector3 direc = rotation*vec;
  1073. direc.Normalize();
  1074. direc *= 0.03f*128f;
  1075. if (m_physicsActor.Flying)
  1076. {
  1077. direc *= 4;
  1078. //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
  1079. //bool colliding = (m_physicsActor.IsColliding==true);
  1080. //if (controlland)
  1081. // m_log.Info("[AGENT]: landCommand");
  1082. //if (colliding )
  1083. // m_log.Info("[AGENT]: colliding");
  1084. //if (m_physicsActor.Flying && colliding && controlland)
  1085. //{
  1086. // StopFlying();
  1087. // m_log.Info("[AGENT]: Stop FLying");
  1088. //}
  1089. }
  1090. else
  1091. {
  1092. if (!m_physicsActor.Flying && m_physicsActor.IsColliding)
  1093. {
  1094. //direc.z *= 40;
  1095. if (direc.z > 2.0f)
  1096. {
  1097. direc.z *= 3;
  1098. //System.Console.WriteLine("Jump");
  1099. // PreJump and jump happen too quickly. Many times prejump gets ignored.
  1100. try
  1101. {
  1102. SetMovementAnimation(Animations.AnimsLLUUID["PREJUMP"]);
  1103. SetMovementAnimation(Animations.AnimsLLUUID["JUMP"]);
  1104. }
  1105. catch (KeyNotFoundException)
  1106. { }
  1107. }
  1108. }
  1109. }
  1110. newVelocity.X = direc.x;
  1111. newVelocity.Y = direc.y;
  1112. newVelocity.Z = direc.z;
  1113. m_forcesList.Add(newVelocity);
  1114. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1115. }
  1116. #endregion
  1117. #region Overridden Methods
  1118. /// <summary>
  1119. ///
  1120. /// </summary>
  1121. public override void Update()
  1122. {
  1123. SendPrimUpdates();
  1124. if (m_newCoarseLocations)
  1125. {
  1126. SendCoarseLocations();
  1127. m_newCoarseLocations = false;
  1128. }
  1129. if (m_isChildAgent == false)
  1130. {
  1131. if (m_newForce) // user movement 'forces' (ie commands to move)
  1132. {
  1133. SendTerseUpdateToAllClients();
  1134. m_updateCount = 0;
  1135. }
  1136. else if (m_movementflag != 0) // scripted movement (?)
  1137. {
  1138. m_updateCount++;
  1139. if (m_updateCount > 3)
  1140. {
  1141. SendTerseUpdateToAllClients();
  1142. m_updateCount = 0;
  1143. }
  1144. }
  1145. else if ((Util.GetDistanceTo(lastPhysPos, AbsolutePosition) > 0.02) || (Util.GetDistanceTo(m_lastVelocity, m_velocity) > 0.02)) // physics-related movement
  1146. {
  1147. // Send Terse Update to all clients updates lastPhysPos and m_lastVelocity
  1148. // doing the above assures us that we know what we sent the clients last
  1149. SendTerseUpdateToAllClients();
  1150. m_updateCount = 0;
  1151. }
  1152. // followed suggestion from mic bowman. reversed the two lines below.
  1153. CheckForBorderCrossing();
  1154. CheckForSignificantMovement(); // sends update to the modules.
  1155. }
  1156. }
  1157. #endregion
  1158. #region Update Client(s)
  1159. /// <summary>
  1160. /// Sends a location update to the client connected to this scenePresence
  1161. /// </summary>
  1162. /// <param name="remoteClient"></param>
  1163. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  1164. {
  1165. m_perfMonMS = System.Environment.TickCount;
  1166. LLVector3 pos = m_pos;
  1167. LLVector3 vel = Velocity;
  1168. LLQuaternion rot = new LLQuaternion(m_bodyRot.x, m_bodyRot.y, m_bodyRot.z, m_bodyRot.w);
  1169. remoteClient.SendAvatarTerseUpdate(m_regionHandle, (ushort)(m_scene.TimeDilation * (float)ushort.MaxValue), LocalId, new LLVector3(pos.X, pos.Y, pos.Z),
  1170. new LLVector3(vel.X, vel.Y, vel.Z), rot);
  1171. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1172. m_scene.AddAgentUpdates(1);
  1173. }
  1174. /// <summary>
  1175. /// Send a location/velocity/accelleration update to all agents in scene
  1176. /// </summary>
  1177. public void SendTerseUpdateToAllClients()
  1178. {
  1179. m_perfMonMS = System.Environment.TickCount;
  1180. m_scene.Broadcast(SendTerseUpdateToClient);
  1181. m_lastVelocity = m_velocity;
  1182. lastPhysPos = AbsolutePosition;
  1183. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1184. }
  1185. public void SendCoarseLocations()
  1186. {
  1187. m_perfMonMS = System.Environment.TickCount;
  1188. List<LLVector3> CoarseLocations = new List<LLVector3>();
  1189. List<ScenePresence> avatars = m_scene.GetAvatars();
  1190. for (int i = 0; i < avatars.Count; i++)
  1191. {
  1192. if (avatars[i] != this)
  1193. {
  1194. CoarseLocations.Add(avatars[i].m_pos);
  1195. }
  1196. }
  1197. m_controllingClient.SendCoarseLocationUpdate(CoarseLocations);
  1198. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1199. }
  1200. public void CoarseLocationChange()
  1201. {
  1202. m_newCoarseLocations = true;
  1203. }
  1204. /// <summary>
  1205. /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar)
  1206. /// </summary>
  1207. /// <param name="remoteAvatar"></param>
  1208. public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar)
  1209. {
  1210. remoteAvatar.m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_uuid,
  1211. LocalId, m_pos, m_appearance.TextureEntry.ToBytes(),
  1212. m_parentID);
  1213. m_scene.AddAgentUpdates(1);
  1214. }
  1215. /// <summary>
  1216. /// Tell *ALL* agents about this agent
  1217. /// </summary>
  1218. public void SendFullUpdateToAllClients()
  1219. {
  1220. m_perfMonMS = System.Environment.TickCount;
  1221. List<ScenePresence> avatars = m_scene.GetScenePresences();
  1222. foreach (ScenePresence avatar in avatars)
  1223. {
  1224. SendFullUpdateToOtherClient(avatar);
  1225. if (avatar.LocalId != LocalId)
  1226. {
  1227. if (!avatar.m_isChildAgent || m_scene.m_seeIntoRegionFromNeighbor)
  1228. {
  1229. avatar.SendFullUpdateToOtherClient(this);
  1230. avatar.SendAppearanceToOtherAgent(this);
  1231. }
  1232. }
  1233. }
  1234. m_scene.AddAgentUpdates(avatars.Count);
  1235. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1236. }
  1237. /// <summary>
  1238. ///
  1239. /// </summary>
  1240. public void SendInitialData()
  1241. {
  1242. m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_uuid, LocalId,
  1243. m_pos, m_appearance.TextureEntry.ToBytes(), m_parentID);
  1244. if (!m_isChildAgent)
  1245. {
  1246. m_scene.InformClientOfNeighbours(this);
  1247. }
  1248. SendFullUpdateToAllClients();
  1249. SendAppearanceToAllOtherAgents();
  1250. }
  1251. /// <summary>
  1252. ///
  1253. /// </summary>
  1254. /// <param name="client"></param>
  1255. public void SendOwnAppearance()
  1256. {
  1257. m_appearance.SendOwnWearables(ControllingClient);
  1258. // TODO: remove this once the SunModule is slightly more tested
  1259. // m_controllingClient.SendViewerTime(m_scene.TimePhase);
  1260. }
  1261. /// <summary>
  1262. ///
  1263. /// </summary>
  1264. public void SendAppearanceToAllOtherAgents()
  1265. {
  1266. m_perfMonMS=System.Environment.TickCount;
  1267. m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
  1268. {
  1269. if (scenePresence.UUID != UUID)
  1270. {
  1271. m_appearance.SendAppearanceToOtherAgent(scenePresence);
  1272. }
  1273. });
  1274. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1275. }
  1276. public void SendAppearanceToOtherAgent(ScenePresence avatar)
  1277. {
  1278. m_appearance.SendAppearanceToOtherAgent(avatar);
  1279. }
  1280. public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
  1281. {
  1282. m_appearance.SetAppearance(texture, visualParam);
  1283. SetHeight(m_appearance.AvatarHeight);
  1284. SendAppearanceToAllOtherAgents();
  1285. }
  1286. public void SetWearable(int wearableId, AvatarWearable wearable)
  1287. {
  1288. m_appearance.SetWearable(ControllingClient, wearableId, wearable);
  1289. }
  1290. /// <summary>
  1291. ///
  1292. /// </summary>
  1293. /// <param name="animations"></param>
  1294. /// <param name="seqs"></param>
  1295. public void SendAnimPack(LLUUID[] animations, int[] seqs)
  1296. {
  1297. if(m_isChildAgent)
  1298. return;
  1299. m_scene.Broadcast(
  1300. delegate(IClientAPI client) { client.SendAnimations(animations, seqs, m_controllingClient.AgentId); });
  1301. }
  1302. /// <summary>
  1303. ///
  1304. /// </summary>
  1305. public void SendAnimPack()
  1306. {
  1307. SendAnimPack(m_animations.ToArray(), m_animationSeqs.ToArray());
  1308. }
  1309. #endregion
  1310. #region Significant Movement Method
  1311. /// <summary>
  1312. /// This checks for a significant movement and sends a courselocationchange update
  1313. /// </summary>
  1314. protected void CheckForSignificantMovement()
  1315. {
  1316. if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > 0.5)
  1317. {
  1318. posLastSignificantMove = AbsolutePosition;
  1319. handlerSignificantClientMovement = OnSignificantClientMovement;
  1320. if (handlerSignificantClientMovement != null)
  1321. {
  1322. handlerSignificantClientMovement(m_controllingClient);
  1323. m_scene.NotifyMyCoarseLocationChange();
  1324. }
  1325. }
  1326. // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m
  1327. if (Util.GetDistanceTo(AbsolutePosition,m_LastChildAgentUpdatePosition) > 32)
  1328. {
  1329. ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
  1330. cadu.ActiveGroupID=LLUUID.Zero.UUID;
  1331. cadu.AgentID = UUID.UUID;
  1332. cadu.alwaysrun = m_setAlwaysRun;
  1333. cadu.AVHeight = m_avHeight;
  1334. LLVector3 tempCameraCenter = new LLVector3(m_CameraCenter.x, m_CameraCenter.y, m_CameraCenter.z);
  1335. cadu.cameraPosition = new sLLVector3(tempCameraCenter);
  1336. cadu.drawdistance = m_DrawDistance;
  1337. cadu.godlevel = m_godlevel;
  1338. cadu.GroupAccess = 0;
  1339. cadu.Position = new sLLVector3(AbsolutePosition);
  1340. cadu.regionHandle = m_scene.RegionInfo.RegionHandle;
  1341. cadu.throttles = ControllingClient.GetThrottlesPacked(1f);
  1342. cadu.Velocity = new sLLVector3(Velocity);
  1343. m_scene.SendOutChildAgentUpdates(cadu,this);
  1344. m_LastChildAgentUpdatePosition.X = AbsolutePosition.X;
  1345. m_LastChildAgentUpdatePosition.Y = AbsolutePosition.Y;
  1346. m_LastChildAgentUpdatePosition.Z = AbsolutePosition.Z;
  1347. }
  1348. }
  1349. #endregion
  1350. #region Border Crossing Methods
  1351. /// <summary>
  1352. /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion
  1353. /// </summary>
  1354. protected void CheckForBorderCrossing()
  1355. {
  1356. LLVector3 pos2 = AbsolutePosition;
  1357. LLVector3 vel = Velocity;
  1358. float timeStep = 0.1f;
  1359. pos2.X = pos2.X + (vel.X*timeStep);
  1360. pos2.Y = pos2.Y + (vel.Y*timeStep);
  1361. pos2.Z = pos2.Z + (vel.Z*timeStep);
  1362. if ((pos2.X < 0) || (pos2.X > Constants.RegionSize))
  1363. {
  1364. CrossToNewRegion();
  1365. }
  1366. if ((pos2.Y < 0) || (pos2.Y > Constants.RegionSize))
  1367. {
  1368. CrossToNewRegion();
  1369. }
  1370. }
  1371. /// <summary>
  1372. /// Moves the agent outside the region bounds
  1373. /// Tells neighbor region that we're crossing to it
  1374. /// If the neighbor accepts, remove the agent's viewable avatar from this scene
  1375. /// set them to a child agent.
  1376. /// </summary>
  1377. protected void CrossToNewRegion()
  1378. {
  1379. LLVector3 pos = AbsolutePosition;
  1380. LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z);
  1381. uint neighbourx = m_regionInfo.RegionLocX;
  1382. uint neighboury = m_regionInfo.RegionLocY;
  1383. // distance to edge that will trigger crossing
  1384. const float boundaryDistance = 1.7f;
  1385. // distance into new region to place avatar
  1386. const float enterDistance = 0.1f;
  1387. if (pos.X < boundaryDistance)
  1388. {
  1389. neighbourx--;
  1390. newpos.X = Constants.RegionSize - enterDistance;
  1391. }
  1392. else if (pos.X > Constants.RegionSize - boundaryDistance)
  1393. {
  1394. neighbourx++;
  1395. newpos.X = enterDistance;
  1396. }
  1397. if (pos.Y < boundaryDistance)
  1398. {
  1399. neighboury--;
  1400. newpos.Y = Constants.RegionSize - enterDistance;
  1401. }
  1402. else if (pos.Y > Constants.RegionSize - boundaryDistance)
  1403. {
  1404. neighboury++;
  1405. newpos.Y = enterDistance;
  1406. }
  1407. LLVector3 vel = m_velocity;
  1408. ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
  1409. SimpleRegionInfo neighbourRegion = m_scene.RequestNeighbouringRegionInfo(neighbourHandle);
  1410. if (neighbourRegion != null)
  1411. {
  1412. // When the neighbour is informed of the border crossing, it will set up CAPS handlers for the avatar
  1413. // This means we need to remove the current caps handler here and possibly compensate later,
  1414. // in case both scenes are being hosted on the same region server. Messy
  1415. m_scene.RemoveCapsHandler(UUID);
  1416. newpos = newpos + (vel);
  1417. bool res =
  1418. m_scene.InformNeighbourOfCrossing(neighbourHandle, m_controllingClient.AgentId, newpos,
  1419. m_physicsActor.Flying);
  1420. if (res)
  1421. {
  1422. AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
  1423. // TODO Should construct this behind a method
  1424. string capsPath =
  1425. "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort
  1426. + "/CAPS/" + circuitdata.CapsPath + "0000/";
  1427. m_log.DebugFormat(
  1428. "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, m_uuid);
  1429. m_controllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.ExternalEndPoint,
  1430. capsPath);
  1431. MakeChildAgent();
  1432. CrossAttachmentsIntoNewRegion(neighbourHandle);
  1433. m_scene.SendKillObject(m_localId);
  1434. m_scene.NotifyMyCoarseLocationChange();
  1435. }
  1436. else
  1437. {
  1438. m_scene.AddCapsHandler(UUID);
  1439. }
  1440. }
  1441. }
  1442. #endregion
  1443. /// <summary>
  1444. /// This allows the Sim owner the abiility to kick users from their sim currently.
  1445. /// It tells the client that the agent has permission to do so.
  1446. /// </summary>
  1447. public void GrantGodlikePowers(LLUUID agentID, LLUUID sessionID, LLUUID token, bool godStatus)
  1448. {
  1449. GrantGodlikePowersPacket respondPacket = new GrantGodlikePowersPacket();
  1450. GrantGodlikePowersPacket.GrantDataBlock gdb = new GrantGodlikePowersPacket.GrantDataBlock();
  1451. GrantGodlikePowersPacket.AgentDataBlock adb = new GrantGodlikePowersPacket.AgentDataBlock();
  1452. adb.AgentID = agentID;
  1453. adb.SessionID = sessionID; // More security
  1454. if (godStatus)
  1455. {
  1456. gdb.GodLevel = (byte)250;
  1457. m_godlevel = 250;
  1458. }
  1459. else
  1460. {
  1461. gdb.GodLevel = (byte)0;
  1462. m_godlevel = 0;
  1463. }
  1464. gdb.Token = token;
  1465. //respondPacket.AgentData = (GrantGodlikePowersPacket.AgentDataBlock)ablock;
  1466. respondPacket.GrantData = gdb;
  1467. respondPacket.AgentData = adb;
  1468. ControllingClient.OutPacket(respondPacket, ThrottleOutPacketType.Task);
  1469. }
  1470. /// <summary>
  1471. /// This updates important decision making data about a child agent
  1472. /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
  1473. /// </summary>
  1474. public void ChildAgentDataUpdate(ChildAgentDataUpdate cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY)
  1475. {
  1476. //
  1477. int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize;
  1478. int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize;
  1479. m_DrawDistance = cAgentData.drawdistance;
  1480. m_pos = new LLVector3(cAgentData.Position.x + shiftx, cAgentData.Position.y + shifty, cAgentData.Position.z);
  1481. // It's hard to say here.. We can't really tell where the camera position is unless it's in world cordinates from the sending region
  1482. m_CameraCenter =
  1483. new Vector3(cAgentData.cameraPosition.x, cAgentData.cameraPosition.y, cAgentData.cameraPosition.z);
  1484. m_godlevel = cAgentData.godlevel;
  1485. SetHeight(cAgentData.AVHeight);
  1486. ControllingClient.SetChildAgentThrottle(cAgentData.throttles);
  1487. // Sends out the objects in the user's draw distance if m_sendTasksToChild is true.
  1488. if (m_scene.m_seeIntoRegionFromNeighbor)
  1489. m_scene.SendAllSceneObjectsToClient(this);
  1490. //cAgentData.AVHeight;
  1491. //cAgentData.regionHandle;
  1492. //m_velocity = cAgentData.Velocity;
  1493. }
  1494. /// <summary>
  1495. /// Handles part of the PID controller function for moving an avatar.
  1496. /// </summary>
  1497. public override void UpdateMovement()
  1498. {
  1499. m_newForce = false;
  1500. lock (m_forcesList)
  1501. {
  1502. if (m_forcesList.Count > 0)
  1503. {
  1504. for (int i = 0; i < m_forcesList.Count; i++)
  1505. {
  1506. NewForce force = m_forcesList[i];
  1507. m_updateflag = true;
  1508. try
  1509. {
  1510. movementvector.X = force.X;
  1511. movementvector.Y = force.Y;
  1512. movementvector.Z = force.Z;
  1513. Velocity = movementvector;
  1514. }
  1515. catch (NullReferenceException)
  1516. {
  1517. // Under extreme load, this returns a NullReference Exception that we can ignore.
  1518. // Ignoring this causes no movement to be sent to the physics engine...
  1519. // which when the scene is moving at 1 frame every 10 seconds, it doesn't really matter!
  1520. }
  1521. m_newForce = true;
  1522. }
  1523. for (int i = 0; i < m_forcesList.Count; i++)
  1524. {
  1525. m_forcesList.RemoveAt(0);
  1526. }
  1527. }
  1528. }
  1529. }
  1530. static ScenePresence()
  1531. {
  1532. LLObject.TextureEntry textu = AvatarAppearance.GetDefaultTextureEntry();
  1533. DefaultTexture = textu.ToBytes();
  1534. }
  1535. [Serializable]
  1536. public class NewForce
  1537. {
  1538. public float X;
  1539. public float Y;
  1540. public float Z;
  1541. public NewForce()
  1542. {
  1543. }
  1544. }
  1545. [Serializable]
  1546. public class ScenePartUpdate : ISerializable
  1547. {
  1548. public LLUUID FullID;
  1549. public uint LastFullUpdateTime;
  1550. public uint LastTerseUpdateTime;
  1551. public ScenePartUpdate()
  1552. {
  1553. FullID = LLUUID.Zero;
  1554. LastFullUpdateTime = 0;
  1555. LastTerseUpdateTime = 0;
  1556. }
  1557. protected ScenePartUpdate(SerializationInfo info, StreamingContext context)
  1558. {
  1559. //System.Console.WriteLine("ScenePartUpdate Deserialize BGN");
  1560. if (info == null)
  1561. {
  1562. throw new ArgumentNullException("info");
  1563. }
  1564. FullID = new LLUUID((Guid)info.GetValue("FullID", typeof(Guid)));
  1565. LastFullUpdateTime = (uint)info.GetValue("LastFullUpdateTime", typeof(uint));
  1566. LastTerseUpdateTime = (uint)info.GetValue("LastTerseUpdateTime", typeof(uint));
  1567. //System.Console.WriteLine("ScenePartUpdate Deserialize END");
  1568. }
  1569. [SecurityPermission(SecurityAction.LinkDemand,
  1570. Flags = SecurityPermissionFlag.SerializationFormatter)]
  1571. public virtual void GetObjectData(
  1572. SerializationInfo info, StreamingContext context)
  1573. {
  1574. if (info == null)
  1575. {
  1576. throw new ArgumentNullException("info");
  1577. }
  1578. info.AddValue("FullID", FullID.UUID);
  1579. info.AddValue("LastFullUpdateTime", LastFullUpdateTime);
  1580. info.AddValue("LastTerseUpdateTime", LastTerseUpdateTime);
  1581. }
  1582. }
  1583. public override void SetText(string text, Vector3 color, double alpha)
  1584. {
  1585. throw new Exception("Can't set Text on avatar.");
  1586. }
  1587. /// <summary>
  1588. /// Adds a physical representation of the avatar to the Physics plugin
  1589. /// </summary>
  1590. public void AddToPhysicalScene()
  1591. {
  1592. PhysicsScene scene = m_scene.PhysicsScene;
  1593. PhysicsVector pVec =
  1594. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1595. AbsolutePosition.Z);
  1596. if (m_avHeight == 127.0f)
  1597. {
  1598. m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, 1.56f));
  1599. }
  1600. else
  1601. {
  1602. m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, m_avHeight));
  1603. }
  1604. //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
  1605. m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
  1606. m_physicsActor.LocalID = LocalId;
  1607. }
  1608. // Event called by the physics plugin to tell the avatar about a collision.
  1609. private void PhysicsCollisionUpdate(EventArgs e)
  1610. {
  1611. bool isUserMoving = Velocity.X > 0 || Velocity.Y > 0;
  1612. UpdateMovementAnimations(isUserMoving);
  1613. }
  1614. internal void Close()
  1615. {
  1616. lock (m_attachments)
  1617. {
  1618. foreach (SceneObjectGroup grp in m_attachments)
  1619. {
  1620. // ControllingClient may be null at this point!
  1621. m_scene.m_innerScene.DetachSingleAttachmentToInv(grp.GetFromAssetID(), ControllingClient);
  1622. }
  1623. m_attachments.Clear();
  1624. }
  1625. lock (m_knownPrimUUID)
  1626. {
  1627. m_knownPrimUUID.Clear();
  1628. }
  1629. lock (m_knownChildRegions)
  1630. {
  1631. m_knownChildRegions.Clear();
  1632. }
  1633. lock (m_updateTimes)
  1634. {
  1635. m_updateTimes.Clear();
  1636. }
  1637. lock (m_partsUpdateQueue)
  1638. {
  1639. m_partsUpdateQueue.Clear();
  1640. }
  1641. RemoveFromPhysicalScene();
  1642. GC.Collect();
  1643. }
  1644. public ScenePresence()
  1645. {
  1646. /* JB
  1647. if (Animations == null)
  1648. {
  1649. Animations = new AvatarAnimations();
  1650. Animations.LoadAnims();
  1651. }
  1652. */
  1653. if (DefaultTexture == null)
  1654. {
  1655. LLObject.TextureEntry textu = AvatarAppearance.GetDefaultTextureEntry();
  1656. DefaultTexture = textu.ToBytes();
  1657. }
  1658. }
  1659. public void AddAttachment(SceneObjectGroup gobj)
  1660. {
  1661. lock (m_attachments)
  1662. {
  1663. m_attachments.Add(gobj);
  1664. }
  1665. }
  1666. public void RemoveAttachment(SceneObjectGroup gobj)
  1667. {
  1668. lock (m_attachments)
  1669. {
  1670. if (m_attachments.Contains(gobj))
  1671. {
  1672. m_attachments.Remove(gobj);
  1673. }
  1674. }
  1675. }
  1676. public void CrossAttachmentsIntoNewRegion(ulong regionHandle)
  1677. {
  1678. lock (m_attachments)
  1679. {
  1680. foreach (SceneObjectGroup gobj in m_attachments)
  1681. {
  1682. // If the prim group is null then something must have happened to it!
  1683. if (gobj != null)
  1684. {
  1685. // Set the parent localID to 0 so it transfers over properly.
  1686. gobj.RootPart.SetParentLocalId(0);
  1687. gobj.RootPart.m_IsAttachment = false;
  1688. gobj.AbsolutePosition = gobj.RootPart.m_attachedPos;
  1689. gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
  1690. m_scene.CrossPrimGroupIntoNewRegion(regionHandle, gobj);
  1691. }
  1692. }
  1693. m_attachments.Clear();
  1694. }
  1695. }
  1696. public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene)
  1697. {
  1698. m_controllingClient = client;
  1699. m_regionInfo = region;
  1700. m_scene = scene;
  1701. RegisterToEvents();
  1702. /*
  1703. AbsolutePosition = client.StartPos;
  1704. Animations = new AvatarAnimations();
  1705. Animations.LoadAnims();
  1706. m_animations = new List<LLUUID>();
  1707. m_animations.Add(Animations.AnimsLLUUID["STAND"]);
  1708. m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber);
  1709. SetDirectionVectors();
  1710. */
  1711. }
  1712. protected ScenePresence(SerializationInfo info, StreamingContext context)
  1713. : base (info, context)
  1714. {
  1715. //System.Console.WriteLine("ScenePresence Deserialize BGN");
  1716. if (info == null)
  1717. {
  1718. throw new ArgumentNullException("info");
  1719. }
  1720. /* JB
  1721. if (Animations == null)
  1722. {
  1723. Animations = new AvatarAnimations();
  1724. Animations.LoadAnims();
  1725. }
  1726. */
  1727. if (DefaultTexture == null)
  1728. {
  1729. LLObject.TextureEntry textu = AvatarAppearance.GetDefaultTextureEntry();
  1730. DefaultTexture = textu.ToBytes();
  1731. }
  1732. List<Guid> animations_work = (List<Guid>)info.GetValue("m_animations", typeof(List<Guid>));
  1733. foreach (Guid guid in animations_work)
  1734. {
  1735. m_animations.Add(new LLUUID(guid));
  1736. }
  1737. m_animationSeqs = (List<int>)info.GetValue("m_animationSeqs", typeof(List<int>));
  1738. m_updateflag = (bool)info.GetValue("m_updateflag", typeof(bool));
  1739. m_movementflag = (byte)info.GetValue("m_movementflag", typeof(byte));
  1740. m_forcesList = (List<NewForce>)info.GetValue("m_forcesList", typeof(List<NewForce>));
  1741. m_updateCount = (short)info.GetValue("m_updateCount", typeof(short));
  1742. m_requestedSitTargetID = (uint)info.GetValue("m_requestedSitTargetID", typeof(uint));
  1743. m_requestedSitOffset
  1744. = new LLVector3(
  1745. (float)info.GetValue("m_requestedSitOffset.X", typeof(float)),
  1746. (float)info.GetValue("m_requestedSitOffset.Y", typeof(float)),
  1747. (float)info.GetValue("m_requestedSitOffset.Z", typeof(float)));
  1748. m_sitAvatarHeight = (float)info.GetValue("m_sitAvatarHeight", typeof(float));
  1749. m_godlevel = (float)info.GetValue("m_godlevel", typeof(float));
  1750. m_setAlwaysRun = (bool)info.GetValue("m_setAlwaysRun", typeof(bool));
  1751. m_bodyRot
  1752. = new Quaternion(
  1753. (float)info.GetValue("m_bodyRot.w", typeof(float)),
  1754. (float)info.GetValue("m_bodyRot.x", typeof(float)),
  1755. (float)info.GetValue("m_bodyRot.y", typeof(float)),
  1756. (float)info.GetValue("m_bodyRot.z", typeof(float)));
  1757. IsRestrictedToRegion = (bool)info.GetValue("IsRestrictedToRegion", typeof(bool));
  1758. m_newForce = (bool)info.GetValue("m_newForce", typeof(bool));
  1759. //m_newAvatar = (bool)info.GetValue("m_newAvatar", typeof(bool));
  1760. m_newCoarseLocations = (bool)info.GetValue("m_newCoarseLocations", typeof(bool));
  1761. m_gotAllObjectsInScene = (bool)info.GetValue("m_gotAllObjectsInScene", typeof(bool));
  1762. m_avHeight = (float)info.GetValue("m_avHeight", typeof(float));
  1763. crossingFromRegion = (ulong)info.GetValue("crossingFromRegion", typeof(ulong));
  1764. List<float[]> Dir_Vectors_work = (List<float[]>)info.GetValue("Dir_Vectors", typeof(List<float[]>));
  1765. List<Vector3> Dir_Vectors_work2 = new List<Vector3>();
  1766. foreach (float[] f3 in Dir_Vectors_work)
  1767. {
  1768. Dir_Vectors_work2.Add(new Vector3(f3[0], f3[1], f3[2]));
  1769. }
  1770. Dir_Vectors = Dir_Vectors_work2.ToArray();
  1771. lastPhysPos
  1772. = new LLVector3(
  1773. (float)info.GetValue("lastPhysPos.X", typeof(float)),
  1774. (float)info.GetValue("lastPhysPos.Y", typeof(float)),
  1775. (float)info.GetValue("lastPhysPos.Z", typeof(float)));
  1776. m_CameraCenter
  1777. = new Vector3(
  1778. (float)info.GetValue("m_CameraCenter.X", typeof(float)),
  1779. (float)info.GetValue("m_CameraCenter.Y", typeof(float)),
  1780. (float)info.GetValue("m_CameraCenter.Z", typeof(float)));
  1781. m_CameraAtAxis
  1782. = new Vector3(
  1783. (float)info.GetValue("m_CameraAtAxis.X", typeof(float)),
  1784. (float)info.GetValue("m_CameraAtAxis.Y", typeof(float)),
  1785. (float)info.GetValue("m_CameraAtAxis.Z", typeof(float)));
  1786. m_CameraLeftAxis
  1787. = new Vector3(
  1788. (float)info.GetValue("m_CameraLeftAxis.X", typeof(float)),
  1789. (float)info.GetValue("m_CameraLeftAxis.Y", typeof(float)),
  1790. (float)info.GetValue("m_CameraLeftAxis.Z", typeof(float)));
  1791. m_CameraUpAxis
  1792. = new Vector3(
  1793. (float)info.GetValue("m_CameraUpAxis.X", typeof(float)),
  1794. (float)info.GetValue("m_CameraUpAxis.Y", typeof(float)),
  1795. (float)info.GetValue("m_CameraUpAxis.Z", typeof(float)));
  1796. m_DrawDistance = (float)info.GetValue("m_DrawDistance", typeof(float));
  1797. m_appearance = (AvatarAppearance)info.GetValue("m_appearance", typeof(AvatarAppearance));
  1798. m_knownChildRegions = (List<ulong>)info.GetValue("m_knownChildRegions", typeof(List<ulong>));
  1799. posLastSignificantMove
  1800. = new LLVector3(
  1801. (float)info.GetValue("posLastSignificantMove.X", typeof(float)),
  1802. (float)info.GetValue("posLastSignificantMove.Y", typeof(float)),
  1803. (float)info.GetValue("posLastSignificantMove.Z", typeof(float)));
  1804. // m_partsUpdateQueue = (UpdateQueue)info.GetValue("m_partsUpdateQueue", typeof(UpdateQueue));
  1805. /*
  1806. Dictionary<Guid, ScenePartUpdate> updateTimes_work
  1807. = (Dictionary<Guid, ScenePartUpdate>)info.GetValue("m_updateTimes", typeof(Dictionary<Guid, ScenePartUpdate>));
  1808. foreach (Guid id in updateTimes_work.Keys)
  1809. {
  1810. m_updateTimes.Add(new LLUUID(id), updateTimes_work[id]);
  1811. }
  1812. */
  1813. m_regionHandle = (ulong)info.GetValue("m_regionHandle", typeof(ulong));
  1814. m_firstname = (string)info.GetValue("m_firstname", typeof(string));
  1815. m_lastname = (string)info.GetValue("m_lastname", typeof(string));
  1816. m_allowMovement = (bool)info.GetValue("m_allowMovement", typeof(bool));
  1817. m_parentPosition = new LLVector3((float)info.GetValue("m_parentPosition.X", typeof(float)),
  1818. (float)info.GetValue("m_parentPosition.Y", typeof(float)),
  1819. (float)info.GetValue("m_parentPosition.Z", typeof(float)));
  1820. m_isChildAgent = (bool)info.GetValue("m_isChildAgent", typeof(bool));
  1821. m_parentID = (uint)info.GetValue("m_parentID", typeof(uint));
  1822. // for OpenSim_v0.5
  1823. currentParcelUUID = new LLUUID((Guid)info.GetValue("currentParcelUUID", typeof(Guid)));
  1824. lastKnownAllowedPosition
  1825. = new Vector3(
  1826. (float)info.GetValue("lastKnownAllowedPosition.X", typeof(float)),
  1827. (float)info.GetValue("lastKnownAllowedPosition.Y", typeof(float)),
  1828. (float)info.GetValue("lastKnownAllowedPosition.Z", typeof(float)));
  1829. sentMessageAboutRestrictedParcelFlyingDown = (bool)info.GetValue("sentMessageAboutRestrictedParcelFlyingDown", typeof(bool));
  1830. m_LastChildAgentUpdatePosition
  1831. = new LLVector3(
  1832. (float)info.GetValue("m_LastChildAgentUpdatePosition.X", typeof(float)),
  1833. (float)info.GetValue("m_LastChildAgentUpdatePosition.Y", typeof(float)),
  1834. (float)info.GetValue("m_LastChildAgentUpdatePosition.Z", typeof(float)));
  1835. m_perfMonMS = (int)info.GetValue("m_perfMonMS", typeof(int));
  1836. m_AgentControlFlags = (uint)info.GetValue("m_AgentControlFlags", typeof(uint));
  1837. m_headrotation
  1838. = new LLQuaternion(
  1839. (float)info.GetValue("m_headrotation.W", typeof(float)),
  1840. (float)info.GetValue("m_headrotation.X", typeof(float)),
  1841. (float)info.GetValue("m_headrotation.Y", typeof(float)),
  1842. (float)info.GetValue("m_headrotation.Z", typeof(float)));
  1843. m_state = (byte)info.GetValue("m_state", typeof(byte));
  1844. List<Guid> knownPrimUUID_work = (List<Guid>)info.GetValue("m_knownPrimUUID", typeof(List<Guid>));
  1845. foreach (Guid id in knownPrimUUID_work)
  1846. {
  1847. m_knownPrimUUID.Add(new LLUUID(id));
  1848. }
  1849. //System.Console.WriteLine("ScenePresence Deserialize END");
  1850. }
  1851. [SecurityPermission(SecurityAction.LinkDemand,
  1852. Flags = SecurityPermissionFlag.SerializationFormatter)]
  1853. public override void GetObjectData(
  1854. SerializationInfo info, StreamingContext context)
  1855. {
  1856. if (info == null)
  1857. {
  1858. throw new ArgumentNullException("info");
  1859. }
  1860. base.GetObjectData(info, context);
  1861. List<Guid> animations_work = new List<Guid>();
  1862. foreach (LLUUID uuid in m_animations)
  1863. {
  1864. animations_work.Add(uuid.UUID);
  1865. }
  1866. info.AddValue("m_animations", animations_work);
  1867. info.AddValue("m_animationSeqs", m_animationSeqs);
  1868. info.AddValue("m_updateflag", m_updateflag);
  1869. info.AddValue("m_movementflag", m_movementflag);
  1870. info.AddValue("m_forcesList", m_forcesList);
  1871. info.AddValue("m_updateCount", m_updateCount);
  1872. info.AddValue("m_requestedSitTargetID", m_requestedSitTargetID);
  1873. // LLVector3
  1874. info.AddValue("m_requestedSitOffset.X", m_requestedSitOffset.X);
  1875. info.AddValue("m_requestedSitOffset.Y", m_requestedSitOffset.Y);
  1876. info.AddValue("m_requestedSitOffset.Z", m_requestedSitOffset.Z);
  1877. info.AddValue("m_sitAvatarHeight", m_sitAvatarHeight);
  1878. info.AddValue("m_godlevel", m_godlevel);
  1879. info.AddValue("m_setAlwaysRun", m_setAlwaysRun);
  1880. // Quaternion
  1881. info.AddValue("m_bodyRot.w", m_bodyRot.w);
  1882. info.AddValue("m_bodyRot.x", m_bodyRot.x);
  1883. info.AddValue("m_bodyRot.y", m_bodyRot.y);
  1884. info.AddValue("m_bodyRot.z", m_bodyRot.z);
  1885. info.AddValue("IsRestrictedToRegion", IsRestrictedToRegion);
  1886. info.AddValue("m_newForce", m_newForce);
  1887. //info.AddValue("m_newAvatar", m_newAvatar);
  1888. info.AddValue("m_newCoarseLocations", m_newCoarseLocations);
  1889. info.AddValue("m_gotAllObjectsInScene", m_gotAllObjectsInScene);
  1890. info.AddValue("m_avHeight", m_avHeight);
  1891. // info.AddValue("m_regionInfo", m_regionInfo);
  1892. info.AddValue("crossingFromRegion", crossingFromRegion);
  1893. List<float[]> Dir_Vectors_work = new List<float[]>();
  1894. foreach (Vector3 v3 in Dir_Vectors)
  1895. {
  1896. Dir_Vectors_work.Add(new float[] { v3.x, v3.y, v3.z });
  1897. }
  1898. info.AddValue("Dir_Vectors", Dir_Vectors_work);
  1899. // LLVector3
  1900. info.AddValue("lastPhysPos.X", lastPhysPos.X);
  1901. info.AddValue("lastPhysPos.Y", lastPhysPos.Y);
  1902. info.AddValue("lastPhysPos.Z", lastPhysPos.Z);
  1903. // Vector3
  1904. info.AddValue("m_CameraCenter.X", m_CameraCenter.x);
  1905. info.AddValue("m_CameraCenter.Y", m_CameraCenter.y);
  1906. info.AddValue("m_CameraCenter.Z", m_CameraCenter.z);
  1907. // Vector3
  1908. info.AddValue("m_CameraAtAxis.X", m_CameraAtAxis.x);
  1909. info.AddValue("m_CameraAtAxis.Y", m_CameraAtAxis.y);
  1910. info.AddValue("m_CameraAtAxis.Z", m_CameraAtAxis.z);
  1911. // Vector3
  1912. info.AddValue("m_CameraLeftAxis.X", m_CameraLeftAxis.x);
  1913. info.AddValue("m_CameraLeftAxis.Y", m_CameraLeftAxis.y);
  1914. info.AddValue("m_CameraLeftAxis.Z", m_CameraLeftAxis.z);
  1915. // Vector3
  1916. info.AddValue("m_CameraUpAxis.X", m_CameraUpAxis.x);
  1917. info.AddValue("m_CameraUpAxis.Y", m_CameraUpAxis.y);
  1918. info.AddValue("m_CameraUpAxis.Z", m_CameraUpAxis.z);
  1919. info.AddValue("m_DrawDistance", m_DrawDistance);
  1920. info.AddValue("m_appearance", m_appearance);
  1921. info.AddValue("m_knownChildRegions", m_knownChildRegions);
  1922. // LLVector3
  1923. info.AddValue("posLastSignificantMove.X", posLastSignificantMove.X);
  1924. info.AddValue("posLastSignificantMove.Y", posLastSignificantMove.Y);
  1925. info.AddValue("posLastSignificantMove.Z", posLastSignificantMove.Z);
  1926. //info.AddValue("m_partsUpdateQueue", m_partsUpdateQueue);
  1927. /*
  1928. Dictionary<Guid, ScenePartUpdate> updateTimes_work = new Dictionary<Guid, ScenePartUpdate>();
  1929. foreach ( LLUUID id in m_updateTimes.Keys)
  1930. {
  1931. updateTimes_work.Add(id.UUID, m_updateTimes[id]);
  1932. }
  1933. info.AddValue("m_updateTimes", updateTimes_work);
  1934. */
  1935. info.AddValue("m_regionHandle", m_regionHandle);
  1936. info.AddValue("m_firstname", m_firstname);
  1937. info.AddValue("m_lastname", m_lastname);
  1938. info.AddValue("m_allowMovement", m_allowMovement);
  1939. //info.AddValue("m_physicsActor", m_physicsActor);
  1940. info.AddValue("m_parentPosition.X", m_parentPosition.X);
  1941. info.AddValue("m_parentPosition.Y", m_parentPosition.Y);
  1942. info.AddValue("m_parentPosition.Z", m_parentPosition.Z);
  1943. info.AddValue("m_isChildAgent", m_isChildAgent);
  1944. info.AddValue("m_parentID", m_parentID);
  1945. // for OpenSim_v0.5
  1946. info.AddValue("currentParcelUUID", currentParcelUUID.UUID);
  1947. info.AddValue("lastKnownAllowedPosition.X", lastKnownAllowedPosition.x);
  1948. info.AddValue("lastKnownAllowedPosition.Y", lastKnownAllowedPosition.y);
  1949. info.AddValue("lastKnownAllowedPosition.Z", lastKnownAllowedPosition.z);
  1950. info.AddValue("sentMessageAboutRestrictedParcelFlyingDown", sentMessageAboutRestrictedParcelFlyingDown);
  1951. info.AddValue("m_LastChildAgentUpdatePosition.X", m_LastChildAgentUpdatePosition.X);
  1952. info.AddValue("m_LastChildAgentUpdatePosition.Y", m_LastChildAgentUpdatePosition.Y);
  1953. info.AddValue("m_LastChildAgentUpdatePosition.Z", m_LastChildAgentUpdatePosition.Z);
  1954. info.AddValue("m_perfMonMS", m_perfMonMS);
  1955. info.AddValue("m_AgentControlFlags", m_AgentControlFlags);
  1956. info.AddValue("m_headrotation.W", m_headrotation.W);
  1957. info.AddValue("m_headrotation.X", m_headrotation.X);
  1958. info.AddValue("m_headrotation.Y", m_headrotation.Y);
  1959. info.AddValue("m_headrotation.Z", m_headrotation.Z);
  1960. info.AddValue("m_state", m_state);
  1961. List<Guid> knownPrimUUID_work = new List<Guid>();
  1962. foreach (LLUUID id in m_knownPrimUUID)
  1963. {
  1964. knownPrimUUID_work.Add(id.UUID);
  1965. }
  1966. info.AddValue("m_knownPrimUUID", knownPrimUUID_work);
  1967. }
  1968. }
  1969. }