Stinson Linden avatar Stinson Linden committed 9f98d9c

PATH-849: Refactoring the behavior after loading the owner name of a pathfinding object into the avatar name cache so that each object can simply update its respective row in the scroll list rather than rebuilding from scratch after all names are loaded.

Comments (0)

Files changed (8)

indra/newview/llfloaterpathfindingcharacters.cpp

 	LLPathfindingManager::getInstance()->requestGetCharacters(getNewRequestId(), boost::bind(&LLFloaterPathfindingCharacters::handleNewObjectList, this, _1, _2, _3));
 }
 
-LLSD LLFloaterPathfindingCharacters::convertObjectsIntoScrollListData(const LLPathfindingObjectListPtr pObjectListPtr)
+void LLFloaterPathfindingCharacters::buildObjectsScrollList(const LLPathfindingObjectListPtr pObjectListPtr)
 {
 	llassert(pObjectListPtr != NULL);
 	llassert(!pObjectListPtr->isEmpty());
 
-	LLSD scrollListData = LLSD::emptyArray();
-
 	for (LLPathfindingObjectList::const_iterator objectIter = pObjectListPtr->begin();	objectIter != pObjectListPtr->end(); ++objectIter)
 	{
-		const LLPathfindingCharacter *characterPtr = dynamic_cast<const LLPathfindingCharacter *>(objectIter->second.get());
-		LLSD element = buildCharacterScrollListData(characterPtr);
-		scrollListData.append(element);
+		const LLPathfindingObjectPtr objectPtr = objectIter->second;
+		const LLPathfindingCharacter *characterPtr = dynamic_cast<const LLPathfindingCharacter *>(objectPtr.get());
+		llassert(characterPtr != NULL);
 
-		if (characterPtr->hasOwner() && !characterPtr->hasOwnerName())
-		{
-			rebuildScrollListAfterAvatarNameLoads(characterPtr->getUUID());
-		}
+		LLSD scrollListItemData = buildCharacterScrollListItemData(characterPtr);
+		addObjectToScrollList(objectPtr, scrollListItemData);
 	}
-
-	return scrollListData;
 }
 
 void LLFloaterPathfindingCharacters::updateControlsOnScrollListChange()
 	}
 }
 
-LLSD LLFloaterPathfindingCharacters::buildCharacterScrollListData(const LLPathfindingCharacter *pCharacterPtr) const
+LLSD LLFloaterPathfindingCharacters::buildCharacterScrollListItemData(const LLPathfindingCharacter *pCharacterPtr) const
 {
-	LLSD columns;
+	LLSD columns = LLSD::emptyArray();
 
 	columns[0]["column"] = "name";
 	columns[0]["value"] = pCharacterPtr->getName();
 	columns[4]["column"] = "altitude";
 	columns[4]["value"] = llformat("%1.0f m", pCharacterPtr->getLocation()[2]);
 
-	LLSD element;
-	element["id"] = pCharacterPtr->getUUID().asString();
-	element["column"] = columns;
-
-	return element;
+	return columns;
 }
 
 void LLFloaterPathfindingCharacters::updateStateOnDisplayControls()

indra/newview/llfloaterpathfindingcharacters.h

 
 	virtual void                       requestGetObjects();
 
-	virtual LLSD                       convertObjectsIntoScrollListData(const LLPathfindingObjectListPtr pObjectListPtr);
+	virtual void                       buildObjectsScrollList(const LLPathfindingObjectListPtr pObjectListPtr);
 
 	virtual void                       updateControlsOnScrollListChange();
 
 private:
 	void onShowPhysicsCapsuleClicked();
 
-	LLSD buildCharacterScrollListData(const LLPathfindingCharacter *pCharacterPtr) const;
+	LLSD buildCharacterScrollListItemData(const LLPathfindingCharacter *pCharacterPtr) const;
 
 	void updateStateOnDisplayControls();
 	void showSelectedCharacterCapsules();

