From 95ff7acd6df9c3459a2ac795a012f067b850bee3 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Thu, 21 Mar 2019 01:09:47 -0400 Subject: [PATCH] [Joystick] Do the code better --- indra/newview/llfloaterjoystick.cpp | 19 +++++++++-------- indra/newview/llviewerjoystick.cpp | 32 +++++++++++++++-------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index b2d1d63fa..e4f594fa0 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -59,26 +59,29 @@ LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) void LLFloaterJoystick::draw() { + // Singu TODO: Cache these children, or consider not doing this in the draw call bool joystick_inited = LLViewerJoystick::getInstance()->isJoystickInitialized(); childSetEnabled("enable_joystick", joystick_inited); - childSetEnabled("joystick_type", joystick_inited); + auto type(getChild("joystick_type")); + type->setEnabled(joystick_inited); std::string desc = LLViewerJoystick::getInstance()->getDescription(); if (desc.empty()) desc = getString("NoDevice"); - childSetText("joystick_type", desc); + type->setValue(desc); LLViewerJoystick* joystick(LLViewerJoystick::getInstance()); - for (U32 i = 0; i < 6; i++) + for (U32 i = 0; i < 6; ++i) { F32 value = joystick->getJoystickAxis(i); mAxisStats[i]->addValue(value * gFrameIntervalSeconds); - - if (mAxisStatsBar[i]->mMinBar > value) + auto& bar = mAxisStatsBar[i]; + + if (bar->mMinBar > value) { - mAxisStatsBar[i]->mMinBar = value; + bar->mMinBar = value; } - if (mAxisStatsBar[i]->mMaxBar < value) + if (bar->mMaxBar < value) { - mAxisStatsBar[i]->mMaxBar = value; + bar->mMaxBar = value; } } diff --git a/indra/newview/llviewerjoystick.cpp b/indra/newview/llviewerjoystick.cpp index aa2099066..8d0456495 100644 --- a/indra/newview/llviewerjoystick.cpp +++ b/indra/newview/llviewerjoystick.cpp @@ -47,15 +47,15 @@ // ---------------------------------------------------------------------------- // Constants -#define X_I 1 -#define Y_I 2 -#define Z_I 0 -#define RX_I 4 -#define RY_I 5 -#define RZ_I 3 +constexpr auto X_I = 1; +constexpr auto Y_I = 2; +constexpr auto Z_I = 0; +constexpr auto RX_I = 4; +constexpr auto RY_I = 5; +constexpr auto RZ_I = 3; // minimum time after setting away state before coming back -const F32 MIN_AFK_TIME = 2.f; +constexpr F32 MIN_AFK_TIME = 2.f; F32 LLViewerJoystick::sLastDelta[] = {0,0,0,0,0,0,0}; F32 LLViewerJoystick::sDelta[] = {0,0,0,0,0,0,0}; @@ -113,11 +113,13 @@ enum DS3Keys S32 get_joystick_type() { - if (sType == SPACE_NAV) return 0; - if (sType == XBOX) return isOUYA(LLViewerJoystick::getInstance()->getDescription()) ? 1 : 2; - if (sType == DS3) return 3; - - return -1; // sType == NONE || sType == UNKNOWN + switch (sType) + { + case SPACE_NAV: return 0; + case XBOX: return isOUYA(LLViewerJoystick::getInstance()->getDescription()) ? 1 : 2; + case DS3: return 3; + default: return -1; // sType == NONE || sType == UNKNOWN + } } // @@ -126,8 +128,8 @@ S32 get_joystick_type() // should be. It has to be equal to 3000 because the SpaceNavigator on Windows // refuses to respond to the DirectInput SetProperty call; it always returns // values in the [-3000, 3000] range. -#define MAX_SPACENAVIGATOR_INPUT 3000.0f -#define MAX_JOYSTICK_INPUT_VALUE MAX_SPACENAVIGATOR_INPUT +constexpr auto MAX_SPACENAVIGATOR_INPUT = 3000.0f; +constexpr auto MAX_JOYSTICK_INPUT_VALUE = MAX_SPACENAVIGATOR_INPUT; // ----------------------------------------------------------------------------- void LLViewerJoystick::updateEnabled(bool autoenable) @@ -1390,7 +1392,7 @@ void LLViewerJoystick::setSNDefaults(S32 type) const float platformScaleAvXZ = 2.f; const bool is_3d_cursor = true; #endif - + //gViewerWindow->alertXml("CacheWillClear"); const bool ouya = type == 1; const bool xbox = ouya || type == 2;