From b15e34b94207c52d81e310f962e72f4d8030bd94 Mon Sep 17 00:00:00 2001
From: Loren Shih <seraph@lindenlab.com>
Date: Tue, 30 Mar 2010 14:21:20 -0400
Subject: [PATCH] EXT-6630 : INFRASTRUCTURE: Pull out -Keys functions from
 llagent into llagentcamera

Orbit/Pan keys were already in llagentcamera.  Pulled alt/walk/left/up/yaw/pitch into llagentcamera.
---
 indra/newview/llagent.cpp       |  67 +++++------------
 indra/newview/llagent.h         |  13 ----
 indra/newview/llagentcamera.cpp | 118 +++++++++++++++++++----------
 indra/newview/llagentcamera.h   | 127 +++++++++++++++++++++++---------
 4 files changed, 186 insertions(+), 139 deletions(-)

diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 3eeaacf93b2..0215dc1309b 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -218,13 +218,6 @@ LLAgent::LLAgent() :
 
 	mIsBusy(FALSE),
 
-	mAtKey(0), // Either 1, 0, or -1... indicates that movement-key is pressed
-	mWalkKey(0), // like AtKey, but causes less forward thrust
-	mLeftKey(0),
-	mUpKey(0),
-	mYawKey(0.f),
-	mPitchKey(0.f),
-
 	mControlFlags(0x00000000),
 	mbFlagsDirty(FALSE),
 	mbFlagsNeedReset(FALSE),
@@ -339,7 +332,7 @@ void LLAgent::moveAt(S32 direction, bool reset)
 	// age chat timer so it fades more quickly when you are intentionally moving
 	ageChat();
 
