From b81c1c4e871be0ff5e5dbbfa235571350cd477fe Mon Sep 17 00:00:00 2001 From: Erik Kundiman Date: Thu, 31 Jul 2025 20:42:38 +0800 Subject: Optimise nearby tab distance & arrival time impl by not having extra calls to getAvatars, by avoiding unnecessary function overhead which actually make it possible to share some iterative code, and by piggybacking updateNearbyList and updateArrivalTime which is already done periodically though the range had to be lengthened to match nearby list range which is MPVNearMeRange instead of SLv's NearMeRange. Minimise differences from SLv too (arrival time really doesn't need to be updated *every* second.. every 5 seconds is just okay). --- indra/newview/llavatarlist.cpp | 70 +++++++++++++----------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) (limited to 'indra/newview/llavatarlist.cpp') diff --git a/indra/newview/llavatarlist.cpp b/indra/newview/llavatarlist.cpp index 5f9d03ca66..834288a93e 100644 --- a/indra/newview/llavatarlist.cpp +++ b/indra/newview/llavatarlist.cpp @@ -48,12 +48,11 @@ #include "llvoiceclient.h" #include "llviewercontrol.h" // for gSavedSettings #include "lltooldraganddrop.h" -#include "llworld.h" static LLDefaultChildRegistry::Register r("avatar_list"); // Last interaction time update period. -static const F32 LIT_UPDATE_PERIOD = 1; +static const F32 LIT_UPDATE_PERIOD = 5; // Maximum number of avatars that can be added to a list in one pass. // Used to limit time spent for avatar list update per frame. @@ -187,6 +186,12 @@ std::string LLAvatarList::getAvatarName(LLAvatarName av_name) return mShowCompleteName? av_name.getCompleteName(false, mForceCompleteName) : av_name.getDisplayName(); } +void LLAvatarList::setAvatarsPositions(const std::map& avatarsPositions) +{ + mAvatarsPositions.clear(); + mAvatarsPositions = avatarsPositions; +} + // virtual void LLAvatarList::draw() { @@ -205,13 +210,22 @@ void LLAvatarList::draw() if ((mShowLastInteractionTime || mAvatarDistance || mAvatarArrivalTime) && mLITUpdateTimer->hasExpired()) { - if (mAvatarArrivalTime) + if (mAvatarArrivalTime || mAvatarDistance) { - updateAvatarArrivalTime(); - } - if (mAvatarDistance) - { - updateAvatarDistance(); + std::vector items; + getItems(items); + for (auto it = items.begin(); it != items.end(); it++) + { + auto item = static_cast(*it); + if (mAvatarArrivalTime) + { + auto secs_since = LLDate::now().secondsSinceEpoch() - LLRecentPeople::instance().getArrivalTimeByID(item->getAvatarId()); + if (secs_since >= 0) + item->setAvatarArrivalTime(secs_since); + } + if (mAvatarDistance) + item->setAvatarDistance(dist_vec(mAvatarsPositions[item->getAvatarId()], gAgent.getPositionGlobal())); + } } if (mShowLastInteractionTime) { @@ -554,46 +568,6 @@ void LLAvatarList::computeDifference( LLCommonUtils::computeDifference(vnew_unsorted, vcur, vadded, vremoved); } -void LLAvatarList::updateAvatarArrivalTime() -{ - std::vector items; - getItems(items); - auto uuids = getIDs(); - std::vector positions; - auto me_pos = gAgent.getPositionGlobal(); - LLWorld::getInstance()->getAvatars(&uuids, &positions, me_pos, gSavedSettings.getF32("MPVNearMeRange")); - LLRecentPeople::instance().updateAvatarsArrivalTime(uuids); - for (auto it = items.begin(); it != items.end(); it++) - { - auto item = static_cast(*it); - auto secs_since = LLDate::now().secondsSinceEpoch() - LLRecentPeople::instance().getArrivalTimeByID(item->getAvatarId()); - if (secs_since >= 0) - item->setAvatarArrivalTime(secs_since); - } -} - - void LLAvatarList::updateAvatarDistance() -{ - std::vector items; - getItems(items); - auto uuids = getIDs(); - std::vector positions; - auto me_pos = gAgent.getPositionGlobal(); - LLWorld::getInstance()->getAvatars(&uuids, &positions, me_pos, gSavedSettings.getF32("MPVNearMeRange")); - std::map avatarsPositions; - auto pos_it = positions.begin(); - auto id_it = uuids.begin(); - for (;pos_it != positions.end() && id_it != uuids.end(); ++pos_it, ++id_it) - { - avatarsPositions[*id_it] = *pos_it; - } - for (auto it = items.begin(); it != items.end(); it++) - { - auto item = static_cast(*it); - item->setAvatarDistance(dist_vec(avatarsPositions[item->getAvatarId()], me_pos)); - } -} - // Refresh shown time of our last interaction with all listed avatars. void LLAvatarList::updateLastInteractionTimes() { -- cgit v1.2.3 From 3c464b4d8bb9bed58edc0418a8c91e8a609b5160 Mon Sep 17 00:00:00 2001 From: Erik Kundiman Date: Thu, 31 Jul 2025 23:39:09 +0800 Subject: Optimise arrival & departure notifications by not having extra calls to getAvatars. The avatars' positions member had to be moved to an object that is accessible from VOAvatar too, and that would be the global Agent. It makes sense too, that it's the object that keeps the positions of other agents. It even has a section for positions too. --- indra/newview/llavatarlist.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'indra/newview/llavatarlist.cpp') diff --git a/indra/newview/llavatarlist.cpp b/indra/newview/llavatarlist.cpp index 834288a93e..e29be0c757 100644 --- a/indra/newview/llavatarlist.cpp +++ b/indra/newview/llavatarlist.cpp @@ -186,12 +186,6 @@ std::string LLAvatarList::getAvatarName(LLAvatarName av_name) return mShowCompleteName? av_name.getCompleteName(false, mForceCompleteName) : av_name.getDisplayName(); } -void LLAvatarList::setAvatarsPositions(const std::map& avatarsPositions) -{ - mAvatarsPositions.clear(); - mAvatarsPositions = avatarsPositions; -} - // virtual void LLAvatarList::draw() { @@ -224,7 +218,10 @@ void LLAvatarList::draw() item->setAvatarArrivalTime(secs_since); } if (mAvatarDistance) - item->setAvatarDistance(dist_vec(mAvatarsPositions[item->getAvatarId()], gAgent.getPositionGlobal())); + { + auto avatarsPositions = gAgent.getAvatarsPositions(); + item->setAvatarDistance(dist_vec(avatarsPositions[item->getAvatarId()], gAgent.getPositionGlobal())); + } } } if (mShowLastInteractionTime) -- cgit v1.2.3