From f5492144ad07359bf57252081dadb5227aa90f5b Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Thu, 21 Mar 2019 22:01:13 -0400 Subject: [PATCH] Gesture Optimization Pass 2 --- indra/llcharacter/llmultigesture.cpp | 190 +++------- indra/llcharacter/llmultigesture.h | 80 ++-- indra/newview/llgesturemgr.cpp | 539 +++++++++++---------------- indra/newview/llgesturemgr.h | 39 +- 4 files changed, 338 insertions(+), 510 deletions(-) diff --git a/indra/llcharacter/llmultigesture.cpp b/indra/llcharacter/llmultigesture.cpp index 7fbb5c137..64de502b6 100644 --- a/indra/llcharacter/llmultigesture.cpp +++ b/indra/llcharacter/llmultigesture.cpp @@ -36,7 +36,7 @@ #include "lldatapacker.h" #include "llstl.h" -const S32 GESTURE_VERSION = 2; +constexpr S32 GESTURE_VERSION = 2; //--------------------------------------------------------------------------- // LLMultiGesture @@ -48,10 +48,10 @@ LLMultiGesture::LLMultiGesture() mTrigger(), mReplaceText(), mSteps(), - mPlaying(FALSE), + mPlaying(false), mLocal(false), mCurrentStep(0), - mDoneCallback(NULL) + mDoneCallback(nullptr) { reset(); } @@ -63,13 +63,13 @@ LLMultiGesture::~LLMultiGesture() void LLMultiGesture::reset() { - mPlaying = FALSE; + mPlaying = false; mLocal = false; mCurrentStep = 0; mWaitTimer.reset(); - mWaitingTimer = FALSE; - mWaitingAnimations = FALSE; - mWaitingAtEnd = FALSE; + mWaitingTimer = false; + mWaitingAnimations = false; + mWaitingAtEnd = false; mRequestedAnimIDs.clear(); mPlayingAnimIDs.clear(); } @@ -88,10 +88,8 @@ S32 LLMultiGesture::getMaxSerialSize() const max_size += 64; // step count S32 - std::vector::const_iterator it; - for (it = mSteps.begin(); it != mSteps.end(); ++it) + for (const auto& step : mSteps) { - LLGestureStep* step = *it; max_size += 64; // type S32 max_size += step->getMaxSerialSize(); } @@ -104,10 +102,8 @@ S32 LLMultiGesture::getMaxSerialSize() const max_size += sizeof(S32); // step count - std::vector::const_iterator it; - for (it = mSteps.begin(); it != mSteps.end(); ++it) + for (const auto& step : mSteps) { - LLGestureStep* step = *it; max_size += sizeof(S32); // type max_size += step->getMaxSerialSize(); } @@ -116,7 +112,7 @@ S32 LLMultiGesture::getMaxSerialSize() const return max_size; } -BOOL LLMultiGesture::serialize(LLDataPacker& dp) const +bool LLMultiGesture::serialize(LLDataPacker& dp) const { dp.packS32(GESTURE_VERSION, "version"); dp.packU8(mKey, "key"); @@ -126,22 +122,18 @@ BOOL LLMultiGesture::serialize(LLDataPacker& dp) const S32 count = (S32)mSteps.size(); dp.packS32(count, "step_count"); - S32 i; - for (i = 0; i < count; ++i) + for (const auto& step : mSteps) { - LLGestureStep* step = mSteps[i]; - dp.packS32(step->getType(), "step_type"); - BOOL ok = step->serialize(dp); - if (!ok) + if (!step->serialize(dp)) { - return FALSE; + return false; } } - return TRUE; + return true; } -BOOL LLMultiGesture::deserialize(LLDataPacker& dp) +bool LLMultiGesture::deserialize(LLDataPacker& dp) { S32 version; dp.unpackS32(version, "version"); @@ -150,15 +142,12 @@ BOOL LLMultiGesture::deserialize(LLDataPacker& dp) LL_WARNS() << "Bad LLMultiGesture version " << version << " should be " << GESTURE_VERSION << LL_ENDL; - return FALSE; + return false; } dp.unpackU8(mKey, "key"); dp.unpackU32(mMask, "mask"); - - dp.unpackString(mTrigger, "trigger"); - dp.unpackString(mReplaceText, "replace"); S32 count; @@ -166,58 +155,31 @@ BOOL LLMultiGesture::deserialize(LLDataPacker& dp) if (count < 0) { LL_WARNS() << "Bad LLMultiGesture step count " << count << LL_ENDL; - return FALSE; + return false; } - S32 i; - for (i = 0; i < count; ++i) + std::unique_ptr step; + for (S32 i = 0; i < count; ++i) { S32 type; dp.unpackS32(type, "step_type"); - EStepType step_type = (EStepType)type; - switch(step_type) + switch((EStepType)type) { - case STEP_ANIMATION: - { - std::unique_ptr step(new LLGestureStepAnimation()); - BOOL ok = step->deserialize(dp); - if (!ok) return FALSE; - mSteps.push_back(step.release()); - break; - } - case STEP_SOUND: - { - std::unique_ptr step(new LLGestureStepSound()); - BOOL ok = step->deserialize(dp); - if (!ok) return FALSE; - mSteps.push_back(step.release()); - break; - } - case STEP_CHAT: - { - std::unique_ptr step(new LLGestureStepChat()); - BOOL ok = step->deserialize(dp); - if (!ok) return FALSE; - mSteps.push_back(step.release()); - break; - } - case STEP_WAIT: - { - std::unique_ptr step(new LLGestureStepWait()); - BOOL ok = step->deserialize(dp); - if (!ok) return FALSE; - mSteps.push_back(step.release()); - break; - } + case STEP_ANIMATION: step.reset(new LLGestureStepAnimation); break; + case STEP_SOUND: step.reset(new LLGestureStepSound); break; + case STEP_CHAT: step.reset(new LLGestureStepChat); break; + case STEP_WAIT: step.reset(new LLGestureStepWait); break; default: { LL_WARNS() << "Bad LLMultiGesture step type " << type << LL_ENDL; - return FALSE; + return false; } } + if (!step->deserialize(dp)) return false; + mSteps.push_back(step.release()); } - return TRUE; + return true; } void LLMultiGesture::dump() @@ -226,10 +188,8 @@ void LLMultiGesture::dump() << " trigger " << mTrigger << " replace " << mReplaceText << LL_ENDL; - U32 i; - for (i = 0; i < mSteps.size(); ++i) + for (const auto& step : mSteps) { - LLGestureStep* step = mSteps[i]; step->dump(); } } @@ -264,21 +224,21 @@ S32 LLGestureStepAnimation::getMaxSerialSize() const return max_size; } -BOOL LLGestureStepAnimation::serialize(LLDataPacker& dp) const +bool LLGestureStepAnimation::serialize(LLDataPacker& dp) const { dp.packString(mAnimName, "anim_name"); dp.packUUID(mAnimAssetID, "asset_id"); dp.packU32(mFlags, "flags"); - return TRUE; + return true; } -BOOL LLGestureStepAnimation::deserialize(LLDataPacker& dp) +bool LLGestureStepAnimation::deserialize(LLDataPacker& dp) { dp.unpackString(mAnimName, "anim_name"); // Apparently an earlier version of the gesture code added \r to the end // of the animation names. Get rid of it. JC - if (!mAnimName.empty() && mAnimName[mAnimName.length() - 1] == '\r') + if (!mAnimName.empty() && mAnimName.back() == '\r') { // chop the last character mAnimName.resize(mAnimName.length() - 1); @@ -286,29 +246,18 @@ BOOL LLGestureStepAnimation::deserialize(LLDataPacker& dp) dp.unpackUUID(mAnimAssetID, "asset_id"); dp.unpackU32(mFlags, "flags"); - return TRUE; + return true; } // *NOTE: result is translated in LLPreviewGesture::getLabel() std::vector LLGestureStepAnimation::getLabel() const { - std::vector strings; - -// std::string label; +/* std::string label; if (mFlags & ANIM_FLAG_STOP) - { - strings.push_back( "AnimFlagStop"); - -// label = "Stop Animation: "; - } + label = "Stop Animation: "; else - { - strings.push_back( "AnimFlagStart"); - -// label = "Start Animation: "; - } - strings.push_back( mAnimName); -// label += mAnimName; - return strings; + label = "Start Animation: "; + label += mAnimName;*/ + return {mFlags & ANIM_FLAG_STOP ? "AnimFlagStop" : "AnimFlagStart", mAnimName}; } void LLGestureStepAnimation::dump() @@ -346,31 +295,28 @@ S32 LLGestureStepSound::getMaxSerialSize() const return max_size; } -BOOL LLGestureStepSound::serialize(LLDataPacker& dp) const +bool LLGestureStepSound::serialize(LLDataPacker& dp) const { dp.packString(mSoundName, "sound_name"); dp.packUUID(mSoundAssetID, "asset_id"); dp.packU32(mFlags, "flags"); - return TRUE; + return true; } -BOOL LLGestureStepSound::deserialize(LLDataPacker& dp) +bool LLGestureStepSound::deserialize(LLDataPacker& dp) { dp.unpackString(mSoundName, "sound_name"); dp.unpackUUID(mSoundAssetID, "asset_id"); dp.unpackU32(mFlags, "flags"); - return TRUE; + return true; } // *NOTE: result is translated in LLPreviewGesture::getLabel() std::vector LLGestureStepSound::getLabel() const { - std::vector strings; - strings.push_back( "Sound"); - strings.push_back( mSoundName); // std::string label("Sound: "); // label += mSoundName; - return strings; + return {"Sound", mSoundName}; } void LLGestureStepSound::dump() @@ -406,27 +352,23 @@ S32 LLGestureStepChat::getMaxSerialSize() const return max_size; } -BOOL LLGestureStepChat::serialize(LLDataPacker& dp) const +bool LLGestureStepChat::serialize(LLDataPacker& dp) const { dp.packString(mChatText, "chat_text"); dp.packU32(mFlags, "flags"); - return TRUE; + return true; } -BOOL LLGestureStepChat::deserialize(LLDataPacker& dp) +bool LLGestureStepChat::deserialize(LLDataPacker& dp) { dp.unpackString(mChatText, "chat_text"); - dp.unpackU32(mFlags, "flags"); - return TRUE; + return true; } // *NOTE: result is translated in LLPreviewGesture::getLabel() std::vector LLGestureStepChat::getLabel() const { - std::vector strings; - strings.push_back("Chat"); - strings.push_back(mChatText); - return strings; + return {"Chat", mChatText}; } void LLGestureStepChat::dump() @@ -461,44 +403,26 @@ S32 LLGestureStepWait::getMaxSerialSize() const return max_size; } -BOOL LLGestureStepWait::serialize(LLDataPacker& dp) const +bool LLGestureStepWait::serialize(LLDataPacker& dp) const { dp.packF32(mWaitSeconds, "wait_seconds"); dp.packU32(mFlags, "flags"); - return TRUE; + return true; } -BOOL LLGestureStepWait::deserialize(LLDataPacker& dp) +bool LLGestureStepWait::deserialize(LLDataPacker& dp) { dp.unpackF32(mWaitSeconds, "wait_seconds"); dp.unpackU32(mFlags, "flags"); - return TRUE; + return true; } // *NOTE: result is translated in LLPreviewGesture::getLabel() std::vector LLGestureStepWait::getLabel() const { - std::vector strings; - strings.push_back( "Wait" ); - -// std::string label("--- Wait: "); - if (mFlags & WAIT_FLAG_TIME) - { - char buffer[64]; /* Flawfinder: ignore */ - snprintf(buffer, sizeof(buffer), "%.1f seconds", (double)mWaitSeconds); /* Flawfinder: ignore */ - strings.push_back(buffer); -// label += buffer; - } - else if (mFlags & WAIT_FLAG_ALL_ANIM) - { - strings.push_back("until animations are done"); - // label += "until animations are done"; - } - else - { - strings.push_back(""); - } - - return strings; + return {"Wait", + mFlags & WAIT_FLAG_TIME ? llformat("%.1f seconds", mWaitSeconds) + : mFlags & WAIT_FLAG_ALL_ANIM ? "until animations are done" + : LLStringUtil::null}; } diff --git a/indra/llcharacter/llmultigesture.h b/indra/llcharacter/llmultigesture.h index 8e4821357..e7a5fda15 100644 --- a/indra/llcharacter/llmultigesture.h +++ b/indra/llcharacter/llmultigesture.h @@ -27,7 +27,7 @@ #ifndef LL_LLMULTIGESTURE_H #define LL_LLMULTIGESTURE_H -#include +#include #include #include @@ -46,8 +46,8 @@ public: // Maximum number of bytes this could hold once serialized. S32 getMaxSerialSize() const; - BOOL serialize(LLDataPacker& dp) const; - BOOL deserialize(LLDataPacker& dp); + bool serialize(LLDataPacker& dp) const; + bool deserialize(LLDataPacker& dp); void dump(); @@ -77,7 +77,7 @@ public: std::vector mSteps; // Is the gesture currently playing? - BOOL mPlaying; + bool mPlaying; // Is the gesture to be played locally? bool mLocal; @@ -86,25 +86,25 @@ public: S32 mCurrentStep; // We're waiting for triggered animations to stop playing - BOOL mWaitingAnimations; + bool mWaitingAnimations; // We're waiting a fixed amount of time - BOOL mWaitingTimer; + bool mWaitingTimer; // Waiting after the last step played for all animations to complete - BOOL mWaitingAtEnd; + bool mWaitingAtEnd; // Timer for waiting LLFrameTimer mWaitTimer; - boost::function mDoneCallback; + std::function mDoneCallback; // Animations that we requested to start - std::set mRequestedAnimIDs; + std::unordered_set mRequestedAnimIDs; // Once the animation starts playing (sim says to start playing) // the ID is moved from mRequestedAnimIDs to here. - std::set mPlayingAnimIDs; + std::unordered_set mPlayingAnimIDs; }; @@ -127,14 +127,14 @@ public: LLGestureStep() {} virtual ~LLGestureStep() {} - virtual EStepType getType() = 0; + virtual EStepType getType() const = 0; // Return a user-readable label for this step virtual std::vector getLabel() const = 0; virtual S32 getMaxSerialSize() const = 0; - virtual BOOL serialize(LLDataPacker& dp) const = 0; - virtual BOOL deserialize(LLDataPacker& dp) = 0; + virtual bool serialize(LLDataPacker& dp) const = 0; + virtual bool deserialize(LLDataPacker& dp) = 0; virtual void dump() = 0; }; @@ -142,7 +142,7 @@ public: // By default, animation steps start animations. // If the least significant bit is 1, it will stop animations. -const U32 ANIM_FLAG_STOP = 0x01; +constexpr U32 ANIM_FLAG_STOP = 0x01; class LLGestureStepAnimation : public LLGestureStep { @@ -150,15 +150,15 @@ public: LLGestureStepAnimation(); virtual ~LLGestureStepAnimation(); - virtual EStepType getType() { return STEP_ANIMATION; } + EStepType getType() const override { return STEP_ANIMATION; } - virtual std::vector getLabel() const; + std::vector getLabel() const override; - virtual S32 getMaxSerialSize() const; - virtual BOOL serialize(LLDataPacker& dp) const; - virtual BOOL deserialize(LLDataPacker& dp); + S32 getMaxSerialSize() const override; + bool serialize(LLDataPacker& dp) const override; + bool deserialize(LLDataPacker& dp) override; - virtual void dump(); + void dump() override; public: std::string mAnimName; @@ -173,15 +173,15 @@ public: LLGestureStepSound(); virtual ~LLGestureStepSound(); - virtual EStepType getType() { return STEP_SOUND; } + EStepType getType() const override { return STEP_SOUND; } - virtual std::vector getLabel() const; + std::vector getLabel() const override; - virtual S32 getMaxSerialSize() const; - virtual BOOL serialize(LLDataPacker& dp) const; - virtual BOOL deserialize(LLDataPacker& dp); + S32 getMaxSerialSize() const override; + bool serialize(LLDataPacker& dp) const override; + bool deserialize(LLDataPacker& dp) override; - virtual void dump(); + void dump() override; public: std::string mSoundName; @@ -196,15 +196,15 @@ public: LLGestureStepChat(); virtual ~LLGestureStepChat(); - virtual EStepType getType() { return STEP_CHAT; } + EStepType getType() const override { return STEP_CHAT; } - virtual std::vector getLabel() const; + std::vector getLabel() const override; - virtual S32 getMaxSerialSize() const; - virtual BOOL serialize(LLDataPacker& dp) const; - virtual BOOL deserialize(LLDataPacker& dp); + S32 getMaxSerialSize() const override; + bool serialize(LLDataPacker& dp) const override; + bool deserialize(LLDataPacker& dp) override; - virtual void dump(); + void dump() override; public: std::string mChatText; @@ -212,8 +212,8 @@ public: }; -const U32 WAIT_FLAG_TIME = 0x01; -const U32 WAIT_FLAG_ALL_ANIM = 0x02; +constexpr U32 WAIT_FLAG_TIME = 0x01; +constexpr U32 WAIT_FLAG_ALL_ANIM = 0x02; class LLGestureStepWait : public LLGestureStep { @@ -221,15 +221,15 @@ public: LLGestureStepWait(); virtual ~LLGestureStepWait(); - virtual EStepType getType() { return STEP_WAIT; } + EStepType getType() const override { return STEP_WAIT; } - virtual std::vector getLabel() const; + std::vector getLabel() const override; - virtual S32 getMaxSerialSize() const; - virtual BOOL serialize(LLDataPacker& dp) const; - virtual BOOL deserialize(LLDataPacker& dp); + S32 getMaxSerialSize() const override; + bool serialize(LLDataPacker& dp) const override; + bool deserialize(LLDataPacker& dp) override; - virtual void dump(); + void dump() override; public: F32 mWaitSeconds; diff --git a/indra/newview/llgesturemgr.cpp b/indra/newview/llgesturemgr.cpp index 1d821e3f8..22eaccd1a 100644 --- a/indra/newview/llgesturemgr.cpp +++ b/indra/newview/llgesturemgr.cpp @@ -69,7 +69,7 @@ const F32 MAX_WAIT_ANIM_SECS = 30.f; // Lightweight constructor. // init() does the heavy lifting. LLGestureMgr::LLGestureMgr() -: mValid(FALSE), +: mValid(false), mPlaying(), mActive(), mLoadingCount(0) @@ -87,7 +87,7 @@ LLGestureMgr::~LLGestureMgr() LLMultiGesture* gesture = (*it).second; delete gesture; - gesture = NULL; + gesture = nullptr; } gInventory.removeObserver(this); } @@ -148,86 +148,64 @@ void LLGestureMgr::activateGesture(const LLUUID& item_id) mLoadingCount = 1; mDeactivateSimilarNames.clear(); - const BOOL inform_server = TRUE; - const BOOL deactivate_similar = FALSE; + const bool inform_server = true; + const bool deactivate_similar = false; activateGestureWithAsset(item_id, asset_id, inform_server, deactivate_similar); } void LLGestureMgr::activateGestures(LLViewerInventoryItem::item_array_t& items) { - // Load up the assets - S32 count = 0; - LLViewerInventoryItem::item_array_t::const_iterator it; - for (it = items.begin(); it != items.end(); ++it) - { - LLViewerInventoryItem* item = *it; - - if (isGestureActive(item->getUUID())) - { - continue; - } - else - { // Make gesture active and persistent through login sessions. -Aura 07-12-06 - activateGesture(item->getUUID()); - } - - count++; - } - - mLoadingCount = count; mDeactivateSimilarNames.clear(); - for (it = items.begin(); it != items.end(); ++it) - { - LLViewerInventoryItem* item = *it; - - if (isGestureActive(item->getUUID())) - { - continue; - } - - // Don't inform server, we'll do that in bulk - const BOOL no_inform_server = FALSE; - const BOOL deactivate_similar = TRUE; - activateGestureWithAsset(item->getUUID(), item->getAssetUUID(), - no_inform_server, - deactivate_similar); - } + // Load up the assets + mLoadingCount = 0; // Inform the database of this change LLMessageSystem* msg = gMessageSystem; + bool start_message = true; - BOOL start_message = TRUE; - - for (it = items.begin(); it != items.end(); ++it) + for (const auto& item : items) { - LLViewerInventoryItem* item = *it; - - if (isGestureActive(item->getUUID())) + const auto& id = item->getUUID(); + if (isGestureActive(id)) { continue; } + // Make gesture active and persistent through login sessions. -Aura 07-12-06 + activateGesture(id); + + ++mLoadingCount; + + const auto& asset_id = item->getAssetUUID(); + + // Don't inform server, we'll do that in bulk + const bool no_inform_server = false; + const bool deactivate_similar = true; + activateGestureWithAsset(id, asset_id, + no_inform_server, + deactivate_similar); + if (start_message) { msg->newMessage("ActivateGestures"); msg->nextBlock("AgentData"); - msg->addUUID("AgentID", gAgent.getID()); + msg->addUUID("AgentID", gAgentID); msg->addUUID("SessionID", gAgent.getSessionID()); msg->addU32("Flags", 0x0); - start_message = FALSE; + start_message = false; } msg->nextBlock("Data"); - msg->addUUID("ItemID", item->getUUID()); - msg->addUUID("AssetID", item->getAssetUUID()); + msg->addUUID("ItemID", id); + msg->addUUID("AssetID", asset_id); msg->addU32("GestureFlags", 0x0); if (msg->getCurrentSendTotal() > MTUBYTES) { gAgent.sendReliableMessage(); - start_message = TRUE; + start_message = true; } } @@ -241,8 +219,8 @@ void LLGestureMgr::activateGestures(LLViewerInventoryItem::item_array_t& items) struct LLLoadInfo { LLUUID mItemID; - BOOL mInformServer; - BOOL mDeactivateSimilar; + bool mInformServer; + bool mDeactivateSimilar; }; // If inform_server is true, will send a message upstream to update @@ -252,8 +230,8 @@ struct LLLoadInfo */ void LLGestureMgr::activateGestureWithAsset(const LLUUID& item_id, const LLUUID& asset_id, - BOOL inform_server, - BOOL deactivate_similar) + bool inform_server, + bool deactivate_similar) { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); @@ -275,9 +253,9 @@ void LLGestureMgr::activateGestureWithAsset(const LLUUID& item_id, // return; // } - // For now, put NULL into the item map. We'll build a gesture + // For now, put nullptr into the item map. We'll build a gesture // class object when the asset data arrives. - mActive[base_item_id] = NULL; + mActive[base_item_id] = nullptr; // Copy the UUID if (asset_id.notNull()) @@ -287,7 +265,7 @@ void LLGestureMgr::activateGestureWithAsset(const LLUUID& item_id, info->mInformServer = inform_server; info->mDeactivateSimilar = deactivate_similar; - const BOOL high_priority = TRUE; + const bool high_priority = true; gAssetStorage->getAssetData(asset_id, LLAssetType::AT_GESTURE, onLoadComplete, @@ -304,7 +282,7 @@ void LLGestureMgr::activateGestureWithAsset(const LLUUID& item_id, void LLGestureMgr::deactivateGesture(const LLUUID& item_id) { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); - item_map_t::iterator it = mActive.find(base_item_id); + const auto& it = mActive.find(base_item_id); if (it == mActive.end()) { LL_WARNS() << "deactivateGesture for inactive gesture " << base_item_id << LL_ENDL; @@ -314,13 +292,13 @@ void LLGestureMgr::deactivateGesture(const LLUUID& item_id) // mActive owns this gesture pointer, so clean up memory. LLMultiGesture* gesture = (*it).second; - // Can be NULL gestures in the map + // Can be nullptr gestures in the map if (gesture) { stopGesture(gesture); delete gesture; - gesture = NULL; + gesture = nullptr; } mActive.erase(it); @@ -330,7 +308,7 @@ void LLGestureMgr::deactivateGesture(const LLUUID& item_id) LLMessageSystem* msg = gMessageSystem; msg->newMessage("DeactivateGestures"); msg->nextBlock("AgentData"); - msg->addUUID("AgentID", gAgent.getID()); + msg->addUUID("AgentID", gAgentID); msg->addUUID("SessionID", gAgent.getSessionID()); msg->addU32("Flags", 0x0); @@ -346,14 +324,16 @@ void LLGestureMgr::deactivateGesture(const LLUUID& item_id) } -void LLGestureMgr::deactivateSimilarGestures(LLMultiGesture* in, const LLUUID& in_item_id) +void LLGestureMgr::deactivateSimilarGestures(const LLMultiGesture* in, const LLUUID& in_item_id) { const LLUUID& base_in_item_id = gInventory.getLinkedItemID(in_item_id); - uuid_vec_t gest_item_ids; + + // Inform database of the change + LLMessageSystem* msg = gMessageSystem; + bool start_message = true; // Deactivate all gestures that match - item_map_t::iterator it; - for (it = mActive.begin(); it != mActive.end(); ) + for (auto& it = mActive.begin(); it != mActive.end(); ) { const LLUUID& item_id = (*it).first; LLMultiGesture* gest = (*it).second; @@ -368,16 +348,37 @@ void LLGestureMgr::deactivateSimilarGestures(LLMultiGesture* in, const LLUUID& i else if ((!gest->mTrigger.empty() && gest->mTrigger == in->mTrigger) || (gest->mKey != KEY_NONE && gest->mKey == in->mKey && gest->mMask == in->mMask)) { - gest_item_ids.push_back(item_id); - stopGesture(gest); delete gest; - gest = NULL; + gest = nullptr; - mActive.erase(it++); + it = mActive.erase(it); gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id); + if (start_message) + { + msg->newMessage("DeactivateGestures"); + msg->nextBlock("AgentData"); + msg->addUUID("AgentID", gAgentID); + msg->addUUID("SessionID", gAgent.getSessionID()); + msg->addU32("Flags", 0x0); + start_message = false; + } + + msg->nextBlock("Data"); + msg->addUUID("ItemID", item_id); + msg->addU32("GestureFlags", 0x0); + + if (msg->getCurrentSendTotal() > MTUBYTES) + { + gAgent.sendReliableMessage(); + start_message = true; + } + + // Add to the list of names for the user. + if (const auto& item = gInventory.getItem(item_id)) + mDeactivateSimilarNames += item->getName() + '\n'; } else { @@ -385,88 +386,45 @@ void LLGestureMgr::deactivateSimilarGestures(LLMultiGesture* in, const LLUUID& i } } - // Inform database of the change - LLMessageSystem* msg = gMessageSystem; - BOOL start_message = TRUE; - uuid_vec_t::const_iterator vit = gest_item_ids.begin(); - while (vit != gest_item_ids.end()) - { - if (start_message) - { - msg->newMessage("DeactivateGestures"); - msg->nextBlock("AgentData"); - msg->addUUID("AgentID", gAgent.getID()); - msg->addUUID("SessionID", gAgent.getSessionID()); - msg->addU32("Flags", 0x0); - start_message = FALSE; - } - - msg->nextBlock("Data"); - msg->addUUID("ItemID", *vit); - msg->addU32("GestureFlags", 0x0); - - if (msg->getCurrentSendTotal() > MTUBYTES) - { - gAgent.sendReliableMessage(); - start_message = TRUE; - } - - ++vit; - } - if (!start_message) { gAgent.sendReliableMessage(); } - // Add to the list of names for the user. - for (vit = gest_item_ids.begin(); vit != gest_item_ids.end(); ++vit) - { - LLViewerInventoryItem* item = gInventory.getItem(*vit); - if (!item) continue; - - mDeactivateSimilarNames.append(item->getName()); - mDeactivateSimilarNames.append("\n"); - } - + // *TODO: We call notify observers in stopGesture above, should we pass a flag to only do that here? notifyObservers(); } -BOOL LLGestureMgr::isGestureActive(const LLUUID& item_id) +bool LLGestureMgr::isGestureActive(const LLUUID& item_id) const { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); - item_map_t::iterator it = mActive.find(base_item_id); + const auto& it = mActive.find(base_item_id); return (it != mActive.end()); } -BOOL LLGestureMgr::isGesturePlaying(const LLUUID& item_id) +bool LLGestureMgr::isGesturePlaying(const LLUUID& item_id) const { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); - item_map_t::iterator it = mActive.find(base_item_id); - if (it == mActive.end()) return FALSE; + const auto& it = mActive.find(base_item_id); + if (it == mActive.end()) return false; - LLMultiGesture* gesture = (*it).second; - if (!gesture) return FALSE; + const LLMultiGesture* gesture = (*it).second; + if (!gesture) return false; return gesture->mPlaying; } -BOOL LLGestureMgr::isGesturePlaying(LLMultiGesture* gesture) +bool LLGestureMgr::isGesturePlaying(const LLMultiGesture* gesture) const { - if(!gesture) - { - return FALSE; - } - - return gesture->mPlaying; + return gesture && gesture->mPlaying; } void LLGestureMgr::replaceGesture(const LLUUID& item_id, LLMultiGesture* new_gesture, const LLUUID& asset_id) { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); - item_map_t::iterator it = mActive.find(base_item_id); + const auto& it = mActive.find(base_item_id); if (it == mActive.end()) { LL_WARNS() << "replaceGesture for inactive gesture " << base_item_id << LL_ENDL; @@ -481,7 +439,7 @@ void LLGestureMgr::replaceGesture(const LLUUID& item_id, LLMultiGesture* new_ges mActive[base_item_id] = new_gesture; delete old_gesture; - old_gesture = NULL; + old_gesture = nullptr; if (asset_id.notNull()) { @@ -490,10 +448,10 @@ void LLGestureMgr::replaceGesture(const LLUUID& item_id, LLMultiGesture* new_ges LLLoadInfo* info = new LLLoadInfo; info->mItemID = base_item_id; - info->mInformServer = TRUE; - info->mDeactivateSimilar = FALSE; + info->mInformServer = true; + info->mDeactivateSimilar = false; - const BOOL high_priority = TRUE; + const bool high_priority = true; gAssetStorage->getAssetData(asset_id, LLAssetType::AT_GESTURE, onLoadComplete, @@ -508,7 +466,7 @@ void LLGestureMgr::replaceGesture(const LLUUID& item_id, const LLUUID& new_asset { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); - item_map_t::iterator it = LLGestureMgr::instance().mActive.find(base_item_id); + auto it = LLGestureMgr::instance().mActive.find(base_item_id); if (it == mActive.end()) { LL_WARNS() << "replaceGesture for inactive gesture " << base_item_id << LL_ENDL; @@ -528,7 +486,7 @@ void LLGestureMgr::playGesture(LLMultiGesture* gesture, bool local) gesture->mCurrentStep = 0; // Add to list of playing - gesture->mPlaying = TRUE; + gesture->mPlaying = true; gesture->mLocal = local; mPlaying.push_back(gesture); @@ -565,7 +523,7 @@ void LLGestureMgr::playGesture(LLMultiGesture* gesture, bool local) LLAssetType::AT_ANIMATION, onAssetLoadComplete, (void *)id, - TRUE); + true); } break; } @@ -581,8 +539,8 @@ void LLGestureMgr::playGesture(LLMultiGesture* gesture, bool local) gAssetStorage->getAssetData(sound_id, LLAssetType::AT_SOUND, onAssetLoadComplete, - NULL, - TRUE); + nullptr, + true); } break; } @@ -624,12 +582,12 @@ void LLGestureMgr::playGesture(const LLUUID& item_id, bool local) // Iterates through space delimited tokens in string, triggering any gestures found. // Generates a revised string that has the found tokens replaced by their replacement strings // and (as a minor side effect) has multiple spaces in a row replaced by single spaces. -BOOL LLGestureMgr::triggerAndReviseString(const std::string &utf8str, std::string* revised_string) +bool LLGestureMgr::triggerAndReviseString(const std::string &utf8str, std::string* revised_string) { std::string tokenized = utf8str; - BOOL found_gestures = FALSE; - BOOL first_token = TRUE; + bool found_gestures = false; + bool first_token = true; typedef boost::tokenizer > tokenizer; boost::char_separator sep(" "); @@ -639,17 +597,16 @@ BOOL LLGestureMgr::triggerAndReviseString(const std::string &utf8str, std::strin for( token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter) { const char* cur_token = token_iter->c_str(); - LLMultiGesture* gesture = NULL; + LLMultiGesture* gesture = nullptr; // Only pay attention to the first gesture in the string. if( !found_gestures ) { // collect gestures that match std::vector matching; - item_map_t::iterator it; - for (it = mActive.begin(); it != mActive.end(); ++it) + for (const auto& pair : mActive) { - gesture = (*it).second; + gesture = pair.second; // Gesture asset data might not have arrived yet if (!gesture) continue; @@ -659,7 +616,7 @@ BOOL LLGestureMgr::triggerAndReviseString(const std::string &utf8str, std::strin matching.push_back(gesture); } - gesture = NULL; + gesture = nullptr; } @@ -673,59 +630,43 @@ BOOL LLGestureMgr::triggerAndReviseString(const std::string &utf8str, std::strin playGesture(gesture); - if (!gesture->mReplaceText.empty()) + if (revised_string && !gesture->mReplaceText.empty()) { - if( !first_token ) - { - if (revised_string) - revised_string->append( " " ); - } + if (!first_token) revised_string->push_back(' '); // Don't muck with the user's capitalization if we don't have to. - if( LLStringUtil::compareInsensitive(cur_token, gesture->mReplaceText) == 0) - { - if (revised_string) - revised_string->append( cur_token ); - } - else - { - if (revised_string) - revised_string->append( gesture->mReplaceText ); - } + revised_string->append(LLStringUtil::compareInsensitive(cur_token, gesture->mReplaceText) == 0 ? + cur_token : gesture->mReplaceText); } - found_gestures = TRUE; + found_gestures = true; } } } - if(!gesture) + if (!gesture && revised_string) { // This token doesn't match a gesture. Pass it through to the output. - if( !first_token ) - { - if (revised_string) - revised_string->append( " " ); - } - if (revised_string) - revised_string->append( cur_token ); + if (!first_token) revised_string->push_back(' '); + revised_string->append(cur_token); } - first_token = FALSE; - gesture = NULL; + first_token = false; + gesture = nullptr; } return found_gestures; } -BOOL LLGestureMgr::triggerGesture(KEY key, MASK mask) +bool LLGestureMgr::triggerGesture(KEY key, MASK mask) { - std::vector matching; - item_map_t::iterator it; + if (mActive.empty()) return false; + + std::vector matching; // collect matching gestures - for (it = mActive.begin(); it != mActive.end(); ++it) + for (const auto& pair : mActive) { - LLMultiGesture* gesture = (*it).second; + LLMultiGesture* gesture = pair.second; // asset data might not have arrived yet if (!gesture) continue; @@ -738,16 +679,13 @@ BOOL LLGestureMgr::triggerGesture(KEY key, MASK mask) } // choose one and play it - if (matching.size() > 0) + const auto& count = matching.size(); + if (count > 0) { - U32 random = ll_rand(matching.size()); - - LLMultiGesture* gesture = matching[random]; - - playGesture(gesture); - return TRUE; + playGesture(matching[ll_rand(count)]); + return true; } - return FALSE; + return false; } @@ -761,49 +699,38 @@ struct IsGesturePlaying : public std::unary_function { bool operator()(const LLMultiGesture* gesture) const { - return gesture->mPlaying ? true : false; + return gesture->mPlaying; } }; void LLGestureMgr::update() { - S32 i; - for (i = 0; i < (S32)mPlaying.size(); ++i) + bool notify = false; + for (auto& it = mPlaying.begin(); it != mPlaying.end();) { - stepGesture(mPlaying[i]); - } - - // Clear out gestures that are done, by moving all the - // ones that are still playing to the front. - std::vector::iterator new_end; - new_end = std::partition(mPlaying.begin(), - mPlaying.end(), - IsGesturePlaying()); - - // Something finished playing - if (new_end != mPlaying.end()) - { - // Delete the completed gestures that want deletion - std::vector::iterator it; - for (it = new_end; it != mPlaying.end(); ++it) + auto& gesture = *it; + stepGesture(gesture); + if (!gesture->mPlaying) { - LLMultiGesture* gesture = *it; - + // Delete the completed gestures that want deletion if (gesture->mDoneCallback) { gesture->mDoneCallback(gesture); // callback might have deleted gesture, can't // rely on this pointer any more - gesture = NULL; + gesture = nullptr; } + + // And take done gesture out of the playing list + it = mPlaying.erase(it); + notify = true; } - - // And take done gestures out of the playing list - mPlaying.erase(new_end, mPlaying.end()); - - notifyObservers(); + else ++it; } + + // Something finished playing + if (notify) notifyObservers(); } @@ -818,22 +745,21 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) // Of the ones that started playing, have any stopped? - std::set::iterator gest_it; - for (gest_it = gesture->mPlayingAnimIDs.begin(); - gest_it != gesture->mPlayingAnimIDs.end(); - ) + const auto& signaled(gAgentAvatarp->mSignaledAnimations); + const auto& signaled_end(signaled.end()); + for (auto gest_it = gesture->mPlayingAnimIDs.begin(), end = gesture->mPlayingAnimIDs.end(); gest_it != end;) { if (gesture->mLocal) { // Local, erase if no longer playing (or gone) LLMotion* motion = gAgentAvatarp->findMotion(*gest_it); if (!motion || motion->isStopped()) - gesture->mPlayingAnimIDs.erase(gest_it); - ++gest_it; + gest_it = gesture->mPlayingAnimIDs.erase(gest_it); + else ++gest_it; } // look in signaled animations (simulator's view of what is // currently playing. - else if (gAgentAvatarp->mSignaledAnimations.find(*gest_it) != gAgentAvatarp->mSignaledAnimations.end()) + else if (signaled.find(*gest_it) != signaled_end) { ++gest_it; } @@ -841,23 +767,20 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) { // not found, so not currently playing or scheduled to play // delete from the triggered set - gesture->mPlayingAnimIDs.erase(gest_it++); + gest_it = gesture->mPlayingAnimIDs.erase(gest_it); } } // Of all the animations that we asked the sim to start for us, // pick up the ones that have actually started. - for (gest_it = gesture->mRequestedAnimIDs.begin(); - gest_it != gesture->mRequestedAnimIDs.end(); - ) + for (auto gest_it = gesture->mRequestedAnimIDs.begin(), end = gesture->mRequestedAnimIDs.end(); gest_it != end;) { - LLVOAvatar::AnimIterator play_it = gAgentAvatarp->mSignaledAnimations.find(*gest_it); - if (play_it != gAgentAvatarp->mSignaledAnimations.end()) + if (signaled.find(*gest_it) != signaled_end) { // Hooray, this animation has started playing! // Copy into playing. gesture->mPlayingAnimIDs.insert(*gest_it); - gesture->mRequestedAnimIDs.erase(gest_it++); + gest_it = gesture->mRequestedAnimIDs.erase(gest_it); } else { @@ -867,21 +790,21 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) } // Run the current steps - BOOL waiting = FALSE; + bool waiting = false; while (!waiting && gesture->mPlaying) { // Get the current step, if there is one. // Otherwise enter the waiting at end state. - LLGestureStep* step = NULL; + LLGestureStep* step = nullptr; if (gesture->mCurrentStep < (S32)gesture->mSteps.size()) { step = gesture->mSteps[gesture->mCurrentStep]; - llassert(step != NULL); + llassert(step != nullptr); } else { // step stays null, we're off the end - gesture->mWaitingAtEnd = TRUE; + gesture->mWaitingAtEnd = true; } @@ -896,12 +819,12 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) && gesture->mPlayingAnimIDs.empty())) { // all animations are done playing - gesture->mWaitingAtEnd = FALSE; - gesture->mPlaying = FALSE; + gesture->mWaitingAtEnd = false; + gesture->mPlaying = false; } else { - waiting = TRUE; + waiting = true; } continue; } @@ -916,20 +839,20 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) && gesture->mPlayingAnimIDs.empty())) { // all animations are done playing - gesture->mWaitingAnimations = FALSE; - gesture->mCurrentStep++; + gesture->mWaitingAnimations = false; + ++gesture->mCurrentStep; } else if (gesture->mWaitTimer.getElapsedTimeF32() > MAX_WAIT_ANIM_SECS) { // we've waited too long for an animation LL_INFOS() << "Waited too long for animations to stop, continuing gesture." << LL_ENDL; - gesture->mWaitingAnimations = FALSE; - gesture->mCurrentStep++; + gesture->mWaitingAnimations = false; + ++gesture->mCurrentStep; } else { - waiting = TRUE; + waiting = true; } continue; } @@ -945,13 +868,13 @@ void LLGestureMgr::stepGesture(LLMultiGesture* gesture) if (elapsed > wait_step->mWaitSeconds) { // wait is done, continue execution - gesture->mWaitingTimer = FALSE; - gesture->mCurrentStep++; + gesture->mWaitingTimer = false; + ++gesture->mCurrentStep; } else { // we're waiting, so execution is done for now - waiting = TRUE; + waiting = true; } continue; } @@ -971,7 +894,7 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) LLGestureStepAnimation* anim_step = (LLGestureStepAnimation*)step; if (anim_step->mAnimAssetID.isNull()) { - gesture->mCurrentStep++; + ++gesture->mCurrentStep; } if (anim_step->mFlags & ANIM_FLAG_STOP) @@ -984,7 +907,7 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) { gAgent.sendAnimationRequest(anim_step->mAnimAssetID, ANIM_REQUEST_STOP); // remove it from our request set in case we just requested it - std::set::iterator set_it = gesture->mRequestedAnimIDs.find(anim_step->mAnimAssetID); + auto& set_it = gesture->mRequestedAnimIDs.find(anim_step->mAnimAssetID); if (set_it != gesture->mRequestedAnimIDs.end()) { gesture->mRequestedAnimIDs.erase(set_it); @@ -1008,38 +931,37 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) gesture->mRequestedAnimIDs.insert(anim_step->mAnimAssetID); } } - gesture->mCurrentStep++; + ++gesture->mCurrentStep; break; } case STEP_SOUND: { LLGestureStepSound* sound_step = (LLGestureStepSound*)step; const LLUUID& sound_id = sound_step->mSoundAssetID; - const F32 volume = 1.f; + constexpr F32 volume = 1.f; if (gesture->mLocal) gAudiop->triggerSound(sound_id, gAgentID, volume, LLAudioEngine::AUDIO_TYPE_UI, gAgent.getPositionGlobal()); else send_sound_trigger(sound_id, volume); - gesture->mCurrentStep++; + ++gesture->mCurrentStep; break; } case STEP_CHAT: { LLGestureStepChat* chat_step = (LLGestureStepChat*)step; - std::string chat_text = chat_step->mChatText; + const std::string& chat_text = chat_step->mChatText; // Don't animate the nodding, as this might not blend with // other playing animations. - const BOOL animate = FALSE; - - if ( cmd_line_chat(chat_text, CHAT_TYPE_NORMAL)) + constexpr bool animate = false; + if (cmd_line_chat(chat_text, CHAT_TYPE_NORMAL)) { #if SHY_MOD //Command handler if(!SHCommandHandler::handleCommand(true, chat_text, gAgentID, gAgentAvatarp))//returns true if handled #endif //shy_mod gesture->mLocal ? fake_local_chat(chat_text) : gChatBar->sendChatFromViewer(chat_text, CHAT_TYPE_NORMAL, animate); } - gesture->mCurrentStep++; + ++gesture->mCurrentStep; break; } case STEP_WAIT: @@ -1047,19 +969,19 @@ void LLGestureMgr::runStep(LLMultiGesture* gesture, LLGestureStep* step) LLGestureStepWait* wait_step = (LLGestureStepWait*)step; if (wait_step->mFlags & WAIT_FLAG_TIME) { - gesture->mWaitingTimer = TRUE; + gesture->mWaitingTimer = true; gesture->mWaitTimer.reset(); } else if (wait_step->mFlags & WAIT_FLAG_ALL_ANIM) { - gesture->mWaitingAnimations = TRUE; + gesture->mWaitingAnimations = true; // Use the wait timer as a deadlock breaker for animation // waits. gesture->mWaitTimer.reset(); } else { - gesture->mCurrentStep++; + ++gesture->mCurrentStep; } // Don't increment instruction pointer until wait is complete. break; @@ -1080,32 +1002,29 @@ void LLGestureMgr::onLoadComplete(LLVFS *vfs, { LLLoadInfo* info = (LLLoadInfo*)user_data; - LLUUID item_id = info->mItemID; - BOOL inform_server = info->mInformServer; - BOOL deactivate_similar = info->mDeactivateSimilar; + const LLUUID& item_id = info->mItemID; + const bool& inform_server = info->mInformServer; + const bool& deactivate_similar = info->mDeactivateSimilar; delete info; - info = NULL; + info = nullptr; LLGestureMgr& self = LLGestureMgr::instance(); - self.mLoadingCount--; + --self.mLoadingCount; if (0 == status) { LLVFile file(vfs, asset_uuid, type, LLVFile::READ); S32 size = file.getSize(); - std::vector buffer(size+1); - + // ensure there's a trailing nullptr so strlen will work. + std::vector buffer(size+1, '\0'); file.read((U8*)&buffer[0], size); - // ensure there's a trailing NULL so strlen will work. - buffer[size] = '\0'; LLMultiGesture* gesture = new LLMultiGesture(); LLDataPackerAsciiBuffer dp(&buffer[0], size+1); - BOOL ok = gesture->deserialize(dp); - if (ok) + if (gesture->deserialize(dp)) { if (deactivate_similar) { @@ -1155,7 +1074,7 @@ void LLGestureMgr::onLoadComplete(LLVFS *vfs, gAgent.sendReliableMessage(); } - callback_map_t::iterator i_cb = self.mCallbackMap.find(item_id); + auto& i_cb = self.mCallbackMap.find(item_id); if(i_cb != self.mCallbackMap.end()) { @@ -1172,7 +1091,7 @@ void LLGestureMgr::onLoadComplete(LLVFS *vfs, self.mActive.erase(item_id); delete gesture; - gesture = NULL; + gesture = nullptr; } } else @@ -1240,11 +1159,8 @@ bool LLGestureMgr::hasLoadingAssets(LLMultiGesture* gesture) { LLGestureMgr& self = LLGestureMgr::instance(); - for (std::vector::iterator steps_it = gesture->mSteps.begin(); - steps_it != gesture->mSteps.end(); - ++steps_it) + for (auto& step : gesture->mSteps) { - LLGestureStep* step = *steps_it; switch(step->getType()) { case STEP_ANIMATION: @@ -1293,28 +1209,21 @@ void LLGestureMgr::stopGesture(LLMultiGesture* gesture) if (!gesture) return; // Stop any animations that this gesture is currently playing - std::set::const_iterator set_it; - for (set_it = gesture->mRequestedAnimIDs.begin(); set_it != gesture->mRequestedAnimIDs.end(); ++set_it) + for (const auto& anim_id : gesture->mRequestedAnimIDs) { - const LLUUID& anim_id = *set_it; gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_STOP); } - for (set_it = gesture->mPlayingAnimIDs.begin(); set_it != gesture->mPlayingAnimIDs.end(); ++set_it) + for (const auto& anim_id : gesture->mPlayingAnimIDs) { - const LLUUID& anim_id = *set_it; if (gesture->mLocal) - gAgentAvatarp->stopMotion(anim_id, TRUE); + gAgentAvatarp->stopMotion(anim_id, true); else gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_STOP); } - std::vector::iterator it; - it = std::find(mPlaying.begin(), mPlaying.end(), gesture); - while (it != mPlaying.end()) - { - mPlaying.erase(it); - it = std::find(mPlaying.begin(), mPlaying.end(), gesture); - } + for (auto& it = std::find(mPlaying.begin(), mPlaying.end(), gesture); + it != mPlaying.end(); + it = std::find(mPlaying.erase(it), mPlaying.end(), gesture)); gesture->reset(); @@ -1324,7 +1233,7 @@ void LLGestureMgr::stopGesture(LLMultiGesture* gesture) // callback might have deleted gesture, can't // rely on this pointer any more - gesture = NULL; + gesture = nullptr; } notifyObservers(); @@ -1334,7 +1243,7 @@ void LLGestureMgr::stopGesture(LLMultiGesture* gesture) void LLGestureMgr::stopGesture(const LLUUID& item_id) { const LLUUID& base_item_id = gInventory.getLinkedItemID(item_id); - item_map_t::iterator it = mActive.find(base_item_id); + auto& it = mActive.find(base_item_id); if (it == mActive.end()) return; LLMultiGesture* gesture = (*it).second; @@ -1351,9 +1260,9 @@ void LLGestureMgr::addObserver(LLGestureManagerObserver* observer) void LLGestureMgr::removeObserver(LLGestureManagerObserver* observer) { - std::vector::iterator it; - it = std::find(mObservers.begin(), mObservers.end(), observer); - if (it != mObservers.end()) + const auto& end = mObservers.end(); + auto& it = std::find(mObservers.begin(), end, observer); + if (it != end) { mObservers.erase(it); } @@ -1366,27 +1275,23 @@ void LLGestureMgr::notifyObservers() { LL_DEBUGS() << "LLGestureMgr::notifyObservers" << LL_ENDL; - for(std::vector::iterator iter = mObservers.begin(); - iter != mObservers.end(); - ++iter) + for(auto& observer : mObservers) { - LLGestureManagerObserver* observer = (*iter); observer->changed(); } } -BOOL LLGestureMgr::matchPrefix(const std::string& in_str, std::string* out_str) +bool LLGestureMgr::matchPrefix(const std::string& in_str, std::string* out_str) const { S32 in_len = in_str.length(); #ifdef MATCH_COMMON_CHARS - std::string rest_of_match = ""; - std::string buf = ""; + std::string rest_of_match; + std::string buf; #endif - item_map_t::iterator it; - for (it = mActive.begin(); it != mActive.end(); ++it) + for (const auto& pair : mActive) { - LLMultiGesture* gesture = (*it).second; + const LLMultiGesture* gesture = pair.second; if (gesture) { const std::string& trigger = gesture->getTrigger(); @@ -1395,7 +1300,7 @@ BOOL LLGestureMgr::matchPrefix(const std::string& in_str, std::string* out_str) if (!LLStringUtil::compareInsensitive(in_str, trigger)) { *out_str = trigger; - return TRUE; + return true; } #else if (in_len > (S32)trigger.length()) continue; // too short, bail out @@ -1408,37 +1313,36 @@ BOOL LLGestureMgr::matchPrefix(const std::string& in_str, std::string* out_str) { #ifndef MATCH_COMMON_CHARS *out_str = trigger; - return TRUE; + return true; #else - if (rest_of_match.compare("") == 0) + if (rest_of_match.empty()) { rest_of_match = trigger.substr(in_str.size()); } std::string cur_rest_of_match = trigger.substr(in_str.size()); - buf = ""; - U32 i=0; + buf.clear(); - while (ipush_back(it->first); + ids->push_back(pair.first); } } void LLGestureMgr::done() { bool notify = false; - for(item_map_t::iterator it = mActive.begin(); it != mActive.end(); ++it) + for(const auto& pair : mActive) { - if(it->second && it->second->mName.empty()) + if (pair.second && pair.second->mName.empty()) { - LLViewerInventoryItem* item = gInventory.getItem(it->first); + LLViewerInventoryItem* item = gInventory.getItem(pair.first); if(item) { - it->second->mName = item->getName(); + pair.second->mName = item->getName(); notify = true; } } diff --git a/indra/newview/llgesturemgr.h b/indra/newview/llgesturemgr.h index 419ae77e7..4eef5275f 100644 --- a/indra/newview/llgesturemgr.h +++ b/indra/newview/llgesturemgr.h @@ -27,8 +27,9 @@ #ifndef LL_LLGESTUREMGR_H #define LL_LLGESTUREMGR_H -#include #include +#include +#include #include #include "llassetstorage.h" // LLAssetType @@ -53,10 +54,10 @@ class LLGestureMgr : public LLSingleton, public LLInventoryFetchIt { public: - typedef boost::function gesture_loaded_callback_t; + typedef std::function gesture_loaded_callback_t; // Maps inventory item_id to gesture - typedef std::map item_map_t; - typedef std::map callback_map_t; + typedef std::unordered_map item_map_t; + typedef std::unordered_map callback_map_t; LLGestureMgr(); ~LLGestureMgr(); @@ -81,24 +82,24 @@ public: // Load gesture into in-memory active form. // Can be called even if the inventory item isn't loaded yet. - // inform_server TRUE will send message upstream to update database + // inform_server true will send message upstream to update database // user_gesture_active table, which isn't necessary on login. // deactivate_similar will cause other gestures with the same trigger phrase // or keybinding to be deactivated. - void activateGestureWithAsset(const LLUUID& item_id, const LLUUID& asset_id, BOOL inform_server, BOOL deactivate_similar); + void activateGestureWithAsset(const LLUUID& item_id, const LLUUID& asset_id, bool inform_server, bool deactivate_similar); // Takes gesture out of active list and deletes it. void deactivateGesture(const LLUUID& item_id); // Deactivates all gestures that match either this trigger phrase, // or this hot key. - void deactivateSimilarGestures(LLMultiGesture* gesture, const LLUUID& in_item_id); + void deactivateSimilarGestures(const LLMultiGesture* gesture, const LLUUID& in_item_id); - BOOL isGestureActive(const LLUUID& item_id); + bool isGestureActive(const LLUUID& item_id) const; - BOOL isGesturePlaying(const LLUUID& item_id); + bool isGesturePlaying(const LLUUID& item_id) const; - BOOL isGesturePlaying(LLMultiGesture* gesture); + bool isGesturePlaying(const LLMultiGesture* gesture) const; const item_map_t& getActiveGestures() const { return mActive; } // Force a gesture to be played, for example, if it is being @@ -115,19 +116,19 @@ public: * Note: * Manager will call cb after gesture will be loaded and will remove cb automatically. */ - void setGestureLoadedCallback(LLUUID inv_item_id, gesture_loaded_callback_t cb) + void setGestureLoadedCallback(const LLUUID& inv_item_id, gesture_loaded_callback_t cb) { mCallbackMap[inv_item_id] = cb; } // Trigger the first gesture that matches this key. // Returns TRUE if it finds a gesture bound to that key. - BOOL triggerGesture(KEY key, MASK mask); + bool triggerGesture(KEY key, MASK mask); // Trigger all gestures referenced as substrings in this string - BOOL triggerAndReviseString(const std::string &str, std::string *revised_string = NULL); + bool triggerAndReviseString(const std::string &str, std::string *revised_string = NULL); // Does some gesture have this key bound? - BOOL isKeyBound(KEY key, MASK mask); + //bool isKeyBound(KEY key, MASK mask) const; S32 getPlayingCount() const; @@ -138,10 +139,10 @@ public: // Overriding so we can update active gesture names and notify observers void changed(U32 mask); - BOOL matchPrefix(const std::string& in_str, std::string* out_str); + bool matchPrefix(const std::string& in_str, std::string* out_str) const; // Copy item ids into the vector - void getItemIDs(uuid_vec_t* ids); + void getItemIDs(uuid_vec_t* ids) const; protected: // Handle the processing of a single gesture @@ -172,7 +173,7 @@ protected: private: // Active gestures. - // NOTE: The gesture pointer CAN BE NULL. This means that + // NOTE: The gesture pointer CAN BE a nullptr. This means that // there is a gesture with that item_id, but the asset data // is still on its way down from the server. item_map_t mActive; @@ -183,9 +184,9 @@ private: std::vector mObservers; callback_map_t mCallbackMap; std::vector mPlaying; - BOOL mValid; + bool mValid; - std::set mLoadingAssets; + std::unordered_set mLoadingAssets; }; #endif