llviewerobjectlist.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLVIEWEROBJECTLIST_H
00033 #define LL_LLVIEWEROBJECTLIST_H
00034 
00035 #include <map>
00036 #include <set>
00037 
00038 // common includes
00039 #include "doublelinkedlist.h"
00040 #include "llstat.h"
00041 #include "lldarrayptr.h"
00042 #include "llskipmap.h"
00043 #include "llstring.h"
00044 
00045 // project includes
00046 #include "llviewerobject.h"
00047 
00048 class LLNetMap;
00049 class LLDebugBeacon;
00050 
00051 const U32 CLOSE_BIN_SIZE = 10;
00052 const U32 NUM_BINS = 16;
00053 
00054 // GL name = position in object list + GL_NAME_INDEX_OFFSET so that
00055 // we can have special numbers like zero.
00056 const U32 GL_NAME_LAND = 0;
00057 const U32 GL_NAME_PARCEL_WALL = 1;
00058 
00059 const U32 GL_NAME_INDEX_OFFSET = 10;
00060 
00061 class LLViewerObjectList
00062 {
00063 public:
00064         LLViewerObjectList();
00065         ~LLViewerObjectList();
00066 
00067         void destroy();
00068 
00069         // For internal use only.  Does NOT take a local id, takes an index into
00070         // an internal dynamic array.
00071         inline LLViewerObject *getObject(const S32 index);
00072         
00073         inline LLViewerObject *findObject(const LLUUID &id);
00074         LLViewerObject *createObjectViewer(const LLPCode pcode, LLViewerRegion *regionp); // Create a viewer-side object
00075         LLViewerObject *createObject(const LLPCode pcode, LLViewerRegion *regionp,
00076                                                                  const LLUUID &uuid, const U32 local_id, const LLHost &sender);
00077 
00078         LLViewerObject *replaceObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp); // TomY: hack to switch VO instances on the fly
00079         
00080         BOOL killObject(LLViewerObject *objectp);
00081         void killObjects(LLViewerRegion *regionp); // Kill all objects owned by a particular region.
00082         void killAllObjects();
00083         void removeDrawable(LLDrawable* drawablep);
00084 
00085         void cleanDeadObjects(const BOOL use_timer = TRUE);     // Clean up the dead object list.
00086 
00087         // Simulator and viewer side object updates...
00088         void processUpdateCore(LLViewerObject* objectp, void** data, U32 block, const EObjectUpdateType update_type, LLDataPacker* dpp, BOOL justCreated);
00089         void processObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type, bool cached=false, bool compressed=false);
00090         void processCompressedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type);
00091         void processCachedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type);
00092         void updateApparentAngles(LLAgent &agent);
00093         void update(LLAgent &agent, LLWorld &world);
00094 
00095         void shiftObjects(const LLVector3 &offset);
00096 
00097         void renderObjectsForMap(LLNetMap &netmap);
00098         void renderObjectBounds(const LLVector3 &center);
00099 
00100         void addDebugBeacon(const LLVector3 &pos_agent, const LLString &string,
00101                                                 const LLColor4 &color=LLColor4(1.f, 0.f, 0.f, 0.5f),
00102                                                 const LLColor4 &text_color=LLColor4(1.f, 1.f, 1.f, 1.f),
00103                                                 S32 line_width = 1);
00104         void renderObjectBeacons();
00105         void resetObjectBeacons();
00106 
00107         void relightAllObjects();
00108         void dirtyAllObjectInventory();
00109 
00110         void updateActive(LLViewerObject *objectp);
00111         void updateAvatarVisibility();
00112 
00113         // Selection related stuff
00114         U32 renderObjectsForSelect(LLCamera &camera, BOOL pick_parcel_wall = FALSE, BOOL keep_pick_list = FALSE);
00115         LLViewerObject *getSelectedObject(const U32 object_id);
00116 
00117         inline S32 getNumObjects() { return mObjects.count(); }
00118 
00119         void addToMap(LLViewerObject *objectp);
00120         void removeFromMap(LLViewerObject *objectp);
00121 
00122         void clearDebugText();
00123 
00125         //
00126         // Only accessed by markDead in LLViewerObject
00127         void cleanupReferences(LLViewerObject *objectp);
00128 
00129         S32 findReferences(LLDrawable *drawablep) const; // Find references to drawable in all objects, and return value.
00130 
00131         S32 getOrphanParentCount() const { return mOrphanParents.count(); }
00132         S32 getOrphanCount() const { return mNumOrphans; }
00133         void orphanize(LLViewerObject *childp, U32 parent_id, U32 ip, U32 port);
00134         void findOrphans(LLViewerObject* objectp, U32 ip, U32 port);
00135 
00136 public:
00137         // Class for keeping track of orphaned objects
00138         class OrphanInfo
00139         {
00140         public:
00141                 OrphanInfo();
00142                 OrphanInfo(const U64 parent_info, const LLUUID child_info);
00143                 bool operator==(const OrphanInfo &rhs) const;
00144                 bool operator!=(const OrphanInfo &rhs) const;
00145                 U64 mParentInfo;
00146                 LLUUID mChildInfo;
00147         };
00148 
00149 
00150         U32     mCurBin; // Current bin we're working on...
00151 
00153         //
00154         // Statistics data
00155         //
00156         //
00157         LLStat mNumObjectsStat;
00158         LLStat mNumActiveObjectsStat;
00159         LLStat mNumNewObjectsStat;
00160         LLStat mNumSizeCulledStat;
00161         LLStat mNumVisCulledStat;
00162 
00163         S32 mNumNewObjects;
00164 
00165         S32 mNumSizeCulled;
00166         S32 mNumVisCulled;
00167 
00168         // if we paused in the last frame
00169         // used to discount stats from this frame
00170         BOOL mWasPaused;
00171 
00172         static void getUUIDFromLocal(LLUUID &id,
00173                                                                 const U32 local_id,
00174                                                                 const U32 ip,
00175                                                                 const U32 port);
00176         static void setUUIDAndLocal(const LLUUID &id,
00177                                                                 const U32 local_id,
00178                                                                 const U32 ip,
00179                                                                 const U32 port); // Requires knowledge of message system info!
00180 
00181         static BOOL removeFromLocalIDTable(const LLViewerObject &object);
00182         // Used ONLY by the orphaned object code.
00183         static U64 getIndex(const U32 local_id, const U32 ip, const U32 port);
00184 
00185         S32 mNumUnknownUpdates;
00186         S32 mNumDeadObjectUpdates;
00187         S32 mNumUnknownKills;
00188         S32 mNumDeadObjects;
00189 protected:
00190         LLDynamicArray<U64>     mOrphanParents; // LocalID/ip,port of orphaned objects
00191         LLDynamicArray<OrphanInfo> mOrphanChildren;     // UUID's of orphaned objects
00192         S32 mNumOrphans;
00193 
00194         LLDynamicArrayPtr<LLPointer<LLViewerObject>, 256> mObjects;
00195         std::set<LLPointer<LLViewerObject> > mActiveObjects;
00196 
00197         LLDynamicArrayPtr<LLPointer<LLViewerObject> > mMapObjects;
00198 
00199         typedef std::map<LLUUID, LLPointer<LLViewerObject> > vo_map;
00200         vo_map mDeadObjects;    // Need to keep multiple entries per UUID
00201 
00202         std::map<LLUUID, LLPointer<LLViewerObject> > mUUIDObjectMap;
00203 
00204         LLDynamicArray<LLDebugBeacon> mDebugBeacons;
00205 
00206         S32 mCurLazyUpdateIndex;
00207 
00208         static U32 sSimulatorMachineIndex;
00209         static LLMap<U64, U32> sIPAndPortToIndex;
00210 
00211         static std::map<U64, LLUUID> sIndexAndLocalIDToUUID;
00212 
00213         std::set<LLViewerObject *> mSelectPickList;
00214 
00215         friend class LLViewerObject;
00216 };
00217 
00218 
00219 class LLDebugBeacon
00220 {
00221 public:
00222         ~LLDebugBeacon()
00223         {
00224                 if (mHUDObject.notNull())
00225                 {
00226                         mHUDObject->markDead();
00227                 }
00228         }
00229 
00230         LLVector3 mPositionAgent;
00231         LLString mString;
00232         LLColor4 mColor;
00233         LLColor4 mTextColor;
00234         S32 mLineWidth;
00235         LLPointer<LLHUDObject> mHUDObject;
00236 };
00237 
00238 
00239 
00240 // Global object list
00241 extern LLViewerObjectList gObjectList;
00242 
00243 // Inlines
00244 inline LLViewerObject *LLViewerObjectList::findObject(const LLUUID &id)
00245 {
00246         std::map<LLUUID, LLPointer<LLViewerObject> >::iterator iter = mUUIDObjectMap.find(id);
00247         if(iter != mUUIDObjectMap.end())
00248         {
00249                 return iter->second;
00250         }
00251         else
00252         {
00253                 return NULL;
00254         }
00255 }
00256 
00257 inline LLViewerObject *LLViewerObjectList::getObject(const S32 index)
00258 {
00259         LLViewerObject *objectp;
00260         objectp = mObjects[index];
00261         if (objectp->isDead())
00262         {
00263                 //llwarns << "Dead object " << objectp->mID << " in getObject" << llendl;
00264                 return NULL;
00265         }
00266         return objectp;
00267 }
00268 
00269 inline void LLViewerObjectList::addToMap(LLViewerObject *objectp)
00270 {
00271         mMapObjects.put(objectp);
00272 }
00273 
00274 inline void LLViewerObjectList::removeFromMap(LLViewerObject *objectp)
00275 {
00276         mMapObjects.removeObj(objectp);
00277 }
00278 
00279 
00280 #endif // LL_VIEWER_OBJECT_LIST_H

Generated on Thu Jul 1 06:09:32 2010 for Second Life Viewer by  doxygen 1.4.7