llviewerparcelmgr.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /**
  2. * @file llviewerparcelmgr.h
  3. * @brief Viewer-side representation of owned land
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERPARCELMGR_H
  33. #define LL_LLVIEWERPARCELMGR_H
  34. #include "boost/function.hpp"
  35. #include "boost/signals2.hpp"
  36. #include "llframetimer.h"
  37. #include "llhandle.h"
  38. #include "llparcel.h"
  39. #include "llvector3d.h"
  40. #include "llparcelselection.h"
  41. class LLMessageSystem;
  42. class LLViewerTexture;
  43. class LLViewerRegion;
  44. // A dwell having this value will be displayed as Loading...
  45. constexpr F32 DWELL_NAN = -1.f;
  46. constexpr F32 PARCEL_POST_HEIGHT = 0.666f;
  47. // Base class for people who want to "observe" changes in the viewer parcel
  48. // selection.
  49. class LLParcelSelectionObserver
  50. {
  51. public:
  52. virtual ~LLParcelSelectionObserver() = default;
  53. virtual void changed() = 0;
  54. };
  55. struct LLParcelData
  56. {
  57. S32 mActualArea;
  58. S32 mBillableArea;
  59. S32 mSalePrice;
  60. S32 mAuctionId;
  61. F32 mGlobalX;
  62. F32 mGlobalY;
  63. F32 mGlobalZ;
  64. F32 mDwell;
  65. LLUUID mParcelId;
  66. LLUUID mOwnerId;
  67. LLUUID mSnapshotId;
  68. std::string mName;
  69. std::string mDesc;
  70. std::string mSimName;
  71. U8 mFlags;
  72. };
  73. class LLParcelInfoObserver
  74. {
  75. public:
  76. LLParcelInfoObserver()
  77. {
  78. mObserverHandle.bind(this);
  79. }
  80. virtual ~LLParcelInfoObserver()
  81. {
  82. }
  83. virtual void processParcelInfo(const LLParcelData& parcel_data) = 0;
  84. virtual void setParcelID(const LLUUID& parcel_id) = 0;
  85. virtual void setErrorStatus(S32 status, const std::string& reason) = 0;
  86. LL_INLINE LLHandle<LLParcelInfoObserver> getObserverHandle() const
  87. {
  88. return mObserverHandle;
  89. }
  90. protected:
  91. LLRootHandle<LLParcelInfoObserver> mObserverHandle;
  92. };
  93. class LLViewerParcelMgr
  94. {
  95. protected:
  96. LOG_CLASS(LLViewerParcelMgr);
  97. public:
  98. typedef boost::function<void (const LLVector3d&,
  99. const bool& local)> tp_finished_cb_t;
  100. typedef boost::signals2::signal<void(const LLVector3d&,
  101. const bool&)> tp_finished_sig_t;
  102. typedef boost::function<void()> parcel_changed_cb_t;
  103. typedef boost::signals2::signal<void()> parcel_changed_sig_t;
  104. LLViewerParcelMgr();
  105. void initClass();
  106. void cleanupClass();
  107. // Variable region size support
  108. void setRegionWidth(F32 region_size);
  109. LL_INLINE bool selectionEmpty() const { return !mSelected; }
  110. LL_INLINE F32 getSelectionWidth() const { return F32(mEastNorth.mdV[VX] -
  111. mWestSouth.mdV[VX]); }
  112. LL_INLINE F32 getSelectionHeight() const { return F32(mEastNorth.mdV[VY] -
  113. mWestSouth.mdV[VY]); }
  114. LL_INLINE bool getSelection(LLVector3d& min, LLVector3d& max)
  115. {
  116. min = mWestSouth;
  117. max = mEastNorth;
  118. return !selectionEmpty();
  119. }
  120. LLViewerRegion* getSelectionRegion();
  121. LL_INLINE F32 getDwelling() const { return mSelectedDwell;}
  122. void getDisplayInfo(S32* area, S32* claim, S32* rent, bool* for_sale,
  123. F32* dwell);
  124. // Returns selected area
  125. S32 getSelectedArea() const;
  126. void resetSegments(U8* segments);
  127. // write a rectangle's worth of line segments into the highlight array
  128. void writeHighlightSegments(F32 west, F32 south, F32 east, F32 north);
  129. // Write highlight segments from a packed bitmap of the appropriate
  130. // parcel.
  131. void writeSegmentsFromBitmap(U8* bitmap, U8* segments);
  132. void writeAgentParcelFromBitmap(U8* bitmap);
  133. // Select the collision parcel
  134. void selectCollisionParcel();
  135. // Select the parcel at a specific point
  136. LLParcelSelectionHandle selectParcelAt(const LLVector3d& pos_global);
  137. // Take the current rectangle select, and select the parcel contained
  138. // within it.
  139. LLParcelSelectionHandle selectParcelInRectangle();
  140. // Select a piece of land
  141. LLParcelSelectionHandle selectLand(const LLVector3d& corner1,
  142. const LLVector3d& corner2,
  143. bool snap_to_parcel);
  144. // Clear the selection, and stop drawing the highlight.
  145. void deselectLand();
  146. void deselectUnused();
  147. void addSelectionObserver(LLParcelSelectionObserver* obs);
  148. void removeSelectionObserver(LLParcelSelectionObserver* obs);
  149. void notifySelectionObservers();
  150. LL_INLINE void setSelectionVisible(bool b) { mRenderSelection = b; }
  151. bool isOwnedAt(const LLVector3d& pos_global) const;
  152. bool isOwnedSelfAt(const LLVector3d& pos_global) const;
  153. bool isOwnedOtherAt(const LLVector3d& pos_global) const;
  154. bool isSoundLocal(const LLVector3d& pos_global) const;
  155. bool canHearSound(const LLVector3d& pos_global) const;
  156. // Returns a reference counted pointer to current parcel selection.
  157. // Selection does not change to reflect new selections made by user.
  158. // Use this when implementing a task UI that refers to a specific
  159. // selection.
  160. LL_INLINE LLParcelSelectionHandle getParcelSelection() const
  161. {
  162. return mCurrentParcelSelection;
  163. }
  164. // Returns a reference counted pointer to current parcel selection.
  165. // Pointer tracks whatever the user has currently selected.
  166. // Use this when implementing an inspector UI.
  167. // http://en.wikipedia.org/wiki/Inspector_window
  168. LL_INLINE LLParcelSelectionHandle getFloatingParcelSelection() const
  169. {
  170. return mFloatingParcelSelection;
  171. }
  172. LL_INLINE LLParcel* getAgentParcel() const { return mAgentParcel; }
  173. LLParcel* getSelectedOrAgentParcel() const;
  174. bool inAgentParcel(const LLVector3d& pos_global) const;
  175. LL_INLINE LLParcel* getHoverParcel() const
  176. {
  177. return mHoverRequestResult == PARCEL_RESULT_SUCCESS ? mHoverParcel
  178. : NULL;
  179. }
  180. LL_INLINE LLParcel* getCollisionParcel() const
  181. {
  182. return mRenderCollision ? mCollisionParcel : NULL;
  183. }
  184. // Can this agent build on the parcel he is on ?
  185. // Used for parcel property icons in status bar.
  186. bool allowAgentBuild(bool prelude_check = true) const;
  187. bool allowAgentBuild(const LLParcel* parcel) const;
  188. // Can this agent speak on the parcel he is on ?
  189. // Used for parcel property icons in status bar.
  190. bool allowAgentVoice() const;
  191. bool allowAgentVoice(const LLViewerRegion* region,
  192. const LLParcel* parcel) const;
  193. // Can this agent start flying on this parcel ?
  194. // Used for parcel property icons in status bar.
  195. bool allowAgentFly(const LLViewerRegion* region,
  196. const LLParcel* parcel) const;
  197. // Can this agent be pushed by llPushObject() on this parcel?
  198. // Used for parcel property icons in status bar.
  199. bool allowAgentPush(const LLViewerRegion* region,
  200. const LLParcel* parcel) const;
  201. // Can scripts written by non-parcel-owners run on the agent's current
  202. // parcel ? Used for parcel property icons in status bar.
  203. bool allowAgentScripts(const LLViewerRegion* region,
  204. const LLParcel* parcel) const;
  205. // Can the agent be damaged here ?
  206. // Used for parcel property icons in status bar.
  207. bool allowAgentDamage(const LLViewerRegion* region,
  208. const LLParcel* parcel) const;
  209. LL_INLINE F32 getHoverParcelWidth() const
  210. {
  211. return F32(mHoverEastNorth.mdV[VX] - mHoverWestSouth.mdV[VX]);
  212. }
  213. LL_INLINE F32 getHoverParcelHeight() const
  214. {
  215. return F32(mHoverEastNorth.mdV[VY] - mHoverWestSouth.mdV[VY]);
  216. }
  217. // UTILITIES
  218. void render();
  219. void renderParcelCollision();
  220. void renderRect(const LLVector3d& west_south_bottom,
  221. const LLVector3d& east_north_top);
  222. void renderOneSegment(F32 x1, F32 y1, F32 x2, F32 y2, F32 height,
  223. U8 direction, LLViewerRegion* regionp);
  224. void renderHighlightSegments(const U8* segments, LLViewerRegion* regionp);
  225. void renderCollisionSegments(U8* segments, bool use_pass,
  226. LLViewerRegion* regionp);
  227. void sendParcelGodForceOwner(const LLUUID& owner_id);
  228. // Makes the selected parcel a content parcel.
  229. void sendParcelGodForceToContent();
  230. // Packs information about this parcel and send it to the region containing
  231. // the southwest corner of the selection.
  232. void sendParcelPropertiesUpdate(LLParcel* parcel,
  233. bool use_agent_region = false);
  234. // Takes an Access List flag, like AL_ACCESS or AL_BAN
  235. void sendParcelAccessListUpdate(U32 which);
  236. // Takes an Access List flag, like AL_ACCESS or AL_BAN
  237. void sendParcelAccessListRequest(U32 flags);
  238. // Dwell is not part of the usual parcel update information because the
  239. // simulator does not actually know the per-parcel dwell. Ack ! We have
  240. // to get it out of the database.
  241. void sendParcelDwellRequest();
  242. // If the point is outside the current hover parcel, request more data
  243. void setHoverParcel(const LLVector3d& pos_global);
  244. // Used to re-request agent parcel properties (with id omitted).
  245. bool requestParcelProperties(const LLVector3d& pos_global,
  246. S32 id = UPDATE_AGENT_PARCEL_SEQ_ID);
  247. bool canAgentBuyParcel(LLParcel* parcel, bool for_group) const;
  248. void startBuyLand(bool is_for_group = false);
  249. void startSellLand();
  250. void startReleaseLand();
  251. void startDivideLand();
  252. void startJoinLand();
  253. void startDeedLandToGroup();
  254. void reclaimParcel();
  255. void buyPass();
  256. // Buying Land
  257. struct ParcelBuyInfo;
  258. ParcelBuyInfo* setupParcelBuy(const LLUUID& agent_id,
  259. const LLUUID& session_id,
  260. const LLUUID& group_id,
  261. bool is_group_owned, bool is_claim,
  262. bool remove_contribution);
  263. // Callers responsibility to call deleteParcelBuy() on return value
  264. void sendParcelBuy(ParcelBuyInfo*);
  265. void deleteParcelBuy(ParcelBuyInfo*&);
  266. void sendParcelDeed(const LLUUID& group_id);
  267. // Send the ParcelRelease message
  268. void sendParcelRelease();
  269. // Accessors for mAgentParcel
  270. LL_INLINE const std::string& getAgentParcelName() const
  271. {
  272. return mAgentParcel->getName();
  273. }
  274. S32 getAgentParcelId() const;
  275. LL_INLINE bool waitingForParcelInfo() const
  276. {
  277. return mTeleportInProgress;
  278. }
  279. #if 0 // *NOTE: Taken out 2005-03-21. Phoenix.
  280. // Create a landmark at the "appropriate" location for the currently
  281. // selected parcel.
  282. void makeLandmarkAtSelection();
  283. #endif
  284. void resetCollisionSegments();
  285. static void processParcelOverlay(LLMessageSystem* msg, void** data);
  286. static void processParcelProperties(LLMessageSystem* msg, void** data);
  287. static void processParcelAccessListReply(LLMessageSystem* msg,
  288. void** data);
  289. static void processParcelDwellReply(LLMessageSystem* msg, void** data);
  290. void dump();
  291. // Whether or not the collision border around the parcel is there because
  292. // the agent is banned or not in the allowed group
  293. bool isCollisionBanned();
  294. boost::signals2::connection addAgentParcelChangedCB(parcel_changed_cb_t cb);
  295. boost::signals2::connection setTPArrivingCallback(parcel_changed_cb_t cb);
  296. boost::signals2::connection setTPFinishedCallback(tp_finished_cb_t cb);
  297. boost::signals2::connection setTPFailedCallback(parcel_changed_cb_t cb);
  298. void onTeleportFinished(bool local, const LLVector3d& new_pos);
  299. void onTeleportFailed();
  300. static bool isParcelOwnedByAgent(const LLParcel* parcelp,
  301. U64 group_proxy_power);
  302. static bool isParcelModifiableByAgent(const LLParcel* parcelp,
  303. U64 group_proxy_power);
  304. // Methods for parcel info observers (declared in llremoteparcelrequest.h
  305. // in v3 viewers).
  306. void addInfoObserver(const LLUUID& parcel_id, LLParcelInfoObserver* obs);
  307. void removeInfoObserver(const LLUUID& parcel_id,
  308. LLParcelInfoObserver* obs);
  309. void sendParcelInfoRequest(const LLUUID& parcel_id);
  310. bool requestRegionParcelInfo(const std::string& url,
  311. const LLUUID& region_id,
  312. const LLVector3& region_pos,
  313. const LLVector3d& global_pos,
  314. LLHandle<LLParcelInfoObserver> obs_handle);
  315. static void processParcelInfoReply(LLMessageSystem* msg, void**);
  316. private:
  317. static bool releaseAlertCB(const LLSD& notification, const LLSD& response);
  318. static void sendParcelAccessListUpdate(U32 flags,
  319. const access_map_t& entries,
  320. LLViewerRegion* region,
  321. S32 parcel_local_id);
  322. // Moves land from current owner to its group.
  323. void deedLandToGroup();
  324. static bool deedAlertCB(const LLSD& notification, const LLSD& response);
  325. static bool callbackDivideLand(const LLSD& notification,
  326. const LLSD& response);
  327. static bool callbackJoinLand(const LLSD& notification,
  328. const LLSD& response);
  329. LLViewerTexture* getBlockedImage() const;
  330. LLViewerTexture* getPassImage() const;
  331. void regionParcelInfoCoro(const std::string& url, LLUUID region_id,
  332. LLVector3 pos_region, LLVector3d pos_global,
  333. LLHandle<LLParcelInfoObserver> obs_handle);
  334. private:
  335. LLParcel* mCurrentParcel; // Selected parcel info
  336. LLParcelSelectionHandle mCurrentParcelSelection;
  337. LLParcelSelectionHandle mFloatingParcelSelection;
  338. S32 mRequestResult; // Last parcel request result
  339. LLVector3d mWestSouth;
  340. LLVector3d mEastNorth;
  341. F32 mSelectedDwell;
  342. // Info for parcel agent is in
  343. LLParcel* mAgentParcel;
  344. // Incrementing counter to suppress out of order updates
  345. S32 mAgentParcelSequenceID;
  346. LLParcel* mHoverParcel;
  347. S32 mHoverRequestResult;
  348. LLVector3d mHoverWestSouth;
  349. LLVector3d mHoverEastNorth;
  350. typedef safe_hset<LLParcelSelectionObserver*> observers_list_t;
  351. observers_list_t mSelectionObservers;
  352. bool mSelected;
  353. bool mTeleportInProgress;
  354. tp_finished_sig_t mTeleportFinishedSignal;
  355. parcel_changed_sig_t mTeleportArrivingSignal;
  356. parcel_changed_sig_t mTeleportFailedSignal;
  357. parcel_changed_sig_t mAgentParcelChangedSignal;
  358. // Array of pieces of parcel edges to potentially draw.
  359. // Has (parcels_per_edge + 1) * (parcels_per_edge + 1) elements so that we
  360. // can represent edges of the grid.
  361. // WEST_MASK = draw west edge
  362. // SOUTH_MASK = draw south edge
  363. S32 mParcelsPerEdge;
  364. U8* mHighlightSegments;
  365. U8* mAgentParcelOverlay;
  366. // Raw data buffer for unpacking parcel overlay chunks
  367. // Size = parcels_per_edge * parcels_per_edge / parcel_overlay_chunks
  368. static U8* sPackedOverlay;
  369. // Watch for pending collisions with a parcel you can't access.
  370. // If it's coming, draw the parcel's boundaries.
  371. LLParcel* mCollisionParcel;
  372. U8* mCollisionSegments;
  373. bool mRenderCollision;
  374. bool mRenderSelection;
  375. S32 mCollisionBanned;
  376. LLFrameTimer mCollisionTimer;
  377. LLViewerTexture* mBlockedImage;
  378. LLViewerTexture* mPassImage;
  379. typedef std::multimap<LLUUID,
  380. LLHandle<LLParcelInfoObserver> > info_obs_multimap_t;
  381. info_obs_multimap_t mInfoObservers;
  382. };
  383. extern LLViewerParcelMgr gViewerParcelMgr;
  384. void sanitize_corners(const LLVector3d& corner1,
  385. const LLVector3d& corner2,
  386. LLVector3d& west_south_bottom,
  387. LLVector3d& east_north_top);
  388. #endif