-	setKey(direction, mAtKey);
+	gAgentCamera.setAtKey(LLAgentCamera::directionToKey(direction));
 
 	if (direction > 0)
 	{
@@ -364,7 +357,7 @@ void LLAgent::moveAtNudge(S32 direction)
 	// age chat timer so it fades more quickly when you are intentionally moving
 	ageChat();
 
-	setKey(direction, mWalkKey);
+	gAgentCamera.setWalkKey(LLAgentCamera::directionToKey(direction));
 
 	if (direction > 0)
 	{
@@ -386,7 +379,7 @@ void LLAgent::moveLeft(S32 direction)
 	// age chat timer so it fades more quickly when you are intentionally moving
 	ageChat();
 
-	setKey(direction, mLeftKey);
+	gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
 
 	if (direction > 0)
 	{
@@ -408,7 +401,7 @@ void LLAgent::moveLeftNudge(S32 direction)
 	// age chat timer so it fades more quickly when you are intentionally moving
 	ageChat();
 
-	setKey(direction, mLeftKey);
+	gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
 
 	if (direction > 0)
 	{
@@ -430,7 +423,7 @@ void LLAgent::moveUp(S32 direction)
 	// age chat timer so it fades more quickly when you are intentionally moving
 	ageChat();
 
-	setKey(direction, mUpKey);
+	gAgentCamera.setUpKey(LLAgentCamera::directionToKey(direction));
 
 	if (direction > 0)
 	{
@@ -449,7 +442,7 @@ void LLAgent::moveUp(S32 direction)
 //-----------------------------------------------------------------------------
 void LLAgent::moveYaw(F32 mag, bool reset_view)
 {
-	mYawKey = mag;
+	gAgentCamera.setYawKey(mag);
 
 	if (mag > 0)
 	{
@@ -471,7 +464,7 @@ void LLAgent::moveYaw(F32 mag, bool reset_view)
 //-----------------------------------------------------------------------------
 void LLAgent::movePitch(F32 mag)
 {
-	mPitchKey = mag;
+	gAgentCamera.setPitchKey(mag);
 
 	if (mag > 0)
 	{
@@ -1048,26 +1041,6 @@ LLQuaternion LLAgent::getQuat() const
 	return mFrameAgent.getQuaternion();
 }
 
-//-----------------------------------------------------------------------------
-// setKey()
-//-----------------------------------------------------------------------------
-void LLAgent::setKey(const S32 direction, S32 &key)
-{
-	if (direction > 0)
-	{
-		key = 1;
-	}
-	else if (direction < 0)
-	{
-		key = -1;
-	}
-	else
-	{
-		key = 0;
-	}
-}
-
-
 //-----------------------------------------------------------------------------
 // getControlFlags()
 //-----------------------------------------------------------------------------
@@ -1537,20 +1510,20 @@ void LLAgent::propagate(const F32 dt)
 	LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
 	if (floater_move)
 	{
-		floater_move->mForwardButton   ->setToggleState( mAtKey > 0 || mWalkKey > 0 );
-		floater_move->mBackwardButton  ->setToggleState( mAtKey < 0 || mWalkKey < 0 );
-		floater_move->mTurnLeftButton  ->setToggleState( mYawKey > 0.f );
-		floater_move->mTurnRightButton ->setToggleState( mYawKey < 0.f );
-		floater_move->mMoveUpButton    ->setToggleState( mUpKey > 0 );
-		floater_move->mMoveDownButton  ->setToggleState( mUpKey < 0 );
+		floater_move->mForwardButton   ->setToggleState( gAgentCamera.getAtKey() > 0 || gAgentCamera.getWalkKey() > 0 );
+		floater_move->mBackwardButton  ->setToggleState( gAgentCamera.getAtKey() < 0 || gAgentCamera.getWalkKey() < 0 );
+		floater_move->mTurnLeftButton  ->setToggleState( gAgentCamera.getYawKey() > 0.f );
+		floater_move->mTurnRightButton ->setToggleState( gAgentCamera.getYawKey() < 0.f );
+		floater_move->mMoveUpButton    ->setToggleState( gAgentCamera.getUpKey() > 0 );
+		floater_move->mMoveDownButton  ->setToggleState( gAgentCamera.getUpKey() < 0 );
 	}
 
 	// handle rotation based on keyboard levels
 	const F32 YAW_RATE = 90.f * DEG_TO_RAD;				// radians per second
-	yaw(YAW_RATE * mYawKey * dt);
+	yaw(YAW_RATE * gAgentCamera.getYawKey() * dt);
 
 	const F32 PITCH_RATE = 90.f * DEG_TO_RAD;			// radians per second
-	pitch(PITCH_RATE * mPitchKey * dt);
+	pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt);
 	
 	// handle auto-land behavior
 	if (isAgentAvatarValid())
@@ -1560,7 +1533,7 @@ void LLAgent::propagate(const F32 dt)
 		land_vel.mV[VZ] = 0.f;
 
 		if (!in_air 
-			&& mUpKey < 0 
+			&& gAgentCamera.getUpKey() < 0 
 			&& land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED
 			&& gSavedSettings.getBOOL("AutomaticFly"))
 		{
@@ -1569,13 +1542,7 @@ void LLAgent::propagate(const F32 dt)
 		}
 	}
 
-	// clear keys
-	mAtKey = 0;
-	mWalkKey = 0;
-	mLeftKey = 0;
-	mUpKey = 0;
-	mYawKey = 0.f;
-	mPitchKey = 0.f;
+	gAgentCamera.clearGeneralKeys();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index 55d9b292d7a..ab4eee8d7d2 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -434,19 +434,6 @@ class LLAgent : public LLOldEvents::LLObservable
  **                                                                            **
  **                    MOVEMENT
  **/
-	
-	//--------------------------------------------------------------------
-	// Keys
-	//--------------------------------------------------------------------
-public:
-	void			setKey(const S32 direction, S32 &key); // Sets key to +1 for +direction, -1 for -direction
-private:
-	S32 			mAtKey;				// Either 1, 0, or -1. Indicates that movement key is pressed
-	S32				mWalkKey; 			// Like AtKey, but causes less forward thrust
-	S32 			mLeftKey;
-	S32				mUpKey;
-	F32				mYawKey;
-	F32				mPitchKey;
 
 	//--------------------------------------------------------------------
 	// Movement from user input
diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp
index 8ff55cafca8..394c07b0f4e 100644
--- a/indra/newview/llagentcamera.cpp
+++ b/indra/newview/llagentcamera.cpp
@@ -35,6 +35,7 @@
 
 #include "pipeline.h"
 
+// SERAPH clean this up
 #include "llagentlistener.h"
 #include "llagentwearables.h"
 #include "llagentui.h"
@@ -181,6 +182,13 @@ LLAgentCamera::LLAgentCamera() :
 	mTrackFocusObject(TRUE),
 	mUIOffset(0.f),
 
+	mAtKey(0), // Either 1, 0, or -1... indicates that movement-key is pressed
+	mWalkKey(0), // like AtKey, but causes less forward thrust
+	mLeftKey(0),
+	mUpKey(0),
+	mYawKey(0.f),
+	mPitchKey(0.f),
+
 	mOrbitLeftKey(0.f),
 	mOrbitRightKey(0.f),
 	mOrbitUpKey(0.f),
@@ -196,6 +204,10 @@ LLAgentCamera::LLAgentCamera() :
 	mPanOutKey(0.f)
 {
 	mFollowCam.setMaxCameraDistantFromSubject( MAX_CAMERA_DISTANCE_FROM_AGENT );
+
+	clearGeneralKeys();
+	clearOrbitKeys();
+	clearPanKeys();
 }
 
 // Requires gSavedSettings to be initialized.
@@ -1204,17 +1216,15 @@ void LLAgentCamera::updateCamera()
 	LLFloaterCamera* camera_floater = LLFloaterReg::findTypedInstance<LLFloaterCamera>("camera");
 	if (camera_floater)
 	{
-		camera_floater->mRotate->setToggleState(
-		mOrbitRightKey > 0.f,	// left
-		mOrbitUpKey > 0.f,		// top
-		mOrbitLeftKey > 0.f,	// right
-		mOrbitDownKey > 0.f);	// bottom
-
-		camera_floater->mTrack->setToggleState(
-		mPanLeftKey > 0.f,		// left
-		mPanUpKey > 0.f,		// top
-		mPanRightKey > 0.f,		// right
-		mPanDownKey > 0.f);		// bottom
+		camera_floater->mRotate->setToggleState(gAgentCamera.getOrbitRightKey() > 0.f,	// left
+												gAgentCamera.getOrbitUpKey() > 0.f,		// top
+												gAgentCamera.getOrbitLeftKey() > 0.f,	// right
+												gAgentCamera.getOrbitDownKey() > 0.f);	// bottom
+		
+		camera_floater->mTrack->setToggleState(gAgentCamera.getPanLeftKey() > 0.f,		// left
+											   gAgentCamera.getPanUpKey() > 0.f,			// top
+											   gAgentCamera.getPanRightKey() > 0.f,		// right
+											   gAgentCamera.getPanDownKey() > 0.f);		// bottom
 	}
 
 	// Handle camera movement based on keyboard.
@@ -1222,21 +1232,21 @@ void LLAgentCamera::updateCamera()
 	const F32 ORBIT_AROUND_RATE = 90.f * DEG_TO_RAD;		// radians per second
 	const F32 PAN_RATE = 5.f;								// meters per second
 
-	if( mOrbitUpKey || mOrbitDownKey )
+	if (gAgentCamera.getOrbitUpKey() || gAgentCamera.getOrbitDownKey())
 	{
-		F32 input_rate = mOrbitUpKey - mOrbitDownKey;
+		F32 input_rate = gAgentCamera.getOrbitUpKey() - gAgentCamera.getOrbitDownKey();
 		cameraOrbitOver( input_rate * ORBIT_OVER_RATE / gFPSClamped );
 	}
 
-	if( mOrbitLeftKey || mOrbitRightKey)
+	if (gAgentCamera.getOrbitLeftKey() || gAgentCamera.getOrbitRightKey())
 	{
-		F32 input_rate = mOrbitLeftKey - mOrbitRightKey;
-		cameraOrbitAround( input_rate * ORBIT_AROUND_RATE / gFPSClamped );
+		F32 input_rate = gAgentCamera.getOrbitLeftKey() - gAgentCamera.getOrbitRightKey();
+		cameraOrbitAround(input_rate * ORBIT_AROUND_RATE / gFPSClamped);
 	}
 
-	if( mOrbitInKey || mOrbitOutKey )
+	if (gAgentCamera.getOrbitInKey() || gAgentCamera.getOrbitOutKey())
 	{
-		F32 input_rate = mOrbitInKey - mOrbitOutKey;
+		F32 input_rate = gAgentCamera.getOrbitInKey() - gAgentCamera.getOrbitOutKey();
 		
 		LLVector3d to_focus = gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin()) - calcFocusPositionTargetGlobal();
 		F32 distance_to_focus = (F32)to_focus.magVec();
@@ -1244,38 +1254,27 @@ void LLAgentCamera::updateCamera()
 		cameraOrbitIn( input_rate * distance_to_focus / gFPSClamped );
 	}
 
-	if( mPanInKey || mPanOutKey )
+	if (gAgentCamera.getPanInKey() || gAgentCamera.getPanOutKey())
 	{
-		F32 input_rate = mPanInKey - mPanOutKey;
-		cameraPanIn( input_rate * PAN_RATE / gFPSClamped );
+		F32 input_rate = gAgentCamera.getPanInKey() - gAgentCamera.getPanOutKey();
+		cameraPanIn(input_rate * PAN_RATE / gFPSClamped);
 	}
 
-	if( mPanRightKey || mPanLeftKey )
+	if (gAgentCamera.getPanRightKey() || gAgentCamera.getPanLeftKey())
 	{
-		F32 input_rate = mPanRightKey - mPanLeftKey;
-		cameraPanLeft( input_rate * -PAN_RATE / gFPSClamped );
+		F32 input_rate = gAgentCamera.getPanRightKey() - gAgentCamera.getPanLeftKey();
+		cameraPanLeft(input_rate * -PAN_RATE / gFPSClamped );
 	}
 
-	if( mPanUpKey || mPanDownKey )
+	if (gAgentCamera.getPanUpKey() || gAgentCamera.getPanDownKey())
 	{
-		F32 input_rate = mPanUpKey - mPanDownKey;
-		cameraPanUp( input_rate * PAN_RATE / gFPSClamped );
+		F32 input_rate = gAgentCamera.getPanUpKey() - gAgentCamera.getPanDownKey();
+		cameraPanUp(input_rate * PAN_RATE / gFPSClamped );
 	}
 
 	// Clear camera keyboard keys.
-	mOrbitLeftKey		= 0.f;
-	mOrbitRightKey		= 0.f;
-	mOrbitUpKey			= 0.f;
-	mOrbitDownKey		= 0.f;
-	mOrbitInKey			= 0.f;
-	mOrbitOutKey		= 0.f;
-
-	mPanRightKey		= 0.f;
-	mPanLeftKey			= 0.f;
-	mPanUpKey			= 0.f;
-	mPanDownKey			= 0.f;
-	mPanInKey			= 0.f;
-	mPanOutKey			= 0.f;
+	gAgentCamera.clearOrbitKeys();
+	gAgentCamera.clearPanKeys();
 
 	// lerp camera focus offset
 	mCameraFocusOffset = lerp(mCameraFocusOffset, mCameraFocusOffsetTarget, LLCriticalDamp::getInterpolant(CAMERA_FOCUS_HALF_LIFE));
@@ -2850,5 +2849,44 @@ EPointAtType LLAgentCamera::getPointAtType()
 	return POINTAT_TARGET_NONE;
 }
 
+void LLAgentCamera::clearGeneralKeys()
+{
+	mAtKey 				= 0;
+	mWalkKey 			= 0;
+	mLeftKey 			= 0;
+	mUpKey 				= 0;
+	mYawKey 			= 0.f;
+	mPitchKey 			= 0.f;
+}
+
+void LLAgentCamera::clearOrbitKeys()
+{
+	mOrbitLeftKey		= 0.f;
+	mOrbitRightKey		= 0.f;
+	mOrbitUpKey			= 0.f;
+	mOrbitDownKey		= 0.f;
+	mOrbitInKey			= 0.f;
+	mOrbitOutKey		= 0.f;
+}
+
+void LLAgentCamera::clearPanKeys()
+{
+	mPanRightKey		= 0.f;
+	mPanLeftKey			= 0.f;
+	mPanUpKey			= 0.f;
+	mPanDownKey			= 0.f;
+	mPanInKey			= 0.f;
+	mPanOutKey			= 0.f;
+}
+
+// static
+S32 LLAgentCamera::directionToKey(S32 direction)
+{
+	if (direction > 0) return 1;
+	if (direction < 0) return -1;
+	return 0;
+}
+
+
 // EOF
 
diff --git a/indra/newview/llagentcamera.h b/indra/newview/llagentcamera.h
index 2074864336f..9d226aeb811 100644
--- a/indra/newview/llagentcamera.h
+++ b/indra/newview/llagentcamera.h
@@ -175,42 +175,6 @@ class LLAgentCamera
 	LLVector3		mCameraLag;						// Third person camera lag
 	LLVector3		mCameraUpVector;				// Camera's up direction in world coordinates (determines the 'roll' of the view)
 
-	//--------------------------------------------------------------------
-	// Orbit
-	//--------------------------------------------------------------------
-public:
-	void			setOrbitLeftKey(F32 mag)	{ mOrbitLeftKey = mag; }
-	void			setOrbitRightKey(F32 mag)	{ mOrbitRightKey = mag; }
-	void			setOrbitUpKey(F32 mag)		{ mOrbitUpKey = mag; }
-	void			setOrbitDownKey(F32 mag)	{ mOrbitDownKey = mag; }
-	void			setOrbitInKey(F32 mag)		{ mOrbitInKey = mag; }
-	void			setOrbitOutKey(F32 mag)		{ mOrbitOutKey = mag; }
-private:
-	F32				mOrbitLeftKey;
-	F32				mOrbitRightKey;
-	F32				mOrbitUpKey;
-	F32				mOrbitDownKey;
-	F32				mOrbitInKey;
-	F32				mOrbitOutKey;
-
-	//--------------------------------------------------------------------
-	// Pan
-	//--------------------------------------------------------------------
-public:
-	void			setPanLeftKey(F32 mag)		{ mPanLeftKey = mag; }
-	void			setPanRightKey(F32 mag)		{ mPanRightKey = mag; }
-	void			setPanUpKey(F32 mag)		{ mPanUpKey = mag; }
-	void			setPanDownKey(F32 mag)		{ mPanDownKey = mag; }
-	void			setPanInKey(F32 mag)		{ mPanInKey = mag; }
-	void			setPanOutKey(F32 mag)		{ mPanOutKey = mag; }
-private:
-	F32				mPanUpKey;						
-	F32				mPanDownKey;					
-	F32				mPanLeftKey;					
-	F32				mPanRightKey;					
-	F32				mPanInKey;
-	F32				mPanOutKey;	
-	
 	//--------------------------------------------------------------------
 	// Follow
 	//--------------------------------------------------------------------
@@ -358,6 +322,97 @@ class LLAgentCamera
 public:
 	F32				mHUDTargetZoom;	// Target zoom level for HUD objects (used when editing)
 	F32				mHUDCurZoom; 	// Current animated zoom level for HUD objects
+
+
+/********************************************************************************
+ **                                                                            **
+ **                    KEYS
+ **/
+
+public:
+	S32				getAtKey() const		{ return mAtKey; }
+	S32				getWalkKey() const		{ return mWalkKey; }
+	S32				getLeftKey() const		{ return mLeftKey; }
+	F32				getUpKey() const		{ return mUpKey; }
+	F32				getYawKey() const		{ return mYawKey; }
+	F32				getPitchKey() const		{ return mPitchKey; }
+
+	void			setAtKey(S32 mag)		{ mAtKey = mag; }
+	void			setWalkKey(S32 mag)		{ mWalkKey = mag; }
+	void			setLeftKey(S32 mag)		{ mLeftKey = mag; }
+	void			setUpKey(F32 mag)		{ mUpKey = mag; }
+	void			setYawKey(F32 mag)		{ mYawKey = mag; }
+	void			setPitchKey(F32 mag)	{ mPitchKey = mag; }
+
+	void			clearGeneralKeys();
+	static S32		directionToKey(S32 direction); // Changes direction to -1/0/1
+
+private:
+	S32 			mAtKey;				// Either 1, 0, or -1. Indicates that movement key is pressed
+	S32				mWalkKey; 			// Like AtKey, but causes less forward thrust
+	S32 			mLeftKey;
+	S32				mUpKey;
+	F32				mYawKey;
+	F32				mPitchKey;
+
+	//--------------------------------------------------------------------
+	// Orbit
+	//--------------------------------------------------------------------
+public:
+	F32				getOrbitLeftKey() const		{ return mOrbitLeftKey; }
+	F32				getOrbitRightKey() const	{ return mOrbitRightKey; }
+	F32				getOrbitUpKey() const		{ return mOrbitUpKey; }
+	F32				getOrbitDownKey() const		{ return mOrbitDownKey; }
+	F32				getOrbitInKey() const		{ return mOrbitInKey; }
+	F32				getOrbitOutKey() const		{ return mOrbitOutKey; }
+
+	void			setOrbitLeftKey(F32 mag)	{ mOrbitLeftKey = mag; }
+	void			setOrbitRightKey(F32 mag)	{ mOrbitRightKey = mag; }
+	void			setOrbitUpKey(F32 mag)		{ mOrbitUpKey = mag; }
+	void			setOrbitDownKey(F32 mag)	{ mOrbitDownKey = mag; }
+	void			setOrbitInKey(F32 mag)		{ mOrbitInKey = mag; }
+	void			setOrbitOutKey(F32 mag)		{ mOrbitOutKey = mag; }
+
+	void			clearOrbitKeys();
+private:
+	F32				mOrbitLeftKey;
+	F32				mOrbitRightKey;
+	F32				mOrbitUpKey;
+	F32				mOrbitDownKey;
+	F32				mOrbitInKey;
+	F32				mOrbitOutKey;
+
+	//--------------------------------------------------------------------
+	// Pan
+	//--------------------------------------------------------------------
+public:
+	F32				getPanLeftKey() const		{ return mPanLeftKey; }
+	F32				getPanRightKey() const	{ return mPanRightKey; }
+	F32				getPanUpKey() const		{ return mPanUpKey; }
+	F32				getPanDownKey() const		{ return mPanDownKey; }
+	F32				getPanInKey() const		{ return mPanInKey; }
+	F32				getPanOutKey() const		{ return mPanOutKey; }
+
+	void			setPanLeftKey(F32 mag)		{ mPanLeftKey = mag; }
+	void			setPanRightKey(F32 mag)		{ mPanRightKey = mag; }
+	void			setPanUpKey(F32 mag)		{ mPanUpKey = mag; }
+	void			setPanDownKey(F32 mag)		{ mPanDownKey = mag; }
+	void			setPanInKey(F32 mag)		{ mPanInKey = mag; }
+	void			setPanOutKey(F32 mag)		{ mPanOutKey = mag; }
+
+	void			clearPanKeys();
+private:
+	F32				mPanUpKey;						
+	F32				mPanDownKey;					
+	F32				mPanLeftKey;					
+	F32				mPanRightKey;					
+	F32				mPanInKey;
+	F32				mPanOutKey;
+
+/**                    Keys
+ **                                                                            **
+ *******************************************************************************/
+
 };
 
 extern LLAgentCamera gAgentCamera;
-- 
GitLab