diff --git a/indra/newview/llspeakers.cpp b/indra/newview/llspeakers.cpp index a4e11d815..ce2122974 100644 --- a/indra/newview/llspeakers.cpp +++ b/indra/newview/llspeakers.cpp @@ -240,7 +240,7 @@ LLSpeakersDelayActionsStorage::~LLSpeakersDelayActionsStorage() void LLSpeakersDelayActionsStorage::setActionTimer(const LLUUID& speaker_id) { bool not_found = true; - if (mActionTimersMap.size() > 0) + if (!mActionTimersMap.empty()) { not_found = mActionTimersMap.find(speaker_id) == mActionTimersMap.end(); } @@ -258,7 +258,7 @@ void LLSpeakersDelayActionsStorage::setActionTimer(const LLUUID& speaker_id) void LLSpeakersDelayActionsStorage::unsetActionTimer(const LLUUID& speaker_id) { - if (mActionTimersMap.size() == 0) return; + if (mActionTimersMap.empty()) return; LLSpeakerActionTimer::action_timer_iter_t it_speaker = mActionTimersMap.find(speaker_id); @@ -434,8 +434,8 @@ void LLSpeakerMgr::update(BOOL resort_ok) return; } - LLColor4 speaking_color = gSavedSettings.getColor4("SpeakingColor"); - LLColor4 overdriven_color = gSavedSettings.getColor4("OverdrivenColor"); + static const LLCachedControl speaking_color(gSavedSettings, "SpeakingColor"); + static const LLCachedControl overdriven_color(gSavedSettings, "OverdrivenColor"); if(resort_ok) // only allow list changes when user is not interacting with it { @@ -445,10 +445,10 @@ void LLSpeakerMgr::update(BOOL resort_ok) // update status of all current speakers BOOL voice_channel_active = (!mVoiceChannel && LLVoiceClient::getInstance()->inProximalChannel()) || (mVoiceChannel && mVoiceChannel->isActive()); bool re_sort = false; - for (speaker_map_t::iterator speaker_it = mSpeakers.begin(); speaker_it != mSpeakers.end(); ++speaker_it) + for (auto& speaker : mSpeakers) { - LLUUID speaker_id = speaker_it->first; - LLSpeaker* speakerp = speaker_it->second; + LLUUID speaker_id = speaker.first; + LLSpeaker* speakerp = speaker.second; if (voice_channel_active && LLVoiceClient::getInstance()->getVoiceEnabled(speaker_id)) { @@ -532,12 +532,8 @@ void LLSpeakerMgr::update(BOOL resort_ok) bool index_changed = false; S32 recent_speaker_count = 0; S32 sort_index = 0; - for (speaker_list_t::iterator sorted_speaker_it = mSpeakersSorted.begin(); - sorted_speaker_it != mSpeakersSorted.end(); - ++sorted_speaker_it) + for (auto speakerp : mSpeakersSorted) { - LLPointer speakerp = *sorted_speaker_it; - // color code recent speakers who are not currently speaking if (speakerp->mStatus == LLSpeaker::STATUS_HAS_SPOKEN) { @@ -561,9 +557,6 @@ void LLSpeakerMgr::update(BOOL resort_ok) void LLSpeakerMgr::updateSpeakerList() { - // Always add the current agent (it has to be there...). Will do nothing if already there. - setSpeaker({ gAgentID, LLSpeaker::SPEAKER_AGENT, LLSpeaker::STATUS_VOICE_ACTIVE }); - // Are we bound to the currently active voice channel? if ((!mVoiceChannel && LLVoiceClient::getInstance()->inProximalChannel()) || (mVoiceChannel && mVoiceChannel->isActive())) { @@ -572,22 +565,21 @@ void LLSpeakerMgr::updateSpeakerList() // If we are, add all voice client participants to our list of known speakers std::vector speakers; speakers.reserve(participants.size()); - for (auto participant_it = participants.begin(); participant_it != participants.end(); ++participant_it) + for (auto participant : participants) { - speakers.emplace_back( - *participant_it, - (LLVoiceClient::getInstance()->isParticipantAvatar(*participant_it) ? LLSpeaker::SPEAKER_AGENT : LLSpeaker::SPEAKER_EXTERNAL), + speakers.emplace_back(participant, + (LLVoiceClient::getInstance()->isParticipantAvatar(participant) ? LLSpeaker::SPEAKER_AGENT : LLSpeaker::SPEAKER_EXTERNAL), LLSpeaker::STATUS_VOICE_ACTIVE, boost::none, boost::none, - LLVoiceClient::getInstance()->getDisplayName(*participant_it)); + LLVoiceClient::getInstance()->getDisplayName(participant)); } setSpeakers(speakers); } else { // If not, check if the list is empty, except if it's Nearby Chat (session_id NULL). - LLUUID session_id = getSessionID(); + LLUUID const& session_id = getSessionID(); if (!session_id.isNull() && !mSpeakerListUpdated) { // If the list is empty, we update it with whatever we have locally so that it doesn't stay empty too long. @@ -636,15 +628,16 @@ void LLSpeakerMgr::updateSpeakerList() mSpeakerListUpdated = true; } } - else if (floater && mSpeakers.size() == 0) + else if (floater && mSpeakers.empty()) { // For all other session type (ad-hoc, P2P, avaline), we use the initial participants targets list - for (const auto& id : floater->mInitialTargetIDs) + for (const auto& target_id : floater->mInitialTargetIDs) { // Add buddies if they are on line, add any other avatar. - if (!LLAvatarTracker::instance().isBuddy(id) || LLAvatarTracker::instance().isBuddyOnline(id)) + if (!LLAvatarTracker::instance().isBuddy(target_id) || LLAvatarTracker::instance().isBuddyOnline( + target_id)) { - setSpeaker({ id, LLSpeaker::SPEAKER_AGENT, LLSpeaker::STATUS_VOICE_ACTIVE }); + setSpeaker({target_id, LLSpeaker::SPEAKER_AGENT, LLSpeaker::STATUS_VOICE_ACTIVE }); } } mSpeakerListUpdated = true; @@ -656,13 +649,18 @@ void LLSpeakerMgr::updateSpeakerList() } } } + // Always add the current agent (it has to be there...). Will do nothing if already there. + setSpeaker({ gAgentID, LLSpeaker::SPEAKER_AGENT, LLSpeaker::STATUS_VOICE_ACTIVE }); } -void LLSpeakerMgr::setSpeakerNotInChannel(LLSpeaker* speakerp) +void LLSpeakerMgr::setSpeakerNotInChannel(LLPointer speakerp) { - speakerp->setStatus(LLSpeaker::STATUS_NOT_IN_CHANNEL); - speakerp->mDotColor = INACTIVE_COLOR; - mSpeakerDelayRemover->setActionTimer(speakerp->mID); + if (speakerp.notNull()) + { + speakerp->setStatus(LLSpeaker::STATUS_NOT_IN_CHANNEL); + speakerp->mDotColor = INACTIVE_COLOR; + mSpeakerDelayRemover->setActionTimer(speakerp->mID); + } } bool LLSpeakerMgr::removeSpeaker(const LLUUID& speaker_id) @@ -691,12 +689,12 @@ bool LLSpeakerMgr::removeSpeaker(const LLUUID& speaker_id) LLPointer LLSpeakerMgr::findSpeaker(const LLUUID& speaker_id) { //In some conditions map causes crash if it is empty(Windows only), adding check (EK) - if (mSpeakers.size() == 0) - return NULL; + if (mSpeakers.empty()) + return nullptr; speaker_map_t::iterator found_it = mSpeakers.find(speaker_id); if (found_it == mSpeakers.end()) { - return NULL; + return nullptr; } return found_it->second; } @@ -704,9 +702,9 @@ LLPointer LLSpeakerMgr::findSpeaker(const LLUUID& speaker_id) void LLSpeakerMgr::getSpeakerList(speaker_list_t* speaker_list, BOOL include_text) { speaker_list->clear(); - for (speaker_map_t::iterator speaker_it = mSpeakers.begin(); speaker_it != mSpeakers.end(); ++speaker_it) + for (auto& speaker : mSpeakers) { - LLPointer speakerp = speaker_it->second; + LLPointer speakerp = speaker.second; // what about text only muted or inactive? if (include_text || speakerp->mStatus != LLSpeaker::STATUS_TEXT_ONLY) { @@ -715,12 +713,12 @@ void LLSpeakerMgr::getSpeakerList(speaker_list_t* speaker_list, BOOL include_tex } } -const LLUUID LLSpeakerMgr::getSessionID() +const LLUUID LLSpeakerMgr::getSessionID() const { return mVoiceChannel->getSessionID(); } -bool LLSpeakerMgr::isSpeakerToBeRemoved(const LLUUID& speaker_id) +bool LLSpeakerMgr::isSpeakerToBeRemoved(const LLUUID& speaker_id) const { return mSpeakerDelayRemover && mSpeakerDelayRemover->isTimerStarted(speaker_id); } @@ -746,7 +744,7 @@ void LLSpeakerMgr::speakerChatted(const LLUUID& speaker_id) } } -BOOL LLSpeakerMgr::isVoiceActive() +BOOL LLSpeakerMgr::isVoiceActive() const { // mVoiceChannel = NULL means current voice channel, whatever it is return LLVoiceClient::getInstance()->voiceEnabled() && mVoiceChannel && mVoiceChannel->isActive(); @@ -778,8 +776,7 @@ void LLIMSpeakerMgr::setSpeakers(const LLSD& speakers) std::vector speakerentries; if ( speakers.has("agent_info") && speakers["agent_info"].isMap() ) { - LLSD::map_const_iterator speaker_it; - for(speaker_it = speakers["agent_info"].beginMap(); + for(LLSD::map_const_iterator speaker_it = speakers["agent_info"].beginMap(); speaker_it != speakers["agent_info"].endMap(); ++speaker_it) { @@ -803,8 +800,7 @@ void LLIMSpeakerMgr::setSpeakers(const LLSD& speakers) { //older, more decprecated way. Need here for //using older version of servers - LLSD::array_const_iterator speaker_it; - for(speaker_it = speakers["agents"].beginArray(); + for(LLSD::array_const_iterator speaker_it = speakers["agents"].beginArray(); speaker_it != speakers["agents"].endArray(); ++speaker_it) { @@ -821,10 +817,7 @@ void LLIMSpeakerMgr::updateSpeakers(const LLSD& update) std::vector speakerentries; if ( update.has("agent_updates") && update["agent_updates"].isMap() ) { - - LLSD::map_const_iterator update_it; - for( - update_it = update["agent_updates"].beginMap(); + for(LLSD::map_const_iterator update_it = update["agent_updates"].beginMap(); update_it != update["agent_updates"].endMap(); ++update_it) { @@ -838,7 +831,7 @@ void LLIMSpeakerMgr::updateSpeakers(const LLSD& update) LLSD agent_data = update_it->second; if (agent_data.isMap() && agent_data.has("transition")) { - if (agent_data["transition"].asString() == "LEAVE" && speakerp.notNull()) + if (agent_data["transition"].asString() == "LEAVE") { setSpeakerNotInChannel(speakerp); } @@ -882,9 +875,7 @@ void LLIMSpeakerMgr::updateSpeakers(const LLSD& update) } else if ( update.has("updates") && update["updates"].isMap() ) { - LLSD::map_const_iterator update_it; - for ( - update_it = update["updates"].beginMap(); + for (LLSD::map_const_iterator update_it = update["updates"].beginMap(); update_it != update["updates"].endMap(); ++update_it) { @@ -892,7 +883,7 @@ void LLIMSpeakerMgr::updateSpeakers(const LLSD& update) LLPointer speakerp = findSpeaker(agent_id); std::string agent_transition = update_it->second.asString(); - if (agent_transition == "LEAVE" && speakerp.notNull()) + if (agent_transition == "LEAVE") { setSpeakerNotInChannel(speakerp); } @@ -915,7 +906,7 @@ void LLIMSpeakerMgr::toggleAllowTextChat(const LLUUID& speaker_id) LLPointer speakerp = findSpeaker(speaker_id); if (!speakerp) return; - std::string url = gAgent.getRegion()->getCapability("ChatSessionRequest"); + std::string url = gAgent.getRegionCapability("ChatSessionRequest"); LLSD data; data["method"] = "mute update"; data["session-id"] = getSessionID(); @@ -940,7 +931,7 @@ void LLIMSpeakerMgr::moderateVoiceParticipant(const LLUUID& avatar_id, bool unmu // do not send voice moderation changes for avatars not in voice channel if (!is_in_voice) return; - std::string url = gAgent.getRegion()->getCapability("ChatSessionRequest"); + std::string url = gAgent.getRegionCapability("ChatSessionRequest"); LLSD data; data["method"] = "mute update"; data["session-id"] = getSessionID(); @@ -980,7 +971,7 @@ void LLIMSpeakerMgr::processSessionUpdate(const LLSD& session_update) void LLIMSpeakerMgr::moderateVoiceSession(const LLUUID& session_id, bool disallow_voice) { - std::string url = gAgent.getRegion()->getCapability("ChatSessionRequest"); + std::string url = gAgent.getRegionCapability("ChatSessionRequest"); LLSD data; data["method"] = "session update"; data["session-id"] = session_id; @@ -996,13 +987,13 @@ void LLIMSpeakerMgr::moderateVoiceSession(const LLUUID& session_id, bool disallo void LLIMSpeakerMgr::forceVoiceModeratedMode(bool should_be_muted) { - for (speaker_map_t::iterator speaker_it = mSpeakers.begin(); speaker_it != mSpeakers.end(); ++speaker_it) + for (auto& speaker : mSpeakers) { - LLUUID speaker_id = speaker_it->first; - LLSpeaker* speakerp = speaker_it->second; + LLUUID speaker_id = speaker.first; + LLSpeaker* speakerp = speaker.second; // participant does not match requested state - if (should_be_muted != (bool)speakerp->mModeratorMutedVoice) + if (should_be_muted != static_cast(speakerp->mModeratorMutedVoice)) { moderateVoiceParticipant(speaker_id, !should_be_muted); } @@ -1036,10 +1027,9 @@ void LLActiveSpeakerMgr::updateSpeakerList() LLSpeakerMgr::updateSpeakerList(); // clean up text only speakers - for (speaker_map_t::iterator speaker_it = mSpeakers.begin(); speaker_it != mSpeakers.end(); ++speaker_it) + for (auto& speaker : mSpeakers) { - LLUUID speaker_id = speaker_it->first; - LLSpeaker* speakerp = speaker_it->second; + LLSpeaker* speakerp = speaker.second; if (speakerp->mStatus == LLSpeaker::STATUS_TEXT_ONLY) { // automatically flag text only speakers for removal @@ -1085,10 +1075,10 @@ void LLLocalSpeakerMgr::updateSpeakerList() setSpeakers(speakers); // check if text only speakers have moved out of chat range - for (speaker_map_t::iterator speaker_it = mSpeakers.begin(); speaker_it != mSpeakers.end(); ++speaker_it) + for (auto& speaker : mSpeakers) { - LLUUID speaker_id = speaker_it->first; - LLPointer speakerp = speaker_it->second; + LLUUID speaker_id = speaker.first; + LLPointer speakerp = speaker.second; if (speakerp.notNull() && speakerp->mStatus == LLSpeaker::STATUS_TEXT_ONLY) { LLVOAvatar* avatarp = gObjectList.findAvatar(speaker_id); diff --git a/indra/newview/llspeakers.h b/indra/newview/llspeakers.h index 689ba336f..e28cd9a20 100644 --- a/indra/newview/llspeakers.h +++ b/indra/newview/llspeakers.h @@ -36,7 +36,7 @@ class LLSpeakerMgr; class LLVoiceChannel; // data for a given participant in a voice channel -class LLSpeaker : public LLRefCount, public LLOldEvents::LLObservable, public LLHandleProvider, public boost::signals2::trackable +class LLSpeaker final : public LLRefCount, public LLOldEvents::LLObservable, public LLHandleProvider, public boost::signals2::trackable { public: typedef enum e_speaker_type @@ -80,7 +80,7 @@ public: }; LLSpeaker(const speaker_entry_t& entry); - ~LLSpeaker() {}; + ~LLSpeaker() = default; void update(const speaker_entry_t& entry); void lookupName(); @@ -130,44 +130,44 @@ public: S32 mSortIndex; }; -class LLSpeakerUpdateSpeakerEvent : public LLOldEvents::LLEvent +class LLSpeakerUpdateSpeakerEvent final : public LLOldEvents::LLEvent { public: LLSpeakerUpdateSpeakerEvent(LLSpeaker* source); - /*virtual*/ LLSD getValue(); + /*virtual*/ LLSD getValue() override; private: const LLUUID& mSpeakerID; }; -class LLSpeakerUpdateModeratorEvent : public LLOldEvents::LLEvent +class LLSpeakerUpdateModeratorEvent final : public LLOldEvents::LLEvent { public: LLSpeakerUpdateModeratorEvent(LLSpeaker* source); - /*virtual*/ LLSD getValue(); + /*virtual*/ LLSD getValue() override; private: const LLUUID& mSpeakerID; BOOL mIsModerator; }; -class LLSpeakerTextModerationEvent : public LLOldEvents::LLEvent +class LLSpeakerTextModerationEvent final : public LLOldEvents::LLEvent { public: LLSpeakerTextModerationEvent(LLSpeaker* source); - /*virtual*/ LLSD getValue(); + /*virtual*/ LLSD getValue() override; }; -class LLSpeakerVoiceModerationEvent : public LLOldEvents::LLEvent +class LLSpeakerVoiceModerationEvent final : public LLOldEvents::LLEvent { public: LLSpeakerVoiceModerationEvent(LLSpeaker* source); - /*virtual*/ LLSD getValue(); + /*virtual*/ LLSD getValue() override; }; -class LLSpeakerListChangeEvent : public LLOldEvents::LLEvent +class LLSpeakerListChangeEvent final : public LLOldEvents::LLEvent { public: LLSpeakerListChangeEvent(LLSpeakerMgr* source, const LLUUID& speaker_id); - /*virtual*/ LLSD getValue(); + /*virtual*/ LLSD getValue() override; private: const LLUUID& mSpeakerID; @@ -183,7 +183,7 @@ private: * Otherwise it should be deleted manually in place where it is used. * If action callback is not set timer will tick only once and deleted. */ -class LLSpeakerActionTimer : public LLEventTimer +class LLSpeakerActionTimer final : public LLEventTimer { public: typedef std::function action_callback_t; @@ -200,14 +200,14 @@ public: * @param speaker_id - LLUUID of speaker which will be passed into action callback. */ LLSpeakerActionTimer(action_callback_t action_cb, F32 action_period, const LLUUID& speaker_id); - virtual ~LLSpeakerActionTimer() {}; + virtual ~LLSpeakerActionTimer() = default; /** * Implements timer "tick". * * If action callback is not specified returns true. Instance will be deleted by LLEventTimer::updateClass(). */ - virtual BOOL tick(); + BOOL tick() override; /** * Clears the callback. @@ -285,13 +285,13 @@ public: void setSpeakers(const std::vector& speakers); LLPointer setSpeaker(const speaker_entry_t& speakers); - BOOL isVoiceActive(); + BOOL isVoiceActive() const; typedef std::vector > speaker_list_t; void getSpeakerList(speaker_list_t* speaker_list, BOOL include_text); LLVoiceChannel* getVoiceChannel() { return mVoiceChannel; } - const LLUUID getSessionID(); - bool isSpeakerToBeRemoved(const LLUUID& speaker_id); + const LLUUID getSessionID() const; + bool isSpeakerToBeRemoved(const LLUUID& speaker_id) const; /** * Removes avaline speaker. @@ -310,7 +310,7 @@ public: protected: virtual void updateSpeakerList(); - void setSpeakerNotInChannel(LLSpeaker* speackerp); + void setSpeakerNotInChannel(LLPointer speackerp); bool removeSpeaker(const LLUUID& speaker_id); typedef std::map > speaker_map_t; @@ -336,7 +336,7 @@ protected: bool mModerateModeHandledFirstTime; }; -class LLIMSpeakerMgr : public LLSpeakerMgr +class LLIMSpeakerMgr final : public LLSpeakerMgr { LOG_CLASS(LLIMSpeakerMgr); @@ -376,7 +376,7 @@ public: void processSessionUpdate(const LLSD& session_update); protected: - virtual void updateSpeakerList(); + void updateSpeakerList() override; void moderateVoiceSession(const LLUUID& session_id, bool disallow_voice); @@ -387,24 +387,24 @@ protected: }; -class LLActiveSpeakerMgr : public LLSpeakerMgr, public LLSingleton +class LLActiveSpeakerMgr final : public LLSpeakerMgr, public LLSingleton { LOG_CLASS(LLActiveSpeakerMgr); public: LLActiveSpeakerMgr(); protected: - virtual void updateSpeakerList(); + void updateSpeakerList() override; }; -class LLLocalSpeakerMgr : public LLSpeakerMgr, public LLSingleton +class LLLocalSpeakerMgr final : public LLSpeakerMgr, public LLSingleton { LOG_CLASS(LLLocalSpeakerMgr); public: LLLocalSpeakerMgr(); ~LLLocalSpeakerMgr (); protected: - virtual void updateSpeakerList(); + void updateSpeakerList() override; }; #endif // LL_LLSPEAKERS_H