ScenePresence.cs 100 KB

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