Improve readability of vsync and settings update code
This commit is contained in:
+27
-17
@@ -390,7 +390,7 @@ void OverlayController::SetWidget( QQuickItem* quickItem,
|
|||||||
this,
|
this,
|
||||||
SLOT( OnTimeoutPumpEvents() ) );
|
SLOT( OnTimeoutPumpEvents() ) );
|
||||||
|
|
||||||
// was m_pPumpEventsTimer->setInterval( 20 );
|
// Every 1ms we check if the current frame has advanced (for vysnc)
|
||||||
m_pPumpEventsTimer->setInterval( 1 );
|
m_pPumpEventsTimer->setInterval( 1 );
|
||||||
|
|
||||||
m_pPumpEventsTimer->start();
|
m_pPumpEventsTimer->start();
|
||||||
@@ -523,11 +523,27 @@ void OverlayController::processInputBindings()
|
|||||||
m_actions.optionalOverrideRightHandPlayspaceRotate() );
|
m_actions.optionalOverrideRightHandPlayspaceRotate() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vsync implementation:
|
||||||
|
// (this function triggers every 1ms)
|
||||||
void OverlayController::OnTimeoutPumpEvents()
|
void OverlayController::OnTimeoutPumpEvents()
|
||||||
{
|
{
|
||||||
|
// get the current frame number from the VRSystem frame counter
|
||||||
vr::VRSystem()->GetTimeSinceLastVsync( nullptr, &m_currentFrame );
|
vr::VRSystem()->GetTimeSinceLastVsync( nullptr, &m_currentFrame );
|
||||||
|
|
||||||
|
// Check if we are in the next frame yet
|
||||||
if ( m_currentFrame > m_lastFrame )
|
if ( m_currentFrame > m_lastFrame )
|
||||||
|
{
|
||||||
|
// If the frame has advanced since last check, it's time for our main
|
||||||
|
// event loop. (this function should trigger about every 11ms assuming
|
||||||
|
// 90fps compositor)
|
||||||
|
mainEventLoop();
|
||||||
|
|
||||||
|
// wait for the next frame after executing our main event loop once.
|
||||||
|
m_lastFrame = m_currentFrame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverlayController::mainEventLoop()
|
||||||
{
|
{
|
||||||
if ( !vr::VRSystem() )
|
if ( !vr::VRSystem() )
|
||||||
return;
|
return;
|
||||||
@@ -544,12 +560,10 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
{
|
{
|
||||||
case vr::VREvent_MouseMove:
|
case vr::VREvent_MouseMove:
|
||||||
{
|
{
|
||||||
QPoint ptNewMouse
|
QPoint ptNewMouse = getMousePositionForEvent( vrEvent.data.mouse );
|
||||||
= getMousePositionForEvent( vrEvent.data.mouse );
|
|
||||||
if ( ptNewMouse != m_ptLastMouse )
|
if ( ptNewMouse != m_ptLastMouse )
|
||||||
{
|
{
|
||||||
QMouseEvent mouseEvent(
|
QMouseEvent mouseEvent( QEvent::MouseMove,
|
||||||
QEvent::MouseMove,
|
|
||||||
ptNewMouse,
|
ptNewMouse,
|
||||||
m_pWindow->mapToGlobal( ptNewMouse ),
|
m_pWindow->mapToGlobal( ptNewMouse ),
|
||||||
Qt::NoButton,
|
Qt::NoButton,
|
||||||
@@ -564,8 +578,7 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
|
|
||||||
case vr::VREvent_MouseButtonDown:
|
case vr::VREvent_MouseButtonDown:
|
||||||
{
|
{
|
||||||
QPoint ptNewMouse
|
QPoint ptNewMouse = getMousePositionForEvent( vrEvent.data.mouse );
|
||||||
= getMousePositionForEvent( vrEvent.data.mouse );
|
|
||||||
Qt::MouseButton button
|
Qt::MouseButton button
|
||||||
= vrEvent.data.mouse.button == vr::VRMouseButton_Right
|
= vrEvent.data.mouse.button == vr::VRMouseButton_Right
|
||||||
? Qt::RightButton
|
? Qt::RightButton
|
||||||
@@ -583,8 +596,7 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
|
|
||||||
case vr::VREvent_MouseButtonUp:
|
case vr::VREvent_MouseButtonUp:
|
||||||
{
|
{
|
||||||
QPoint ptNewMouse
|
QPoint ptNewMouse = getMousePositionForEvent( vrEvent.data.mouse );
|
||||||
= getMousePositionForEvent( vrEvent.data.mouse );
|
|
||||||
Qt::MouseButton button
|
Qt::MouseButton button
|
||||||
= vrEvent.data.mouse.button == vr::VRMouseButton_Right
|
= vrEvent.data.mouse.button == vr::VRMouseButton_Right
|
||||||
? Qt::RightButton
|
? Qt::RightButton
|
||||||
@@ -702,8 +714,8 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
== vr::TrackingResult_Running_OK )
|
== vr::TrackingResult_Running_OK )
|
||||||
{
|
{
|
||||||
auto& vel = devicePoses[leftId].vVelocity.v;
|
auto& vel = devicePoses[leftId].vVelocity.v;
|
||||||
leftSpeed = std::sqrt( vel[0] * vel[0] + vel[1] * vel[1]
|
leftSpeed
|
||||||
+ vel[2] * vel[2] );
|
= std::sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] );
|
||||||
}
|
}
|
||||||
auto rightId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
|
auto rightId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
|
||||||
vr::TrackedControllerRole_RightHand );
|
vr::TrackedControllerRole_RightHand );
|
||||||
@@ -714,8 +726,8 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
== vr::TrackingResult_Running_OK )
|
== vr::TrackingResult_Running_OK )
|
||||||
{
|
{
|
||||||
auto& vel = devicePoses[rightId].vVelocity.v;
|
auto& vel = devicePoses[rightId].vVelocity.v;
|
||||||
rightSpeed = std::sqrt( vel[0] * vel[0] + vel[1] * vel[1]
|
rightSpeed
|
||||||
+ vel[2] * vel[2] );
|
= std::sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] );
|
||||||
}
|
}
|
||||||
auto hmdSpeed = 0.0f;
|
auto hmdSpeed = 0.0f;
|
||||||
if ( devicePoses[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid
|
if ( devicePoses[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid
|
||||||
@@ -723,8 +735,8 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
== vr::TrackingResult_Running_OK )
|
== vr::TrackingResult_Running_OK )
|
||||||
{
|
{
|
||||||
auto& vel = devicePoses[vr::k_unTrackedDeviceIndex_Hmd].vVelocity.v;
|
auto& vel = devicePoses[vr::k_unTrackedDeviceIndex_Hmd].vVelocity.v;
|
||||||
hmdSpeed = std::sqrt( vel[0] * vel[0] + vel[1] * vel[1]
|
hmdSpeed
|
||||||
+ vel[2] * vel[2] );
|
= std::sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] );
|
||||||
}
|
}
|
||||||
m_moveCenterTabController.eventLoopTick(
|
m_moveCenterTabController.eventLoopTick(
|
||||||
vr::VRCompositor()->GetTrackingSpace(), devicePoses );
|
vr::VRCompositor()->GetTrackingSpace(), devicePoses );
|
||||||
@@ -756,8 +768,6 @@ void OverlayController::OnTimeoutPumpEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_lastFrame = m_currentFrame;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayController::AddOffsetToUniverseCenter(
|
void OverlayController::AddOffsetToUniverseCenter(
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ public:
|
|||||||
|
|
||||||
bool pollNextEvent( vr::VROverlayHandle_t ulOverlayHandle,
|
bool pollNextEvent( vr::VROverlayHandle_t ulOverlayHandle,
|
||||||
vr::VREvent_t* pEvent );
|
vr::VREvent_t* pEvent );
|
||||||
|
void mainEventLoop();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void renderOverlay();
|
void renderOverlay();
|
||||||
|
|||||||
@@ -116,6 +116,19 @@ void AccessibilityTabController::eventLoopTick(
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 151 was chosen because it's a prime number (to reduce overlap of
|
||||||
|
// 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 ( settingsUpdateCounter >= 151 )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
if ( parent->isDashboardVisible() )
|
||||||
|
|||||||
@@ -168,6 +168,19 @@ void AudioTabController::eventLoopTick()
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 89 was chosen because it's a prime number (to reduce overlap of
|
||||||
|
// 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 ( settingsUpdateCounter >= 89 )
|
||||||
{
|
{
|
||||||
if ( m_micProximitySensorCanMute )
|
if ( m_micProximitySensorCanMute )
|
||||||
|
|||||||
@@ -649,6 +649,18 @@ void ChaperoneTabController::eventLoopTick(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 101 was chosen because it's a prime number (to reduce overlap of
|
||||||
|
// 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 ( settingsUpdateCounter >= 101 )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
if ( parent->isDashboardVisible() )
|
||||||
|
|||||||
@@ -976,6 +976,18 @@ 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
|
||||||
|
// 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 ( settingsUpdateCounter >= 149 )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
if ( parent->isDashboardVisible() )
|
||||||
|
|||||||
@@ -309,6 +309,18 @@ 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
|
||||||
|
// 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 ( settingsUpdateCounter >= 139 )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
if ( parent->isDashboardVisible() )
|
||||||
|
|||||||
@@ -28,6 +28,18 @@ 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
|
||||||
|
// 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 ( settingsUpdateCounter >= 157 )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
if ( parent->isDashboardVisible() )
|
||||||
|
|||||||
@@ -22,6 +22,18 @@ 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
|
||||||
|
// 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 ( settingsUpdateCounter >= 97 )
|
||||||
{
|
{
|
||||||
if ( parent->isDashboardVisible() )
|
if ( parent->isDashboardVisible() )
|
||||||
|
|||||||
@@ -321,6 +321,18 @@ 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
|
||||||
|
// 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 )
|
if ( settingsUpdateCounter >= 19 )
|
||||||
{
|
{
|
||||||
vr::VROverlayHandle_t pOverlayHandle;
|
vr::VROverlayHandle_t pOverlayHandle;
|
||||||
|
|||||||
Reference in New Issue
Block a user