indra/newview/llfloaterpathfindinglinksets.cpp

 	LLPathfindingManager::getInstance()->requestGetLinksets(getNewRequestId(), boost::bind(&LLFloaterPathfindingLinksets::handleNewObjectList, this, _1, _2, _3));
 }
 
-LLSD LLFloaterPathfindingLinksets::convertObjectsIntoScrollListData(const LLPathfindingObjectListPtr pObjectListPtr)
+void LLFloaterPathfindingLinksets::buildObjectsScrollList(const LLPathfindingObjectListPtr pObjectListPtr)
 {
 	llassert(pObjectListPtr != NULL);
 	llassert(!pObjectListPtr->isEmpty());
 	bool isFilteringDescription = !descriptionFilter.empty();
 	bool isFilteringLinksetUse = (linksetUseFilter != LLPathfindingLinkset::kUnknown);
 
-	LLSD scrollListData = LLSD::emptyArray();
 	const LLVector3& avatarPosition = gAgent.getPositionAgent();
 
 	if (isFilteringName || isFilteringDescription || isFilteringLinksetUse)
 		LLStringUtil::toUpper(descriptionFilter);
 		for (LLPathfindingObjectList::const_iterator objectIter = pObjectListPtr->begin();	objectIter != pObjectListPtr->end(); ++objectIter)
 		{
-			const LLPathfindingLinkset *linksetPtr = dynamic_cast<const LLPathfindingLinkset *>(objectIter->second.get());
+			const LLPathfindingObjectPtr objectPtr = objectIter->second;
+			const LLPathfindingLinkset *linksetPtr = dynamic_cast<const LLPathfindingLinkset *>(objectPtr.get());
+			llassert(linksetPtr != NULL);
+
 			std::string linksetName = (linksetPtr->isTerrain() ? getString("linkset_terrain_name") : linksetPtr->getName());
 			std::string linksetDescription = linksetPtr->getDescription();
 			LLStringUtil::toUpper(linksetName);
 			LLStringUtil::toUpper(linksetDescription);
+
 			if ((!isFilteringName || (linksetName.find(nameFilter) != std::string::npos)) &&
 				(!isFilteringDescription || (linksetDescription.find(descriptionFilter) != std::string::npos)) &&
 				(!isFilteringLinksetUse || (linksetPtr->getLinksetUse() == linksetUseFilter)))
 			{
-				LLSD element = buildLinksetScrollListData(linksetPtr, avatarPosition);
-				scrollListData.append(element);
-
-				if (linksetPtr->hasOwner() && !linksetPtr->hasOwnerName())
-				{
-					rebuildScrollListAfterAvatarNameLoads(linksetPtr->getUUID());
-				}
+				LLSD scrollListItemData = buildLinksetScrollListItemData(linksetPtr, avatarPosition);
+				addObjectToScrollList(objectPtr, scrollListItemData);
 			}
 		}
 	}
 	{
 		for (LLPathfindingObjectList::const_iterator objectIter = pObjectListPtr->begin();	objectIter != pObjectListPtr->end(); ++objectIter)
 		{
-			const LLPathfindingLinkset *linksetPtr = dynamic_cast<const LLPathfindingLinkset *>(objectIter->second.get());
-			LLSD element = buildLinksetScrollListData(linksetPtr, avatarPosition);
-			scrollListData.append(element);
+			const LLPathfindingObjectPtr objectPtr = objectIter->second;
+			const LLPathfindingLinkset *linksetPtr = dynamic_cast<const LLPathfindingLinkset *>(objectPtr.get());
+			llassert(linksetPtr != NULL);
 
-			if (linksetPtr->hasOwner() && !linksetPtr->hasOwnerName())
-			{
-				rebuildScrollListAfterAvatarNameLoads(linksetPtr->getUUID());
-			}
+			LLSD scrollListItemData = buildLinksetScrollListItemData(linksetPtr, avatarPosition);
+			addObjectToScrollList(objectPtr, scrollListItemData);
 		}
 	}
-
-	return scrollListData;
 }
 
 void LLFloaterPathfindingLinksets::updateControlsOnScrollListChange()
 	}
 }
 
