From 88cb6814f0883cdce15ca1942409da708ab07af5 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Mon, 7 Mar 2016 11:24:48 -0500
Subject: [PATCH] SL-315 WIP - more call stack tracing, initial hooks for
 avatar reset skeleton option.

---
 indra/llcommon/llcallstack.cpp                | 40 +++++++++++++++++--
 indra/llcommon/llcallstack.h                  |  6 ++-
 indra/newview/llagent.cpp                     |  6 ++-
 indra/newview/llviewermenu.cpp                | 13 ++++++
 indra/newview/llvoavatar.cpp                  |  7 ++++
 indra/newview/llvoavatar.h                    |  1 +
 .../default/xui/en/menu_attachment_other.xml  |  9 +++++
 .../default/xui/en/menu_attachment_self.xml   |  7 ++++
 .../default/xui/en/menu_avatar_other.xml      |  9 +++++
 .../skins/default/xui/en/menu_avatar_self.xml |  6 +++
 10 files changed, 97 insertions(+), 7 deletions(-)

diff --git a/indra/llcommon/llcallstack.cpp b/indra/llcommon/llcallstack.cpp
index 2409f7a8764..9978645ff41 100644
--- a/indra/llcommon/llcallstack.cpp
+++ b/indra/llcommon/llcallstack.cpp
@@ -29,6 +29,7 @@
 #include "llcommon.h"
 #include "llcallstack.h"
 #include "StackWalker.h"
+#include "llthreadlocalstorage.h"
 
 #if LL_WINDOWS
 class LLCallStackImpl: public StackWalker
@@ -88,6 +89,19 @@ LLCallStack::LLCallStack(S32 skip_count, bool verbose):
     s_impl->getStack(m_strings, m_skipCount, m_verbose);
 }
 
+bool LLCallStack::contains(const std::string& str)
+{
+    for (std::vector<std::string>::const_iterator it = m_strings.begin();
+         it != m_strings.end(); ++it)
+    {
+        if (it->find(str) != std::string::npos)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 std::ostream& operator<<(std::ostream& s, const LLCallStack& call_stack)
 {
     std::vector<std::string>::const_iterator it;
@@ -98,8 +112,6 @@ std::ostream& operator<<(std::ostream& s, const LLCallStack& call_stack)
     return s;
 }
 
-#include "llthreadlocalstorage.h"
-
 LLContextStrings::LLContextStrings()
 {
 }
@@ -135,18 +147,40 @@ void LLContextStrings::removeContextString(const std::string& str)
     }
 }
 
+// static
+bool LLContextStrings::contains(const std::string& str)
+{
+    const std::map<std::string,S32>& strings =
+        LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->m_contextStrings;
+    for (std::map<std::string,S32>::const_iterator it = strings.begin(); it!=strings.end(); ++it)
+    {
+        if (it->first.find(str) != std::string::npos)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 // static
 void LLContextStrings::output(std::ostream& os)
 {
-    const std::map<std::string,S32>& strings = LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->m_contextStrings;
+    const std::map<std::string,S32>& strings =
+        LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->m_contextStrings;
     for (std::map<std::string,S32>::const_iterator it = strings.begin(); it!=strings.end(); ++it)
     {
         os << it->first << "[" << it->second << "]" << "\n";
     }
 }
 
+// static 
 std::ostream& operator<<(std::ostream& s, const LLContextStatus& context_status)
 {
     LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->output(s);
     return s;
 }
+
+bool LLContextStatus::contains(const std::string& str)
+{
+    return LLThreadLocalSingletonPointer<LLContextStrings>::getInstance()->contains(str);
+}
diff --git a/indra/llcommon/llcallstack.h b/indra/llcommon/llcallstack.h
index 71969079801..1f7a7689d76 100644
--- a/indra/llcommon/llcallstack.h
+++ b/indra/llcommon/llcallstack.h
@@ -34,6 +34,7 @@ class LLCallStack
     LLCallStack(S32 skip_count=0, bool verbose=false);
     std::vector<std::string> m_strings;
     bool m_verbose;
+    bool contains(const std::string& str);
 private:
     static LLCallStackImpl *s_impl;
     S32 m_skipCount;
@@ -49,6 +50,7 @@ class LLContextStrings
     static void removeContextString(const std::string& str);
     static void output(std::ostream& os);
     static LLContextStrings* getThreadLocalInstance();
+    static bool contains(const std::string& str);
 private:
     std::map<std::string,S32> m_contextStrings;
 };
@@ -69,10 +71,10 @@ class LLScopedContextString
     std::string m_str;
 };
 
