llviewerregion.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLVIEWERREGION_H
00033 #define LL_LLVIEWERREGION_H
00034 
00035 // A ViewerRegion is a class that contains a bunch of objects and surfaces
00036 // that are in to a particular region.
00037 #include <string>
00038 
00039 #include "lldarray.h"
00040 #include "llwind.h"
00041 #include "llcloud.h"
00042 #include "llstat.h"
00043 #include "v3dmath.h"
00044 #include "llhost.h"
00045 #include "llstring.h"
00046 #include "llregionflags.h"
00047 #include "llptrskipmap.h"
00048 #include "lluuid.h"
00049 #include "lldatapacker.h"
00050 #include "llvocache.h"
00051 
00052 // Surface id's
00053 #define LAND  1
00054 #define WATER 2
00055 const U32       MAX_OBJECT_CACHE_ENTRIES = 10000;
00056 
00057 
00058 class LLEventPoll;
00059 class LLVLComposition;
00060 class LLViewerObject;
00061 class LLMessageSystem;
00062 class LLNetMap;
00063 class LLViewerParcelOverlay;
00064 class LLSurface;
00065 class LLVOCache;
00066 class LLVOCacheEntry;
00067 
00068 class LLViewerRegion 
00069 {
00070 public:
00071         LLViewerRegion(const U64 &handle,
00072                                    const LLHost &host,
00073                                    const U32 surface_grid_width,
00074                                    const U32 patch_grid_width,
00075                                    const F32 region_width_meters);
00076         ~LLViewerRegion();
00077 
00078         // Call this after you have the region name and handle.
00079         void loadCache();
00080 
00081         void saveCache();
00082 
00083         void sendMessage(); // Send the current message to this region's simulator
00084         void sendReliableMessage(); // Send the current message to this region's simulator
00085 
00086         void setOriginGlobal(const LLVector3d &origin);
00087         void setAgentOffset(const LLVector3d &offset);
00088 
00089         void setAllowDamage(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_DAMAGE); }
00090         void setAllowLandmark(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_LANDMARK); }
00091         void setAllowSetHome(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_SET_HOME); }
00092         void setResetHomeOnTeleport(BOOL b) { setFlags(b, REGION_FLAGS_RESET_HOME_ON_TELEPORT); }
00093         void setSunFixed(BOOL b) { setFlags(b, REGION_FLAGS_SUN_FIXED); }
00094         void setBlockFly(BOOL b) { setFlags(b, REGION_FLAGS_BLOCK_FLY); }
00095         void setAllowDirectTeleport(BOOL b) { setFlags(b, REGION_FLAGS_ALLOW_DIRECT_TELEPORT); }
00096 
00097 
00098         inline BOOL getAllowDamage()                    const;
00099         inline BOOL getAllowLandmark()                  const;
00100         inline BOOL getAllowSetHome()                   const;
00101         inline BOOL getResetHomeOnTeleport()    const;
00102         inline BOOL getSunFixed()                               const;
00103         inline BOOL getBlockFly()                               const;
00104         inline BOOL getAllowDirectTeleport()    const;
00105         inline BOOL isPrelude()                                 const;
00106         inline BOOL getAllowTerraform()                 const;
00107         inline BOOL getRestrictPushObject()             const;
00108 
00109         void setWaterHeight(F32 water_level);
00110         F32 getWaterHeight() const;
00111 
00112         void setBillableFactor(F32 billable_factor) { mBillableFactor = billable_factor; }
00113         F32 getBillableFactor()                 const   { return mBillableFactor; }
00114 
00115         // Maximum number of primitives allowed, regardless of object
00116         // bonus factor.
00117         U32 getMaxTasks() const { return mMaxTasks; }
00118         void setMaxTasks(U32 max_tasks) { mMaxTasks = max_tasks; }
00119 
00120         // Draw lines in the dirt showing ownership. Return number of 
00121         // vertices drawn.
00122         S32 renderPropertyLines();
00123 
00124         // Call this whenever you change the height data in the region.
00125         // (Automatically called by LLSurfacePatch's update routine)
00126         void dirtyHeights();
00127 
00128         LLViewerParcelOverlay *getParcelOverlay() const
00129                         { return mParcelOverlay; }
00130 
00131         void setRegionFlags(U32 flags);
00132         U32 getRegionFlags() const                                      { return mRegionFlags; }
00133 
00134         void setTimeDilation(F32 time_dilation);
00135         F32  getTimeDilation() const                            { return mTimeDilation; }
00136 
00137         // Origin height is at zero.
00138         const LLVector3d &getOriginGlobal() const       { return mOriginGlobal; }
00139         LLVector3 getOriginAgent() const;
00140 
00141         // Center is at the height of the water table.
00142         const LLVector3d &getCenterGlobal() const       { return mCenterGlobal; }
00143         LLVector3 getCenterAgent() const;
00144 
00145         void setRegionNameAndZone(const char* name_and_zone);
00146         const LLString& getName() const                         { return mName; }
00147         const LLString& getZoning() const                       { return mZoning; }
00148 
00149         void setOwner(const LLUUID& owner_id) { mOwnerID = owner_id; }
00150         const LLUUID& getOwner() const { return mOwnerID; }
00151 
00152         // Is the current agent on the estate manager list for this region?
00153         void setIsEstateManager(BOOL b) { mIsEstateManager = b; }
00154         BOOL isEstateManager() const { return mIsEstateManager; }
00155         BOOL canManageEstate() const;
00156 
00157         void setSimAccess(U8 sim_access)                        { mSimAccess = sim_access; }
00158         U8 getSimAccess() const                                         { return mSimAccess; }
00159         const char* getSimAccessString() const;
00160 
00161         // Returns "Sandbox", "Expensive", etc.
00162         static std::string regionFlagsToString(U32 flags);
00163 
00164         // Returns "Mature", "PG", etc.
00165         static const char* accessToString(U8 access);
00166 
00167         static U8 stringToAccess(const char* access_str);
00168 
00169         // Returns "M", "PG", etc.
00170         static const char* accessToShortString(U8 access);              /* Flawfinder: ignore */
00171 
00172         // helper function which just makes sure all interested parties
00173         // can process the message.
00174         static void processRegionInfo(LLMessageSystem* msg, void**);
00175 
00176         void setCacheID(const LLUUID& id)                       { mCacheID = id; }
00177 
00178         F32     getWidth() const                                                { return mWidth; }
00179 
00180         BOOL idleUpdate(F32 max_update_time);
00181 
00182         // Like idleUpdate, but forces everything to complete regardless of
00183         // how long it takes.
00184         void forceUpdate();
00185 
00186         void connectNeighbor(LLViewerRegion *neighborp, U32 direction);
00187 
00188         void updateNetStats();
00189 
00190         U32     getPacketsLost() const;
00191 
00192         // Get/set named capability URLs for this region.
00193         void setSeedCapability(const std::string& url);
00194         void setCapability(const std::string& name, const std::string& url);
00195         std::string getCapability(const std::string& name) const;
00196         void logActiveCapabilities() const;
00197 
00198         const LLHost    &getHost() const                        { return mHost; }
00199         const U64               &getHandle() const                      { return mHandle; }
00200 
00201         LLSurface               &getLand() const                        { return *mLandp; }
00202 
00203         // set and get the region id
00204         const LLUUID& getRegionID() const { return mRegionID; }
00205         void setRegionID(const LLUUID& region_id) { mRegionID = region_id; }
00206 
00207         BOOL pointInRegionGlobal(const LLVector3d &point_global) const;
00208         LLVector3       getPosRegionFromGlobal(const LLVector3d &point_global) const;
00209         LLVector3       getPosRegionFromAgent(const LLVector3 &agent_pos) const;
00210         LLVector3       getPosAgentFromRegion(const LLVector3 &region_pos) const;
00211         LLVector3d      getPosGlobalFromRegion(const LLVector3 &offset) const;
00212 
00213         LLVLComposition *getComposition() const         { return mCompositionp; }
00214         F32 getCompositionXY(const S32 x, const S32 y) const;
00215 
00216         BOOL isOwnedSelf(const LLVector3& pos);
00217 
00218         // Owned by a group you belong to?  (officer OR member)
00219         BOOL isOwnedGroup(const LLVector3& pos);
00220 
00221         // deal with map object updates in the world.
00222         void updateCoarseLocations(LLMessageSystem* msg);
00223 
00224         F32 getLandHeightRegion(const LLVector3& region_pos);
00225 
00226         LLString getInfoString();
00227 
00228         // handle a full update message
00229         void cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp);
00230         LLDataPacker *getDP(U32 local_id, U32 crc);
00231         void requestCacheMisses();
00232         void addCacheMissFull(const U32 local_id);
00233 
00234         void dumpCache();
00235 
00236         void unpackRegionHandshake();
00237 
00238         void calculateCenterGlobal();
00239         void calculateCameraDistance();
00240 
00241         friend std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region);
00242 
00243         // used by LCD to get details for debug screen
00244         U32 getNetDetailsForLCD();
00245 
00246 public:
00247         struct CompareDistance
00248         {
00249                 bool operator()(const LLViewerRegion* const& lhs, const LLViewerRegion* const& rhs)
00250                 {
00251                         return lhs->mCameraDistanceSquared < rhs->mCameraDistanceSquared; 
00252                 }
00253         };
00254         
00255 protected:
00256         void disconnectAllNeighbors();
00257         void initStats();
00258         void setFlags(BOOL b, U32 flags);
00259 
00260 public:
00261         LLWind  mWind;
00262         LLCloudLayer mCloudLayer;
00263         LLViewerParcelOverlay   *mParcelOverlay;
00264 
00265         BOOL    mAlive;                                 // can become false if circuit disconnects
00266 
00267         LLStat  mBitStat;
00268         LLStat  mPacketsStat;
00269         LLStat  mPacketsLostStat;
00270 
00271         // These arrays are maintained in parallel. Ideally they'd be combined into a
00272         // single array of an aggrigate data type but for compatibility with the old
00273         // messaging system in which the previous message only sends and parses the 
00274         // positions stored in the first array so they're maintained separately until 
00275         // we stop supporting the old CoarseLocationUpdate message.
00276         LLDynamicArray<U32> mMapAvatars;
00277         LLDynamicArray<LLUUID> mMapAvatarIDs;
00278 
00279 protected:
00280         // The surfaces and other layers
00281         LLSurface*      mLandp;
00282 
00283         // Region geometry data
00284         LLVector3d      mOriginGlobal;  // Location of southwest corner of region (meters)
00285         LLVector3d      mCenterGlobal;  // Location of center in world space (meters)
00286         F32                     mWidth;                 // Width of region on a side (meters)
00287 
00288         U64                     mHandle;
00289         LLHost          mHost;
00290 
00291         // The unique ID for this region.
00292         LLUUID mRegionID;
00293 
00294         F32                     mTimeDilation;  // time dilation of physics simulation on simulator
00295 
00296         // simulator name
00297         LLString mName;
00298         LLString mZoning;
00299 
00300         // region/estate owner - usually null.
00301         LLUUID mOwnerID;
00302 
00303         // Is this agent on the estate managers list for this region?
00304         BOOL mIsEstateManager;
00305 
00306         // Network statistics for the region's circuit...
00307         LLTimer mLastNetUpdate;
00308         U32             mPacketsIn;
00309         U32             mBitsIn;
00310         U32             mLastBitsIn;
00311         U32             mLastPacketsIn;
00312         U32             mPacketsOut;
00313         U32             mLastPacketsOut;
00314         S32             mPacketsLost;
00315         S32             mLastPacketsLost;
00316         U32             mPingDelay;
00317         F32             mDeltaTime;                             // Time since last measurement of lastPackets, Bits, etc
00318 
00319         // Misc
00320         LLVLComposition *mCompositionp;         // Composition layer for the surface
00321 
00322         U32             mRegionFlags;                   // includes damage flags
00323         U8              mSimAccess;
00324         F32     mBillableFactor;
00325         U32             mMaxTasks;                              // max prim count
00326         F32             mCameraDistanceSquared; // updated once per frame
00327         
00328         // Maps local ids to cache entries.
00329         // Regions can have order 10,000 objects, so assume
00330         // a structure of size 2^14 = 16,000
00331         BOOL                                                                    mCacheLoaded;
00332         LLPtrSkipMap<U32, LLVOCacheEntry *, 14> mCacheMap;
00333         LLVOCacheEntry                                                  mCacheStart;
00334         LLVOCacheEntry                                                  mCacheEnd;
00335         U32                                                                             mCacheEntriesCount;
00336         LLDynamicArray<U32>                                             mCacheMissFull;
00337         LLDynamicArray<U32>                                             mCacheMissCRC;
00338         // time?
00339         // LRU info?
00340 
00341         // Cache ID is unique per-region, across renames, moving locations,
00342         // etc.
00343         LLUUID mCacheID;
00344         
00345         typedef std::map<std::string, std::string> CapabilityMap;
00346         CapabilityMap mCapabilities;
00347         
00348         LLEventPoll* mEventPoll;
00349 };
00350 
00351 inline BOOL LLViewerRegion::getAllowDamage() const
00352 {
00353         return ((mRegionFlags & REGION_FLAGS_ALLOW_DAMAGE) !=0);
00354 }
00355 
00356 inline BOOL LLViewerRegion::getAllowLandmark() const
00357 {
00358         return ((mRegionFlags & REGION_FLAGS_ALLOW_LANDMARK) !=0);
00359 }
00360 
00361 inline BOOL LLViewerRegion::getAllowSetHome() const
00362 {
00363         return ((mRegionFlags & REGION_FLAGS_ALLOW_SET_HOME) != 0);
00364 }
00365 
00366 inline BOOL LLViewerRegion::getResetHomeOnTeleport() const
00367 {
00368         return ((mRegionFlags & REGION_FLAGS_RESET_HOME_ON_TELEPORT) !=0);
00369 }
00370 
00371 inline BOOL LLViewerRegion::getSunFixed() const
00372 {
00373         return ((mRegionFlags & REGION_FLAGS_SUN_FIXED) !=0);
00374 }
00375 
00376 inline BOOL LLViewerRegion::getBlockFly() const
00377 {
00378         return ((mRegionFlags & REGION_FLAGS_BLOCK_FLY) !=0);
00379 }
00380 
00381 inline BOOL LLViewerRegion::getAllowDirectTeleport() const
00382 {
00383         return ((mRegionFlags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT) !=0);
00384 }
00385 
00386 inline BOOL LLViewerRegion::isPrelude() const
00387 {
00388         return is_prelude( mRegionFlags );
00389 }
00390 
00391 inline BOOL LLViewerRegion::getAllowTerraform() const
00392 {
00393         return ((mRegionFlags & REGION_FLAGS_BLOCK_TERRAFORM) == 0);
00394 }
00395 
00396 inline BOOL LLViewerRegion::getRestrictPushObject() const
00397 {
00398         return ((mRegionFlags & REGION_FLAGS_RESTRICT_PUSHOBJECT) != 0);
00399 }
00400 
00401 #endif
00402 
00403 

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