/indra/newview/llworldmap.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 270 lines · 145 code · 47 blank · 78 comment · 5 complexity · c5f1c2c12f389a3846dae54df69e79a4 MD5 · raw file

  1. /**
  2. * @file llworldmap.h
  3. * @brief Underlying data storage for the map of the entire world.
  4. *
  5. * $LicenseInfo:firstyear=2003&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_LLWORLDMAP_H
  27. #define LL_LLWORLDMAP_H
  28. #include "llworldmipmap.h"
  29. #include <boost/function.hpp>
  30. #include "v3dmath.h"
  31. #include "lluuid.h"
  32. #include "llpointer.h"
  33. #include "llsingleton.h"
  34. #include "llviewerregion.h"
  35. #include "llviewertexture.h"
  36. // Description of objects like hubs, events, land for sale, people and more (TBD).
  37. // Note: we don't store a "type" in there so we need to store instances of this class in
  38. // well known objects (i.e. list of objects which type is "well known").
  39. class LLItemInfo
  40. {
  41. public:
  42. LLItemInfo(F32 global_x, F32 global_y, const std::string& name, LLUUID id);
  43. // Setters
  44. void setTooltip(const std::string& tooltip) { mToolTip = tooltip; }
  45. void setElevation(F64 z) { mPosGlobal.mdV[VZ] = z; }
  46. void setCount(S32 count) { mCount = count; }
  47. // void setSelected(bool selected) { mSelected = selected; }
  48. // void setColor(LLColor4 color) { mColor = color; }
  49. // Accessors
  50. const LLVector3d& getGlobalPosition() const { return mPosGlobal; }
  51. const std::string& getName() const { return mName; }
  52. const std::string& getToolTip() const { return mToolTip; }
  53. const LLUUID& getUUID() const { return mID; }
  54. S32 getCount() const { return mCount; }
  55. U64 getRegionHandle() const { return to_region_handle(mPosGlobal); } // Build the handle on the fly
  56. bool isName(const std::string& name) const { return (mName == name); } // True if name same as item's name
  57. // bool isSelected() const { return mSelected; }
  58. private:
  59. std::string mName; // Name of the individual item
  60. std::string mToolTip; // Tooltip : typically, something to be displayed to the user when selecting this item
  61. LLVector3d mPosGlobal; // Global world position
  62. LLUUID mID; // UUID of the item
  63. S32 mCount; // Number of elements in item (e.g. people count)
  64. // Currently not used but might prove useful one day so we comment out
  65. // bool mSelected; // Selected or not: updated by the viewer UI, not the simulator or asset DB
  66. // LLColor4 mColor; // Color of the item
  67. };
  68. // Info per region
  69. // Such records are stored in a global map hold by the LLWorldMap and indexed by region handles.
  70. // To avoid creating too many of them, they are requested in "blocks" corresponding to areas covered by the screen.
  71. // Unfortunately, when the screen covers the whole world (zoomed out), that can translate in requesting info for
  72. // every sim on the grid... Not good...
  73. // To avoid this, the code implements a cut-off threshold for overlay graphics and, therefore, all LLSimInfo.
  74. // In other words, when zooming out too much, we simply stop requesting LLSimInfo and
  75. // LLItemInfo and just display the map tiles.
  76. // As they are stored in different structures (LLSimInfo and LLWorldMipmap), this strategy is now workable.
  77. class LLSimInfo
  78. {
  79. public:
  80. LLSimInfo(U64 handle);
  81. // Convert local region coordinates into world coordinates
  82. LLVector3d getGlobalPos(const LLVector3& local_pos) const;
  83. // Get the world coordinates of the SW corner of that region
  84. LLVector3d getGlobalOrigin() const;
  85. LLVector3 getLocalPos(LLVector3d global_pos) const;
  86. void clearImage(); // Clears the reference to the Land for sale image for that region
  87. void dropImagePriority(); // Drops the boost level of the Land for sale image for that region
  88. void updateAgentCount(F64 time); // Send an item request for agent count on that region if time's up
  89. // Setters
  90. void setName(std::string& name) { mName = name; }
  91. void setAccess (U32 accesscode) { mAccess = accesscode; }
  92. void setRegionFlags (U32 region_flags) { mRegionFlags = region_flags; }
  93. void setLandForSaleImage (LLUUID image_id);
  94. // void setWaterHeight (F32 water_height) { mWaterHeight = water_height; }
  95. // Accessors
  96. std::string getName() const { return mName; }
  97. const std::string getFlagsString() const { return LLViewerRegion::regionFlagsToString(mRegionFlags); }
  98. const std::string getAccessString() const { return LLViewerRegion::accessToString((U8)mAccess); }
  99. const S32 getAgentCount() const; // Compute the total agents count
  100. LLPointer<LLViewerFetchedTexture> getLandForSaleImage(); // Get the overlay image, fetch it if necessary
  101. bool isName(const std::string& name) const;
  102. bool isDown() { return (mAccess == SIM_ACCESS_DOWN); }
  103. bool isPG() { return (mAccess <= SIM_ACCESS_PG); }
  104. bool isAdult() { return (mAccess == SIM_ACCESS_ADULT); }
  105. // Debug only
  106. void dump() const; // Print the region info to the standard output
  107. // Items lists handling
  108. typedef std::vector<LLItemInfo> item_info_list_t;
  109. void clearItems();
  110. void insertTeleHub(const LLItemInfo& item) { mTelehubs.push_back(item); }
  111. void insertInfoHub(const LLItemInfo& item) { mInfohubs.push_back(item); }
  112. void insertPGEvent(const LLItemInfo& item) { mPGEvents.push_back(item); }
  113. void insertMatureEvent(const LLItemInfo& item) { mMatureEvents.push_back(item); }
  114. void insertAdultEvent(const LLItemInfo& item) { mAdultEvents.push_back(item); }
  115. void insertLandForSale(const LLItemInfo& item) { mLandForSale.push_back(item); }
  116. void insertLandForSaleAdult(const LLItemInfo& item) { mLandForSaleAdult.push_back(item); }
  117. void insertAgentLocation(const LLItemInfo& item);
  118. const LLSimInfo::item_info_list_t& getTeleHub() const { return mTelehubs; }
  119. const LLSimInfo::item_info_list_t& getInfoHub() const { return mInfohubs; }
  120. const LLSimInfo::item_info_list_t& getPGEvent() const { return mPGEvents; }
  121. const LLSimInfo::item_info_list_t& getMatureEvent() const { return mMatureEvents; }
  122. const LLSimInfo::item_info_list_t& getAdultEvent() const { return mAdultEvents; }
  123. const LLSimInfo::item_info_list_t& getLandForSale() const { return mLandForSale; }
  124. const LLSimInfo::item_info_list_t& getLandForSaleAdult() const { return mLandForSaleAdult; }
  125. const LLSimInfo::item_info_list_t& getAgentLocation() const { return mAgentLocations; }
  126. private:
  127. U64 mHandle; // This is a hash of the X and Y world coordinates of the SW corner of the sim
  128. std::string mName; // Region name
  129. F64 mAgentsUpdateTime; // Time stamp giving the last time the agents information was requested for that region
  130. bool mFirstAgentRequest; // Init agent request flag
  131. U32 mAccess; // Down/up and maturity rating of the region
  132. U32 mRegionFlags; // Tell us if the siminfo has been received (if non 0) and what kind of region it is (Sandbox, allow damage)
  133. // Currently not used but might prove useful one day so we comment out
  134. // F32 mWaterHeight; // Water height on the region (not actively used)
  135. // Handling the "land for sale / land for auction" overlay image
  136. LLUUID mMapImageID; // Image ID of the overlay image
  137. LLPointer<LLViewerFetchedTexture> mOverlayImage; // Reference to the overlay image
  138. // Items for this region
  139. // Those are data received through item requests (as opposed to block requests for the rest of the data)
  140. item_info_list_t mTelehubs; // List of tele hubs in the region
  141. item_info_list_t mInfohubs; // List of info hubs in the region
  142. item_info_list_t mPGEvents; // List of PG events in the region
  143. item_info_list_t mMatureEvents; // List of Mature events in the region
  144. item_info_list_t mAdultEvents; // List of Adult events in the region (AO)
  145. item_info_list_t mLandForSale; // List of Land for sales in the region
  146. item_info_list_t mLandForSaleAdult; // List of Adult Land for sales in the region (AO)
  147. item_info_list_t mAgentLocations; // List of agents in the region
  148. };
  149. // We request region data on the world by "blocks" of (MAP_BLOCK_SIZE x MAP_BLOCK_SIZE) regions
  150. // This is to reduce the number of requests to the asset DB and get things in big "blocks"
  151. const S32 MAP_MAX_SIZE = 2048;
  152. const S32 MAP_BLOCK_SIZE = 4;
  153. const S32 MAP_BLOCK_RES = (MAP_MAX_SIZE / MAP_BLOCK_SIZE);
  154. class LLWorldMap : public LLSingleton<LLWorldMap>
  155. {
  156. public:
  157. LLWorldMap();
  158. ~LLWorldMap();
  159. // Clear all: list of region info, tiles, blocks and items
  160. void reset();
  161. void clearImageRefs(); // Clears the image references
  162. void dropImagePriorities(); // Drops the priority of the images being fetched
  163. void reloadItems(bool force = false); // Reload the items (people, hub, etc...)
  164. // Region Map access
  165. typedef std::map<U64, LLSimInfo*> sim_info_map_t;
  166. const LLWorldMap::sim_info_map_t& getRegionMap() const { return mSimInfoMap; }
  167. void updateRegions(S32 x0, S32 y0, S32 x1, S32 y1); // Requests region info for a rectangle of regions (in grid coordinates)
  168. // Insert a region and items in the map global instance
  169. // Note: x_world and y_world in world coordinates (meters)
  170. static bool insertRegion(U32 x_world, U32 y_world, std::string& name, LLUUID& uuid, U32 accesscode, U32 region_flags);
  171. static bool insertItem(U32 x_world, U32 y_world, std::string& name, LLUUID& uuid, U32 type, S32 extra, S32 extra2);
  172. // Get info on sims (region) : note that those methods only search the range of loaded sims (the one that are being browsed)
  173. // *not* the entire world. So a NULL return does not mean a down or unexisting region, just an out of range region.
  174. LLSimInfo* simInfoFromHandle(const U64 handle);
  175. LLSimInfo* simInfoFromPosGlobal(const LLVector3d& pos_global);
  176. LLSimInfo* simInfoFromName(const std::string& sim_name);
  177. // Gets simulator name from a global position, returns true if found
  178. bool simNameFromPosGlobal(const LLVector3d& pos_global, std::string& outSimName );
  179. // Debug only
  180. void dump(); // Print the world info to the standard output
  181. // Track handling
  182. void cancelTracking() { mIsTrackingLocation = false; mIsTrackingFound = false; mIsInvalidLocation = false; mIsTrackingDoubleClick = false; mIsTrackingCommit = false; }
  183. void setTracking(const LLVector3d& loc) { mIsTrackingLocation = true; mTrackingLocation = loc; mIsTrackingFound = false; mIsInvalidLocation = false; mIsTrackingDoubleClick = false; mIsTrackingCommit = false;}
  184. void setTrackingInvalid() { mIsTrackingFound = true; mIsInvalidLocation = true; }
  185. void setTrackingValid() { mIsTrackingFound = true; mIsInvalidLocation = false; }
  186. void setTrackingDoubleClick() { mIsTrackingDoubleClick = true; }
  187. void setTrackingCommit() { mIsTrackingCommit = true; }
  188. bool isTracking() { return mIsTrackingLocation; }
  189. bool isTrackingValidLocation() { return mIsTrackingFound && !mIsInvalidLocation; }
  190. bool isTrackingInvalidLocation() { return mIsTrackingFound && mIsInvalidLocation; }
  191. bool isTrackingDoubleClick() { return mIsTrackingDoubleClick; }
  192. bool isTrackingCommit() { return mIsTrackingCommit; }
  193. bool isTrackingInRectangle(F64 x0, F64 y0, F64 x1, F64 y1);
  194. LLVector3d getTrackedPositionGlobal() const { return mTrackingLocation; }
  195. // World Mipmap delegation: currently used when drawing the mipmap
  196. void equalizeBoostLevels();
  197. LLPointer<LLViewerFetchedTexture> getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load = true) { return mWorldMipmap.getObjectsTile(grid_x, grid_y, level, load); }
  198. private:
  199. bool clearItems(bool force = false); // Clears the item lists
  200. void clearSimFlags(); // Clears the block flags indicating that we've already requested region infos
  201. // Create a region record corresponding to the handle, insert it in the region map and returns a pointer
  202. LLSimInfo* createSimInfoFromHandle(const U64 handle);
  203. // Map from region-handle to region info
  204. sim_info_map_t mSimInfoMap;
  205. // Holds the tiled mipmap of the world. This is the structure that contains the images used for rendering.
  206. LLWorldMipmap mWorldMipmap;
  207. // The World is divided in "blocks" of (MAP_BLOCK_SIZE x MAP_BLOCK_SIZE) regions that get requested at once.
  208. // This boolean table avoids "blocks" to be requested multiple times.
  209. // Issue: Not sure this scheme is foolproof though as I've seen
  210. // cases where a block is never retrieved and, because of this boolean being set, never re-requested
  211. bool * mMapBlockLoaded; // Telling us if the block of regions has been requested or not
  212. // Track location data : used while there's nothing tracked yet by LLTracker
  213. bool mIsTrackingLocation; // True when we're tracking a point
  214. bool mIsTrackingFound; // True when the tracking position has been found, valid or not
  215. bool mIsInvalidLocation; // The region is down or the location does not correspond to an existing region
  216. bool mIsTrackingDoubleClick; // User double clicked to set the location (i.e. teleport when found please...)
  217. bool mIsTrackingCommit; // User used the search or landmark fields to set the location
  218. LLVector3d mTrackingLocation; // World global position being tracked
  219. // General grid items request timing flags (used for events,hubs and land for sale)
  220. LLTimer mRequestTimer;
  221. bool mFirstRequest;
  222. };
  223. #endif