-LLSD LLFloaterPathfindingLinksets::buildLinksetScrollListData(const LLPathfindingLinkset *pLinksetPtr, const LLVector3 &pAvatarPosition) const
+LLSD LLFloaterPathfindingLinksets::buildLinksetScrollListItemData(const LLPathfindingLinkset *pLinksetPtr, const LLVector3 &pAvatarPosition) const
 {
 	llassert(pLinksetPtr != NULL);
-	LLSD columns;
+	LLSD columns = LLSD::emptyArray();
 
 	if (pLinksetPtr->isTerrain())
 	{
 	columns[9]["column"] = "d_percent";
 	columns[9]["value"] = llformat("%3d", pLinksetPtr->getWalkabilityCoefficientD());
 
-	LLSD element;
-	element["id"] = pLinksetPtr->getUUID().asString();
-	element["column"] = columns;
-
-	return element;
+	return columns;
 }
 
 LLSD LLFloaterPathfindingLinksets::buildLinksetUseScrollListData(const std::string &pLabel, S32 pValue) const

indra/newview/llfloaterpathfindinglinksets.h

 
 	virtual void                       requestGetObjects();
 
-	virtual LLSD                       convertObjectsIntoScrollListData(const LLPathfindingObjectListPtr pObjectListPtr);
+	virtual void                       buildObjectsScrollList(const LLPathfindingObjectListPtr pObjectListPtr);
 
 	virtual void                       updateControlsOnScrollListChange();
 
 	void clearFilters();
 
 	void updateEditFieldValues();
-	LLSD buildLinksetScrollListData(const LLPathfindingLinkset *pLinksetPtr, const LLVector3 &pAvatarPosition) const;
+	LLSD buildLinksetScrollListItemData(const LLPathfindingLinkset *pLinksetPtr, const LLVector3 &pAvatarPosition) const;
 	LLSD buildLinksetUseScrollListData(const std::string &pLabel, S32 pValue) const;
 
 	bool isShowUnmodifiablePhantomWarning(LLPathfindingLinkset::ELinksetUse pLinksetUse) const;

indra/newview/llfloaterpathfindingobjects.cpp

 
 #include "llfloaterpathfindingobjects.h"
 
+#include <string>
+#include <map>
 #include <vector>
 
 #include <boost/bind.hpp>
 
 void LLFloaterPathfindingObjects::onClose(bool pIsAppQuitting)
 {
-	
 	if (mGodLevelChangeSlot.connected())
 	{
 		mGodLevelChangeSlot.disconnect();
 	{
 		mObjectsSelection.clear();
 	}
+
+	if (pIsAppQuitting)
+	{
+		clearAllObjects();
+	}
 }
 
 void LLFloaterPathfindingObjects::draw()
 	mReturnButton(NULL),
 	mDeleteButton(NULL),
 	mTeleportButton(NULL),
-	mLoadingAvatarNames(),
 	mDefaultBeaconColor(),
 	mDefaultBeaconTextColor(),
 	mErrorTextColor(),
 	mWarningTextColor(),
 	mMessagingState(kMessagingUnknown),
 	mMessagingRequestId(0U),
+	mMissingNameObjectsScrollListItems(),
 	mObjectList(),
 	mObjectsSelection(),
 	mHasObjectsToBeSelected(false),
 
 LLFloaterPathfindingObjects::~LLFloaterPathfindingObjects()
 {
+	clearAllObjects();
 }
 
 BOOL LLFloaterPathfindingObjects::postBuild()
 
 	S32 origScrollPosition = mObjectsScrollList->getScrollPos();
 	mObjectsScrollList->deleteAllItems();
+	mMissingNameObjectsScrollListItems.clear();
 
 	if ((mObjectList != NULL) && !mObjectList->isEmpty())
 	{
-		LLSD scrollListData = convertObjectsIntoScrollListData(mObjectList);
-		llassert(scrollListData.isArray());
+		buildObjectsScrollList(mObjectList);
 
-		LLScrollListCell::Params cellParams;
-		cellParams.font = LLFontGL::getFontSansSerif();
-
-		for (LLSD::array_const_iterator rowElementIter = scrollListData.beginArray(); rowElementIter != scrollListData.endArray(); ++rowElementIter)
+		mObjectsScrollList->selectMultiple(mObjectsToBeSelected);
+		if (mHasObjectsToBeSelected)
 		{
-			const LLSD &rowElement = *rowElementIter;
-
-			LLScrollListItem::Params rowParams;
-			llassert(rowElement.has("id"));
-			llassert(rowElement.get("id").isString());
-			rowParams.value = rowElement.get("id");
-
-			llassert(rowElement.has("column"));
-			llassert(rowElement.get("column").isArray());
-			const LLSD &columnElement = rowElement.get("column");
-			for (LLSD::array_const_iterator cellIter = columnElement.beginArray(); cellIter != columnElement.endArray(); ++cellIter)
-			{
-				const LLSD &cellElement = *cellIter;
-
-				llassert(cellElement.has("column"));
-				llassert(cellElement.get("column").isString());
-				cellParams.column = cellElement.get("column").asString();
-
-				llassert(cellElement.has("value"));
-				llassert(cellElement.get("value").isString());
-				cellParams.value = cellElement.get("value").asString();
-
-				rowParams.columns.add(cellParams);
-			}
-
-			mObjectsScrollList->addRow(rowParams);
+			mObjectsScrollList->scrollToShowSelected();
 		}
-	}
-
-	mObjectsScrollList->selectMultiple(mObjectsToBeSelected);
-	if (mHasObjectsToBeSelected)
-	{
-		mObjectsScrollList->scrollToShowSelected();
-	}
-	else
-	{
-		mObjectsScrollList->setScrollPos(origScrollPosition);
+		else
+		{
+			mObjectsScrollList->setScrollPos(origScrollPosition);
+		}
 	}
 
 	mObjectsToBeSelected.clear();
 	updateControlsOnScrollListChange();
 }
 
-LLSD LLFloaterPathfindingObjects::convertObjectsIntoScrollListData(const LLPathfindingObjectListPtr pObjectListPtr)
+void LLFloaterPathfindingObjects::buildObjectsScrollList(const LLPathfindingObjectListPtr pObjectListPtr)
 {
 	llassert(0);
-	LLSD nullObjs = LLSD::emptyArray();
-	return nullObjs;
 }
 
-void LLFloaterPathfindingObjects::rebuildScrollListAfterAvatarNameLoads(const LLUUID &pAvatarId)
+void LLFloaterPathfindingObjects::addObjectToScrollList(const LLPathfindingObjectPtr pObjectPtr, const LLSD &pScrollListItemData)
 {
-	std::set<LLUUID>::const_iterator iter = mLoadingAvatarNames.find(pAvatarId);
-	if (iter == mLoadingAvatarNames.end())
+	LLScrollListCell::Params cellParams;
+	cellParams.font = LLFontGL::getFontSansSerif();
+
+	LLScrollListItem::Params rowParams;
+	rowParams.value = pObjectPtr->getUUID().asString();
+
+	llassert(pScrollListItemData.isArray());
+	for (LLSD::array_const_iterator cellIter = pScrollListItemData.beginArray();
+		cellIter != pScrollListItemData.endArray(); ++cellIter)
 	{
-		mLoadingAvatarNames.insert(pAvatarId);
-		LLAvatarNameCache::get(pAvatarId, boost::bind(&LLFloaterPathfindingObjects::handleAvatarNameLoads, this, _1, _2));
+		const LLSD &cellElement = *cellIter;
+
+		llassert(cellElement.has("column"));
+		llassert(cellElement.get("column").isString());
+		cellParams.column = cellElement.get("column").asString();
+
+		llassert(cellElement.has("value"));
+		llassert(cellElement.get("value").isString());
+		cellParams.value = cellElement.get("value").asString();
+
+		rowParams.columns.add(cellParams);
+	}
+
+	LLScrollListItem *scrollListItem = mObjectsScrollList->addRow(rowParams);
+
+	if (pObjectPtr->hasOwner() && !pObjectPtr->hasOwnerName())
+	{
+		mMissingNameObjectsScrollListItems.insert(std::make_pair<std::string, LLScrollListItem *>(pObjectPtr->getUUID().asString(), scrollListItem));
+		pObjectPtr->registerOwnerNameListener(boost::bind(&LLFloaterPathfindingObjects::handleObjectNameResponse, this, _1, _2));
 	}
 }
 
 	return 0;
 }
 
