ScenePresence.cs 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526
  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 OpenMetaverse;
  33. using OpenMetaverse.Packets;
  34. using log4net;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Client;
  37. using OpenSim.Framework.Communications.Cache;
  38. using OpenSim.Region.Environment.Interfaces;
  39. using OpenSim.Region.Environment.Types;
  40. using OpenSim.Region.Interfaces;
  41. using OpenSim.Region.Physics.Manager;
  42. using OSD = OpenMetaverse.StructuredData.OSD;
  43. namespace OpenSim.Region.Environment.Scenes
  44. {
  45. enum ScriptControlled : uint
  46. {
  47. CONTROL_ZERO = 0,
  48. CONTROL_FWD = 1,
  49. CONTROL_BACK = 2,
  50. CONTROL_LEFT = 4,
  51. CONTROL_RIGHT = 8,
  52. CONTROL_UP = 16,
  53. CONTROL_DOWN = 32,
  54. CONTROL_ROT_LEFT = 256,
  55. CONTROL_ROT_RIGHT = 512,
  56. CONTROL_LBUTTON = 268435456,
  57. CONTROL_ML_LBUTTON = 1073741824
  58. }
  59. struct ScriptControllers
  60. {
  61. public UUID itemID;
  62. public uint objID;
  63. public ScriptControlled ignoreControls;
  64. public ScriptControlled eventControls;
  65. }
  66. [Serializable]
  67. public class ScenePresence : EntityBase, ISerializable
  68. {
  69. // ~ScenePresence()
  70. // {
  71. // System.Console.WriteLine("[ScenePresence] Destructor called");
  72. // }
  73. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  74. public static byte[] DefaultTexture;
  75. public UUID currentParcelUUID = UUID.Zero;
  76. private AnimationSet m_animations = new AnimationSet();
  77. private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>();
  78. private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO;
  79. private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO;
  80. private bool MouseDown = false;
  81. private SceneObjectGroup proxyObjectGroup = null;
  82. //private SceneObjectPart proxyObjectPart = null;
  83. public Vector3 lastKnownAllowedPosition = new Vector3();
  84. public bool sentMessageAboutRestrictedParcelFlyingDown = false;
  85. private bool m_updateflag = false;
  86. private byte m_movementflag = 0;
  87. private readonly List<NewForce> m_forcesList = new List<NewForce>();
  88. private short m_updateCount = 0;
  89. private uint m_requestedSitTargetID = 0;
  90. private UUID m_requestedSitTargetUUID = UUID.Zero;
  91. private bool m_startAnimationSet = false;
  92. private Vector3 m_requestedSitOffset = new Vector3();
  93. private Vector3 m_LastFinitePos = new Vector3();
  94. private float m_sitAvatarHeight = 2.0f;
  95. // experimentally determined "fudge factor" to make sit-target positions
  96. // the same as in SecondLife. Fudge factor was tested for 36 different
  97. // test cases including prims of type box, sphere, cylinder, and torus,
  98. // with varying parameters for sit target location, prim size, prim
  99. // rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
  100. // issue #1716
  101. private static readonly Vector3 m_sitTargetCorrectionOffset = new Vector3(0.1f, 0.0f, 0.3f);
  102. private float m_godlevel = 0;
  103. private bool m_invulnerable = true;
  104. private Vector3 m_LastChildAgentUpdatePosition = new Vector3();
  105. private int m_perfMonMS = 0;
  106. private bool m_setAlwaysRun = false;
  107. private Quaternion m_bodyRot= Quaternion.Identity;
  108. public bool IsRestrictedToRegion = false;
  109. public string JID = string.Empty;
  110. // Agent moves with a PID controller causing a force to be exerted.
  111. private bool m_newForce = false;
  112. private bool m_newCoarseLocations = true;
  113. private float m_health = 100f;
  114. private Vector3 m_lastVelocity = Vector3.Zero;
  115. // Default AV Height
  116. private float m_avHeight = 127.0f;
  117. protected RegionInfo m_regionInfo;
  118. protected ulong crossingFromRegion = 0;
  119. private readonly Vector3[] Dir_Vectors = new Vector3[6];
  120. /// <value>
  121. /// The avatar position last sent to clients
  122. /// </value>
  123. private Vector3 lastPhysPos = Vector3.Zero;
  124. /// <value>
  125. /// The avatar body rotation last sent to clients
  126. /// </value>
  127. private Quaternion lastPhysRot = Quaternion.Identity;
  128. // Position of agent's camera in world (region cordinates)
  129. protected Vector3 m_CameraCenter = Vector3.Zero;
  130. // Use these three vectors to figure out what the agent is looking at
  131. // Convert it to a Matrix and/or Quaternion
  132. protected Vector3 m_CameraAtAxis = Vector3.Zero;
  133. protected Vector3 m_CameraLeftAxis = Vector3.Zero;
  134. protected Vector3 m_CameraUpAxis = Vector3.Zero;
  135. private uint m_AgentControlFlags = 0;
  136. private Quaternion m_headrotation = Quaternion.Identity;
  137. private byte m_state = 0;
  138. //Reuse the Vector3 instead of creating a new one on the UpdateMovement method
  139. private Vector3 movementvector = Vector3.Zero;
  140. private bool m_autopilotMoving = false;
  141. private Vector3 m_autoPilotTarget = Vector3.Zero;
  142. private bool m_sitAtAutoTarget = false;
  143. private string m_nextSitAnimation = String.Empty;
  144. //PauPaw:Proper PID Controler for autopilot************
  145. private bool m_moveToPositionInProgress = false;
  146. private Vector3 m_moveToPositionTarget = Vector3.Zero;
  147. //private int m_moveToPositionStateStatus = 0;
  148. //*****************************************************
  149. // Agent's Draw distance.
  150. protected float m_DrawDistance = 0f;
  151. protected AvatarAppearance m_appearance;
  152. protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
  153. // neighbouring regions we have enabled a child agent in
  154. // holds the seed cap for the child agent in that region
  155. private Dictionary<ulong, string> m_knownChildRegions = new Dictionary<ulong, string>();
  156. /// <summary>
  157. /// Implemented Control Flags
  158. /// </summary>
  159. private enum Dir_ControlFlags
  160. {
  161. DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS,
  162. DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG,
  163. DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS,
  164. DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG,
  165. DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
  166. DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
  167. DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
  168. }
  169. /// <summary>
  170. /// Position at which a significant movement was made
  171. /// </summary>
  172. private Vector3 posLastSignificantMove = new Vector3();
  173. private UpdateQueue m_partsUpdateQueue = new UpdateQueue();
  174. private Queue<SceneObjectGroup> m_pendingObjects = null;
  175. private Dictionary<UUID, ScenePartUpdate> m_updateTimes = new Dictionary<UUID, ScenePartUpdate>();
  176. #region Properties
  177. /// <summary>
  178. /// Physical scene representation of this Avatar.
  179. /// </summary>
  180. public PhysicsActor PhysicsActor
  181. {
  182. set { m_physicsActor = value; }
  183. get { return m_physicsActor; }
  184. }
  185. public byte MovementFlag
  186. {
  187. set { m_movementflag = value; }
  188. get { return m_movementflag; }
  189. }
  190. public bool Updated
  191. {
  192. set { m_updateflag = value; }
  193. get { return m_updateflag; }
  194. }
  195. public bool Invulnerable
  196. {
  197. set { m_invulnerable = value; }
  198. get { return m_invulnerable; }
  199. }
  200. public float GodLevel
  201. {
  202. get { return m_godlevel; }
  203. }
  204. private readonly ulong m_regionHandle;
  205. public ulong RegionHandle
  206. {
  207. get { return m_regionHandle; }
  208. }
  209. public Vector3 CameraPosition
  210. {
  211. get { return m_CameraCenter; }
  212. }
  213. public Quaternion CameraRotation
  214. {
  215. get { return Util.Axes2Rot(m_CameraAtAxis, m_CameraLeftAxis, m_CameraUpAxis); }
  216. }
  217. public Vector3 Lookat
  218. {
  219. get
  220. {
  221. Vector3 a = new Vector3(m_CameraAtAxis.X, m_CameraAtAxis.Y, 0);
  222. if (a == Vector3.Zero)
  223. return a;
  224. return Util.GetNormalizedVector(a);
  225. }
  226. }
  227. private readonly string m_firstname;
  228. public string Firstname
  229. {
  230. get { return m_firstname; }
  231. }
  232. private readonly string m_lastname;
  233. public string Lastname
  234. {
  235. get { return m_lastname; }
  236. }
  237. private string m_grouptitle;
  238. public string Grouptitle
  239. {
  240. get { return m_grouptitle; }
  241. set { m_grouptitle = value; }
  242. }
  243. public float DrawDistance
  244. {
  245. get { return m_DrawDistance; }
  246. }
  247. protected bool m_allowMovement = true;
  248. public bool AllowMovement
  249. {
  250. get { return m_allowMovement; }
  251. set { m_allowMovement = value; }
  252. }
  253. public bool SetAlwaysRun
  254. {
  255. get
  256. {
  257. if (PhysicsActor != null)
  258. {
  259. return PhysicsActor.SetAlwaysRun;
  260. }
  261. else
  262. {
  263. return m_setAlwaysRun;
  264. }
  265. }
  266. set
  267. {
  268. m_setAlwaysRun = value;
  269. if (PhysicsActor != null)
  270. {
  271. PhysicsActor.SetAlwaysRun = value;
  272. }
  273. }
  274. }
  275. public byte State
  276. {
  277. get { return m_state; }
  278. set { m_state = value; }
  279. }
  280. public uint AgentControlFlags
  281. {
  282. get { return m_AgentControlFlags; }
  283. set { m_AgentControlFlags = value; }
  284. }
  285. /// <summary>
  286. /// This works out to be the ClientView object associated with this avatar, or it's client connection manager
  287. /// </summary>
  288. private IClientAPI m_controllingClient;
  289. protected PhysicsActor m_physicsActor;
  290. /// <value>
  291. /// The client controlling this presence
  292. /// </value>
  293. public IClientAPI ControllingClient
  294. {
  295. get { return m_controllingClient; }
  296. }
  297. public IClientCore ClientView
  298. {
  299. get { return (IClientCore) m_controllingClient; }
  300. }
  301. protected Vector3 m_parentPosition = new Vector3();
  302. public Vector3 ParentPosition
  303. {
  304. get { return m_parentPosition; }
  305. set { m_parentPosition = value; }
  306. }
  307. /// <summary>
  308. /// Absolute position of this avatar in 'region cordinates'
  309. /// </summary>
  310. public override Vector3 AbsolutePosition
  311. {
  312. get
  313. {
  314. if (m_physicsActor != null)
  315. {
  316. m_pos.X = m_physicsActor.Position.X;
  317. m_pos.Y = m_physicsActor.Position.Y;
  318. m_pos.Z = m_physicsActor.Position.Z;
  319. }
  320. return m_parentPosition + m_pos;
  321. }
  322. set
  323. {
  324. if (m_physicsActor != null)
  325. {
  326. try
  327. {
  328. lock (m_scene.SyncRoot)
  329. {
  330. m_physicsActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  331. }
  332. }
  333. catch (Exception e)
  334. {
  335. Console.WriteLine(e.Message);
  336. }
  337. }
  338. m_pos = value;
  339. m_parentPosition = new Vector3(0, 0, 0);
  340. }
  341. }
  342. /// <summary>
  343. /// Current velocity of the avatar.
  344. /// </summary>
  345. public override Vector3 Velocity
  346. {
  347. get
  348. {
  349. if (m_physicsActor != null)
  350. {
  351. m_velocity.X = m_physicsActor.Velocity.X;
  352. m_velocity.Y = m_physicsActor.Velocity.Y;
  353. m_velocity.Z = m_physicsActor.Velocity.Z;
  354. }
  355. return m_velocity;
  356. }
  357. set
  358. {
  359. //m_log.DebugFormat("In {0} setting velocity of {1} to {2}", m_scene.RegionInfo.RegionName, Name, value);
  360. if (m_physicsActor != null)
  361. {
  362. try
  363. {
  364. lock (m_scene.SyncRoot)
  365. {
  366. m_physicsActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
  367. }
  368. }
  369. catch (Exception e)
  370. {
  371. Console.WriteLine(e.Message);
  372. }
  373. }
  374. m_velocity = value;
  375. }
  376. }
  377. /// <summary>
  378. /// If this is true, agent doesn't have a representation in this scene.
  379. /// this is an agent 'looking into' this scene from a nearby scene(region)
  380. ///
  381. /// if False, this agent has a representation in this scene
  382. /// </summary>
  383. private bool m_isChildAgent = true;
  384. public bool IsChildAgent
  385. {
  386. get { return m_isChildAgent; }
  387. set { m_isChildAgent = value; }
  388. }
  389. private uint m_parentID = 0;
  390. public uint ParentID
  391. {
  392. get { return m_parentID; }
  393. set { m_parentID = value; }
  394. }
  395. public float Health
  396. {
  397. get { return m_health; }
  398. set { m_health = value; }
  399. }
  400. /// <summary>
  401. /// These are the region handles known by the avatar.
  402. /// </summary>
  403. public List<ulong> KnownChildRegionHandles
  404. {
  405. get
  406. {
  407. if (m_knownChildRegions.Count == 0)
  408. return new List<ulong>();
  409. else
  410. return new List<ulong>(m_knownChildRegions.Keys);
  411. }
  412. }
  413. public Dictionary<ulong, string> KnownRegions
  414. {
  415. get { return m_knownChildRegions; }
  416. set
  417. {
  418. //Console.WriteLine(" !! Setting known regions in {0} to {1}", Scene.RegionInfo.RegionName, value.Count);
  419. m_knownChildRegions = value;
  420. }
  421. }
  422. public void AdjustKnownSeeds()
  423. {
  424. Dictionary<ulong, string> seeds = Scene.GetChildrenSeeds(UUID);
  425. List<ulong> old = new List<ulong>();
  426. foreach (ulong handle in seeds.Keys)
  427. {
  428. uint x, y;
  429. Utils.LongToUInts(handle, out x, out y);
  430. x = x / Constants.RegionSize;
  431. y = y / Constants.RegionSize;
  432. if (Util.IsOutsideView(x, Scene.RegionInfo.RegionLocX, y, Scene.RegionInfo.RegionLocY))
  433. {
  434. old.Add(handle);
  435. }
  436. }
  437. DropOldNeighbours(old);
  438. Scene.SetChildrenSeed(UUID, seeds);
  439. KnownRegions = seeds;
  440. //Console.WriteLine(" ++++++++++AFTER+++++++++++++ ");
  441. //DumpKnownRegions();
  442. }
  443. public void DumpKnownRegions()
  444. {
  445. Console.WriteLine("================ KnownRegions {0} ================", Scene.RegionInfo.RegionName);
  446. foreach (KeyValuePair<ulong, string> kvp in KnownRegions)
  447. {
  448. uint x, y;
  449. Utils.LongToUInts(kvp.Key, out x, out y);
  450. x = x / Constants.RegionSize;
  451. y = y / Constants.RegionSize;
  452. Console.WriteLine(" >> {0}, {1}: {2}", x, y, kvp.Value);
  453. }
  454. }
  455. public AnimationSet Animations
  456. {
  457. get { return m_animations; }
  458. }
  459. #endregion
  460. #region Constructor(s)
  461. private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo)
  462. {
  463. m_regionHandle = reginfo.RegionHandle;
  464. m_controllingClient = client;
  465. m_firstname = m_controllingClient.FirstName;
  466. m_lastname = m_controllingClient.LastName;
  467. m_name = String.Format("{0} {1}", m_firstname, m_lastname);
  468. m_scene = world;
  469. m_uuid = client.AgentId;
  470. m_regionInfo = reginfo;
  471. m_localId = m_scene.AllocateLocalId();
  472. IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
  473. if (gm != null)
  474. m_grouptitle = gm.GetGroupTitle(m_uuid);
  475. AbsolutePosition = m_controllingClient.StartPos;
  476. AdjustKnownSeeds();
  477. TrySetMovementAnimation("STAND"); // TODO: I think, this won't send anything, as we are still a child here...
  478. // we created a new ScenePresence (a new child agent) in a fresh region.
  479. // Request info about all the (root) agents in this region
  480. // Note: This won't send data *to* other clients in that region (children don't send)
  481. SendInitialFullUpdateToAllClients();
  482. RegisterToEvents();
  483. SetDirectionVectors();
  484. CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid);
  485. if (userInfo != null)
  486. userInfo.OnItemReceived += ItemReceived;
  487. m_log.Info("[AVATAR]: New ScenePresence in " + Scene.RegionInfo.RegionName);
  488. }
  489. public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams,
  490. AvatarWearable[] wearables)
  491. : this(client, world, reginfo)
  492. {
  493. m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams);
  494. }
  495. public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance)
  496. : this(client, world, reginfo)
  497. {
  498. m_appearance = appearance;
  499. }
  500. public void RegisterToEvents()
  501. {
  502. m_controllingClient.OnRequestWearables += SendWearables;
  503. m_controllingClient.OnSetAppearance += SetAppearance;
  504. m_controllingClient.OnCompleteMovementToRegion += CompleteMovement;
  505. m_controllingClient.OnCompleteMovementToRegion += SendInitialData;
  506. m_controllingClient.OnAgentUpdate += HandleAgentUpdate;
  507. m_controllingClient.OnAgentRequestSit += HandleAgentRequestSit;
  508. m_controllingClient.OnAgentSit += HandleAgentSit;
  509. m_controllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
  510. m_controllingClient.OnStartAnim += HandleStartAnim;
  511. m_controllingClient.OnStopAnim += HandleStopAnim;
  512. m_controllingClient.OnForceReleaseControls += HandleForceReleaseControls;
  513. m_controllingClient.OnAutoPilotGo += DoAutoPilot;
  514. m_controllingClient.AddGenericPacketHandler("autopilot", DoMoveToPosition);
  515. // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
  516. // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
  517. }
  518. private void SetDirectionVectors()
  519. {
  520. Dir_Vectors[0] = new Vector3(1, 0, 0); //FORWARD
  521. Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK
  522. Dir_Vectors[2] = new Vector3(0, 1, 0); //LEFT
  523. Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT
  524. Dir_Vectors[4] = new Vector3(0, 0, 1); //UP
  525. Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN
  526. Dir_Vectors[5] = new Vector3(0, 0, -0.5f); //DOWN_Nudge
  527. }
  528. #endregion
  529. /// <summary>
  530. /// Add the part to the queue of parts for which we need to send an update to the client
  531. /// </summary>
  532. /// <param name="part"></param>
  533. public void QueuePartForUpdate(SceneObjectPart part)
  534. {
  535. //if (InterestList.Contains(part.ParentGroup))
  536. //{
  537. lock (m_partsUpdateQueue)
  538. {
  539. m_partsUpdateQueue.Enqueue(part);
  540. }
  541. // }
  542. }
  543. public uint GenerateClientFlags(UUID ObjectID)
  544. {
  545. return m_scene.Permissions.GenerateClientFlags(m_uuid, ObjectID);
  546. }
  547. /// <summary>
  548. /// Send updates to the client about prims which have been placed on the update queue. We don't
  549. /// necessarily send updates for all the parts on the queue, e.g. if an updates with a more recent
  550. /// timestamp has already been sent.
  551. /// </summary>
  552. public void SendPrimUpdates()
  553. {
  554. // if (m_scene.QuadTree.GetNodeID(this.AbsolutePosition.X, this.AbsolutePosition.Y) != m_currentQuadNode)
  555. //{
  556. // this.UpdateQuadTreeNode();
  557. //this.RefreshQuadObject();
  558. //}
  559. m_perfMonMS = System.Environment.TickCount;
  560. if (m_pendingObjects == null)
  561. {
  562. if (!m_isChildAgent || m_scene.m_seeIntoRegionFromNeighbor)
  563. {
  564. m_pendingObjects = new Queue<SceneObjectGroup>();
  565. List<EntityBase> ents = new List<EntityBase>(m_scene.Entities);
  566. if (!m_isChildAgent) // Proximity sort makes no sense for
  567. { // Child agents
  568. ents.Sort(delegate(EntityBase a, EntityBase b)
  569. {
  570. return Vector3.Distance(AbsolutePosition, a.AbsolutePosition).CompareTo(Vector3.Distance(AbsolutePosition, b.AbsolutePosition));
  571. });
  572. }
  573. foreach (EntityBase e in ents)
  574. {
  575. if (e is SceneObjectGroup)
  576. m_pendingObjects.Enqueue((SceneObjectGroup)e);
  577. }
  578. }
  579. }
  580. while (m_pendingObjects.Count > 0 && m_partsUpdateQueue.Count < 60)
  581. {
  582. SceneObjectGroup g = m_pendingObjects.Dequeue();
  583. // This is where we should check for draw distance
  584. // do culling and stuff. Problem with that is that until
  585. // we recheck in movement, that won't work right.
  586. // So it's not implemented now.
  587. //
  588. // Don't even queue if we have sent this one
  589. //
  590. if (!m_updateTimes.ContainsKey(g.UUID))
  591. g.ScheduleFullUpdateToAvatar(this);
  592. }
  593. int updateCount = 0;
  594. while (m_partsUpdateQueue.Count > 0)
  595. {
  596. SceneObjectPart part = m_partsUpdateQueue.Dequeue();
  597. if (part.ParentGroup == null || part.ParentGroup.IsDeleted)
  598. continue;
  599. if (m_updateTimes.ContainsKey(part.UUID))
  600. {
  601. ScenePartUpdate update = m_updateTimes[part.UUID];
  602. // We deal with the possibility that two updates occur at
  603. // the same unix time at the update point itself.
  604. if ((update.LastFullUpdateTime < part.TimeStampFull) ||
  605. part.IsAttachment)
  606. {
  607. // m_log.DebugFormat(
  608. // "[SCENE PRESENCE]: Fully updating prim {0}, {1} - part timestamp {2}",
  609. // part.Name, part.UUID, part.TimeStampFull);
  610. part.SendFullUpdate(ControllingClient,
  611. GenerateClientFlags(part.UUID));
  612. // We'll update to the part's timestamp rather than
  613. // the current time to avoid the race condition
  614. // whereby the next tick occurs while we are doing
  615. // this update. If this happened, then subsequent
  616. // updates which occurred on the same tick or the
  617. // next tick of the last update would be ignored.
  618. update.LastFullUpdateTime = part.TimeStampFull;
  619. updateCount++;
  620. }
  621. else if (update.LastTerseUpdateTime <= part.TimeStampTerse)
  622. {
  623. // m_log.DebugFormat(
  624. // "[SCENE PRESENCE]: Tersely updating prim {0}, {1} - part timestamp {2}",
  625. // part.Name, part.UUID, part.TimeStampTerse);
  626. part.SendTerseUpdateToClient(ControllingClient);
  627. update.LastTerseUpdateTime = part.TimeStampTerse;
  628. updateCount++;
  629. }
  630. }
  631. else
  632. {
  633. //never been sent to client before so do full update
  634. ScenePartUpdate update = new ScenePartUpdate();
  635. update.FullID = part.UUID;
  636. update.LastFullUpdateTime = part.TimeStampFull;
  637. m_updateTimes.Add(part.UUID, update);
  638. // Attachment handling
  639. //
  640. if (part.ParentGroup.RootPart.Shape.PCode == 9 && part.ParentGroup.RootPart.Shape.State != 0)
  641. {
  642. if (part != part.ParentGroup.RootPart)
  643. continue;
  644. part.ParentGroup.SendFullUpdateToClient(ControllingClient);
  645. continue;
  646. }
  647. part.SendFullUpdate(ControllingClient,
  648. GenerateClientFlags(part.UUID));
  649. updateCount++;
  650. }
  651. if (updateCount > 60)
  652. break;
  653. }
  654. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  655. }
  656. #region Status Methods
  657. /// <summary>
  658. /// This turns a child agent, into a root agent
  659. /// This is called when an agent teleports into a region, or if an
  660. /// agent crosses into this region from a neighbor over the border
  661. /// </summary>
  662. public void MakeRootAgent(Vector3 pos, bool isFlying)
  663. {
  664. m_log.DebugFormat(
  665. "[SCENE]: Upgrading child to root agent for {0} in {1}",
  666. Name, m_scene.RegionInfo.RegionName);
  667. m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
  668. IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
  669. if (gm != null)
  670. m_grouptitle = gm.GetGroupTitle(m_uuid);
  671. m_scene.SetRootAgentScene(m_uuid);
  672. // Moved this from SendInitialData to ensure that m_appearance is initialized
  673. // before the inventory is processed in MakeRootAgent. This fixes a race condition
  674. // related to the handling of attachments
  675. m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance);
  676. if (pos.X < 0 || pos.X > Constants.RegionSize || pos.Y < 0 || pos.Y > Constants.RegionSize || pos.Z < 0)
  677. {
  678. Vector3 emergencyPos = new Vector3(128, 128, 128);
  679. m_log.WarnFormat(
  680. "[SCENE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
  681. pos, Name, UUID, emergencyPos);
  682. pos = emergencyPos;
  683. }
  684. m_isChildAgent = false;
  685. float localAVHeight = 1.56f;
  686. if (m_avHeight != 127.0f)
  687. {
  688. localAVHeight = m_avHeight;
  689. }
  690. float posZLimit = (float)m_scene.GetLandHeight((int)pos.X, (int)pos.Y);
  691. float newPosZ = posZLimit + localAVHeight / 2;
  692. if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
  693. {
  694. pos.Z = newPosZ;
  695. }
  696. AbsolutePosition = pos;
  697. AddToPhysicalScene();
  698. m_physicsActor.Flying = isFlying;
  699. // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
  700. // avatar to return to the standing position in mid-air. On login it looks like this is being sent
  701. // elsewhere anyway
  702. //SendAnimPack();
  703. m_scene.SwapRootAgentCount(false);
  704. m_scene.CommsManager.UserProfileCacheService.RequestInventoryForUser(m_uuid);
  705. m_scene.AddCapsHandler(m_uuid);
  706. // On the next prim update, all objects will be sent
  707. //
  708. m_pendingObjects = null;
  709. m_scene.EventManager.TriggerOnMakeRootAgent(this);
  710. }
  711. /// <summary>
  712. /// This turns a root agent into a child agent
  713. /// when an agent departs this region for a neighbor, this gets called.
  714. ///
  715. /// It doesn't get called for a teleport. Reason being, an agent that
  716. /// teleports out may not end up anywhere near this region
  717. /// </summary>
  718. public void MakeChildAgent()
  719. {
  720. m_animations.Clear();
  721. // m_log.DebugFormat(
  722. // "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
  723. // Name, UUID, m_scene.RegionInfo.RegionName);
  724. // Don't zero out the velocity since this can cause problems when an avatar is making a region crossing,
  725. // depending on the exact timing. This shouldn't matter anyway since child agent positions are not updated.
  726. //Velocity = new Vector3(0, 0, 0);
  727. m_isChildAgent = true;
  728. m_scene.SwapRootAgentCount(true);
  729. RemoveFromPhysicalScene();
  730. m_scene.EventManager.TriggerOnMakeChildAgent(this);
  731. }
  732. /// <summary>
  733. /// Removes physics plugin scene representation of this agent if it exists.
  734. /// </summary>
  735. private void RemoveFromPhysicalScene()
  736. {
  737. if (PhysicsActor != null)
  738. {
  739. m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
  740. m_physicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
  741. m_physicsActor.UnSubscribeEvents();
  742. m_physicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
  743. PhysicsActor = null;
  744. }
  745. }
  746. /// <summary>
  747. ///
  748. /// </summary>
  749. /// <param name="pos"></param>
  750. public void Teleport(Vector3 pos)
  751. {
  752. RemoveFromPhysicalScene();
  753. Velocity = new Vector3(0, 0, 0);
  754. AbsolutePosition = pos;
  755. AddToPhysicalScene();
  756. SendTerseUpdateToAllClients();
  757. }
  758. /// <summary>
  759. ///
  760. /// </summary>
  761. public void StopMovement()
  762. {
  763. }
  764. public void StopFlying()
  765. {
  766. // It turns out to get the agent to stop flying, you have to feed it stop flying velocities
  767. // and send a full object update.
  768. // There's no message to send the client to tell it to stop flying
  769. // Add 1/6 the avatar's height to it's position so it doesn't shoot into the air
  770. // when the avatar stands up
  771. if (m_avHeight != 127.0f)
  772. {
  773. AbsolutePosition = AbsolutePosition + new Vector3(0, 0, (m_avHeight / 6f));
  774. }
  775. else
  776. {
  777. AbsolutePosition = AbsolutePosition + new Vector3(0, 0, (1.56f / 6f));
  778. }
  779. TrySetMovementAnimation("LAND");
  780. SendFullUpdateToAllClients();
  781. }
  782. public void AddNeighbourRegion(ulong regionHandle, string cap)
  783. {
  784. lock (m_knownChildRegions)
  785. {
  786. if (!m_knownChildRegions.ContainsKey(regionHandle))
  787. {
  788. uint x, y;
  789. Utils.LongToUInts(regionHandle, out x, out y);
  790. m_knownChildRegions.Add(regionHandle, cap);
  791. }
  792. }
  793. }
  794. public void RemoveNeighbourRegion(ulong regionHandle)
  795. {
  796. lock (m_knownChildRegions)
  797. {
  798. if (m_knownChildRegions.ContainsKey(regionHandle))
  799. {
  800. m_knownChildRegions.Remove(regionHandle);
  801. //Console.WriteLine(" !!! removing known region {0} in {1}. Count = {2}", regionHandle, Scene.RegionInfo.RegionName, m_knownChildRegions.Count);
  802. }
  803. }
  804. }
  805. public void DropOldNeighbours(List<ulong> oldRegions)
  806. {
  807. foreach (ulong handle in oldRegions)
  808. {
  809. RemoveNeighbourRegion(handle);
  810. Scene.DropChildSeed(UUID, handle);
  811. }
  812. }
  813. public List<ulong> GetKnownRegionList()
  814. {
  815. return new List<ulong>(m_knownChildRegions.Keys);
  816. }
  817. #endregion
  818. #region Event Handlers
  819. /// <summary>
  820. /// Sets avatar height in the phyiscs plugin
  821. /// </summary>
  822. internal void SetHeight(float height)
  823. {
  824. m_avHeight = height;
  825. if (PhysicsActor != null)
  826. {
  827. PhysicsVector SetSize = new PhysicsVector(0.45f, 0.6f, m_avHeight);
  828. PhysicsActor.Size = SetSize;
  829. }
  830. }
  831. /// <summary>
  832. /// Complete Avatar's movement into the region
  833. /// </summary>
  834. public void CompleteMovement()
  835. {
  836. Vector3 look = Velocity;
  837. if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
  838. {
  839. look = new Vector3(0.99f, 0.042f, 0);
  840. }
  841. m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look);
  842. if (m_isChildAgent)
  843. {
  844. m_isChildAgent = false;
  845. MakeRootAgent(AbsolutePosition, false);
  846. }
  847. }
  848. /// <summary>
  849. /// This is the event handler for client movement. If a client is moving, this event is triggering.
  850. /// </summary>
  851. public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
  852. {
  853. //if (m_isChildAgent)
  854. //{
  855. // // Console.WriteLine("DEBUG: HandleAgentUpdate: child agent");
  856. // return;
  857. //}
  858. // Must check for standing up even when PhysicsActor is null,
  859. // since sitting currently removes avatar from physical scene
  860. //m_log.Debug("agentPos:" + AbsolutePosition.ToString());
  861. // This is irritating. Really.
  862. if (!AbsolutePosition.IsFinite())
  863. {
  864. RemoveFromPhysicalScene();
  865. m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error# 9999902");
  866. m_pos = m_LastFinitePos;
  867. if (!m_pos.IsFinite())
  868. {
  869. m_pos.X = 127f;
  870. m_pos.Y = 127f;
  871. m_pos.Z = 127f;
  872. m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error# 9999903");
  873. }
  874. AddToPhysicalScene();
  875. }
  876. else
  877. {
  878. m_LastFinitePos = m_pos;
  879. }
  880. //m_physicsActor.AddForce(new PhysicsVector(999999999, 99999999, 999999999999999), true);
  881. //ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
  882. //if (land != null)
  883. //{
  884. //if (land.landData.landingType == (byte)1 && land.landData.userLocation != Vector3.Zero)
  885. //{
  886. // agent.startpos = land.landData.userLocation;
  887. //}
  888. //}
  889. m_perfMonMS = System.Environment.TickCount;
  890. uint flags = agentData.ControlFlags;
  891. Quaternion bodyRotation = agentData.BodyRotation;
  892. // Camera location in world. We'll need to raytrace
  893. // from this location from time to time.
  894. m_CameraCenter = agentData.CameraCenter;
  895. // Use these three vectors to figure out what the agent is looking at
  896. // Convert it to a Matrix and/or Quaternion
  897. m_CameraAtAxis = agentData.CameraAtAxis;
  898. m_CameraLeftAxis = agentData.CameraLeftAxis;
  899. m_CameraUpAxis = agentData.CameraUpAxis;
  900. // The Agent's Draw distance setting
  901. m_DrawDistance = agentData.Far;
  902. if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0)
  903. {
  904. StandUp();
  905. }
  906. lock (scriptedcontrols)
  907. {
  908. if (scriptedcontrols.Count > 0)
  909. {
  910. SendControlToScripts(flags);
  911. flags = this.RemoveIgnoredControls(flags, IgnoredControls);
  912. }
  913. }
  914. if (PhysicsActor == null)
  915. {
  916. return;
  917. }
  918. if (m_autopilotMoving)
  919. CheckAtSitTarget();
  920. if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
  921. {
  922. // TODO: This doesn't prevent the user from walking yet.
  923. // Setting parent ID would fix this, if we knew what value
  924. // to use. Or we could add a m_isSitting variable.
  925. TrySetMovementAnimation("SIT_GROUND_CONSTRAINED");
  926. }
  927. // In the future, these values might need to go global.
  928. // Here's where you get them.
  929. m_AgentControlFlags = flags;
  930. m_headrotation = agentData.HeadRotation;
  931. m_state = agentData.State;
  932. if (m_allowMovement)
  933. {
  934. int i = 0;
  935. bool update_movementflag = false;
  936. bool update_rotation = false;
  937. bool DCFlagKeyPressed = false;
  938. Vector3 agent_control_v3 = new Vector3(0, 0, 0);
  939. Quaternion q = bodyRotation;
  940. if (PhysicsActor != null)
  941. {
  942. bool oldflying = PhysicsActor.Flying;
  943. PhysicsActor.Flying = ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
  944. if (PhysicsActor.Flying != oldflying)
  945. {
  946. update_movementflag = true;
  947. }
  948. }
  949. if (q != m_bodyRot)
  950. {
  951. m_bodyRot = q;
  952. update_rotation = true;
  953. }
  954. if (m_parentID == 0)
  955. {
  956. bool bAllowUpdateMoveToPosition = false;
  957. bool bResetMoveToPosition = false;
  958. foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags)))
  959. {
  960. if ((flags & (uint) DCF) != 0)
  961. {
  962. bResetMoveToPosition = true;
  963. DCFlagKeyPressed = true;
  964. try
  965. {
  966. agent_control_v3 += Dir_Vectors[i];
  967. }
  968. catch (IndexOutOfRangeException)
  969. {
  970. // Why did I get this?
  971. }
  972. if ((m_movementflag & (uint) DCF) == 0)
  973. {
  974. m_movementflag += (byte) (uint) DCF;
  975. update_movementflag = true;
  976. }
  977. }
  978. else
  979. {
  980. if ((m_movementflag & (uint) DCF) != 0)
  981. {
  982. m_movementflag -= (byte) (uint) DCF;
  983. update_movementflag = true;
  984. }
  985. else
  986. {
  987. bAllowUpdateMoveToPosition = true;
  988. }
  989. }
  990. i++;
  991. }
  992. //Paupaw:Do Proper PID for Autopilot here
  993. if (bResetMoveToPosition)
  994. {
  995. m_moveToPositionTarget = Vector3.Zero;
  996. m_moveToPositionInProgress = false;
  997. update_movementflag = true;
  998. bAllowUpdateMoveToPosition = false;
  999. }
  1000. if (bAllowUpdateMoveToPosition && (m_moveToPositionInProgress && !m_autopilotMoving))
  1001. {
  1002. //Check the error term of the current position in relation to the target position
  1003. if (Util.GetDistanceTo(AbsolutePosition, m_moveToPositionTarget) <= 1.5)
  1004. {
  1005. // we are close enough to the target
  1006. m_moveToPositionTarget = Vector3.Zero;
  1007. m_moveToPositionInProgress = false;
  1008. update_movementflag = true;
  1009. }
  1010. else
  1011. {
  1012. try
  1013. {
  1014. // move avatar in 2D at one meter/second towards target, in avatar coordinate frame.
  1015. // This movement vector gets added to the velocity through AddNewMovement().
  1016. // Theoretically we might need a more complex PID approach here if other
  1017. // unknown forces are acting on the avatar and we need to adaptively respond
  1018. // to such forces, but the following simple approach seems to works fine.
  1019. Vector3 LocalVectorToTarget3D =
  1020. (m_moveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords
  1021. * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords
  1022. // Ignore z component of vector
  1023. Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
  1024. LocalVectorToTarget2D.Normalize();
  1025. agent_control_v3 += LocalVectorToTarget2D;
  1026. // update avatar movement flags. the avatar coordinate system is as follows:
  1027. //
  1028. // +X (forward)
  1029. //
  1030. // ^
  1031. // |
  1032. // |
  1033. // |
  1034. // |
  1035. // (left) +Y <--------o--------> -Y
  1036. // avatar
  1037. // |
  1038. // |
  1039. // |
  1040. // |
  1041. // v
  1042. // -X
  1043. //
  1044. // based on the above avatar coordinate system, classify the movement into
  1045. // one of left/right/back/forward.
  1046. if (LocalVectorToTarget2D.Y > 0)//MoveLeft
  1047. {
  1048. m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT;
  1049. update_movementflag = true;
  1050. }
  1051. else if (LocalVectorToTarget2D.Y < 0) //MoveRight
  1052. {
  1053. m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT;
  1054. update_movementflag = true;
  1055. }
  1056. if (LocalVectorToTarget2D.X < 0) //MoveBack
  1057. {
  1058. m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK;
  1059. update_movementflag = true;
  1060. }
  1061. else if (LocalVectorToTarget2D.X > 0) //Move Forward
  1062. {
  1063. m_movementflag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD;
  1064. update_movementflag = true;
  1065. }
  1066. }
  1067. catch (Exception)
  1068. {
  1069. //Avoid system crash, can be slower but...
  1070. }
  1071. }
  1072. }
  1073. }
  1074. // Cause the avatar to stop flying if it's colliding
  1075. // with something with the down arrow pressed.
  1076. // Only do this if we're flying
  1077. if (m_physicsActor != null && m_physicsActor.Flying)
  1078. {
  1079. // Are the landing controls requirements filled?
  1080. bool controlland = (((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
  1081. ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
  1082. // Are the collision requirements fulfilled?
  1083. bool colliding = (m_physicsActor.IsColliding == true);
  1084. if (m_physicsActor.Flying && colliding && controlland)
  1085. {
  1086. StopFlying();
  1087. }
  1088. }
  1089. if (update_movementflag || (update_rotation && DCFlagKeyPressed))
  1090. {
  1091. // m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed));
  1092. // m_log.DebugFormat(
  1093. // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
  1094. AddNewMovement(agent_control_v3, q);
  1095. if (update_movementflag)
  1096. UpdateMovementAnimations();
  1097. }
  1098. }
  1099. m_scene.EventManager.TriggerOnClientMovement(this);
  1100. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1101. }
  1102. public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client)
  1103. {
  1104. m_autopilotMoving = true;
  1105. m_autoPilotTarget = Pos;
  1106. m_sitAtAutoTarget = false;
  1107. PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
  1108. //proxy.PCode = (byte)PCode.ParticleSystem;
  1109. proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy);
  1110. proxyObjectGroup.AttachToScene(m_scene);
  1111. // Commented out this code since it could never have executed, but might still be informative.
  1112. // if (proxyObjectGroup != null)
  1113. // {
  1114. proxyObjectGroup.SendGroupFullUpdate();
  1115. remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false);
  1116. m_scene.DeleteSceneObject(proxyObjectGroup, false);
  1117. // }
  1118. // else
  1119. // {
  1120. // m_autopilotMoving = false;
  1121. // m_autoPilotTarget = Vector3.Zero;
  1122. // ControllingClient.SendAlertMessage("Autopilot cancelled");
  1123. // }
  1124. }
  1125. public void DoMoveToPosition(Object sender, string method, List<String> args)
  1126. {
  1127. try
  1128. {
  1129. float locx = 0f;
  1130. float locy = 0f;
  1131. float locz = 0f;
  1132. uint regionX = 0;
  1133. uint regionY = 0;
  1134. try
  1135. {
  1136. Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY);
  1137. locx = Convert.ToSingle(args[0]) - (float)regionX;
  1138. locy = Convert.ToSingle(args[1]) - (float)regionY;
  1139. locz = Convert.ToSingle(args[2]);
  1140. }
  1141. catch (InvalidCastException)
  1142. {
  1143. m_log.Error("[CLIENT]: Invalid autopilot request");
  1144. return;
  1145. }
  1146. m_moveToPositionInProgress = true;
  1147. m_moveToPositionTarget = new Vector3(locx, locy, locz);
  1148. }
  1149. catch (Exception ex)
  1150. {
  1151. //Why did I get this error?
  1152. System.Diagnostics.Debug.WriteLine(ex.ToString());
  1153. }
  1154. }
  1155. private void CheckAtSitTarget()
  1156. {
  1157. //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString());
  1158. if (Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget) <= 1.5)
  1159. {
  1160. if (m_sitAtAutoTarget)
  1161. {
  1162. SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetUUID);
  1163. if (part != null)
  1164. {
  1165. AbsolutePosition = part.AbsolutePosition;
  1166. Velocity = new Vector3(0, 0, 0);
  1167. SendFullUpdateToAllClients();
  1168. //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID);
  1169. }
  1170. //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false);
  1171. m_requestedSitTargetUUID = UUID.Zero;
  1172. }
  1173. else
  1174. {
  1175. //ControllingClient.SendAlertMessage("Autopilot cancelled");
  1176. //SendTerseUpdateToAllClients();
  1177. //PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
  1178. //proxy.PCode = (byte)PCode.ParticleSystem;
  1179. ////uint nextUUID = m_scene.NextLocalId;
  1180. //proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, m_autoPilotTarget, Quaternion.Identity, proxy);
  1181. //if (proxyObjectGroup != null)
  1182. //{
  1183. //proxyObjectGroup.SendGroupFullUpdate();
  1184. //ControllingClient.SendSitResponse(UUID.Zero, m_autoPilotTarget, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false);
  1185. //m_scene.DeleteSceneObject(proxyObjectGroup);
  1186. //}
  1187. }
  1188. m_autoPilotTarget = Vector3.Zero;
  1189. m_autopilotMoving = false;
  1190. }
  1191. }
  1192. /// <summary>
  1193. /// Perform the logic necessary to stand the client up. This method also executes
  1194. /// the stand animation.
  1195. /// </summary>
  1196. public void StandUp()
  1197. {
  1198. if (m_parentID != 0)
  1199. {
  1200. SceneObjectPart part = m_scene.GetSceneObjectPart(m_parentID);
  1201. if (part != null)
  1202. {
  1203. TaskInventoryDictionary taskIDict = part.TaskInventory;
  1204. if (taskIDict != null)
  1205. {
  1206. lock (taskIDict)
  1207. {
  1208. foreach (UUID taskID in taskIDict.Keys)
  1209. {
  1210. UnRegisterControlEventsToScript(LocalId, taskID);
  1211. }
  1212. }
  1213. }
  1214. // Reset sit target.
  1215. if (part.GetAvatarOnSitTarget() == UUID)
  1216. part.SetAvatarOnSitTarget(UUID.Zero);
  1217. m_parentPosition = part.GetWorldPosition();
  1218. }
  1219. if (m_physicsActor == null)
  1220. {
  1221. AddToPhysicalScene();
  1222. }
  1223. m_pos += m_parentPosition + new Vector3(0.0f, 0.0f, 2.0f*m_sitAvatarHeight);
  1224. m_parentPosition = new Vector3();
  1225. m_parentID = 0;
  1226. SendFullUpdateToAllClients();
  1227. m_requestedSitTargetID = 0;
  1228. if (m_physicsActor != null)
  1229. {
  1230. SetHeight(m_avHeight);
  1231. }
  1232. }
  1233. TrySetMovementAnimation("STAND");
  1234. }
  1235. private SceneObjectPart FindNextAvailableSitTarget(UUID targetID)
  1236. {
  1237. SceneObjectPart targetPart = m_scene.GetSceneObjectPart(targetID);
  1238. if (targetPart == null)
  1239. return null;
  1240. // If the primitive the player clicked on has a sit target and that sit target is not full, that sit target is used.
  1241. // If the primitive the player clicked on has no sit target, and one or more other linked objects have sit targets that are not full, the sit target of the object with the lowest link number will be used.
  1242. // Get our own copy of the part array, and sort into the order we want to test
  1243. SceneObjectPart[] partArray = targetPart.ParentGroup.GetParts();
  1244. Array.Sort(partArray, delegate(SceneObjectPart p1, SceneObjectPart p2)
  1245. {
  1246. // we want the originally selected part first, then the rest in link order -- so make the selected part link num (-1)
  1247. int linkNum1 = p1==targetPart ? -1 : p1.LinkNum;
  1248. int linkNum2 = p2==targetPart ? -1 : p2.LinkNum;
  1249. return linkNum1 - linkNum2;
  1250. }
  1251. );
  1252. //look for prims with explicit sit targets that are available
  1253. foreach (SceneObjectPart part in partArray)
  1254. {
  1255. // Is a sit target available?
  1256. Vector3 avSitOffSet = part.SitTargetPosition;
  1257. Quaternion avSitOrientation = part.SitTargetOrientation;
  1258. UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
  1259. bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero));
  1260. bool SitTargetisSet =
  1261. (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 1f &&
  1262. avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f));
  1263. if (SitTargetisSet && SitTargetUnOccupied)
  1264. {
  1265. //switch the target to this prim
  1266. return part;
  1267. }
  1268. }
  1269. // no explicit sit target found - use original target
  1270. return targetPart;
  1271. }
  1272. private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset)
  1273. {
  1274. bool autopilot = true;
  1275. Vector3 pos = new Vector3();
  1276. Quaternion sitOrientation = Quaternion.Identity;
  1277. Vector3 cameraEyeOffset = Vector3.Zero;
  1278. Vector3 cameraAtOffset = Vector3.Zero;
  1279. bool forceMouselook = false;
  1280. //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
  1281. SceneObjectPart part = FindNextAvailableSitTarget(targetID);
  1282. if (part != null)
  1283. {
  1284. // TODO: determine position to sit at based on scene geometry; don't trust offset from client
  1285. // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
  1286. // Is a sit target available?
  1287. Vector3 avSitOffSet = part.SitTargetPosition;
  1288. Quaternion avSitOrientation = part.SitTargetOrientation;
  1289. UUID avOnTargetAlready = part.GetAvatarOnSitTarget();
  1290. bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero));
  1291. bool SitTargetisSet =
  1292. (!(avSitOffSet.X == 0f && avSitOffSet.Y == 0f && avSitOffSet.Z == 0f && avSitOrientation.W == 0f &&
  1293. avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f));
  1294. if (SitTargetisSet && SitTargetUnOccupied)
  1295. {
  1296. part.SetAvatarOnSitTarget(UUID);
  1297. offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z);
  1298. sitOrientation = avSitOrientation;
  1299. autopilot = false;
  1300. }
  1301. pos = part.AbsolutePosition + offset;
  1302. //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1)
  1303. //{
  1304. // offset = pos;
  1305. //autopilot = false;
  1306. //}
  1307. if (m_physicsActor != null)
  1308. {
  1309. // If we're not using the client autopilot, we're immediately warping the avatar to the location
  1310. // We can remove the physicsActor until they stand up.
  1311. m_sitAvatarHeight = m_physicsActor.Size.Z;
  1312. if (autopilot)
  1313. {
  1314. if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5)
  1315. {
  1316. autopilot = false;
  1317. RemoveFromPhysicalScene();
  1318. AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
  1319. }
  1320. }
  1321. else
  1322. {
  1323. RemoveFromPhysicalScene();
  1324. }
  1325. }
  1326. cameraAtOffset = part.GetCameraAtOffset();
  1327. cameraEyeOffset = part.GetCameraEyeOffset();
  1328. forceMouselook = part.GetForceMouselook();
  1329. }
  1330. ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook);
  1331. m_requestedSitTargetUUID = targetID;
  1332. // This calls HandleAgentSit twice, once from here, and the client calls
  1333. // HandleAgentSit itself after it gets to the location
  1334. // It doesn't get to the location until we've moved them there though
  1335. // which happens in HandleAgentSit :P
  1336. m_autopilotMoving = autopilot;
  1337. m_autoPilotTarget = pos;
  1338. m_sitAtAutoTarget = autopilot;
  1339. if (!autopilot)
  1340. HandleAgentSit(remoteClient, UUID);
  1341. }
  1342. public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
  1343. {
  1344. if (m_parentID != 0)
  1345. {
  1346. StandUp();
  1347. }
  1348. m_nextSitAnimation = "SIT";
  1349. //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
  1350. SceneObjectPart part = FindNextAvailableSitTarget(targetID);
  1351. if (part != null)
  1352. {
  1353. if (!String.IsNullOrEmpty(part.SitAnimation))
  1354. {
  1355. m_nextSitAnimation = part.SitAnimation;
  1356. }
  1357. m_requestedSitTargetID = part.LocalId;
  1358. m_requestedSitOffset = offset;
  1359. }
  1360. else
  1361. {
  1362. m_log.Warn("Sit requested on unknown object: " + targetID.ToString());
  1363. }
  1364. SendSitResponse(remoteClient, targetID, offset);
  1365. }
  1366. public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation)
  1367. {
  1368. if (m_parentID != 0)
  1369. {
  1370. StandUp();
  1371. }
  1372. if (!String.IsNullOrEmpty(sitAnimation))
  1373. {
  1374. m_nextSitAnimation = sitAnimation;
  1375. }
  1376. else
  1377. {
  1378. m_nextSitAnimation = "SIT";
  1379. }
  1380. //SceneObjectPart part = m_scene.GetSceneObjectPart(targetID);
  1381. SceneObjectPart part = FindNextAvailableSitTarget(targetID);
  1382. if (part != null)
  1383. {
  1384. m_requestedSitTargetID = part.LocalId;
  1385. m_requestedSitOffset = offset;
  1386. }
  1387. else
  1388. {
  1389. m_log.Warn("Sit requested on unknown object: " + targetID.ToString());
  1390. }
  1391. SendSitResponse(remoteClient, targetID, offset);
  1392. }
  1393. public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
  1394. {
  1395. if (!String.IsNullOrEmpty(m_nextSitAnimation))
  1396. {
  1397. HandleAgentSit(remoteClient, agentID, m_nextSitAnimation);
  1398. }
  1399. else
  1400. {
  1401. HandleAgentSit(remoteClient, agentID, "SIT");
  1402. }
  1403. }
  1404. public void HandleAgentSit(IClientAPI remoteClient, UUID agentID, string sitAnimation)
  1405. {
  1406. SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID);
  1407. if (m_sitAtAutoTarget || !m_autopilotMoving)
  1408. {
  1409. if (part != null)
  1410. {
  1411. if (part.GetAvatarOnSitTarget() == UUID)
  1412. {
  1413. Vector3 sitTargetPos = part.SitTargetPosition;
  1414. Quaternion sitTargetOrient = part.SitTargetOrientation;
  1415. //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0);
  1416. //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w);
  1417. //Quaternion result = (sitTargetOrient * vq) * nq;
  1418. m_pos = new Vector3(sitTargetPos.X, sitTargetPos.Y, sitTargetPos.Z);
  1419. m_pos += m_sitTargetCorrectionOffset;
  1420. m_bodyRot = sitTargetOrient;
  1421. //Rotation = sitTargetOrient;
  1422. m_parentPosition = part.AbsolutePosition;
  1423. //SendTerseUpdateToAllClients();
  1424. }
  1425. else
  1426. {
  1427. m_pos -= part.AbsolutePosition;
  1428. m_parentPosition = part.AbsolutePosition;
  1429. }
  1430. }
  1431. else
  1432. {
  1433. return;
  1434. }
  1435. }
  1436. m_parentID = m_requestedSitTargetID;
  1437. Velocity = new Vector3(0, 0, 0);
  1438. RemoveFromPhysicalScene();
  1439. TrySetMovementAnimation(sitAnimation);
  1440. SendFullUpdateToAllClients();
  1441. // This may seem stupid, but Our Full updates don't send avatar rotation :P
  1442. // So we're also sending a terse update (which has avatar rotation)
  1443. // [Update] We do now.
  1444. //SendTerseUpdateToAllClients();
  1445. }
  1446. /// <summary>
  1447. /// Event handler for the 'Always run' setting on the client
  1448. /// Tells the physics plugin to increase speed of movement.
  1449. /// </summary>
  1450. public void HandleSetAlwaysRun(IClientAPI remoteClient, bool SetAlwaysRun)
  1451. {
  1452. m_setAlwaysRun = SetAlwaysRun;
  1453. if (PhysicsActor != null)
  1454. {
  1455. PhysicsActor.SetAlwaysRun = SetAlwaysRun;
  1456. }
  1457. }
  1458. public void AddAnimation(UUID animID)
  1459. {
  1460. if (m_isChildAgent)
  1461. return;
  1462. if (m_animations.Add(animID, m_controllingClient.NextAnimationSequenceNumber))
  1463. {
  1464. SendAnimPack();
  1465. }
  1466. }
  1467. public void AddAnimation(string name)
  1468. {
  1469. if (m_isChildAgent)
  1470. return;
  1471. UUID animID = m_controllingClient.GetDefaultAnimation(name);
  1472. if (animID == UUID.Zero)
  1473. return;
  1474. AddAnimation(animID);
  1475. }
  1476. public void RemoveAnimation(UUID animID)
  1477. {
  1478. if (m_isChildAgent)
  1479. return;
  1480. if (m_animations.Remove(animID))
  1481. {
  1482. SendAnimPack();
  1483. }
  1484. }
  1485. public void RemoveAnimation(string name)
  1486. {
  1487. if (m_isChildAgent)
  1488. return;
  1489. UUID animID = m_controllingClient.GetDefaultAnimation(name);
  1490. if (animID == UUID.Zero)
  1491. return;
  1492. RemoveAnimation(animID);
  1493. }
  1494. public UUID[] GetAnimationArray()
  1495. {
  1496. UUID[] animIDs;
  1497. int[] sequenceNums;
  1498. m_animations.GetArrays( out animIDs, out sequenceNums );
  1499. return animIDs;
  1500. }
  1501. public void HandleStartAnim(IClientAPI remoteClient, UUID animID)
  1502. {
  1503. AddAnimation(animID);
  1504. }
  1505. public void HandleStopAnim(IClientAPI remoteClient, UUID animID)
  1506. {
  1507. RemoveAnimation(animID);
  1508. }
  1509. /// <summary>
  1510. /// The movement animation is reserved for "main" animations
  1511. /// that are mutually exclusive, e.g. flying and sitting.
  1512. /// </summary>
  1513. protected void TrySetMovementAnimation(string anim)
  1514. {
  1515. //m_log.DebugFormat("Updating movement animation to {0}", anim);
  1516. if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber))
  1517. {
  1518. SendAnimPack();
  1519. }
  1520. }
  1521. /// <summary>
  1522. /// This method determines the proper movement related animation
  1523. /// </summary>
  1524. public string GetMovementAnimation()
  1525. {
  1526. if (m_movementflag != 0)
  1527. {
  1528. // We are moving
  1529. if (PhysicsActor != null && PhysicsActor.Flying)
  1530. {
  1531. return "FLY";
  1532. }
  1533. else if (PhysicsActor != null && (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 &&
  1534. PhysicsActor.IsColliding)
  1535. {
  1536. if ((m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 ||
  1537. (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
  1538. {
  1539. return "CROUCHWALK";
  1540. }
  1541. else
  1542. {
  1543. return "CROUCH";
  1544. }
  1545. }
  1546. else if (PhysicsActor != null && !PhysicsActor.IsColliding && PhysicsActor.Velocity.Z < -2)
  1547. {
  1548. return "FALLDOWN";
  1549. }
  1550. else if (PhysicsActor != null && !PhysicsActor.IsColliding && Velocity.Z > 1e-6 &&
  1551. (m_movementflag & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0)
  1552. {
  1553. return "JUMP";
  1554. }
  1555. else if (m_setAlwaysRun)
  1556. {
  1557. return "RUN";
  1558. }
  1559. else
  1560. {
  1561. return "WALK";
  1562. }
  1563. }
  1564. else
  1565. {
  1566. // We are not moving
  1567. if (PhysicsActor != null && !PhysicsActor.IsColliding && PhysicsActor.Velocity.Z < -2 && !PhysicsActor.Flying)
  1568. {
  1569. return "FALLDOWN";
  1570. }
  1571. else if (PhysicsActor != null && !PhysicsActor.IsColliding && Velocity.Z > 6 && !PhysicsActor.Flying)
  1572. {
  1573. // HACK: We check if Velocity.Z > 6 for this animation in order to avoid false positives during normal movement.
  1574. // TODO: set this animation only when on the ground and UP_POS is received?
  1575. // This is the standing jump
  1576. return "JUMP";
  1577. }
  1578. else if (PhysicsActor != null && PhysicsActor.Flying)
  1579. {
  1580. return "HOVER";
  1581. }
  1582. else
  1583. {
  1584. return "STAND";
  1585. }
  1586. }
  1587. }
  1588. /// <summary>
  1589. /// Update the movement animation of this avatar according to its current state
  1590. /// </summary>
  1591. protected void UpdateMovementAnimations()
  1592. {
  1593. string animation = GetMovementAnimation();
  1594. TrySetMovementAnimation(animation);
  1595. }
  1596. /// <summary>
  1597. /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
  1598. /// </summary>
  1599. /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
  1600. /// <param name="rotation">The direction in which this avatar should now face.
  1601. public void AddNewMovement(Vector3 vec, Quaternion rotation)
  1602. {
  1603. if (m_isChildAgent)
  1604. {
  1605. Console.WriteLine("DEBUG: AddNewMovement: child agent");
  1606. return;
  1607. }
  1608. m_perfMonMS = System.Environment.TickCount;
  1609. m_rotation = rotation;
  1610. NewForce newVelocity = new NewForce();
  1611. Vector3 direc = vec * rotation;
  1612. direc.Normalize();
  1613. direc *= 0.03f * 128f;
  1614. if (m_physicsActor.Flying)
  1615. {
  1616. direc *= 4;
  1617. //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
  1618. //bool colliding = (m_physicsActor.IsColliding==true);
  1619. //if (controlland)
  1620. // m_log.Info("[AGENT]: landCommand");
  1621. //if (colliding)
  1622. // m_log.Info("[AGENT]: colliding");
  1623. //if (m_physicsActor.Flying && colliding && controlland)
  1624. //{
  1625. // StopFlying();
  1626. // m_log.Info("[AGENT]: Stop FLying");
  1627. //}
  1628. }
  1629. else
  1630. {
  1631. if (!m_physicsActor.Flying && m_physicsActor.IsColliding)
  1632. {
  1633. if (direc.Z > 2.0f)
  1634. {
  1635. direc.Z *= 3;
  1636. // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
  1637. TrySetMovementAnimation("PREJUMP");
  1638. TrySetMovementAnimation("JUMP");
  1639. }
  1640. }
  1641. }
  1642. newVelocity.X = direc.X;
  1643. newVelocity.Y = direc.Y;
  1644. newVelocity.Z = direc.Z;
  1645. m_forcesList.Add(newVelocity);
  1646. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1647. }
  1648. #endregion
  1649. #region Overridden Methods
  1650. public override void Update()
  1651. {
  1652. SendPrimUpdates();
  1653. if (m_newCoarseLocations)
  1654. {
  1655. SendCoarseLocations();
  1656. m_newCoarseLocations = false;
  1657. }
  1658. if (m_isChildAgent == false)
  1659. {
  1660. if (m_newForce) // user movement 'forces' (ie commands to move)
  1661. {
  1662. SendTerseUpdateToAllClients();
  1663. m_updateCount = 0;
  1664. }
  1665. else if (m_movementflag != 0) // scripted movement (?)
  1666. {
  1667. m_updateCount++;
  1668. if (m_updateCount > 3)
  1669. {
  1670. SendTerseUpdateToAllClients();
  1671. m_updateCount = 0;
  1672. }
  1673. }
  1674. else if ((Util.GetDistanceTo(lastPhysPos, AbsolutePosition) > 0.02)
  1675. || (Util.GetDistanceTo(m_lastVelocity, m_velocity) > 0.02)
  1676. || lastPhysRot != m_bodyRot)
  1677. {
  1678. // Send Terse Update to all clients updates lastPhysPos and m_lastVelocity
  1679. // doing the above assures us that we know what we sent the clients last
  1680. SendTerseUpdateToAllClients();
  1681. m_updateCount = 0;
  1682. }
  1683. // followed suggestion from mic bowman. reversed the two lines below.
  1684. CheckForBorderCrossing();
  1685. CheckForSignificantMovement(); // sends update to the modules.
  1686. }
  1687. }
  1688. #endregion
  1689. #region Update Client(s)
  1690. /// <summary>
  1691. /// Sends a location update to the client connected to this scenePresence
  1692. /// </summary>
  1693. /// <param name="remoteClient"></param>
  1694. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  1695. {
  1696. m_perfMonMS = System.Environment.TickCount;
  1697. Vector3 pos = m_pos;
  1698. Vector3 vel = Velocity;
  1699. Quaternion rot = m_bodyRot;
  1700. pos.Z -= m_appearance.HipOffset;
  1701. remoteClient.SendAvatarTerseUpdate(m_regionHandle, (ushort)(m_scene.TimeDilation * (float)ushort.MaxValue), LocalId, new Vector3(pos.X, pos.Y, pos.Z),
  1702. new Vector3(vel.X, vel.Y, vel.Z), rot);
  1703. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1704. m_scene.AddAgentUpdates(1);
  1705. }
  1706. /// <summary>
  1707. /// Send a location/velocity/accelleration update to all agents in scene
  1708. /// </summary>
  1709. public void SendTerseUpdateToAllClients()
  1710. {
  1711. m_perfMonMS = System.Environment.TickCount;
  1712. m_scene.Broadcast(SendTerseUpdateToClient);
  1713. m_lastVelocity = m_velocity;
  1714. lastPhysPos = AbsolutePosition;
  1715. lastPhysRot = m_bodyRot;
  1716. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1717. }
  1718. public void SendCoarseLocations()
  1719. {
  1720. m_perfMonMS = System.Environment.TickCount;
  1721. List<Vector3> CoarseLocations = new List<Vector3>();
  1722. List<ScenePresence> avatars = m_scene.GetAvatars();
  1723. for (int i = 0; i < avatars.Count; i++)
  1724. {
  1725. if (avatars[i] != this)
  1726. {
  1727. if (avatars[i].ParentID != 0)
  1728. {
  1729. // sitting avatar
  1730. SceneObjectPart sop = m_scene.GetSceneObjectPart(avatars[i].ParentID);
  1731. if (sop != null)
  1732. {
  1733. CoarseLocations.Add(sop.AbsolutePosition + avatars[i].m_pos);
  1734. }
  1735. else
  1736. {
  1737. // we can't find the parent.. ! arg!
  1738. CoarseLocations.Add(avatars[i].m_pos);
  1739. }
  1740. }
  1741. else
  1742. {
  1743. CoarseLocations.Add(avatars[i].m_pos);
  1744. }
  1745. }
  1746. }
  1747. m_controllingClient.SendCoarseLocationUpdate(CoarseLocations);
  1748. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1749. }
  1750. public void CoarseLocationChange()
  1751. {
  1752. m_newCoarseLocations = true;
  1753. }
  1754. /// <summary>
  1755. /// Tell other client about this avatar (The client previously didn't know or had outdated details about this avatar)
  1756. /// </summary>
  1757. /// <param name="remoteAvatar"></param>
  1758. public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar)
  1759. {
  1760. // 2 stage check is needed.
  1761. if (remoteAvatar == null)
  1762. return;
  1763. IClientAPI cl=remoteAvatar.ControllingClient;
  1764. if (cl == null)
  1765. return;
  1766. if (m_appearance.Texture == null)
  1767. return;
  1768. // Note: because Quaternion is a struct, it can't be null
  1769. Quaternion rot = m_bodyRot;
  1770. Vector3 pos = m_pos;
  1771. pos.Z -= m_appearance.HipOffset;
  1772. remoteAvatar.m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid,
  1773. LocalId, m_pos, m_appearance.Texture.ToBytes(),
  1774. m_parentID, rot);
  1775. m_scene.AddAgentUpdates(1);
  1776. }
  1777. /// <summary>
  1778. /// Tell *ALL* agents about this agent
  1779. /// </summary>
  1780. public void SendInitialFullUpdateToAllClients()
  1781. {
  1782. m_perfMonMS = System.Environment.TickCount;
  1783. List<ScenePresence> avatars = m_scene.GetScenePresences();
  1784. foreach (ScenePresence avatar in avatars)
  1785. {
  1786. // only send if this is the root (children are only "listening posts" in a foreign region)
  1787. if (!IsChildAgent)
  1788. {
  1789. SendFullUpdateToOtherClient(avatar);
  1790. }
  1791. if (avatar.LocalId != LocalId)
  1792. {
  1793. if (!avatar.IsChildAgent)
  1794. {
  1795. avatar.SendFullUpdateToOtherClient(this);
  1796. avatar.SendAppearanceToOtherAgent(this);
  1797. avatar.SendAnimPackToClient(this.ControllingClient);
  1798. }
  1799. }
  1800. }
  1801. m_scene.AddAgentUpdates(avatars.Count);
  1802. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1803. }
  1804. public void SendFullUpdateToAllClients()
  1805. {
  1806. m_perfMonMS = System.Environment.TickCount;
  1807. // only send update from root agents to other clients; children are only "listening posts"
  1808. List<ScenePresence> avatars = m_scene.GetAvatars();
  1809. foreach (ScenePresence avatar in avatars)
  1810. {
  1811. SendFullUpdateToOtherClient(avatar);
  1812. }
  1813. m_scene.AddAgentUpdates(avatars.Count);
  1814. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1815. SendAnimPack();
  1816. }
  1817. /// <summary>
  1818. /// Do everything required once a client completes its movement into a region
  1819. /// </summary>
  1820. public void SendInitialData()
  1821. {
  1822. // Moved this into CompleteMovement to ensure that m_appearance is initialized before
  1823. // the inventory arrives
  1824. // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance);
  1825. // Note: because Quaternion is a struct, it can't be null
  1826. Quaternion rot = m_bodyRot;
  1827. Vector3 pos = m_pos;
  1828. pos.Z -= m_appearance.HipOffset;
  1829. m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
  1830. m_pos, m_appearance.Texture.ToBytes(), m_parentID, rot);
  1831. if (!m_isChildAgent)
  1832. {
  1833. m_scene.InformClientOfNeighbours(this);
  1834. }
  1835. SendInitialFullUpdateToAllClients();
  1836. SendAppearanceToAllOtherAgents();
  1837. }
  1838. /// <summary>
  1839. /// Tell the client for this scene presence what items it should be wearing now
  1840. /// </summary>
  1841. /// <param name="client"></param>
  1842. public void SendWearables()
  1843. {
  1844. m_log.DebugFormat("[APPEARANCE]: Sending wearables to {0}", Name);
  1845. ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
  1846. }
  1847. /// <summary>
  1848. ///
  1849. /// </summary>
  1850. public void SendAppearanceToAllOtherAgents()
  1851. {
  1852. m_log.DebugFormat("[APPEARANCE]: Sending appearance to all other agents for {0}", Name);
  1853. m_perfMonMS = System.Environment.TickCount;
  1854. m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
  1855. {
  1856. if (scenePresence.UUID != UUID)
  1857. {
  1858. SendAppearanceToOtherAgent(scenePresence);
  1859. }
  1860. });
  1861. m_scene.AddAgentTime(System.Environment.TickCount - m_perfMonMS);
  1862. }
  1863. /// <summary>
  1864. /// Send appearance data to an agent that isn't this one.
  1865. /// </summary>
  1866. /// <param name="avatar"></param>
  1867. public void SendAppearanceToOtherAgent(ScenePresence avatar)
  1868. {
  1869. avatar.ControllingClient.SendAppearance(
  1870. m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.ToBytes());
  1871. }
  1872. /// <summary>
  1873. /// Set appearance data (textureentry and slider settings) received from the client
  1874. /// </summary>
  1875. /// <param name="texture"></param>
  1876. /// <param name="visualParam"></param>
  1877. public void SetAppearance(byte[] texture, List<byte> visualParam)
  1878. {
  1879. m_log.DebugFormat("[APPEARANCE]: Receiving appearance for {0}", Name);
  1880. m_appearance.SetAppearance(texture, visualParam);
  1881. SetHeight(m_appearance.AvatarHeight);
  1882. m_scene.CommsManager.AvatarService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance);
  1883. SendAppearanceToAllOtherAgents();
  1884. //SendWearables();
  1885. if (!m_startAnimationSet)
  1886. {
  1887. UpdateMovementAnimations();
  1888. m_startAnimationSet = true;
  1889. }
  1890. }
  1891. public void SetWearable(int wearableId, AvatarWearable wearable)
  1892. {
  1893. m_log.DebugFormat("[APPEARANCE]: Setting wearable for {0}", Name);
  1894. m_appearance.SetWearable(wearableId, wearable);
  1895. m_scene.CommsManager.AvatarService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance);
  1896. m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
  1897. }
  1898. // Because appearance setting is in a module, we actually need
  1899. // to give it access to our appearance directly, otherwise we
  1900. // get a synchronization issue.
  1901. public AvatarAppearance Appearance
  1902. {
  1903. get { return m_appearance; }
  1904. set { m_appearance = value; }
  1905. }
  1906. /// <summary>
  1907. ///
  1908. /// </summary>
  1909. /// <param name="animations"></param>
  1910. /// <param name="seqs"></param>
  1911. public void SendAnimPack(UUID[] animations, int[] seqs)
  1912. {
  1913. if (m_isChildAgent)
  1914. return;
  1915. m_scene.Broadcast(
  1916. delegate(IClientAPI client) { client.SendAnimations(animations, seqs, m_controllingClient.AgentId); });
  1917. }
  1918. public void SendAnimPackToClient(IClientAPI client)
  1919. {
  1920. if (m_isChildAgent)
  1921. return;
  1922. UUID[] animIDs;
  1923. int[] sequenceNums;
  1924. m_animations.GetArrays(out animIDs, out sequenceNums);
  1925. client.SendAnimations(animIDs, sequenceNums, m_controllingClient.AgentId);
  1926. }
  1927. /// <summary>
  1928. /// Send animation information about this avatar to all clients.
  1929. /// </summary>
  1930. public void SendAnimPack()
  1931. {
  1932. //m_log.Debug("Sending animation pack");
  1933. if (m_isChildAgent)
  1934. return;
  1935. UUID[] animIDs;
  1936. int[] sequenceNums;
  1937. m_animations.GetArrays(out animIDs, out sequenceNums);
  1938. SendAnimPack(animIDs, sequenceNums);
  1939. }
  1940. #endregion
  1941. #region Significant Movement Method
  1942. /// <summary>
  1943. /// This checks for a significant movement and sends a courselocationchange update
  1944. /// </summary>
  1945. protected void CheckForSignificantMovement()
  1946. {
  1947. if (Util.GetDistanceTo(AbsolutePosition, posLastSignificantMove) > 0.5)
  1948. {
  1949. posLastSignificantMove = AbsolutePosition;
  1950. m_scene.EventManager.TriggerSignificantClientMovement(m_controllingClient);
  1951. m_scene.NotifyMyCoarseLocationChange();
  1952. }
  1953. // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m
  1954. if (Util.GetDistanceTo(AbsolutePosition,m_LastChildAgentUpdatePosition) > 32)
  1955. {
  1956. ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
  1957. cadu.ActiveGroupID = UUID.Zero.Guid;
  1958. cadu.AgentID = UUID.Guid;
  1959. cadu.alwaysrun = m_setAlwaysRun;
  1960. cadu.AVHeight = m_avHeight;
  1961. sLLVector3 tempCameraCenter = new sLLVector3(new Vector3(m_CameraCenter.X, m_CameraCenter.Y, m_CameraCenter.Z));
  1962. cadu.cameraPosition = tempCameraCenter;
  1963. cadu.drawdistance = m_DrawDistance;
  1964. cadu.godlevel = m_godlevel;
  1965. cadu.GroupAccess = 0;
  1966. cadu.Position = new sLLVector3(AbsolutePosition);
  1967. cadu.regionHandle = m_scene.RegionInfo.RegionHandle;
  1968. float multiplier = 1;
  1969. int innacurateNeighbors = m_scene.GetInaccurateNeighborCount();
  1970. if (innacurateNeighbors != 0)
  1971. {
  1972. multiplier = 1f / (float)innacurateNeighbors;
  1973. }
  1974. if (multiplier <= 0f)
  1975. {
  1976. multiplier = 0.25f;
  1977. }
  1978. //m_log.Info("[NeighborThrottle]: " + m_scene.GetInaccurateNeighborCount().ToString() + " - m: " + multiplier.ToString());
  1979. cadu.throttles = ControllingClient.GetThrottlesPacked(multiplier);
  1980. cadu.Velocity = new sLLVector3(Velocity);
  1981. AgentData agent = new AgentData();
  1982. agent.CopyFrom(cadu);
  1983. m_scene.SendOutChildAgentUpdates(agent, this);
  1984. m_LastChildAgentUpdatePosition.X = AbsolutePosition.X;
  1985. m_LastChildAgentUpdatePosition.Y = AbsolutePosition.Y;
  1986. m_LastChildAgentUpdatePosition.Z = AbsolutePosition.Z;
  1987. }
  1988. }
  1989. #endregion
  1990. #region Border Crossing Methods
  1991. /// <summary>
  1992. /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion
  1993. /// </summary>
  1994. protected void CheckForBorderCrossing()
  1995. {
  1996. if (IsChildAgent)
  1997. return;
  1998. Vector3 pos2 = AbsolutePosition;
  1999. Vector3 vel = Velocity;
  2000. float timeStep = 0.1f;
  2001. pos2.X = pos2.X + (vel.X*timeStep);
  2002. pos2.Y = pos2.Y + (vel.Y*timeStep);
  2003. pos2.Z = pos2.Z + (vel.Z*timeStep);
  2004. if ((pos2.X < 0) || (pos2.X > Constants.RegionSize))
  2005. {
  2006. CrossToNewRegion();
  2007. }
  2008. if ((pos2.Y < 0) || (pos2.Y > Constants.RegionSize))
  2009. {
  2010. CrossToNewRegion();
  2011. }
  2012. }
  2013. /// <summary>
  2014. /// Moves the agent outside the region bounds
  2015. /// Tells neighbor region that we're crossing to it
  2016. /// If the neighbor accepts, remove the agent's viewable avatar from this scene
  2017. /// set them to a child agent.
  2018. /// </summary>
  2019. protected void CrossToNewRegion()
  2020. {
  2021. Vector3 pos = AbsolutePosition;
  2022. Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
  2023. uint neighbourx = m_regionInfo.RegionLocX;
  2024. uint neighboury = m_regionInfo.RegionLocY;
  2025. // distance to edge that will trigger crossing
  2026. const float boundaryDistance = 1.7f;
  2027. // distance into new region to place avatar
  2028. const float enterDistance = 0.1f;
  2029. if (pos.X < boundaryDistance)
  2030. {
  2031. neighbourx--;
  2032. newpos.X = Constants.RegionSize - enterDistance;
  2033. }
  2034. else if (pos.X > Constants.RegionSize - boundaryDistance)
  2035. {
  2036. neighbourx++;
  2037. newpos.X = enterDistance;
  2038. }
  2039. if (pos.Y < boundaryDistance)
  2040. {
  2041. neighboury--;
  2042. newpos.Y = Constants.RegionSize - enterDistance;
  2043. }
  2044. else if (pos.Y > Constants.RegionSize - boundaryDistance)
  2045. {
  2046. neighboury++;
  2047. newpos.Y = enterDistance;
  2048. }
  2049. Vector3 vel = m_velocity;
  2050. ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
  2051. SimpleRegionInfo neighbourRegion = m_scene.RequestNeighbouringRegionInfo(neighbourHandle);
  2052. if (neighbourRegion != null && ValidateAttachments())
  2053. {
  2054. // When the neighbour is informed of the border crossing, it will set up CAPS handlers for the avatar
  2055. // This means we need to remove the current caps handler here and possibly compensate later,
  2056. // in case both scenes are being hosted on the same region server. Messy
  2057. //m_scene.RemoveCapsHandler(UUID);
  2058. newpos = newpos + (vel);
  2059. CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(UUID);
  2060. if (userInfo != null)
  2061. {
  2062. userInfo.DropInventory();
  2063. }
  2064. else
  2065. {
  2066. m_log.WarnFormat("[SCENE PRESENCE]: No cached user info found for {0} {1} on leaving region", Name, UUID);
  2067. }
  2068. bool crossingSuccessful =
  2069. m_scene.InformNeighbourOfCrossing(neighbourHandle, m_controllingClient.AgentId, newpos,
  2070. m_physicsActor.Flying);
  2071. if (crossingSuccessful)
  2072. {
  2073. // Next, let's close the child agent connections that are too far away.
  2074. CloseChildAgents(neighbourx, neighboury);
  2075. //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
  2076. m_controllingClient.RequestClientInfo();
  2077. //Console.WriteLine("BEFORE CROSS");
  2078. //Scene.DumpChildrenSeeds(UUID);
  2079. //DumpKnownRegions();
  2080. // TODO Should construct this behind a method
  2081. string capsPath =
  2082. "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort
  2083. + "/CAPS/" + m_knownChildRegions[neighbourRegion.RegionHandle] /*circuitdata.CapsPath*/ + "0000/";
  2084. m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, m_uuid);
  2085. IEventQueue eq = m_scene.RequestModuleInterface<IEventQueue>();
  2086. if (eq != null)
  2087. {
  2088. OSD Item = EventQueueHelper.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.ExternalEndPoint,
  2089. capsPath, UUID, ControllingClient.SessionId);
  2090. eq.Enqueue(Item, UUID);
  2091. }
  2092. else
  2093. {
  2094. m_controllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.ExternalEndPoint,
  2095. capsPath);
  2096. }
  2097. MakeChildAgent();
  2098. // now we have a child agent in this region. Request all interesting data about other (root) agents
  2099. SendInitialFullUpdateToAllClients();
  2100. CrossAttachmentsIntoNewRegion(neighbourHandle, true);
  2101. // m_scene.SendKillObject(m_localId);
  2102. m_scene.NotifyMyCoarseLocationChange();
  2103. // the user may change their profile information in other region,
  2104. // so the userinfo in UserProfileCache is not reliable any more, delete it
  2105. if (m_scene.NeedSceneCacheClear(UUID))
  2106. {
  2107. m_scene.CommsManager.UserProfileCacheService.RemoveUser(UUID);
  2108. m_log.InfoFormat("[AVATAR]: User {0} is going to another region, profile cache removed", UUID);
  2109. }
  2110. }
  2111. else
  2112. {
  2113. // Restore the user structures that we needed to delete before asking the receiving region to complete the crossing
  2114. m_scene.CommsManager.UserProfileCacheService.RequestInventoryForUser(UUID);
  2115. m_scene.AddCapsHandler(UUID);
  2116. }
  2117. }
  2118. //Console.WriteLine("AFTER CROSS");
  2119. //Scene.DumpChildrenSeeds(UUID);
  2120. //DumpKnownRegions();
  2121. }
  2122. /// <summary>
  2123. /// Computes which child agents to close when the scene presence moves to another region.
  2124. /// Removes those regions from m_knownRegions.
  2125. /// </summary>
  2126. /// <param name="newRegionX">The new region's x on the map</param>
  2127. /// <param name="newRegionY">The new region's y on the map</param>
  2128. /// <returns></returns>
  2129. public void CloseChildAgents(uint newRegionX, uint newRegionY)
  2130. {
  2131. List<ulong> byebyeRegions = new List<ulong>();
  2132. m_log.DebugFormat("[AVATAR]: Closing child agents. Checking {0} regions in {1}", m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName);
  2133. //DumpKnownRegions();
  2134. lock (m_knownChildRegions)
  2135. {
  2136. foreach (ulong handle in m_knownChildRegions.Keys)
  2137. {
  2138. // Don't close the agent on this region yet
  2139. if (handle != Scene.RegionInfo.RegionHandle)
  2140. {
  2141. uint x, y;
  2142. Utils.LongToUInts(handle, out x, out y);
  2143. x = x / Constants.RegionSize;
  2144. y = y / Constants.RegionSize;
  2145. //Console.WriteLine("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
  2146. //Console.WriteLine("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
  2147. if (Util.IsOutsideView(x, newRegionX, y, newRegionY))
  2148. {
  2149. byebyeRegions.Add(handle);
  2150. }
  2151. }
  2152. }
  2153. }
  2154. if (byebyeRegions.Count > 0)
  2155. {
  2156. m_log.Info("[AVATAR]: Closing " + byebyeRegions.Count + " child agents");
  2157. m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions);
  2158. }
  2159. foreach (ulong handle in byebyeRegions)
  2160. {
  2161. RemoveNeighbourRegion(handle);
  2162. }
  2163. }
  2164. #endregion
  2165. /// <summary>
  2166. /// This allows the Sim owner the abiility to kick users from their sim currently.
  2167. /// It tells the client that the agent has permission to do so.
  2168. /// </summary>
  2169. public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus)
  2170. {
  2171. if (godStatus)
  2172. {
  2173. // For now, assign god level 200 to anyone
  2174. // who is granted god powers, but has no god level set.
  2175. //
  2176. CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
  2177. if (profile.UserProfile.GodLevel > 0)
  2178. m_godlevel = profile.UserProfile.GodLevel;
  2179. else
  2180. m_godlevel = 200;
  2181. }
  2182. else
  2183. {
  2184. m_godlevel = 0;
  2185. }
  2186. ControllingClient.SendAdminResponse(token, (uint)m_godlevel);
  2187. }
  2188. /// <summary>
  2189. /// This updates important decision making data about a child agent
  2190. /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
  2191. /// </summary>
  2192. public void ChildAgentDataUpdate(AgentData cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY)
  2193. {
  2194. //
  2195. if (!IsChildAgent)
  2196. return;
  2197. int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize;
  2198. int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize;
  2199. m_DrawDistance = cAgentData.Far;
  2200. m_pos = new Vector3(cAgentData.Position.X + shiftx, cAgentData.Position.Y + shifty, cAgentData.Position.Z);
  2201. // 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
  2202. m_CameraCenter = cAgentData.Center;
  2203. // new Vector3(cAgentData.cameraPosition.x, cAgentData.cameraPosition.y, cAgentData.cameraPosition.z);
  2204. m_godlevel = cAgentData.GodLevel;
  2205. m_avHeight = cAgentData.Size.Z;
  2206. //SetHeight(cAgentData.AVHeight);
  2207. ControllingClient.SetChildAgentThrottle(cAgentData.Throttles);
  2208. // Sends out the objects in the user's draw distance if m_sendTasksToChild is true.
  2209. if (m_scene.m_seeIntoRegionFromNeighbor)
  2210. m_pendingObjects = null;
  2211. //cAgentData.AVHeight;
  2212. //cAgentData.regionHandle;
  2213. //m_velocity = cAgentData.Velocity;
  2214. }
  2215. /// <summary>
  2216. /// Handles part of the PID controller function for moving an avatar.
  2217. /// </summary>
  2218. public override void UpdateMovement()
  2219. {
  2220. m_newForce = false;
  2221. lock (m_forcesList)
  2222. {
  2223. if (m_forcesList.Count > 0)
  2224. {
  2225. for (int i = 0; i < m_forcesList.Count; i++)
  2226. {
  2227. NewForce force = m_forcesList[i];
  2228. m_updateflag = true;
  2229. try
  2230. {
  2231. movementvector.X = force.X;
  2232. movementvector.Y = force.Y;
  2233. movementvector.Z = force.Z;
  2234. Velocity = movementvector;
  2235. }
  2236. catch (NullReferenceException)
  2237. {
  2238. // Under extreme load, this returns a NullReference Exception that we can ignore.
  2239. // Ignoring this causes no movement to be sent to the physics engine...
  2240. // which when the scene is moving at 1 frame every 10 seconds, it doesn't really matter!
  2241. }
  2242. m_newForce = true;
  2243. }
  2244. for (int i = 0; i < m_forcesList.Count; i++)
  2245. {
  2246. m_forcesList.RemoveAt(0);
  2247. }
  2248. }
  2249. }
  2250. }
  2251. static ScenePresence()
  2252. {
  2253. Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
  2254. DefaultTexture = textu.ToBytes();
  2255. }
  2256. [Serializable]
  2257. public class NewForce
  2258. {
  2259. public float X;
  2260. public float Y;
  2261. public float Z;
  2262. public NewForce()
  2263. {
  2264. }
  2265. }
  2266. [Serializable]
  2267. public class ScenePartUpdate : ISerializable
  2268. {
  2269. public UUID FullID;
  2270. public uint LastFullUpdateTime;
  2271. public uint LastTerseUpdateTime;
  2272. public ScenePartUpdate()
  2273. {
  2274. FullID = UUID.Zero;
  2275. LastFullUpdateTime = 0;
  2276. LastTerseUpdateTime = 0;
  2277. }
  2278. protected ScenePartUpdate(SerializationInfo info, StreamingContext context)
  2279. {
  2280. //System.Console.WriteLine("ScenePartUpdate Deserialize BGN");
  2281. if (info == null)
  2282. {
  2283. throw new ArgumentNullException("info");
  2284. }
  2285. FullID = new UUID((Guid)info.GetValue("FullID", typeof(Guid)));
  2286. LastFullUpdateTime = (uint)info.GetValue("LastFullUpdateTime", typeof(uint));
  2287. LastTerseUpdateTime = (uint)info.GetValue("LastTerseUpdateTime", typeof(uint));
  2288. //System.Console.WriteLine("ScenePartUpdate Deserialize END");
  2289. }
  2290. [SecurityPermission(SecurityAction.LinkDemand,
  2291. Flags = SecurityPermissionFlag.SerializationFormatter)]
  2292. public virtual void GetObjectData(
  2293. SerializationInfo info, StreamingContext context)
  2294. {
  2295. if (info == null)
  2296. {
  2297. throw new ArgumentNullException("info");
  2298. }
  2299. info.AddValue("FullID", FullID.Guid);
  2300. info.AddValue("LastFullUpdateTime", LastFullUpdateTime);
  2301. info.AddValue("LastTerseUpdateTime", LastTerseUpdateTime);
  2302. }
  2303. }
  2304. public override void SetText(string text, Vector3 color, double alpha)
  2305. {
  2306. throw new Exception("Can't set Text on avatar.");
  2307. }
  2308. /// <summary>
  2309. /// Adds a physical representation of the avatar to the Physics plugin
  2310. /// </summary>
  2311. public void AddToPhysicalScene()
  2312. {
  2313. PhysicsScene scene = m_scene.PhysicsScene;
  2314. PhysicsVector pVec =
  2315. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  2316. AbsolutePosition.Z);
  2317. if (m_avHeight == 127.0f)
  2318. {
  2319. m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, 1.56f));
  2320. }
  2321. else
  2322. {
  2323. m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, m_avHeight));
  2324. }
  2325. //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
  2326. m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
  2327. m_physicsActor.SubscribeEvents(1000);
  2328. m_physicsActor.LocalID = LocalId;
  2329. }
  2330. // Event called by the physics plugin to tell the avatar about a collision.
  2331. private void PhysicsCollisionUpdate(EventArgs e)
  2332. {
  2333. if (e == null)
  2334. return;
  2335. CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
  2336. Dictionary<uint, float> coldata = collisionData.m_objCollisionList;
  2337. float starthealth = Health;
  2338. uint killerObj = 0;
  2339. foreach (uint localid in coldata.Keys)
  2340. {
  2341. if (coldata[localid] <= 0.10f || m_invulnerable)
  2342. continue;
  2343. //if (localid == 0)
  2344. //continue;
  2345. Health -= coldata[localid] * 5;
  2346. if (Health <= 0)
  2347. {
  2348. if (localid != 0)
  2349. killerObj = localid;
  2350. }
  2351. //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString());
  2352. }
  2353. //Health = 100;
  2354. if (!m_invulnerable)
  2355. {
  2356. if (starthealth != Health)
  2357. {
  2358. ControllingClient.SendHealth(Health);
  2359. }
  2360. if (m_health <= 0)
  2361. m_scene.EventManager.TriggerAvatarKill(killerObj, this);
  2362. }
  2363. if (Velocity.X > 0 || Velocity.Y > 0)
  2364. UpdateMovementAnimations();
  2365. }
  2366. public void setHealthWithUpdate(float health)
  2367. {
  2368. Health = health;
  2369. ControllingClient.SendHealth(Health);
  2370. }
  2371. public void Close()
  2372. {
  2373. lock (m_attachments)
  2374. {
  2375. // Delete attachments from scene
  2376. // Don't try to save, as this thread won't live long
  2377. // enough to complete the save. This would cause no copy
  2378. // attachments to poof!
  2379. //
  2380. foreach (SceneObjectGroup grp in m_attachments)
  2381. {
  2382. m_scene.DeleteSceneObject(grp, false);
  2383. }
  2384. m_attachments.Clear();
  2385. }
  2386. lock (m_knownChildRegions)
  2387. {
  2388. m_knownChildRegions.Clear();
  2389. }
  2390. lock (m_updateTimes)
  2391. {
  2392. m_updateTimes.Clear();
  2393. }
  2394. lock (m_partsUpdateQueue)
  2395. {
  2396. m_partsUpdateQueue.Clear();
  2397. }
  2398. RemoveFromPhysicalScene();
  2399. GC.Collect();
  2400. }
  2401. public ScenePresence()
  2402. {
  2403. /* JB
  2404. if (Animations == null)
  2405. {
  2406. Animations = new AvatarAnimations();
  2407. Animations.LoadAnims();
  2408. }
  2409. */
  2410. if (DefaultTexture == null)
  2411. {
  2412. Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
  2413. DefaultTexture = textu.ToBytes();
  2414. }
  2415. }
  2416. public void AddAttachment(SceneObjectGroup gobj)
  2417. {
  2418. lock (m_attachments)
  2419. {
  2420. m_attachments.Add(gobj);
  2421. }
  2422. }
  2423. public bool HasAttachments()
  2424. {
  2425. return m_attachments.Count > 0;
  2426. }
  2427. public bool HasScriptedAttachments()
  2428. {
  2429. lock (m_attachments)
  2430. {
  2431. foreach (SceneObjectGroup gobj in m_attachments)
  2432. {
  2433. if (gobj != null)
  2434. {
  2435. if (gobj.RootPart.Inventory.ContainsScripts())
  2436. return true;
  2437. }
  2438. }
  2439. }
  2440. return false;
  2441. }
  2442. public void RemoveAttachment(SceneObjectGroup gobj)
  2443. {
  2444. lock (m_attachments)
  2445. {
  2446. if (m_attachments.Contains(gobj))
  2447. {
  2448. m_attachments.Remove(gobj);
  2449. }
  2450. }
  2451. }
  2452. public bool ValidateAttachments()
  2453. {
  2454. lock (m_attachments)
  2455. {
  2456. // Validate
  2457. foreach (SceneObjectGroup gobj in m_attachments)
  2458. {
  2459. if (gobj == null)
  2460. return false;
  2461. if (gobj.IsDeleted)
  2462. return false;
  2463. }
  2464. }
  2465. return true;
  2466. }
  2467. public bool CrossAttachmentsIntoNewRegion(ulong regionHandle, bool silent)
  2468. {
  2469. lock (m_attachments)
  2470. {
  2471. // Validate
  2472. foreach (SceneObjectGroup gobj in m_attachments)
  2473. {
  2474. if (gobj == null || gobj.IsDeleted)
  2475. return false;
  2476. }
  2477. foreach (SceneObjectGroup gobj in m_attachments)
  2478. {
  2479. // If the prim group is null then something must have happened to it!
  2480. if (gobj != null && gobj.RootPart != null)
  2481. {
  2482. // Set the parent localID to 0 so it transfers over properly.
  2483. gobj.RootPart.SetParentLocalId(0);
  2484. gobj.RootPart.IsAttachment = false;
  2485. gobj.AbsolutePosition = gobj.RootPart.AttachedPos;
  2486. gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
  2487. m_log.DebugFormat("[ATTACHMENT]: Sending attachment {0} to region {1}", gobj.UUID, regionHandle);
  2488. m_scene.CrossPrimGroupIntoNewRegion(regionHandle, gobj, silent);
  2489. }
  2490. }
  2491. m_attachments.Clear();
  2492. return true;
  2493. }
  2494. }
  2495. public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene)
  2496. {
  2497. m_controllingClient = client;
  2498. m_regionInfo = region;
  2499. m_scene = scene;
  2500. RegisterToEvents();
  2501. /*
  2502. AbsolutePosition = client.StartPos;
  2503. Animations = new AvatarAnimations();
  2504. Animations.LoadAnims();
  2505. m_animations = new List<UUID>();
  2506. m_animations.Add(Animations.AnimsUUID["STAND"]);
  2507. m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber);
  2508. SetDirectionVectors();
  2509. */
  2510. }
  2511. protected ScenePresence(SerializationInfo info, StreamingContext context)
  2512. : base (info, context)
  2513. {
  2514. //System.Console.WriteLine("ScenePresence Deserialize BGN");
  2515. if (info == null)
  2516. {
  2517. throw new ArgumentNullException("info");
  2518. }
  2519. /* JB
  2520. if (Animations == null)
  2521. {
  2522. Animations = new AvatarAnimations();
  2523. Animations.LoadAnims();
  2524. }
  2525. */
  2526. if (DefaultTexture == null)
  2527. {
  2528. Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
  2529. DefaultTexture = textu.ToBytes();
  2530. }
  2531. m_animations = (AnimationSet)info.GetValue("m_animations", typeof(AnimationSet));
  2532. m_updateflag = (bool)info.GetValue("m_updateflag", typeof(bool));
  2533. m_movementflag = (byte)info.GetValue("m_movementflag", typeof(byte));
  2534. m_forcesList = (List<NewForce>)info.GetValue("m_forcesList", typeof(List<NewForce>));
  2535. m_updateCount = (short)info.GetValue("m_updateCount", typeof(short));
  2536. m_requestedSitTargetID = (uint)info.GetValue("m_requestedSitTargetID", typeof(uint));
  2537. m_requestedSitOffset
  2538. = new Vector3(
  2539. (float)info.GetValue("m_requestedSitOffset.X", typeof(float)),
  2540. (float)info.GetValue("m_requestedSitOffset.Y", typeof(float)),
  2541. (float)info.GetValue("m_requestedSitOffset.Z", typeof(float)));
  2542. m_sitAvatarHeight = (float)info.GetValue("m_sitAvatarHeight", typeof(float));
  2543. m_godlevel = (float)info.GetValue("m_godlevel", typeof(float));
  2544. m_setAlwaysRun = (bool)info.GetValue("m_setAlwaysRun", typeof(bool));
  2545. m_bodyRot
  2546. = new Quaternion(
  2547. (float)info.GetValue("m_bodyRot.X", typeof(float)),
  2548. (float)info.GetValue("m_bodyRot.Y", typeof(float)),
  2549. (float)info.GetValue("m_bodyRot.Z", typeof(float)),
  2550. (float)info.GetValue("m_bodyRot.W", typeof(float)));
  2551. IsRestrictedToRegion = (bool)info.GetValue("IsRestrictedToRegion", typeof(bool));
  2552. m_newForce = (bool)info.GetValue("m_newForce", typeof(bool));
  2553. //m_newAvatar = (bool)info.GetValue("m_newAvatar", typeof(bool));
  2554. m_newCoarseLocations = (bool)info.GetValue("m_newCoarseLocations", typeof(bool));
  2555. m_avHeight = (float)info.GetValue("m_avHeight", typeof(float));
  2556. crossingFromRegion = (ulong)info.GetValue("crossingFromRegion", typeof(ulong));
  2557. List<float[]> Dir_Vectors_work = (List<float[]>)info.GetValue("Dir_Vectors", typeof(List<float[]>));
  2558. List<Vector3> Dir_Vectors_work2 = new List<Vector3>();
  2559. foreach (float[] f3 in Dir_Vectors_work)
  2560. {
  2561. Dir_Vectors_work2.Add(new Vector3(f3[0], f3[1], f3[2]));
  2562. }
  2563. Dir_Vectors = Dir_Vectors_work2.ToArray();
  2564. lastPhysPos
  2565. = new Vector3(
  2566. (float)info.GetValue("lastPhysPos.X", typeof(float)),
  2567. (float)info.GetValue("lastPhysPos.Y", typeof(float)),
  2568. (float)info.GetValue("lastPhysPos.Z", typeof(float)));
  2569. // Possibly we should store lastPhysRot. But there may well be not much point since rotation changes
  2570. // wouldn't carry us across borders anyway
  2571. m_CameraCenter
  2572. = new Vector3(
  2573. (float)info.GetValue("m_CameraCenter.X", typeof(float)),
  2574. (float)info.GetValue("m_CameraCenter.Y", typeof(float)),
  2575. (float)info.GetValue("m_CameraCenter.Z", typeof(float)));
  2576. m_CameraAtAxis
  2577. = new Vector3(
  2578. (float)info.GetValue("m_CameraAtAxis.X", typeof(float)),
  2579. (float)info.GetValue("m_CameraAtAxis.Y", typeof(float)),
  2580. (float)info.GetValue("m_CameraAtAxis.Z", typeof(float)));
  2581. m_CameraLeftAxis
  2582. = new Vector3(
  2583. (float)info.GetValue("m_CameraLeftAxis.X", typeof(float)),
  2584. (float)info.GetValue("m_CameraLeftAxis.Y", typeof(float)),
  2585. (float)info.GetValue("m_CameraLeftAxis.Z", typeof(float)));
  2586. m_CameraUpAxis
  2587. = new Vector3(
  2588. (float)info.GetValue("m_CameraUpAxis.X", typeof(float)),
  2589. (float)info.GetValue("m_CameraUpAxis.Y", typeof(float)),
  2590. (float)info.GetValue("m_CameraUpAxis.Z", typeof(float)));
  2591. m_DrawDistance = (float)info.GetValue("m_DrawDistance", typeof(float));
  2592. m_appearance = (AvatarAppearance)info.GetValue("m_appearance", typeof(AvatarAppearance));
  2593. m_knownChildRegions = (Dictionary<ulong, string>)info.GetValue("m_knownChildRegions", typeof(Dictionary<ulong, string>));
  2594. posLastSignificantMove
  2595. = new Vector3(
  2596. (float)info.GetValue("posLastSignificantMove.X", typeof(float)),
  2597. (float)info.GetValue("posLastSignificantMove.Y", typeof(float)),
  2598. (float)info.GetValue("posLastSignificantMove.Z", typeof(float)));
  2599. // m_partsUpdateQueue = (UpdateQueue)info.GetValue("m_partsUpdateQueue", typeof(UpdateQueue));
  2600. /*
  2601. Dictionary<Guid, ScenePartUpdate> updateTimes_work
  2602. = (Dictionary<Guid, ScenePartUpdate>)info.GetValue("m_updateTimes", typeof(Dictionary<Guid, ScenePartUpdate>));
  2603. foreach (Guid id in updateTimes_work.Keys)
  2604. {
  2605. m_updateTimes.Add(new UUID(id), updateTimes_work[id]);
  2606. }
  2607. */
  2608. m_regionHandle = (ulong)info.GetValue("m_regionHandle", typeof(ulong));
  2609. m_firstname = (string)info.GetValue("m_firstname", typeof(string));
  2610. m_lastname = (string)info.GetValue("m_lastname", typeof(string));
  2611. m_allowMovement = (bool)info.GetValue("m_allowMovement", typeof(bool));
  2612. m_parentPosition = new Vector3((float)info.GetValue("m_parentPosition.X", typeof(float)),
  2613. (float)info.GetValue("m_parentPosition.Y", typeof(float)),
  2614. (float)info.GetValue("m_parentPosition.Z", typeof(float)));
  2615. m_isChildAgent = (bool)info.GetValue("m_isChildAgent", typeof(bool));
  2616. m_parentID = (uint)info.GetValue("m_parentID", typeof(uint));
  2617. // for OpenSim_v0.5
  2618. currentParcelUUID = new UUID((Guid)info.GetValue("currentParcelUUID", typeof(Guid)));
  2619. lastKnownAllowedPosition
  2620. = new Vector3(
  2621. (float)info.GetValue("lastKnownAllowedPosition.X", typeof(float)),
  2622. (float)info.GetValue("lastKnownAllowedPosition.Y", typeof(float)),
  2623. (float)info.GetValue("lastKnownAllowedPosition.Z", typeof(float)));
  2624. sentMessageAboutRestrictedParcelFlyingDown = (bool)info.GetValue("sentMessageAboutRestrictedParcelFlyingDown", typeof(bool));
  2625. m_LastChildAgentUpdatePosition
  2626. = new Vector3(
  2627. (float)info.GetValue("m_LastChildAgentUpdatePosition.X", typeof(float)),
  2628. (float)info.GetValue("m_LastChildAgentUpdatePosition.Y", typeof(float)),
  2629. (float)info.GetValue("m_LastChildAgentUpdatePosition.Z", typeof(float)));
  2630. m_perfMonMS = (int)info.GetValue("m_perfMonMS", typeof(int));
  2631. m_AgentControlFlags = (uint)info.GetValue("m_AgentControlFlags", typeof(uint));
  2632. m_headrotation
  2633. = new Quaternion(
  2634. (float)info.GetValue("m_headrotation.X", typeof(float)),
  2635. (float)info.GetValue("m_headrotation.Y", typeof(float)),
  2636. (float)info.GetValue("m_headrotation.Z", typeof(float)),
  2637. (float)info.GetValue("m_headrotation.W", typeof(float)));
  2638. m_state = (byte)info.GetValue("m_state", typeof(byte));
  2639. //System.Console.WriteLine("ScenePresence Deserialize END");
  2640. }
  2641. [SecurityPermission(SecurityAction.LinkDemand,
  2642. Flags = SecurityPermissionFlag.SerializationFormatter)]
  2643. public override void GetObjectData(
  2644. SerializationInfo info, StreamingContext context)
  2645. {
  2646. if (info == null)
  2647. {
  2648. throw new ArgumentNullException("info");
  2649. }
  2650. base.GetObjectData(info, context);
  2651. info.AddValue("m_animations", m_animations);
  2652. info.AddValue("m_updateflag", m_updateflag);
  2653. info.AddValue("m_movementflag", m_movementflag);
  2654. info.AddValue("m_forcesList", m_forcesList);
  2655. info.AddValue("m_updateCount", m_updateCount);
  2656. info.AddValue("m_requestedSitTargetID", m_requestedSitTargetID);
  2657. // Vector3
  2658. info.AddValue("m_requestedSitOffset.X", m_requestedSitOffset.X);
  2659. info.AddValue("m_requestedSitOffset.Y", m_requestedSitOffset.Y);
  2660. info.AddValue("m_requestedSitOffset.Z", m_requestedSitOffset.Z);
  2661. info.AddValue("m_sitAvatarHeight", m_sitAvatarHeight);
  2662. info.AddValue("m_godlevel", m_godlevel);
  2663. info.AddValue("m_setAlwaysRun", m_setAlwaysRun);
  2664. // Quaternion
  2665. info.AddValue("m_bodyRot.X", m_bodyRot.X);
  2666. info.AddValue("m_bodyRot.Y", m_bodyRot.Y);
  2667. info.AddValue("m_bodyRot.Z", m_bodyRot.Z);
  2668. info.AddValue("m_bodyRot.W", m_bodyRot.W);
  2669. info.AddValue("IsRestrictedToRegion", IsRestrictedToRegion);
  2670. info.AddValue("m_newForce", m_newForce);
  2671. //info.AddValue("m_newAvatar", m_newAvatar);
  2672. info.AddValue("m_newCoarseLocations", m_newCoarseLocations);
  2673. info.AddValue("m_gotAPrimitivesInScene", false);
  2674. info.AddValue("m_avHeight", m_avHeight);
  2675. // info.AddValue("m_regionInfo", m_regionInfo);
  2676. info.AddValue("crossingFromRegion", crossingFromRegion);
  2677. List<float[]> Dir_Vectors_work = new List<float[]>();
  2678. foreach (Vector3 v3 in Dir_Vectors)
  2679. {
  2680. Dir_Vectors_work.Add(new float[] { v3.X, v3.Y, v3.Z });
  2681. }
  2682. info.AddValue("Dir_Vectors", Dir_Vectors_work);
  2683. // Vector3
  2684. info.AddValue("lastPhysPos.X", lastPhysPos.X);
  2685. info.AddValue("lastPhysPos.Y", lastPhysPos.Y);
  2686. info.AddValue("lastPhysPos.Z", lastPhysPos.Z);
  2687. // Possibly we should retrieve lastPhysRot. But there may well be not much point since rotation changes
  2688. // wouldn't carry us across borders anyway
  2689. // Vector3
  2690. info.AddValue("m_CameraCenter.X", m_CameraCenter.X);
  2691. info.AddValue("m_CameraCenter.Y", m_CameraCenter.Y);
  2692. info.AddValue("m_CameraCenter.Z", m_CameraCenter.Z);
  2693. // Vector3
  2694. info.AddValue("m_CameraAtAxis.X", m_CameraAtAxis.X);
  2695. info.AddValue("m_CameraAtAxis.Y", m_CameraAtAxis.Y);
  2696. info.AddValue("m_CameraAtAxis.Z", m_CameraAtAxis.Z);
  2697. // Vector3
  2698. info.AddValue("m_CameraLeftAxis.X", m_CameraLeftAxis.X);
  2699. info.AddValue("m_CameraLeftAxis.Y", m_CameraLeftAxis.Y);
  2700. info.AddValue("m_CameraLeftAxis.Z", m_CameraLeftAxis.Z);
  2701. // Vector3
  2702. info.AddValue("m_CameraUpAxis.X", m_CameraUpAxis.X);
  2703. info.AddValue("m_CameraUpAxis.Y", m_CameraUpAxis.Y);
  2704. info.AddValue("m_CameraUpAxis.Z", m_CameraUpAxis.Z);
  2705. info.AddValue("m_DrawDistance", m_DrawDistance);
  2706. info.AddValue("m_appearance", m_appearance);
  2707. info.AddValue("m_knownChildRegions", m_knownChildRegions);
  2708. // Vector3
  2709. info.AddValue("posLastSignificantMove.X", posLastSignificantMove.X);
  2710. info.AddValue("posLastSignificantMove.Y", posLastSignificantMove.Y);
  2711. info.AddValue("posLastSignificantMove.Z", posLastSignificantMove.Z);
  2712. //info.AddValue("m_partsUpdateQueue", m_partsUpdateQueue);
  2713. /*
  2714. Dictionary<Guid, ScenePartUpdate> updateTimes_work = new Dictionary<Guid, ScenePartUpdate>();
  2715. foreach (UUID id in m_updateTimes.Keys)
  2716. {
  2717. updateTimes_work.Add(id.UUID, m_updateTimes[id]);
  2718. }
  2719. info.AddValue("m_updateTimes", updateTimes_work);
  2720. */
  2721. info.AddValue("m_regionHandle", m_regionHandle);
  2722. info.AddValue("m_firstname", m_firstname);
  2723. info.AddValue("m_lastname", m_lastname);
  2724. info.AddValue("m_allowMovement", m_allowMovement);
  2725. //info.AddValue("m_physicsActor", m_physicsActor);
  2726. info.AddValue("m_parentPosition.X", m_parentPosition.X);
  2727. info.AddValue("m_parentPosition.Y", m_parentPosition.Y);
  2728. info.AddValue("m_parentPosition.Z", m_parentPosition.Z);
  2729. info.AddValue("m_isChildAgent", m_isChildAgent);
  2730. info.AddValue("m_parentID", m_parentID);
  2731. // for OpenSim_v0.5
  2732. info.AddValue("currentParcelUUID", currentParcelUUID.Guid);
  2733. info.AddValue("lastKnownAllowedPosition.X", lastKnownAllowedPosition.X);
  2734. info.AddValue("lastKnownAllowedPosition.Y", lastKnownAllowedPosition.Y);
  2735. info.AddValue("lastKnownAllowedPosition.Z", lastKnownAllowedPosition.Z);
  2736. info.AddValue("sentMessageAboutRestrictedParcelFlyingDown", sentMessageAboutRestrictedParcelFlyingDown);
  2737. info.AddValue("m_LastChildAgentUpdatePosition.X", m_LastChildAgentUpdatePosition.X);
  2738. info.AddValue("m_LastChildAgentUpdatePosition.Y", m_LastChildAgentUpdatePosition.Y);
  2739. info.AddValue("m_LastChildAgentUpdatePosition.Z", m_LastChildAgentUpdatePosition.Z);
  2740. info.AddValue("m_perfMonMS", m_perfMonMS);
  2741. info.AddValue("m_AgentControlFlags", m_AgentControlFlags);
  2742. info.AddValue("m_headrotation.W", m_headrotation.W);
  2743. info.AddValue("m_headrotation.X", m_headrotation.X);
  2744. info.AddValue("m_headrotation.Y", m_headrotation.Y);
  2745. info.AddValue("m_headrotation.Z", m_headrotation.Z);
  2746. info.AddValue("m_state", m_state);
  2747. List<Guid> knownPrimUUID_work = new List<Guid>();
  2748. info.AddValue("m_knownPrimUUID", knownPrimUUID_work);
  2749. }
  2750. internal void PushForce(PhysicsVector impulse)
  2751. {
  2752. if (PhysicsActor != null)
  2753. {
  2754. PhysicsActor.AddForce(impulse,true);
  2755. }
  2756. }
  2757. public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
  2758. {
  2759. ScriptControllers obj = new ScriptControllers();
  2760. obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
  2761. obj.eventControls = ScriptControlled.CONTROL_ZERO;
  2762. obj.itemID = Script_item_UUID;
  2763. obj.objID = Obj_localID;
  2764. if (pass_on == 0 && accept == 0)
  2765. {
  2766. IgnoredControls |= (ScriptControlled)controls;
  2767. obj.ignoreControls = (ScriptControlled)controls;
  2768. }
  2769. if (pass_on == 0 && accept == 1)
  2770. {
  2771. IgnoredControls |= (ScriptControlled)controls;
  2772. obj.ignoreControls = (ScriptControlled)controls;
  2773. obj.eventControls = (ScriptControlled)controls;
  2774. }
  2775. if (pass_on == 1 && accept == 1)
  2776. {
  2777. IgnoredControls = ScriptControlled.CONTROL_ZERO;
  2778. obj.eventControls = (ScriptControlled)controls;
  2779. obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
  2780. }
  2781. lock (scriptedcontrols)
  2782. {
  2783. if (pass_on == 1 && accept == 0)
  2784. {
  2785. IgnoredControls &= ~(ScriptControlled)controls;
  2786. if (scriptedcontrols.ContainsKey(Script_item_UUID))
  2787. scriptedcontrols.Remove(Script_item_UUID);
  2788. }
  2789. else
  2790. {
  2791. if (scriptedcontrols.ContainsKey(Script_item_UUID))
  2792. {
  2793. scriptedcontrols[Script_item_UUID] = obj;
  2794. }
  2795. else
  2796. {
  2797. scriptedcontrols.Add(Script_item_UUID, obj);
  2798. }
  2799. }
  2800. }
  2801. ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true);
  2802. }
  2803. public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID)
  2804. {
  2805. IgnoredControls = ScriptControlled.CONTROL_ZERO;
  2806. lock (scriptedcontrols)
  2807. {
  2808. scriptedcontrols.Clear();
  2809. }
  2810. ControllingClient.SendTakeControls(int.MaxValue, false, false);
  2811. }
  2812. public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
  2813. {
  2814. lock (scriptedcontrols)
  2815. {
  2816. if (scriptedcontrols.ContainsKey(Script_item_UUID))
  2817. {
  2818. ScriptControllers takecontrolls = scriptedcontrols[Script_item_UUID];
  2819. ScriptControlled sctc = takecontrolls.eventControls;
  2820. ControllingClient.SendTakeControls((int)sctc, false, false);
  2821. ControllingClient.SendTakeControls((int)sctc, true, false);
  2822. scriptedcontrols.Remove(Script_item_UUID);
  2823. IgnoredControls = ScriptControlled.CONTROL_ZERO;
  2824. foreach (ScriptControllers scData in scriptedcontrols.Values)
  2825. {
  2826. IgnoredControls |= scData.ignoreControls;
  2827. }
  2828. }
  2829. }
  2830. }
  2831. internal void SendControlToScripts(uint flags)
  2832. {
  2833. ScriptControlled allflags = ScriptControlled.CONTROL_ZERO;
  2834. if (MouseDown)
  2835. {
  2836. allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON);
  2837. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0)
  2838. {
  2839. allflags = ScriptControlled.CONTROL_ZERO;
  2840. MouseDown = true;
  2841. }
  2842. }
  2843. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0)
  2844. {
  2845. allflags |= ScriptControlled.CONTROL_ML_LBUTTON;
  2846. MouseDown = true;
  2847. }
  2848. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0)
  2849. {
  2850. allflags |= ScriptControlled.CONTROL_LBUTTON;
  2851. MouseDown = true;
  2852. }
  2853. // find all activated controls, whether the scripts are interested in them or not
  2854. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0)
  2855. {
  2856. allflags |= ScriptControlled.CONTROL_FWD;
  2857. }
  2858. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0)
  2859. {
  2860. allflags |= ScriptControlled.CONTROL_BACK;
  2861. }
  2862. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0)
  2863. {
  2864. allflags |= ScriptControlled.CONTROL_UP;
  2865. }
  2866. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)
  2867. {
  2868. allflags |= ScriptControlled.CONTROL_DOWN;
  2869. }
  2870. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0)
  2871. {
  2872. allflags |= ScriptControlled.CONTROL_LEFT;
  2873. }
  2874. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0)
  2875. {
  2876. allflags |= ScriptControlled.CONTROL_RIGHT;
  2877. }
  2878. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
  2879. {
  2880. allflags |= ScriptControlled.CONTROL_ROT_RIGHT;
  2881. }
  2882. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
  2883. {
  2884. allflags |= ScriptControlled.CONTROL_ROT_LEFT;
  2885. }
  2886. // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that
  2887. if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands)
  2888. {
  2889. lock (scriptedcontrols)
  2890. {
  2891. foreach (UUID scriptUUID in scriptedcontrols.Keys)
  2892. {
  2893. ScriptControllers scriptControlData = scriptedcontrols[scriptUUID];
  2894. ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us
  2895. ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle
  2896. ScriptControlled localChange = localHeld ^ localLast; // the changed bits
  2897. if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO)
  2898. {
  2899. // only send if still pressed or just changed
  2900. m_scene.EventManager.TriggerControlEvent(scriptControlData.objID, scriptUUID, UUID, (uint)localHeld, (uint)localChange);
  2901. }
  2902. }
  2903. }
  2904. }
  2905. LastCommands = allflags;
  2906. }
  2907. internal uint RemoveIgnoredControls(uint flags, ScriptControlled Ignored)
  2908. {
  2909. if (Ignored == ScriptControlled.CONTROL_ZERO)
  2910. return flags;
  2911. if ((Ignored & ScriptControlled.CONTROL_BACK) != 0)
  2912. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG);
  2913. if ((Ignored & ScriptControlled.CONTROL_FWD) != 0)
  2914. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS);
  2915. if ((Ignored & ScriptControlled.CONTROL_DOWN) != 0)
  2916. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG);
  2917. if ((Ignored & ScriptControlled.CONTROL_UP) != 0)
  2918. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS);
  2919. if ((Ignored & ScriptControlled.CONTROL_LEFT) != 0)
  2920. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS);
  2921. if ((Ignored & ScriptControlled.CONTROL_RIGHT) != 0)
  2922. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG);
  2923. if ((Ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0)
  2924. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG);
  2925. if ((Ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0)
  2926. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS);
  2927. if ((Ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0)
  2928. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN);
  2929. if ((Ignored & ScriptControlled.CONTROL_LBUTTON) != 0)
  2930. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN);
  2931. //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS,
  2932. //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG,
  2933. //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS,
  2934. //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG,
  2935. //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
  2936. //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
  2937. //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
  2938. return flags;
  2939. }
  2940. private void ItemReceived(UUID itemID)
  2941. {
  2942. if (IsChildAgent)
  2943. return;
  2944. if (null == m_appearance)
  2945. {
  2946. m_log.Warn("[ATTACHMENT] Appearance has not been initialized");
  2947. return;
  2948. }
  2949. int attachpoint = m_appearance.GetAttachpoint(itemID);
  2950. if (attachpoint == 0)
  2951. return;
  2952. UUID asset = m_appearance.GetAttachedAsset(attachpoint);
  2953. if (UUID.Zero == asset) // We have just logged in
  2954. {
  2955. try
  2956. {
  2957. // Rez from inventory
  2958. asset = m_scene.RezSingleAttachment(ControllingClient,
  2959. itemID, (uint)attachpoint);
  2960. // Corner case: We are not yet a Scene Entity
  2961. // Setting attachment info in RezSingleAttachment will fail
  2962. // Set it here
  2963. //
  2964. m_appearance.SetAttachment((int)attachpoint, itemID,
  2965. asset);
  2966. m_log.InfoFormat("[ATTACHMENT] Rezzed attachment {0}, inworld asset {1}",
  2967. itemID.ToString(), asset);
  2968. }
  2969. catch (Exception e)
  2970. {
  2971. m_log.ErrorFormat("[ATTACHMENT] Unable to rez attachment: {0}", e.ToString());
  2972. }
  2973. return;
  2974. }
  2975. SceneObjectPart att = m_scene.GetSceneObjectPart(asset);
  2976. // If this is null, then the asset has not yet appeared in world
  2977. // so we revisit this when it does
  2978. //
  2979. if (att != null && att.UUID != asset) // Yes. It's really needed
  2980. {
  2981. m_log.DebugFormat("[ATTACHMENT]: Attach from in world: ItemID {0}, Asset ID {1}, Attachment inworld: {2}", itemID.ToString(), asset.ToString(), att.UUID.ToString());
  2982. // This will throw if crossing katty-korner
  2983. // So catch it here to avoid the noid
  2984. //
  2985. try
  2986. {
  2987. // Attach from world, if not already attached
  2988. if (att.ParentGroup != null && !att.IsAttachment)
  2989. m_scene.AttachObject(ControllingClient, att.ParentGroup.LocalId, (uint)0, Quaternion.Identity, att.ParentGroup.AbsolutePosition, false);
  2990. }
  2991. catch (NullReferenceException)
  2992. {
  2993. }
  2994. }
  2995. }
  2996. }
  2997. }