PageRenderTime 40ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewerobjectlist.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 298 lines | 183 code | 65 blank | 50 comment | 6 complexity | 7333c7fc0eee448a2434f8e5cd2d9540 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerobjectlist.h
  3. * @brief Description of LLViewerObjectList class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVIEWEROBJECTLIST_H
  27. #define LL_LLVIEWEROBJECTLIST_H
  28. #include <map>
  29. #include <set>
  30. // common includes
  31. #include "llstat.h"
  32. #include "llstring.h"
  33. // project includes
  34. #include "llviewerobject.h"
  35. class LLCamera;
  36. class LLNetMap;
  37. class LLDebugBeacon;
  38. const U32 CLOSE_BIN_SIZE = 10;
  39. const U32 NUM_BINS = 128;
  40. // GL name = position in object list + GL_NAME_INDEX_OFFSET so that
  41. // we can have special numbers like zero.
  42. const U32 GL_NAME_LAND = 0;
  43. const U32 GL_NAME_PARCEL_WALL = 1;
  44. const U32 GL_NAME_INDEX_OFFSET = 10;
  45. class LLViewerObjectList
  46. {
  47. public:
  48. LLViewerObjectList();
  49. ~LLViewerObjectList();
  50. void destroy();
  51. // For internal use only. Does NOT take a local id, takes an index into
  52. // an internal dynamic array.
  53. inline LLViewerObject *getObject(const S32 index);
  54. inline LLViewerObject *findObject(const LLUUID &id);
  55. LLViewerObject *createObjectViewer(const LLPCode pcode, LLViewerRegion *regionp); // Create a viewer-side object
  56. LLViewerObject *createObject(const LLPCode pcode, LLViewerRegion *regionp,
  57. const LLUUID &uuid, const U32 local_id, const LLHost &sender);
  58. LLViewerObject *replaceObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp); // TomY: hack to switch VO instances on the fly
  59. BOOL killObject(LLViewerObject *objectp);
  60. void killObjects(LLViewerRegion *regionp); // Kill all objects owned by a particular region.
  61. void killAllObjects();
  62. void removeDrawable(LLDrawable* drawablep);
  63. void cleanDeadObjects(const BOOL use_timer = TRUE); // Clean up the dead object list.
  64. // Simulator and viewer side object updates...
  65. void processUpdateCore(LLViewerObject* objectp, void** data, U32 block, const EObjectUpdateType update_type, LLDataPacker* dpp, BOOL justCreated);
  66. void processObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type, bool cached=false, bool compressed=false);
  67. void processCompressedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type);
  68. void processCachedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type);
  69. void updateApparentAngles(LLAgent &agent);
  70. void update(LLAgent &agent, LLWorld &world);
  71. void fetchObjectCosts();
  72. void fetchPhysicsFlags();
  73. void updateObjectCost(LLViewerObject* object);
  74. void updateObjectCost(const LLUUID& object_id, F32 object_cost, F32 link_cost, F32 physics_cost, F32 link_physics_cost);
  75. void onObjectCostFetchFailure(const LLUUID& object_id);
  76. void updatePhysicsFlags(const LLViewerObject* object);
  77. void onPhysicsFlagsFetchFailure(const LLUUID& object_id);
  78. void updatePhysicsShapeType(const LLUUID& object_id, S32 type);
  79. void updatePhysicsProperties(const LLUUID& object_id,
  80. F32 density,
  81. F32 friction,
  82. F32 restitution,
  83. F32 gravity_multiplier);
  84. void shiftObjects(const LLVector3 &offset);
  85. void repartitionObjects();
  86. bool hasMapObjectInRegion(LLViewerRegion* regionp) ;
  87. void clearAllMapObjectsInRegion(LLViewerRegion* regionp) ;
  88. void renderObjectsForMap(LLNetMap &netmap);
  89. void renderObjectBounds(const LLVector3 &center);
  90. void addDebugBeacon(const LLVector3 &pos_agent, const std::string &string,
  91. const LLColor4 &color=LLColor4(1.f, 0.f, 0.f, 0.5f),
  92. const LLColor4 &text_color=LLColor4(1.f, 1.f, 1.f, 1.f),
  93. S32 line_width = 1);
  94. void renderObjectBeacons();
  95. void resetObjectBeacons();
  96. void dirtyAllObjectInventory();
  97. void updateActive(LLViewerObject *objectp);
  98. void updateAvatarVisibility();
  99. // Selection related stuff
  100. void generatePickList(LLCamera &camera);
  101. LLViewerObject *getSelectedObject(const U32 object_id);
  102. inline S32 getNumObjects() { return (S32) mObjects.size(); }
  103. void addToMap(LLViewerObject *objectp);
  104. void removeFromMap(LLViewerObject *objectp);
  105. void clearDebugText();
  106. ////////////////////////////////////////////
  107. //
  108. // Only accessed by markDead in LLViewerObject
  109. void cleanupReferences(LLViewerObject *objectp);
  110. S32 findReferences(LLDrawable *drawablep) const; // Find references to drawable in all objects, and return value.
  111. S32 getOrphanParentCount() const { return (S32) mOrphanParents.size(); }
  112. S32 getOrphanCount() const { return mNumOrphans; }
  113. void orphanize(LLViewerObject *childp, U32 parent_id, U32 ip, U32 port);
  114. void findOrphans(LLViewerObject* objectp, U32 ip, U32 port);
  115. public:
  116. // Class for keeping track of orphaned objects
  117. class OrphanInfo
  118. {
  119. public:
  120. OrphanInfo();
  121. OrphanInfo(const U64 parent_info, const LLUUID child_info);
  122. bool operator==(const OrphanInfo &rhs) const;
  123. bool operator!=(const OrphanInfo &rhs) const;
  124. U64 mParentInfo;
  125. LLUUID mChildInfo;
  126. };
  127. U32 mCurBin; // Current bin we're working on...
  128. // Statistics data (see also LLViewerStats)
  129. S32 mNumNewObjects;
  130. S32 mNumSizeCulled;
  131. S32 mNumVisCulled;
  132. // if we paused in the last frame
  133. // used to discount stats from this frame
  134. BOOL mWasPaused;
  135. static void getUUIDFromLocal(LLUUID &id,
  136. const U32 local_id,
  137. const U32 ip,
  138. const U32 port);
  139. static void setUUIDAndLocal(const LLUUID &id,
  140. const U32 local_id,
  141. const U32 ip,
  142. const U32 port); // Requires knowledge of message system info!
  143. static BOOL removeFromLocalIDTable(const LLViewerObject* objectp);
  144. // Used ONLY by the orphaned object code.
  145. static U64 getIndex(const U32 local_id, const U32 ip, const U32 port);
  146. S32 mNumUnknownUpdates;
  147. S32 mNumDeadObjectUpdates;
  148. S32 mNumUnknownKills;
  149. S32 mNumDeadObjects;
  150. protected:
  151. std::vector<U64> mOrphanParents; // LocalID/ip,port of orphaned objects
  152. std::vector<OrphanInfo> mOrphanChildren; // UUID's of orphaned objects
  153. S32 mNumOrphans;
  154. typedef std::vector<LLPointer<LLViewerObject> > vobj_list_t;
  155. vobj_list_t mObjects;
  156. std::set<LLPointer<LLViewerObject> > mActiveObjects;
  157. vobj_list_t mMapObjects;
  158. std::set<LLUUID> mDeadObjects;
  159. std::map<LLUUID, LLPointer<LLViewerObject> > mUUIDObjectMap;
  160. //set of objects that need to update their cost
  161. std::set<LLUUID> mStaleObjectCost;
  162. std::set<LLUUID> mPendingObjectCost;
  163. //set of objects that need to update their physics flags
  164. std::set<LLUUID> mStalePhysicsFlags;
  165. std::set<LLUUID> mPendingPhysicsFlags;
  166. std::vector<LLDebugBeacon> mDebugBeacons;
  167. S32 mCurLazyUpdateIndex;
  168. static U32 sSimulatorMachineIndex;
  169. static std::map<U64, U32> sIPAndPortToIndex;
  170. static std::map<U64, LLUUID> sIndexAndLocalIDToUUID;
  171. std::set<LLViewerObject *> mSelectPickList;
  172. friend class LLViewerObject;
  173. };
  174. class LLDebugBeacon
  175. {
  176. public:
  177. ~LLDebugBeacon()
  178. {
  179. if (mHUDObject.notNull())
  180. {
  181. mHUDObject->markDead();
  182. }
  183. }
  184. LLVector3 mPositionAgent;
  185. std::string mString;
  186. LLColor4 mColor;
  187. LLColor4 mTextColor;
  188. S32 mLineWidth;
  189. LLPointer<LLHUDObject> mHUDObject;
  190. };
  191. // Global object list
  192. extern LLViewerObjectList gObjectList;
  193. // Inlines
  194. /**
  195. * Note:
  196. * it will return NULL for offline avatar_id
  197. */
  198. inline LLViewerObject *LLViewerObjectList::findObject(const LLUUID &id)
  199. {
  200. std::map<LLUUID, LLPointer<LLViewerObject> >::iterator iter = mUUIDObjectMap.find(id);
  201. if(iter != mUUIDObjectMap.end())
  202. {
  203. return iter->second;
  204. }
  205. else
  206. {
  207. return NULL;
  208. }
  209. }
  210. inline LLViewerObject *LLViewerObjectList::getObject(const S32 index)
  211. {
  212. LLViewerObject *objectp;
  213. objectp = mObjects[index];
  214. if (objectp->isDead())
  215. {
  216. //llwarns << "Dead object " << objectp->mID << " in getObject" << llendl;
  217. return NULL;
  218. }
  219. return objectp;
  220. }
  221. inline void LLViewerObjectList::addToMap(LLViewerObject *objectp)
  222. {
  223. mMapObjects.push_back(objectp);
  224. }
  225. inline void LLViewerObjectList::removeFromMap(LLViewerObject *objectp)
  226. {
  227. std::vector<LLPointer<LLViewerObject> >::iterator iter = std::find(mMapObjects.begin(), mMapObjects.end(), objectp);
  228. if (iter != mMapObjects.end())
  229. {
  230. mMapObjects.erase(iter);
  231. }
  232. }
  233. #endif // LL_VIEWER_OBJECT_LIST_H