From c9981ec59c4613531b2d5bb03f6ab8f6d914343c Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Mon, 8 Dec 2014 13:12:28 -0500
Subject: SL-92 WIP - hover height communicated via appearance messages.

---
 indra/llmessage/message_prehash.cpp        |  2 ++
 indra/llmessage/message_prehash.h          |  2 ++
 indra/newview/app_settings/logcontrol.xml  |  2 +-
 indra/newview/llfloaterhoverheight.cpp     | 46 ++++++++++++++++++++++++++----
 indra/newview/llfloaterhoverheight.h       |  2 ++
 indra/newview/llvoavatar.cpp               | 30 +++++++++++++++++--
 indra/newview/llvoavatar.h                 |  1 +
 indra/newview/llvoavatarself.cpp           |  2 ++
 scripts/messages/message_template.msg      |  4 +++
 scripts/messages/message_template.msg.sha1 |  2 +-
 10 files changed, 82 insertions(+), 11 deletions(-)

diff --git a/indra/llmessage/message_prehash.cpp b/indra/llmessage/message_prehash.cpp
index 39cfb6019e..a62b9c3227 100755
--- a/indra/llmessage/message_prehash.cpp
+++ b/indra/llmessage/message_prehash.cpp
@@ -1383,3 +1383,5 @@ char const* const _PREHASH_GroupAVSounds = LLMessageStringTable::getInstance()->
 char const* const _PREHASH_AppearanceData = LLMessageStringTable::getInstance()->getString("AppearanceData");
 char const* const _PREHASH_AppearanceVersion = LLMessageStringTable::getInstance()->getString("AppearanceVersion");
 char const* const _PREHASH_CofVersion = LLMessageStringTable::getInstance()->getString("CofVersion");
+char const* const _PREHASH_AppearanceHover = LLMessageStringTable::getInstance()->getString("AppearanceHover");
+char const* const _PREHASH_HoverHeight = LLMessageStringTable::getInstance()->getString("HoverHeight");
diff --git a/indra/llmessage/message_prehash.h b/indra/llmessage/message_prehash.h
index 573e10dc0b..573c8e466f 100755
--- a/indra/llmessage/message_prehash.h
+++ b/indra/llmessage/message_prehash.h
@@ -1383,4 +1383,6 @@ extern char const* const _PREHASH_GroupAVSounds;
 extern char const* const _PREHASH_AppearanceData;
 extern char const* const _PREHASH_AppearanceVersion;
 extern char const* const _PREHASH_CofVersion;
+extern char const* const _PREHASH_AppearanceHover;
+extern char const* const _PREHASH_HoverHeight;
 #endif
diff --git a/indra/newview/app_settings/logcontrol.xml b/indra/newview/app_settings/logcontrol.xml
index 29639bb9c2..de3732f339 100755
--- a/indra/newview/app_settings/logcontrol.xml
+++ b/indra/newview/app_settings/logcontrol.xml
@@ -42,8 +42,8 @@
 						</array>
 					<key>tags</key>
 						<array>
-						     <string>Avatar</string>
 						<!-- sample entry for debugging specific items	
+						     <string>Avatar</string>
 						     <string>Inventory</string>
 						     <string>SceneLoadTiming</string>
 						     <string>Avatar</string>
diff --git a/indra/newview/llfloaterhoverheight.cpp b/indra/newview/llfloaterhoverheight.cpp
index 6f7f8374d2..f25d491910 100755
--- a/indra/newview/llfloaterhoverheight.cpp
+++ b/indra/newview/llfloaterhoverheight.cpp
@@ -30,6 +30,28 @@
 #include "llfloaterhoverheight.h"
 #include "llsliderctrl.h"
 #include "llviewercontrol.h"
