Replace magic numbers, fix bindings localization

Replace magic numbers with constants and centralize settings update counters. Rename actions manifest localization from "en" to "en_US" (Thanks Ykeara)
This commit is contained in:
Kung-vr
2019-01-30 15:11:11 +09:00
parent 1d058dffcf
commit 31696863be
11 changed files with 56 additions and 136 deletions
+14
View File
@@ -55,6 +55,20 @@ public:
static constexpr const char* applicationKey = "matzman666.AdvancedSettings"; static constexpr const char* applicationKey = "matzman666.AdvancedSettings";
static constexpr const char* applicationDisplayName = "Advanced Settings"; static constexpr const char* applicationDisplayName = "Advanced Settings";
static constexpr const char* applicationVersionString = "v2.8.0-dev"; static constexpr const char* applicationVersionString = "v2.8.0-dev";
// These counters set timing for refreshing settings changes in tab ui
// SettingsUpdateCounter values are set as prime numbers to reduce overlap
// of simultaneous settings updates.
// Actual rates of updates are counter * vsync (~11ms)
// Values chosen based on update speed priority
// Avoid setting values to the same numbers.
static constexpr int k_accessibilitySettingsUpdateCounter = 151;
static constexpr int k_audioSettingsUpdateCounter = 89;
static constexpr int k_chaperoneSettingsUpdateCounter = 101;
static constexpr int k_moveCenterSettingsUpdateCounter = 149;
static constexpr int k_reviveSettingsUpdateCounter = 139;
static constexpr int k_settingsTabSettingsUpdateCounter = 157;
static constexpr int k_steamVrSettingsUpdateCounter = 97;
static constexpr int k_utilitiesSettingsUpdateCounter = 19;
private: private:
vr::VROverlayHandle_t m_ulOverlayHandle = vr::k_ulOverlayHandleInvalid; vr::VROverlayHandle_t m_ulOverlayHandle = vr::k_ulOverlayHandleInvalid;
+1 -1
View File
@@ -75,7 +75,7 @@
], ],
"localization" : [ "localization" : [
{ {
"language_tag": "en", "language_tag": "en_US",
"/actions/main" : "Advanced Settings Actions", "/actions/main" : "Advanced Settings Actions",
@@ -117,19 +117,7 @@ void AccessibilityTabController::eventLoopTick(
return; return;
} }
// 151 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_accessibilitySettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 151 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AudioTabController: 89
// ChaperoneTabController: 101
// MoveCenterTabController: 149
// ReviveTabController: 139
// SettingsTabController: 157
// SteamVRTabController: 97
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 151 )
{ {
if ( parent->isDashboardVisible() ) if ( parent->isDashboardVisible() )
{ {
+1 -13
View File
@@ -169,19 +169,7 @@ void AudioTabController::eventLoopTick()
return; return;
} }
// 89 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_audioSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 89 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// ChaperoneTabController: 101
// MoveCenterTabController: 149
// ReviveTabController: 139
// SettingsTabController: 157
// SteamVRTabController: 97
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 89 )
{ {
if ( m_micProximitySensorCanMute ) if ( m_micProximitySensorCanMute )
{ {
+1 -13
View File
@@ -649,19 +649,7 @@ void ChaperoneTabController::eventLoopTick(
} }
} }
// 101 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_chaperoneSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 101 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// AudioTabController: 89
// MoveCenterTabController: 149
// ReviveTabController: 139
// SettingsTabController: 157
// SteamVRTabController: 97
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 101 )
{ {
if ( parent->isDashboardVisible() ) if ( parent->isDashboardVisible() )
{ {
+27 -37
View File
@@ -148,7 +148,7 @@ void MoveCenterTabController::setRotation( int value, bool notify )
{ {
if ( m_rotation != value ) if ( m_rotation != value )
{ {
double angle = ( value - m_rotation ) * M_PI / 18000.0; double angle = ( value - m_rotation ) * k_centidegreesToRadians;
// Revert now because we don't commit in RotateUniverseCenter and // Revert now because we don't commit in RotateUniverseCenter and
// AddOffsetToUniverseCenter. We do this so rotation and offset can // AddOffsetToUniverseCenter. We do this so rotation and offset can
@@ -173,7 +173,7 @@ void MoveCenterTabController::setRotation( int value, bool notify )
= { oldHmdPos.m[0][3], oldHmdPos.m[1][3], oldHmdPos.m[2][3] }; = { oldHmdPos.m[0][3], oldHmdPos.m[1][3], oldHmdPos.m[2][3] };
// Convert oldHmdXyz into un-rotated coordinates. // Convert oldHmdXyz into un-rotated coordinates.
double oldAngle = -m_rotation * M_PI / 18000.0; double oldAngle = -m_rotation * k_centidegreesToRadians;
rotateCoordinates( oldHmdXyz, oldAngle ); rotateCoordinates( oldHmdXyz, oldAngle );
// Set newHmdXyz to have additional rotation from incoming angle change. // Set newHmdXyz to have additional rotation from incoming angle change.
@@ -201,7 +201,7 @@ void MoveCenterTabController::setRotation( int value, bool notify )
// We use rotated coordinates here because we have already applied // We use rotated coordinates here because we have already applied
// RotateUniverseCenter. This will be the final offset ready to apply, // RotateUniverseCenter. This will be the final offset ready to apply,
// so it must match the current universe axis rotation. // so it must match the current universe axis rotation.
double finalAngle = m_rotation * M_PI / 18000.0; double finalAngle = m_rotation * k_centidegreesToRadians;
double finalHmdRotDiff[3] = { hmdRotDiff[0], 0, hmdRotDiff[2] }; double finalHmdRotDiff[3] = { hmdRotDiff[0], 0, hmdRotDiff[2] };
rotateCoordinates( finalHmdRotDiff, finalAngle ); rotateCoordinates( finalHmdRotDiff, finalAngle );
@@ -259,7 +259,7 @@ void MoveCenterTabController::setAdjustChaperone( bool value, bool notify )
m_adjustChaperone = value; m_adjustChaperone = value;
if ( m_trackingUniverse == vr::TrackingUniverseStanding ) if ( m_trackingUniverse == vr::TrackingUniverseStanding )
{ {
double angle = m_rotation * M_PI / 18000.0; double angle = m_rotation * k_centidegreesToRadians;
double offsetdir = m_adjustChaperone ? -1.0 : 1.0; double offsetdir = m_adjustChaperone ? -1.0 : 1.0;
double offset[3] = { offsetdir * m_offsetX, double offset[3] = { offsetdir * m_offsetX,
offsetdir * m_offsetY, offsetdir * m_offsetY,
@@ -406,7 +406,7 @@ void MoveCenterTabController::modOffsetX( float value, bool notify )
// TODO ? possible issue with locking position this way // TODO ? possible issue with locking position this way
if ( !m_lockXToggle ) if ( !m_lockXToggle )
{ {
double angle = m_rotation * M_PI / 18000.0; double angle = m_rotation * k_centidegreesToRadians;
double offset[3] = { value, 0, 0 }; double offset[3] = { value, 0, 0 };
rotateCoordinates( offset, angle ); rotateCoordinates( offset, angle );
float offsetFloat[3] = { static_cast<float>( offset[0] ), float offsetFloat[3] = { static_cast<float>( offset[0] ),
@@ -445,7 +445,7 @@ void MoveCenterTabController::modOffsetZ( float value, bool notify )
{ {
if ( !m_lockZToggle ) if ( !m_lockZToggle )
{ {
double angle = m_rotation * M_PI / 18000.0; double angle = m_rotation * k_centidegreesToRadians;
double offset[3] = { 0, 0, value }; double offset[3] = { 0, 0, value };
rotateCoordinates( offset, angle ); rotateCoordinates( offset, angle );
float offsetFloat[3] = { static_cast<float>( offset[0] ), float offsetFloat[3] = { static_cast<float>( offset[0] ),
@@ -468,7 +468,7 @@ void MoveCenterTabController::reset()
vr::VRChaperoneSetup()->RevertWorkingCopy(); vr::VRChaperoneSetup()->RevertWorkingCopy();
parent->RotateUniverseCenter( parent->RotateUniverseCenter(
vr::TrackingUniverseOrigin( m_trackingUniverse ), vr::TrackingUniverseOrigin( m_trackingUniverse ),
static_cast<float>( -m_rotation * M_PI / 18000.0 ), static_cast<float>( -m_rotation * k_centidegreesToRadians ),
m_adjustChaperone, m_adjustChaperone,
false ); false );
float offset[3] = { -m_offsetX, -m_offsetY, -m_offsetZ }; float offset[3] = { -m_offsetX, -m_offsetY, -m_offsetZ };
@@ -862,19 +862,7 @@ void MoveCenterTabController::eventLoopTick(
vr::ETrackingUniverseOrigin universe, vr::ETrackingUniverseOrigin universe,
vr::TrackedDevicePose_t* devicePoses ) vr::TrackedDevicePose_t* devicePoses )
{ {
// 149 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_moveCenterSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 149 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// AudioTabController: 89
// ChaperoneTabController: 101
// ReviveTabController: 139
// SettingsTabController: 157
// SteamVRTabController: 97
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 149 )
{ {
if ( parent->isDashboardVisible() ) if ( parent->isDashboardVisible() )
{ {
@@ -887,7 +875,7 @@ void MoveCenterTabController::eventLoopTick(
settingsUpdateCounter++; settingsUpdateCounter++;
} }
double angle = m_rotation * M_PI / 18000.0; double angle = m_rotation * k_centidegreesToRadians;
// START of hmd rotation stats tracking: // START of hmd rotation stats tracking:
// Check if hmd is tracking ok and do everything // Check if hmd is tracking ok and do everything
@@ -907,13 +895,13 @@ void MoveCenterTabController::eventLoopTick(
utils::matMul33( hmdMatrixAbsolute, hmdMatrixRotMat, hmdMatrix ); utils::matMul33( hmdMatrixAbsolute, hmdMatrixRotMat, hmdMatrix );
// Convert pose matrix to quaternion // Convert pose matrix to quaternion
hmdQuaternion = utils::getQuaternion( hmdMatrixAbsolute ); m_hmdQuaternion = utils::getQuaternion( hmdMatrixAbsolute );
// Get rotation change of hmd // Get rotation change of hmd
// Checking if set to -1000.0 placeholder for invalid hmd pose. // Checking if set to -1000.0 placeholder for invalid hmd pose.
if ( lastHmdQuaternion.w < -900.0 ) if ( m_lastHmdQuaternion.w < -900.0 )
{ {
lastHmdQuaternion = hmdQuaternion; m_lastHmdQuaternion = m_hmdQuaternion;
} }
else else
@@ -921,8 +909,8 @@ void MoveCenterTabController::eventLoopTick(
// Construct a quaternion representing difference between old // Construct a quaternion representing difference between old
// hmd pose and new hmd pose. // hmd pose and new hmd pose.
vr::HmdQuaternion_t hmdDiffQuaternion = utils::multiplyQuaternion( vr::HmdQuaternion_t hmdDiffQuaternion = utils::multiplyQuaternion(
hmdQuaternion, m_hmdQuaternion,
utils::quaternionConjugate( lastHmdQuaternion ) ); utils::quaternionConjugate( m_lastHmdQuaternion ) );
// Calculate yaw from quaternion. // Calculate yaw from quaternion.
double hmdYawDiff = atan2( double hmdYawDiff = atan2(
@@ -936,7 +924,7 @@ void MoveCenterTabController::eventLoopTick(
// Apply yaw difference to m_hmdYawTotal. // Apply yaw difference to m_hmdYawTotal.
m_hmdYawTotal += hmdYawDiff; m_hmdYawTotal += hmdYawDiff;
lastHmdQuaternion = hmdQuaternion; m_lastHmdQuaternion = m_hmdQuaternion;
} }
// end check if hmdpose is ok // end check if hmdpose is ok
@@ -944,7 +932,7 @@ void MoveCenterTabController::eventLoopTick(
else else
{ {
// set lastHmdQuaternion.w to placeholder -1000.0 for invalid // set lastHmdQuaternion.w to placeholder -1000.0 for invalid
lastHmdQuaternion.w = -1000.0; m_lastHmdQuaternion.w = -1000.0;
} // END of hmd rotation stats tracking } // END of hmd rotation stats tracking
/* /*
@@ -1077,7 +1065,7 @@ void MoveCenterTabController::eventLoopTick(
{ {
// Set lastHandQuaternion.w to placeholder value for invalid // Set lastHandQuaternion.w to placeholder value for invalid
// (-1000.0) // (-1000.0)
lastHandQuaternion.w = -1000.0; m_lastHandQuaternion.w = -1000.0;
} }
m_lastRotateHand = m_activeTurnHand; m_lastRotateHand = m_activeTurnHand;
} }
@@ -1108,15 +1096,15 @@ void MoveCenterTabController::eventLoopTick(
utils::matMul33( handMatrixAbsolute, handMatrixRotMat, handMatrix ); utils::matMul33( handMatrixAbsolute, handMatrixRotMat, handMatrix );
// Convert pose matrix to quaternion // Convert pose matrix to quaternion
handQuaternion = utils::getQuaternion( handMatrixAbsolute ); m_handQuaternion = utils::getQuaternion( handMatrixAbsolute );
if ( m_lastRotateHand == m_activeTurnHand ) if ( m_lastRotateHand == m_activeTurnHand )
{ {
// Get rotation change of hand. // Get rotation change of hand.
// Checking if set to -1000.0 placeholder for invalid hand. // Checking if set to -1000.0 placeholder for invalid hand.
if ( lastHandQuaternion.w < -900.0 ) if ( m_lastHandQuaternion.w < -900.0 )
{ {
lastHandQuaternion = handQuaternion; m_lastHandQuaternion = m_handQuaternion;
} }
else else
@@ -1125,8 +1113,9 @@ void MoveCenterTabController::eventLoopTick(
// between old hand and new hand. // between old hand and new hand.
vr::HmdQuaternion_t handDiffQuaternion vr::HmdQuaternion_t handDiffQuaternion
= utils::multiplyQuaternion( = utils::multiplyQuaternion(
handQuaternion, m_handQuaternion,
utils::quaternionConjugate( lastHandQuaternion ) ); utils::quaternionConjugate(
m_lastHandQuaternion ) );
// Calculate yaw from quaternion. // Calculate yaw from quaternion.
double handYawDiff = atan2( double handYawDiff = atan2(
@@ -1141,9 +1130,10 @@ void MoveCenterTabController::eventLoopTick(
* handDiffQuaternion.x ) ); * handDiffQuaternion.x ) );
int newRotationAngleDeg = static_cast<int>( int newRotationAngleDeg = static_cast<int>(
round( handYawDiff * 18000.0 / M_PI ) + m_rotation ); round( handYawDiff * k_radiansToCentidegrees )
+ m_rotation );
// Keep angle within -18000 ~ 18000 // Keep angle within -18000 ~ 18000 centidegrees
if ( newRotationAngleDeg > 18000 ) if ( newRotationAngleDeg > 18000 )
{ {
newRotationAngleDeg -= 36000; newRotationAngleDeg -= 36000;
@@ -1156,7 +1146,7 @@ void MoveCenterTabController::eventLoopTick(
setRotation( newRotationAngleDeg ); setRotation( newRotationAngleDeg );
} }
} }
lastHandQuaternion = handQuaternion; m_lastHandQuaternion = m_handQuaternion;
m_lastRotateHand = m_activeTurnHand; m_lastRotateHand = m_activeTurnHand;
} }
} // END of hand rotation } // END of hand rotation
+7 -7
View File
@@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include <openvr.h> #include <openvr.h>
#include <chrono> #include <chrono>
#include <qmath.h>
class QQuickWindow; class QQuickWindow;
// application namespace // application namespace
@@ -65,11 +66,11 @@ private:
bool m_lockZToggle = false; bool m_lockZToggle = false;
std::chrono::system_clock::time_point lastMoveButtonClick[2]; std::chrono::system_clock::time_point lastMoveButtonClick[2];
// Set lastHandQuaternion.w to -1000.0 when last hand is invalid. // Set lastHandQuaternion.w to -1000.0 when last hand is invalid.
vr::HmdQuaternion_t lastHandQuaternion = { -1000.0, 0.0, 0.0, 0.0 }; vr::HmdQuaternion_t m_lastHandQuaternion = { -1000.0, 0.0, 0.0, 0.0 };
vr::HmdQuaternion_t handQuaternion; vr::HmdQuaternion_t m_handQuaternion;
// Set lastHmdQuaternion.w to -1000.0 when last hmd pose is invalid. // Set lastHmdQuaternion.w to -1000.0 when last hmd pose is invalid.
vr::HmdQuaternion_t lastHmdQuaternion = { -1000.0, 0.0, 0.0, 0.0 }; vr::HmdQuaternion_t m_lastHmdQuaternion = { -1000.0, 0.0, 0.0, 0.0 };
vr::HmdQuaternion_t hmdQuaternion; vr::HmdQuaternion_t m_hmdQuaternion;
double m_hmdYawTotal = 0.0; double m_hmdYawTotal = 0.0;
vr::ETrackedControllerRole m_activeDragHand vr::ETrackedControllerRole m_activeDragHand
= vr::TrackedControllerRole_Invalid; = vr::TrackedControllerRole_Invalid;
@@ -87,10 +88,9 @@ private:
bool m_rightHandTurnPressed = false; bool m_rightHandTurnPressed = false;
bool m_overrideLeftHandTurnPressed = false; bool m_overrideLeftHandTurnPressed = false;
bool m_overrideRightHandTurnPressed = false; bool m_overrideRightHandTurnPressed = false;
unsigned settingsUpdateCounter = 0; unsigned settingsUpdateCounter = 0;
static constexpr double k_centidegreesToRadians = M_PI / 18000.0;
// vr::ETrackedControllerRole getMoveShortcutHand(); static constexpr double k_radiansToCentidegrees = 18000.0 / M_PI;
public: public:
void initStage1(); void initStage1();
+1 -13
View File
@@ -309,19 +309,7 @@ void ReviveTabController::eventLoopTick()
if ( m_isOverlayInstalled if ( m_isOverlayInstalled
|| parent->m_settingsTabController.forceRevivePage() ) || parent->m_settingsTabController.forceRevivePage() )
{ {
// 139 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_reviveSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 139 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// AudioTabController: 89
// ChaperoneTabController: 101
// MoveCenterTabController: 149
// SettingsTabController: 157
// SteamVRTabController: 97
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 139 )
{ {
if ( parent->isDashboardVisible() ) if ( parent->isDashboardVisible() )
{ {
+1 -13
View File
@@ -28,19 +28,7 @@ void SettingsTabController::initStage2( OverlayController* var_parent,
void SettingsTabController::eventLoopTick() void SettingsTabController::eventLoopTick()
{ {
// 157 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_settingsTabSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 157 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// AudioTabController: 89
// ChaperoneTabController: 101
// MoveCenterTabController: 149
// ReviveTabController: 139
// SteamVRTabController: 97
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 157 )
{ {
if ( parent->isDashboardVisible() ) if ( parent->isDashboardVisible() )
{ {
+1 -13
View File
@@ -22,19 +22,7 @@ void SteamVRTabController::initStage2( OverlayController* var_parent,
void SteamVRTabController::eventLoopTick() void SteamVRTabController::eventLoopTick()
{ {
// 97 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_steamVrSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 97 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// AudioTabController: 89
// ChaperoneTabController: 101
// MoveCenterTabController: 149
// ReviveTabController: 139
// SettingsTabController: 157
// UtilitiesTabController: 19
if ( settingsUpdateCounter >= 97 )
{ {
if ( parent->isDashboardVisible() ) if ( parent->isDashboardVisible() )
{ {
+1 -13
View File
@@ -321,19 +321,7 @@ vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index )
void UtilitiesTabController::eventLoopTick() void UtilitiesTabController::eventLoopTick()
{ {
// 19 was chosen because it's a prime number (to reduce overlap of if ( settingsUpdateCounter >= parent->k_utilitiesSettingsUpdateCounter )
// simultaneous settings updates).
// Actual rate of updates is 19 * vsync (~11ms)
// Values chosen based on update speed priority
// Values in other tabs are as follows (avoid using same values):
// AccessibiltyTabController: 151
// AudioTabController: 89
// ChaperoneTabController: 101
// MoveCenterTabController: 149
// ReviveTabController: 139
// SettingsTabController: 157
// SteamVRTabController: 97
if ( settingsUpdateCounter >= 19 )
{ {
vr::VROverlayHandle_t pOverlayHandle; vr::VROverlayHandle_t pOverlayHandle;
auto error = vr::VROverlay()->FindOverlay( steamDesktopOverlaykey, auto error = vr::VROverlay()->FindOverlay( steamDesktopOverlaykey,