llviewerobjectlist.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**
  2. * @file llviewerobjectlist.h
  3. * @brief Description 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. #ifndef LL_LLVIEWEROBJECTLIST_H
  33. #define LL_LLVIEWEROBJECTLIST_H
  34. #include "llstat.h"
  35. #include "llstring.h"
  36. #include "llviewerobject.h"
  37. class LLPanelMiniMap;
  38. class LLVOAvatar;
  39. class LLVOCacheEntry;
  40. constexpr U32 CLOSE_BIN_SIZE = 10;
  41. constexpr U32 NUM_BINS = 128;
  42. // GL name = position in object list + GL_NAME_INDEX_OFFSET so that we can have
  43. // special numbers like zero.
  44. constexpr U32 GL_NAME_LAND = 0;
  45. constexpr U32 GL_NAME_PARCEL_WALL = 1;
  46. constexpr U32 GL_NAME_INDEX_OFFSET = 10;
  47. class LLDebugBeacon
  48. {
  49. public:
  50. LL_INLINE LLDebugBeacon()
  51. : mLineWidth(1)
  52. {
  53. }
  54. LL_INLINE LLDebugBeacon(const LLVector3& pos_agent, const std::string& text,
  55. const LLColor4& text_col, const LLColor4& color,
  56. S32 line_width)
  57. : mPositionAgent(pos_agent),
  58. mString(text),
  59. mTextColor(text_col),
  60. mColor(color),
  61. mLineWidth(line_width)
  62. {
  63. }
  64. ~LLDebugBeacon();
  65. public:
  66. LLPointer<LLHUDObject> mHUDObject;
  67. std::string mString;
  68. LLColor4 mColor;
  69. LLColor4 mTextColor;
  70. LLVector3 mPositionAgent;
  71. S32 mLineWidth;
  72. };
  73. class LLViewerObjectList
  74. {
  75. friend class LLViewerObject;
  76. protected:
  77. LOG_CLASS(LLViewerObjectList);
  78. public:
  79. typedef std::vector<LLPointer<LLViewerObject> > vobj_list_t;
  80. typedef fast_hmap<LLUUID, LLPointer<LLViewerObject> > objs_map_t;
  81. typedef fast_hmap<LLUUID, LLPointer<LLVOAvatar> > avatars_map_t;
  82. LLViewerObjectList();
  83. void cleanupClass(); // Called from LLWorld::cleanupClass()
  84. // For internal use only. Does NOT take a local Id, but takes an index into
  85. // an internal dynamic array.
  86. LL_INLINE LLViewerObject* getObject(S32 index) const
  87. {
  88. if (index < 0 || index >= (S32)mObjects.size())
  89. {
  90. return NULL;
  91. }
  92. LLViewerObject* objectp = mObjects[index];
  93. return !objectp || objectp->isDead() ? NULL : objectp;
  94. }
  95. LL_INLINE LLViewerObject* findObject(const LLUUID& id) const
  96. {
  97. objs_map_t::const_iterator iter = mUUIDObjectMap.find(id);
  98. return iter != mUUIDObjectMap.end() ? iter->second.get() : NULL;
  99. }
  100. LL_INLINE LLVOAvatar* findAvatar(const LLUUID& id) const
  101. {
  102. avatars_map_t::const_iterator iter = mUUIDAvatarMap.find(id);
  103. return iter != mUUIDAvatarMap.end() ? iter->second.get() : NULL;
  104. }
  105. // Create a viewer-side object:
  106. LLViewerObject* createObjectViewer(LLPCode pcode, LLViewerRegion* regionp,
  107. S32 flags = 0);
  108. LLViewerObject* createObjectFromCache(LLPCode pcode,
  109. LLViewerRegion* regionp,
  110. const LLUUID& uuid,
  111. U32 local_id);
  112. LLViewerObject* createObject(LLPCode pcode, LLViewerRegion* regionp,
  113. const LLUUID& uuid, U32 local_id,
  114. const LLHost& sender);
  115. // TomY: hack to switch VO instances on the fly:
  116. LLViewerObject* replaceObject(const LLUUID& id, LLPCode pcode,
  117. LLViewerRegion* regionp);
  118. bool killObject(LLViewerObject* objectp);
  119. // Kills all objects owned by a particular region:
  120. void killObjects(LLViewerRegion* regionp);
  121. void killAllObjects();
  122. // Clean up the dead objects list.
  123. void cleanDeadObjects();
  124. // Simulator and viewer side object updates...
  125. void processUpdateCore(LLViewerObject* objectp, void** data, U32 block,
  126. EObjectUpdateType update_type,
  127. LLDataPacker* dpp,
  128. bool just_created, bool from_cache = false);
  129. LLViewerObject* processObjectUpdateFromCache(LLVOCacheEntry* entry,
  130. LLViewerRegion* regionp);
  131. void processObjectUpdate(LLMessageSystem* msg, void** user_data,
  132. EObjectUpdateType update_type,
  133. bool compressed = false);
  134. void processCompressedObjectUpdate(LLMessageSystem* msg, void** user_data,
  135. EObjectUpdateType update_type);
  136. void processCachedObjectUpdate(LLMessageSystem* msg, void** user_data,
  137. EObjectUpdateType update_type);
  138. void updateApparentAngles();
  139. void update();
  140. void fetchObjectCosts();
  141. void fetchPhysicsFlags();
  142. bool gotObjectPhysicsFlags(LLViewerObject* objectp);
  143. void updateObjectCost(LLViewerObject* object);
  144. void updateObjectCost(const LLUUID& object_id, F32 object_cost,
  145. F32 link_cost, F32 physics_cost,
  146. F32 link_physics_cost);
  147. void onObjectCostFetchFailure(const LLUUID& object_id);
  148. void updatePhysicsFlags(const LLViewerObject* object);
  149. void onPhysicsFlagsFetchFailure(const LLUUID& object_id);
  150. void updatePhysicsShapeType(const LLUUID& object_id, S32 type);
  151. void updatePhysicsProperties(const LLUUID& object_id, F32 density,
  152. F32 friction, F32 restitution,
  153. F32 gravity_multiplier);
  154. void shiftObjects(const LLVector3& offset);
  155. void repartitionObjects();
  156. void clearAllMapObjectsInRegion(LLViewerRegion* regionp);
  157. void renderObjectsForMap(LLPanelMiniMap* map);
  158. void addDebugBeacon(const LLVector3& pos_agent, const std::string& text,
  159. const LLColor4& color = LLColor4(1.f, 0.f, 0.f, 0.5f),
  160. const LLColor4& text_color = LLColor4(1.f, 1.f, 1.f, 1.f),
  161. S32 line_width = 1);
  162. void renderObjectBeacons();
  163. void resetObjectBeacons();
  164. void dirtyAllObjectInventory();
  165. void removeFromActiveList(LLViewerObject* objectp);
  166. void updateActive(LLViewerObject* objectp);
  167. void updateAvatarVisibility();
  168. LL_INLINE S32 getNumObjects() { return (S32)mObjects.size(); }
  169. LL_INLINE S32 getNumActiveObjects() { return (S32)mActiveObjects.size(); }
  170. LL_INLINE S32 getNumDeadObjects() { return (S32)mDeadObjects.size(); }
  171. LL_INLINE void addToMap(LLViewerObject* objectp)
  172. {
  173. mMapObjects.emplace_back(objectp);
  174. }
  175. LL_INLINE void removeFromMap(LLViewerObject* objectp)
  176. {
  177. vobj_list_t::iterator iter = std::find(mMapObjects.begin(),
  178. mMapObjects.end(), objectp);
  179. if (iter != mMapObjects.end())
  180. {
  181. mMapObjects.erase(iter);
  182. }
  183. }
  184. void clearDebugText();
  185. // Only accessed by markDead in LLViewerObject
  186. void cleanupReferences(LLViewerObject* objectp);
  187. #if LL_DEBUG && 0
  188. // Debugging method.
  189. // Find references to drawable in all objects, and return value.
  190. S32 findReferences(LLDrawable* drawablep) const;
  191. #endif
  192. LL_INLINE S32 getOrphanParentCount() const { return (S32)mOrphanParents.size(); }
  193. LL_INLINE S32 getOrphanCount() const { return mNumOrphans; }
  194. void orphanize(LLViewerObject* childp, U32 parent_id, U32 ip, U32 port);
  195. void findOrphans(LLViewerObject* objectp, U32 ip, U32 port);
  196. void getUUIDFromLocal(LLUUID& id, U32 local_id, U32 ip, U32 port);
  197. // Requires knowledge of message system info.
  198. void setUUIDAndLocal(const LLUUID& id, U32 local_id, U32 ip, U32 port);
  199. bool removeFromLocalIDTable(const LLViewerObject* objectp);
  200. // Used ONLY by the orphaned object code.
  201. U64 getIndex(U32 local_id, U32 ip, U32 port);
  202. void registerKilledAttachment(const LLUUID& id);
  203. private:
  204. void fetchObjectCostsCoro(const std::string& url);
  205. void fetchPhysicsFlagsCoro(const std::string& url);
  206. public:
  207. // Class for keeping track of orphaned objects
  208. class OrphanInfo
  209. {
  210. public:
  211. OrphanInfo();
  212. OrphanInfo(U64 parent_info, const LLUUID& child_info);
  213. bool operator==(const OrphanInfo& rhs) const;
  214. bool operator!=(const OrphanInfo& rhs) const;
  215. public:
  216. U64 mParentInfo;
  217. LLUUID mChildInfo;
  218. };
  219. U32 mCurBin; // Current bin we are working on.
  220. // Statistics data
  221. S32 mNumNewObjects;
  222. S32 mNumSizeCulled;
  223. S32 mNumVisCulled;
  224. S32 mNumUnknownUpdates;
  225. S32 mNumDeadObjectUpdates;
  226. LLStat mNumObjectsStat;
  227. LLStat mNumActiveObjectsStat;
  228. LLStat mNumNewObjectsStat;
  229. LLStat mNumSizeCulledStat;
  230. LLStat mNumVisCulledStat;
  231. // If we paused in the last frame used to discount stats from this frame
  232. bool mWasPaused;
  233. // Derendered objects
  234. uuid_list_t mBlackListedObjects;
  235. protected:
  236. S32 mCurLazyUpdateIndex;
  237. S32 mNumOrphans;
  238. S32 mIdleListSlots;
  239. // LocalID/ip, port of orphaned objects
  240. std::vector<U64> mOrphanParents;
  241. // UUID's of orphaned objects
  242. std::vector<OrphanInfo> mOrphanChildren;
  243. vobj_list_t mObjects;
  244. vobj_list_t mActiveObjects;
  245. vobj_list_t mMapObjects;
  246. uuid_list_t mDeadObjects;
  247. objs_map_t mUUIDObjectMap;
  248. avatars_map_t mUUIDAvatarMap;
  249. // Set of objects that need to update their cost
  250. uuid_list_t mStaleObjectCost;
  251. uuid_list_t mPendingObjectCost;
  252. // Set of objects that need to update their physics flags
  253. uuid_list_t mStalePhysicsFlags;
  254. uuid_list_t mPendingPhysicsFlags;
  255. typedef std::vector<LLViewerObject*> vobj_vec_t;
  256. vobj_vec_t mIdleList;
  257. vobj_vec_t mDeadList;
  258. std::vector<LLDebugBeacon> mDebugBeacons;
  259. uuid_list_t mKilledAttachments;
  260. U64 mKilledAttachmentsStamp;
  261. typedef fast_hmap<U64, U32> ip_to_idx_map_t;
  262. ip_to_idx_map_t mIPAndPortToIndex;
  263. typedef fast_hmap<U64, LLUUID> idx_to_uuid_map_t;
  264. idx_to_uuid_map_t mIndexAndLocalIDToUUID;
  265. U32 mSimulatorMachineIndex;
  266. };
  267. // Global object list
  268. extern LLViewerObjectList gObjectList;
  269. #endif // LL_VIEWER_OBJECT_LIST_H