Combine send_ObjectDeGrab and send_ObjectGrab repetitive code

This commit is contained in:
Liru Færs
2020-01-13 18:36:55 -05:00
parent 623a484ae3
commit b9156b7955
3 changed files with 44 additions and 64 deletions

View File

@@ -403,7 +403,7 @@ void LLToolGrab::startGrab()
mDragStartPointGlobal = grab_start_global;
mDragStartFromCamera = grab_start_global - gAgentCamera.getCameraPositionGlobal();
send_ObjectGrab_message(objectp, mGrabPick, grab_offset);
send_ObjectGrab_message(objectp, true, &mGrabPick, grab_offset);
mGrabOffsetFromCenterInitial = grab_offset;
mGrabHiddenOffsetFromCamera = mDragStartFromCamera;
@@ -1079,7 +1079,7 @@ void LLToolGrab::stopGrab()
case GRAB_ACTIVE_CENTER:
case GRAB_NONPHYSICAL:
case GRAB_LOCKED:
send_ObjectDeGrab_message(objectp, pick);
send_ObjectGrab_message(objectp, false, &pick);
mVerticalDragging = FALSE;
break;
@@ -1133,64 +1133,45 @@ LLVector3d LLToolGrab::getGrabPointGlobal()
}
void send_ObjectGrab_message(LLViewerObject* object, const LLPickInfo & pick, const LLVector3 &grab_offset)
void send_ObjectGrab_message(LLViewerObject* object, bool grab, const LLPickInfo* const pick, const LLVector3 &grab_offset)
{
if (!object) return;
LLMessageSystem *msg = gMessageSystem;
msg->newMessageFast(_PREHASH_ObjectGrab);
msg->newMessageFast(grab ? _PREHASH_ObjectGrab : _PREHASH_ObjectDeGrab);
msg->nextBlockFast( _PREHASH_AgentData);
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
msg->nextBlockFast( _PREHASH_ObjectData);
msg->addU32Fast( _PREHASH_LocalID, object->mLocalID);
msg->addVector3Fast(_PREHASH_GrabOffset, grab_offset);
msg->nextBlock("SurfaceInfo");
msg->addVector3("UVCoord", LLVector3(pick.mUVCoords));
msg->addVector3("STCoord", LLVector3(pick.mSTCoords));
msg->addS32Fast(_PREHASH_FaceIndex, pick.mObjectFace);
msg->addVector3("Position", pick.mIntersection);
msg->addVector3("Normal", pick.mNormal);
msg->addVector3("Binormal", pick.mBinormal);
if (grab) msg->addVector3Fast(_PREHASH_GrabOffset, grab_offset);
if (pick)
{
msg->nextBlock("SurfaceInfo");
msg->addVector3("UVCoord", LLVector3(pick->mUVCoords));
msg->addVector3("STCoord", LLVector3(pick->mSTCoords));
msg->addS32Fast(_PREHASH_FaceIndex, pick->mObjectFace);
msg->addVector3("Position", pick->mIntersection);
msg->addVector3("Normal", pick->mNormal);
msg->addVector3("Binormal", pick->mBinormal);
}
msg->sendMessage( object->getRegion()->getHost());
/* Diagnostic code
LL_INFOS() << "mUVCoords: " << pick.mUVCoords
<< ", mSTCoords: " << pick.mSTCoords
<< ", mObjectFace: " << pick.mObjectFace
<< ", mIntersection: " << pick.mIntersection
<< ", mNormal: " << pick.mNormal
<< ", mBinormal: " << pick.mBinormal
if (pick)
{
LL_INFOS() << "mUVCoords: " << pick->mUVCoords
<< ", mSTCoords: " << pick->mSTCoords
<< ", mObjectFace: " << pick->mObjectFace
<< ", mIntersection: " << pick->mIntersection
<< ", mNormal: " << pick->mNormal
<< ", mBinormal: " << pick->mBinormal
<< LL_ENDL;
}
LL_INFOS() << "Avatar pos: " << gAgent.getPositionAgent() << LL_ENDL;
LL_INFOS() << "Object pos: " << object->getPosition() << LL_ENDL;
*/
}
void send_ObjectDeGrab_message(LLViewerObject* object, const LLPickInfo & pick)
{
if (!object) return;
LLMessageSystem *msg = gMessageSystem;
msg->newMessageFast(_PREHASH_ObjectDeGrab);
msg->nextBlockFast(_PREHASH_AgentData);
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
msg->nextBlockFast(_PREHASH_ObjectData);
msg->addU32Fast(_PREHASH_LocalID, object->mLocalID);
msg->nextBlock("SurfaceInfo");
msg->addVector3("UVCoord", LLVector3(pick.mUVCoords));
msg->addVector3("STCoord", LLVector3(pick.mSTCoords));
msg->addS32Fast(_PREHASH_FaceIndex, pick.mObjectFace);
msg->addVector3("Position", pick.mIntersection);
msg->addVector3("Normal", pick.mNormal);
msg->addVector3("Binormal", pick.mBinormal);
msg->sendMessage(object->getRegion()->getHost());
}