+#include "llsdserialize.h"
+#include "llhttpclient.h"
+#include "llagent.h"
+#include "llviewerregion.h"
+#include "llvoavatarself.h"
+
+class LLHoverHeightResponder: public LLHTTPClient::Responder
+{
+public:
+	LLHoverHeightResponder(): LLHTTPClient::Responder() {}
+
+private:
+	void httpFailure()
+	{
+		LL_WARNS() << dumpResponse() << LL_ENDL;
+	}
+
+	void httpSuccess()
+	{
+		LL_INFOS() << dumpResponse() << LL_ENDL;
+	}
+};
 
 LLFloaterHoverHeight::LLFloaterHoverHeight(const LLSD& key) : LLFloater(key)
 {
@@ -53,12 +75,6 @@ BOOL LLFloaterHoverHeight::postBuild()
 // static
 void LLFloaterHoverHeight::onSliderMoved(LLUICtrl* ctrl, void* userData)
 {
-	LLSliderCtrl* sldrCtrl = static_cast<LLSliderCtrl*>(ctrl);
-	F32 value = sldrCtrl->getValueF32();
-
-	LLVector3 offset = gSavedSettings.getVector3("AvatarPosFinalOffset");
-	offset[2] = value;
-	gSavedSettings.setVector3("AvatarPosFinalOffset",offset);
 }
 
 // Do extra send-to-the-server work when slider drag completes, or new
@@ -66,4 +82,22 @@ void LLFloaterHoverHeight::onSliderMoved(LLUICtrl* ctrl, void* userData)
 void LLFloaterHoverHeight::onFinalCommit()
 {
 	LL_INFOS() << "FINAL FINAL!!!" << LL_ENDL;
+	sendHoverHeightUpdate();
+}
+
+void LLFloaterHoverHeight::sendHoverHeightUpdate()
+{
+	LLSliderCtrl* sldrCtrl = getChild<LLSliderCtrl>("HoverHeightSlider");
+	F32 value = sldrCtrl->getValueF32();
+
+	std::string url = gAgent.getRegion()->getCapability("AgentPreferences");
+
+	if (!url.empty())
+	{
+		LLSD update = LLSD::emptyMap();
+		update["hover_height"] = value;
+
+		LL_INFOS() << "updating hover height to " << value << LL_ENDL;
+		LLHTTPClient::post(url, update, new LLHoverHeightResponder);
+	}
 }
diff --git a/indra/newview/llfloaterhoverheight.h b/indra/newview/llfloaterhoverheight.h
index 1aede19e57..b81f293ae5 100755
--- a/indra/newview/llfloaterhoverheight.h
+++ b/indra/newview/llfloaterhoverheight.h
@@ -38,6 +38,8 @@ public:
 	static void onSliderMoved(LLUICtrl* ctrl, void* userData);
 
 	void onFinalCommit();
+
+	void sendHoverHeightUpdate();
 };
 
 #endif
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 2c1dedede0..d150ace455 100755
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -252,6 +252,8 @@ struct LLAppearanceMessageContents
 	//U32 appearance_flags = 0;
 	std::vector<F32> mParamWeights;
 	std::vector<LLVisualParam*> mParams;
+	LLVector3 mHoverOffset;
+	bool mHoverOffsetWasSet;
 };
 
 struct LLVOAvatarChildJoint : public LLInitParam::ChoiceBlock<LLVOAvatarChildJoint>
