PageRenderTime 38ms CodeModel.GetById 12ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  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
 27#ifndef LL_LLVIEWEROBJECTLIST_H
 28#define LL_LLVIEWEROBJECTLIST_H
 29
 30#include <map>
 31#include <set>
 32
 33// common includes
 34#include "llstat.h"
 35#include "llstring.h"
 36
 37// project includes
 38#include "llviewerobject.h"
 39
 40class LLCamera;
 41class LLNetMap;
 42class LLDebugBeacon;
 43
 44const U32 CLOSE_BIN_SIZE = 10;
 45const U32 NUM_BINS = 128;
 46
 47// GL name = position in object list + GL_NAME_INDEX_OFFSET so that
 48// we can have special numbers like zero.
 49const U32 GL_NAME_LAND = 0;
 50const U32 GL_NAME_PARCEL_WALL = 1;
 51
 52const U32 GL_NAME_INDEX_OFFSET = 10;
 53
 54class LLViewerObjectList
 55{
 56public:
 57	LLViewerObjectList();
 58	~LLViewerObjectList();
 59
 60	void destroy();
 61
 62	// For internal use only.  Does NOT take a local id, takes an index into
 63	// an internal dynamic array.
 64	inline LLViewerObject *getObject(const S32 index);
 65	
 66	inline LLViewerObject *findObject(const LLUUID &id);
 67	LLViewerObject *createObjectViewer(const LLPCode pcode, LLViewerRegion *regionp); // Create a viewer-side object
 68	LLViewerObject *createObject(const LLPCode pcode, LLViewerRegion *regionp,
 69								 const LLUUID &uuid, const U32 local_id, const LLHost &sender);
 70
 71	LLViewerObject *replaceObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp); // TomY: hack to switch VO instances on the fly
 72	
 73	BOOL killObject(LLViewerObject *objectp);
 74	void killObjects(LLViewerRegion *regionp); // Kill all objects owned by a particular region.
 75	void killAllObjects();
 76	void removeDrawable(LLDrawable* drawablep);
 77
 78	void cleanDeadObjects(const BOOL use_timer = TRUE);	// Clean up the dead object list.
 79
 80	// Simulator and viewer side object updates...
 81	void processUpdateCore(LLViewerObject* objectp, void** data, U32 block, const EObjectUpdateType update_type, LLDataPacker* dpp, BOOL justCreated);
 82	void processObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type, bool cached=false, bool compressed=false);
 83	void processCompressedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type);
 84	void processCachedObjectUpdate(LLMessageSystem *mesgsys, void **user_data, EObjectUpdateType update_type);
 85	void updateApparentAngles(LLAgent &agent);
 86	void update(LLAgent &agent, LLWorld &world);
 87
 88	void fetchObjectCosts();
 89	void fetchPhysicsFlags();
 90
 91	void updateObjectCost(LLViewerObject* object);
 92	void updateObjectCost(const LLUUID& object_id, F32 object_cost, F32 link_cost, F32 physics_cost, F32 link_physics_cost);
 93	void onObjectCostFetchFailure(const LLUUID& object_id);
 94
 95	void updatePhysicsFlags(const LLViewerObject* object);
 96	void onPhysicsFlagsFetchFailure(const LLUUID& object_id);
 97	void updatePhysicsShapeType(const LLUUID& object_id, S32 type);
 98	void updatePhysicsProperties(const LLUUID& object_id,
 99									F32 density,
100									F32 friction,
101									F32 restitution,
102									F32 gravity_multiplier);
103
104	void shiftObjects(const LLVector3 &offset);
105	void repartitionObjects();
106
107	bool hasMapObjectInRegion(LLViewerRegion* regionp) ;
108	void clearAllMapObjectsInRegion(LLViewerRegion* regionp) ;
109	void renderObjectsForMap(LLNetMap &netmap);
110	void renderObjectBounds(const LLVector3 &center);
111
112	void addDebugBeacon(const LLVector3 &pos_agent, const std::string &string,
113						const LLColor4 &color=LLColor4(1.f, 0.f, 0.f, 0.5f),
114						const LLColor4 &text_color=LLColor4(1.f, 1.f, 1.f, 1.f),
115						S32 line_width = 1);
116	void renderObjectBeacons();
117	void resetObjectBeacons();
118
119	void dirtyAllObjectInventory();
120
121	void updateActive(LLViewerObject *objectp);
122	void updateAvatarVisibility();
123
124	// Selection related stuff
125	void generatePickList(LLCamera &camera);
126
127	LLViewerObject *getSelectedObject(const U32 object_id);
128
129	inline S32 getNumObjects() { return (S32) mObjects.size(); }
130
131	void addToMap(LLViewerObject *objectp);
132	void removeFromMap(LLViewerObject *objectp);
133
134	void clearDebugText();
135
136	////////////////////////////////////////////
137	//
138	// Only accessed by markDead in LLViewerObject
139	void cleanupReferences(LLViewerObject *objectp);
140
141	S32 findReferences(LLDrawable *drawablep) const; // Find references to drawable in all objects, and return value.
142
143	S32 getOrphanParentCount() const { return (S32) mOrphanParents.size(); }
144	S32 getOrphanCount() const { return mNumOrphans; }
145	void orphanize(LLViewerObject *childp, U32 parent_id, U32 ip, U32 port);
146	void findOrphans(LLViewerObject* objectp, U32 ip, U32 port);
147
148public:
149	// Class for keeping track of orphaned objects
150	class OrphanInfo
151	{
152	public:
153		OrphanInfo();
154		OrphanInfo(const U64 parent_info, const LLUUID child_info);
155		bool operator==(const OrphanInfo &rhs) const;
156		bool operator!=(const OrphanInfo &rhs) const;
157		U64 mParentInfo;
158		LLUUID mChildInfo;
159	};
160
161
162	U32	mCurBin; // Current bin we're working on...
163
164	// Statistics data (see also LLViewerStats)
165	S32 mNumNewObjects;
166	S32 mNumSizeCulled;
167	S32 mNumVisCulled;
168
169	// if we paused in the last frame
170	// used to discount stats from this frame
171	BOOL mWasPaused;
172
173	static void getUUIDFromLocal(LLUUID &id,
174								const U32 local_id,
175								const U32 ip,
176								const U32 port);
177	static void setUUIDAndLocal(const LLUUID &id,
178								const U32 local_id,
179								const U32 ip,
180								const U32 port); // Requires knowledge of message system info!
181
182	static BOOL removeFromLocalIDTable(const LLViewerObject* objectp);
183	// Used ONLY by the orphaned object code.
184	static U64 getIndex(const U32 local_id, const U32 ip, const U32 port);
185
186	S32 mNumUnknownUpdates;
187	S32 mNumDeadObjectUpdates;
188	S32 mNumUnknownKills;
189	S32 mNumDeadObjects;
190protected:
191	std::vector<U64>	mOrphanParents;	// LocalID/ip,port of orphaned objects
192	std::vector<OrphanInfo> mOrphanChildren;	// UUID's of orphaned objects
193	S32 mNumOrphans;
194
195	typedef std::vector<LLPointer<LLViewerObject> > vobj_list_t;
196
197	vobj_list_t mObjects;
198	std::set<LLPointer<LLViewerObject> > mActiveObjects;
199
200	vobj_list_t mMapObjects;
201
202	std::set<LLUUID> mDeadObjects;	
203
204	std::map<LLUUID, LLPointer<LLViewerObject> > mUUIDObjectMap;
205
206	//set of objects that need to update their cost
207	std::set<LLUUID> mStaleObjectCost;
208	std::set<LLUUID> mPendingObjectCost;
209
210	//set of objects that need to update their physics flags
211	std::set<LLUUID> mStalePhysicsFlags;
212	std::set<LLUUID> mPendingPhysicsFlags;
213
214	std::vector<LLDebugBeacon> mDebugBeacons;
215
216	S32 mCurLazyUpdateIndex;
217
218	static U32 sSimulatorMachineIndex;
219	static std::map<U64, U32> sIPAndPortToIndex;
220
221	static std::map<U64, LLUUID> sIndexAndLocalIDToUUID;
222
223	std::set<LLViewerObject *> mSelectPickList;
224
225	friend class LLViewerObject;
226};
227
228
229class LLDebugBeacon
230{
231public:
232	~LLDebugBeacon()
233	{
234		if (mHUDObject.notNull())
235		{
236			mHUDObject->markDead();
237		}
238	}
239
240	LLVector3 mPositionAgent;
241	std::string mString;
242	LLColor4 mColor;
243	LLColor4 mTextColor;
244	S32 mLineWidth;
245	LLPointer<LLHUDObject> mHUDObject;
246};
247
248
249
250// Global object list
251extern LLViewerObjectList gObjectList;
252
253// Inlines
254/**
255 * Note:
256 * it will return NULL for offline avatar_id 
257 */
258inline LLViewerObject *LLViewerObjectList::findObject(const LLUUID &id)
259{
260	std::map<LLUUID, LLPointer<LLViewerObject> >::iterator iter = mUUIDObjectMap.find(id);
261	if(iter != mUUIDObjectMap.end())
262	{
263		return iter->second;
264	}
265	else
266	{
267		return NULL;
268	}
269}
270
271inline LLViewerObject *LLViewerObjectList::getObject(const S32 index)
272{
273	LLViewerObject *objectp;
274	objectp = mObjects[index];
275	if (objectp->isDead())
276	{
277		//llwarns << "Dead object " << objectp->mID << " in getObject" << llendl;
278		return NULL;
279	}
280	return objectp;
281}
282
283inline void LLViewerObjectList::addToMap(LLViewerObject *objectp)
284{
285	mMapObjects.push_back(objectp);
286}
287
288inline void LLViewerObjectList::removeFromMap(LLViewerObject *objectp)
289{
290	std::vector<LLPointer<LLViewerObject> >::iterator iter = std::find(mMapObjects.begin(), mMapObjects.end(), objectp);
291	if (iter != mMapObjects.end())
292	{
293		mMapObjects.erase(iter);
294	}
295}
296
297
298#endif // LL_VIEWER_OBJECT_LIST_H