+S32 LLFloaterPathfindingObjects::getOwnerNameColumnIndex() const
+{
+	return 2;
+}
+
 const LLColor4 &LLFloaterPathfindingObjects::getBeaconColor() const
 {
 	return mDefaultBeaconColor;
 {
 	selectNoneObjects();
 	mObjectsScrollList->deleteAllItems();
+	mMissingNameObjectsScrollListItems.clear();
 	mObjectList.reset();
 }
 
 	requestGetObjects();
 }
 
-void LLFloaterPathfindingObjects::handleAvatarNameLoads(const LLUUID &pAvatarId, const LLAvatarName &pAvatarName)
+void LLFloaterPathfindingObjects::handleObjectNameResponse(const LLUUID &pObjectUUID, const std::string &pOwnerName)
 {
-	llassert(mLoadingAvatarNames.find(pAvatarId) != mLoadingAvatarNames.end());
-	mLoadingAvatarNames.erase(pAvatarId);
-	if (mLoadingAvatarNames.empty())
+	const std::string uuid = pObjectUUID.asString();
+	scroll_list_item_map::iterator scrollListItemIter = mMissingNameObjectsScrollListItems.find(uuid);
+	if (scrollListItemIter != mMissingNameObjectsScrollListItems.end())
 	{
-		rebuildObjectsScrollList();
+		LLScrollListItem *scrollListItem = scrollListItemIter->second;
+		llassert(scrollListItem != NULL);
+
+		LLScrollListCell *scrollListCell = scrollListItem->getColumn(getOwnerNameColumnIndex());
+		LLSD ownerName = pOwnerName;
+
+		scrollListCell->setValue(ownerName);
+
+		mMissingNameObjectsScrollListItems.erase(scrollListItemIter);
 	}
 }
 

