Add ChaperoneProfile to new settings object API

chaperoneGeometryQuads was converted from an implicit pointer array to a
std::vector because the only thing the pointer array did was hide the
fact that it was an array.
This commit is contained in:
Vasily
2020-01-30 10:36:21 +01:00
committed by username223
parent 2930ea6d4f
commit 9d8e3ad3ef
2 changed files with 183 additions and 283 deletions
+9 -281
View File
@@ -36,285 +36,12 @@ ChaperoneTabController::~ChaperoneTabController()
void ChaperoneTabController::reloadChaperoneProfiles()
{
chaperoneProfiles.clear();
auto settings = OverlayController::appSettings();
settings->beginGroup( "chaperoneSettings" );
auto profileCount = settings->beginReadArray( "chaperoneProfiles" );
for ( int i = 0; i < profileCount; i++ )
{
settings->setArrayIndex( i );
chaperoneProfiles.emplace_back();
auto& entry = chaperoneProfiles[static_cast<size_t>( i )];
entry.profileName
= settings->value( "profileName" ).toString().toStdString();
entry.includesChaperoneGeometry
= settings->value( "includesChaperoneGeometry", false ).toBool();
if ( entry.includesChaperoneGeometry )
{
entry.chaperoneGeometryQuadCount
= settings->value( "chaperoneGeometryQuadCount", 0 ).toUInt();
entry.chaperoneGeometryQuads.reset(
new vr::HmdQuad_t[entry.chaperoneGeometryQuadCount] );
unsigned qi = 0;
for ( auto q :
settings->value( "chaperoneGeometryQuads" ).toList() )
{
unsigned ci = 0;
for ( auto c : q.toList() )
{
unsigned cci = 0;
for ( auto cc : c.toList() )
{
entry.chaperoneGeometryQuads.get()[qi]
.vCorners[ci]
.v[cci]
= cc.toFloat();
cci++;
}
ci++;
}
qi++;
}
unsigned i1 = 0;
for ( auto l1 : settings->value( "standingCenter" ).toList() )
{
unsigned i2 = 0;
for ( auto l2 : l1.toList() )
{
entry.standingCenter.m[i1][i2] = l2.toFloat();
i2++;
}
i1++;
}
entry.playSpaceAreaX
= settings->value( "playSpaceAreaX", 0.0f ).toFloat();
entry.playSpaceAreaZ
= settings->value( "playSpaceAreaZ", 0.0f ).toFloat();
}
entry.includesVisibility
= settings->value( "includesVisibility", false ).toBool();
if ( entry.includesVisibility )
{
entry.visibility = settings->value( "visibility", 0.6 ).toFloat();
}
entry.includesFadeDistance
= settings->value( "includesFadeDistance", false ).toBool();
if ( entry.includesFadeDistance )
{
entry.fadeDistance
= settings->value( "fadeDistance", 0.7 ).toFloat();
}
entry.includesCenterMarker
= settings->value( "includesCenterMarker", false ).toBool();
if ( entry.includesCenterMarker )
{
entry.centerMarker
= settings->value( "centerMarker", false ).toBool();
}
entry.includesPlaySpaceMarker
= settings->value( "includesPlaySpaceMarker", false ).toBool();
if ( entry.includesPlaySpaceMarker )
{
entry.playSpaceMarker
= settings->value( "playSpaceMarker", false ).toBool();
}
entry.includesFloorBoundsMarker
= settings->value( "includesFloorBoundsMarker", false ).toBool();
if ( entry.includesFloorBoundsMarker )
{
entry.floorBoundsMarker
= settings->value( "floorBoundsMarker", false ).toBool();
}
entry.includesBoundsColor
= settings->value( "includesBoundsColor", false ).toBool();
if ( entry.includesBoundsColor )
{
auto color = settings->value( "boundsColor" ).toList();
entry.boundsColor[0] = color[0].toInt();
entry.boundsColor[1] = color[1].toInt();
entry.boundsColor[2] = color[2].toInt();
}
entry.includesChaperoneStyle
= settings->value( "includesChaperoneStyle", false ).toBool();
if ( entry.includesChaperoneStyle )
{
entry.chaperoneStyle
= settings->value( "chaperoneStyle", 0 ).toInt();
}
entry.includesForceBounds
= settings->value( "includesForceBounds", false ).toBool();
if ( entry.includesForceBounds )
{
entry.forceBounds
= settings->value( "forceBounds", false ).toBool();
}
entry.includesProximityWarningSettings
= settings->value( "includesProximityWarningSettings", false )
.toBool();
if ( entry.includesProximityWarningSettings )
{
entry.enableChaperoneSwitchToBeginner
= settings->value( "chaperoneSwitchToBeginnerEnabled", false )
.toBool();
entry.chaperoneSwitchToBeginnerDistance
= settings->value( "chaperoneSwitchToBeginnerDistance", 0.5f )
.toFloat();
entry.enableChaperoneHapticFeedback
= settings->value( "chaperoneHapticFeedbackEnabled", false )
.toBool();
entry.chaperoneHapticFeedbackDistance
= settings->value( "chaperoneHapticFeedbackDistance", 0.5f )
.toFloat();
entry.enableChaperoneAlarmSound
= settings->value( "chaperoneAlarmSoundEnabled", false )
.toBool();
entry.chaperoneAlarmSoundLooping
= settings->value( "chaperoneAlarmSoundLooping", true )
.toBool();
entry.chaperoneAlarmSoundAdjustVolume
= settings->value( "chaperoneAlarmSoundAdjustVolume", false )
.toBool();
entry.chaperoneAlarmSoundDistance
= settings->value( "chaperoneAlarmSoundDistance", 0.5f )
.toFloat();
entry.enableChaperoneShowDashboard
= settings->value( "chaperoneShowDashboardEnabled", false )
.toBool();
entry.chaperoneShowDashboardDistance
= settings->value( "chaperoneShowDashboardDistance", 0.5f )
.toFloat();
}
}
settings->endArray();
settings->endGroup();
settings::loadAllObjects( chaperoneProfiles );
}
void ChaperoneTabController::saveChaperoneProfiles()
{
auto settings = OverlayController::appSettings();
settings->beginGroup( "chaperoneSettings" );
settings->beginWriteArray( "chaperoneProfiles" );
unsigned i = 0;
for ( auto& p : chaperoneProfiles )
{
settings->setArrayIndex( static_cast<int>( i ) );
settings->setValue( "profileName",
QString::fromStdString( p.profileName ) );
settings->setValue( "includesChaperoneGeometry",
p.includesChaperoneGeometry );
if ( p.includesChaperoneGeometry )
{
settings->setValue( "chaperoneGeometryQuadCount",
p.chaperoneGeometryQuadCount );
QVariantList quadList;
for ( unsigned qi = 0; qi < p.chaperoneGeometryQuadCount; qi++ )
{
QVariantList cornerList;
for ( unsigned ci = 0; ci < 4; ci++ )
{
QVariantList coordVector;
for ( unsigned cci = 0; cci < 3; cci++ )
{
coordVector.push_back(
p.chaperoneGeometryQuads.get()[qi]
.vCorners[ci]
.v[cci] );
}
cornerList.push_back( coordVector );
}
quadList.push_back( cornerList );
}
settings->setValue( "chaperoneGeometryQuads", quadList );
QVariantList l1;
for ( unsigned i1 = 0; i1 < 3; i1++ )
{
QVariantList l2;
for ( unsigned i2 = 0; i2 < 4; i2++ )
{
l2.push_back( p.standingCenter.m[i1][i2] );
}
l1.push_back( l2 );
}
settings->setValue( "standingCenter", l1 );
settings->setValue( "playSpaceAreaX", p.playSpaceAreaX );
settings->setValue( "playSpaceAreaZ", p.playSpaceAreaZ );
}
settings->setValue( "includesVisibility", p.includesVisibility );
if ( p.includesVisibility )
{
settings->setValue( "visibility", p.visibility );
}
settings->setValue( "includesFadeDistance", p.includesFadeDistance );
if ( p.includesFadeDistance )
{
settings->setValue( "fadeDistance", p.fadeDistance );
}
settings->setValue( "includesCenterMarker", p.includesCenterMarker );
if ( p.includesCenterMarker )
{
settings->setValue( "centerMarker", p.centerMarker );
}
settings->setValue( "includesPlaySpaceMarker",
p.includesPlaySpaceMarker );
if ( p.includesPlaySpaceMarker )
{
settings->setValue( "playSpaceMarker", p.playSpaceMarker );
}
settings->setValue( "includesFloorBoundsMarker",
p.includesFloorBoundsMarker );
if ( p.includesFloorBoundsMarker )
{
settings->setValue( "floorBoundsMarker", p.floorBoundsMarker );
}
settings->setValue( "includesBoundsColor", p.includesBoundsColor );
if ( p.includesBoundsColor )
{
QVariantList color;
color.push_back( p.boundsColor[0] );
color.push_back( p.boundsColor[1] );
color.push_back( p.boundsColor[2] );
settings->setValue( "boundsColor", color );
}
settings->setValue( "includesChaperoneStyle",
p.includesChaperoneStyle );
if ( p.includesChaperoneStyle )
{
settings->setValue( "chaperoneStyle", p.chaperoneStyle );
}
settings->setValue( "includesForceBounds", p.includesForceBounds );
if ( p.includesForceBounds )
{
settings->setValue( "forceBounds", p.forceBounds );
}
settings->setValue( "includesProximityWarningSettings",
p.includesProximityWarningSettings );
if ( p.includesProximityWarningSettings )
{
settings->setValue( "chaperoneSwitchToBeginnerEnabled",
p.enableChaperoneSwitchToBeginner );
settings->setValue( "chaperoneSwitchToBeginnerDistance",
p.chaperoneSwitchToBeginnerDistance );
settings->setValue( "chaperoneHapticFeedbackEnabled",
p.enableChaperoneHapticFeedback );
settings->setValue( "chaperoneHapticFeedbackDistance",
p.chaperoneHapticFeedbackDistance );
settings->setValue( "chaperoneAlarmSoundEnabled",
p.enableChaperoneAlarmSound );
settings->setValue( "chaperoneAlarmSoundLooping",
p.chaperoneAlarmSoundLooping );
settings->setValue( "chaperoneAlarmSoundAdjustVolume",
p.chaperoneAlarmSoundAdjustVolume );
settings->setValue( "chaperoneAlarmSoundDistance",
p.chaperoneAlarmSoundDistance );
settings->setValue( "chaperoneShowDashboardEnabled",
p.enableChaperoneShowDashboard );
settings->setValue( "chaperoneShowDashboardDistance",
p.chaperoneShowDashboardDistance );
}
i++;
}
settings->endArray();
settings->endGroup();
settings::saveAllObjects( chaperoneProfiles );
}
void ChaperoneTabController::handleChaperoneWarnings( float distance )
@@ -1204,9 +931,13 @@ void ChaperoneTabController::addChaperoneProfile(
vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo( nullptr,
&quadCount );
profile->chaperoneGeometryQuadCount = quadCount;
profile->chaperoneGeometryQuads.reset( new vr::HmdQuad_t[quadCount] );
for ( int i = 0; i < static_cast<int>( quadCount ); ++i )
{
profile->chaperoneGeometryQuads.emplace_back();
}
vr::VRChaperoneSetup()->GetLiveCollisionBoundsInfo(
profile->chaperoneGeometryQuads.get(), &quadCount );
profile->chaperoneGeometryQuads.data(), &quadCount );
vr::VRChaperoneSetup()->GetWorkingStandingZeroPoseToRawTrackingPose(
&profile->standingCenter );
vr::VRChaperoneSetup()->GetWorkingPlayAreaSize(
@@ -1332,7 +1063,6 @@ void ChaperoneTabController::addChaperoneProfile(
= chaperoneShowDashboardDistance();
}
saveChaperoneProfiles();
OverlayController::appSettings()->sync();
emit chaperoneProfilesUpdated();
}
@@ -1347,7 +1077,7 @@ void ChaperoneTabController::applyChaperoneProfile( unsigned index )
vr::VRChaperoneSetup()->HideWorkingSetPreview();
vr::VRChaperoneSetup()->RevertWorkingCopy();
vr::VRChaperoneSetup()->SetWorkingCollisionBoundsInfo(
profile.chaperoneGeometryQuads.get(),
profile.chaperoneGeometryQuads.data(),
profile.chaperoneGeometryQuadCount );
vr::VRChaperoneSetup()->SetWorkingStandingZeroPoseToRawTrackingPose(
&profile.standingCenter );
@@ -1436,7 +1166,6 @@ void ChaperoneTabController::deleteChaperoneProfile( unsigned index )
auto pos = chaperoneProfiles.begin() + index;
chaperoneProfiles.erase( pos );
saveChaperoneProfiles();
OverlayController::appSettings()->sync();
emit chaperoneProfilesUpdated();
}
}
@@ -1485,7 +1214,6 @@ void ChaperoneTabController::createNewAutosaveProfile()
chaperoneProfiles[currentAutosaveIndexLookup.second].profileName
= "«Autosaved Profile (previous)»";
saveChaperoneProfiles();
OverlayController::appSettings()->sync();
emit chaperoneProfilesUpdated();
}
else
+174 -2
View File
@@ -8,6 +8,7 @@
#include <openvr.h>
#include <cmath>
#include "../utils/FrameRateUtils.h"
#include "../settings/settings_object.h"
class QQuickWindow;
// application namespace
@@ -16,13 +17,13 @@ namespace advsettings
// forward declaration
class OverlayController;
struct ChaperoneProfile
struct ChaperoneProfile : settings::ISettingsObject
{
std::string profileName;
bool includesChaperoneGeometry = false;
unsigned chaperoneGeometryQuadCount = 0;
std::unique_ptr<vr::HmdQuad_t> chaperoneGeometryQuads = nullptr;
std::vector<vr::HmdQuad_t> chaperoneGeometryQuads;
vr::HmdMatrix34_t standingCenter;
float playSpaceAreaX = 0.0f;
float playSpaceAreaZ = 0.0f;
@@ -62,6 +63,177 @@ struct ChaperoneProfile
float chaperoneAlarmSoundDistance = 0.0f;
bool enableChaperoneShowDashboard = false;
float chaperoneShowDashboardDistance = 0.0f;
virtual settings::SettingsObjectData saveSettings() const override
{
settings::SettingsObjectData o;
o.addValue( profileName );
o.addValue( includesChaperoneGeometry );
o.addValue( static_cast<int>( chaperoneGeometryQuadCount ) );
if ( chaperoneGeometryQuadCount > 0 )
{
for ( auto& arrayMember : chaperoneGeometryQuads )
{
for ( auto& corner : arrayMember.vCorners )
{
for ( auto& vector : corner.v )
{
o.addValue( static_cast<double>( vector ) );
}
}
}
}
for ( int i = 0; i < 3; ++i )
{
for ( int j = 0; j < 4; ++j )
{
o.addValue( static_cast<double>( standingCenter.m[i][j] ) );
}
}
o.addValue( static_cast<double>( playSpaceAreaX ) );
o.addValue( static_cast<double>( playSpaceAreaZ ) );
o.addValue( includesVisibility );
o.addValue( static_cast<double>( visibility ) );
o.addValue( includesFadeDistance );
o.addValue( static_cast<double>( fadeDistance ) );
o.addValue( includesCenterMarker );
o.addValue( centerMarker );
o.addValue( includesPlaySpaceMarker );
o.addValue( playSpaceMarker );
o.addValue( includesFloorBoundsMarker );
o.addValue( floorBoundsMarker );
o.addValue( includesBoundsColor );
for ( const auto& c : boundsColor )
{
o.addValue( c );
}
o.addValue( includesChaperoneStyle );
o.addValue( chaperoneStyle );
o.addValue( includesForceBounds );
o.addValue( forceBounds );
o.addValue( includesProximityWarningSettings );
o.addValue( enableChaperoneSwitchToBeginner );
o.addValue( static_cast<double>( chaperoneSwitchToBeginnerDistance ) );
o.addValue( enableChaperoneHapticFeedback );
o.addValue( static_cast<double>( chaperoneHapticFeedbackDistance ) );
o.addValue( enableChaperoneAlarmSound );
o.addValue( chaperoneAlarmSoundLooping );
o.addValue( chaperoneAlarmSoundAdjustVolume );
o.addValue( static_cast<double>( chaperoneAlarmSoundDistance ) );
o.addValue( enableChaperoneShowDashboard );
o.addValue( static_cast<double>( chaperoneShowDashboardDistance ) );
return o;
}
virtual void loadSettings( settings::SettingsObjectData& obj ) override
{
profileName = obj.getNextValueOrDefault( "" );
includesChaperoneGeometry = obj.getNextValueOrDefault( false );
chaperoneGeometryQuadCount
= static_cast<unsigned>( obj.getNextValueOrDefault( 0 ) );
// chaperoneGeometryQuads = nullptr;
const auto chaperoneGeometryQuadsValid
= obj.getNextValueOrDefault( false );
if ( chaperoneGeometryQuadsValid )
{
for ( int i = 0; i < static_cast<int>( chaperoneGeometryQuadCount );
++i )
{
chaperoneGeometryQuads.emplace_back();
}
for ( auto& arrayMember : chaperoneGeometryQuads )
{
for ( auto& corner : arrayMember.vCorners )
{
for ( auto& vector : corner.v )
{
vector = static_cast<float>(
obj.getNextValueOrDefault( 0.0 ) );
}
}
}
}
for ( int i = 0; i < 3; ++i )
{
for ( int j = 0; j < 4; ++j )
{
standingCenter.m[i][j]
= static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
}
}
playSpaceAreaX = static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
playSpaceAreaZ = static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
includesVisibility = obj.getNextValueOrDefault( false );
visibility = static_cast<float>( obj.getNextValueOrDefault( 0.6 ) );
includesFadeDistance = obj.getNextValueOrDefault( false );
fadeDistance = static_cast<float>( obj.getNextValueOrDefault( 0.7 ) );
includesCenterMarker = obj.getNextValueOrDefault( false );
centerMarker = obj.getNextValueOrDefault( false );
includesPlaySpaceMarker = obj.getNextValueOrDefault( false );
playSpaceMarker = obj.getNextValueOrDefault( false );
includesFloorBoundsMarker = obj.getNextValueOrDefault( false );
floorBoundsMarker = obj.getNextValueOrDefault( false );
includesBoundsColor = obj.getNextValueOrDefault( false );
for ( auto& c : boundsColor )
{
c = obj.getNextValueOrDefault( 0 );
}
includesChaperoneStyle = obj.getNextValueOrDefault( false );
chaperoneStyle = obj.getNextValueOrDefault( 0 );
includesForceBounds = obj.getNextValueOrDefault( false );
forceBounds = obj.getNextValueOrDefault( false );
includesProximityWarningSettings = obj.getNextValueOrDefault( false );
enableChaperoneSwitchToBeginner = obj.getNextValueOrDefault( false );
chaperoneSwitchToBeginnerDistance
= static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
enableChaperoneHapticFeedback = obj.getNextValueOrDefault( false );
chaperoneHapticFeedbackDistance
= static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
enableChaperoneAlarmSound = obj.getNextValueOrDefault( false );
chaperoneAlarmSoundLooping = obj.getNextValueOrDefault( true );
chaperoneAlarmSoundAdjustVolume = obj.getNextValueOrDefault( false );
chaperoneAlarmSoundDistance
= static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
enableChaperoneShowDashboard = obj.getNextValueOrDefault( false );
chaperoneShowDashboardDistance
= static_cast<float>( obj.getNextValueOrDefault( 0.0 ) );
}
virtual std::string settingsName() const override
{
return "ChaperoneTabController::ChaperoneProfile";
}
};
class ChaperoneTabController : public QObject