llviewerobjectlist.cpp 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484
  1. /**
  2. * @file llviewerobjectlist.cpp
  3. * @brief Implementation of LLViewerObjectList class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include <iterator>
  34. #include <utility>
  35. #include "zlib.h"
  36. #include "llviewerobjectlist.h"
  37. #include "llcommonmath.h"
  38. #include "llcorehttputil.h"
  39. #include "lldatapacker.h"
  40. #include "llfasttimer.h"
  41. #include "llkeyboard.h"
  42. #include "lllocale.h"
  43. #include "llrenderutils.h"
  44. #include "llmessage.h"
  45. #include "object_flags.h"
  46. #include "llagent.h"
  47. #include "llappviewer.h"
  48. #include "lldrawable.h"
  49. #include "llface.h"
  50. #include "llflexibleobject.h"
  51. #include "llhoverview.h"
  52. #include "llhudtext.h"
  53. #include "hbobjectbackup.h"
  54. #include "llpanelminimap.h"
  55. #include "llpipeline.h"
  56. #include "llselectmgr.h"
  57. #include "llsky.h"
  58. #include "llspatialpartition.h"
  59. #include "lltoolmgr.h"
  60. #include "lltoolpie.h"
  61. #include "hbviewerautomation.h"
  62. #include "llviewercamera.h"
  63. #include "llviewercontrol.h"
  64. #include "llviewermessage.h" // For add_newly_created_object()
  65. #include "llviewerobject.h"
  66. #include "llviewerregion.h"
  67. #include "llviewerstats.h"
  68. #include "llviewertextureanim.h"
  69. #include "llviewerwindow.h"
  70. #include "llvoavatarself.h"
  71. #include "llvocache.h"
  72. #include "llworld.h"
  73. extern F32 gMinObjectDistance;
  74. #define LL_IGNORE_DEAD 0
  75. // Global lists of objects - should go away soon.
  76. LLViewerObjectList gObjectList;
  77. extern LLPipeline gPipeline;
  78. // Maximum number of objects per cost/physics flags request (500 is the limit
  79. // seen in SL as of 2016-06-14):
  80. S32 gMaxObjectsPerFetch = 500;
  81. LLViewerObjectList::LLViewerObjectList()
  82. : mWasPaused(false),
  83. mNumVisCulled(0),
  84. mNumSizeCulled(0),
  85. mCurLazyUpdateIndex(0),
  86. mCurBin(0),
  87. mNumOrphans(0),
  88. mNumNewObjects(0),
  89. mNumDeadObjectUpdates(0),
  90. mNumUnknownUpdates(0),
  91. mKilledAttachments(0),
  92. mKilledAttachmentsStamp(0),
  93. mSimulatorMachineIndex(1), // Not zero to speed up index check
  94. mIdleListSlots(32768)
  95. {
  96. mIdleList.reserve(mIdleListSlots);
  97. }
  98. void LLViewerObjectList::cleanupClass()
  99. {
  100. llinfos << "Destroying all the objects in the list..." << llendl;
  101. killAllObjects();
  102. mDebugBeacons.clear();
  103. mUUIDObjectMap.clear();
  104. mUUIDAvatarMap.clear();
  105. llinfos << "All objects destroyed." << llendl;
  106. }
  107. void LLViewerObjectList::getUUIDFromLocal(LLUUID& id, U32 local_id, U32 ip,
  108. U32 port)
  109. {
  110. U64 ipport = (((U64)ip) << 32) | (U64)port;
  111. U32 index;
  112. ip_to_idx_map_t::iterator it = mIPAndPortToIndex.find(ipport);
  113. if (it == mIPAndPortToIndex.end())
  114. {
  115. index = mSimulatorMachineIndex++;
  116. mIPAndPortToIndex[ipport] = index;
  117. }
  118. else
  119. {
  120. index = it->second;
  121. }
  122. U64 indexid = (((U64)index) << 32) | (U64)local_id;
  123. id = get_if_there(mIndexAndLocalIDToUUID, indexid, LLUUID::null);
  124. }
  125. U64 LLViewerObjectList::getIndex(U32 local_id, U32 ip, U32 port)
  126. {
  127. U64 ipport = (((U64)ip) << 32) | (U64)port;
  128. U32 index = mIPAndPortToIndex[ipport];
  129. return index ? (((U64)index) << 32) | (U64)local_id : 0;
  130. }
  131. bool LLViewerObjectList::removeFromLocalIDTable(const LLViewerObject* objectp)
  132. {
  133. LL_TRACY_TIMER(TRC_OBJ_REMOVE_LOCAL_ID);
  134. if (objectp && objectp->getRegion())
  135. {
  136. U32 local_id = objectp->mLocalID;
  137. LLHost region_host = objectp->getRegion()->getHost();
  138. U32 ip = region_host.getAddress();
  139. U32 port = region_host.getPort();
  140. U64 ipport = (((U64)ip) << 32) | (U64)port;
  141. U32 index = mIPAndPortToIndex[ipport];
  142. U64 indexid = (((U64)index) << 32) | (U64)local_id;
  143. idx_to_uuid_map_t::iterator it = mIndexAndLocalIDToUUID.find(indexid);
  144. if (it == mIndexAndLocalIDToUUID.end())
  145. {
  146. return false;
  147. }
  148. // Found existing entry
  149. if (it->second == objectp->getID())
  150. {
  151. // Full UUIDs match, so remove the entry
  152. mIndexAndLocalIDToUUID.erase(it);
  153. return true;
  154. }
  155. // UUIDs did not match: this would zap a valid entry, so do not erase
  156. // it
  157. }
  158. return false;
  159. }
  160. void LLViewerObjectList::setUUIDAndLocal(const LLUUID& id, U32 local_id,
  161. U32 ip, U32 port)
  162. {
  163. U64 ipport = (((U64)ip) << 32) | (U64)port;
  164. U32 index = mIPAndPortToIndex[ipport];
  165. if (!index)
  166. {
  167. index = mSimulatorMachineIndex++;
  168. mIPAndPortToIndex[ipport] = index;
  169. }
  170. U64 indexid = (((U64)index) << 32) | (U64)local_id;
  171. mIndexAndLocalIDToUUID[indexid] = id;
  172. LL_DEBUGS("ObjectCacheSpam") << "Local Id " << local_id
  173. << " associated with UUID " << id << LL_ENDL;
  174. }
  175. // Because there is a bug in message_template.msg, which define the "Set" field
  176. // in the ObjectData block of the ObjectPermissions message as an U8 instead of
  177. // a bool (it does not change anything at the message level, but it causes the
  178. // viewers to issue warnings when they set "Set" as a bool, which it should be.
  179. #define MESSAGE_TEMPLATE_FIXED 0
  180. void LLViewerObjectList::processUpdateCore(LLViewerObject* objectp,
  181. void** user_data, U32 i,
  182. EObjectUpdateType update_type,
  183. LLDataPacker* dpp,
  184. bool just_created, bool from_cache)
  185. {
  186. LL_TRACY_TIMER(TRC_PROCESS_OBJECTS_CORE);
  187. LLMessageSystem* msg = from_cache ? NULL : gMessageSystemp;
  188. // Ignore returned flags
  189. objectp->processUpdateMessage(msg, user_data, i, update_type, dpp);
  190. if (objectp->isDead())
  191. {
  192. // The update failed
  193. return;
  194. }
  195. updateActive(objectp);
  196. if (just_created)
  197. {
  198. gPipeline.addObject(objectp);
  199. }
  200. else
  201. {
  202. HBObjectBackup::primUpdate(objectp);
  203. }
  204. // Also sets the approx. pixel area
  205. objectp->setPixelAreaAndAngle();
  206. // RN: this must be called after we have a drawable (from
  207. // gPipeline.addObject) so that the drawable parent is set properly.
  208. if (msg)
  209. {
  210. findOrphans(objectp, msg->getSenderIP(), msg->getSenderPort());
  211. }
  212. else
  213. {
  214. LLViewerRegion* regionp = objectp->getRegion();
  215. if (regionp)
  216. {
  217. findOrphans(objectp, regionp->getHost().getAddress(),
  218. regionp->getHost().getPort());
  219. }
  220. }
  221. // If we are just wandering around, do not create new objects selected.
  222. if (just_created && update_type != OUT_TERSE_IMPROVED &&
  223. objectp->mCreateSelected)
  224. {
  225. if (!gToolMgr.isCurrentTool(&gToolPie))
  226. {
  227. LL_DEBUGS("ViewerObject") << "Selecting " << objectp->mID
  228. << LL_ENDL;
  229. gSelectMgr.selectObjectAndFamily(objectp);
  230. dialog_refresh_all();
  231. }
  232. objectp->mCreateSelected = false;
  233. gWindowp->decBusyCount();
  234. gWindowp->setCursor(UI_CURSOR_ARROW);
  235. // Set the object permission to the user-selected default ones
  236. LLViewerRegion* region = objectp->getRegion();
  237. if (region) // Paranoia
  238. {
  239. #if MESSAGE_TEMPLATE_FIXED
  240. bool perm_modify = gSavedSettings.getBool("NextOwnerModify");
  241. bool perm_copy = gSavedSettings.getBool("NextOwnerCopy");
  242. bool perm_transfer = gSavedSettings.getBool("NextOwnerTransfer");
  243. bool perm_all_copy = gSavedSettings.getBool("EveryoneCopy");
  244. bool perm_group = gSavedSettings.getBool("ShareWithGroup");
  245. #else
  246. U8 perm_modify = (U8)gSavedSettings.getBool("NextOwnerModify");
  247. U8 perm_copy = (U8)gSavedSettings.getBool("NextOwnerCopy");
  248. U8 perm_transfer = (U8)gSavedSettings.getBool("NextOwnerTransfer");
  249. U8 perm_all_copy = (U8)gSavedSettings.getBool("EveryoneCopy");
  250. U8 perm_group = (U8)gSavedSettings.getBool("ShareWithGroup");
  251. #endif
  252. U32 local_id = objectp->getLocalID();
  253. LLMessageSystem* msg = gMessageSystemp;
  254. msg->newMessageFast(_PREHASH_ObjectPermissions);
  255. msg->nextBlockFast(_PREHASH_AgentData);
  256. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  257. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  258. msg->nextBlockFast(_PREHASH_HeaderData);
  259. msg->addBoolFast(_PREHASH_Override, false);
  260. msg->nextBlockFast(_PREHASH_ObjectData);
  261. msg->addU32Fast(_PREHASH_ObjectLocalID, local_id);
  262. msg->addU8Fast(_PREHASH_Field, PERM_NEXT_OWNER);
  263. #if MESSAGE_TEMPLATE_FIXED
  264. msg->addBoolFast(_PREHASH_Set, perm_modify);
  265. #else
  266. msg->addU8Fast(_PREHASH_Set, perm_modify);
  267. #endif
  268. msg->addU32Fast(_PREHASH_Mask, PERM_MODIFY);
  269. msg->nextBlockFast(_PREHASH_ObjectData);
  270. msg->addU32Fast(_PREHASH_ObjectLocalID, local_id);
  271. msg->addU8Fast(_PREHASH_Field, PERM_NEXT_OWNER);
  272. #if MESSAGE_TEMPLATE_FIXED
  273. msg->addBoolFast(_PREHASH_Set, perm_copy);
  274. #else
  275. msg->addU8Fast(_PREHASH_Set, perm_copy);
  276. #endif
  277. msg->addU32Fast(_PREHASH_Mask, PERM_COPY);
  278. msg->nextBlockFast(_PREHASH_ObjectData);
  279. msg->addU32Fast(_PREHASH_ObjectLocalID, local_id);
  280. msg->addU8Fast(_PREHASH_Field, PERM_NEXT_OWNER);
  281. #if MESSAGE_TEMPLATE_FIXED
  282. msg->addBoolFast(_PREHASH_Set, perm_transfer);
  283. #else
  284. msg->addU8Fast(_PREHASH_Set, perm_transfer);
  285. #endif
  286. msg->addU32Fast(_PREHASH_Mask, PERM_TRANSFER);
  287. msg->nextBlockFast(_PREHASH_ObjectData);
  288. msg->addU32Fast(_PREHASH_ObjectLocalID, local_id);
  289. msg->addU8Fast(_PREHASH_Field, PERM_EVERYONE);
  290. #if MESSAGE_TEMPLATE_FIXED
  291. msg->addBoolFast(_PREHASH_Set, perm_all_copy);
  292. #else
  293. msg->addU8Fast(_PREHASH_Set, perm_all_copy);
  294. #endif
  295. msg->addU32Fast(_PREHASH_Mask, PERM_COPY);
  296. msg->nextBlockFast(_PREHASH_ObjectData);
  297. msg->addU32Fast(_PREHASH_ObjectLocalID, local_id);
  298. msg->addU8Fast(_PREHASH_Field, PERM_GROUP);
  299. #if MESSAGE_TEMPLATE_FIXED
  300. msg->addBoolFast(_PREHASH_Set, perm_group);
  301. #else
  302. msg->addU8Fast(_PREHASH_Set, perm_group);
  303. #endif
  304. msg->addU32Fast(_PREHASH_Mask,
  305. PERM_MODIFY | PERM_MOVE | PERM_COPY);
  306. msg->sendReliable(objectp->getRegion()->getHost());
  307. }
  308. HBObjectBackup::newPrim(objectp);
  309. }
  310. }
  311. LLViewerObject* LLViewerObjectList::processObjectUpdateFromCache(LLVOCacheEntry* entry,
  312. LLViewerRegion* regionp)
  313. {
  314. LL_TRACY_TIMER(TRC_PROCESS_OBJECTS);
  315. LLDataPacker* cached_dpp = entry->getDP();
  316. if (!cached_dpp)
  317. {
  318. return NULL; // Nothing cached.
  319. }
  320. #if 0
  321. // Cache Hit.
  322. entry->recordHit();
  323. #endif
  324. cached_dpp->reset();
  325. LLUUID fullid;
  326. cached_dpp->unpackUUID(fullid, "ID");
  327. U32 local_id;
  328. cached_dpp->unpackU32(local_id, "LocalID");
  329. LLPCode pcode = 0;
  330. cached_dpp->unpackU8(pcode, "PCode");
  331. if (mBlackListedObjects.count(fullid))
  332. {
  333. // This object was blacklisted/derendered: do not restore it from
  334. // cache.
  335. return NULL;
  336. }
  337. bool just_created = false;
  338. LLViewerObject* objectp = findObject(fullid);
  339. if (objectp)
  340. {
  341. if (!objectp->isDead() &&
  342. (objectp->mLocalID != entry->getLocalID() ||
  343. objectp->getRegion() != regionp))
  344. {
  345. removeFromLocalIDTable(objectp);
  346. setUUIDAndLocal(fullid, entry->getLocalID(),
  347. regionp->getHost().getAddress(),
  348. regionp->getHost().getPort());
  349. if (objectp->mLocalID != entry->getLocalID())
  350. {
  351. // Update local ID in object with the one sent from the region
  352. objectp->setlocalID(entry->getLocalID());
  353. }
  354. if (objectp->getRegion() != regionp)
  355. {
  356. // Object changed region, so update it
  357. objectp->updateRegion(regionp); // for LLVOAvatar
  358. }
  359. }
  360. #if 0 // Should fall through if already loaded because may need to update the
  361. // object.
  362. else
  363. {
  364. return objectp; // Already loaded.
  365. }
  366. #endif
  367. }
  368. else if (mDeadObjects.count(fullid))
  369. {
  370. LL_DEBUGS("ViewerObject") << "Attempt to re-create a dead object for: "
  371. << fullid << ". Skipping." << LL_ENDL;
  372. return NULL;
  373. }
  374. else
  375. {
  376. objectp = createObjectFromCache(pcode, regionp, fullid,
  377. entry->getLocalID());
  378. if (!objectp)
  379. {
  380. llinfos << "Failure to create object: " << fullid << llendl;
  381. return NULL;
  382. }
  383. just_created = true;
  384. ++mNumNewObjects;
  385. }
  386. if (objectp->isDead())
  387. {
  388. llwarns << "Dead object " << objectp->mID << " in UUID map" << llendl;
  389. }
  390. processUpdateCore(objectp, NULL, 0, OUT_FULL_CACHED, cached_dpp,
  391. just_created, true);
  392. // Just in case, reload update flags from cache:
  393. U32 flags = entry->getUpdateFlags();
  394. objectp->loadFlags(flags);
  395. if (entry->getHitCount() > 0)
  396. {
  397. objectp->setLastUpdateType(OUT_FULL_CACHED);
  398. }
  399. else
  400. {
  401. objectp->setLastUpdateType(OUT_FULL_COMPRESSED); // Newly cached
  402. objectp->setLastUpdateCached(true);
  403. }
  404. if (objectp->getPCode() == LL_PCODE_LEGACY_AVATAR)
  405. {
  406. LLVOAvatar::setAvatarCullingDirty();
  407. }
  408. return objectp;
  409. }
  410. void LLViewerObjectList::processObjectUpdate(LLMessageSystem* msg,
  411. void** user_data,
  412. EObjectUpdateType update_type,
  413. bool compressed)
  414. {
  415. LL_FAST_TIMER(FTM_PROCESS_OBJECTS);
  416. // Figure out which simulator these are from and get it's index.
  417. // Coordinates in simulators are region-local. Until we get region-locality
  418. // working on viewer we have to transform to absolute coordinates.
  419. S32 num_objects = msg->getNumberOfBlocksFast(_PREHASH_ObjectData);
  420. #if 0
  421. if (!compressed && update_type != OUT_FULL)
  422. {
  423. S32 size;
  424. if (msg->getReceiveCompressedSize())
  425. {
  426. size = msg->getReceiveCompressedSize();
  427. }
  428. else
  429. {
  430. size = msg->getReceiveSize();
  431. }
  432. llinfos << "Received terse " << num_objects << " in " << size
  433. << " bytes (" << size / num_objects << ")" << llendl;
  434. }
  435. else
  436. {
  437. S32 size;
  438. if (msg->getReceiveCompressedSize())
  439. {
  440. size = msg->getReceiveCompressedSize();
  441. }
  442. else
  443. {
  444. size = msg->getReceiveSize();
  445. }
  446. llinfos << "Received " << num_objects << " in " << size
  447. << " bytes (" << size / num_objects << ")" << llendl;
  448. }
  449. #endif
  450. U64 region_handle;
  451. msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
  452. LLViewerRegion* regionp = gWorld.getRegionFromHandle(region_handle);
  453. if (!regionp)
  454. {
  455. llwarns << "Object update from unknown region ! " << region_handle
  456. << llendl;
  457. return;
  458. }
  459. U8 compressed_dpbuffer[2048];
  460. LLDataPackerBinaryBuffer compressed_dp(compressed_dpbuffer, 2048);
  461. LLPCode pcode = 0;
  462. U32 local_id;
  463. LLUUID fullid;
  464. bool got_avatars = false;
  465. for (S32 i = 0; i < num_objects; ++i)
  466. {
  467. bool just_created = false;
  468. // Update object cache if it is a full-update or terse update
  469. bool update_cache = false;
  470. if (compressed)
  471. {
  472. compressed_dp.reset();
  473. S32 uncompressed_length = msg->getSizeFast(_PREHASH_ObjectData, i,
  474. _PREHASH_Data);
  475. msg->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_Data,
  476. compressed_dpbuffer, 0, i, 2048);
  477. compressed_dp.assignBuffer(compressed_dpbuffer,
  478. uncompressed_length);
  479. if (update_type != OUT_TERSE_IMPROVED)
  480. {
  481. U32 flags = 0;
  482. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags,
  483. flags, i);
  484. compressed_dp.unpackUUID(fullid, "ID");
  485. compressed_dp.unpackU32(local_id, "LocalID");
  486. compressed_dp.unpackU8(pcode, "PCode");
  487. if (mDeadObjects.count(fullid))
  488. {
  489. LL_DEBUGS("ViewerObject") << "Attempt to update a dead object for: "
  490. << fullid << ". Skipping."
  491. << LL_ENDL;
  492. continue;
  493. }
  494. if (pcode == 0)
  495. {
  496. llwarns_once << "Invalid Pcode (0) for object " << fullid
  497. << " (LocalID: " << local_id << llendl;
  498. continue;
  499. }
  500. if ((flags & FLAGS_TEMPORARY_ON_REZ) == 0)
  501. {
  502. // Send to object cache
  503. regionp->cacheFullUpdate(compressed_dp, flags);
  504. continue;
  505. }
  506. }
  507. else // OUT_TERSE_IMPROVED
  508. {
  509. update_cache = true;
  510. compressed_dp.unpackU32(local_id, "LocalID");
  511. getUUIDFromLocal(fullid, local_id, msg->getSenderIP(),
  512. msg->getSenderPort());
  513. if (fullid.isNull())
  514. {
  515. LL_DEBUGS("ViewerObject") << "Update for unknown localid: "
  516. << local_id << " - Host: "
  517. << msg->getSender() << ":"
  518. << msg->getSenderPort()
  519. << LL_ENDL;
  520. ++mNumUnknownUpdates;
  521. }
  522. }
  523. }
  524. else if (update_type != OUT_FULL)
  525. {
  526. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
  527. getUUIDFromLocal(fullid, local_id, msg->getSenderIP(),
  528. msg->getSenderPort());
  529. if (fullid.isNull())
  530. {
  531. LL_DEBUGS("ViewerObject") << "Update for unknown localid: "
  532. << local_id << " - Host: "
  533. << msg->getSender() << ":"
  534. << msg->getSenderPort()
  535. << LL_ENDL;
  536. ++mNumUnknownUpdates;
  537. }
  538. }
  539. else
  540. {
  541. update_cache = true;
  542. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FullID, fullid, i);
  543. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
  544. LL_DEBUGS("ViewerObject") << "Full Update, obj: " << local_id
  545. << " - Global ID: " << fullid
  546. << " - From: " << msg->getSender()
  547. << LL_ENDL;
  548. }
  549. if (mBlackListedObjects.count(fullid))
  550. {
  551. // This object was blaclisted/derendered: do not recreate it
  552. continue;
  553. }
  554. if (mDeadObjects.count(fullid))
  555. {
  556. LL_DEBUGS("ViewerObject") << "Attempt to update a dead object for: "
  557. << fullid << ". Skipping."
  558. << LL_ENDL;
  559. continue;
  560. }
  561. LLViewerObject* objectp = findObject(fullid);
  562. bool new_object = objectp == NULL;
  563. if (update_cache)
  564. {
  565. // Update object cache if the object receives a full-update or
  566. // terse update
  567. objectp = regionp->updateCacheEntry(local_id, objectp);
  568. }
  569. if (new_object && objectp)
  570. {
  571. add_newly_created_object(objectp->mID);
  572. }
  573. if (mKilledAttachments.count(fullid))
  574. {
  575. bool remove = true;
  576. LL_DEBUGS("Attachment") << "Update for a killed attachment object: "
  577. << fullid;
  578. if (!objectp && mDeadObjects.count(fullid))
  579. {
  580. #if LL_IGNORE_DEAD
  581. LL_CONT << " - Object is in dead list !";
  582. #else
  583. LL_CONT << " - Object is in dead list and this update will be discarded !";
  584. remove = false;
  585. #endif
  586. }
  587. LL_CONT << LL_ENDL;
  588. if (remove)
  589. {
  590. mKilledAttachments.erase(fullid);
  591. }
  592. }
  593. // This looks like it will break if the local_id of the object does not
  594. // change upon boundary crossing, but we check for region id matching
  595. // later...
  596. // Reset object local id and region pointer if things have changed.
  597. if (objectp &&
  598. (objectp->mLocalID != local_id || objectp->getRegion() != regionp))
  599. {
  600. #if 0
  601. if (objectp->getRegion())
  602. {
  603. llinfos << "Local ID change: Removing object from table, local ID "
  604. << objectp->mLocalID << ", id from message "
  605. << local_id << ", from "
  606. << LLHost(objectp->getRegion()->getHost().getAddress(),
  607. objectp->getRegion()->getHost().getPort())
  608. << ", full id " << fullid << ", objects id "
  609. << objectp->getID() << ", regionp " << (U32)regionp
  610. << ", object region " << (U32)objectp->getRegion()
  611. << llendl;
  612. }
  613. #endif
  614. removeFromLocalIDTable(objectp);
  615. setUUIDAndLocal(fullid, local_id, msg->getSenderIP(),
  616. msg->getSenderPort());
  617. // Update local ID in object with the one sent from the region
  618. objectp->setlocalID(local_id);
  619. if (objectp->getRegion() != regionp)
  620. {
  621. // Object changed region, so update it
  622. objectp->updateRegion(regionp); // for LLVOAvatar
  623. }
  624. }
  625. if (!objectp)
  626. {
  627. if (compressed)
  628. {
  629. if (update_type == OUT_TERSE_IMPROVED)
  630. {
  631. LL_DEBUGS("ViewerObject") << "Terse update for an unknown object: "
  632. << fullid << LL_ENDL;
  633. continue;
  634. }
  635. }
  636. else
  637. {
  638. if (update_type != OUT_FULL)
  639. {
  640. LL_DEBUGS("ViewerObject") << "Terse update for an unknown object: "
  641. << fullid << LL_ENDL;
  642. continue;
  643. }
  644. msg->getU8Fast(_PREHASH_ObjectData, _PREHASH_PCode, pcode, i);
  645. }
  646. #if LL_IGNORE_DEAD
  647. if (mDeadObjects.count(fullid))
  648. {
  649. ++mNumDeadObjectUpdates;
  650. LL_DEBUGS("ViewerObject") << "Update for a dead object: "
  651. << fullid << LL_ENDL;
  652. continue;
  653. }
  654. #endif
  655. objectp = createObject(pcode, regionp, fullid, local_id,
  656. msg->getSender());
  657. if (!objectp)
  658. {
  659. llwarns << "CreateObject failure for object: " << fullid
  660. << llendl;
  661. continue;
  662. }
  663. just_created = true;
  664. ++mNumNewObjects;
  665. }
  666. if (objectp->isDead())
  667. {
  668. llwarns << "Dead object " << objectp->mID << " in UUID map"
  669. << llendl;
  670. }
  671. if (compressed)
  672. {
  673. if (update_type != OUT_TERSE_IMPROVED)
  674. {
  675. objectp->setlocalID(local_id);
  676. }
  677. processUpdateCore(objectp, user_data, i, update_type,
  678. &compressed_dp, just_created);
  679. #if 1
  680. if (update_type != OUT_TERSE_IMPROVED)
  681. {
  682. U32 flags = 0;
  683. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags,
  684. flags, i);
  685. if (!(flags & FLAGS_TEMPORARY_ON_REZ))
  686. {
  687. objectp->mRegionp->cacheFullUpdate(objectp, compressed_dp,
  688. flags);
  689. objectp->setLastUpdateCached(true);
  690. }
  691. }
  692. #endif
  693. }
  694. else
  695. {
  696. if (update_type == OUT_FULL)
  697. {
  698. objectp->setlocalID(local_id);
  699. }
  700. processUpdateCore(objectp, user_data, i, update_type, NULL,
  701. just_created);
  702. }
  703. objectp->setLastUpdateType(update_type);
  704. got_avatars |= objectp->getPCode() == LL_PCODE_LEGACY_AVATAR;
  705. }
  706. if (got_avatars)
  707. {
  708. LLVOAvatar::setAvatarCullingDirty();
  709. }
  710. }
  711. void LLViewerObjectList::processCompressedObjectUpdate(LLMessageSystem* msg,
  712. void** user_data,
  713. EObjectUpdateType t)
  714. {
  715. processObjectUpdate(msg, user_data, t, true);
  716. }
  717. void LLViewerObjectList::processCachedObjectUpdate(LLMessageSystem* msg,
  718. void** user_data,
  719. EObjectUpdateType t)
  720. {
  721. #if 0
  722. processObjectUpdate(msg, user_data, t, false);
  723. #endif
  724. S32 num_objects = msg->getNumberOfBlocksFast(_PREHASH_ObjectData);
  725. U64 region_handle;
  726. msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
  727. LLViewerRegion* regionp = gWorld.getRegionFromHandle(region_handle);
  728. if (!regionp)
  729. {
  730. llwarns << "Object update from unknown region " << region_handle
  731. << llendl;
  732. return;
  733. }
  734. for (S32 i = 0; i < num_objects; ++i)
  735. {
  736. U32 local_id, crc, flags;
  737. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
  738. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_CRC, crc, i);
  739. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags,
  740. flags, i);
  741. // Lookup data packer and add this id to cache miss lists if necessary.
  742. U8 cache_miss_type = LLViewerRegion::CACHE_MISS_TYPE_NONE;
  743. regionp->probeCache(local_id, crc, flags, cache_miss_type);
  744. }
  745. }
  746. void LLViewerObjectList::dirtyAllObjectInventory()
  747. {
  748. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  749. {
  750. LLViewerObject* objectp = mObjects[i];
  751. if (objectp)
  752. {
  753. objectp->dirtyInventory();
  754. }
  755. }
  756. }
  757. void LLViewerObjectList::updateApparentAngles()
  758. {
  759. const S32 objects_size = (S32)mObjects.size();
  760. // The list can have shrunken down since mCurLazyUpdateIndex was last
  761. // updated.
  762. if (mCurLazyUpdateIndex >= objects_size)
  763. {
  764. mCurLazyUpdateIndex = 0;
  765. }
  766. S32 num_updates, max_value;
  767. if (mCurBin == NUM_BINS - 1)
  768. {
  769. // Remainder (mObjects.size() could have changed)
  770. num_updates = objects_size - mCurLazyUpdateIndex;
  771. max_value = objects_size;
  772. }
  773. else
  774. {
  775. num_updates = objects_size / NUM_BINS + 1;
  776. max_value = llmin(objects_size, mCurLazyUpdateIndex + num_updates);
  777. }
  778. bool got_avatars = false;
  779. LLViewerObject* objectp;
  780. if (gHoverViewp)
  781. {
  782. // Slam priorities for textures that we care about (hovered, selected,
  783. // and focused). Hovered. Assumes only one level deep of parenting
  784. objectp = gHoverViewp->getLastHoverObject();
  785. if (objectp && !objectp->isDead())
  786. {
  787. objectp->boostTexturePriority();
  788. got_avatars |= objectp->getPCode() == LL_PCODE_LEGACY_AVATAR;
  789. }
  790. }
  791. // Focused
  792. objectp = gAgent.getFocusObject();
  793. if (objectp && !objectp->isDead())
  794. {
  795. objectp->boostTexturePriority();
  796. got_avatars |= objectp->getPCode() == LL_PCODE_LEGACY_AVATAR;
  797. }
  798. // Selected
  799. struct f final : public LLSelectedObjectFunctor
  800. {
  801. bool apply(LLViewerObject* objectp) override
  802. {
  803. if (objectp && !objectp->isDead())
  804. {
  805. objectp->boostTexturePriority();
  806. }
  807. return true;
  808. }
  809. } func;
  810. gSelectMgr.getSelection()->applyToRootObjects(&func);
  811. // Iterate through some of the objects and lazy update their texture
  812. // priorities
  813. #if LL_OPENMP
  814. objectp = NULL;
  815. size_t num_objects = max_value - mCurLazyUpdateIndex;
  816. std::vector<LLViewerObject*> objects(num_objects, objectp);
  817. # pragma omp parallel for private(objectp) reduction(|:got_avatars)
  818. for (S32 i = mCurLazyUpdateIndex; i < max_value; ++i)
  819. {
  820. objectp = mObjects[i];
  821. if (objectp && !objectp->isDead())
  822. {
  823. got_avatars |= objectp->getPCode() == LL_PCODE_LEGACY_AVATAR;
  824. // Update distance & gpw
  825. // Also sets the approx. pixel area:
  826. objectp->setPixelAreaAndAngle();
  827. // Store for later textures update
  828. objects[i - mCurLazyUpdateIndex] = objectp;
  829. }
  830. }
  831. // This CANNOT be called from an OMP thread, because updateTextures() may
  832. // result in OpenGL calls, that might themselves be threaded via pthread !
  833. for (S32 i = 0, count = objects.size(); i < count; ++i)
  834. {
  835. objectp = objects[i];
  836. if (objectp && !objectp->isDead())
  837. {
  838. // Update the image levels of textures for this object:
  839. objects[i]->updateTextures();
  840. }
  841. }
  842. #else
  843. for (S32 i = mCurLazyUpdateIndex; i < max_value; ++i)
  844. {
  845. objectp = mObjects[i];
  846. if (objectp && !objectp->isDead())
  847. {
  848. got_avatars |= objectp->getPCode() == LL_PCODE_LEGACY_AVATAR;
  849. // Update distance & gpw
  850. // Also sets the approx. pixel area:
  851. objectp->setPixelAreaAndAngle();
  852. // Update the image levels of textures for this object:
  853. objectp->updateTextures();
  854. }
  855. }
  856. #endif
  857. mCurLazyUpdateIndex = max_value;
  858. if ((size_t)mCurLazyUpdateIndex == mObjects.size())
  859. {
  860. // Restart
  861. mCurLazyUpdateIndex = 0;
  862. // Keep in sync with index (mObjects.size() could have changed)
  863. mCurBin = 0;
  864. }
  865. else
  866. {
  867. mCurBin = (mCurBin + 1) % NUM_BINS;
  868. }
  869. if (got_avatars || LLVOAvatar::avatarCullingDirty())
  870. {
  871. LLVOAvatar::cullAvatarsByPixelArea();
  872. }
  873. }
  874. void LLViewerObjectList::update()
  875. {
  876. // Update global timers
  877. F32 last_time = gFrameTimeSeconds;
  878. // This will become the new gFrameTime when the update is done
  879. U64 time = LLTimer::totalTime();
  880. F64 time_diff = U64_to_F64(time - gFrameTime) / (F64)SEC_TO_MICROSEC;
  881. if (time_diff < 0.0)
  882. {
  883. // Time went backwards... Use last frame interval as an approximation.
  884. time_diff = gFrameIntervalSeconds;
  885. // Adjust start time accordingly...
  886. gStartTime += time - gFrameTime;
  887. }
  888. gFrameTime = time;
  889. F64 time_since_start = U64_to_F64(gFrameTime - gStartTime) /
  890. (F64)SEC_TO_MICROSEC;
  891. gFrameTimeSeconds = (F32)time_since_start;
  892. gFrameIntervalSeconds = gFrameTimeSeconds - last_time;
  893. if (gFrameIntervalSeconds < 0.f)
  894. {
  895. gFrameIntervalSeconds = 0.f;
  896. }
  897. // Clear avatar LOD change counter
  898. LLVOAvatar::sNumLODChangesThisFrame = 0;
  899. const F64 frame_time = LLFrameTimer::getElapsedSeconds();
  900. // Make a copy of the list in case something in idleUpdate() messes with it
  901. S32 idle_count = 0;
  902. {
  903. LL_FAST_TIMER(FTM_OBJECTLIST_COPY);
  904. S32 count = mActiveObjects.size();
  905. if (count > mIdleListSlots)
  906. {
  907. // Minimize fragmentation and reallocation time overhead:
  908. mIdleList.clear();
  909. mIdleListSlots = 125 * count / 100;
  910. mIdleList.reserve(mIdleListSlots);
  911. }
  912. S32 idle_list_old_size = mIdleList.size();
  913. for (S32 i = 0; i < count; )
  914. {
  915. LLViewerObject* objectp = mActiveObjects[i];
  916. if (!objectp)
  917. {
  918. // There should not be any NULL pointer in the list, but they
  919. // have caused crashes before.
  920. llwarns << "mActiveObjects has a NULL object. Removing."
  921. << llendl;
  922. if (i != --count)
  923. {
  924. mActiveObjects[i] = std::move(mActiveObjects.back());
  925. }
  926. mActiveObjects.pop_back();
  927. continue;
  928. }
  929. if (objectp->isDead())
  930. {
  931. // There should not be any dead object in the list, but they
  932. // have caused crashes before.
  933. llwarns << "mActiveObjects has dead object "
  934. << objectp->getID() << ". Removing." << llendl;
  935. mDeadList.push_back(objectp);
  936. }
  937. else if (idle_count >= idle_list_old_size)
  938. {
  939. mIdleList.push_back(objectp);
  940. ++idle_count;
  941. }
  942. else
  943. {
  944. mIdleList[idle_count++] = objectp;
  945. }
  946. ++i;
  947. }
  948. }
  949. S32 count = mDeadList.size();
  950. if (count)
  951. {
  952. LL_DEBUGS("ViewerObject") << "Removing detected dead objects from the active objects list."
  953. << LL_ENDL;
  954. for (S32 i = 0; i < count; ++i )
  955. {
  956. cleanupReferences(mDeadList[i]);
  957. }
  958. mDeadList.clear();
  959. }
  960. if (LLPipeline::sFreezeTime)
  961. {
  962. for (S32 i = 0; i < idle_count; ++i)
  963. {
  964. LLViewerObject* objectp = mIdleList[i];
  965. if (objectp->isAvatar() ||
  966. objectp->getPCode() == LLViewerObject::LL_VO_CLOUDS)
  967. {
  968. objectp->idleUpdate(frame_time);
  969. }
  970. }
  971. }
  972. else
  973. {
  974. for (S32 i = 0; i < idle_count; ++i)
  975. {
  976. LLViewerObject* objectp = mIdleList[i];
  977. objectp->idleUpdate(frame_time);
  978. }
  979. // Update flexible objects
  980. LLVolumeImplFlexible::updateClass();
  981. if (LLVOVolume::sAnimateTextures)
  982. {
  983. // Update animated textures
  984. LLViewerTextureAnim::updateClass();
  985. }
  986. }
  987. fetchObjectCosts();
  988. fetchPhysicsFlags();
  989. mNumSizeCulled = 0;
  990. mNumVisCulled = 0;
  991. // Compute all sorts of time-based stats; do not factor frames that were
  992. // paused into the stats.
  993. if (!mWasPaused)
  994. {
  995. gViewerStats.updateFrameStats(time_diff);
  996. }
  997. #if 0
  998. // Debugging code for viewing orphans, and orphaned parents
  999. LLUUID id;
  1000. std::string id_str;
  1001. for (S32 i = 0, count = mOrphanParents.size(); i < count; ++i)
  1002. {
  1003. id = mIndexAndLocalIDToUUID[mOrphanParents[i]];
  1004. LLViewerObject* objectp = findObject(id);
  1005. if (objectp)
  1006. {
  1007. objectp->mID.toString(id_str);
  1008. std::string tmpstr = "Parent: " + id_str;
  1009. addDebugBeacon(objectp->getPositionAgent(), tmpstr, LLColor4::red,
  1010. LLColor4::white);
  1011. }
  1012. }
  1013. LLColor4 text_color;
  1014. std::string tmpstr;
  1015. for (S32 i = 0, count = mOrphanChildren.size(); i < count; ++i)
  1016. {
  1017. OrphanInfo oi = mOrphanChildren[i];
  1018. LLViewerObject* objectp = findObject(oi.mChildInfo);
  1019. if (objectp)
  1020. {
  1021. objectp->mID.toString(id_str);
  1022. if (objectp->getParent())
  1023. {
  1024. tmpstr = "ChP: " + id_str;
  1025. text_color = LLColor4::green;
  1026. }
  1027. else
  1028. {
  1029. tmpstr = "ChNoP: " + id_str;
  1030. text_color = LLColor4::red;
  1031. }
  1032. id = mIndexAndLocalIDToUUID[oi.mParentInfo];
  1033. addDebugBeacon(objectp->getPositionAgent() +
  1034. LLVector3(0.f, 0.f, -0.25f),
  1035. tmpstr, LLColor4::grey4,
  1036. text_color);
  1037. }
  1038. }
  1039. #endif
  1040. mNumObjectsStat.addValue((S32)(mObjects.size() - mDeadObjects.size()));
  1041. mNumActiveObjectsStat.addValue(idle_count);
  1042. mNumSizeCulledStat.addValue(mNumSizeCulled);
  1043. mNumVisCulledStat.addValue(mNumVisCulled);
  1044. }
  1045. // Issues HTTP request for stale object physics costs
  1046. void LLViewerObjectList::fetchObjectCosts()
  1047. {
  1048. if (mStaleObjectCost.empty())
  1049. {
  1050. return;
  1051. }
  1052. const std::string& url = gAgent.getRegionCapability("GetObjectCost");
  1053. if (url.empty())
  1054. {
  1055. mStaleObjectCost.clear();
  1056. mPendingObjectCost.clear();
  1057. return;
  1058. }
  1059. gCoros.launch("LLViewerObjectList::fetchObjectCostsCoro",
  1060. boost::bind(&LLViewerObjectList::fetchObjectCostsCoro, this,
  1061. url));
  1062. }
  1063. void LLViewerObjectList::fetchObjectCostsCoro(const std::string& url)
  1064. {
  1065. LLSD object_ids = LLSD::emptyArray();
  1066. S32 count = 0;
  1067. uuid_list_t::iterator it = mStaleObjectCost.begin();
  1068. while (it != mStaleObjectCost.end() && count < gMaxObjectsPerFetch)
  1069. {
  1070. // Check to see if a request for this object has already been made.
  1071. if (mPendingObjectCost.find(*it) == mPendingObjectCost.end())
  1072. {
  1073. mPendingObjectCost.emplace(*it);
  1074. object_ids.append(*it);
  1075. ++count;
  1076. }
  1077. mStaleObjectCost.erase(it++);
  1078. }
  1079. if (object_ids.size() < 1)
  1080. {
  1081. return;
  1082. }
  1083. LLSD body = LLSD::emptyMap();
  1084. body["object_ids"] = object_ids;
  1085. LLCoreHttpUtil::HttpCoroutineAdapter adapter("fetchObjectCostsCoro");
  1086. LLSD result = adapter.postAndSuspend(url, body);
  1087. LLCore::HttpStatus status =
  1088. LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(result);
  1089. if (!status || result.has("error"))
  1090. {
  1091. if (result.has("error"))
  1092. {
  1093. const LLSD& error = result["error"];
  1094. std::string identifier;
  1095. if (error.has("identifier"))
  1096. {
  1097. identifier = error["identifier"].asString();
  1098. }
  1099. llwarns << "Application level error when fetching object cost. Message: "
  1100. << error["message"].asString()
  1101. << " - Identifier: " << identifier << llendl;
  1102. if (gMaxObjectsPerFetch > 32 &&
  1103. identifier.find("TooManyObjects") != std::string::npos)
  1104. {
  1105. // Reduce the maximum number of objects per fetch by 25%.
  1106. gMaxObjectsPerFetch = 4 * gMaxObjectsPerFetch / 5;
  1107. llinfos << "Reduced maximum objects limit per fetch to: "
  1108. << gMaxObjectsPerFetch << llendl;
  1109. }
  1110. }
  1111. // *TODO: No more hard coding
  1112. for (LLSD::array_iterator iter = object_ids.beginArray(),
  1113. end = object_ids.endArray();
  1114. iter != end; ++iter)
  1115. {
  1116. onObjectCostFetchFailure(iter->asUUID());
  1117. }
  1118. return;
  1119. }
  1120. // Success, grab the resource cost and linked set costs for an object if
  1121. // one was returned
  1122. for (LLSD::array_iterator it = object_ids.beginArray(),
  1123. end = object_ids.endArray();
  1124. it != end; ++it)
  1125. {
  1126. LLUUID object_id = it->asUUID();
  1127. // If the object was added to the StaleObjectCost set after it had been
  1128. // added to mPendingObjectCost it would still be in the StaleObjectCost
  1129. // set when we got the response back.
  1130. mStaleObjectCost.erase(object_id);
  1131. // Check to see if the request contains data for the object
  1132. if (result.has(it->asString()))
  1133. {
  1134. LLSD data = result[it->asString()];
  1135. F32 link_cost = data["linked_set_resource_cost"].asReal();
  1136. F32 object_cost = data["resource_cost"].asReal();
  1137. F32 physics_cost = data["physics_cost"].asReal();
  1138. F32 linkset_cost = data["linked_set_physics_cost"].asReal();
  1139. updateObjectCost(object_id, object_cost, link_cost, physics_cost,
  1140. linkset_cost);
  1141. }
  1142. else
  1143. {
  1144. // *TODO: Give user feedback about the missing data ?
  1145. onObjectCostFetchFailure(object_id);
  1146. }
  1147. }
  1148. }
  1149. // Issues HTTP request for stale object physics flags
  1150. void LLViewerObjectList::fetchPhysicsFlags()
  1151. {
  1152. if (mStalePhysicsFlags.empty())
  1153. {
  1154. return;
  1155. }
  1156. const std::string& url =
  1157. gAgent.getRegionCapability("GetObjectPhysicsData");
  1158. if (url.empty())
  1159. {
  1160. mStalePhysicsFlags.clear();
  1161. mPendingPhysicsFlags.clear();
  1162. return;
  1163. }
  1164. gCoros.launch("LLViewerObjectList::fetchPhysicsFlagsCoro",
  1165. boost::bind(&LLViewerObjectList::fetchPhysicsFlagsCoro, this,
  1166. url));
  1167. }
  1168. void LLViewerObjectList::fetchPhysicsFlagsCoro(const std::string& url)
  1169. {
  1170. LLSD object_ids;
  1171. S32 object_index = 0;
  1172. uuid_list_t::iterator it = mStalePhysicsFlags.begin();
  1173. while (it != mStalePhysicsFlags.end() &&
  1174. object_index < gMaxObjectsPerFetch)
  1175. {
  1176. // Check to see if a request for this object has already been made.
  1177. if (mPendingPhysicsFlags.find(*it) == mPendingPhysicsFlags.end())
  1178. {
  1179. mPendingPhysicsFlags.emplace(*it);
  1180. object_ids[object_index++] = *it;
  1181. }
  1182. mStalePhysicsFlags.erase(it++);
  1183. }
  1184. if (object_ids.size() < 1)
  1185. {
  1186. return;
  1187. }
  1188. LLSD body = LLSD::emptyMap();
  1189. body["object_ids"] = object_ids;
  1190. LLCoreHttpUtil::HttpCoroutineAdapter adapter("fetchPhysicsFlagsCoro");
  1191. LLSD result = adapter.postAndSuspend(url, body);
  1192. LLCore::HttpStatus status =
  1193. LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(result);
  1194. if (!status || result.has("error"))
  1195. {
  1196. if (result.has("error"))
  1197. {
  1198. const LLSD& error = result["error"];
  1199. std::string identifier;
  1200. if (error.has("identifier"))
  1201. {
  1202. identifier = error["identifier"].asString();
  1203. }
  1204. llwarns << "Application level error when fetching object physics flags. Message: "
  1205. << error["message"].asString()
  1206. << " - Identifier: " << identifier << llendl;
  1207. if (gMaxObjectsPerFetch > 32 &&
  1208. identifier.find("TooManyObjects") != std::string::npos)
  1209. {
  1210. // Reduce the maximum number of objects per fetch by 25%.
  1211. gMaxObjectsPerFetch = 4 * gMaxObjectsPerFetch / 5;
  1212. llinfos << "Reduced maximum objects limit per fetch to: "
  1213. << gMaxObjectsPerFetch << llendl;
  1214. }
  1215. }
  1216. for (LLSD::array_iterator iter = object_ids.beginArray(),
  1217. end = object_ids.endArray();
  1218. iter != end; ++iter)
  1219. {
  1220. onPhysicsFlagsFetchFailure(iter->asUUID());
  1221. }
  1222. return;
  1223. }
  1224. // Success, grab the physics parameters for an object if one was returned
  1225. for (LLSD::array_iterator it = object_ids.beginArray(),
  1226. end = object_ids.endArray();
  1227. it != end; ++it)
  1228. {
  1229. LLUUID object_id = it->asUUID();
  1230. // Check to see if the request contains data for the object
  1231. if (result.has(it->asString()))
  1232. {
  1233. const LLSD& data = result[it->asString()];
  1234. S32 shapeType = data["PhysicsShapeType"].asInteger();
  1235. updatePhysicsShapeType(object_id, shapeType);
  1236. if (data.has("Density"))
  1237. {
  1238. F32 density = data["Density"].asReal();
  1239. F32 friction = data["Friction"].asReal();
  1240. F32 restitution = data["Restitution"].asReal();
  1241. F32 gravity = data["GravityMultiplier"].asReal();
  1242. updatePhysicsProperties(object_id, density, friction,
  1243. restitution, gravity);
  1244. }
  1245. }
  1246. else
  1247. {
  1248. // *TODO: Give user feedback about the missing data?
  1249. onPhysicsFlagsFetchFailure(object_id);
  1250. }
  1251. }
  1252. }
  1253. bool LLViewerObjectList::gotObjectPhysicsFlags(LLViewerObject* objectp)
  1254. {
  1255. // This will insert objectp in mStalePhysicsFlags if needed:
  1256. objectp->getPhysicsShapeType();
  1257. // Data has been retrieved if the object is not in either of the two lists:
  1258. const LLUUID& id = objectp->getID();
  1259. return mPendingPhysicsFlags.count(id) == 0 &&
  1260. mStalePhysicsFlags.count(id) == 0;
  1261. }
  1262. void LLViewerObjectList::clearDebugText()
  1263. {
  1264. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  1265. {
  1266. LLViewerObject* objectp = mObjects[i];
  1267. if (objectp && !objectp->isDead())
  1268. {
  1269. objectp->setDebugText("");
  1270. }
  1271. }
  1272. }
  1273. void LLViewerObjectList::cleanupReferences(LLViewerObject* objectp)
  1274. {
  1275. LL_TRACY_TIMER(TRC_OBJ_CLEANUP_REF);
  1276. if (!objectp)
  1277. {
  1278. llwarns << "NULL object pointer passed." << llendl;
  1279. return;
  1280. }
  1281. const LLUUID& object_id = objectp->mID;
  1282. // Cleanup any references we have to this object. Remove from object maps
  1283. // so that no one can look it up.
  1284. mUUIDObjectMap.erase(object_id);
  1285. mUUIDAvatarMap.erase(object_id);
  1286. if (mDeadObjects.count(object_id))
  1287. {
  1288. LL_DEBUGS("ViewerObject") << "Object " << object_id
  1289. << " already on dead list !" << LL_ENDL;
  1290. }
  1291. else
  1292. {
  1293. mDeadObjects.emplace(object_id);
  1294. }
  1295. removeFromLocalIDTable(objectp);
  1296. if (objectp->onActiveList())
  1297. {
  1298. LL_DEBUGS("ViewerObject") << "Removing " << object_id << " "
  1299. << objectp->getPCodeString()
  1300. << " from active list." << LL_ENDL;
  1301. objectp->setOnActiveList(false);
  1302. removeFromActiveList(objectp);
  1303. }
  1304. if (objectp->isOnMap())
  1305. {
  1306. removeFromMap(objectp);
  1307. }
  1308. }
  1309. bool LLViewerObjectList::killObject(LLViewerObject* objectp)
  1310. {
  1311. // Do not ever kill gAgentAvatarp, just force it to the agent's region
  1312. // unless region is NULL which is assumed to mean you are logging out.
  1313. if (objectp == gAgentAvatarp && gAgent.getRegion())
  1314. {
  1315. objectp->setRegion(gAgent.getRegion());
  1316. return false;
  1317. }
  1318. // When we are killing objects, all we do is mark them as dead.
  1319. // We clean up the dead objects later.
  1320. if (objectp)
  1321. {
  1322. #if 0 // NOT needed for the Cool VL Viewer; the only occurrence of such
  1323. // a self-destructing object in markDead() (puppet avatar unlinking)
  1324. // was already identified and fixed by me in LLViewerObject::markDead()
  1325. // (see the comment at the end of that method)... Plus, smart pointers
  1326. // to killed objects are kept in mObjects till cleanDeadObjects() is
  1327. // called, so the reason given below is bullshit. HB
  1328. // We are going to cleanup a lot of smart pointers to this object; they
  1329. // might be last, and object being NULLed while inside its own function
  1330. // would cause a crash. So, create a smart pointer to make sure the
  1331. // object will stay alive untill markDead() finishes.
  1332. LLPointer<LLViewerObject> objp(objectp);
  1333. objp->markDead(); // Does the right thing if object already dead
  1334. #else
  1335. objectp->markDead(); // Does the right thing if object already dead
  1336. #endif
  1337. return true;
  1338. }
  1339. return false;
  1340. }
  1341. void LLViewerObjectList::killObjects(LLViewerRegion* regionp)
  1342. {
  1343. LLTimer kill_timer;
  1344. S32 killed = 0;
  1345. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  1346. {
  1347. LLViewerObject* objectp = mObjects[i];
  1348. if (objectp && objectp->mRegionp == regionp)
  1349. {
  1350. ++killed;
  1351. killObject(objectp);
  1352. }
  1353. }
  1354. // Have to clean right away because the region is becoming invalid.
  1355. cleanDeadObjects();
  1356. llinfos << "Removed " << killed << " objects for region "
  1357. << regionp->getIdentity() << " in "
  1358. << kill_timer.getElapsedTimeF64() * 1000.0 << "ms" << llendl;
  1359. }
  1360. // Used only on global destruction.
  1361. void LLViewerObjectList::killAllObjects()
  1362. {
  1363. llinfos << "Marking all objects dead..." << llendl;
  1364. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  1365. {
  1366. LLViewerObject* objectp = mObjects[i];
  1367. if (objectp)
  1368. {
  1369. killObject(objectp);
  1370. // Object must be dead, or it is the LLVOAvatarSelf which never
  1371. // dies
  1372. llassert(objectp == gAgentAvatarp || objectp->isDead());
  1373. }
  1374. }
  1375. llinfos << "Cleaning up dead objects..." << llendl;
  1376. cleanDeadObjects();
  1377. if (!mDeadObjects.empty())
  1378. {
  1379. llwarns << "There are still has entries left in mDeadObjects: "
  1380. << mObjects.size() << llendl;
  1381. mDeadObjects.clear();
  1382. }
  1383. if (!mObjects.empty())
  1384. {
  1385. llwarns << "There are still has entries left in mObjects: "
  1386. << mObjects.size() << llendl;
  1387. mObjects.clear();
  1388. }
  1389. if (!mActiveObjects.empty())
  1390. {
  1391. llwarns << "Some objects still on active object list !" << llendl;
  1392. mActiveObjects.clear();
  1393. }
  1394. if (!mMapObjects.empty())
  1395. {
  1396. llwarns << "Some objects still on map object list !" << llendl;
  1397. mMapObjects.clear();
  1398. }
  1399. }
  1400. void LLViewerObjectList::cleanDeadObjects()
  1401. {
  1402. U32 num_dead_objects = mDeadObjects.size();
  1403. if (!num_dead_objects)
  1404. {
  1405. // No dead object, so we do not need to scan objects list.
  1406. return;
  1407. }
  1408. U32 num_removed = 0;
  1409. U32 null_objects = 0;
  1410. vobj_list_t::iterator iter = mObjects.begin();
  1411. while (iter != mObjects.end())
  1412. {
  1413. LLViewerObject* objectp = (*iter).get();
  1414. if (!objectp || objectp->isDead())
  1415. {
  1416. if (iter + 1 != mObjects.end())
  1417. {
  1418. *iter = std::move(mObjects.back());
  1419. }
  1420. mObjects.pop_back();
  1421. if (objectp)
  1422. {
  1423. ++num_removed;
  1424. }
  1425. else
  1426. {
  1427. ++null_objects;
  1428. }
  1429. }
  1430. else
  1431. {
  1432. ++iter;
  1433. }
  1434. }
  1435. if (num_removed != num_dead_objects)
  1436. {
  1437. llwarns << "Removed " << num_removed
  1438. << " dead objects from the list while it was supposed to have "
  1439. << num_dead_objects << " such objects in it." << llendl;
  1440. llassert(false);
  1441. }
  1442. if (null_objects)
  1443. {
  1444. llwarns << "Found " << null_objects
  1445. << " NULL objects in the list (now removed)." << llendl;
  1446. llassert(false);
  1447. }
  1448. // Blow away the dead list.
  1449. mDeadObjects.clear();
  1450. }
  1451. void LLViewerObjectList::removeFromActiveList(LLViewerObject* objectp)
  1452. {
  1453. S32 idx = objectp->getListIndex();
  1454. if (idx != -1)
  1455. {
  1456. // Remove by moving last element to this object's position
  1457. llassert(mActiveObjects[idx] == objectp);
  1458. objectp->setListIndex(-1);
  1459. S32 last_index = mActiveObjects.size() - 1;
  1460. if (idx != last_index)
  1461. {
  1462. mActiveObjects[idx] = std::move(mActiveObjects[last_index]);
  1463. mActiveObjects[idx]->setListIndex(idx);
  1464. }
  1465. mActiveObjects.pop_back();
  1466. }
  1467. }
  1468. void LLViewerObjectList::updateActive(LLViewerObject* objectp)
  1469. {
  1470. LL_TRACY_TIMER(TRC_OBJ_UPDATE_ACTIVE);
  1471. if (!objectp || objectp->isDead())
  1472. {
  1473. return; // We do not update dead objects !
  1474. }
  1475. bool active = objectp->isActive();
  1476. if (active != objectp->onActiveList())
  1477. {
  1478. if (active)
  1479. {
  1480. S32 idx = objectp->getListIndex();
  1481. if (idx <= -1)
  1482. {
  1483. mActiveObjects.push_back(objectp);
  1484. objectp->setListIndex(mActiveObjects.size() - 1);
  1485. objectp->setOnActiveList(true);
  1486. }
  1487. else if (idx >= (S32)mActiveObjects.size() ||
  1488. mActiveObjects[idx] != objectp)
  1489. {
  1490. llwarns << "Invalid object list index detected !"
  1491. << llendl;
  1492. llassert(false);
  1493. }
  1494. }
  1495. else
  1496. {
  1497. removeFromActiveList(objectp);
  1498. objectp->setOnActiveList(false);
  1499. }
  1500. }
  1501. // Post condition: if object is active, it must be on the active list:
  1502. llassert(!active || std::find(mActiveObjects.begin(),
  1503. mActiveObjects.end(),
  1504. objectp) != mActiveObjects.end());
  1505. // Post condition: if object is not active, it must not be on the active
  1506. // list
  1507. llassert(active || std::find(mActiveObjects.begin(),
  1508. mActiveObjects.end(),
  1509. objectp) == mActiveObjects.end());
  1510. }
  1511. void LLViewerObjectList::updateObjectCost(LLViewerObject* object)
  1512. {
  1513. if (object && !object->isDead())
  1514. {
  1515. if (!object->isRoot() && object->getParent())
  1516. {
  1517. // Always fetch cost for the parent when fetching cost for children
  1518. mStaleObjectCost.emplace(((LLViewerObject*)object->getParent())->getID());
  1519. }
  1520. mStaleObjectCost.emplace(object->getID());
  1521. }
  1522. }
  1523. void LLViewerObjectList::updateObjectCost(const LLUUID& object_id,
  1524. F32 object_cost, F32 link_cost,
  1525. F32 physics_cost,
  1526. F32 link_physics_cost)
  1527. {
  1528. mPendingObjectCost.erase(object_id);
  1529. LLViewerObject* object = findObject(object_id);
  1530. if (object && !object->isDead())
  1531. {
  1532. object->setObjectCost(object_cost);
  1533. object->setLinksetCost(link_cost);
  1534. object->setPhysicsCost(physics_cost);
  1535. object->setLinksetPhysicsCost(link_physics_cost);
  1536. }
  1537. }
  1538. void LLViewerObjectList::onObjectCostFetchFailure(const LLUUID& object_id)
  1539. {
  1540. mPendingObjectCost.erase(object_id);
  1541. }
  1542. void LLViewerObjectList::updatePhysicsFlags(const LLViewerObject* object)
  1543. {
  1544. mStalePhysicsFlags.emplace(object->getID());
  1545. }
  1546. void LLViewerObjectList::updatePhysicsShapeType(const LLUUID& object_id,
  1547. S32 type)
  1548. {
  1549. mPendingPhysicsFlags.erase(object_id);
  1550. LLViewerObject* object = findObject(object_id);
  1551. if (object && !object->isDead())
  1552. {
  1553. object->setPhysicsShapeType(type);
  1554. }
  1555. }
  1556. void LLViewerObjectList::updatePhysicsProperties(const LLUUID& object_id,
  1557. F32 density, F32 friction,
  1558. F32 restitution,
  1559. F32 gravity_multiplier)
  1560. {
  1561. mPendingPhysicsFlags.erase(object_id);
  1562. LLViewerObject* object = findObject(object_id);
  1563. if (object && !object->isDead())
  1564. {
  1565. object->setPhysicsDensity(density);
  1566. object->setPhysicsFriction(friction);
  1567. object->setPhysicsGravity(gravity_multiplier);
  1568. object->setPhysicsRestitution(restitution);
  1569. }
  1570. }
  1571. void LLViewerObjectList::onPhysicsFlagsFetchFailure(const LLUUID& object_id)
  1572. {
  1573. mPendingPhysicsFlags.erase(object_id);
  1574. }
  1575. // This is called when we shift our origin when we cross region boundaries...
  1576. // We need to update many object caches, I will document this more as I dig
  1577. // through the code cleaning things out...
  1578. void LLViewerObjectList::shiftObjects(const LLVector3& offset)
  1579. {
  1580. if (offset.lengthSquared() == 0.f)
  1581. {
  1582. return;
  1583. }
  1584. LL_FAST_TIMER(FTM_SHIFT_OBJECTS);
  1585. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  1586. {
  1587. LLViewerObject* objectp = mObjects[i];
  1588. // There could be dead objects on the object list, so do not update
  1589. // stuff if the object is dead.
  1590. if (objectp && !objectp->isDead())
  1591. {
  1592. objectp->updatePositionCaches();
  1593. // NOTE: LLPipeline::markShift() tests for non-NULL and non-dead
  1594. // drawable, so not need to perform these tests here. HB
  1595. gPipeline.markShift(objectp->mDrawable);
  1596. }
  1597. }
  1598. {
  1599. LL_FAST_TIMER(FTM_PIPELINE_SHIFT);
  1600. gPipeline.shiftObjects(offset);
  1601. }
  1602. {
  1603. LL_FAST_TIMER(FTM_REGION_SHIFT);
  1604. gWorld.shiftRegions(offset);
  1605. }
  1606. }
  1607. void LLViewerObjectList::repartitionObjects()
  1608. {
  1609. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  1610. {
  1611. LLViewerObject* objectp = mObjects[i];
  1612. if (objectp && !objectp->isDead())
  1613. {
  1614. LLDrawable* drawable = objectp->mDrawable;
  1615. if (drawable && !drawable->isDead())
  1616. {
  1617. drawable->updateBinRadius();
  1618. drawable->updateSpatialExtents();
  1619. drawable->movePartition();
  1620. }
  1621. }
  1622. }
  1623. }
  1624. void LLViewerObjectList::clearAllMapObjectsInRegion(LLViewerRegion* regionp)
  1625. {
  1626. for (S32 i = 0, count = mMapObjects.size(); i < count; ++i)
  1627. {
  1628. LLViewerObject* objectp = mMapObjects[i];
  1629. // Clean up the list from invalid objects, while we are at it... HB
  1630. if (!objectp || objectp->isDead() || objectp->isOrphaned() ||
  1631. // ... and remove objects present in the specified region.
  1632. objectp->getRegion() == regionp)
  1633. {
  1634. if (i != --count)
  1635. {
  1636. mMapObjects[i] = std::move(mMapObjects.back());
  1637. }
  1638. mMapObjects.pop_back();
  1639. }
  1640. }
  1641. }
  1642. void LLViewerObjectList::renderObjectsForMap(LLPanelMiniMap* map)
  1643. {
  1644. static LLCachedControl<LLColor4U>
  1645. above_water_color(gColors, "MiniMapOtherOwnAboveWater");
  1646. static LLCachedControl<LLColor4U>
  1647. below_water_color(gColors, "MiniMapOtherOwnBelowWater");
  1648. static LLCachedControl<LLColor4U>
  1649. you_own_above_water_color(gColors, "MiniMapYouOwnAboveWater");
  1650. static LLCachedControl<LLColor4U>
  1651. you_own_below_water_color(gColors, "MiniMapYouOwnBelowWater");
  1652. static LLCachedControl<LLColor4U>
  1653. group_own_above_water_color(gColors, "MiniMapGroupOwnAboveWater");
  1654. static LLCachedControl<LLColor4U>
  1655. group_own_below_water_color(gColors, "MiniMapGroupOwnBelowWater");
  1656. for (S32 i = 0, count = mMapObjects.size(); i < count; ++i)
  1657. {
  1658. LLViewerObject* objectp = mMapObjects[i];
  1659. // Clean up the list from invalid objects, while we are at it. HB
  1660. if (!objectp || objectp->isDead() || !objectp->getRegion() ||
  1661. objectp->isOrphaned())
  1662. {
  1663. if (i != --count)
  1664. {
  1665. mMapObjects[i] = std::move(mMapObjects.back());
  1666. }
  1667. mMapObjects.pop_back();
  1668. continue;
  1669. }
  1670. const LLVector3d pos = objectp->getPositionGlobal();
  1671. if (objectp->flagCharacter())
  1672. {
  1673. if (objectp->isRoot())
  1674. {
  1675. // Path-finding characters are ploted by the mini-map code
  1676. // itself.
  1677. map->addPathFindingCharacter(pos);
  1678. }
  1679. continue;
  1680. }
  1681. const LLVector3& scale = objectp->getScale();
  1682. const F64 water_height = F64(objectp->getRegion()->getWaterHeight());
  1683. // Note: 0.325 = 0.5^2 * 1.3 (1.3 is a fudge)
  1684. F32 approx_radius = (scale.mV[VX] + scale.mV[VY]) * 0.325f;
  1685. // We draw physical objects after all others (and thus above them), to
  1686. // be sure to see them on map...
  1687. if (objectp->flagUsePhysics())
  1688. {
  1689. if (objectp->isRoot())
  1690. {
  1691. // Physcical objects (mobiles) are ploted by the mini-map code
  1692. // itself.
  1693. map->addPhysicalObject(pos);
  1694. }
  1695. continue;
  1696. }
  1697. LLColor4U color = above_water_color;
  1698. if (objectp->permYouOwner())
  1699. {
  1700. constexpr F32 MIN_RADIUS_FOR_OWNED_OBJECTS = 2.f;
  1701. if (approx_radius < MIN_RADIUS_FOR_OWNED_OBJECTS)
  1702. {
  1703. approx_radius = MIN_RADIUS_FOR_OWNED_OBJECTS;
  1704. }
  1705. if (pos.mdV[VZ] >= water_height)
  1706. {
  1707. if (objectp->permGroupOwner())
  1708. {
  1709. color = group_own_above_water_color;
  1710. }
  1711. else
  1712. {
  1713. color = you_own_above_water_color;
  1714. }
  1715. }
  1716. else if (objectp->permGroupOwner())
  1717. {
  1718. color = group_own_below_water_color;
  1719. }
  1720. else
  1721. {
  1722. color = you_own_below_water_color;
  1723. }
  1724. }
  1725. else if (pos.mdV[VZ] < water_height)
  1726. {
  1727. color = below_water_color;
  1728. }
  1729. map->renderScaledPointGlobal(pos, color, approx_radius);
  1730. }
  1731. }
  1732. void LLViewerObjectList::addDebugBeacon(const LLVector3& pos_agent,
  1733. const std::string& text,
  1734. const LLColor4& color,
  1735. const LLColor4& text_color,
  1736. S32 line_width)
  1737. {
  1738. mDebugBeacons.emplace_back(pos_agent, text, text_color, color, line_width);
  1739. }
  1740. void LLViewerObjectList::resetObjectBeacons()
  1741. {
  1742. mDebugBeacons.clear();
  1743. }
  1744. LLViewerObject* LLViewerObjectList::createObjectViewer(LLPCode pcode,
  1745. LLViewerRegion* regionp,
  1746. S32 flags)
  1747. {
  1748. LLUUID fullid;
  1749. fullid.generate();
  1750. LLViewerObject* objectp = LLViewerObject::createObject(fullid, pcode,
  1751. regionp, flags);
  1752. if (!objectp)
  1753. {
  1754. LL_DEBUGS("ViewerObject") << "Could not create object of type "
  1755. << LLPrimitive::pCodeToString(pcode)
  1756. << LL_ENDL;
  1757. return NULL;
  1758. }
  1759. mUUIDObjectMap[fullid] = objectp;
  1760. if (objectp->isAvatar())
  1761. {
  1762. LLVOAvatar* avatarp = objectp->asAvatar();
  1763. if (avatarp)
  1764. {
  1765. mUUIDAvatarMap[fullid] = avatarp;
  1766. }
  1767. }
  1768. mObjects.push_back(objectp);
  1769. updateActive(objectp);
  1770. return objectp;
  1771. }
  1772. LLViewerObject* LLViewerObjectList::createObjectFromCache(LLPCode pcode,
  1773. LLViewerRegion* regionp,
  1774. const LLUUID& uuid,
  1775. U32 local_id)
  1776. {
  1777. llassert_always(uuid.notNull());
  1778. LLViewerObject* objectp = LLViewerObject::createObject(uuid, pcode,
  1779. regionp);
  1780. if (!objectp)
  1781. {
  1782. LL_DEBUGS("ViewerObject") << "Could not create object of type "
  1783. << LLPrimitive::pCodeToString(pcode)
  1784. << " - Id: " << uuid << LL_ENDL;
  1785. return NULL;
  1786. }
  1787. LL_DEBUGS("ObjectCacheSpam") << "Created object " << uuid
  1788. << " from cache." << LL_ENDL;
  1789. objectp->setlocalID(local_id);
  1790. mUUIDObjectMap[uuid] = objectp;
  1791. setUUIDAndLocal(uuid, local_id, regionp->getHost().getAddress(),
  1792. regionp->getHost().getPort());
  1793. mObjects.push_back(objectp);
  1794. updateActive(objectp);
  1795. return objectp;
  1796. }
  1797. LLViewerObject* LLViewerObjectList::createObject(LLPCode pcode,
  1798. LLViewerRegion* regionp,
  1799. const LLUUID& uuid,
  1800. U32 local_id,
  1801. const LLHost& sender)
  1802. {
  1803. LL_FAST_TIMER(FTM_CREATE_OBJECT);
  1804. LLUUID fullid;
  1805. if (uuid.isNull())
  1806. {
  1807. fullid.generate();
  1808. }
  1809. else if (mDeadObjects.count(uuid))
  1810. {
  1811. LL_DEBUGS("ViewerObject") << "Attempt to re-create a dead object for: "
  1812. << uuid << ". Skipping." << LL_ENDL;
  1813. return NULL;
  1814. }
  1815. else
  1816. {
  1817. fullid = uuid;
  1818. }
  1819. LLViewerObject* objectp = LLViewerObject::createObject(fullid, pcode,
  1820. regionp);
  1821. if (!objectp)
  1822. {
  1823. LL_DEBUGS("ViewerObject") << "Could not create object of type "
  1824. << LLPrimitive::pCodeToString(pcode)
  1825. << " id:" << fullid << LL_ENDL;
  1826. return NULL;
  1827. }
  1828. if (regionp)
  1829. {
  1830. regionp->addToCreatedList(local_id);
  1831. }
  1832. mUUIDObjectMap[fullid] = objectp;
  1833. if (objectp->isAvatar())
  1834. {
  1835. LLVOAvatar* avatarp = objectp->asAvatar();
  1836. if (avatarp)
  1837. {
  1838. mUUIDAvatarMap[fullid] = avatarp;
  1839. }
  1840. }
  1841. setUUIDAndLocal(fullid, local_id, gMessageSystemp->getSenderIP(),
  1842. gMessageSystemp->getSenderPort());
  1843. mObjects.push_back(objectp);
  1844. if (gAutomationp && objectp->isAvatar())
  1845. {
  1846. gAutomationp->onAvatarRezzing(fullid);
  1847. }
  1848. updateActive(objectp);
  1849. return objectp;
  1850. }
  1851. LLViewerObject* LLViewerObjectList::replaceObject(const LLUUID& id,
  1852. LLPCode pcode,
  1853. LLViewerRegion* regionp)
  1854. {
  1855. LLViewerObject* old_instance = findObject(id);
  1856. if (old_instance)
  1857. {
  1858. #if 0
  1859. cleanupReferences(old_instance);
  1860. #endif
  1861. old_instance->markDead();
  1862. return createObject(pcode, regionp, id, old_instance->getLocalID(),
  1863. LLHost());
  1864. }
  1865. return NULL;
  1866. }
  1867. #if LL_DEBUG && 0
  1868. S32 LLViewerObjectList::findReferences(LLDrawable* drawablep) const
  1869. {
  1870. LLViewerObject* objectp;
  1871. S32 num_refs = 0;
  1872. for (S32 i = 0, count = mObjects.size(); i < count; ++i)
  1873. {
  1874. objectp = mObjects[i];
  1875. if (objectp && objectp->mDrawable.notNull())
  1876. {
  1877. num_refs += objectp->mDrawable->findReferences(drawablep);
  1878. }
  1879. }
  1880. return num_refs;
  1881. }
  1882. #endif
  1883. void LLViewerObjectList::orphanize(LLViewerObject* childp, U32 parent_id,
  1884. U32 ip, U32 port)
  1885. {
  1886. LL_DEBUGS("Orphans") << "Orphaning object " << childp->getID()
  1887. << " with parent " << parent_id << llendl;
  1888. // We are an orphan, flag things appropriately.
  1889. childp->mOrphaned = true;
  1890. if (childp->mDrawable.notNull())
  1891. {
  1892. bool make_invisible = true;
  1893. LLViewerObject* parentp = (LLViewerObject*)childp->getParent();
  1894. if (parentp)
  1895. {
  1896. if (parentp->getRegion() != childp->getRegion())
  1897. {
  1898. // This is probably an object flying across a region boundary,
  1899. // the object probably ISN'T being reparented, but just got an
  1900. // object update out of order (child update before parent).
  1901. make_invisible = false;
  1902. }
  1903. }
  1904. if (make_invisible)
  1905. {
  1906. // Make sure that this object becomes invisible if it is an orphan.
  1907. childp->mDrawable->setState(LLDrawable::FORCE_INVISIBLE);
  1908. }
  1909. }
  1910. // Unknown parent, add to orpaned child list
  1911. U64 parent_info = getIndex(parent_id, ip, port);
  1912. if (std::find(mOrphanParents.begin(), mOrphanParents.end(),
  1913. parent_info) == mOrphanParents.end())
  1914. {
  1915. mOrphanParents.push_back(parent_info);
  1916. }
  1917. LLViewerObjectList::OrphanInfo oi(parent_info, childp->mID);
  1918. if (std::find(mOrphanChildren.begin(), mOrphanChildren.end(), oi) ==
  1919. mOrphanChildren.end())
  1920. {
  1921. mOrphanChildren.push_back(oi);
  1922. ++mNumOrphans;
  1923. }
  1924. }
  1925. void LLViewerObjectList::findOrphans(LLViewerObject* objectp, U32 ip, U32 port)
  1926. {
  1927. LL_TRACY_TIMER(TRC_OBJ_FIND_ORPHANS);
  1928. if (!objectp)
  1929. {
  1930. return;
  1931. }
  1932. if (objectp->isDead())
  1933. {
  1934. llwarns << "Trying to find orphans for dead obj " << objectp->mID
  1935. << ":" << objectp->getPCodeString() << llendl;
  1936. return;
  1937. }
  1938. // Search object cache to get orphans
  1939. if (objectp->getRegion())
  1940. {
  1941. objectp->getRegion()->findOrphans(objectp->getLocalID());
  1942. }
  1943. // See if we are a parent of an orphan.
  1944. // Note: this code is fairly inefficient but it should happen very rarely.
  1945. // It can be sped up if this is somehow a performance issue...
  1946. if (mOrphanParents.empty())
  1947. {
  1948. // No known orphan parents
  1949. return;
  1950. }
  1951. if (std::find(mOrphanParents.begin(), mOrphanParents.end(),
  1952. getIndex(objectp->mLocalID, ip, port)) == mOrphanParents.end())
  1953. {
  1954. // Did not find objectp in OrphanParent list
  1955. return;
  1956. }
  1957. U64 parent_info = getIndex(objectp->mLocalID, ip, port);
  1958. bool orphans_found = false;
  1959. // Iterate through the orphan list, and set parents of matching children.
  1960. for (std::vector<OrphanInfo>::iterator iter = mOrphanChildren.begin();
  1961. iter != mOrphanChildren.end(); )
  1962. {
  1963. if (iter->mParentInfo != parent_info)
  1964. {
  1965. ++iter;
  1966. continue;
  1967. }
  1968. LLViewerObject* childp = findObject(iter->mChildInfo);
  1969. if (childp)
  1970. {
  1971. if (childp == objectp)
  1972. {
  1973. llwarns << objectp->mID << " has self as parent, skipping !"
  1974. << llendl;
  1975. ++iter;
  1976. continue;
  1977. }
  1978. LL_DEBUGS("Orphans") << "Reunited parent " << objectp->mID
  1979. << " with child " << childp->mID
  1980. << " - Global position: "
  1981. << objectp->getPositionGlobal()
  1982. << " - Position from agent: "
  1983. << objectp->getPositionAgent();
  1984. addDebugBeacon(objectp->getPositionAgent(), "");
  1985. LL_CONT << LL_ENDL;
  1986. gPipeline.markMoved(objectp->mDrawable);
  1987. objectp->setChanged(LLXform::MOVED | LLXform::SILHOUETTE);
  1988. // Flag the object as no longer orphaned
  1989. childp->mOrphaned = false;
  1990. if (childp->mDrawable.notNull())
  1991. {
  1992. // Make the drawable visible again and set the drawable parent
  1993. childp->mDrawable->clearState(LLDrawable::FORCE_INVISIBLE);
  1994. childp->setDrawableParent(objectp->mDrawable);
  1995. gPipeline.markRebuild(childp->mDrawable);
  1996. }
  1997. // Make certain particles, icon and HUD aren't hidden
  1998. childp->hideExtraDisplayItems(false);
  1999. objectp->addChild(childp);
  2000. orphans_found = true;
  2001. ++iter;
  2002. }
  2003. else
  2004. {
  2005. llinfos << "Missing orphan child, removing from list" << llendl;
  2006. iter = mOrphanChildren.erase(iter);
  2007. }
  2008. }
  2009. // Remove orphan parent and children from lists now that they have been
  2010. // found
  2011. {
  2012. std::vector<U64>::iterator iter = std::find(mOrphanParents.begin(),
  2013. mOrphanParents.end(),
  2014. parent_info);
  2015. if (iter != mOrphanParents.end())
  2016. {
  2017. mOrphanParents.erase(iter);
  2018. }
  2019. }
  2020. for (std::vector<OrphanInfo>::iterator iter = mOrphanChildren.begin();
  2021. iter != mOrphanChildren.end(); )
  2022. {
  2023. if (iter->mParentInfo == parent_info)
  2024. {
  2025. iter = mOrphanChildren.erase(iter);
  2026. --mNumOrphans;
  2027. }
  2028. else
  2029. {
  2030. ++iter;
  2031. }
  2032. }
  2033. if (orphans_found && objectp->isSelected())
  2034. {
  2035. LLSelectNode* nodep = gSelectMgr.getSelection()->findNode(objectp);
  2036. if (nodep && !nodep->mIndividualSelection)
  2037. {
  2038. // Rebuild selection with orphans
  2039. gSelectMgr.deselectObjectAndFamily(objectp);
  2040. gSelectMgr.selectObjectAndFamily(objectp);
  2041. }
  2042. }
  2043. }
  2044. void LLViewerObjectList::registerKilledAttachment(const LLUUID& id)
  2045. {
  2046. U64 handle = 0;
  2047. LLViewerRegion* regionp = gAgent.getRegion();
  2048. if (regionp)
  2049. {
  2050. handle = regionp->getHandle();
  2051. }
  2052. if (mKilledAttachmentsStamp != handle)
  2053. {
  2054. mKilledAttachmentsStamp = handle;
  2055. mKilledAttachments.clear();
  2056. }
  2057. mKilledAttachments.emplace(id);
  2058. }
  2059. /*****************************************************************************/
  2060. // Methods that used to be in llglsandbox.cpp
  2061. void LLViewerObjectList::renderObjectBeacons()
  2062. {
  2063. if (mDebugBeacons.empty())
  2064. {
  2065. return;
  2066. }
  2067. LLGLSUIDefault gls_ui;
  2068. gUIProgram.bind();
  2069. LLTexUnit* unit0 = gGL.getTexUnit(0);
  2070. {
  2071. unit0->unbind(LLTexUnit::TT_TEXTURE);
  2072. S32 last_line_width = -1;
  2073. for (std::vector<LLDebugBeacon>::iterator iter = mDebugBeacons.begin(),
  2074. end = mDebugBeacons.end();
  2075. iter != end; ++iter)
  2076. {
  2077. const LLDebugBeacon& debug_beacon = *iter;
  2078. LLColor4 color = debug_beacon.mColor;
  2079. color.mV[3] *= 0.25f;
  2080. if (gUsePBRShaders)
  2081. {
  2082. color = linearColor4(color);
  2083. }
  2084. S32 line_width = debug_beacon.mLineWidth;
  2085. if (line_width != last_line_width)
  2086. {
  2087. gGL.flush();
  2088. gGL.lineWidth((F32)line_width);
  2089. last_line_width = line_width;
  2090. }
  2091. const LLVector3& thisline = debug_beacon.mPositionAgent;
  2092. const F32& x = thisline.mV[VX];
  2093. const F32& y = thisline.mV[VY];
  2094. const F32& z = thisline.mV[VZ];
  2095. gGL.begin(LLRender::LINES);
  2096. gGL.color4fv(color.mV);
  2097. gGL.vertex3f(x, y, z - 50.f);
  2098. gGL.vertex3f(x, y, z + 50.f);
  2099. gGL.vertex3f(x - 2.f, y, z);
  2100. gGL.vertex3f(x + 2.f, y, z);
  2101. gGL.vertex3f(x, y - 2.f, z);
  2102. gGL.vertex3f(x, y + 2.f, z);
  2103. gl_draw_3d_line_cube(0.1f, thisline);
  2104. gGL.end();
  2105. }
  2106. }
  2107. {
  2108. unit0->unbind(LLTexUnit::TT_TEXTURE);
  2109. LLGLDepthTest gls_depth(GL_TRUE);
  2110. S32 last_line_width = -1;
  2111. for (std::vector<LLDebugBeacon>::iterator iter = mDebugBeacons.begin(),
  2112. end = mDebugBeacons.end();
  2113. iter != end; ++iter)
  2114. {
  2115. const LLDebugBeacon& debug_beacon = *iter;
  2116. S32 line_width = debug_beacon.mLineWidth;
  2117. if (line_width != last_line_width)
  2118. {
  2119. gGL.flush();
  2120. gGL.lineWidth((F32)line_width);
  2121. last_line_width = line_width;
  2122. }
  2123. const LLVector3& thisline = debug_beacon.mPositionAgent;
  2124. gGL.begin(LLRender::LINES);
  2125. LLColor4 color = debug_beacon.mColor;
  2126. if (gUsePBRShaders)
  2127. {
  2128. color = linearColor4(color);
  2129. }
  2130. gGL.color4fv(color.mV);
  2131. gl_draw_3d_cross_lines(thisline, 0.5f, 0.5f, 0.5f);
  2132. gl_draw_3d_line_cube(0.1f, thisline);
  2133. gGL.end();
  2134. }
  2135. gGL.flush();
  2136. gGL.lineWidth(1.f);
  2137. LLHUDText* hudtp;
  2138. for (std::vector<LLDebugBeacon>::iterator iter = mDebugBeacons.begin(),
  2139. end = mDebugBeacons.end();
  2140. iter != end; ++iter)
  2141. {
  2142. LLDebugBeacon& debug_beacon = *iter;
  2143. if (debug_beacon.mString.empty())
  2144. {
  2145. continue;
  2146. }
  2147. hudtp = (LLHUDText*)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
  2148. hudtp->setZCompare(false);
  2149. LLColor4 color;
  2150. color = debug_beacon.mTextColor;
  2151. color.mV[3] *= 1.f;
  2152. hudtp->setString(utf8str_to_wstring(debug_beacon.mString));
  2153. hudtp->setColor(color);
  2154. hudtp->setPositionAgent(debug_beacon.mPositionAgent);
  2155. debug_beacon.mHUDObject = hudtp;
  2156. }
  2157. }
  2158. stop_glerror();
  2159. }
  2160. ////////////////////////////////////////////////////////////////////////////
  2161. LLViewerObjectList::OrphanInfo::OrphanInfo()
  2162. : mParentInfo(0)
  2163. {
  2164. }
  2165. LLViewerObjectList::OrphanInfo::OrphanInfo(U64 parent_info,
  2166. const LLUUID& child_info)
  2167. : mParentInfo(parent_info),
  2168. mChildInfo(child_info)
  2169. {
  2170. }
  2171. bool LLViewerObjectList::OrphanInfo::operator==(const OrphanInfo& rhs) const
  2172. {
  2173. return mParentInfo == rhs.mParentInfo && mChildInfo == rhs.mChildInfo;
  2174. }
  2175. bool LLViewerObjectList::OrphanInfo::operator!=(const OrphanInfo& rhs) const
  2176. {
  2177. return mParentInfo != rhs.mParentInfo || mChildInfo != rhs.mChildInfo;
  2178. }
  2179. ////////////////////////////////////////////////////////////////////////////
  2180. LLDebugBeacon::~LLDebugBeacon()
  2181. {
  2182. if (mHUDObject.notNull())
  2183. {
  2184. mHUDObject->markDead();
  2185. }
  2186. }