View File

@@ -41,9 +41,7 @@ class LLPickInfo;
// Message utilities
void send_ObjectGrab_message(LLViewerObject* object, const LLPickInfo & pick, const LLVector3 &grab_offset);
void send_ObjectDeGrab_message(LLViewerObject* object, const LLPickInfo & pick);
void send_ObjectGrab_message(LLViewerObject* object, bool grab, const LLPickInfo* const pick = nullptr, const LLVector3& grab_offset = LLVector3::zero);
class LLToolGrab : public LLTool, public LLSingleton<LLToolGrab>

View File

@@ -1792,21 +1792,18 @@ class LLObjectTouch : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
handle_object_touch();
handle_object_touch(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject(), LLToolPie::getInstance()->getPick());
return true;
}
};
void handle_object_touch()
void handle_object_touch(LLViewerObject* object, const LLPick const* pick);
{
LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
if (!object) return;
LLPickInfo pick = LLToolPie::getInstance()->getPick();
// [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Modified: RLVa-1.1.0l
// NOTE: fallback code since we really shouldn't be getting an active selection if we can't touch this
if ( (rlv_handler_t::isEnabled()) && (!gRlvHandler.canTouch(object, pick.mObjectOffset)) )
if ( (rlv_handler_t::isEnabled()) && (!gRlvHandler.canTouch(object, pick ? pick->mObjectOffset : LLVector3::zero)) )
{
RLV_ASSERT(false);
return;
@@ -1816,24 +1813,27 @@ void handle_object_touch()
// *NOTE: Hope the packets arrive safely and in order or else
// there will be some problems.
// *TODO: Just fix this bad assumption.
send_ObjectGrab_message(object, pick, LLVector3::zero);
send_ObjectDeGrab_message(object, pick);
send_ObjectGrab_message(object, true, pick);
send_ObjectGrab_message(object, false, pick);
}
bool enable_object_touch(LLViewerObject* obj, const LLVector3& offset)
{
bool new_value = obj && obj->flagHandleTouch();
// [RLVa:KB] - Checked: 2010-11-12 (RLVa-1.2.1g) | Added: RLVa-1.2.1g
if (new_value && rlv_handler_t::isEnabled())
{
// RELEASE-RLVa: [RLVa-1.2.1] Make sure this stays in sync with handle_object_touch()
new_value = gRlvHandler.canTouch(obj, offset);
}
// [/RLVa:KB]
return new_value;
}
bool enable_object_touch(const LLSD& userdata)
{
LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
bool new_value = obj && obj->flagHandleTouch();
// [RLVa:KB] - Checked: 2010-11-12 (RLVa-1.2.1g) | Added: RLVa-1.2.1g
if ( (rlv_handler_t::isEnabled()) && (new_value) )
{
// RELEASE-RLVa: [RLVa-1.2.1] Make sure this stays in sync with handle_object_touch()
new_value = gRlvHandler.canTouch(obj, LLToolPie::getInstance()->getPick().mObjectOffset);
}
// [/RLVa:KB]
std::string touch_text;
// Update label based on the node touch name if available.
@@ -1849,7 +1849,8 @@ bool enable_object_touch(const LLSD& userdata)
gMenuHolder->childSetText("Object Touch", touch_text);
gMenuHolder->childSetText("Attachment Object Touch", touch_text);
return new_value;
return enable_object_touch(obj, LLToolPie::getInstance()->getPick().mObjectOffset);
};
// One object must have touch sensor