From 95623bc740048f95b2f15c67d179e9782ee56b60 Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Thu, 28 May 2020 17:50:17 +0100
Subject: [PATCH] SL-13000 - animation state management for jellydolled avatars

---
 indra/newview/llvoavatar.cpp | 78 ++++++++++++++++++++++++++++--------
 indra/newview/llvoavatar.h   |  1 +
 2 files changed, 63 insertions(+), 16 deletions(-)

diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 1a2d8a3f432..90035038fc5 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -5680,14 +5680,14 @@ void LLVOAvatar::processAnimationStateChanges()
 	}
 	
 	// start up all new anims
-	for (anim_it = mSignaledAnimations.begin(); anim_it != mSignaledAnimations.end();)
+	if (getOverallAppearance() == AOA_NORMAL)
 	{
-		AnimIterator found_anim = mPlayingAnimations.find(anim_it->first);
-
-		// signaled but not playing, or different sequence id, start motion
-		if (found_anim == mPlayingAnimations.end() || found_anim->second != anim_it->second)
+		for (anim_it = mSignaledAnimations.begin(); anim_it != mSignaledAnimations.end();)
 		{
-			if (getOverallAppearance() == AOA_NORMAL)
+			AnimIterator found_anim = mPlayingAnimations.find(anim_it->first);
+
+			// signaled but not playing, or different sequence id, start motion
+			if (found_anim == mPlayingAnimations.end() || found_anim->second != anim_it->second)
 			{
 				if (processSingleAnimationStateChange(anim_it->first, TRUE))
 				{
@@ -5696,9 +5696,9 @@ void LLVOAvatar::processAnimationStateChanges()
 					continue;
 				}
 			}
-		}
 
-		++anim_it;
+			++anim_it;
+		}
 	}
 
 	// clear source information for animations which have been stopped
@@ -10607,8 +10607,12 @@ void LLVOAvatar::setVisualMuteSettings(VisualMuteSettings set)
     LLRenderMuteList::getInstance()->saveVisualMuteSetting(getID(), S32(set));
 }
 
+
 void LLVOAvatar::setOverallAppearanceNormal()
 {
+	if (isControlAvatar())
+		return;
+
 	resetSkeleton(false);
 	for (auto it = mJellyAnims.begin(); it !=  mJellyAnims.end(); ++it)
 	{
@@ -10621,10 +10625,14 @@ void LLVOAvatar::setOverallAppearanceNormal()
 		}
 	}
 	mJellyAnims.clear();
+	//processAnimationStateChanges();
 }
 
 void LLVOAvatar::setOverallAppearanceJellyDoll()
 {
+	if (isControlAvatar())
+		return;
+
 	resetSkeleton(false);
 
 	// stop current animations
@@ -10633,19 +10641,11 @@ void LLVOAvatar::setOverallAppearanceJellyDoll()
 			  anim_it != mPlayingAnimations.end();
 			  ++anim_it)
 		{
-			if (anim_it->first != ANIM_AGENT_STAND)
 			{
 				stopMotion(anim_it->first);
 			}
 		}
 	}
-	// start the default stand
-	bool stand_is_playing = (mPlayingAnimations.find(ANIM_AGENT_STAND) != mPlayingAnimations.end());
-	if (!stand_is_playing)
-	{
-		startMotion(ANIM_AGENT_STAND, 5.0f);
-		mJellyAnims.insert(ANIM_AGENT_STAND);
-	}
 	processAnimationStateChanges();
 }
 
@@ -10672,6 +10672,52 @@ void LLVOAvatar::updateOverallAppearance()
 		}
 		mOverallAppearance = new_overall;
 	}
+
+	// This needs to be done even if overall appearance has not
+	// changed, since sit/stand status can be different.
+	updateOverallAppearanceAnimations();
+}
+
+void LLVOAvatar::updateOverallAppearanceAnimations()
+{
+	if (isControlAvatar())
+		return;
+
+	if (getOverallAppearance() == AOA_JELLYDOLL)
+	{
+		LLUUID motion_id;
+		if (isSitting() && getParent()) // sitting on object
+		{
+			motion_id = ANIM_AGENT_SIT_FEMALE; 
+		}
+		else if (isSitting()) // sitting on ground
+		{
+			motion_id = ANIM_AGENT_SIT_GROUND_CONSTRAINED;
+		}
+		else // standing
+		{
+			motion_id = ANIM_AGENT_STAND;
+		}
+		if (mJellyAnims.find(motion_id) == mJellyAnims.end())
+		{
+			for (auto it = mJellyAnims.begin(); it !=  mJellyAnims.end(); ++it)
+			{
+				bool is_playing = (mPlayingAnimations.find(*it) != mPlayingAnimations.end());
+				LL_DEBUGS("Avatar") << "jelly anim " << *it << " " << is_playing << LL_ENDL;
+				if (!is_playing)
+				{
+					// Anim was not requested for this av by sim, but may be playing locally
+					stopMotion(*it);
+				}
+			}
+			mJellyAnims.clear();
+
+			startMotion(motion_id);
+			mJellyAnims.insert(motion_id);
+
+			processAnimationStateChanges();
+		}
+	}
 }
 
 // Based on isVisuallyMuted(), but has 3 possible results.
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 28db007d565..6ef9e6a7251 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -467,6 +467,7 @@ class LLVOAvatar :
 	void setOverallAppearanceInvisible();
 		
 	void updateOverallAppearance();
+	void updateOverallAppearanceAnimations();
 
 	std::set<LLUUID> mJellyAnims;
 
-- 
GitLab