diff options
author | Merov Linden <merov@lindenlab.com> | 2012-09-21 20:13:50 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2012-09-21 20:13:50 -0700 |
commit | 552f288a0caea45e30a231478a19f4243d69689c (patch) | |
tree | a81d25696bf1b5e1fe29f0ba8f341cfec9d4e2e4 | |
parent | f95974637e720a7968b959d80cc4ab68260ccbe5 (diff) |
CHUI-340 : Implement distance computation and update
-rw-r--r-- | indra/newview/llconversationmodel.cpp | 24 | ||||
-rwxr-xr-x | indra/newview/llconversationmodel.h | 7 | ||||
-rwxr-xr-x | indra/newview/llimfloatercontainer.cpp | 40 | ||||
-rw-r--r-- | indra/newview/llimfloatercontainer.h | 1 |
4 files changed, 66 insertions, 6 deletions
diff --git a/indra/newview/llconversationmodel.cpp b/indra/newview/llconversationmodel.cpp index e090d1647f..b0d691fa13 100644 --- a/indra/newview/llconversationmodel.cpp +++ b/indra/newview/llconversationmodel.cpp @@ -181,6 +181,16 @@ void LLConversationItemSession::setTimeNow(const LLUUID& participant_id) } } +void LLConversationItemSession::setDistance(const LLUUID& participant_id, F64 dist) +{ + LLConversationItemParticipant* participant = findParticipant(participant_id); + if (participant) + { + participant->setDistance(dist); + mNeedsRefresh = true; + } +} + // The time of activity of a session is the time of the most recent activity, session and participants included const bool LLConversationItemSession::getTime(F64& time) const { @@ -224,13 +234,17 @@ void LLConversationItemSession::dumpDebugData() LLConversationItemParticipant::LLConversationItemParticipant(std::string display_name, const LLUUID& uuid, LLFolderViewModelInterface& root_view_model) : LLConversationItem(display_name,uuid,root_view_model), mIsMuted(false), - mIsModerator(false) + mIsModerator(false), + mDistToAgent(-1.0) { mConvType = CONV_PARTICIPANT; } LLConversationItemParticipant::LLConversationItemParticipant(const LLUUID& uuid, LLFolderViewModelInterface& root_view_model) : - LLConversationItem(uuid,root_view_model) + LLConversationItem(uuid,root_view_model), + mIsMuted(false), + mIsModerator(false), + mDistToAgent(-1.0) { mConvType = CONV_PARTICIPANT; } @@ -284,13 +298,13 @@ bool LLConversationSort::operator()(const LLConversationItem* const& a, const LL } else if (sort_order == LLConversationFilter::SO_DISTANCE) { - F32 dist_a = 0.0; - F32 dist_b = 0.0; + F64 dist_a = 0.0; + F64 dist_b = 0.0; bool has_dist_a = a->getDistanceToAgent(dist_a); bool has_dist_b = b->getDistanceToAgent(dist_b); if (has_dist_a && has_dist_b) { - return (dist_a > dist_b); + return (dist_a < dist_b); } else if (has_dist_a || has_dist_b) { diff --git a/indra/newview/llconversationmodel.h b/indra/newview/llconversationmodel.h index e67aeb9aca..18c5dd1ce1 100755 --- a/indra/newview/llconversationmodel.h +++ b/indra/newview/llconversationmodel.h @@ -107,7 +107,7 @@ public: // Methods used in sorting (see LLConversationSort::operator()) EConversationType const getType() const { return mConvType; } virtual const bool getTime(F64& time) const { time = mLastActiveTime; return (time > 0.1); } - virtual const bool getDistanceToAgent(F32& distance) const { return false; } + virtual const bool getDistanceToAgent(F64& distance) const { return false; } // This method will be called to determine if a drop can be // performed, and will set drop to TRUE if a drop is @@ -151,6 +151,7 @@ public: void setParticipantIsMuted(const LLUUID& participant_id, bool is_muted); void setParticipantIsModerator(const LLUUID& participant_id, bool is_moderator); void setTimeNow(const LLUUID& participant_id); + void setDistance(const LLUUID& participant_id, F64 dist); bool isLoaded() { return mIsLoaded; } @@ -174,14 +175,18 @@ public: void setIsMuted(bool is_muted) { mIsMuted = is_muted; mNeedsRefresh = true; } void setIsModerator(bool is_moderator) { mIsModerator = is_moderator; mNeedsRefresh = true; } void setTimeNow() { mLastActiveTime = LLFrameTimer::getElapsedSeconds(); mNeedsRefresh = true; } + void setDistance(F64 dist) { mDistToAgent = dist; mNeedsRefresh = true; } void onAvatarNameCache(const LLAvatarName& av_name); + virtual const bool getDistanceToAgent(F64& dist) const { dist = mDistToAgent; return (dist >= 0.0); } + void dumpDebugData(); private: bool mIsMuted; // default is false bool mIsModerator; // default is false + F64 mDistToAgent; // Distance to the agent. A negative (meaningless) value means the distance has not been set. }; // We don't want to ever filter conversations but we need to declare that class to create a conversation view model. diff --git a/indra/newview/llimfloatercontainer.cpp b/indra/newview/llimfloatercontainer.cpp index 3c21794d28..cd56ea6081 100755 --- a/indra/newview/llimfloatercontainer.cpp +++ b/indra/newview/llimfloatercontainer.cpp @@ -47,6 +47,7 @@ #include "llviewercontrol.h" #include "llconversationview.h" #include "llcallbacklist.h" +#include "llworld.h" // // LLIMFloaterContainer @@ -333,6 +334,14 @@ void LLIMFloaterContainer::setMinimized(BOOL b) void LLIMFloaterContainer::idle(void* user_data) { LLIMFloaterContainer* self = static_cast<LLIMFloaterContainer*>(user_data); + + // Update the distance to agent in the nearby chat session if required + // Note: it makes no sense of course to update the distance in other session + if (self->mConversationViewModel.getSorter().getSortOrderParticipants() == LLConversationFilter::SO_DISTANCE) + { + self->setNearbyDistances(); + } + self->mConversationsRoot->update(); } @@ -725,6 +734,37 @@ void LLIMFloaterContainer::setTimeNow(const LLUUID& session_id, const LLUUID& pa } } +void LLIMFloaterContainer::setNearbyDistances() +{ + // Get the nearby chat session: that's the one with uuid nul in mConversationsItems + conversations_items_map::iterator item_it = mConversationsItems.find(LLUUID()); + if (item_it != mConversationsItems.end()) + { + LLConversationItemSession* item = dynamic_cast<LLConversationItemSession*>(item_it->second); + if (item) + { + // Get the positions of the nearby avatars and their ids + std::vector<LLVector3d> positions; + uuid_vec_t avatar_ids; + LLWorld::getInstance()->getAvatars(&avatar_ids, &positions, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange")); + // Get the position of the agent + const LLVector3d& me_pos = gAgent.getPositionGlobal(); + // For each nearby avatar, compute and update the distance + int avatar_count = positions.size(); + for (int i = 0; i < avatar_count; i++) + { + F64 dist = dist_vec_squared(positions[i], me_pos); + item->setDistance(avatar_ids[i],dist); + } + // Also does it for the agent itself + item->setDistance(gAgent.getID(),0.0f); + // Request resort + mConversationViewModel.requestSortAll(); + mConversationsRoot->arrangeAll(); + } + } +} + void LLIMFloaterContainer::addConversationListItem(const LLUUID& uuid) { bool is_nearby_chat = uuid.isNull(); diff --git a/indra/newview/llimfloatercontainer.h b/indra/newview/llimfloatercontainer.h index 4546029e93..e8d185297c 100644 --- a/indra/newview/llimfloatercontainer.h +++ b/indra/newview/llimfloatercontainer.h @@ -125,6 +125,7 @@ public: void removeConversationListItem(const LLUUID& uuid, bool change_focus = true); void addConversationListItem(const LLUUID& uuid); void setTimeNow(const LLUUID& session_id, const LLUUID& participant_id); + void setNearbyDistances(); private: LLConversationViewSession* createConversationItemWidget(LLConversationItem* item); |