PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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