-// This doesn't really have any state, just acts as class to hook the
-// ostream override to.
+// Mostly exists as a class to hook an ostream override to.
 struct LLContextStatus
 {
+    bool contains(const std::string& str);
 };
 
 LL_COMMON_API std::ostream& operator<<(std::ostream& s, const LLContextStatus& context_status);
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 3f32be1d68a..0393f416667 100755
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -4137,6 +4137,8 @@ void LLAgent::setTeleportState(ETeleportState state)
 
 void LLAgent::stopCurrentAnimations()
 {
+    LL_DEBUGS("Avatar") << "Stopping current animations" << LL_ENDL;
+
 	// This function stops all current overriding animations on this
 	// avatar, propagating this change back to the server.
 	if (isAgentAvatarValid())
@@ -4154,6 +4156,7 @@ void LLAgent::stopCurrentAnimations()
 				// don't cancel a ground-sit anim, as viewers
 				// use this animation's status in
 				// determining whether we're sitting. ick.
+                LL_DEBUGS("Avatar") << "sit or do-not-disturb animation will not be stopped" << LL_ENDL;
 			}
 			else
 			{
@@ -4183,8 +4186,7 @@ void LLAgent::stopCurrentAnimations()
 
 		// re-assert at least the default standing animation, because
 		// viewers get confused by avs with no associated anims.
-		sendAnimationRequest(ANIM_AGENT_STAND,
-				     ANIM_REQUEST_START);
+		sendAnimationRequest(ANIM_AGENT_STAND, ANIM_REQUEST_START);
 	}
 }
 
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index bbd7183dd20..fefbcabb2be 100755
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -6031,6 +6031,18 @@ class LLAvatarToggleMyProfile : public view_listener_t
 	}
 };
 
+class LLAvatarResetSkeleton: public view_listener_t
+{
+    bool handleEvent(const LLSD& userdata)
+    {
+		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+		if(avatar)
+        {
+            avatar->resetSkeleton();
+        }
+        return true;
+    }
+};
 
 class LLAvatarAddContact : public view_listener_t
 {
@@ -9017,6 +9029,7 @@ void initialize_menus()
 	enable.add("Avatar.EnableCall", boost::bind(&LLAvatarActions::canCall));
 	view_listener_t::addMenu(new LLAvatarReportAbuse(), "Avatar.ReportAbuse");
 	view_listener_t::addMenu(new LLAvatarToggleMyProfile(), "Avatar.ToggleMyProfile");
+	view_listener_t::addMenu(new LLAvatarResetSkeleton(), "Avatar.ResetSkeleton");
 	enable.add("Avatar.IsMyProfileOpen", boost::bind(&my_profile_visible));
 
 	commit.add("Avatar.OpenMarketplace", boost::bind(&LLWeb::loadURLExternal, gSavedSettings.getString("MarketplaceURL")));
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index a8cc797f163..204432dc166 100755
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1801,6 +1801,13 @@ void LLVOAvatar::buildCharacter()
 	mMeshValid = TRUE;
 }
 
