ScenePresence.cs 137 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522
  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. m_scene.SendOutChildAgentUpdates(cadu,this);
  1982. m_LastChildAgentUpdatePosition.X = AbsolutePosition.X;
  1983. m_LastChildAgentUpdatePosition.Y = AbsolutePosition.Y;
  1984. m_LastChildAgentUpdatePosition.Z = AbsolutePosition.Z;
  1985. }
  1986. }
  1987. #endregion
  1988. #region Border Crossing Methods
  1989. /// <summary>
  1990. /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion
  1991. /// </summary>
  1992. protected void CheckForBorderCrossing()
  1993. {
  1994. if (IsChildAgent)
  1995. return;
  1996. Vector3 pos2 = AbsolutePosition;
  1997. Vector3 vel = Velocity;
  1998. float timeStep = 0.1f;
  1999. pos2.X = pos2.X + (vel.X*timeStep);
  2000. pos2.Y = pos2.Y + (vel.Y*timeStep);
  2001. pos2.Z = pos2.Z + (vel.Z*timeStep);
  2002. if ((pos2.X < 0) || (pos2.X > Constants.RegionSize))
  2003. {
  2004. CrossToNewRegion();
  2005. }
  2006. if ((pos2.Y < 0) || (pos2.Y > Constants.RegionSize))
  2007. {
  2008. CrossToNewRegion();
  2009. }
  2010. }
  2011. /// <summary>
  2012. /// Moves the agent outside the region bounds
  2013. /// Tells neighbor region that we're crossing to it
  2014. /// If the neighbor accepts, remove the agent's viewable avatar from this scene
  2015. /// set them to a child agent.
  2016. /// </summary>
  2017. protected void CrossToNewRegion()
  2018. {
  2019. Vector3 pos = AbsolutePosition;
  2020. Vector3 newpos = new Vector3(pos.X, pos.Y, pos.Z);
  2021. uint neighbourx = m_regionInfo.RegionLocX;
  2022. uint neighboury = m_regionInfo.RegionLocY;
  2023. // distance to edge that will trigger crossing
  2024. const float boundaryDistance = 1.7f;
  2025. // distance into new region to place avatar
  2026. const float enterDistance = 0.1f;
  2027. if (pos.X < boundaryDistance)
  2028. {
  2029. neighbourx--;
  2030. newpos.X = Constants.RegionSize - enterDistance;
  2031. }
  2032. else if (pos.X > Constants.RegionSize - boundaryDistance)
  2033. {
  2034. neighbourx++;
  2035. newpos.X = enterDistance;
  2036. }
  2037. if (pos.Y < boundaryDistance)
  2038. {
  2039. neighboury--;
  2040. newpos.Y = Constants.RegionSize - enterDistance;
  2041. }
  2042. else if (pos.Y > Constants.RegionSize - boundaryDistance)
  2043. {
  2044. neighboury++;
  2045. newpos.Y = enterDistance;
  2046. }
  2047. Vector3 vel = m_velocity;
  2048. ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
  2049. SimpleRegionInfo neighbourRegion = m_scene.RequestNeighbouringRegionInfo(neighbourHandle);
  2050. if (neighbourRegion != null && ValidateAttachments())
  2051. {
  2052. // When the neighbour is informed of the border crossing, it will set up CAPS handlers for the avatar
  2053. // This means we need to remove the current caps handler here and possibly compensate later,
  2054. // in case both scenes are being hosted on the same region server. Messy
  2055. //m_scene.RemoveCapsHandler(UUID);
  2056. newpos = newpos + (vel);
  2057. CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(UUID);
  2058. if (userInfo != null)
  2059. {
  2060. userInfo.DropInventory();
  2061. }
  2062. else
  2063. {
  2064. m_log.WarnFormat("[SCENE PRESENCE]: No cached user info found for {0} {1} on leaving region", Name, UUID);
  2065. }
  2066. bool crossingSuccessful =
  2067. m_scene.InformNeighbourOfCrossing(neighbourHandle, m_controllingClient.AgentId, newpos,
  2068. m_physicsActor.Flying);
  2069. if (crossingSuccessful)
  2070. {
  2071. // Next, let's close the child agent connections that are too far away.
  2072. CloseChildAgents(neighbourx, neighboury);
  2073. //AgentCircuitData circuitdata = m_controllingClient.RequestClientInfo();
  2074. m_controllingClient.RequestClientInfo();
  2075. //Console.WriteLine("BEFORE CROSS");
  2076. //Scene.DumpChildrenSeeds(UUID);
  2077. //DumpKnownRegions();
  2078. // TODO Should construct this behind a method
  2079. string capsPath =
  2080. "http://" + neighbourRegion.ExternalHostName + ":" + neighbourRegion.HttpPort
  2081. + "/CAPS/" + m_knownChildRegions[neighbourRegion.RegionHandle] /*circuitdata.CapsPath*/ + "0000/";
  2082. m_log.DebugFormat("[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, m_uuid);
  2083. IEventQueue eq = m_scene.RequestModuleInterface<IEventQueue>();
  2084. if (eq != null)
  2085. {
  2086. OSD Item = EventQueueHelper.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.ExternalEndPoint,
  2087. capsPath, UUID, ControllingClient.SessionId);
  2088. eq.Enqueue(Item, UUID);
  2089. }
  2090. else
  2091. {
  2092. m_controllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.ExternalEndPoint,
  2093. capsPath);
  2094. }
  2095. MakeChildAgent();
  2096. // now we have a child agent in this region. Request all interesting data about other (root) agents
  2097. SendInitialFullUpdateToAllClients();
  2098. CrossAttachmentsIntoNewRegion(neighbourHandle, true);
  2099. // m_scene.SendKillObject(m_localId);
  2100. m_scene.NotifyMyCoarseLocationChange();
  2101. // the user may change their profile information in other region,
  2102. // so the userinfo in UserProfileCache is not reliable any more, delete it
  2103. if (m_scene.NeedSceneCacheClear(UUID))
  2104. {
  2105. m_scene.CommsManager.UserProfileCacheService.RemoveUser(UUID);
  2106. m_log.InfoFormat("[AVATAR]: User {0} is going to another region, profile cache removed", UUID);
  2107. }
  2108. }
  2109. else
  2110. {
  2111. // Restore the user structures that we needed to delete before asking the receiving region to complete the crossing
  2112. m_scene.CommsManager.UserProfileCacheService.RequestInventoryForUser(UUID);
  2113. m_scene.AddCapsHandler(UUID);
  2114. }
  2115. }
  2116. //Console.WriteLine("AFTER CROSS");
  2117. //Scene.DumpChildrenSeeds(UUID);
  2118. //DumpKnownRegions();
  2119. }
  2120. /// <summary>
  2121. /// Computes which child agents to close when the scene presence moves to another region.
  2122. /// Removes those regions from m_knownRegions.
  2123. /// </summary>
  2124. /// <param name="newRegionX">The new region's x on the map</param>
  2125. /// <param name="newRegionY">The new region's y on the map</param>
  2126. /// <returns></returns>
  2127. public void CloseChildAgents(uint newRegionX, uint newRegionY)
  2128. {
  2129. List<ulong> byebyeRegions = new List<ulong>();
  2130. m_log.DebugFormat("[AVATAR]: Closing child agents. Checking {0} regions in {1}", m_knownChildRegions.Keys.Count, Scene.RegionInfo.RegionName);
  2131. //DumpKnownRegions();
  2132. lock (m_knownChildRegions)
  2133. {
  2134. foreach (ulong handle in m_knownChildRegions.Keys)
  2135. {
  2136. // Don't close the agent on this region yet
  2137. if (handle != Scene.RegionInfo.RegionHandle)
  2138. {
  2139. uint x, y;
  2140. Utils.LongToUInts(handle, out x, out y);
  2141. x = x / Constants.RegionSize;
  2142. y = y / Constants.RegionSize;
  2143. //Console.WriteLine("---> x: " + x + "; newx:" + newRegionX + "; Abs:" + (int)Math.Abs((int)(x - newRegionX)));
  2144. //Console.WriteLine("---> y: " + y + "; newy:" + newRegionY + "; Abs:" + (int)Math.Abs((int)(y - newRegionY)));
  2145. if (Util.IsOutsideView(x, newRegionX, y, newRegionY))
  2146. {
  2147. byebyeRegions.Add(handle);
  2148. }
  2149. }
  2150. }
  2151. }
  2152. if (byebyeRegions.Count > 0)
  2153. {
  2154. m_log.Info("[AVATAR]: Closing " + byebyeRegions.Count + " child agents");
  2155. m_scene.SceneGridService.SendCloseChildAgentConnections(m_controllingClient.AgentId, byebyeRegions);
  2156. }
  2157. foreach (ulong handle in byebyeRegions)
  2158. {
  2159. RemoveNeighbourRegion(handle);
  2160. }
  2161. }
  2162. #endregion
  2163. /// <summary>
  2164. /// This allows the Sim owner the abiility to kick users from their sim currently.
  2165. /// It tells the client that the agent has permission to do so.
  2166. /// </summary>
  2167. public void GrantGodlikePowers(UUID agentID, UUID sessionID, UUID token, bool godStatus)
  2168. {
  2169. if (godStatus)
  2170. {
  2171. // For now, assign god level 200 to anyone
  2172. // who is granted god powers, but has no god level set.
  2173. //
  2174. CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
  2175. if (profile.UserProfile.GodLevel > 0)
  2176. m_godlevel = profile.UserProfile.GodLevel;
  2177. else
  2178. m_godlevel = 200;
  2179. }
  2180. else
  2181. {
  2182. m_godlevel = 0;
  2183. }
  2184. ControllingClient.SendAdminResponse(token, (uint)m_godlevel);
  2185. }
  2186. /// <summary>
  2187. /// This updates important decision making data about a child agent
  2188. /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
  2189. /// </summary>
  2190. public void ChildAgentDataUpdate(ChildAgentDataUpdate cAgentData, uint tRegionX, uint tRegionY, uint rRegionX, uint rRegionY)
  2191. {
  2192. //
  2193. if (!IsChildAgent)
  2194. return;
  2195. int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize;
  2196. int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize;
  2197. m_DrawDistance = cAgentData.drawdistance;
  2198. m_pos = new Vector3(cAgentData.Position.x + shiftx, cAgentData.Position.y + shifty, cAgentData.Position.z);
  2199. // 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
  2200. m_CameraCenter =
  2201. new Vector3(cAgentData.cameraPosition.x, cAgentData.cameraPosition.y, cAgentData.cameraPosition.z);
  2202. m_godlevel = cAgentData.godlevel;
  2203. m_avHeight = cAgentData.AVHeight;
  2204. //SetHeight(cAgentData.AVHeight);
  2205. ControllingClient.SetChildAgentThrottle(cAgentData.throttles);
  2206. // Sends out the objects in the user's draw distance if m_sendTasksToChild is true.
  2207. if (m_scene.m_seeIntoRegionFromNeighbor)
  2208. m_pendingObjects = null;
  2209. //cAgentData.AVHeight;
  2210. //cAgentData.regionHandle;
  2211. //m_velocity = cAgentData.Velocity;
  2212. }
  2213. /// <summary>
  2214. /// Handles part of the PID controller function for moving an avatar.
  2215. /// </summary>
  2216. public override void UpdateMovement()
  2217. {
  2218. m_newForce = false;
  2219. lock (m_forcesList)
  2220. {
  2221. if (m_forcesList.Count > 0)
  2222. {
  2223. for (int i = 0; i < m_forcesList.Count; i++)
  2224. {
  2225. NewForce force = m_forcesList[i];
  2226. m_updateflag = true;
  2227. try
  2228. {
  2229. movementvector.X = force.X;
  2230. movementvector.Y = force.Y;
  2231. movementvector.Z = force.Z;
  2232. Velocity = movementvector;
  2233. }
  2234. catch (NullReferenceException)
  2235. {
  2236. // Under extreme load, this returns a NullReference Exception that we can ignore.
  2237. // Ignoring this causes no movement to be sent to the physics engine...
  2238. // which when the scene is moving at 1 frame every 10 seconds, it doesn't really matter!
  2239. }
  2240. m_newForce = true;
  2241. }
  2242. for (int i = 0; i < m_forcesList.Count; i++)
  2243. {
  2244. m_forcesList.RemoveAt(0);
  2245. }
  2246. }
  2247. }
  2248. }
  2249. static ScenePresence()
  2250. {
  2251. Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
  2252. DefaultTexture = textu.ToBytes();
  2253. }
  2254. [Serializable]
  2255. public class NewForce
  2256. {
  2257. public float X;
  2258. public float Y;
  2259. public float Z;
  2260. public NewForce()
  2261. {
  2262. }
  2263. }
  2264. [Serializable]
  2265. public class ScenePartUpdate : ISerializable
  2266. {
  2267. public UUID FullID;
  2268. public uint LastFullUpdateTime;
  2269. public uint LastTerseUpdateTime;
  2270. public ScenePartUpdate()
  2271. {
  2272. FullID = UUID.Zero;
  2273. LastFullUpdateTime = 0;
  2274. LastTerseUpdateTime = 0;
  2275. }
  2276. protected ScenePartUpdate(SerializationInfo info, StreamingContext context)
  2277. {
  2278. //System.Console.WriteLine("ScenePartUpdate Deserialize BGN");
  2279. if (info == null)
  2280. {
  2281. throw new ArgumentNullException("info");
  2282. }
  2283. FullID = new UUID((Guid)info.GetValue("FullID", typeof(Guid)));
  2284. LastFullUpdateTime = (uint)info.GetValue("LastFullUpdateTime", typeof(uint));
  2285. LastTerseUpdateTime = (uint)info.GetValue("LastTerseUpdateTime", typeof(uint));
  2286. //System.Console.WriteLine("ScenePartUpdate Deserialize END");
  2287. }
  2288. [SecurityPermission(SecurityAction.LinkDemand,
  2289. Flags = SecurityPermissionFlag.SerializationFormatter)]
  2290. public virtual void GetObjectData(
  2291. SerializationInfo info, StreamingContext context)
  2292. {
  2293. if (info == null)
  2294. {
  2295. throw new ArgumentNullException("info");
  2296. }
  2297. info.AddValue("FullID", FullID.Guid);
  2298. info.AddValue("LastFullUpdateTime", LastFullUpdateTime);
  2299. info.AddValue("LastTerseUpdateTime", LastTerseUpdateTime);
  2300. }
  2301. }
  2302. public override void SetText(string text, Vector3 color, double alpha)
  2303. {
  2304. throw new Exception("Can't set Text on avatar.");
  2305. }
  2306. /// <summary>
  2307. /// Adds a physical representation of the avatar to the Physics plugin
  2308. /// </summary>
  2309. public void AddToPhysicalScene()
  2310. {
  2311. PhysicsScene scene = m_scene.PhysicsScene;
  2312. PhysicsVector pVec =
  2313. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  2314. AbsolutePosition.Z);
  2315. if (m_avHeight == 127.0f)
  2316. {
  2317. m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, 1.56f));
  2318. }
  2319. else
  2320. {
  2321. m_physicsActor = scene.AddAvatar(Firstname + "." + Lastname, pVec, new PhysicsVector(0, 0, m_avHeight));
  2322. }
  2323. //m_physicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
  2324. m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
  2325. m_physicsActor.SubscribeEvents(1000);
  2326. m_physicsActor.LocalID = LocalId;
  2327. }
  2328. // Event called by the physics plugin to tell the avatar about a collision.
  2329. private void PhysicsCollisionUpdate(EventArgs e)
  2330. {
  2331. if (e == null)
  2332. return;
  2333. CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
  2334. Dictionary<uint, float> coldata = collisionData.m_objCollisionList;
  2335. float starthealth = Health;
  2336. uint killerObj = 0;
  2337. foreach (uint localid in coldata.Keys)
  2338. {
  2339. if (coldata[localid] <= 0.10f || m_invulnerable)
  2340. continue;
  2341. //if (localid == 0)
  2342. //continue;
  2343. Health -= coldata[localid] * 5;
  2344. if (Health <= 0)
  2345. {
  2346. if (localid != 0)
  2347. killerObj = localid;
  2348. }
  2349. //m_log.Debug("[AVATAR]: Collision with localid: " + localid.ToString() + " at depth: " + coldata[localid].ToString());
  2350. }
  2351. //Health = 100;
  2352. if (!m_invulnerable)
  2353. {
  2354. if (starthealth != Health)
  2355. {
  2356. ControllingClient.SendHealth(Health);
  2357. }
  2358. if (m_health <= 0)
  2359. m_scene.EventManager.TriggerAvatarKill(killerObj, this);
  2360. }
  2361. if (Velocity.X > 0 || Velocity.Y > 0)
  2362. UpdateMovementAnimations();
  2363. }
  2364. public void setHealthWithUpdate(float health)
  2365. {
  2366. Health = health;
  2367. ControllingClient.SendHealth(Health);
  2368. }
  2369. public void Close()
  2370. {
  2371. lock (m_attachments)
  2372. {
  2373. // Delete attachments from scene
  2374. // Don't try to save, as this thread won't live long
  2375. // enough to complete the save. This would cause no copy
  2376. // attachments to poof!
  2377. //
  2378. foreach (SceneObjectGroup grp in m_attachments)
  2379. {
  2380. m_scene.DeleteSceneObject(grp, false);
  2381. }
  2382. m_attachments.Clear();
  2383. }
  2384. lock (m_knownChildRegions)
  2385. {
  2386. m_knownChildRegions.Clear();
  2387. }
  2388. lock (m_updateTimes)
  2389. {
  2390. m_updateTimes.Clear();
  2391. }
  2392. lock (m_partsUpdateQueue)
  2393. {
  2394. m_partsUpdateQueue.Clear();
  2395. }
  2396. RemoveFromPhysicalScene();
  2397. GC.Collect();
  2398. }
  2399. public ScenePresence()
  2400. {
  2401. /* JB
  2402. if (Animations == null)
  2403. {
  2404. Animations = new AvatarAnimations();
  2405. Animations.LoadAnims();
  2406. }
  2407. */
  2408. if (DefaultTexture == null)
  2409. {
  2410. Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
  2411. DefaultTexture = textu.ToBytes();
  2412. }
  2413. }
  2414. public void AddAttachment(SceneObjectGroup gobj)
  2415. {
  2416. lock (m_attachments)
  2417. {
  2418. m_attachments.Add(gobj);
  2419. }
  2420. }
  2421. public bool HasAttachments()
  2422. {
  2423. return m_attachments.Count > 0;
  2424. }
  2425. public bool HasScriptedAttachments()
  2426. {
  2427. lock (m_attachments)
  2428. {
  2429. foreach (SceneObjectGroup gobj in m_attachments)
  2430. {
  2431. if (gobj != null)
  2432. {
  2433. if (gobj.RootPart.Inventory.ContainsScripts())
  2434. return true;
  2435. }
  2436. }
  2437. }
  2438. return false;
  2439. }
  2440. public void RemoveAttachment(SceneObjectGroup gobj)
  2441. {
  2442. lock (m_attachments)
  2443. {
  2444. if (m_attachments.Contains(gobj))
  2445. {
  2446. m_attachments.Remove(gobj);
  2447. }
  2448. }
  2449. }
  2450. public bool ValidateAttachments()
  2451. {
  2452. lock (m_attachments)
  2453. {
  2454. // Validate
  2455. foreach (SceneObjectGroup gobj in m_attachments)
  2456. {
  2457. if (gobj == null)
  2458. return false;
  2459. if (gobj.IsDeleted)
  2460. return false;
  2461. }
  2462. }
  2463. return true;
  2464. }
  2465. public bool CrossAttachmentsIntoNewRegion(ulong regionHandle, bool silent)
  2466. {
  2467. lock (m_attachments)
  2468. {
  2469. // Validate
  2470. foreach (SceneObjectGroup gobj in m_attachments)
  2471. {
  2472. if (gobj == null || gobj.IsDeleted)
  2473. return false;
  2474. }
  2475. foreach (SceneObjectGroup gobj in m_attachments)
  2476. {
  2477. // If the prim group is null then something must have happened to it!
  2478. if (gobj != null && gobj.RootPart != null)
  2479. {
  2480. // Set the parent localID to 0 so it transfers over properly.
  2481. gobj.RootPart.SetParentLocalId(0);
  2482. gobj.RootPart.IsAttachment = false;
  2483. gobj.AbsolutePosition = gobj.RootPart.AttachedPos;
  2484. gobj.RootPart.LastOwnerID = gobj.GetFromAssetID();
  2485. m_log.DebugFormat("[ATTACHMENT]: Sending attachment {0} to region {1}", gobj.UUID, regionHandle);
  2486. m_scene.CrossPrimGroupIntoNewRegion(regionHandle, gobj, silent);
  2487. }
  2488. }
  2489. m_attachments.Clear();
  2490. return true;
  2491. }
  2492. }
  2493. public void initializeScenePresence(IClientAPI client, RegionInfo region, Scene scene)
  2494. {
  2495. m_controllingClient = client;
  2496. m_regionInfo = region;
  2497. m_scene = scene;
  2498. RegisterToEvents();
  2499. /*
  2500. AbsolutePosition = client.StartPos;
  2501. Animations = new AvatarAnimations();
  2502. Animations.LoadAnims();
  2503. m_animations = new List<UUID>();
  2504. m_animations.Add(Animations.AnimsUUID["STAND"]);
  2505. m_animationSeqs.Add(m_controllingClient.NextAnimationSequenceNumber);
  2506. SetDirectionVectors();
  2507. */
  2508. }
  2509. protected ScenePresence(SerializationInfo info, StreamingContext context)
  2510. : base (info, context)
  2511. {
  2512. //System.Console.WriteLine("ScenePresence Deserialize BGN");
  2513. if (info == null)
  2514. {
  2515. throw new ArgumentNullException("info");
  2516. }
  2517. /* JB
  2518. if (Animations == null)
  2519. {
  2520. Animations = new AvatarAnimations();
  2521. Animations.LoadAnims();
  2522. }
  2523. */
  2524. if (DefaultTexture == null)
  2525. {
  2526. Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
  2527. DefaultTexture = textu.ToBytes();
  2528. }
  2529. m_animations = (AnimationSet)info.GetValue("m_animations", typeof(AnimationSet));
  2530. m_updateflag = (bool)info.GetValue("m_updateflag", typeof(bool));
  2531. m_movementflag = (byte)info.GetValue("m_movementflag", typeof(byte));
  2532. m_forcesList = (List<NewForce>)info.GetValue("m_forcesList", typeof(List<NewForce>));
  2533. m_updateCount = (short)info.GetValue("m_updateCount", typeof(short));
  2534. m_requestedSitTargetID = (uint)info.GetValue("m_requestedSitTargetID", typeof(uint));
  2535. m_requestedSitOffset
  2536. = new Vector3(
  2537. (float)info.GetValue("m_requestedSitOffset.X", typeof(float)),
  2538. (float)info.GetValue("m_requestedSitOffset.Y", typeof(float)),
  2539. (float)info.GetValue("m_requestedSitOffset.Z", typeof(float)));
  2540. m_sitAvatarHeight = (float)info.GetValue("m_sitAvatarHeight", typeof(float));
  2541. m_godlevel = (float)info.GetValue("m_godlevel", typeof(float));
  2542. m_setAlwaysRun = (bool)info.GetValue("m_setAlwaysRun", typeof(bool));
  2543. m_bodyRot
  2544. = new Quaternion(
  2545. (float)info.GetValue("m_bodyRot.X", typeof(float)),
  2546. (float)info.GetValue("m_bodyRot.Y", typeof(float)),
  2547. (float)info.GetValue("m_bodyRot.Z", typeof(float)),
  2548. (float)info.GetValue("m_bodyRot.W", typeof(float)));
  2549. IsRestrictedToRegion = (bool)info.GetValue("IsRestrictedToRegion", typeof(bool));
  2550. m_newForce = (bool)info.GetValue("m_newForce", typeof(bool));
  2551. //m_newAvatar = (bool)info.GetValue("m_newAvatar", typeof(bool));
  2552. m_newCoarseLocations = (bool)info.GetValue("m_newCoarseLocations", typeof(bool));
  2553. m_avHeight = (float)info.GetValue("m_avHeight", typeof(float));
  2554. crossingFromRegion = (ulong)info.GetValue("crossingFromRegion", typeof(ulong));
  2555. List<float[]> Dir_Vectors_work = (List<float[]>)info.GetValue("Dir_Vectors", typeof(List<float[]>));
  2556. List<Vector3> Dir_Vectors_work2 = new List<Vector3>();
  2557. foreach (float[] f3 in Dir_Vectors_work)
  2558. {
  2559. Dir_Vectors_work2.Add(new Vector3(f3[0], f3[1], f3[2]));
  2560. }
  2561. Dir_Vectors = Dir_Vectors_work2.ToArray();
  2562. lastPhysPos
  2563. = new Vector3(
  2564. (float)info.GetValue("lastPhysPos.X", typeof(float)),
  2565. (float)info.GetValue("lastPhysPos.Y", typeof(float)),
  2566. (float)info.GetValue("lastPhysPos.Z", typeof(float)));
  2567. // Possibly we should store lastPhysRot. But there may well be not much point since rotation changes
  2568. // wouldn't carry us across borders anyway
  2569. m_CameraCenter
  2570. = new Vector3(
  2571. (float)info.GetValue("m_CameraCenter.X", typeof(float)),
  2572. (float)info.GetValue("m_CameraCenter.Y", typeof(float)),
  2573. (float)info.GetValue("m_CameraCenter.Z", typeof(float)));
  2574. m_CameraAtAxis
  2575. = new Vector3(
  2576. (float)info.GetValue("m_CameraAtAxis.X", typeof(float)),
  2577. (float)info.GetValue("m_CameraAtAxis.Y", typeof(float)),
  2578. (float)info.GetValue("m_CameraAtAxis.Z", typeof(float)));
  2579. m_CameraLeftAxis
  2580. = new Vector3(
  2581. (float)info.GetValue("m_CameraLeftAxis.X", typeof(float)),
  2582. (float)info.GetValue("m_CameraLeftAxis.Y", typeof(float)),
  2583. (float)info.GetValue("m_CameraLeftAxis.Z", typeof(float)));
  2584. m_CameraUpAxis
  2585. = new Vector3(
  2586. (float)info.GetValue("m_CameraUpAxis.X", typeof(float)),
  2587. (float)info.GetValue("m_CameraUpAxis.Y", typeof(float)),
  2588. (float)info.GetValue("m_CameraUpAxis.Z", typeof(float)));
  2589. m_DrawDistance = (float)info.GetValue("m_DrawDistance", typeof(float));
  2590. m_appearance = (AvatarAppearance)info.GetValue("m_appearance", typeof(AvatarAppearance));
  2591. m_knownChildRegions = (Dictionary<ulong, string>)info.GetValue("m_knownChildRegions", typeof(Dictionary<ulong, string>));
  2592. posLastSignificantMove
  2593. = new Vector3(
  2594. (float)info.GetValue("posLastSignificantMove.X", typeof(float)),
  2595. (float)info.GetValue("posLastSignificantMove.Y", typeof(float)),
  2596. (float)info.GetValue("posLastSignificantMove.Z", typeof(float)));
  2597. // m_partsUpdateQueue = (UpdateQueue)info.GetValue("m_partsUpdateQueue", typeof(UpdateQueue));
  2598. /*
  2599. Dictionary<Guid, ScenePartUpdate> updateTimes_work
  2600. = (Dictionary<Guid, ScenePartUpdate>)info.GetValue("m_updateTimes", typeof(Dictionary<Guid, ScenePartUpdate>));
  2601. foreach (Guid id in updateTimes_work.Keys)
  2602. {
  2603. m_updateTimes.Add(new UUID(id), updateTimes_work[id]);
  2604. }
  2605. */
  2606. m_regionHandle = (ulong)info.GetValue("m_regionHandle", typeof(ulong));
  2607. m_firstname = (string)info.GetValue("m_firstname", typeof(string));
  2608. m_lastname = (string)info.GetValue("m_lastname", typeof(string));
  2609. m_allowMovement = (bool)info.GetValue("m_allowMovement", typeof(bool));
  2610. m_parentPosition = new Vector3((float)info.GetValue("m_parentPosition.X", typeof(float)),
  2611. (float)info.GetValue("m_parentPosition.Y", typeof(float)),
  2612. (float)info.GetValue("m_parentPosition.Z", typeof(float)));
  2613. m_isChildAgent = (bool)info.GetValue("m_isChildAgent", typeof(bool));
  2614. m_parentID = (uint)info.GetValue("m_parentID", typeof(uint));
  2615. // for OpenSim_v0.5
  2616. currentParcelUUID = new UUID((Guid)info.GetValue("currentParcelUUID", typeof(Guid)));
  2617. lastKnownAllowedPosition
  2618. = new Vector3(
  2619. (float)info.GetValue("lastKnownAllowedPosition.X", typeof(float)),
  2620. (float)info.GetValue("lastKnownAllowedPosition.Y", typeof(float)),
  2621. (float)info.GetValue("lastKnownAllowedPosition.Z", typeof(float)));
  2622. sentMessageAboutRestrictedParcelFlyingDown = (bool)info.GetValue("sentMessageAboutRestrictedParcelFlyingDown", typeof(bool));
  2623. m_LastChildAgentUpdatePosition
  2624. = new Vector3(
  2625. (float)info.GetValue("m_LastChildAgentUpdatePosition.X", typeof(float)),
  2626. (float)info.GetValue("m_LastChildAgentUpdatePosition.Y", typeof(float)),
  2627. (float)info.GetValue("m_LastChildAgentUpdatePosition.Z", typeof(float)));
  2628. m_perfMonMS = (int)info.GetValue("m_perfMonMS", typeof(int));
  2629. m_AgentControlFlags = (uint)info.GetValue("m_AgentControlFlags", typeof(uint));
  2630. m_headrotation
  2631. = new Quaternion(
  2632. (float)info.GetValue("m_headrotation.X", typeof(float)),
  2633. (float)info.GetValue("m_headrotation.Y", typeof(float)),
  2634. (float)info.GetValue("m_headrotation.Z", typeof(float)),
  2635. (float)info.GetValue("m_headrotation.W", typeof(float)));
  2636. m_state = (byte)info.GetValue("m_state", typeof(byte));
  2637. //System.Console.WriteLine("ScenePresence Deserialize END");
  2638. }
  2639. [SecurityPermission(SecurityAction.LinkDemand,
  2640. Flags = SecurityPermissionFlag.SerializationFormatter)]
  2641. public override void GetObjectData(
  2642. SerializationInfo info, StreamingContext context)
  2643. {
  2644. if (info == null)
  2645. {
  2646. throw new ArgumentNullException("info");
  2647. }
  2648. base.GetObjectData(info, context);
  2649. info.AddValue("m_animations", m_animations);
  2650. info.AddValue("m_updateflag", m_updateflag);
  2651. info.AddValue("m_movementflag", m_movementflag);
  2652. info.AddValue("m_forcesList", m_forcesList);
  2653. info.AddValue("m_updateCount", m_updateCount);
  2654. info.AddValue("m_requestedSitTargetID", m_requestedSitTargetID);
  2655. // Vector3
  2656. info.AddValue("m_requestedSitOffset.X", m_requestedSitOffset.X);
  2657. info.AddValue("m_requestedSitOffset.Y", m_requestedSitOffset.Y);
  2658. info.AddValue("m_requestedSitOffset.Z", m_requestedSitOffset.Z);
  2659. info.AddValue("m_sitAvatarHeight", m_sitAvatarHeight);
  2660. info.AddValue("m_godlevel", m_godlevel);
  2661. info.AddValue("m_setAlwaysRun", m_setAlwaysRun);
  2662. // Quaternion
  2663. info.AddValue("m_bodyRot.X", m_bodyRot.X);
  2664. info.AddValue("m_bodyRot.Y", m_bodyRot.Y);
  2665. info.AddValue("m_bodyRot.Z", m_bodyRot.Z);
  2666. info.AddValue("m_bodyRot.W", m_bodyRot.W);
  2667. info.AddValue("IsRestrictedToRegion", IsRestrictedToRegion);
  2668. info.AddValue("m_newForce", m_newForce);
  2669. //info.AddValue("m_newAvatar", m_newAvatar);
  2670. info.AddValue("m_newCoarseLocations", m_newCoarseLocations);
  2671. info.AddValue("m_gotAPrimitivesInScene", false);
  2672. info.AddValue("m_avHeight", m_avHeight);
  2673. // info.AddValue("m_regionInfo", m_regionInfo);
  2674. info.AddValue("crossingFromRegion", crossingFromRegion);
  2675. List<float[]> Dir_Vectors_work = new List<float[]>();
  2676. foreach (Vector3 v3 in Dir_Vectors)
  2677. {
  2678. Dir_Vectors_work.Add(new float[] { v3.X, v3.Y, v3.Z });
  2679. }
  2680. info.AddValue("Dir_Vectors", Dir_Vectors_work);
  2681. // Vector3
  2682. info.AddValue("lastPhysPos.X", lastPhysPos.X);
  2683. info.AddValue("lastPhysPos.Y", lastPhysPos.Y);
  2684. info.AddValue("lastPhysPos.Z", lastPhysPos.Z);
  2685. // Possibly we should retrieve lastPhysRot. But there may well be not much point since rotation changes
  2686. // wouldn't carry us across borders anyway
  2687. // Vector3
  2688. info.AddValue("m_CameraCenter.X", m_CameraCenter.X);
  2689. info.AddValue("m_CameraCenter.Y", m_CameraCenter.Y);
  2690. info.AddValue("m_CameraCenter.Z", m_CameraCenter.Z);
  2691. // Vector3
  2692. info.AddValue("m_CameraAtAxis.X", m_CameraAtAxis.X);
  2693. info.AddValue("m_CameraAtAxis.Y", m_CameraAtAxis.Y);
  2694. info.AddValue("m_CameraAtAxis.Z", m_CameraAtAxis.Z);
  2695. // Vector3
  2696. info.AddValue("m_CameraLeftAxis.X", m_CameraLeftAxis.X);
  2697. info.AddValue("m_CameraLeftAxis.Y", m_CameraLeftAxis.Y);
  2698. info.AddValue("m_CameraLeftAxis.Z", m_CameraLeftAxis.Z);
  2699. // Vector3
  2700. info.AddValue("m_CameraUpAxis.X", m_CameraUpAxis.X);
  2701. info.AddValue("m_CameraUpAxis.Y", m_CameraUpAxis.Y);
  2702. info.AddValue("m_CameraUpAxis.Z", m_CameraUpAxis.Z);
  2703. info.AddValue("m_DrawDistance", m_DrawDistance);
  2704. info.AddValue("m_appearance", m_appearance);
  2705. info.AddValue("m_knownChildRegions", m_knownChildRegions);
  2706. // Vector3
  2707. info.AddValue("posLastSignificantMove.X", posLastSignificantMove.X);
  2708. info.AddValue("posLastSignificantMove.Y", posLastSignificantMove.Y);
  2709. info.AddValue("posLastSignificantMove.Z", posLastSignificantMove.Z);
  2710. //info.AddValue("m_partsUpdateQueue", m_partsUpdateQueue);
  2711. /*
  2712. Dictionary<Guid, ScenePartUpdate> updateTimes_work = new Dictionary<Guid, ScenePartUpdate>();
  2713. foreach (UUID id in m_updateTimes.Keys)
  2714. {
  2715. updateTimes_work.Add(id.UUID, m_updateTimes[id]);
  2716. }
  2717. info.AddValue("m_updateTimes", updateTimes_work);
  2718. */
  2719. info.AddValue("m_regionHandle", m_regionHandle);
  2720. info.AddValue("m_firstname", m_firstname);
  2721. info.AddValue("m_lastname", m_lastname);
  2722. info.AddValue("m_allowMovement", m_allowMovement);
  2723. //info.AddValue("m_physicsActor", m_physicsActor);
  2724. info.AddValue("m_parentPosition.X", m_parentPosition.X);
  2725. info.AddValue("m_parentPosition.Y", m_parentPosition.Y);
  2726. info.AddValue("m_parentPosition.Z", m_parentPosition.Z);
  2727. info.AddValue("m_isChildAgent", m_isChildAgent);
  2728. info.AddValue("m_parentID", m_parentID);
  2729. // for OpenSim_v0.5
  2730. info.AddValue("currentParcelUUID", currentParcelUUID.Guid);
  2731. info.AddValue("lastKnownAllowedPosition.X", lastKnownAllowedPosition.X);
  2732. info.AddValue("lastKnownAllowedPosition.Y", lastKnownAllowedPosition.Y);
  2733. info.AddValue("lastKnownAllowedPosition.Z", lastKnownAllowedPosition.Z);
  2734. info.AddValue("sentMessageAboutRestrictedParcelFlyingDown", sentMessageAboutRestrictedParcelFlyingDown);
  2735. info.AddValue("m_LastChildAgentUpdatePosition.X", m_LastChildAgentUpdatePosition.X);
  2736. info.AddValue("m_LastChildAgentUpdatePosition.Y", m_LastChildAgentUpdatePosition.Y);
  2737. info.AddValue("m_LastChildAgentUpdatePosition.Z", m_LastChildAgentUpdatePosition.Z);
  2738. info.AddValue("m_perfMonMS", m_perfMonMS);
  2739. info.AddValue("m_AgentControlFlags", m_AgentControlFlags);
  2740. info.AddValue("m_headrotation.W", m_headrotation.W);
  2741. info.AddValue("m_headrotation.X", m_headrotation.X);
  2742. info.AddValue("m_headrotation.Y", m_headrotation.Y);
  2743. info.AddValue("m_headrotation.Z", m_headrotation.Z);
  2744. info.AddValue("m_state", m_state);
  2745. List<Guid> knownPrimUUID_work = new List<Guid>();
  2746. info.AddValue("m_knownPrimUUID", knownPrimUUID_work);
  2747. }
  2748. internal void PushForce(PhysicsVector impulse)
  2749. {
  2750. if (PhysicsActor != null)
  2751. {
  2752. PhysicsActor.AddForce(impulse,true);
  2753. }
  2754. }
  2755. public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
  2756. {
  2757. ScriptControllers obj = new ScriptControllers();
  2758. obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
  2759. obj.eventControls = ScriptControlled.CONTROL_ZERO;
  2760. obj.itemID = Script_item_UUID;
  2761. obj.objID = Obj_localID;
  2762. if (pass_on == 0 && accept == 0)
  2763. {
  2764. IgnoredControls |= (ScriptControlled)controls;
  2765. obj.ignoreControls = (ScriptControlled)controls;
  2766. }
  2767. if (pass_on == 0 && accept == 1)
  2768. {
  2769. IgnoredControls |= (ScriptControlled)controls;
  2770. obj.ignoreControls = (ScriptControlled)controls;
  2771. obj.eventControls = (ScriptControlled)controls;
  2772. }
  2773. if (pass_on == 1 && accept == 1)
  2774. {
  2775. IgnoredControls = ScriptControlled.CONTROL_ZERO;
  2776. obj.eventControls = (ScriptControlled)controls;
  2777. obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
  2778. }
  2779. lock (scriptedcontrols)
  2780. {
  2781. if (pass_on == 1 && accept == 0)
  2782. {
  2783. IgnoredControls &= ~(ScriptControlled)controls;
  2784. if (scriptedcontrols.ContainsKey(Script_item_UUID))
  2785. scriptedcontrols.Remove(Script_item_UUID);
  2786. }
  2787. else
  2788. {
  2789. if (scriptedcontrols.ContainsKey(Script_item_UUID))
  2790. {
  2791. scriptedcontrols[Script_item_UUID] = obj;
  2792. }
  2793. else
  2794. {
  2795. scriptedcontrols.Add(Script_item_UUID, obj);
  2796. }
  2797. }
  2798. }
  2799. ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true);
  2800. }
  2801. public void HandleForceReleaseControls(IClientAPI remoteClient, UUID agentID)
  2802. {
  2803. IgnoredControls = ScriptControlled.CONTROL_ZERO;
  2804. lock (scriptedcontrols)
  2805. {
  2806. scriptedcontrols.Clear();
  2807. }
  2808. ControllingClient.SendTakeControls(int.MaxValue, false, false);
  2809. }
  2810. public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
  2811. {
  2812. lock (scriptedcontrols)
  2813. {
  2814. if (scriptedcontrols.ContainsKey(Script_item_UUID))
  2815. {
  2816. ScriptControllers takecontrolls = scriptedcontrols[Script_item_UUID];
  2817. ScriptControlled sctc = takecontrolls.eventControls;
  2818. ControllingClient.SendTakeControls((int)sctc, false, false);
  2819. ControllingClient.SendTakeControls((int)sctc, true, false);
  2820. scriptedcontrols.Remove(Script_item_UUID);
  2821. IgnoredControls = ScriptControlled.CONTROL_ZERO;
  2822. foreach (ScriptControllers scData in scriptedcontrols.Values)
  2823. {
  2824. IgnoredControls |= scData.ignoreControls;
  2825. }
  2826. }
  2827. }
  2828. }
  2829. internal void SendControlToScripts(uint flags)
  2830. {
  2831. ScriptControlled allflags = ScriptControlled.CONTROL_ZERO;
  2832. if (MouseDown)
  2833. {
  2834. allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON);
  2835. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0)
  2836. {
  2837. allflags = ScriptControlled.CONTROL_ZERO;
  2838. MouseDown = true;
  2839. }
  2840. }
  2841. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0)
  2842. {
  2843. allflags |= ScriptControlled.CONTROL_ML_LBUTTON;
  2844. MouseDown = true;
  2845. }
  2846. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0)
  2847. {
  2848. allflags |= ScriptControlled.CONTROL_LBUTTON;
  2849. MouseDown = true;
  2850. }
  2851. // find all activated controls, whether the scripts are interested in them or not
  2852. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0)
  2853. {
  2854. allflags |= ScriptControlled.CONTROL_FWD;
  2855. }
  2856. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0)
  2857. {
  2858. allflags |= ScriptControlled.CONTROL_BACK;
  2859. }
  2860. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0)
  2861. {
  2862. allflags |= ScriptControlled.CONTROL_UP;
  2863. }
  2864. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)
  2865. {
  2866. allflags |= ScriptControlled.CONTROL_DOWN;
  2867. }
  2868. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0)
  2869. {
  2870. allflags |= ScriptControlled.CONTROL_LEFT;
  2871. }
  2872. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0)
  2873. {
  2874. allflags |= ScriptControlled.CONTROL_RIGHT;
  2875. }
  2876. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
  2877. {
  2878. allflags |= ScriptControlled.CONTROL_ROT_RIGHT;
  2879. }
  2880. if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
  2881. {
  2882. allflags |= ScriptControlled.CONTROL_ROT_LEFT;
  2883. }
  2884. // optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that
  2885. if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands)
  2886. {
  2887. lock (scriptedcontrols)
  2888. {
  2889. foreach (UUID scriptUUID in scriptedcontrols.Keys)
  2890. {
  2891. ScriptControllers scriptControlData = scriptedcontrols[scriptUUID];
  2892. ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us
  2893. ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle
  2894. ScriptControlled localChange = localHeld ^ localLast; // the changed bits
  2895. if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO)
  2896. {
  2897. // only send if still pressed or just changed
  2898. m_scene.EventManager.TriggerControlEvent(scriptControlData.objID, scriptUUID, UUID, (uint)localHeld, (uint)localChange);
  2899. }
  2900. }
  2901. }
  2902. }
  2903. LastCommands = allflags;
  2904. }
  2905. internal uint RemoveIgnoredControls(uint flags, ScriptControlled Ignored)
  2906. {
  2907. if (Ignored == ScriptControlled.CONTROL_ZERO)
  2908. return flags;
  2909. if ((Ignored & ScriptControlled.CONTROL_BACK) != 0)
  2910. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG);
  2911. if ((Ignored & ScriptControlled.CONTROL_FWD) != 0)
  2912. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS);
  2913. if ((Ignored & ScriptControlled.CONTROL_DOWN) != 0)
  2914. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG);
  2915. if ((Ignored & ScriptControlled.CONTROL_UP) != 0)
  2916. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS);
  2917. if ((Ignored & ScriptControlled.CONTROL_LEFT) != 0)
  2918. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS);
  2919. if ((Ignored & ScriptControlled.CONTROL_RIGHT) != 0)
  2920. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG | (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG);
  2921. if ((Ignored & ScriptControlled.CONTROL_ROT_LEFT) != 0)
  2922. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG);
  2923. if ((Ignored & ScriptControlled.CONTROL_ROT_RIGHT) != 0)
  2924. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS);
  2925. if ((Ignored & ScriptControlled.CONTROL_ML_LBUTTON) != 0)
  2926. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN);
  2927. if ((Ignored & ScriptControlled.CONTROL_LBUTTON) != 0)
  2928. flags &= ~((uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP | (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN);
  2929. //DIR_CONTROL_FLAG_FORWARD = AgentManager.ControlFlags.AGENT_CONTROL_AT_POS,
  2930. //DIR_CONTROL_FLAG_BACK = AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG,
  2931. //DIR_CONTROL_FLAG_LEFT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS,
  2932. //DIR_CONTROL_FLAG_RIGHT = AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG,
  2933. //DIR_CONTROL_FLAG_UP = AgentManager.ControlFlags.AGENT_CONTROL_UP_POS,
  2934. //DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG,
  2935. //DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
  2936. return flags;
  2937. }
  2938. private void ItemReceived(UUID itemID)
  2939. {
  2940. if (IsChildAgent)
  2941. return;
  2942. if (null == m_appearance)
  2943. {
  2944. m_log.Warn("[ATTACHMENT] Appearance has not been initialized");
  2945. return;
  2946. }
  2947. int attachpoint = m_appearance.GetAttachpoint(itemID);
  2948. if (attachpoint == 0)
  2949. return;
  2950. UUID asset = m_appearance.GetAttachedAsset(attachpoint);
  2951. if (UUID.Zero == asset) // We have just logged in
  2952. {
  2953. try
  2954. {
  2955. // Rez from inventory
  2956. asset = m_scene.RezSingleAttachment(ControllingClient,
  2957. itemID, (uint)attachpoint);
  2958. // Corner case: We are not yet a Scene Entity
  2959. // Setting attachment info in RezSingleAttachment will fail
  2960. // Set it here
  2961. //
  2962. m_appearance.SetAttachment((int)attachpoint, itemID,
  2963. asset);
  2964. m_log.InfoFormat("[ATTACHMENT] Rezzed attachment {0}, inworld asset {1}",
  2965. itemID.ToString(), asset);
  2966. }
  2967. catch (Exception e)
  2968. {
  2969. m_log.ErrorFormat("[ATTACHMENT] Unable to rez attachment: {0}", e.ToString());
  2970. }
  2971. return;
  2972. }
  2973. SceneObjectPart att = m_scene.GetSceneObjectPart(asset);
  2974. // If this is null, then the asset has not yet appeared in world
  2975. // so we revisit this when it does
  2976. //
  2977. if (att != null && att.UUID != asset) // Yes. It's really needed
  2978. {
  2979. m_log.DebugFormat("[ATTACHMENT]: Attach from in world: ItemID {0}, Asset ID {1}, Attachment inworld: {2}", itemID.ToString(), asset.ToString(), att.UUID.ToString());
  2980. // This will throw if crossing katty-korner
  2981. // So catch it here to avoid the noid
  2982. //
  2983. try
  2984. {
  2985. // Attach from world, if not already attached
  2986. if (att.ParentGroup != null && !att.IsAttachment)
  2987. m_scene.AttachObject(ControllingClient, att.ParentGroup.LocalId, (uint)0, Quaternion.Identity, att.ParentGroup.AbsolutePosition, false);
  2988. }
  2989. catch (NullReferenceException)
  2990. {
  2991. }
  2992. }
  2993. }
  2994. }
  2995. }