@@ -717,7 +719,8 @@ LLVOAvatar::LLVOAvatar(const LLUUID& id,
 	mIsEditingAppearance(FALSE),
 	mUseLocalAppearance(FALSE),
 	mLastUpdateRequestCOFVersion(-1),
-	mLastUpdateReceivedCOFVersion(-1)
+	mLastUpdateReceivedCOFVersion(-1),
+	mHoverOffset(0.0, 0.0, 0.0)
 {
 	//VTResume();  // VTune
 	
@@ -1959,6 +1962,11 @@ U32 LLVOAvatar::processUpdateMessage(LLMessageSystem *mesgsys,
 	// Do base class updates...
 	U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
 
+	//LLTEContents tec;
+	//S32 te_retval = parseTEMessage(mesgsys, _PREHASH_ObjectData, block_num, tec);
+
+	LL_DEBUGS("Avatar") << avString() << update_type << LL_ENDL; 
+
 	// Print out arrival information once we have name of avatar.
 		if (has_name && getNVPair("FirstName"))
 		{
@@ -3411,7 +3419,7 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
 		// correct for the fact that the pelvis is not necessarily the center 
 		// of the agent's physical representation
 		root_pos.mdV[VZ] -= (0.5f * mBodySize.mV[VZ]) - mPelvisToFoot;
-		root_pos += LLVector3d(gSavedSettings.getVector3("AvatarPosFinalOffset"));
+		root_pos += LLVector3d(mHoverOffset);
 		
 		LLVector3 newPosition = gAgent.getPosAgentFromGlobal(root_pos);
 
@@ -3581,7 +3589,7 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
 	else if (mDrawable.notNull())
 	{
 		LLVector3 pos = mDrawable->getPosition();
-		pos += gSavedSettings.getVector3("AvatarPosFinalOffset");
+		pos += mHoverOffset;
 		mRoot->setPosition(pos);
 		mRoot->setRotation(mDrawable->getRotation());
 	}
@@ -7007,6 +7015,17 @@ void LLVOAvatar::parseAppearanceMessage(LLMessageSystem* mesgsys, LLAppearanceMe
 		// For future use:
 		//mesgsys->getU32Fast(_PREHASH_AppearanceData, _PREHASH_Flags, appearance_flags, 0);
 	}
+
+	// Parse the AppearanceData field, if any.
+	contents.mHoverOffsetWasSet = false;
+	if (mesgsys->has(_PREHASH_AppearanceHover))
+	{
+		LLVector3 hover;
+		mesgsys->getVector3Fast(_PREHASH_AppearanceHover, _PREHASH_HoverHeight, hover);
+		LL_DEBUGS("Avatar") << avString() << " hover received " << hover.mV[ VX ] << "," << hover.mV[ VY ] << "," << hover.mV[ VZ ] << LL_ENDL;
+		contents.mHoverOffset = hover;
+		contents.mHoverOffsetWasSet = true;
+	}
 	
 	// Parse visual params, if any.
 	S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_VisualParam);
@@ -7308,6 +7327,11 @@ void LLVOAvatar::processAvatarAppearance( LLMessageSystem* mesgsys )
 		}
 	}
 
+	if (contents.mHoverOffsetWasSet)
+	{
+		mHoverOffset = contents.mHoverOffset;
+	}
+
 	setCompositeUpdatesEnabled( TRUE );
 
 	// If all of the avatars are completely baked, release the global image caches to conserve memory.
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 42ff7bff92..445f0ff921 100755
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -210,6 +210,7 @@ public:
 	/*virtual*/ LLVector3		getPosAgentFromGlobal(const LLVector3d &position);
 	virtual void				updateVisualParams();
 
+	LLVector3 mHoverOffset;
 
 /**                    Inherited
  **                                                                            **
diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp
index 42a7c2e576..f4c6472f7a 100755
--- a/indra/newview/llvoavatarself.cpp
+++ b/indra/newview/llvoavatarself.cpp
@@ -163,6 +163,8 @@ LLVOAvatarSelf::LLVOAvatarSelf(const LLUUID& id,
 {
 	mMotionController.mIsSelf = TRUE;
 
+	mHoverOffset = gSavedSettings.getVector3("AvatarPosFinalOffset");
+
 	LL_DEBUGS() << "Marking avatar as self " << id << LL_ENDL;
 }
 
diff --git a/scripts/messages/message_template.msg b/scripts/messages/message_template.msg
index 6702de9b4a..e0a80ee9cd 100755
--- a/scripts/messages/message_template.msg
+++ b/scripts/messages/message_template.msg
@@ -3594,6 +3594,10 @@ version 2.0
 		{	CofVersion			S32	}
 		{	Flags				U32	}
 	}
+	{
+		AppearanceHover		Single
+		{	HoverHeight	LLVector3	}
+	}
 }
 
 // AvatarSitResponse - response to a request to sit on an object
diff --git a/scripts/messages/message_template.msg.sha1 b/scripts/messages/message_template.msg.sha1
index 7a31177f11..affee31086 100755
--- a/scripts/messages/message_template.msg.sha1
+++ b/scripts/messages/message_template.msg.sha1
@@ -1 +1 @@
-4dbf88396c3188ad4c54c4f847a7d8817793668d
\ No newline at end of file
+bc6a4d7f7fd9bfddefcef336c3e30b623497447f
\ No newline at end of file
-- 
cgit v1.2.3