PageRenderTime 345ms CodeModel.GetById 131ms app.highlight 16ms RepoModel.GetById 195ms app.codeStats 0ms

/indra/newview/lllandmarklist.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 212 lines | 146 code | 29 blank | 37 comment | 25 complexity | c49c731607ac234372ebe1b65596f86e MD5 | raw file
  1/** 
  2 * @file lllandmarklist.cpp
  3 * @brief Landmark asset list class
  4 *
  5 * $LicenseInfo:firstyear=2002&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#include "llviewerprecompiledheaders.h"
 28
 29#include "lllandmarklist.h"
 30
 31#include "message.h"
 32#include "llassetstorage.h"
 33
 34#include "llappviewer.h"
 35#include "llagent.h"
 36#include "llvfile.h"
 37#include "llviewerstats.h"
 38
 39// Globals
 40LLLandmarkList gLandmarkList;
 41
 42
 43////////////////////////////////////////////////////////////////////////////
 44// LLLandmarkList
 45
 46LLLandmarkList::~LLLandmarkList()
 47{
 48	std::for_each(mList.begin(), mList.end(), DeletePairedPointer());
 49}
 50
 51LLLandmark* LLLandmarkList::getAsset(const LLUUID& asset_uuid, loaded_callback_t cb)
 52{
 53	LLLandmark* landmark = get_ptr_in_map(mList, asset_uuid);
 54	if(landmark)
 55	{
 56		LLVector3d dummy;
 57		if(cb && !landmark->getGlobalPos(dummy))
 58		{
 59			// landmark is not completely loaded yet
 60			loaded_callback_map_t::value_type vt(asset_uuid, cb);
 61			mLoadedCallbackMap.insert(vt);
 62		}
 63		return landmark;
 64	}
 65	else
 66	{
 67	    if ( mBadList.find(asset_uuid) != mBadList.end() )
 68		{
 69			return NULL;
 70		}
 71		
 72		landmark_requested_list_t::iterator iter = mRequestedList.find(asset_uuid);
 73		if (iter != mRequestedList.end())
 74		{
 75			const F32 rerequest_time = 30.f; // 30 seconds between requests
 76			if (gFrameTimeSeconds - iter->second < rerequest_time)
 77			{
 78				return NULL;
 79			}
 80		}
 81		
 82		if (cb)
 83		{
 84			loaded_callback_map_t::value_type vt(asset_uuid, cb);
 85			mLoadedCallbackMap.insert(vt);
 86		}
 87
 88		gAssetStorage->getAssetData(asset_uuid,
 89									LLAssetType::AT_LANDMARK,
 90									LLLandmarkList::processGetAssetReply,
 91									NULL);
 92		mRequestedList[asset_uuid] = gFrameTimeSeconds;
 93	}
 94	return NULL;
 95}
 96
 97// static
 98void LLLandmarkList::processGetAssetReply(
 99	LLVFS *vfs,
100	const LLUUID& uuid,
101	LLAssetType::EType type,
102	void* user_data,
103	S32 status, 
104	LLExtStat ext_status )
105{
106	if( status == 0 )
107	{
108		LLVFile file(vfs, uuid, type);
109		S32 file_length = file.getSize();
110
111		std::vector<char> buffer(file_length + 1);
112		file.read( (U8*)&buffer[0], file_length);
113		buffer[ file_length ] = 0;
114
115		LLLandmark* landmark = LLLandmark::constructFromString(&buffer[0]);
116		if (landmark)
117		{
118			gLandmarkList.mList[ uuid ] = landmark;
119			gLandmarkList.mRequestedList.erase(uuid);
120			
121			LLVector3d pos;
122			if(!landmark->getGlobalPos(pos))
123			{
124				LLUUID region_id;
125				if(landmark->getRegionID(region_id))
126				{
127					LLLandmark::requestRegionHandle(
128						gMessageSystem,
129						gAgent.getRegionHost(),
130						region_id,
131						boost::bind(&LLLandmarkList::onRegionHandle, &gLandmarkList, uuid));
132				}
133
134				// the callback will be called when we get the region handle.
135			}
136			else
137			{
138				gLandmarkList.makeCallbacks(uuid);
139			}
140		}
141	}
142	else
143	{
144		LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
145		// SJB: No use case for a notification here. Use lldebugs instead
146		if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status )
147		{
148			LL_WARNS("Landmarks") << "Missing Landmark" << LL_ENDL;
149			//LLNotificationsUtil::add("LandmarkMissing");
150		}
151		else
152		{
153			LL_WARNS("Landmarks") << "Unable to load Landmark" << LL_ENDL;
154			//LLNotificationsUtil::add("UnableToLoadLandmark");
155		}
156
157		gLandmarkList.mBadList.insert(uuid);
158	}
159
160}
161
162BOOL LLLandmarkList::isAssetInLoadedCallbackMap(const LLUUID& asset_uuid)
163{
164	return mLoadedCallbackMap.find(asset_uuid) != mLoadedCallbackMap.end();
165}
166
167BOOL LLLandmarkList::assetExists(const LLUUID& asset_uuid)
168{
169	return mList.count(asset_uuid) != 0 || mBadList.count(asset_uuid) != 0;
170}
171
172void LLLandmarkList::onRegionHandle(const LLUUID& landmark_id)
173{
174	LLLandmark* landmark = getAsset(landmark_id);
175
176	if (!landmark)
177	{
178		llwarns << "Got region handle but the landmark not found." << llendl;
179		return;
180	}
181
182	// Calculate landmark global position.
183	// This should succeed since the region handle is available.
184	LLVector3d pos;
185	if (!landmark->getGlobalPos(pos))
186	{
187		llwarns << "Got region handle but the landmark global position is still unknown." << llendl;
188		return;
189	}
190
191	makeCallbacks(landmark_id);
192}
193
194void LLLandmarkList::makeCallbacks(const LLUUID& landmark_id)
195{
196	LLLandmark* landmark = getAsset(landmark_id);
197
198	if (!landmark)
199	{
200		llwarns << "Landmark to make callbacks for not found." << llendl;
201	}
202
203	// make all the callbacks here.
204	loaded_callback_map_t::iterator it;
205	while((it = mLoadedCallbackMap.find(landmark_id)) != mLoadedCallbackMap.end())
206	{
207		if (landmark)
208			(*it).second(landmark);
209
210		mLoadedCallbackMap.erase(it);
211	}
212}