indra/newview/llfloaterpathfindingobjects.h

 #ifndef LL_LLFLOATERPATHFINDINGOBJECTS_H
 #define LL_LLFLOATERPATHFINDINGOBJECTS_H
 
-#include <set>
+#include <string>
+#include <map>
 
 #include <boost/signals2.hpp>
 
 	void                               handleUpdateObjectList(LLPathfindingManager::request_id_t pRequestId, LLPathfindingManager::ERequestStatus pRequestStatus, LLPathfindingObjectListPtr pObjectList);
 
 	void                               rebuildObjectsScrollList();
-	virtual LLSD                       convertObjectsIntoScrollListData(const LLPathfindingObjectListPtr pObjectListPtr);
-
-	void                               rebuildScrollListAfterAvatarNameLoads(const LLUUID &pAvatarId);
+	virtual void                       buildObjectsScrollList(const LLPathfindingObjectListPtr pObjectListPtr);
+	void                               addObjectToScrollList(const LLPathfindingObjectPtr pObjectPr, const LLSD &pScrollListItemData);
 
 	virtual void                       updateControlsOnScrollListChange();
 	virtual void                       updateControlsOnInWorldSelectionChange();
 
 	virtual S32                        getNameColumnIndex() const;
+	virtual S32                        getOwnerNameColumnIndex() const;
 	virtual const LLColor4             &getBeaconColor() const;
 	virtual const LLColor4             &getBeaconTextColor() const;
 	virtual S32                        getBeaconWidth() const;
 	void                   onRegionBoundaryCrossed();
 	void                   onGodLevelChange(U8 pGodLevel);
 
