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