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

Generated on Fri May 16 08:34:17 2008 for SecondLife by  doxygen 1.5.5