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