diff options
Diffstat (limited to 'indra/newview/lllandmarkactions.cpp')
| -rw-r--r-- | indra/newview/lllandmarkactions.cpp | 101 |
1 files changed, 94 insertions, 7 deletions
diff --git a/indra/newview/lllandmarkactions.cpp b/indra/newview/lllandmarkactions.cpp index 73425e9f4c..9b90e41549 100644 --- a/indra/newview/lllandmarkactions.cpp +++ b/indra/newview/lllandmarkactions.cpp @@ -80,6 +80,40 @@ public: } }; +class LLFetchFirstLandmarkByPos : public LLInventoryCollectFunctor +{ +private: + LLVector3d mPos; + bool mFound = false; +public: + LLFetchFirstLandmarkByPos(const LLVector3d& pos) : + mPos(pos), mFound(false) + { + } + + /*virtual*/ bool operator()(LLInventoryCategory* cat, LLInventoryItem* item) + { + if (mFound || !item || item->getType() != LLAssetType::AT_LANDMARK) + return false; + + LLLandmark* landmark = gLandmarkList.getAsset(item->getAssetUUID()); + if (!landmark) // the landmark not been loaded yet + return false; + + LLVector3d landmark_global_pos; + if (!landmark->getGlobalPos(landmark_global_pos)) + return false; + //we have to round off each coordinates to compare positions properly + mFound = ll_round(mPos.mdV[VX]) == ll_round(landmark_global_pos.mdV[VX]) + && ll_round(mPos.mdV[VY]) == ll_round(landmark_global_pos.mdV[VY]) + && ll_round(mPos.mdV[VZ]) == ll_round(landmark_global_pos.mdV[VZ]); + return mFound; + } + + // only care about first found landmark, so stop when found + /*virtual*/ bool exceedsLimit() { return mFound; } +}; + class LLFetchLandmarksByName : public LLInventoryCollectFunctor { private: @@ -155,6 +189,9 @@ public: mFounded = LLViewerParcelMgr::getInstance()->inAgentParcel(landmark_global_pos); return mFounded; } + + // only care about first found landmark, so stop when found + /*virtual*/ bool exceedsLimit() { return mFounded; } }; static void fetch_landmarks(LLInventoryModel::cat_array_t& cats, @@ -197,23 +234,61 @@ bool LLLandmarkActions::landmarkAlreadyExists() //static bool LLLandmarkActions::hasParcelLandmark() { + static LLUUID sLastItemID; + static S32 sLastFrame = -1; + if (sLastItemID.notNull()) + { + LLInventoryItem* item = gInventory.getItem(sLastItemID); + if (item) + { + LLLandmark* landmark = gLandmarkList.getAsset(item->getAssetUUID()); + if (landmark) + { + LLVector3d landmark_global_pos; + if (landmark->getGlobalPos(landmark_global_pos) + && LLViewerParcelMgr::getInstance()->inAgentParcel(landmark_global_pos)) + { + return true; + } + } + } + // Cached landmark does not match current parcel anymore, + // repeat inventory search to find a replacement landmark + // or to make sure there are none. + sLastItemID.setNull(); + sLastFrame = -1; + } + + if (sLastFrame == LLFrameTimer::getFrameCount()) + { + // Ideally this should also check parcel change and landmark additions, + // not just frame change. + // But should be sufficient to check only frame as this is used + // after inventory and parcel operations. + return false; + } + sLastFrame = LLFrameTimer::getFrameCount(); + LLFirstAgentParcelLandmark get_first_agent_landmark; LLInventoryModel::cat_array_t cats; LLInventoryModel::item_array_t items; fetch_landmarks(cats, items, get_first_agent_landmark); - return !items.empty(); - + if (!items.empty()) + { + sLastItemID = items[0]->getUUID(); + return true; + } + return false; } -// *TODO: This could be made more efficient by only fetching the FIRST -// landmark that meets the criteria LLViewerInventoryItem* LLLandmarkActions::findLandmarkForGlobalPos(const LLVector3d &pos) { // Determine whether there are landmarks pointing to the current parcel. + // Will stop after first found landmark. LLInventoryModel::cat_array_t cats; LLInventoryModel::item_array_t items; - LLFetchlLandmarkByPos is_current_pos_landmark(pos); - fetch_landmarks(cats, items, is_current_pos_landmark); + LLFetchFirstLandmarkByPos get_landmark_from_pos(pos); + fetch_landmarks(cats, items, get_landmark_from_pos); if(items.empty()) { @@ -385,12 +460,24 @@ void LLLandmarkActions::copySLURLtoClipboard(const LLUUID& landmarkInventoryItem { LLVector3d global_pos; landmark->getGlobalPos(global_pos); - LLLandmarkActions::getSLURLfromPosGlobal(global_pos,©_slurl_to_clipboard_callback,true); + if (!global_pos.isExactlyZero()) + { + LLLandmarkActions::getSLURLfromPosGlobal(global_pos, ©_slurl_to_clipboard_callback, true); + } + else + { + LLNotificationsUtil::add("LandmarkLocationUnknown"); + } } } void copy_slurl_to_clipboard_callback(const std::string& slurl) { + if (slurl.empty()) + { + LLNotificationsUtil::add("LandmarkLocationUnknown"); + return; + } gViewerWindow->getWindow()->copyTextToClipboard(utf8str_to_wstring(slurl)); LLSD args; args["SLURL"] = slurl; |
