llworldmap.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /**
  2. * @file llworldmap.h
  3. * @brief Underlying data storage for the map of the entire world.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, Linden Research, Inc.
  8. * Copyright (c) 2009-2021, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLWORLDMAP_H
  34. #define LL_LLWORLDMAP_H
  35. #include "boost/function.hpp"
  36. #include "hbfastmap.h"
  37. #include "llframetimer.h"
  38. #include "llpointer.h"
  39. #include "llrect.h"
  40. #include "llstring.h"
  41. #include "lluuid.h"
  42. #include "llvector3d.h"
  43. #include "llviewertexture.h"
  44. // Region map layer numbers
  45. constexpr S32 MAP_SIM_OBJECTS = 0;
  46. constexpr S32 MAP_SIM_TERRAIN = 1;
  47. // Transparent alpha overlay of land for sale
  48. constexpr S32 MAP_SIM_LAND_FOR_SALE = 2;
  49. constexpr S32 MAP_SIM_IMAGE_TYPES = 3; // Number of map layers
  50. // map item types
  51. constexpr U32 MAP_ITEM_TELEHUB = 0x01;
  52. constexpr U32 MAP_ITEM_PG_EVENT = 0x02;
  53. constexpr U32 MAP_ITEM_MATURE_EVENT = 0x03;
  54. //constexpr U32 MAP_ITEM_POPULAR = 0x04;
  55. //constexpr U32 MAP_ITEM_AGENT_COUNT = 0x05;
  56. constexpr U32 MAP_ITEM_AGENT_LOCATIONS = 0x06;
  57. constexpr U32 MAP_ITEM_LAND_FOR_SALE = 0x07;
  58. constexpr U32 MAP_ITEM_CLASSIFIED = 0x08;
  59. constexpr U32 MAP_ITEM_ADULT_EVENT = 0x09;
  60. constexpr U32 MAP_ITEM_LAND_FOR_SALE_ADULT = 0x0a;
  61. class LLMessageSystem;
  62. class LLItemInfo
  63. {
  64. public:
  65. LLItemInfo(F32 global_x, F32 global_y, const std::string& name,
  66. const LLUUID& id, S32 extra = 0, S32 extra2 = 0);
  67. public:
  68. LLVector3d mPosGlobal;
  69. LLUUID mID;
  70. S32 mExtra;
  71. S32 mExtra2;
  72. U64 mRegionHandle;
  73. std::string mName;
  74. std::string mToolTip;
  75. bool mSelected;
  76. };
  77. #define MAP_SIM_IMAGE_TYPES 3
  78. // 0 - Prim
  79. // 1 - Terrain Only
  80. // 2 - Overlay: Land For Sale
  81. class LLSimInfo
  82. {
  83. public:
  84. LLSimInfo();
  85. LLVector3d getGlobalPos(LLVector3 local_pos) const;
  86. // Get the world coordinates of the SW corner of that region
  87. LLVector3d getGlobalOrigin() const;
  88. LL_INLINE void setSize(U16 x, U16 y) { mSizeX = y; mSizeY = y; }
  89. LL_INLINE const U64& getHandle() const { return mHandle; }
  90. LL_INLINE U16 getSizeX() const { return mSizeX; }
  91. LL_INLINE U16 getSizeY() const { return mSizeY; }
  92. public:
  93. U64 mHandle;
  94. U64 mRegionFlags;
  95. F64 mAgentsUpdateTime;
  96. // Hold a reference to the currently displayed image.
  97. LLPointer<LLViewerFetchedTexture> mCurrentImage[2];
  98. LLPointer<LLViewerFetchedTexture> mOverlayImage;
  99. std::string mName;
  100. // Image ID for the current overlay mode.
  101. LLUUID mMapImageID[MAP_SIM_IMAGE_TYPES];
  102. // Filled up when counting agents on the map: caching this number here
  103. // prevents from managing a separate std::map and speeds things up...
  104. S32 mAgentsCount;
  105. F32 mAlpha;
  106. // For variable region size support
  107. U16 mSizeX;
  108. U16 mSizeY;
  109. U8 mAccess;
  110. // Are agents visible ?
  111. bool mShowAgentLocations;
  112. };
  113. #define MAP_BLOCK_RES 256
  114. // We request region data on the world by "blocks" of (MAP_BLOCK_SIZE x
  115. // MAP_BLOCK_SIZE) regions. This is to reduce the number of requests to the
  116. // asset DB and get things in big "blocks"
  117. #define MAP_BLOCK_SIZE 16
  118. struct LLWorldMapLayer
  119. {
  120. LLWorldMapLayer()
  121. : mLayerDefined(false)
  122. {
  123. }
  124. LLPointer<LLViewerFetchedTexture> mLayerImage;
  125. LLUUID mLayerImageID;
  126. LLRect mLayerExtents;
  127. bool mLayerDefined;
  128. };
  129. class LLWorldMap
  130. {
  131. protected:
  132. LOG_CLASS(LLWorldMap);
  133. public:
  134. typedef boost::function<void(U64 region_handle, const std::string& url,
  135. const LLUUID& snapshot_id,
  136. bool teleport)> url_callback_t;
  137. LLWorldMap();
  138. ~LLWorldMap();
  139. // Clears the list
  140. void reset();
  141. // Clear the visible items
  142. void eraseItems(bool force = false);
  143. // Removes references to cached images. If layer is omitted or out of range
  144. // images for both layer 0 and 1 are unloaded. Else, only the requested
  145. // layer image is unloaded.
  146. void clearImageRefs(S32 layer = -1);
  147. // Clears the flags indicating that we've received sim infos. Causes a
  148. // re-request of the sim info without erasing existing info.
  149. void clearSimFlags();
  150. // Returns simulator information, or NULL if out of range
  151. LLSimInfo* simInfoFromHandle(U64 handle);
  152. // Returns simulator information, or NULL if out of range
  153. LLSimInfo* simInfoFromPosGlobal(const LLVector3d& pos_global);
  154. // Returns simulator information for named sim, or NULL if non-existent
  155. LLSimInfo* simInfoFromName(std::string sim_name);
  156. // Gets simulator name for a global position, returns true if it was found
  157. bool simNameFromPosGlobal(const LLVector3d& pos_global,
  158. std::string& sim_name);
  159. // Sets the current layer
  160. void setCurrentLayer(U32 layer, bool request_layer = false);
  161. LL_INLINE U32 getCurrentLayer() const { return mCurrentMap; }
  162. void forceUpdateRegion(U64 handle);
  163. U32 updateRegions(S32 x0, S32 y0, S32 x1, S32 y1, bool force_upd = false);
  164. void sendMapLayerRequest();
  165. void sendMapBlockRequest(U16 min_x, U16 min_y, U16 max_x, U16 max_y,
  166. bool return_nonexistent = false);
  167. void sendNamedRegionRequest(const std::string& region_name);
  168. void sendNamedRegionRequest(const std::string& region_name,
  169. url_callback_t callback,
  170. const std::string& callback_url,
  171. bool teleport);
  172. // When teleport is true, the callback should TP the agent
  173. void sendHandleRegionRequest(U64 region_handle,
  174. url_callback_t callback = NULL,
  175. const std::string& url = LLStringUtil::null,
  176. bool teleport = false);
  177. void sendItemRequest(U32 type, U64 handle = 0);
  178. static void processMapLayerReply(LLMessageSystem*, void**);
  179. static void processMapBlockReply(LLMessageSystem*, void**);
  180. static void processMapItemReply(LLMessageSystem*, void**);
  181. LL_INLINE static void gotMapServerURL(bool b) { sGotMapURL = b; }
  182. LL_INLINE static void setMapServerURL(std::string url,
  183. bool login = false)
  184. {
  185. sMapURL = url;
  186. sMapURLSetOnLogin = login;
  187. }
  188. LL_INLINE static bool wasMapURLSetOnLogin() { return sMapURLSetOnLogin; }
  189. static bool useWebMapTiles();
  190. static LLPointer<LLViewerFetchedTexture> loadObjectsTile(U32 grid_x,
  191. U32 grid_y);
  192. void dump();
  193. // Bounds of the world, in meters
  194. LL_INLINE U32 getWorldWidth() const { return mMaxX - mMinX; }
  195. LL_INLINE U32 getWorldHeight() const { return mMaxY - mMinY; }
  196. private:
  197. // Extend the bounding box of the list of simulators. Returns true if the
  198. // extents changed.
  199. bool extendAABB(U32 x_min, U32 y_min, U32 x_max, U32 y_max);
  200. bool isTrackedUnknownLocation(U32 x, U32 y) const;
  201. static void mapLayerRequestCallback(LLSD result);
  202. public:
  203. LLVector3d mUnknownLocation;
  204. // Map from region-handle to simulator info
  205. typedef fast_hmap<U64, LLSimInfo*> sim_info_map_t;
  206. sim_info_map_t mSimInfoMap;
  207. typedef std::vector<LLItemInfo> item_info_list_t;
  208. item_info_list_t mTelehubs;
  209. item_info_list_t mInfohubs;
  210. item_info_list_t mPGEvents;
  211. item_info_list_t mMatureEvents;
  212. item_info_list_t mAdultEvents;
  213. item_info_list_t mLandForSale;
  214. item_info_list_t mLandForSaleAdult;
  215. typedef fast_hmap<U64, item_info_list_t> agent_list_map_t;
  216. agent_list_map_t mAgentLocationsMap;
  217. typedef fast_hmap<U32, std::vector<bool> > mapblock_map_t;
  218. mapblock_map_t mMapBlockMap[MAP_SIM_IMAGE_TYPES];
  219. typedef std::vector<LLWorldMapLayer> map_layers_vec_t;
  220. map_layers_vec_t mMapLayers[MAP_SIM_IMAGE_TYPES];
  221. bool mMapLoaded[MAP_SIM_IMAGE_TYPES];
  222. bool mIsTrackingUnknownLocation;
  223. bool mInvalidLocation;
  224. bool mIsTrackingDoubleClick;
  225. bool mIsTrackingCommit;
  226. bool mRequestLandForSale;
  227. private:
  228. U32 mCurrentMap;
  229. // AABB of the list of simulators
  230. U32 mMinX;
  231. U32 mMaxX;
  232. U32 mMinY;
  233. U32 mMaxY;
  234. LLTimer mRequestTimer;
  235. U64 mSLURLRegionHandle;
  236. // Search for named region for url processing
  237. std::string mSLURLRegionName;
  238. std::string mSLURL;
  239. url_callback_t mSLURLCallback;
  240. bool mSLURLTeleport;
  241. static bool sGotMapURL;
  242. static bool sMapURLSetOnLogin;
  243. static std::string sMapURL;
  244. };
  245. extern LLWorldMap gWorldMap;
  246. #endif