Skip to content

Commit

Permalink
Option to gently fade chaperone to disabled below a certain height (#622
Browse files Browse the repository at this point in the history
)

* Option to fade out chaperone when HMD goes below a configured height

Useful for setups in which you have a seat just outside your VR space,
or like to sit in the middle of your space for any amount of time. Will
fade out the boundaries to 0% opacity over 5 seconds, 5 seconds after
you sit down. Standing back up to the configured height will make them
pop back in immediately.

Can be found under Chaperone -> Additional Settings.

* Update format.sh to require clang-format v10

* Use fade distance instead of opacity, opacity inconsistently applied

* Bugfixes (#624)

* stop crashing on HMD Init Errors, as well as bypass force quit on all steamvr Init Errors

* add qtc clang to gitignore

* add app volume adjustment

* adjust app volume placement in menu

* fix type error

* increment version

* fix version number

---------

Co-authored-by: ykeara <ykeara1@gmail.com>
  • Loading branch information
feilen and ykeara authored May 17, 2023
1 parent 65b5aac commit 1cfd9ff
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ installer/*.exe
build_scripts/win/__pycache__
build_scripts/win/current_build.bat
AdvancedSettings_resource.rc
.qtc_clangd/
2 changes: 1 addition & 1 deletion build_scripts/compile_version_string.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.2-release
5.7.0-release
19 changes: 15 additions & 4 deletions build_scripts/linux/format.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#!/usr/bin/env bash
set -e

clang-format --version
if [ -x /usr/bin/clang-format-10 ]; then
CLANG_FORMAT_EXE=clang-format-10
else
CLANG_FORMAT_EXE=clang-format
fi

CLANG_VERSION="$($CLANG_FORMAT_EXE --version)"
echo $CLANG_VERSION
if [[ "$CLANG_VERSION" != *"clang-format version 10"* ]]; then
echo "Wrong clang-format version found! Install version 10"
exit 1
fi

if [ $? -eq 0 ]; then
echo "Clang-format found."
build_path="`dirname \"$0\"`"
project_path=$build_path/../..

find $project_path/src/ -regex '.*\.\(cpp\|h\)' -exec clang-format -style=file -i {} \; -exec echo "Iteration 1: {}" \;
find $project_path/src/ -regex '.*\.\(cpp\|h\)' -exec clang-format -style=file -i {} \; -exec echo "Iteration 2: {}" \;
find $project_path/src/ -regex '.*\.\(cpp\|h\)' -exec $CLANG_FORMAT_EXE -style=file -i {} \; -exec echo "Iteration 1: {}" \;
find $project_path/src/ -regex '.*\.\(cpp\|h\)' -exec $CLANG_FORMAT_EXE -style=file -i {} \; -exec echo "Iteration 2: {}" \;
echo "DONE"
else
echo "Could not find clang-format."
echo "Could not find clang-format-10."
fi

18 changes: 14 additions & 4 deletions src/openvr/openvr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,25 @@ void initializeProperly( const OpenVrInitializationType initType )
if ( initError == vr::VRInitError_Init_HmdNotFound
|| initError == vr::VRInitError_Init_HmdNotFoundPresenceFailed )
{
QMessageBox::critical( nullptr,
"OpenVR Advanced Settings Overlay",
"Could not find HMD!" );
// In particular in some setups these errors are thrown while
// nothing is wrong with their setup presumably this is some sort of
// race condition
LOG( WARNING ) << "HMD not Found During Startup";
LOG( WARNING ) << "steamvr error: "
+ std::string(
vr::VR_GetVRInitErrorAsEnglishDescription(
initError ) );
return;
}
LOG( ERROR ) << "Failed to initialize OpenVR: "
+ std::string(
vr::VR_GetVRInitErrorAsEnglishDescription(
initError ) );
exit( EXIT_FAILURE );
// Going to stop Exiting App, This may lead to crashes if OpenVR
// actually fails to start, HOWEVER based on the HMD errors we are
// probably pre-maturely killing ourselves from some sort of OpenVR race
// condition
// exit( EXIT_FAILURE );
}
else
{
Expand Down
25 changes: 23 additions & 2 deletions src/overlaycontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ OverlayController::OverlayController( bool desktopMode,
m_runtimePathUrl = QUrl::fromLocalFile( tempRuntimePath );
LOG( INFO ) << "VR Runtime Path: " << m_runtimePathUrl.toLocalFile();

const double initVol = soundVolume();
constexpr auto clickSoundURL = "res/sounds/click.wav";
const auto activationSoundFile
= paths::binaryDirectoryFindFile( clickSoundURL );
Expand All @@ -77,7 +78,7 @@ OverlayController::OverlayController( bool desktopMode,
{
m_activationSoundEffect.setSource( QUrl::fromLocalFile(
QString::fromStdString( ( *activationSoundFile ) ) ) );
m_activationSoundEffect.setVolume( 0.7 );
m_activationSoundEffect.setVolume( initVol );
}
else
{
Expand All @@ -92,7 +93,7 @@ OverlayController::OverlayController( bool desktopMode,
{
m_focusChangedSoundEffect.setSource( QUrl::fromLocalFile(
QString::fromStdString( ( *focusChangedSoundFile ) ) ) );
m_focusChangedSoundEffect.setVolume( 0.7 );
m_focusChangedSoundEffect.setVolume( initVol );
}
else
{
Expand Down Expand Up @@ -1648,6 +1649,26 @@ void OverlayController::setKeyboardPos()
vr::VROverlay()->SetKeyboardPositionForOverlay( m_ulOverlayHandle, empty );
}

void OverlayController::setSoundVolume( double value, bool notify )
{
m_activationSoundEffect.setVolume( value );
m_focusChangedSoundEffect.setVolume( value );
// leaving alarm sound alone for now as chaperone warning setting effects it
// m_alarm01SoundEffect.setVolume( value);
settings::setSetting( settings::DoubleSetting::APPLICATION_appVolume,
value );
if ( notify )
{
emit soundVolumeChanged( value );
}
}

double OverlayController::soundVolume() const
{
return settings::getSetting(
settings::DoubleSetting::APPLICATION_appVolume );
}

void OverlayController::playActivationSound()
{
if ( !m_noSound )
Expand Down
6 changes: 6 additions & 0 deletions src/overlaycontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class OverlayController : public QObject
Q_PROPERTY( bool autoApplyChaperoneEnabled READ autoApplyChaperoneEnabled
WRITE setAutoApplyChaperoneEnabled NOTIFY
autoApplyChaperoneEnabledChanged )
Q_PROPERTY( double soundVolume READ soundVolume WRITE setSoundVolume NOTIFY
soundVolumeChanged )

private:
vr::VROverlayHandle_t m_ulOverlayHandle = vr::k_ulOverlayHandleInvalid;
Expand Down Expand Up @@ -252,6 +254,8 @@ class OverlayController : public QObject
int debugState() const;
std::string autoApplyChaperoneName();

double soundVolume() const;

public slots:
void renderOverlay();
void OnRenderRequest();
Expand All @@ -277,6 +281,7 @@ public slots:
void setCustomTickRateMs( int value, bool notify = true );
void setDebugState( int value, bool notify = true );
void setAutoApplyChaperoneEnabled( bool value, bool notify = true );
void setSoundVolume( double value, bool notify = true );

signals:
void keyBoardInputSignal( QString input, unsigned long userValue = 0 );
Expand All @@ -290,6 +295,7 @@ public slots:
void customTickRateMsChanged( int value );
void debugStateChanged( int value );
void autoApplyChaperoneEnabledChanged( bool value );
void soundVolumeChanged( double value );
};

} // namespace advsettings
71 changes: 71 additions & 0 deletions src/res/qml/SettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,73 @@ MyStackViewPage {
ColumnLayout {
spacing: 18

RowLayout{
MyText {
text: "Application Volume:"
Layout.rightMargin: 12
}

MyPushButton2 {
text: "-"
Layout.preferredWidth: 40
onClicked: {
volumeSlider.value -= 0.05
}
}

MySlider {
id: volumeSlider
from: 0.0
to: 1.0
stepSize: 0.01
value: 0.7
Layout.fillWidth: true
onPositionChanged: {
var val = (this.value * 100)
volumeText.text = Math.round(val) + "%"
}
onValueChanged: {
OverlayController.setSoundVolume(value, false)
}
}

MyPushButton2 {
text: "+"
Layout.preferredWidth: 40
onClicked: {
volumeSlider.value += 0.05
}
}


MyTextField {
id: volumeText
text: "70%"
keyBoardUID: 503
Layout.preferredWidth: 100
Layout.leftMargin: 10
horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) {
var val = parseFloat(input)
if (!isNaN(val)) {
if (val < 0) {
val = 0
} else if (val > 100.0) {
val = 100.0
}

var v = (val/100).toFixed(0)
if (v <= volumeSlider.to) {
chaperoneVisibilitySlider.value = v
} else {
ChaperoneTabController.setBoundsVisibility(v, false)
}
}
text = Math.round(ChaperoneTabController.boundsVisibility * 100) + "%"
}
}
}

MyToggleButton {
id: settingsAutoStartToggle
text: "Autostart"
Expand Down Expand Up @@ -295,6 +362,7 @@ MyStackViewPage {

seatedOldExternalWarning.visible = MoveCenterTabController.allowExternalEdits && MoveCenterTabController.oldStyleMotion
reloadChaperoneProfiles()
volumeSlider.value = OverlayController.soundVolume
}

Connections {
Expand Down Expand Up @@ -357,6 +425,9 @@ MyStackViewPage {
onAutoApplyChaperoneEnabledChanged: {
autoApplyChaperoneToggleButton.checked = OverlayController.autoApplyChaperoneEnabled
}
onSoundVolumeChanged:{
volumeSlider.value = OverlayController.soundVolume
}
}
Connections{
target: ChaperoneTabController
Expand Down
29 changes: 28 additions & 1 deletion src/res/qml/chaperone_page/ChaperonePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ MyStackViewPage {
}

MyPushButton2 {
id: chaperoneVisibilityMinus
text: "-"
Layout.preferredWidth: 40
onClicked: {
Expand All @@ -268,6 +269,7 @@ MyStackViewPage {
}

MyPushButton2 {
id: chaperoneVisibilityPlus
text: "+"
Layout.preferredWidth: 40
onClicked: {
Expand Down Expand Up @@ -561,7 +563,13 @@ MyStackViewPage {
chaperonePlaySpaceToggle.checked = ChaperoneTabController.playSpaceMarker
chaperoneForceBoundsToggle.checked = ChaperoneTabController.forceBounds
chaperoneDisableChaperone.checked = ChaperoneTabController.disableChaperone
if(chaperoneDisableChaperone.checked){
var dim = ChaperoneTabController.chaperoneDimHeight
if(dim > 0.0){
chaperoneDisableChaperone.enabled = false;
}else{
chaperoneDisableChaperone.enabled = true;
}
if(dim > 0.0 || chaperoneDisableChaperone.checked){
chaperoneFadeDistanceMinus.enabled = false;
chaperoneFadeDistancePlus.enabled = false;
chaperoneFadeDistanceSlider.enabled = false;
Expand Down Expand Up @@ -597,7 +605,26 @@ MyStackViewPage {
}
chaperoneHeightText.text = h
}
onChaperoneDimHeightChanged: {
var dim = ChaperoneTabController.chaperoneDimHeight
if(dim > 0.0){
chaperoneDisableChaperone.enabled = false;
}else{
chaperoneDisableChaperone.enabled = true;
}
if(dim > 0.0 || chaperoneDisableChaperone.checked){
chaperoneFadeDistanceMinus.enabled = false;
chaperoneFadeDistancePlus.enabled = false;
chaperoneFadeDistanceSlider.enabled = false;
chaperoneFadeDistanceText.enabled = false;

}else{
chaperoneFadeDistanceMinus.enabled = true;
chaperoneFadeDistancePlus.enabled = true;
chaperoneFadeDistanceSlider.enabled = true;
chaperoneFadeDistanceText.enabled = true;
}
}
onCenterMarkerNewChanged: {
chaperoneCenterMarkerToggle.checked = ChaperoneTabController.centerMarkerNew
}
Expand Down
Loading

0 comments on commit 1cfd9ff

Please sign in to comment.