From 236fa2a2842341d767e822425bf4a9acd07b8faa Mon Sep 17 00:00:00 2001 From: Inusaito Sayori Date: Fri, 24 Jan 2014 22:57:19 -0500 Subject: [PATCH] Fix Issue 870: Crouch toggle not reset when pressing "Fly" button, causes avatar to run/fly downhill. Reimplements crouch toggle such that crouch is now tracked by the agent object Fixes crouch being reset when restoring focus to the viewer window, as well. --- indra/newview/llagent.cpp | 10 +++++++++- indra/newview/llagent.h | 9 +++++++++ indra/newview/llappviewer.cpp | 2 +- indra/newview/llviewerkeyboard.cpp | 9 ++------- indra/newview/llviewerkeyboard.h | 1 - 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 78c5c666e..cdacbeb94 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -420,6 +420,7 @@ LLAgent::LLAgent() : mNextFidgetTime(0.f), mCurrentFidget(0), + mCrouch(false), mFirstLogin(FALSE), mGenderChosen(FALSE), mAppearanceSerialNum(0), @@ -639,13 +640,14 @@ void LLAgent::moveUp(S32 direction) if (direction > 0) { setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP); + mCrouch = false; } else if (direction < 0) { setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP); } - if (!isCrouch) camera_reset_on_motion(); + if (!mCrouch) camera_reset_on_motion(); } //----------------------------------------------------------------------------- @@ -687,6 +689,11 @@ void LLAgent::movePitch(F32 mag) } } +bool LLAgent::isCrouching() const +{ + return mCrouch && !getFlying(); // Never crouch when flying +} + // Does this parcel allow you to fly? BOOL LLAgent::canFly() @@ -770,6 +777,7 @@ void LLAgent::setFlying(BOOL fly) { LLViewerStats::getInstance()->incStat(LLViewerStats::ST_FLY_COUNT); } + mCrouch = false; setControlFlags(AGENT_CONTROL_FLY); } else diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h index 26501953a..a66b375f4 100644 --- a/indra/newview/llagent.h +++ b/indra/newview/llagent.h @@ -302,6 +302,15 @@ private: F32 mNextFidgetTime; S32 mCurrentFidget; + //-------------------------------------------------------------------- + // Crouch + //-------------------------------------------------------------------- +public: + bool isCrouching() const; + void toggleCrouch() { mCrouch = !mCrouch; } +private: + bool mCrouch; + //-------------------------------------------------------------------- // Fly //-------------------------------------------------------------------- diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 32501de62..eb1a28576 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -1220,7 +1220,7 @@ bool LLAppViewer::mainLoop() { joystick->scanJoystick(); gKeyboard->scanKeyboard(); - if(isCrouch) + if (gAgent.isCrouching()) { gAgent.moveUp(-1); } diff --git a/indra/newview/llviewerkeyboard.cpp b/indra/newview/llviewerkeyboard.cpp index 1c8b3b629..8c899a4ae 100644 --- a/indra/newview/llviewerkeyboard.cpp +++ b/indra/newview/llviewerkeyboard.cpp @@ -61,14 +61,11 @@ const F32 YAW_NUDGE_RATE = 0.05f; // fraction of normal speed LLViewerKeyboard gViewerKeyboard; -bool isCrouch = false; //Shouldn't start crouched. - void agent_jump( EKeystate s ) { if( KEYSTATE_UP == s ) return; F32 time = gKeyboard->getCurKeyElapsedTime(); S32 frame_count = llround(gKeyboard->getCurKeyElapsedFrameCount()); - isCrouch = false; if( time < FLY_TIME || frame_count <= FLY_FRAMES || gAgent.upGrabbed() @@ -86,18 +83,17 @@ void agent_toggle_down( EKeystate s ) { if(KEYSTATE_UP == s) return; - gAgent.moveUp(-1); if(KEYSTATE_DOWN == s && !gAgent.getFlying() && gSavedSettings.getBOOL("SGShiftCrouchToggle")) { - isCrouch = !isCrouch; + gAgent.toggleCrouch(); } + gAgent.moveUp(-1); } void agent_push_down( EKeystate s ) { if( KEYSTATE_UP == s ) return; gAgent.moveUp(-1); - isCrouch = false; } static void agent_handle_doubletap_run(EKeystate s, LLAgent::EDoubleTapRunMode mode) @@ -247,7 +243,6 @@ void agent_toggle_fly( EKeystate s ) if (KEYSTATE_DOWN == s ) { gAgent.toggleFlying(); - isCrouch = false; } } diff --git a/indra/newview/llviewerkeyboard.h b/indra/newview/llviewerkeyboard.h index e3ef315b5..2be702fee 100644 --- a/indra/newview/llviewerkeyboard.h +++ b/indra/newview/llviewerkeyboard.h @@ -93,6 +93,5 @@ protected: }; extern LLViewerKeyboard gViewerKeyboard; -extern bool isCrouch; void agent_push_forward(EKeystate s); #endif // LL_LLVIEWERKEYBOARD_H