Refactor update rates of tab controllers

Previous way of controlling when controllers were run was split among
the different controllers, meaning that third parties would require
knowledge of internal state of controllers in order to be on the same
update schedule as them.

This refactor moves the logic into a seperate class.

Additionally, it also stops the use of the `adjustUpdateRate` function
on all tab controllers, since it broke the prime-number-ability of
less collisions.
This commit is contained in:
Vasily
2020-06-06 20:53:34 +02:00
committed by username223
parent 82a0357748
commit 3857c2ac2f
19 changed files with 423 additions and 395 deletions
+4
View File
@@ -23,6 +23,7 @@ SOURCES += src/main.cpp\
src/settings/settings.cpp \ src/settings/settings.cpp \
src/settings/settings_object.cpp \ src/settings/settings_object.cpp \
src/alarm_clock/vr_alarm.cpp \ src/alarm_clock/vr_alarm.cpp \
src/utils/update_rate.cpp \
@@ -64,6 +65,9 @@ HEADERS += src/overlaycontroller.h \
src/settings/settings_object.h \ src/settings/settings_object.h \
src/settings/internal/settings_object_data.h \ src/settings/internal/settings_object_data.h \
src/alarm_clock/vr_alarm.h \ src/alarm_clock/vr_alarm.h \
src/settings/internal/settings_object_data.h \
src/settings/internal/settings_object_data.h \
src/utils/update_rate.h \
win32 { win32 {
+7
View File
@@ -2,6 +2,7 @@
#include "../tabcontrollers/UtilitiesTabController.h" #include "../tabcontrollers/UtilitiesTabController.h"
#include "vr_alarm.h" #include "vr_alarm.h"
#include "../openvr/ovr_overlay_wrapper.h" #include "../openvr/ovr_overlay_wrapper.h"
#include "../utils/update_rate.h"
namespace alarm_clock namespace alarm_clock
{ {
@@ -36,6 +37,12 @@ VrAlarm::VrAlarm()
void VrAlarm::eventLoopTick() void VrAlarm::eventLoopTick()
{ {
if ( updateRate.shouldSubjectNotRun(
UpdateSubject::UtilitiesTabController ) )
{
return;
}
if ( alarmEnabled() && m_alarm.isValid() ) if ( alarmEnabled() && m_alarm.isValid() )
{ {
checkAlarmStatus(); checkAlarmStatus();
+2 -1
View File
@@ -150,7 +150,6 @@ OverlayController::OverlayController( bool desktopMode,
m_moveCenterTabController.initStage1(); m_moveCenterTabController.initStage1();
m_audioTabController.initStage1(); m_audioTabController.initStage1();
m_settingsTabController.initStage1(); m_settingsTabController.initStage1();
m_utilitiesTabController.initStage1();
m_videoTabController.initStage1(); m_videoTabController.initStage1();
m_rotationTabController.initStage1(); m_rotationTabController.initStage1();
@@ -958,6 +957,8 @@ void OverlayController::OnTimeoutPumpEvents()
m_vsyncTooLateCounter++; m_vsyncTooLateCounter++;
} }
} }
updateRate.incrementCounter();
} }
void OverlayController::mainEventLoop() void OverlayController::mainEventLoop()
+2 -17
View File
@@ -44,6 +44,8 @@
#include "alarm_clock/vr_alarm.h" #include "alarm_clock/vr_alarm.h"
#include "utils/update_rate.h"
namespace application_strings namespace application_strings
{ {
constexpr auto applicationOrganizationName = "AdvancedSettings-Team"; constexpr auto applicationOrganizationName = "AdvancedSettings-Team";
@@ -61,23 +63,6 @@ constexpr const char* applicationVersionString = APPLICATION_VERSION;
// application namespace // application namespace
namespace advsettings namespace advsettings
{ {
// 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.
constexpr int k_audioSettingsUpdateCounter = 89;
constexpr int k_chaperoneSettingsUpdateCounter = 101;
constexpr int k_moveCenterSettingsUpdateCounter = 83;
constexpr int k_settingsTabSettingsUpdateCounter = 157;
constexpr int k_steamVrSettingsUpdateCounter = 97;
constexpr int k_utilitiesSettingsUpdateCounter = 19;
// Dashboard Updates These can be faster as they should only be running while
// Dashboard is active.
constexpr int k_videoDashboardUpdateCounter = 47;
// k_nonVsyncTickRate determines number of ms we wait to force the next event // k_nonVsyncTickRate determines number of ms we wait to force the next event
// loop tick when vsync is too late due to dropped frames. // loop tick when vsync is too late due to dropped frames.
constexpr int k_nonVsyncTickRate = 20; constexpr int k_nonVsyncTickRate = 20;
+8 -12
View File
@@ -4,6 +4,7 @@
#include "../overlaycontroller.h" #include "../overlaycontroller.h"
#include "../settings/settings.h" #include "../settings/settings.h"
#include "../settings/settings_object.h" #include "../settings/settings_object.h"
#include "../utils/update_rate.h"
#ifdef _WIN32 #ifdef _WIN32
# include "audiomanager/AudioManagerWindows.h" # include "audiomanager/AudioManagerWindows.h"
#elif __linux__ #elif __linux__
@@ -26,8 +27,6 @@ void AudioTabController::initStage1()
audioManager.reset( new AudioManagerDummy() ); audioManager.reset( new AudioManagerDummy() );
#endif #endif
audioManager->init( this ); audioManager->init( this );
m_audioSettingsUpdateCounter
= utils::adjustUpdateRate( k_audioSettingsUpdateCounter );
initOverride(); initOverride();
m_playbackDevices = audioManager->getPlaybackDevices(); m_playbackDevices = audioManager->getPlaybackDevices();
m_recordingDevices = audioManager->getRecordingDevices(); m_recordingDevices = audioManager->getRecordingDevices();
@@ -190,17 +189,19 @@ bool AudioTabController::audioProfileDefault() const
void AudioTabController::eventLoopTick() void AudioTabController::eventLoopTick()
{ {
if ( updateRate.shouldSubjectNotRun( UpdateSubject::AudioTabController ) )
{
return;
}
if ( !eventLoopMutex.try_lock() ) if ( !eventLoopMutex.try_lock() )
{ {
return; return;
} }
if ( settingsUpdateCounter >= m_audioSettingsUpdateCounter )
{
vr::EVRSettingsError vrSettingsError; vr::EVRSettingsError vrSettingsError;
char mirrorDeviceId[1024]; char mirrorDeviceId[1024];
vr::VRSettings()->GetString( vr::VRSettings()->GetString( vr::k_pch_audio_Section,
vr::k_pch_audio_Section,
vr::k_pch_audio_PlaybackMirrorDevice_String, vr::k_pch_audio_PlaybackMirrorDevice_String,
mirrorDeviceId, mirrorDeviceId,
1024, 1024,
@@ -229,12 +230,7 @@ void AudioTabController::eventLoopTick()
setMicVolume( audioManager->getMicVolume() ); setMicVolume( audioManager->getMicVolume() );
setMicMuted( audioManager->getMicMuted() ); setMicMuted( audioManager->getMicMuted() );
} }
settingsUpdateCounter = 0;
}
else
{
settingsUpdateCounter++;
}
eventLoopMutex.unlock(); eventLoopMutex.unlock();
} }
-2
View File
@@ -131,8 +131,6 @@ private:
bool m_isPlaybackOverride = false; bool m_isPlaybackOverride = false;
bool m_isRecordingOverride = false; bool m_isRecordingOverride = false;
unsigned int m_audioSettingsUpdateCounter = 90;
int m_defaultProfileIndex = -1; int m_defaultProfileIndex = -1;
unsigned settingsUpdateCounter = 0; unsigned settingsUpdateCounter = 0;
@@ -4,6 +4,7 @@
#include "../settings/settings.h" #include "../settings/settings.h"
#include "../utils/Matrix.h" #include "../utils/Matrix.h"
#include "../quaternion/quaternion.h" #include "../quaternion/quaternion.h"
#include "../utils/update_rate.h"
#include <cmath> #include <cmath>
// application namespace // application namespace
@@ -18,8 +19,6 @@ void ChaperoneTabController::initStage1()
} }
reloadChaperoneProfiles(); reloadChaperoneProfiles();
m_chaperoneSettingsUpdateCounter
= utils::adjustUpdateRate( k_chaperoneSettingsUpdateCounter );
initCenterMarkerOverlay(); initCenterMarkerOverlay();
eventLoopTick( m_trackingUniverse, nullptr ); eventLoopTick( m_trackingUniverse, nullptr );
} }
@@ -42,15 +41,13 @@ void ChaperoneTabController::initStage2( OverlayController* var_parent )
void ChaperoneTabController::dashboardLoopTick() void ChaperoneTabController::dashboardLoopTick()
{ {
if ( settingsUpdateCounter >= m_chaperoneSettingsUpdateCounter ) if ( updateRate.shouldSubjectNotRun(
UpdateSubject::ChaperoneTabController ) )
{ {
return;
}
updateChaperoneSettings(); updateChaperoneSettings();
settingsUpdateCounter = 0;
}
else
{
settingsUpdateCounter++;
}
} }
ChaperoneTabController::~ChaperoneTabController() ChaperoneTabController::~ChaperoneTabController()
@@ -363,8 +363,6 @@ private:
int m_updateTicksChaperoneReload = 0; int m_updateTicksChaperoneReload = 0;
unsigned int m_chaperoneSettingsUpdateCounter = 101;
vr::VRActionHandle_t m_rightActionHandle; vr::VRActionHandle_t m_rightActionHandle;
vr::VRActionHandle_t m_leftActionHandle; vr::VRActionHandle_t m_leftActionHandle;
vr::VRInputValueHandle_t m_leftInputHandle; vr::VRInputValueHandle_t m_leftInputHandle;
@@ -39,8 +39,6 @@ namespace advsettings
void MoveCenterTabController::initStage1() void MoveCenterTabController::initStage1()
{ {
reloadOffsetProfiles(); reloadOffsetProfiles();
m_moveCenterSettingsUpdateCounter
= utils::adjustUpdateRate( k_moveCenterSettingsUpdateCounter );
m_lastDragUpdateTimePoint = std::chrono::steady_clock::now(); m_lastDragUpdateTimePoint = std::chrono::steady_clock::now();
m_lastGravityUpdateTimePoint = std::chrono::steady_clock::now(); m_lastGravityUpdateTimePoint = std::chrono::steady_clock::now();
} }
@@ -204,8 +204,6 @@ private:
unsigned m_dragComfortFrameSkipCounter = 0; unsigned m_dragComfortFrameSkipCounter = 0;
unsigned m_turnComfortFrameSkipCounter = 0; unsigned m_turnComfortFrameSkipCounter = 0;
unsigned int m_moveCenterSettingsUpdateCounter = 83;
// Matrix used For Center Marker // Matrix used For Center Marker
vr::HmdMatrix34_t m_offsetmatrix = utils::k_forwardUpMatrix; vr::HmdMatrix34_t m_offsetmatrix = utils::k_forwardUpMatrix;
+6 -9
View File
@@ -1,6 +1,7 @@
#include "SettingsTabController.h" #include "SettingsTabController.h"
#include <QQuickWindow> #include <QQuickWindow>
#include "../overlaycontroller.h" #include "../overlaycontroller.h"
#include "../utils/update_rate.h"
// application namespace // application namespace
namespace advsettings namespace advsettings
@@ -9,8 +10,6 @@ void SettingsTabController::initStage1()
{ {
m_autoStartEnabled = vr::VRApplications()->GetApplicationAutoLaunch( m_autoStartEnabled = vr::VRApplications()->GetApplicationAutoLaunch(
application_strings::applicationKey ); application_strings::applicationKey );
m_settingsTabSettingsUpdateCounter
= utils::adjustUpdateRate( k_settingsTabSettingsUpdateCounter );
} }
void SettingsTabController::initStage2( OverlayController* var_parent ) void SettingsTabController::initStage2( OverlayController* var_parent )
@@ -22,16 +21,14 @@ void SettingsTabController::initStage2( OverlayController* var_parent )
void SettingsTabController::dashboardLoopTick() void SettingsTabController::dashboardLoopTick()
{ {
if ( settingsUpdateCounter >= m_settingsTabSettingsUpdateCounter ) if ( updateRate.shouldSubjectNotRun(
UpdateSubject::SettingsTabController ) )
{ {
return;
}
setAutoStartEnabled( vr::VRApplications()->GetApplicationAutoLaunch( setAutoStartEnabled( vr::VRApplications()->GetApplicationAutoLaunch(
application_strings::applicationKey ) ); application_strings::applicationKey ) );
settingsUpdateCounter = 0;
}
else
{
settingsUpdateCounter++;
}
} }
bool SettingsTabController::autoStartEnabled() const bool SettingsTabController::autoStartEnabled() const
@@ -26,13 +26,9 @@ class SettingsTabController : public QObject
private: private:
OverlayController* parent; OverlayController* parent;
unsigned settingsUpdateCounter = 0;
bool m_autoStartEnabled = false; bool m_autoStartEnabled = false;
bool m_nativeChaperoneToggle = false; bool m_nativeChaperoneToggle = false;
unsigned int m_settingsTabSettingsUpdateCounter = 157;
public: public:
void initStage1(); void initStage1();
void initStage2( OverlayController* parent ); void initStage2( OverlayController* parent );
+11 -20
View File
@@ -1,14 +1,13 @@
#include "SteamVRTabController.h" #include "SteamVRTabController.h"
#include <QQuickWindow> #include <QQuickWindow>
#include "../overlaycontroller.h" #include "../overlaycontroller.h"
#include "../utils/update_rate.h"
// application namespace // application namespace
namespace advsettings namespace advsettings
{ {
void SteamVRTabController::initStage1() void SteamVRTabController::initStage1()
{ {
m_steamVrSettingsUpdateCounter
= utils::adjustUpdateRate( k_steamVrSettingsUpdateCounter );
dashboardLoopTick(); dashboardLoopTick();
} }
@@ -19,8 +18,11 @@ void SteamVRTabController::initStage2( OverlayController* var_parent )
void SteamVRTabController::dashboardLoopTick() void SteamVRTabController::dashboardLoopTick()
{ {
if ( settingsUpdateCounter >= m_steamVrSettingsUpdateCounter ) if ( updateRate.shouldSubjectNotRun( UpdateSubject::SteamVrTabController ) )
{ {
return;
}
vr::EVRSettingsError vrSettingsError; vr::EVRSettingsError vrSettingsError;
// Checks and synchs performance graph // Checks and synchs performance graph
@@ -30,8 +32,7 @@ void SteamVRTabController::dashboardLoopTick()
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING ) << "Could not read \""
<< vr::k_pch_Perf_PerfGraphInHMD_Bool << vr::k_pch_Perf_PerfGraphInHMD_Bool << "\" setting: "
<< "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
vrSettingsError ); vrSettingsError );
} }
@@ -59,8 +60,7 @@ void SteamVRTabController::dashboardLoopTick()
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING ) << "Could not read \""
<< vr::k_pch_SteamVR_DoNotFadeToGrid << vr::k_pch_SteamVR_DoNotFadeToGrid << "\" setting: "
<< "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
vrSettingsError ); vrSettingsError );
} }
@@ -82,8 +82,8 @@ void SteamVRTabController::dashboardLoopTick()
setMultipleDriver( md ); setMultipleDriver( md );
// synch dnd // synch dnd
auto donotd = vr::VRSettings()->GetBool( auto donotd
vr::k_pch_Notifications_Section, = vr::VRSettings()->GetBool( vr::k_pch_Notifications_Section,
vr::k_pch_Notifications_DoNotDisturb_Bool, vr::k_pch_Notifications_DoNotDisturb_Bool,
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
@@ -103,8 +103,7 @@ void SteamVRTabController::dashboardLoopTick()
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) << "Could not read \"" LOG( WARNING ) << "Could not read \""
<< vr::k_pch_Camera_EnableCamera_Bool << vr::k_pch_Camera_EnableCamera_Bool << "\" setting: "
<< "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
vrSettingsError ); vrSettingsError );
} }
@@ -147,21 +146,13 @@ void SteamVRTabController::dashboardLoopTick()
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
{ {
LOG( WARNING ) LOG( WARNING ) << "Could not read \""
<< "Could not read \""
<< vr::k_pch_Camera_EnableCameraForCollisionBounds_Bool << vr::k_pch_Camera_EnableCameraForCollisionBounds_Bool
<< "\" setting: " << "\" setting: "
<< vr::VRSettings()->GetSettingsErrorNameFromEnum( << vr::VRSettings()->GetSettingsErrorNameFromEnum(
vrSettingsError ); vrSettingsError );
} }
setCameraBounds( cb ); setCameraBounds( cb );
settingsUpdateCounter = 0;
}
else
{
settingsUpdateCounter++;
}
} }
bool SteamVRTabController::performanceGraph() const bool SteamVRTabController::performanceGraph() const
@@ -49,10 +49,6 @@ private:
bool m_cameraRoom = false; bool m_cameraRoom = false;
bool m_cameraDashboard = false; bool m_cameraDashboard = false;
unsigned settingsUpdateCounter = 0;
unsigned int m_steamVrSettingsUpdateCounter = 97;
public: public:
void initStage1(); void initStage1();
void initStage2( OverlayController* parent ); void initStage2( OverlayController* parent );
+11 -22
View File
@@ -4,18 +4,13 @@
#include "../overlaycontroller.h" #include "../overlaycontroller.h"
#include "../keyboard_input/input_sender.h" #include "../keyboard_input/input_sender.h"
#include "../settings/settings.h" #include "../settings/settings.h"
#include "../utils/update_rate.h"
#include <chrono> #include <chrono>
#include <thread> #include <thread>
// application namespace // application namespace
namespace advsettings namespace advsettings
{ {
void UtilitiesTabController::initStage1()
{
m_utilitiesSettingsUpdateCounter
= utils::adjustUpdateRate( k_utilitiesSettingsUpdateCounter );
}
void UtilitiesTabController::initStage2( OverlayController* var_parent ) void UtilitiesTabController::initStage2( OverlayController* var_parent )
{ {
this->m_parent = var_parent; this->m_parent = var_parent;
@@ -270,8 +265,12 @@ vr::VROverlayHandle_t createBatteryOverlay( vr::TrackedDeviceIndex_t index )
void UtilitiesTabController::eventLoopTick() void UtilitiesTabController::eventLoopTick()
{ {
if ( settingsUpdateCounter >= m_utilitiesSettingsUpdateCounter ) if ( updateRate.shouldSubjectNotRun(
UpdateSubject::UtilitiesTabController ) )
{ {
return;
}
// attach battery overlay to all tracked devices that aren't a // attach battery overlay to all tracked devices that aren't a
// controller or hmd // controller or hmd
for ( vr::TrackedDeviceIndex_t i = 0; i < vr::k_unMaxTrackedDeviceCount; for ( vr::TrackedDeviceIndex_t i = 0; i < vr::k_unMaxTrackedDeviceCount;
@@ -295,13 +294,11 @@ void UtilitiesTabController::eventLoopTick()
{ {
if ( shouldShow ) if ( shouldShow )
{ {
vr::VROverlay()->ShowOverlay( vr::VROverlay()->ShowOverlay( m_batteryOverlayHandles[i] );
m_batteryOverlayHandles[i] );
} }
else else
{ {
vr::VROverlay()->HideOverlay( vr::VROverlay()->HideOverlay( m_batteryOverlayHandles[i] );
m_batteryOverlayHandles[i] );
} }
m_batteryVisible[i] = shouldShow; m_batteryVisible[i] = shouldShow;
} }
@@ -313,8 +310,7 @@ void UtilitiesTabController::eventLoopTick()
Prop_DeviceProvidesBatteryStatus_Bool ); Prop_DeviceProvidesBatteryStatus_Bool );
if ( hasBatteryStatus ) if ( hasBatteryStatus )
{ {
float battery float battery = vr::VRSystem()->GetFloatTrackedDeviceProperty(
= vr::VRSystem()->GetFloatTrackedDeviceProperty(
i, i,
vr::ETrackedDeviceProperty:: vr::ETrackedDeviceProperty::
Prop_DeviceBatteryPercentage_Float ); Prop_DeviceBatteryPercentage_Float );
@@ -324,8 +320,8 @@ void UtilitiesTabController::eventLoopTick()
if ( batteryState != m_batteryState[i] ) if ( batteryState != m_batteryState[i] )
{ {
LOG( INFO ) LOG( INFO )
<< "Updating battery overlay for device " << i << "Updating battery overlay for device " << i << " to "
<< " to " << batteryState << "(" << battery << ")" << batteryState << "(" << battery << ")"
<< QString::number( m_batteryOverlayHandles[i] ); << QString::number( m_batteryOverlayHandles[i] );
QString batteryIconPath QString batteryIconPath
= getBatteryIconPath( batteryState ); = getBatteryIconPath( batteryState );
@@ -345,13 +341,6 @@ void UtilitiesTabController::eventLoopTick()
} }
} }
} }
settingsUpdateCounter = 0;
}
else
{
settingsUpdateCounter++;
}
} }
} // namespace advsettings } // namespace advsettings
@@ -32,10 +32,7 @@ private:
int m_batteryState[vr::k_unMaxTrackedDeviceCount]; int m_batteryState[vr::k_unMaxTrackedDeviceCount];
bool m_batteryVisible[vr::k_unMaxTrackedDeviceCount]; bool m_batteryVisible[vr::k_unMaxTrackedDeviceCount];
unsigned int m_utilitiesSettingsUpdateCounter = 19;
public: public:
void initStage1();
void initStage2( OverlayController* var_parent ); void initStage2( OverlayController* var_parent );
void eventLoopTick(); void eventLoopTick();
+8 -13
View File
@@ -3,6 +3,7 @@
#include <QApplication> #include <QApplication>
#include "../settings/settings.h" #include "../settings/settings.h"
#include "../overlaycontroller.h" #include "../overlaycontroller.h"
#include "../utils/update_rate.h"
#include <cmath> #include <cmath>
namespace advsettings namespace advsettings
@@ -15,9 +16,6 @@ void VideoTabController::initStage1()
synchGain( true ); synchGain( true );
resetGain(); resetGain();
m_videoDashboardUpdateCounter
= utils::adjustUpdateRate( k_videoDashboardUpdateCounter );
initBrightnessOverlay(); initBrightnessOverlay();
initColorOverlay(); initColorOverlay();
initMotionSmoothing(); initMotionSmoothing();
@@ -141,8 +139,11 @@ void VideoTabController::eventLoopTick() {}
void VideoTabController::dashboardLoopTick() void VideoTabController::dashboardLoopTick()
{ {
if ( settingsUpdateCounter >= m_videoDashboardUpdateCounter ) if ( updateRate.shouldSubjectNotRun( UpdateSubject::VideoDashboard ) )
{ {
return;
}
vr::EVRSettingsError vrSettingsError; vr::EVRSettingsError vrSettingsError;
// checks supersampling override and resynchs if necessry // checks supersampling override and resynchs if necessry
@@ -162,8 +163,8 @@ void VideoTabController::dashboardLoopTick()
setAllowSupersampleOverride( sso ); setAllowSupersampleOverride( sso );
// checks supersampling and re-synchs if necessary // checks supersampling and re-synchs if necessary
auto ss = vr::VRSettings()->GetFloat( auto ss
vr::k_pch_SteamVR_Section, = vr::VRSettings()->GetFloat( vr::k_pch_SteamVR_Section,
vr::k_pch_SteamVR_SupersampleScale_Float, vr::k_pch_SteamVR_SupersampleScale_Float,
&vrSettingsError ); &vrSettingsError );
if ( vrSettingsError != vr::VRSettingsError_None ) if ( vrSettingsError != vr::VRSettingsError_None )
@@ -206,8 +207,7 @@ void VideoTabController::dashboardLoopTick()
// 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::k_pch_SteamVR_Section,
= vr::VRSettings()->GetBool( 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 )
@@ -231,11 +231,6 @@ void VideoTabController::dashboardLoopTick()
synchGain( valueAdjust ); synchGain( valueAdjust );
settingsUpdateCounter = 0; settingsUpdateCounter = 0;
}
else
{
settingsUpdateCounter++;
}
} }
void VideoTabController::reloadVideoConfig() void VideoTabController::reloadVideoConfig()
+57
View File
@@ -0,0 +1,57 @@
#include "update_rate.h"
UpdateRate updateRate{};
/**
@brief getSubjectRate returns the amount of frames before a subject is run
again.
@param Subject
@return Amount of frames before subject is run again.
So a return value of 19 would mean that every 19 frames, the subject is run.
Divide the expected framerate with the return value to get the amount of
times per second the subject is run.
*/
constexpr unsigned int getSubjectRate( const UpdateSubject subject )
{
/*
Return values are primes in order to reduce the amount of times where
multiple subjects are run on the same frame.
*/
switch ( subject )
{
case UpdateSubject::UtilitiesTabController:
return 19;
case UpdateSubject::VideoDashboard:
return 47;
case UpdateSubject::AudioTabController:
return 89;
case UpdateSubject::SteamVrTabController:
return 97;
case UpdateSubject::ChaperoneTabController:
return 101;
case UpdateSubject::SettingsTabController:
return 157;
}
return 0;
}
bool UpdateRate::shouldSubjectRun( const UpdateSubject subject ) noexcept
{
const auto subjectTarget = getSubjectRate( subject );
const auto shouldRun = ( m_counter % subjectTarget ) == 0;
return shouldRun;
}
bool UpdateRate::shouldSubjectNotRun( const UpdateSubject subject ) noexcept
{
return !shouldSubjectRun( subject );
}
void UpdateRate::incrementCounter() noexcept
{
m_counter++;
}
+28
View File
@@ -0,0 +1,28 @@
#pragma once
enum class UpdateSubject
{
AudioTabController,
ChaperoneTabController,
SettingsTabController,
SteamVrTabController,
UtilitiesTabController,
VideoDashboard,
};
class UpdateRate
{
public:
[[nodiscard]] bool shouldSubjectRun( const UpdateSubject subject ) noexcept;
[[nodiscard]] bool
shouldSubjectNotRun( const UpdateSubject subject ) noexcept;
void incrementCounter() noexcept;
private:
// counter is deliberately set as unsigned so that the program can continue
// functioning if the counter should go above INT_MAX (or UINT_MAX in this
// case)
unsigned int m_counter;
};
extern UpdateRate updateRate;