Implemented vsync tick for event loops

This commit is contained in:
Kung-vr
2019-01-14 03:24:15 +09:00
parent 733f4f8dc0
commit 53138c5fef
11 changed files with 531 additions and 479 deletions
+33 -24
View File
@@ -495,7 +495,7 @@ void OverlayController::SetWidget( QQuickItem* quickItem,
SLOT( OnTimeoutPumpEvents() ) ); SLOT( OnTimeoutPumpEvents() ) );
// was m_pPumpEventsTimer->setInterval( 20 ); // was m_pPumpEventsTimer->setInterval( 20 );
m_pPumpEventsTimer->setInterval( 5 ); m_pPumpEventsTimer->setInterval( 1 );
m_pPumpEventsTimer->start(); m_pPumpEventsTimer->start();
@@ -579,6 +579,10 @@ QPoint OverlayController::getMousePositionForEvent( vr::VREvent_Mouse_t mouse )
} }
void OverlayController::OnTimeoutPumpEvents() void OverlayController::OnTimeoutPumpEvents()
{
vr::VRSystem()->GetTimeSinceLastVsync( nullptr, &m_currentFrame );
if ( m_currentFrame > m_lastFrame )
{ {
if ( !vr::VRSystem() ) if ( !vr::VRSystem() )
return; return;
@@ -591,10 +595,12 @@ void OverlayController::OnTimeoutPumpEvents()
{ {
case vr::VREvent_MouseMove: case vr::VREvent_MouseMove:
{ {
QPoint ptNewMouse = getMousePositionForEvent( vrEvent.data.mouse ); QPoint ptNewMouse
= getMousePositionForEvent( vrEvent.data.mouse );
if ( ptNewMouse != m_ptLastMouse ) if ( ptNewMouse != m_ptLastMouse )
{ {
QMouseEvent mouseEvent( QEvent::MouseMove, QMouseEvent mouseEvent(
QEvent::MouseMove,
ptNewMouse, ptNewMouse,
m_pWindow->mapToGlobal( ptNewMouse ), m_pWindow->mapToGlobal( ptNewMouse ),
Qt::NoButton, Qt::NoButton,
@@ -609,7 +615,8 @@ void OverlayController::OnTimeoutPumpEvents()
case vr::VREvent_MouseButtonDown: case vr::VREvent_MouseButtonDown:
{ {
QPoint ptNewMouse = getMousePositionForEvent( vrEvent.data.mouse ); QPoint ptNewMouse
= 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
@@ -627,7 +634,8 @@ void OverlayController::OnTimeoutPumpEvents()
case vr::VREvent_MouseButtonUp: case vr::VREvent_MouseButtonUp:
{ {
QPoint ptNewMouse = getMousePositionForEvent( vrEvent.data.mouse ); QPoint ptNewMouse
= 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
@@ -669,8 +677,8 @@ void OverlayController::OnTimeoutPumpEvents()
case vr::VREvent_Quit: case vr::VREvent_Quit:
{ {
LOG( INFO ) << "Received quit request."; LOG( INFO ) << "Received quit request.";
vr::VRSystem()->AcknowledgeQuit_Exiting(); // Let us buy some time vr::VRSystem()->AcknowledgeQuit_Exiting(); // Let us buy some
// just in case // time just in case
m_moveCenterTabController.reset(); m_moveCenterTabController.reset();
m_chaperoneTabController.shutdown(); m_chaperoneTabController.shutdown();
Shutdown(); Shutdown();
@@ -702,12 +710,11 @@ void OverlayController::OnTimeoutPumpEvents()
} }
break; break;
// Multiple ChaperoneUniverseHasChanged are often emitted at the same // Multiple ChaperoneUniverseHasChanged are often emitted at the
// time (some with a little bit of delay) There is no sure way to // same time (some with a little bit of delay) There is no sure way
// recognize redundant events, we can only exclude redundant events // to recognize redundant events, we can only exclude redundant
// during the same call of OnTimeoutPumpEvents() // events during the same call of OnTimeoutPumpEvents() INFO Removed
// INFO Removed logging on play space mover for possible crashing // logging on play space mover for possible crashing issues.
// issues.
case vr::VREvent_ChaperoneUniverseHasChanged: case vr::VREvent_ChaperoneUniverseHasChanged:
case vr::VREvent_ChaperoneDataHasChanged: case vr::VREvent_ChaperoneDataHasChanged:
{ {
@@ -715,8 +722,8 @@ void OverlayController::OnTimeoutPumpEvents()
{ {
// LOG(INFO) << "Re-loading chaperone data ..."; // LOG(INFO) << "Re-loading chaperone data ...";
m_chaperoneUtils.loadChaperoneData(); m_chaperoneUtils.loadChaperoneData();
// LOG(INFO) << "Found " << m_chaperoneUtils.quadsCount() << " // LOG(INFO) << "Found " << m_chaperoneUtils.quadsCount() <<
// chaperone quads."; if // " chaperone quads."; if
// (m_chaperoneUtils.isChaperoneWellFormed()) { LOG(INFO) << // (m_chaperoneUtils.isChaperoneWellFormed()) { LOG(INFO) <<
// "Chaperone data seems to be well-formed."; // "Chaperone data seems to be well-formed.";
//} else { //} else {
@@ -746,8 +753,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 leftSpeed = std::sqrt( vel[0] * vel[0] + vel[1] * vel[1]
= std::sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] ); + vel[2] * vel[2] );
} }
auto rightId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole( auto rightId = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(
vr::TrackedControllerRole_RightHand ); vr::TrackedControllerRole_RightHand );
@@ -758,8 +765,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 rightSpeed = std::sqrt( vel[0] * vel[0] + vel[1] * vel[1]
= std::sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] ); + 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
@@ -767,22 +774,22 @@ 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 hmdSpeed = std::sqrt( vel[0] * vel[0] + vel[1] * vel[1]
= std::sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] ); + vel[2] * vel[2] );
} }
m_moveCenterTabController.eventLoopTick(
vr::VRCompositor()->GetTrackingSpace(), devicePoses );
m_utilitiesTabController.eventLoopTick();
m_fixFloorTabController.eventLoopTick( devicePoses ); m_fixFloorTabController.eventLoopTick( devicePoses );
m_statisticsTabController.eventLoopTick( m_statisticsTabController.eventLoopTick(
devicePoses, leftSpeed, rightSpeed ); devicePoses, leftSpeed, rightSpeed );
m_moveCenterTabController.eventLoopTick(
vr::VRCompositor()->GetTrackingSpace(), devicePoses );
m_steamVRTabController.eventLoopTick(); m_steamVRTabController.eventLoopTick();
m_chaperoneTabController.eventLoopTick( m_chaperoneTabController.eventLoopTick(
devicePoses, leftSpeed, rightSpeed, hmdSpeed ); devicePoses, leftSpeed, rightSpeed, hmdSpeed );
m_settingsTabController.eventLoopTick(); m_settingsTabController.eventLoopTick();
m_reviveTabController.eventLoopTick(); m_reviveTabController.eventLoopTick();
m_audioTabController.eventLoopTick(); m_audioTabController.eventLoopTick();
m_utilitiesTabController.eventLoopTick();
m_accessibilityTabController.eventLoopTick( m_accessibilityTabController.eventLoopTick(
vr::VRCompositor()->GetTrackingSpace() ); vr::VRCompositor()->GetTrackingSpace() );
@@ -801,6 +808,8 @@ void OverlayController::OnTimeoutPumpEvents()
} }
} }
} }
m_lastFrame = m_currentFrame;
}
} }
void OverlayController::AddOffsetToUniverseCenter( void OverlayController::AddOffsetToUniverseCenter(
+3
View File
@@ -80,6 +80,9 @@ private:
QSoundEffect m_focusChangedSoundEffect; QSoundEffect m_focusChangedSoundEffect;
QSoundEffect m_alarm01SoundEffect; QSoundEffect m_alarm01SoundEffect;
uint64_t m_currentFrame = 0;
uint64_t m_lastFrame = 0;
public: // I know it's an ugly hack to make them public to enable external public: // I know it's an ugly hack to make them public to enable external
// access, but I am too lazy to implement getters. // access, but I am too lazy to implement getters.
SteamVRTabController m_steamVRTabController; SteamVRTabController m_steamVRTabController;
+5 -1
View File
@@ -415,7 +415,11 @@ MyStackViewPage {
reloadChaperoneProfiles() reloadChaperoneProfiles()
reloadSteamVRProfiles() reloadSteamVRProfiles()
reloadPttProfiles() reloadPttProfiles()
summaryVersionText.text = applicationVersion
// REVERT TO THIS LATER: summaryVersionText.text = applicationVersion
// TEMP VERSION:
summaryVersionText.text = "Alpha-Kung v1.3"
if (MoveCenterTabController.trackingUniverse === 0) { if (MoveCenterTabController.trackingUniverse === 0) {
summaryPlaySpaceModeText.text = "Sitting" summaryPlaySpaceModeText.text = "Sitting"
} else if (MoveCenterTabController.trackingUniverse === 1) { } else if (MoveCenterTabController.trackingUniverse === 1) {
@@ -116,9 +116,12 @@ void AccessibilityTabController::eventLoopTick(
{ {
return; return;
} }
if ( settingsUpdateCounter >= 50 ) if ( settingsUpdateCounter >= 151 )
{
if ( parent->isDashboardVisible() )
{ {
setTrackingUniverse( ( int ) universe ); setTrackingUniverse( ( int ) universe );
}
settingsUpdateCounter = 0; settingsUpdateCounter = 0;
} }
else else
+1 -1
View File
@@ -167,7 +167,7 @@ void AudioTabController::eventLoopTick()
{ {
return; return;
} }
if ( settingsUpdateCounter >= 50 ) if ( settingsUpdateCounter >= 89 )
{ {
if ( m_micProximitySensorCanMute ) if ( m_micProximitySensorCanMute )
{ {
+10 -4
View File
@@ -649,7 +649,9 @@ void ChaperoneTabController::eventLoopTick(
} }
} }
if ( settingsUpdateCounter >= 50 ) if ( settingsUpdateCounter >= 101 )
{
if ( parent->isDashboardVisible() )
{ {
vr::EVRSettingsError vrSettingsError; vr::EVRSettingsError vrSettingsError;
float vis = vr::VRSettings()->GetInt32( float vis = vr::VRSettings()->GetInt32(
@@ -658,7 +660,8 @@ void ChaperoneTabController::eventLoopTick(
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< "Could not read \""
<< vr::k_pch_CollisionBounds_ColorGammaA_Int32 << vr::k_pch_CollisionBounds_ColorGammaA_Int32
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
@@ -688,7 +691,8 @@ void ChaperoneTabController::eventLoopTick(
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< "Could not read \""
<< vr::k_pch_CollisionBounds_CenterMarkerOn_Bool << vr::k_pch_CollisionBounds_CenterMarkerOn_Bool
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
@@ -701,7 +705,8 @@ void ChaperoneTabController::eventLoopTick(
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< "Could not read \""
<< vr::k_pch_CollisionBounds_PlaySpaceOn_Bool << vr::k_pch_CollisionBounds_PlaySpaceOn_Bool
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
@@ -709,6 +714,7 @@ void ChaperoneTabController::eventLoopTick(
} }
setPlaySpaceMarker( ps ); setPlaySpaceMarker( ps );
updateHeight( getBoundsMaxY() ); updateHeight( getBoundsMaxY() );
}
settingsUpdateCounter = 0; settingsUpdateCounter = 0;
} }
else else
@@ -604,9 +604,12 @@ void MoveCenterTabController::eventLoopTick(
vr::ETrackingUniverseOrigin universe, vr::ETrackingUniverseOrigin universe,
vr::TrackedDevicePose_t* devicePoses ) vr::TrackedDevicePose_t* devicePoses )
{ {
if ( settingsUpdateCounter >= 100 ) if ( settingsUpdateCounter >= 149 )
{
if ( parent->isDashboardVisible() )
{ {
setTrackingUniverse( int( universe ) ); setTrackingUniverse( int( universe ) );
}
settingsUpdateCounter = 0; settingsUpdateCounter = 0;
} }
else else
+26 -11
View File
@@ -309,13 +309,16 @@ void ReviveTabController::eventLoopTick()
if ( m_isOverlayInstalled if ( m_isOverlayInstalled
|| parent->m_settingsTabController.forceRevivePage() ) || parent->m_settingsTabController.forceRevivePage() )
{ {
if ( settingsUpdateCounter >= 50 ) if ( settingsUpdateCounter >= 139 )
{
if ( parent->isDashboardVisible() )
{ {
settingsUpdateCounter = 0;
vr::EVRSettingsError vrSettingsError; vr::EVRSettingsError vrSettingsError;
float valuef = vr::VRSettings()->GetFloat( float valuef
section_revive, key_pixelsPerDisplayPixel, &vrSettingsError ); = vr::VRSettings()->GetFloat( section_revive,
key_pixelsPerDisplayPixel,
&vrSettingsError );
if ( vrSettingsError == vr::VRSettingsError_None ) if ( vrSettingsError == vr::VRSettingsError_None )
{ {
if ( valuef == 0.0 ) if ( valuef == 0.0 )
@@ -421,25 +424,35 @@ void ReviveTabController::eventLoopTick()
} }
char buffer[1024]; char buffer[1024];
vr::VRSettings()->GetString( vr::VRSettings()->GetString( section_revive,
section_revive, key_piUser, buffer, 1024, &vrSettingsError ); key_piUser,
buffer,
1024,
&vrSettingsError );
if ( vrSettingsError == vr::VRSettingsError_None ) if ( vrSettingsError == vr::VRSettingsError_None )
{ {
setPiUsername( buffer ); setPiUsername( buffer );
} }
vr::VRSettings()->GetString( vr::VRSettings()->GetString( section_revive,
section_revive, key_piName, buffer, 1024, &vrSettingsError ); key_piName,
buffer,
1024,
&vrSettingsError );
if ( vrSettingsError == vr::VRSettingsError_None ) if ( vrSettingsError == vr::VRSettingsError_None )
{ {
setPiName( buffer ); setPiName( buffer );
} }
vr::VRSettings()->GetString( vr::VRSettings()->GetString( section_revive,
section_revive, key_piGender, buffer, 1024, &vrSettingsError ); key_piGender,
buffer,
1024,
&vrSettingsError );
if ( vrSettingsError == vr::VRSettingsError_None ) if ( vrSettingsError == vr::VRSettingsError_None )
{ {
if ( QString( buffer ).compare( "male", Qt::CaseInsensitive ) if ( QString( buffer ).compare( "male",
Qt::CaseInsensitive )
== 0 ) == 0 )
{ {
valuei = 1; valuei = 1;
@@ -457,6 +470,8 @@ void ReviveTabController::eventLoopTick()
setPiGender( valuei ); setPiGender( valuei );
} }
} }
settingsUpdateCounter = 0;
}
else else
{ {
settingsUpdateCounter++; settingsUpdateCounter++;
+4 -1
View File
@@ -28,10 +28,13 @@ void SettingsTabController::initStage2( OverlayController* var_parent,
void SettingsTabController::eventLoopTick() void SettingsTabController::eventLoopTick()
{ {
if ( settingsUpdateCounter >= 50 ) if ( settingsUpdateCounter >= 157 )
{
if ( parent->isDashboardVisible() )
{ {
setAutoStartEnabled( vr::VRApplications()->GetApplicationAutoLaunch( setAutoStartEnabled( vr::VRApplications()->GetApplicationAutoLaunch(
OverlayController::applicationKey ) ); OverlayController::applicationKey ) );
}
settingsUpdateCounter = 0; settingsUpdateCounter = 0;
} }
else else
+17 -11
View File
@@ -22,7 +22,9 @@ void SteamVRTabController::initStage2( OverlayController* var_parent,
void SteamVRTabController::eventLoopTick() void SteamVRTabController::eventLoopTick()
{ {
if ( settingsUpdateCounter >= 50 ) if ( settingsUpdateCounter >= 97 )
{
if ( parent->isDashboardVisible() )
{ {
vr::EVRSettingsError vrSettingsError; vr::EVRSettingsError vrSettingsError;
// checks supersampling override and resynchs if necessry // checks supersampling override and resynchs if necessry
@@ -33,7 +35,8 @@ void SteamVRTabController::eventLoopTick()
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< "Could not read \""
<< vr::k_pch_SteamVR_SupersampleManualOverride_Bool << vr::k_pch_SteamVR_SupersampleManualOverride_Bool
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
@@ -47,14 +50,16 @@ void SteamVRTabController::eventLoopTick()
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< "Could not read \""
<< vr::k_pch_SteamVR_SupersampleScale_Float << vr::k_pch_SteamVR_SupersampleScale_Float
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
vrSettingsError ); vrSettingsError );
if ( m_superSampling != 1.0 ) if ( m_superSampling != 1.0 )
{ {
LOG( DEBUG ) << "OpenVR returns an error and we have a custom " LOG( DEBUG )
<< "OpenVR returns an error and we have a custom "
"supersampling value: " "supersampling value: "
<< m_superSampling; << m_superSampling;
setSuperSampling( 1.0 ); setSuperSampling( 1.0 );
@@ -74,7 +79,8 @@ void SteamVRTabController::eventLoopTick()
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< "Could not read \""
<< vr::k_pch_SteamVR_AllowSupersampleFiltering_Bool << vr::k_pch_SteamVR_AllowSupersampleFiltering_Bool
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
@@ -84,20 +90,20 @@ void SteamVRTabController::eventLoopTick()
// Checks if Motion smoothing setting can be read and synchs adv // Checks if Motion smoothing setting can be read and synchs adv
// settings to steamvr/openvr // settings to steamvr/openvr
auto ms auto ms = vr::VRSettings()->GetBool(
= vr::VRSettings()->GetBool( vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_Section,
vr::k_pch_SteamVR_MotionSmoothing_Bool, vr::k_pch_SteamVR_MotionSmoothing_Bool,
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING )
<< vr::k_pch_SteamVR_MotionSmoothing_Bool << "Could not read \""
<< "\" setting: " << vr::k_pch_SteamVR_MotionSmoothing_Bool << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
vrSettingsError ); vrSettingsError );
} }
setMotionSmoothing( ms ); setMotionSmoothing( ms );
}
settingsUpdateCounter = 0; settingsUpdateCounter = 0;
} }
else else
@@ -316,7 +316,7 @@ vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index )
void UtilitiesTabController::eventLoopTick() void UtilitiesTabController::eventLoopTick()
{ {
if ( settingsUpdateCounter >= 10 ) if ( settingsUpdateCounter >= 19 )
{ {
vr::VROverlayHandle_t pOverlayHandle; vr::VROverlayHandle_t pOverlayHandle;
auto error = vr::VROverlay()->FindOverlay( steamDesktopOverlaykey, auto error = vr::VROverlay()->FindOverlay( steamDesktopOverlaykey,