PageRenderTime 397ms CodeModel.GetById 110ms app.highlight 77ms RepoModel.GetById 115ms app.codeStats 0ms

/indra/newview/llviewerregion.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 476 lines | 300 code | 104 blank | 72 comment | 3 complexity | b8ff9191ed9ccd7b18206289f5fac0e1 MD5 | raw file
  1/** 
  2 * @file llviewerregion.h
  3 * @brief Description of the LLViewerRegion 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_LLVIEWERREGION_H
 28#define LL_LLVIEWERREGION_H
 29
 30// A ViewerRegion is a class that contains a bunch of objects and surfaces
 31// that are in to a particular region.
 32#include <string>
 33#include <boost/signals2.hpp>
 34
 35#include "lldarray.h"
 36#include "llwind.h"
 37#include "llstat.h"
 38#include "v3dmath.h"
 39#include "llstring.h"
 40#include "llregionflags.h"
 41#include "lluuid.h"
 42#include "llweb.h"
 43#include "llcapabilityprovider.h"
 44#include "m4math.h"					// LLMatrix4
 45#include "llhttpclient.h"
 46
 47// Surface id's
 48#define LAND  1
 49#define WATER 2
 50const U32	MAX_OBJECT_CACHE_ENTRIES = 50000;
 51
 52
 53class LLEventPoll;
 54class LLVLComposition;
 55class LLViewerObject;
 56class LLMessageSystem;
 57class LLNetMap;
 58class LLViewerParcelOverlay;
 59class LLSurface;
 60class LLVOCache;
 61class LLVOCacheEntry;
 62class LLSpatialPartition;
 63class LLEventPump;
 64class LLCapabilityListener;
 65class LLDataPacker;
 66class LLDataPackerBinaryBuffer;
 67class LLHost;
 68class LLBBox;
 69
 70class LLViewerRegionImpl;
 71
 72class LLViewerRegion: public LLCapabilityProvider // implements this interface
 73{
 74public:
 75	//MUST MATCH THE ORDER OF DECLARATION IN CONSTRUCTOR
 76	typedef enum 
 77	{
 78		PARTITION_HUD=0,
 79		PARTITION_TERRAIN,
 80		PARTITION_VOIDWATER,
 81		PARTITION_WATER,
 82		PARTITION_TREE,
 83		PARTITION_PARTICLE,
 84		PARTITION_GRASS,
 85		PARTITION_VOLUME,
 86		PARTITION_BRIDGE,
 87		PARTITION_HUD_PARTICLE,
 88		PARTITION_NONE,
 89		NUM_PARTITIONS
 90	} eObjectPartitions;
 91
 92	typedef boost::signals2::signal<void(const LLUUID& region_id)> caps_received_signal_t;
 93
 94	LLViewerRegion(const U64 &handle,
 95				   const LLHost &host,
 96				   const U32 surface_grid_width,
 97				   const U32 patch_grid_width,
 98				   const F32 region_width_meters);
 99	~LLViewerRegion();
100
101	// Call this after you have the region name and handle.
102	void loadObjectCache();
103	void saveObjectCache();
104
105	void sendMessage(); // Send the current message to this region's simulator
106	void sendReliableMessage(); // Send the current message to this region's simulator
107
108	void setOriginGlobal(const LLVector3d &origin);
109	//void setAgentOffset(const LLVector3d &offset);
110	void updateRenderMatrix();
111
112	void setAllowDamage(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_DAMAGE); }
113	void setAllowLandmark(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_LANDMARK); }
114	void setAllowSetHome(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_SET_HOME); }
115	void setResetHomeOnTeleport(BOOL b) { setFlags(b, REGION_FLAGS_RESET_HOME_ON_TELEPORT); }
116	void setSunFixed(BOOL b) { setFlags(b, REGION_FLAGS_SUN_FIXED); }
117	void setBlockFly(BOOL b) { setFlags(b, REGION_FLAGS_BLOCK_FLY); }
118	void setAllowDirectTeleport(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_DIRECT_TELEPORT); }
119
120
121	inline BOOL getAllowDamage()			const;
122	inline BOOL getAllowLandmark()			const;
123	inline BOOL getAllowSetHome()			const;
124	inline BOOL getResetHomeOnTeleport()	const;
125	inline BOOL getSunFixed()				const;
126	inline BOOL getBlockFly()				const;
127	inline BOOL getAllowDirectTeleport()	const;
128	inline BOOL isPrelude()					const;
129	inline BOOL getAllowTerraform() 		const;
130	inline BOOL getRestrictPushObject()		const;
131	inline BOOL getReleaseNotesRequested()		const;
132
133	bool isAlive(); // can become false if circuit disconnects
134
135	void setWaterHeight(F32 water_level);
136	F32 getWaterHeight() const;
137
138	BOOL isVoiceEnabled() const;
139
140	void setBillableFactor(F32 billable_factor) { mBillableFactor = billable_factor; }
141	F32 getBillableFactor() 		const 	{ return mBillableFactor; }
142
143	// Maximum number of primitives allowed, regardless of object
144	// bonus factor.
145	U32 getMaxTasks() const { return mMaxTasks; }
146	void setMaxTasks(U32 max_tasks) { mMaxTasks = max_tasks; }
147
148	// Draw lines in the dirt showing ownership. Return number of 
149	// vertices drawn.
150	S32 renderPropertyLines();
151
152	// Call this whenever you change the height data in the region.
153	// (Automatically called by LLSurfacePatch's update routine)
154	void dirtyHeights();
155
156	LLViewerParcelOverlay *getParcelOverlay() const
157			{ return mParcelOverlay; }
158
159	void setRegionFlags(U32 flags);
160	U32 getRegionFlags() const					{ return mRegionFlags; }
161
162	void setTimeDilation(F32 time_dilation);
163	F32  getTimeDilation() const				{ return mTimeDilation; }
164
165	// Origin height is at zero.
166	const LLVector3d &getOriginGlobal() const;
167	LLVector3 getOriginAgent() const;
168
169	// Center is at the height of the water table.
170	const LLVector3d &getCenterGlobal() const;
171	LLVector3 getCenterAgent() const;
172
173	void setRegionNameAndZone(const std::string& name_and_zone);
174	const std::string& getName() const				{ return mName; }
175	const std::string& getZoning() const			{ return mZoning; }
176
177	void setOwner(const LLUUID& owner_id);
178	const LLUUID& getOwner() const;
179
180	// Is the current agent on the estate manager list for this region?
181	void setIsEstateManager(BOOL b) { mIsEstateManager = b; }
182	BOOL isEstateManager() const { return mIsEstateManager; }
183	BOOL canManageEstate() const;
184
185	void setSimAccess(U8 sim_access)			{ mSimAccess = sim_access; }
186	U8 getSimAccess() const						{ return mSimAccess; }
187	const std::string getSimAccessString() const;
188	
189	// Homestead-related getters; there are no setters as nobody should be
190	// setting them other than the individual message handler which is a member
191	S32 getSimClassID()                    const { return mClassID; }
192	S32 getSimCPURatio()                   const { return mCPURatio; }
193	const std::string& getSimColoName()    const { return mColoName; }
194	const std::string& getSimProductSKU()  const { return mProductSKU; }
195	std::string getLocalizedSimProductName() const;
196
197	// Returns "Sandbox", "Expensive", etc.
198	static std::string regionFlagsToString(U32 flags);
199
200	// Returns translated version of "Mature", "PG", "Adult", etc.
201	static std::string accessToString(U8 sim_access);
202
203	// Returns "M", "PG", "A" etc.
204	static std::string accessToShortString(U8 sim_access);
205
206	// Return access icon name
207	static std::string getAccessIcon(U8 sim_access);
208	
209	// helper function which just makes sure all interested parties
210	// can process the message.
211	static void processRegionInfo(LLMessageSystem* msg, void**);
212
213	void setCacheID(const LLUUID& id);
214
215	F32	getWidth() const						{ return mWidth; }
216
217	BOOL idleUpdate(F32 max_update_time);
218
219	// Like idleUpdate, but forces everything to complete regardless of
220	// how long it takes.
221	void forceUpdate();
222
223	void connectNeighbor(LLViewerRegion *neighborp, U32 direction);
224
225	void updateNetStats();
226
227	U32	getPacketsLost() const;
228
229	S32 getHttpResponderID() const;
230
231	// Get/set named capability URLs for this region.
232	void setSeedCapability(const std::string& url);
233	void failedSeedCapability();
234	S32 getNumSeedCapRetries();
235	void setCapability(const std::string& name, const std::string& url);
236	// implements LLCapabilityProvider
237    virtual std::string getCapability(const std::string& name) const;
238
239	// has region received its final (not seed) capability list?
240	bool capabilitiesReceived() const;
241	void setCapabilitiesReceived(bool received);
242	boost::signals2::connection setCapabilitiesReceivedCallback(const caps_received_signal_t::slot_type& cb);
243
244	static bool isSpecialCapabilityName(const std::string &name);
245	void logActiveCapabilities() const;
246
247    /// Get LLEventPump on which we listen for capability requests
248    /// (https://wiki.lindenlab.com/wiki/Viewer:Messaging/Messaging_Notes#Capabilities)
249    LLEventPump& getCapAPI() const;
250
251    /// implements LLCapabilityProvider
252	/*virtual*/ const LLHost& getHost() const;
253	const U64 		&getHandle() const 			{ return mHandle; }
254
255	LLSurface		&getLand() const;
256
257	// set and get the region id
258	const LLUUID& getRegionID() const;
259	void setRegionID(const LLUUID& region_id);
260
261	BOOL pointInRegionGlobal(const LLVector3d &point_global) const;
262	LLVector3	getPosRegionFromGlobal(const LLVector3d &point_global) const;
263	LLVector3	getPosRegionFromAgent(const LLVector3 &agent_pos) const;
264	LLVector3	getPosAgentFromRegion(const LLVector3 &region_pos) const;
265	LLVector3d	getPosGlobalFromRegion(const LLVector3 &offset) const;
266
267	LLVLComposition *getComposition() const;
268	F32 getCompositionXY(const S32 x, const S32 y) const;
269
270	BOOL isOwnedSelf(const LLVector3& pos);
271
272	// Owned by a group you belong to?  (officer OR member)
273	BOOL isOwnedGroup(const LLVector3& pos);
274
275	// deal with map object updates in the world.
276	void updateCoarseLocations(LLMessageSystem* msg);
277
278	F32 getLandHeightRegion(const LLVector3& region_pos);
279
280	void getInfo(LLSD& info);
281	
282	bool meshRezEnabled() const;
283	bool meshUploadEnabled() const;
284
285	void getSimulatorFeatures(LLSD& info);	
286	void setSimulatorFeatures(const LLSD& info);
287
288	typedef enum
289	{
290		CACHE_MISS_TYPE_FULL = 0,
291		CACHE_MISS_TYPE_CRC,
292		CACHE_MISS_TYPE_NONE
293	} eCacheMissType;
294
295	typedef enum
296	{
297		CACHE_UPDATE_DUPE = 0,
298		CACHE_UPDATE_CHANGED,
299		CACHE_UPDATE_ADDED,
300		CACHE_UPDATE_REPLACED
301	} eCacheUpdateResult;
302
303	// handle a full update message
304	eCacheUpdateResult cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp);
305	LLDataPacker *getDP(U32 local_id, U32 crc, U8 &cache_miss_type);
306	void requestCacheMisses();
307	void addCacheMissFull(const U32 local_id);
308
309	void dumpCache();
310
311	void unpackRegionHandshake();
312
313	void calculateCenterGlobal();
314	void calculateCameraDistance();
315
316	friend std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region);
317    /// implements LLCapabilityProvider
318    virtual std::string getDescription() const;
319	std::string getHttpUrl() const { return mHttpUrl ;}
320
321	LLSpatialPartition* getSpatialPartition(U32 type);
322
323	bool objectIsReturnable(const LLVector3& pos, const std::vector<LLBBox>& boxes) const;
324	bool childrenObjectReturnable( const std::vector<LLBBox>& boxes ) const;
325	bool objectsCrossParcel(const std::vector<LLBBox>& boxes) const;
326
327	void getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions );
328	
329public:
330	struct CompareDistance
331	{
332		bool operator()(const LLViewerRegion* const& lhs, const LLViewerRegion* const& rhs)
333		{
334			return lhs->mCameraDistanceSquared < rhs->mCameraDistanceSquared; 
335		}
336	};
337
338	void showReleaseNotes();
339
340protected:
341	void disconnectAllNeighbors();
342	void initStats();
343	void setFlags(BOOL b, U32 flags);
344
345public:
346	LLWind  mWind;
347	LLViewerParcelOverlay	*mParcelOverlay;
348
349	LLStat	mBitStat;
350	LLStat	mPacketsStat;
351	LLStat	mPacketsLostStat;
352
353	LLMatrix4 mRenderMatrix;
354
355	// These arrays are maintained in parallel. Ideally they'd be combined into a
356	// single array of an aggrigate data type but for compatibility with the old
357	// messaging system in which the previous message only sends and parses the 
358	// positions stored in the first array so they're maintained separately until 
359	// we stop supporting the old CoarseLocationUpdate message.
360	LLDynamicArray<U32> mMapAvatars;
361	LLDynamicArray<LLUUID> mMapAvatarIDs;
362
363private:
364	LLViewerRegionImpl * mImpl;
365
366	F32			mWidth;			// Width of region on a side (meters)
367	U64			mHandle;
368	F32			mTimeDilation;	// time dilation of physics simulation on simulator
369
370	// simulator name
371	std::string mName;
372	std::string mZoning;
373
374	// Is this agent on the estate managers list for this region?
375	BOOL mIsEstateManager;
376
377	U32		mPacketsIn;
378	U32		mBitsIn;
379	U32		mLastBitsIn;
380	U32		mLastPacketsIn;
381	U32		mPacketsOut;
382	U32		mLastPacketsOut;
383	S32		mPacketsLost;
384	S32		mLastPacketsLost;
385	U32		mPingDelay;
386	F32		mDeltaTime;				// Time since last measurement of lastPackets, Bits, etc
387
388	U32		mRegionFlags;			// includes damage flags
389	U8		mSimAccess;
390	F32 	mBillableFactor;
391	U32		mMaxTasks;				// max prim count
392	F32		mCameraDistanceSquared;	// updated once per frame
393	
394	// Information for Homestead / CR-53
395	S32 mClassID;
396	S32 mCPURatio;
397
398	std::string mColoName;
399	std::string mProductSKU;
400	std::string mProductName;
401	std::string mHttpUrl ;
402	
403	// Maps local ids to cache entries.
404	// Regions can have order 10,000 objects, so assume
405	// a structure of size 2^14 = 16,000
406	BOOL									mCacheLoaded;
407	BOOL                                    mCacheDirty;
408
409	LLDynamicArray<U32>						mCacheMissFull;
410	LLDynamicArray<U32>						mCacheMissCRC;
411
412	bool	mAlive;					// can become false if circuit disconnects
413	bool	mCapabilitiesReceived;
414	caps_received_signal_t mCapabilitiesReceivedSignal;
415
416	BOOL mReleaseNotesRequested;
417	
418	LLSD mSimulatorFeatures;
419};
420
421inline BOOL LLViewerRegion::getAllowDamage() const
422{
423	return ((mRegionFlags & REGION_FLAGS_ALLOW_DAMAGE) !=0);
424}
425
426inline BOOL LLViewerRegion::getAllowLandmark() const
427{
428	return ((mRegionFlags & REGION_FLAGS_ALLOW_LANDMARK) !=0);
429}
430
431inline BOOL LLViewerRegion::getAllowSetHome() const
432{
433	return ((mRegionFlags & REGION_FLAGS_ALLOW_SET_HOME) != 0);
434}
435
436inline BOOL LLViewerRegion::getResetHomeOnTeleport() const
437{
438	return ((mRegionFlags & REGION_FLAGS_RESET_HOME_ON_TELEPORT) !=0);
439}
440
441inline BOOL LLViewerRegion::getSunFixed() const
442{
443	return ((mRegionFlags & REGION_FLAGS_SUN_FIXED) !=0);
444}
445
446inline BOOL LLViewerRegion::getBlockFly() const
447{
448	return ((mRegionFlags & REGION_FLAGS_BLOCK_FLY) !=0);
449}
450
451inline BOOL LLViewerRegion::getAllowDirectTeleport() const
452{
453	return ((mRegionFlags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT) !=0);
454}
455
456inline BOOL LLViewerRegion::isPrelude() const
457{
458	return is_prelude( mRegionFlags );
459}
460
461inline BOOL LLViewerRegion::getAllowTerraform() const
462{
463	return ((mRegionFlags & REGION_FLAGS_BLOCK_TERRAFORM) == 0);
464}
465
466inline BOOL LLViewerRegion::getRestrictPushObject() const
467{
468	return ((mRegionFlags & REGION_FLAGS_RESTRICT_PUSHOBJECT) != 0);
469}
470
471inline BOOL LLViewerRegion::getReleaseNotesRequested() const
472{
473	return mReleaseNotesRequested;
474}
475
476#endif