From fc63aa74247b9a62871cf2ee929457d68bfdf63d Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 9 Oct 2020 21:53:53 +0300 Subject: SL-14078 No point in verifying display name cap each frame Convoluted due to multiple workarounds. Might be a good idea to spend some time refactoring this, but for now just trottled checks. --- indra/llmessage/llavatarnamecache.cpp | 6 +++ indra/llmessage/llavatarnamecache.h | 2 + indra/newview/llappviewer.cpp | 94 ++++++++++++++++++++--------------- 3 files changed, 62 insertions(+), 40 deletions(-) diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index 7380df041d..756fb940aa 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -549,6 +549,12 @@ void LLAvatarNameCache::idle() eraseUnrefreshed(); } +//static +bool LLAvatarNameCache::hasWork() +{ + return sRequestTimer.hasExpired(); +} + bool LLAvatarNameCache::isRequestPending(const LLUUID& agent_id) { bool isPending = false; diff --git a/indra/llmessage/llavatarnamecache.h b/indra/llmessage/llavatarnamecache.h index 549d1703fa..04400490c7 100644 --- a/indra/llmessage/llavatarnamecache.h +++ b/indra/llmessage/llavatarnamecache.h @@ -62,6 +62,8 @@ public: // cache. Called once per frame. void idle(); + static bool hasWork(); + // If name is in cache, returns true and fills in provided LLAvatarName // otherwise returns false. static bool get(const LLUUID& agent_id, LLAvatarName *av_name); diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index ee055c48d4..cffa346d99 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -5170,9 +5170,14 @@ void LLAppViewer::sendLogoutRequest() void LLAppViewer::idleNameCache() { + static bool cache_needs_update = true; // Neither old nor new name cache can function before agent has a region LLViewerRegion* region = gAgent.getRegion(); - if (!region) return; + if (!region) + { + cache_needs_update = true; + return; + } // deal with any queued name requests and replies. gCacheName->processPending(); @@ -5180,47 +5185,56 @@ void LLAppViewer::idleNameCache() // Can't run the new cache until we have the list of capabilities // for the agent region, and can therefore decide whether to use // display names or fall back to the old name system. - if (!region->capabilitiesReceived()) return; - - // Agent may have moved to a different region, so need to update cap URL - // for name lookups. Can't do this in the cap grant code, as caps are - // granted to neighbor regions before the main agent gets there. Can't - // do it in the move-into-region code because cap not guaranteed to be - // granted yet, for example on teleport. - LLAvatarNameCache *name_cache = LLAvatarNameCache::getInstance(); - bool had_capability = LLAvatarNameCache::getInstance()->hasNameLookupURL(); - std::string name_lookup_url; - name_lookup_url.reserve(128); // avoid a memory allocation below - name_lookup_url = region->getCapability("GetDisplayNames"); - bool have_capability = !name_lookup_url.empty(); - if (have_capability) - { - // we have support for display names, use it - U32 url_size = name_lookup_url.size(); - // capabilities require URLs with slashes before query params: - // https://:/cap//?ids= - // but the caps are granted like: - // https://:/cap/ - if (url_size > 0 && name_lookup_url[url_size-1] != '/') - { - name_lookup_url += '/'; - } - name_cache->setNameLookupURL(name_lookup_url); - } - else - { - // Display names not available on this region - name_cache->setNameLookupURL( std::string() ); - } + if (!region->capabilitiesReceived()) + { + cache_needs_update = true; + return; + } - // Error recovery - did we change state? - if (had_capability != have_capability) - { - // name tags are persistant on screen, so make sure they refresh - LLVOAvatar::invalidateNameTags(); - } + // Agent may have moved to a different region, so need to update cap URL + // for name lookups. Can't do this in the cap grant code, as caps are + // granted to neighbor regions before the main agent gets there. Can't + // do it in the move-into-region code because cap not guaranteed to be + // granted yet, for example on teleport. + // hasWork() is cache's 'idle' timer, 10 updates per second + if (LLAvatarNameCache::hasWork() || cache_needs_update) + { + cache_needs_update = false; + LLAvatarNameCache *name_cache = LLAvatarNameCache::getInstance(); + bool had_capability = name_cache->hasNameLookupURL(); + std::string name_lookup_url; + name_lookup_url.reserve(128); // avoid a memory allocation below + name_lookup_url = region->getCapability("GetDisplayNames"); + bool have_capability = !name_lookup_url.empty(); + if (have_capability) + { + // we have support for display names, use it + U32 url_size = name_lookup_url.size(); + // capabilities require URLs with slashes before query params: + // https://:/cap//?ids= + // but the caps are granted like: + // https://:/cap/ + if (url_size > 0 && name_lookup_url[url_size - 1] != '/') + { + name_lookup_url += '/'; + } + name_cache->setNameLookupURL(name_lookup_url); + } + else + { + // Display names not available on this region + name_cache->setNameLookupURL(std::string()); + } - name_cache->idle(); + // Error recovery - did we change state? + if (had_capability != have_capability) + { + // name tags are persistant on screen, so make sure they refresh + LLVOAvatar::invalidateNameTags(); + } + + name_cache->idle(); + } } // -- cgit v1.2.3