From d504efe3018bd0ce616e67c30b0bb31f5637973a Mon Sep 17 00:00:00 2001 From: Monroe Linden Date: Mon, 16 Nov 2009 16:52:43 -0800 Subject: Made nearby media list sort on distance from avatar instead of priority. When the MediaPerformanceManagerDebug debug setting is enabled, the list will sort by priority the way it used to. --- indra/newview/llviewermedia.cpp | 62 ++++++++++++++++++++++++++++------------- indra/newview/llviewermedia.h | 2 ++ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp index 70490d3a6e..4663e9c8e6 100644 --- a/indra/newview/llviewermedia.cpp +++ b/indra/newview/llviewermedia.cpp @@ -32,6 +32,7 @@ #include "llviewerprecompiledheaders.h" +#include "llagent.h" #include "llviewermedia.h" #include "llviewermediafocus.h" #include "llmimetypes.h" @@ -571,6 +572,11 @@ bool LLViewerMedia::priorityComparitor(const LLViewerMediaImpl* i1, const LLView // Playable items sort above ones that wouldn't play even if they got high enough priority return false; } + else if(i1->getInterest() == i2->getInterest()) + { + // Generally this will mean both objects have zero interest. In this case, sort on distance. + return (i1->getProximityDistance() < i2->getProximityDistance()); + } else { // The object with the larger interest value should be earlier in the list, so we reverse the sense of the comparison here. @@ -578,6 +584,11 @@ bool LLViewerMedia::priorityComparitor(const LLViewerMediaImpl* i1, const LLView } } +static bool proximity_comparitor(const LLViewerMediaImpl* i1, const LLViewerMediaImpl* i2) +{ + return (i1->getProximityDistance() < i2->getProximityDistance()); +} + ////////////////////////////////////////////////////////////////////////////////////////// // static void LLViewerMedia::updateMedia() @@ -603,12 +614,9 @@ void LLViewerMedia::updateMedia() int impl_count_total = 0; int impl_count_interest_low = 0; int impl_count_interest_normal = 0; - int i = 0; - -#if 0 - LL_DEBUGS("PluginPriority") << "Sorted impls:" << llendl; -#endif - + + std::vector proximity_order; + U32 max_instances = gSavedSettings.getU32("PluginInstancesTotal"); U32 max_normal = gSavedSettings.getU32("PluginInstancesNormal"); U32 max_low = gSavedSettings.getU32("PluginInstancesLow"); @@ -714,23 +722,27 @@ void LLViewerMedia::updateMedia() } else { - // Other impls just get the same ordering as the priority list (for now). - pimpl->mProximity = i; + proximity_order.push_back(pimpl); } -#if 0 - LL_DEBUGS("PluginPriority") << " " << pimpl - << ", setting priority to " << new_priority - << (pimpl->hasFocus()?", HAS FOCUS":"") - << (pimpl->getUsedInUI()?", is UI":"") - << ", cpu " << pimpl->getCPUUsage() - << ", interest " << pimpl->getInterest() - << ", media url " << pimpl->getMediaURL() << llendl; -#endif - total_cpu += pimpl->getCPUUsage(); - - i++; + } + + if(gSavedSettings.getBOOL("MediaPerformanceManagerDebug")) + { + // Give impls the same ordering as the priority list + // they're already in the right order for this. + } + else + { + // Use a distance-based sort for proximity values. + std::stable_sort(proximity_order.begin(), proximity_order.end(), proximity_comparitor); + } + + // Transfer the proximity order to the proximity fields in the objects. + for(int i = 0; i < proximity_order.size(); i++) + { + proximity_order[i]->mProximity = i; } LL_DEBUGS("PluginPriority") << "Total reported CPU usage is " << total_cpu << llendl; @@ -782,6 +794,7 @@ LLViewerMediaImpl::LLViewerMediaImpl( const LLUUID& texture_id, mIsDisabled(false), mIsParcelMedia(false), mProximity(-1), + mProximityDistance(0.0f), mMimeTypeProbe(NULL), mIsUpdated(false) { @@ -2109,6 +2122,15 @@ void LLViewerMediaImpl::calculateInterest() mInterest = 0.0f; } + // Calculate distance from the avatar, for use in the proximity calculation. + mProximityDistance = 0.0f; + if(!mObjectList.empty()) + { + // Just use the first object in the list. We could go through the list and find the closest object, but this should work well enough. + LLVector3d global_delta = gAgent.getPositionGlobal() - (*mObjectList.begin())->getPositionGlobal(); + mProximityDistance = global_delta.magVecSquared(); // use distance-squared because it's cheaper and sorts the same. + } + if(mNeedsMuteCheck) { // Check all objects this instance is associated with, and those objects' owners, against the mute list diff --git a/indra/newview/llviewermedia.h b/indra/newview/llviewermedia.h index a06079786e..f4afce6c4c 100644 --- a/indra/newview/llviewermedia.h +++ b/indra/newview/llviewermedia.h @@ -270,6 +270,7 @@ public: F64 getInterest() const { return mInterest; }; F64 getApproximateTextureInterest(); S32 getProximity() const { return mProximity; }; + F64 getProximityDistance() const { return mProximityDistance; }; // Mark this object as being used in a UI panel instead of on a prim // This will be used as part of the interest sorting algorithm. @@ -339,6 +340,7 @@ public: bool mIsDisabled; bool mIsParcelMedia; S32 mProximity; + F64 mProximityDistance; LLMimeDiscoveryResponder *mMimeTypeProbe; private: -- cgit v1.2.3