-	void                   handleAvatarNameLoads(const LLUUID &pAvatarId, const LLAvatarName &pAvatarName);
+	void                   handleObjectNameResponse(const LLUUID &pObjectUUID, const std::string &pOwnerName);
 
 	void                   updateMessagingStatus();
 	void                   updateStateOnListControls();
 	LLButton                           *mDeleteButton;
 	LLButton                           *mTeleportButton;
 
-	std::set<LLUUID>                   mLoadingAvatarNames;
-
 	LLColor4                           mDefaultBeaconColor;
 	LLColor4                           mDefaultBeaconTextColor;
 	LLColor4                           mErrorTextColor;
 	EMessagingState                    mMessagingState;
 	LLPathfindingManager::request_id_t mMessagingRequestId;
 
+	typedef std::map<std::string, LLScrollListItem *> scroll_list_item_map;
+	scroll_list_item_map               mMissingNameObjectsScrollListItems;
+
 	LLPathfindingObjectListPtr         mObjectList;
 
 	LLObjectSelectionHandle            mObjectsSelection;

indra/newview/llpathfindingobject.cpp

 	mOwnerName(),
 	mAvatarNameCacheConnection(),
 	mIsGroupOwned(false),
-	mLocation()
+	mLocation(),
+	mOwnerNameSignal()
 {
 }
 
 	mOwnerName(),
 	mAvatarNameCacheConnection(),
 	mIsGroupOwned(false),
-	mLocation()
+	mLocation(),
+	mOwnerNameSignal()
 {
 	parseObjectData(pObjectData);
 }
 	mOwnerName(),
 	mAvatarNameCacheConnection(),
 	mIsGroupOwned(pOther.mIsGroupOwned),
-	mLocation(pOther.mLocation)
+	mLocation(pOther.mLocation),
+	mOwnerNameSignal()
 {
 	fetchOwnerName();
 }
 	return ownerName;
 }
 
+LLPathfindingObject::name_connection_t LLPathfindingObject::registerOwnerNameListener(name_callback_t pOwnerNameCallback)
+{
+	llassert(hasOwner());
+
+	name_connection_t connection;
+	if (hasOwnerName())
+	{
+		pOwnerNameCallback(getUUID(), getOwnerName());
+	}
+	else
+	{
+		connection = mOwnerNameSignal.connect(pOwnerNameCallback);
+	}
+
+	return connection;
+}
+
 void LLPathfindingObject::parseObjectData(const LLSD &pObjectData)
 {
 	llassert(pObjectData.has(PATHFINDING_OBJECT_NAME_FIELD));
 void LLPathfindingObject::handleAvatarNameFetch(const LLUUID &pOwnerUUID, const LLAvatarName &pAvatarName)
 {
 	llassert(mOwnerUUID == pOwnerUUID);
+
 	mOwnerName = pAvatarName;
 	mHasOwnerName = true;
+
 	disconnectAvatarNameCacheConnection();
+
+	mOwnerNameSignal(getUUID(), getOwnerName());
 }
 
 void LLPathfindingObject::disconnectAvatarNameCacheConnection()

indra/newview/llpathfindingobject.h

 #include <string>
 
 #include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
+#include <boost/signals2.hpp>
 
 #include "llavatarname.h"
 #include "llavatarnamecache.h"
 	inline BOOL               isGroupOwned() const   {return mIsGroupOwned;};
 	inline const LLVector3&   getLocation() const    {return mLocation;};
 
+	typedef boost::function<void (const LLUUID &, const std::string &)>         name_callback_t;
+	typedef boost::signals2::signal<void (const LLUUID &, const std::string &)> name_signal_t;
+	typedef boost::signals2::connection                                         name_connection_t;
+
+	name_connection_t registerOwnerNameListener(name_callback_t pOwnerNameCallback);
+
 protected:
 
 private:
 	LLAvatarNameCache::callback_connection_t mAvatarNameCacheConnection;
 	BOOL                                     mIsGroupOwned;
 	LLVector3                                mLocation;
+	name_signal_t                            mOwnerNameSignal;
 };
 
 #endif // LL_LLPATHFINDINGOBJECT_H
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.