From 06349951d236f2049d5d3c57ead5faf3a213ef16 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Thu, 27 Oct 2011 21:41:19 -0500 Subject: [PATCH] Added tracking of requested(and pending) attachments. Moved Ascent code out of attach/detach functions and into their own for better manageability. --- indra/newview/llinventorybridge.cpp | 18 +- indra/newview/llvoavatarself.cpp | 272 +++++++++++++++++++++------- indra/newview/llvoavatarself.h | 22 +++ 3 files changed, 240 insertions(+), 72 deletions(-) diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp index 132470685..7348b92d4 100644 --- a/indra/newview/llinventorybridge.cpp +++ b/indra/newview/llinventorybridge.cpp @@ -4151,9 +4151,20 @@ void rez_attachment(LLViewerInventoryItem* item, LLViewerJointAttachment* attach attachment = RlvAttachPtLookup::getAttachPoint(item); } // [/RLVa:KB] + const LLUUID& item_id = item->getLinkedUUID(); + + // Check for duplicate request. + if (isAgentAvatarValid() && + (gAgentAvatarp->attachmentWasRequested(item_id) || + gAgentAvatarp->isWearingAttachment(item_id))) + { + llwarns << "duplicate attachment request, ignoring" << llendl; + return; + } + gAgentAvatarp->addAttachmentRequest(item_id); S32 attach_pt = 0; - if (gAgentAvatarp && attachment) + if (isAgentAvatarValid() && attachment) { for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin(); iter != gAgentAvatarp->mAttachmentPoints.end(); ++iter) @@ -4167,11 +4178,12 @@ void rez_attachment(LLViewerInventoryItem* item, LLViewerJointAttachment* attach } LLSD payload; - payload["item_id"] = item->getLinkedUUID(); // Wear the base object in case this is a link. + payload["item_id"] = item_id; // Wear the base object in case this is a link. payload["attachment_point"] = attach_pt; payload["is_add"] = !replace; - if (replace && attachment && attachment->getNumObjects() > 0) + if (replace && + (attachment && attachment->getNumObjects() > 0)) { // [RLVa:KB] - Checked: 2010-08-25 (RLVa-1.2.1a) | Modified: RLVa-1.2.1a // Block if we can't "replace wear" what's currently there diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp index 441bea7f9..8279a5efc 100644 --- a/indra/newview/llvoavatarself.cpp +++ b/indra/newview/llvoavatarself.cpp @@ -459,12 +459,86 @@ void LLVOAvatarSelf::resetJointPositions( void ) { return LLVOAvatar::resetJointPositions(); } +// virtual +BOOL LLVOAvatarSelf::setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL upload_bake ) +{ + if (!which_param) + { + return FALSE; + } + LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(which_param->getID()); + return setParamWeight(param,weight,upload_bake); +} + +// virtual +BOOL LLVOAvatarSelf::setVisualParamWeight(const char* param_name, F32 weight, BOOL upload_bake ) +{ + if (!param_name) + { + return FALSE; + } + LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(param_name); + return setParamWeight(param,weight,upload_bake); +} + +// virtual +BOOL LLVOAvatarSelf::setVisualParamWeight(S32 index, F32 weight, BOOL upload_bake ) +{ + LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(index); + return setParamWeight(param,weight,upload_bake); +} + +BOOL LLVOAvatarSelf::setParamWeight(LLViewerVisualParam *param, F32 weight, BOOL upload_bake ) +{ + if (!param) + { + return FALSE; + } + + /*if (param->getCrossWearable()) + { + LLWearableType::EType type = (LLWearableType::EType)param->getWearableType(); + U32 size = gAgentWearables.getWearableCount(type); + for (U32 count = 0; count < size; ++count) + { + LLWearable *wearable = gAgentWearables.getWearable(type,count); + if (wearable) + { + wearable->setVisualParamWeight(param->getID(), weight, upload_bake); + } + } + }*/ + + return LLCharacter::setVisualParamWeight(param,weight,upload_bake); +} /*virtual*/ void LLVOAvatarSelf::updateVisualParams() { LLVOAvatar::updateVisualParams(); } + +/*virtual*/ +void LLVOAvatarSelf::idleUpdateAppearanceAnimation() +{ + // Animate all top-level wearable visual parameters + /*gAgentWearables.animateAllWearableParams(calcMorphAmount(), FALSE); + + // apply wearable visual params to avatar + for (U32 type = 0; type < LLWearableType::WT_COUNT; type++) + { + LLWearable *wearable = gAgentWearables.getTopWearable((LLWearableType::EType)type); + if (wearable) + { + wearable->writeToAvatar(); + } + }*/ + + //allow avatar to process updates + LLVOAvatar::idleUpdateAppearanceAnimation(); + +} + // virtual void LLVOAvatarSelf::requestStopMotion(LLMotion* motion) { @@ -813,19 +887,44 @@ BOOL LLVOAvatarSelf::isWearingAttachment( const LLUUID& inv_item_id ) const return FALSE; } -// testzone attachpt -BOOL LLVOAvatarSelf::isWearingUnsupportedAttachment( const LLUUID& inv_item_id ) +//----------------------------------------------------------------------------- +BOOL LLVOAvatarSelf::attachmentWasRequested(const LLUUID& inv_item_id) const { - std::map >::iterator end = mUnsupportedAttachmentPoints.end(); - for(std::map >::iterator iter = mUnsupportedAttachmentPoints.begin(); iter != end; ++iter) + const F32 REQUEST_EXPIRATION_SECONDS = 5.0; // any request older than this is ignored/removed. + std::map::iterator it = mAttachmentRequests.find(inv_item_id); + if (it != mAttachmentRequests.end()) { - if((*iter).second.first == inv_item_id) + const LLTimer& request_time = it->second; + F32 request_time_elapsed = request_time.getElapsedTimeF32(); + if (request_time_elapsed > REQUEST_EXPIRATION_SECONDS) + { + mAttachmentRequests.erase(it); + return FALSE; + } + else { return TRUE; } } - return FALSE; + else + { + return FALSE; + } } + +//----------------------------------------------------------------------------- +void LLVOAvatarSelf::addAttachmentRequest(const LLUUID& inv_item_id) +{ + LLTimer current_time; + mAttachmentRequests[inv_item_id] = current_time; +} + +//----------------------------------------------------------------------------- +void LLVOAvatarSelf::removeAttachmentRequest(const LLUUID& inv_item_id) +{ + mAttachmentRequests.erase(inv_item_id); +} + //----------------------------------------------------------------------------- // getWornAttachment() //----------------------------------------------------------------------------- @@ -882,49 +981,24 @@ const LLViewerJointAttachment *LLVOAvatarSelf::attachObject(LLViewerObject *view const LLViewerJointAttachment *attachment = LLVOAvatar::attachObject(viewer_object); if(!attachment) { - // testzone attachpt - S32 attachmentID = ATTACHMENT_ID_FROM_STATE(viewer_object->getState()); - LLUUID item_id; - LLNameValue* item_id_nv = viewer_object->getNVPair("AttachItemID"); - if( item_id_nv ) - { - const char* s = item_id_nv->getString(); - if(s) - item_id.set(s); - } - if(!item_id.isNull()) - { - mUnsupportedAttachmentPoints[attachmentID] = std::pair(item_id,viewer_object->getID()); - if (viewer_object->isSelected()) - { - LLSelectMgr::getInstance()->updateSelectionCenter(); - LLSelectMgr::getInstance()->updatePointAt(); - } - - updateAttachmentVisibility(gAgentCamera.getCameraMode()); - - // Then make sure the inventory is in sync with the avatar. - gInventory.addChangedMask( LLInventoryObserver::LABEL, item_id ); - gInventory.notifyObservers(); - } - else - llwarns << "No item ID" << llendl; - // +// + addUnsupportedAttachment(viewer_object); +// return 0; } updateAttachmentVisibility(gAgentCamera.getCameraMode()); // [RLVa:KB] - Checked: 2010-08-22 (RLVa-1.2.1a) | Modified: RLVa-1.2.1a - // NOTE: RLVa event handlers should be invoked *after* LLVOAvatar::attachObject() calls LLViewerJointAttachment::addObject() - if (rlv_handler_t::isEnabled()) - { - RlvAttachmentLockWatchdog::instance().onAttach(viewer_object, attachment); - gRlvHandler.onAttach(viewer_object, attachment); + // NOTE: RLVa event handlers should be invoked *after* LLVOAvatar::attachObject() calls LLViewerJointAttachment::addObject() + if (rlv_handler_t::isEnabled()) + { + RlvAttachmentLockWatchdog::instance().onAttach(viewer_object, attachment); + gRlvHandler.onAttach(viewer_object, attachment); - if ( (attachment->getIsHUDAttachment()) && (!gRlvAttachmentLocks.hasLockedHUD()) ) - gRlvAttachmentLocks.updateLockedHUD(); - } + if ( (attachment->getIsHUDAttachment()) && (!gRlvAttachmentLocks.hasLockedHUD()) ) + gRlvAttachmentLocks.updateLockedHUD(); + } // [/RLVa:KB] // Then make sure the inventory is in sync with the avatar. @@ -934,7 +1008,10 @@ const LLViewerJointAttachment *LLVOAvatarSelf::attachObject(LLViewerObject *view // Should just be the last object added if (attachment->isObjectAttached(viewer_object)) { - LLCOFMgr::instance().addAttachment(viewer_object->getAttachmentItemID()); + const LLUUID& attachment_id = viewer_object->getAttachmentItemID(); + LLCOFMgr::instance().addAttachment(attachment_id); + // Clear any pending requests once the attachment arrives. + removeAttachmentRequest(attachment_id); updateLODRiggedAttachments(); } @@ -990,7 +1067,82 @@ BOOL LLVOAvatarSelf::detachObject(LLViewerObject *viewer_object) } return TRUE; } - // testzone attachpt + +// + if(removeUnsupportedAttachment(viewer_object)) + return TRUE; +// + + + return FALSE; +} + +// static +BOOL LLVOAvatarSelf::detachAttachmentIntoInventory(const LLUUID &item_id) +{ + LLInventoryItem* item = gInventory.getLinkedItem(item_id); + if ( (item) && (gAgentAvatarp) && (!gAgentAvatarp->isWearingAttachment(item->getUUID())) ) + { + LLCOFMgr::instance().removeAttachment(item->getUUID()); + return FALSE; + } +// if (item) +// [RLVa:KB] - Checked: 2010-09-04 (RLVa-1.2.1c) | Added: RLVa-1.2.1c + if ( (item) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(item))) ) +// [/RLVa:KB] + { + gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv); + gMessageSystem->nextBlockFast(_PREHASH_ObjectData); + gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); + gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id); + gMessageSystem->sendReliable(gAgent.getRegion()->getHost()); + + // This object might have been selected, so let the selection manager know it's gone now + LLViewerObject *found_obj = gObjectList.findObject(item_id); + if (found_obj) + { + LLSelectMgr::getInstance()->remove(found_obj); + } + + return TRUE; + } + return FALSE; +} + +// testzone attachpt +void LLVOAvatarSelf::addUnsupportedAttachment(LLViewerObject *viewer_object) +{ + + S32 attachmentID = ATTACHMENT_ID_FROM_STATE(viewer_object->getState()); + LLUUID item_id; + LLNameValue* item_id_nv = viewer_object->getNVPair("AttachItemID"); + if( item_id_nv ) + { + const char* s = item_id_nv->getString(); + if(s) + item_id.set(s); + } + if(!item_id.isNull()) + { + mUnsupportedAttachmentPoints[attachmentID] = std::pair(item_id,viewer_object->getID()); + if (viewer_object->isSelected()) + { + LLSelectMgr::getInstance()->updateSelectionCenter(); + LLSelectMgr::getInstance()->updatePointAt(); + } + + updateAttachmentVisibility(gAgentCamera.getCameraMode()); + + // Then make sure the inventory is in sync with the avatar. + gInventory.addChangedMask( LLInventoryObserver::LABEL, item_id ); + gInventory.notifyObservers(); + } + else + llwarns << "No item ID" << llendl; + +} +bool LLVOAvatarSelf::removeUnsupportedAttachment(LLViewerObject *viewer_object) +{ LLUUID item_id; LLNameValue* item_id_nv = viewer_object->getNVPair("AttachItemID"); if( item_id_nv ) @@ -1037,40 +1189,22 @@ BOOL LLVOAvatarSelf::detachObject(LLViewerObject *viewer_object) { llwarns << "No item ID" << llendl; } - // return FALSE; } -BOOL LLVOAvatarSelf::detachAttachmentIntoInventory(const LLUUID &item_id) +BOOL LLVOAvatarSelf::isWearingUnsupportedAttachment( const LLUUID& inv_item_id ) { - LLInventoryItem* item = gInventory.getLinkedItem(item_id); - if ( (item) && (gAgentAvatarp) && (!gAgentAvatarp->isWearingAttachment(item->getUUID())) ) + std::map >::iterator end = mUnsupportedAttachmentPoints.end(); + for(std::map >::iterator iter = mUnsupportedAttachmentPoints.begin(); iter != end; ++iter) { - LLCOFMgr::instance().removeAttachment(item->getUUID()); - return FALSE; - } -// if (item) -// [RLVa:KB] - Checked: 2010-09-04 (RLVa-1.2.1c) | Added: RLVa-1.2.1c - if ( (item) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(item))) ) -// [/RLVa:KB] - { - gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv); - gMessageSystem->nextBlockFast(_PREHASH_ObjectData); - gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); - gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id); - gMessageSystem->sendReliable(gAgent.getRegion()->getHost()); - - // This object might have been selected, so let the selection manager know it's gone now - LLViewerObject *found_obj = gObjectList.findObject(item_id); - if (found_obj) + if((*iter).second.first == inv_item_id) { - LLSelectMgr::getInstance()->remove(found_obj); + return TRUE; } - - return TRUE; } return FALSE; } - +// + U32 LLVOAvatarSelf::getNumWearables(LLVOAvatarDefines::ETextureIndex i) const { LLWearableType::EType type = LLVOAvatarDictionary::getInstance()->getTEWearableType(i); diff --git a/indra/newview/llvoavatarself.h b/indra/newview/llvoavatarself.h index fb0003553..c56d83b00 100644 --- a/indra/newview/llvoavatarself.h +++ b/indra/newview/llvoavatarself.h @@ -83,7 +83,15 @@ public: void resetJointPositions( void ); + /*virtual*/ BOOL setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL upload_bake = FALSE ); + /*virtual*/ BOOL setVisualParamWeight(const char* param_name, F32 weight, BOOL upload_bake = FALSE ); + /*virtual*/ BOOL setVisualParamWeight(S32 index, F32 weight, BOOL upload_bake = FALSE ); /*virtual*/ void updateVisualParams(); + /*virtual*/ void idleUpdateAppearanceAnimation(); + +private: + // helper function. Passed in param is assumed to be in avatar's parameter list. + BOOL setParamWeight(LLViewerVisualParam *param, F32 weight, BOOL upload_bake = FALSE ); /** Initialization @@ -259,17 +267,31 @@ protected: public: void updateAttachmentVisibility(U32 camera_mode); BOOL isWearingAttachment(const LLUUID& inv_item_id) const; + BOOL attachmentWasRequested(const LLUUID& inv_item_id) const; + void addAttachmentRequest(const LLUUID& inv_item_id); + void removeAttachmentRequest(const LLUUID& inv_item_id); LLViewerObject* getWornAttachment(const LLUUID& inv_item_id); const std::string getAttachedPointName(const LLUUID& inv_item_id) const; /*virtual*/ const LLViewerJointAttachment *attachObject(LLViewerObject *viewer_object); /*virtual*/ BOOL detachObject(LLViewerObject *viewer_object); static BOOL detachAttachmentIntoInventory(const LLUUID& item_id); + +private: + // Track attachments that have been requested but have not arrived yet. + mutable std::map mAttachmentRequests; + // testzone attachpt +public: + void addUnsupportedAttachment( LLViewerObject *viewer_object ); + bool removeUnsupportedAttachment( LLViewerObject *viewer_object ); BOOL isWearingUnsupportedAttachment( const LLUUID& inv_item_id ); std::map > mUnsupportedAttachmentPoints; + // + // [RLVa:KB] - Checked: 2010-03-14 (RLVa-1.2.0a) | Added: RLVa-1.1.0i LLViewerJointAttachment* getWornAttachmentPoint(const LLUUID& inv_item_id) const; // [/RLVa:KB] + private: LLViewerJoint* mScreenp; // special purpose joint for HUD attachments