+//-----------------------------------------------------------------------------
+// resetSkeleton()
+//-----------------------------------------------------------------------------
+void LLVOAvatar::resetSkeleton()
+{
+    LL_DEBUGS("Avatar") << avString() << LL_ENDL;
+}
 
 //-----------------------------------------------------------------------------
 // releaseMeshData()
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index e1b4885bbb4..76b40fb90a4 100755
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -364,6 +364,7 @@ class LLVOAvatar :
 
 	/*virtual*/ BOOL	loadSkeletonNode();
 	/*virtual*/ void	buildCharacter();
+    void				resetSkeleton();
 
 	LLVector3			mCurRootToHeadOffset;
 	LLVector3			mTargetRootToHeadOffset;
diff --git a/indra/newview/skins/default/xui/en/menu_attachment_other.xml b/indra/newview/skins/default/xui/en/menu_attachment_other.xml
index ba91b0b5d94..c3c6701d01b 100755
--- a/indra/newview/skins/default/xui/en/menu_attachment_other.xml
+++ b/indra/newview/skins/default/xui/en/menu_attachment_other.xml
@@ -39,6 +39,15 @@
       <menu_item_call.on_click
          function="Avatar.InviteToGroup" />
       </menu_item_call>
+   <menu_item_separator />
+
+     <menu_item_call label="Reset Skeleton"
+       layout="topleft"
+       name="Reset Skeleton">
+       <menu_item_call.on_click
+        function="Avatar.ResetSkeleton" />
+     </menu_item_call>
+
    <menu_item_separator />
     <menu_item_call
      enabled="false"
diff --git a/indra/newview/skins/default/xui/en/menu_attachment_self.xml b/indra/newview/skins/default/xui/en/menu_attachment_self.xml
index c6ae844d676..ced0dd37b16 100755
--- a/indra/newview/skins/default/xui/en/menu_attachment_self.xml
+++ b/indra/newview/skins/default/xui/en/menu_attachment_self.xml
@@ -99,6 +99,13 @@ name="Edit Outfit">
      <menu_item_call.on_enable
       function="Edit.EnableHoverHeight" />
   </menu_item_call>
+  <menu_item_call label="Reset Skeleton"
+       layout="topleft"
+       name="Reset Skeleton">
+       <menu_item_call.on_click
+        function="Avatar.ResetSkeleton" />
+  </menu_item_call>
+
   <menu_item_call
     label="My Friends"
     layout="topleft"
diff --git a/indra/newview/skins/default/xui/en/menu_avatar_other.xml b/indra/newview/skins/default/xui/en/menu_avatar_other.xml
index cfbbe41f954..f04a70d0a54 100755
--- a/indra/newview/skins/default/xui/en/menu_avatar_other.xml
+++ b/indra/newview/skins/default/xui/en/menu_avatar_other.xml
@@ -40,6 +40,15 @@
          function="Avatar.InviteToGroup" />
       </menu_item_call>
     
+   <menu_item_separator />
+
+     <menu_item_call label="Reset Skeleton"
+       layout="topleft"
+       name="Reset Skeleton">
+       <menu_item_call.on_click
+        function="Avatar.ResetSkeleton" />
+     </menu_item_call>
+
    <menu_item_separator />
    
      <menu_item_call
diff --git a/indra/newview/skins/default/xui/en/menu_avatar_self.xml b/indra/newview/skins/default/xui/en/menu_avatar_self.xml
index d3b0b07f700..924e8b84545 100755
--- a/indra/newview/skins/default/xui/en/menu_avatar_self.xml
+++ b/indra/newview/skins/default/xui/en/menu_avatar_self.xml
@@ -237,6 +237,12 @@
      <menu_item_call.on_enable
       function="Edit.EnableHoverHeight" />
    </menu_item_call>
+   <menu_item_call label="Reset Skeleton"
+     layout="topleft"
+     name="Reset Skeleton">
+     <menu_item_call.on_click
+      function="Avatar.ResetSkeleton" />
+   </menu_item_call>
    <menu_item_call
      label="My Friends"
      layout="topleft"
-- 
GitLab