-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathoverlaycontroller.cpp
More file actions
1686 lines (1538 loc) · 55.5 KB
/
overlaycontroller.cpp
File metadata and controls
1686 lines (1538 loc) · 55.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "overlaycontroller.h"
#include <QOpenGLFramebufferObjectFormat>
#include <QOpenGLPaintDevice>
#include <QPainter>
#include <QQuickView>
#include <QApplication>
#include <QQmlEngine>
#include <QQmlContext>
#include <QtWidgets/QWidget>
#include <QMouseEvent>
#include <QtWidgets/QGraphicsSceneMouseEvent>
#include <QtWidgets/QApplication>
#include <QtWidgets/QGraphicsEllipseItem>
#include <QOpenGLExtraFunctions>
#include <QCursor>
#include <QProcess>
#include <QMessageBox>
#include <iostream>
#include <cmath>
#include <openvr.h>
#include <easylogging++.h>
#include "utils/Matrix.h"
#include "keyboard_input/input_sender.h"
#include "settings/settings.h"
// application namespace
namespace advsettings
{
int verifyCustomTickRate( const int tickRate )
{
if ( tickRate < 1 )
{
return 1;
}
else if ( tickRate > k_maxCustomTickRate )
{
return k_maxCustomTickRate;
}
return tickRate;
}
OverlayController::OverlayController( bool desktopMode,
bool noSound,
QQmlEngine& qmlEngine )
: QObject(), m_desktopMode( desktopMode ), m_noSound( noSound ),
m_verifiedCustomTickRateMs( verifyCustomTickRate( settings::getSetting(
settings::IntSetting::APPLICATION_customTickRateMs ) ) ),
m_actions(), m_alarm()
{
// Arbitrarily chosen Max Length of Directory path, should be sufficient for
// Any set-up
const uint32_t maxLength = 16192;
uint32_t requiredLength;
char tempRuntimePath[maxLength];
bool pathIsGood
= vr::VR_GetRuntimePath( tempRuntimePath, maxLength, &requiredLength );
// Throw Error If over 16k characters in path string
if ( !pathIsGood )
{
LOG( ERROR ) << "Error Finding VR Runtime Path, Attempting Recovery: ";
uint32_t maxLengthRe = requiredLength;
LOG( INFO ) << "Open VR reporting Required path length of: "
<< maxLengthRe;
}
m_runtimePathUrl = QUrl::fromLocalFile( tempRuntimePath );
LOG( INFO ) << "VR Runtime Path: " << m_runtimePathUrl.toLocalFile();
constexpr auto clickSoundURL = "res/sounds/click.wav";
const auto activationSoundFile
= paths::binaryDirectoryFindFile( clickSoundURL );
if ( activationSoundFile.has_value() )
{
m_activationSoundEffect.setSource( QUrl::fromLocalFile(
QString::fromStdString( ( *activationSoundFile ) ) ) );
m_activationSoundEffect.setVolume( 0.7 );
}
else
{
LOG( ERROR ) << "Could not find activation sound file "
<< clickSoundURL;
}
constexpr auto focusChangedSoundURL = "res/sounds/focus.wav";
const auto focusChangedSoundFile
= paths::binaryDirectoryFindFile( focusChangedSoundURL );
if ( focusChangedSoundFile.has_value() )
{
m_focusChangedSoundEffect.setSource( QUrl::fromLocalFile(
QString::fromStdString( ( *focusChangedSoundFile ) ) ) );
m_focusChangedSoundEffect.setVolume( 0.7 );
}
else
{
LOG( ERROR ) << "Could not find focus Changed sound file "
<< focusChangedSoundURL;
}
constexpr auto alarmFileName = "res/sounds/alarm01.wav";
const auto alarm01SoundFile
= paths::binaryDirectoryFindFile( alarmFileName );
if ( alarm01SoundFile.has_value() )
{
m_alarm01SoundEffect.setSource( QUrl::fromLocalFile(
QString::fromStdString( ( *alarm01SoundFile ) ) ) );
m_alarm01SoundEffect.setVolume( 1.0 );
}
else
{
LOG( ERROR ) << "Could not find alarm01 sound file " << alarmFileName;
}
QSurfaceFormat format;
// Qt's QOpenGLPaintDevice is not compatible with OpenGL versions >= 3.0
// NVIDIA does not care, but unfortunately AMD does
// Are subtle changes to the semantics of OpenGL functions actually covered
// by the compatibility profile, and this is an AMD bug?
format.setVersion( 2, 1 );
// format.setProfile( QSurfaceFormat::CompatibilityProfile );
format.setDepthBufferSize( 16 );
format.setStencilBufferSize( 8 );
format.setSamples( 16 );
m_openGLContext.setFormat( format );
if ( !m_openGLContext.create() )
{
throw std::runtime_error( "Could not create OpenGL context" );
}
// create an offscreen surface to attach the context and FBO to
m_offscreenSurface.setFormat( m_openGLContext.format() );
m_offscreenSurface.create();
m_openGLContext.makeCurrent( &m_offscreenSurface );
if ( !vr::VROverlay() )
{
QMessageBox::critical(
nullptr, "OpenVR Advanced Settings Overlay", "Is OpenVR running?" );
throw std::runtime_error( std::string( "No Overlay interface" ) );
}
// Init controllers
m_steamVRTabController.initStage1();
m_chaperoneTabController.initStage1();
m_moveCenterTabController.initStage1();
m_audioTabController.initStage1();
m_settingsTabController.initStage1();
m_videoTabController.initStage1();
m_rotationTabController.initStage1();
// init action handles
m_chaperoneTabController.setLeftHapticActionHandle(
m_actions.leftHapticActionHandle() );
m_chaperoneTabController.setRightHapticActionHandle(
m_actions.rightHapticActionHandle() );
m_chaperoneTabController.setLeftInputHandle( m_actions.leftInputHandle() );
m_chaperoneTabController.setRightInputHandle(
m_actions.rightInputHandle() );
// Set qml context
qmlEngine.rootContext()->setContextProperty( "applicationVersion",
getVersionString() );
qmlEngine.rootContext()->setContextProperty( "vrRuntimePath",
getVRRuntimePathUrl() );
// Pretty disgusting trick to allow qmlRegisterSingletonType to continue
// working with the lambdas that were already there. The callback function
// in qmlRegisterSingletonType won't work with any lambdas that capture the
// environment. The alternative to making a static pointer to this was
// rewriting all QML to not be singletons, which should probably be done
// whenever possible.
static OverlayController* const objectAddress = this;
constexpr auto qmlSingletonImportName = "ovras.advsettings";
qmlRegisterSingletonType<OverlayController>(
qmlSingletonImportName,
1,
0,
"OverlayController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = objectAddress;
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
// It is unknown if it it intended for the generic in
// qmlRegisterSingletonType to be <SteamVRTabController> in all the
// remaining function calls, or if it's just a copy paste accident that
// happens to work.
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"SteamVRTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_steamVRTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"ChaperoneTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_chaperoneTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"MoveCenterTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_moveCenterTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"FixFloorTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_fixFloorTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"AudioTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_audioTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"StatisticsTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_statisticsTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"SettingsTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_settingsTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"UtilitiesTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_utilitiesTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"VideoTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_videoTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<SteamVRTabController>(
qmlSingletonImportName,
1,
0,
"RotationTabController",
[]( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_rotationTabController );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
qmlRegisterSingletonType<alarm_clock::VrAlarm>(
qmlSingletonImportName, 1, 0, "VrAlarm", []( QQmlEngine*, QJSEngine* ) {
QObject* obj = &( objectAddress->m_alarm );
QQmlEngine::setObjectOwnership( obj, QQmlEngine::CppOwnership );
return obj;
} );
// Grab local version number
QStringList verNumericalString
= QString( application_strings::applicationVersionString ).split( "-" );
QStringList verMajorMinorPatchString = verNumericalString[0].split( "." );
m_localVersionMajor = verMajorMinorPatchString[0].toInt();
m_localVersionMinor = verMajorMinorPatchString[1].toInt();
m_localVersionPatch = verMajorMinorPatchString[2].toInt();
// Init network manager
connect( netManager,
SIGNAL( finished( QNetworkReply* ) ),
this,
SLOT( OnNetworkReply( QNetworkReply* ) ) );
if ( !disableVersionCheck() )
{
QNetworkRequest netRequest;
netRequest.setUrl( QUrl( application_strings::versionCheckUrl ) );
netManager->get( netRequest );
}
else
{
LOG( INFO ) << "Version Check: Feature disabled. Not checking version.";
}
LOG( INFO ) << "OPENSSL VERSION: "
<< QSslSocket::sslLibraryBuildVersionString();
}
OverlayController::~OverlayController()
{
Shutdown();
}
void OverlayController::exitApp()
{
// save to settings that shutdown was safe
setPreviousShutdownSafe( true );
settings::saveAllSettings();
m_moveCenterTabController.shutdown();
// Un-mute mic before Exiting VR, as it is set at system level Not
// Vr level.
// m_audioTabController.setMicMuted( false, false );
m_audioTabController.shutdown();
m_chaperoneTabController.shutdown();
Shutdown();
QApplication::exit();
LOG( INFO ) << "All systems exited.";
exit( EXIT_SUCCESS );
// Does not fallthrough
}
void OverlayController::Shutdown()
{
disconnect( &m_pumpEventsTimer,
SIGNAL( timeout() ),
this,
SLOT( OnTimeoutPumpEvents() ) );
m_pumpEventsTimer.stop();
if ( m_pRenderTimer )
{
disconnect( &m_renderControl,
SIGNAL( renderRequested() ),
this,
SLOT( OnRenderRequest() ) );
disconnect( &m_renderControl,
SIGNAL( sceneChanged() ),
this,
SLOT( OnRenderRequest() ) );
disconnect( m_pRenderTimer.get(),
SIGNAL( timeout() ),
this,
SLOT( renderOverlay() ) );
m_pRenderTimer->stop();
m_pRenderTimer.reset();
}
m_pFbo.reset();
}
void OverlayController::SetWidget( QQuickItem* quickItem,
const std::string& name,
const std::string& key )
{
if ( !m_desktopMode )
{
vr::VROverlayError overlayError
= vr::VROverlay()->CreateDashboardOverlay(
key.c_str(),
name.c_str(),
&m_ulOverlayHandle,
&m_ulOverlayThumbnailHandle );
if ( overlayError != vr::VROverlayError_None )
{
if ( overlayError == vr::VROverlayError_KeyInUse )
{
QMessageBox::critical( nullptr,
"OpenVR Advanced Settings Overlay",
"Another instance is already running." );
}
throw std::runtime_error( std::string(
"Failed to create Overlay: "
+ std::string( vr::VROverlay()->GetOverlayErrorNameFromEnum(
overlayError ) ) ) );
}
vr::VROverlay()->SetOverlayWidthInMeters( m_ulOverlayHandle, 2.5f );
vr::VROverlay()->SetOverlayInputMethod(
m_ulOverlayHandle, vr::VROverlayInputMethod_Mouse );
vr::VROverlay()->SetOverlayFlag(
m_ulOverlayHandle,
vr::VROverlayFlags_SendVRSmoothScrollEvents,
true );
constexpr auto thumbiconFilename = "res/img/icons/thumbicon.png";
const auto thumbIconPath
= paths::binaryDirectoryFindFile( thumbiconFilename );
if ( thumbIconPath.has_value() )
{
vr::VROverlay()->SetOverlayFromFile( m_ulOverlayThumbnailHandle,
thumbIconPath->c_str() );
}
else
{
LOG( ERROR ) << "Could not find thumbnail icon \""
<< thumbiconFilename << "\"";
}
// Too many render calls in too short time overwhelm Qt and an
// assertion gets thrown. Therefore we use an timer to delay render
// calls
m_pRenderTimer.reset( new QTimer() );
m_pRenderTimer->setSingleShot( true );
m_pRenderTimer->setInterval( 5 );
connect( m_pRenderTimer.get(),
SIGNAL( timeout() ),
this,
SLOT( renderOverlay() ) );
QOpenGLFramebufferObjectFormat fboFormat;
fboFormat.setAttachment(
QOpenGLFramebufferObject::CombinedDepthStencil );
fboFormat.setTextureTarget( GL_TEXTURE_2D );
m_pFbo.reset( new QOpenGLFramebufferObject(
static_cast<int>( quickItem->width() ),
static_cast<int>( quickItem->height() ),
fboFormat ) );
m_window.setRenderTarget( m_pFbo.get() );
quickItem->setParentItem( m_window.contentItem() );
m_window.setGeometry( 0,
0,
static_cast<int>( quickItem->width() ),
static_cast<int>( quickItem->height() ) );
m_renderControl.initialize( &m_openGLContext );
vr::HmdVector2_t vecWindowSize
= { static_cast<float>( quickItem->width() ),
static_cast<float>( quickItem->height() ) };
vr::VROverlay()->SetOverlayMouseScale( m_ulOverlayHandle,
&vecWindowSize );
connect( &m_renderControl,
SIGNAL( renderRequested() ),
this,
SLOT( OnRenderRequest() ) );
connect( &m_renderControl,
SIGNAL( sceneChanged() ),
this,
SLOT( OnRenderRequest() ) );
}
connect( &m_pumpEventsTimer,
SIGNAL( timeout() ),
this,
SLOT( OnTimeoutPumpEvents() ) );
// Every 1ms we check if the current frame has advanced (for vsync)
m_pumpEventsTimer.setInterval( 1 );
m_pumpEventsTimer.start();
m_steamVRTabController.initStage2( this );
m_chaperoneTabController.initStage2( this );
m_fixFloorTabController.initStage2( this );
m_audioTabController.initStage2();
m_statisticsTabController.initStage2( this );
m_settingsTabController.initStage2( this );
m_utilitiesTabController.initStage2( this );
m_moveCenterTabController.initStage2( this );
m_rotationTabController.initStage2( this );
m_videoTabController.initStage2();
}
void OverlayController::OnRenderRequest()
{
if ( m_pRenderTimer && !m_pRenderTimer->isActive() )
{
m_pRenderTimer->start();
}
}
void OverlayController::renderOverlay()
{
if ( !m_desktopMode )
{
// skip rendering if the overlay isn't visible
if ( !vr::VROverlay()
|| ( !vr::VROverlay()->IsOverlayVisible( m_ulOverlayHandle )
&& !vr::VROverlay()->IsOverlayVisible(
m_ulOverlayThumbnailHandle ) ) )
return;
m_renderControl.polishItems();
m_renderControl.sync();
m_renderControl.render();
GLuint unTexture = m_pFbo->texture();
if ( unTexture != 0 )
{
#if defined _WIN64 || defined _LP64
// To avoid any compiler warning because of cast to a larger
// pointer type (warning C4312 on VC)
vr::Texture_t texture = { reinterpret_cast<void*>(
static_cast<uint64_t>( unTexture ) ),
vr::TextureType_OpenGL,
vr::ColorSpace_Auto };
#else
vr::Texture_t texture = { reinterpret_cast<void*>( unTexture ),
vr::TextureType_OpenGL,
vr::ColorSpace_Auto };
#endif
vr::VROverlay()->SetOverlayTexture( m_ulOverlayHandle, &texture );
}
m_openGLContext.functions()->glFlush(); // We need to flush otherwise
// the texture may be empty.*/
}
}
bool OverlayController::pollNextEvent( vr::VROverlayHandle_t ulOverlayHandle,
vr::VREvent_t* pEvent )
{
if ( isDesktopMode() )
{
return vr::VRSystem()->PollNextEvent( pEvent, sizeof( vr::VREvent_t ) );
}
else
{
return vr::VROverlay()->PollNextOverlayEvent(
ulOverlayHandle, pEvent, sizeof( vr::VREvent_t ) );
}
}
QPoint OverlayController::getMousePositionForEvent( vr::VREvent_Mouse_t mouse )
{
float y = mouse.y;
#ifdef __linux__
float h = static_cast<float>( m_window.height() );
y = h - y;
#endif
return QPoint( static_cast<int>( mouse.x ), static_cast<int>( y ) );
}
void OverlayController::processMediaKeyBindings()
{
if ( m_actions.nextSong() )
{
m_utilitiesTabController.sendMediaNextSong();
}
if ( m_actions.previousSong() )
{
m_utilitiesTabController.sendMediaPreviousSong();
}
if ( m_actions.pausePlaySong() )
{
m_utilitiesTabController.sendMediaPausePlay();
}
if ( m_actions.stopSong() )
{
m_utilitiesTabController.sendMediaStopSong();
}
}
void OverlayController::processMotionBindings()
{
// Execution order for moveCenterTabController actions is important.
// Don't reorder these. Override actions must always come after normal
// because active priority is set based on which action is "newest"
// normal actions:
m_moveCenterTabController.leftHandSpaceDrag(
m_actions.leftHandSpaceDrag() );
m_moveCenterTabController.rightHandSpaceDrag(
m_actions.rightHandSpaceDrag() );
m_moveCenterTabController.leftHandSpaceTurn(
m_actions.leftHandSpaceTurn() );
m_moveCenterTabController.rightHandSpaceTurn(
m_actions.rightHandSpaceTurn() );
m_moveCenterTabController.gravityToggleAction( m_actions.gravityToggle() );
m_moveCenterTabController.gravityReverseAction(
m_actions.gravityReverse() );
m_moveCenterTabController.heightToggleAction( m_actions.heightToggle() );
m_moveCenterTabController.resetOffsets( m_actions.resetOffsets() );
m_moveCenterTabController.snapTurnLeft( m_actions.snapTurnLeft() );
m_moveCenterTabController.snapTurnRight( m_actions.snapTurnRight() );
m_moveCenterTabController.smoothTurnLeft( m_actions.smoothTurnLeft() );
m_moveCenterTabController.smoothTurnRight( m_actions.smoothTurnRight() );
m_moveCenterTabController.xAxisLockToggle( m_actions.xAxisLockToggle() );
m_moveCenterTabController.yAxisLockToggle( m_actions.yAxisLockToggle() );
m_moveCenterTabController.zAxisLockToggle( m_actions.zAxisLockToggle() );
// override actions:
m_moveCenterTabController.optionalOverrideLeftHandSpaceDrag(
m_actions.optionalOverrideLeftHandSpaceDrag() );
m_moveCenterTabController.optionalOverrideRightHandSpaceDrag(
m_actions.optionalOverrideRightHandSpaceDrag() );
m_moveCenterTabController.optionalOverrideLeftHandSpaceTurn(
m_actions.optionalOverrideLeftHandSpaceTurn() );
m_moveCenterTabController.optionalOverrideRightHandSpaceTurn(
m_actions.optionalOverrideRightHandSpaceTurn() );
m_moveCenterTabController.swapSpaceDragToLeftHandOverride(
m_actions.swapSpaceDragToLeftHandOverride() );
m_moveCenterTabController.swapSpaceDragToRightHandOverride(
m_actions.swapSpaceDragToRightHandOverride() );
}
void OverlayController::processChaperoneBindings()
{
if ( m_actions.chaperoneToggle() )
{
m_chaperoneTabController.setDisableChaperone(
!( m_chaperoneTabController.disableChaperone() ), true );
}
m_chaperoneTabController.setProxState( m_actions.proxState() );
m_chaperoneTabController.addLeftHapticClick(
m_actions.addLeftHapticClick() );
m_chaperoneTabController.addRightHapticClick(
m_actions.addRightHapticClick() );
}
void OverlayController::processPushToTalkBindings()
{
const auto pushToTalkCannotChange = !m_audioTabController.pttChangeValid();
const auto pushToTalkEnabled = m_audioTabController.pttEnabled();
const auto proxSensorActivated = m_actions.proxState();
const auto useProxSensor = m_audioTabController.micProximitySensorCanMute();
if ( useProxSensor )
{
if ( !proxSensorActivated )
{
m_audioTabController.setMicMuted( true );
return;
}
// strictly speaking this is not the most elegant solution, but
// should work well enough.
else if ( !pushToTalkEnabled )
{
m_audioTabController.setMicMuted( false );
}
}
if ( pushToTalkCannotChange || !pushToTalkEnabled )
{
return;
}
const auto pushToTalkButtonActivated = m_actions.pushToTalk();
const auto pushToTalkCurrentlyActive = m_audioTabController.pttActive();
if ( pushToTalkButtonActivated && !pushToTalkCurrentlyActive )
{
m_audioTabController.startPtt();
}
else if ( !pushToTalkButtonActivated && pushToTalkCurrentlyActive )
{
m_audioTabController.stopPtt();
}
}
void OverlayController::processKeyboardBindings()
{
if ( m_actions.keyboardOne() )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyboardOne );
sendStringAsInput( commands );
}
if ( m_actions.keyboardTwo() )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyboardTwo );
sendStringAsInput( commands );
}
if ( m_actions.keyboardThree() )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyboardThree );
sendStringAsInput( commands );
}
// Press Key One
if ( m_actions.keyPressMisc() && !m_keyPressOneState )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyPressMisc );
sendFirstCharAsInput( commands, KeyStatus::Down );
m_keyPressOneState = true;
}
if ( m_keyPressOneState && !m_actions.keyPressMisc() )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyPressMisc );
sendFirstCharAsInput( commands, KeyStatus::Up );
m_keyPressOneState = false;
}
// Press Key Two
if ( m_actions.keyPressSystem() && !m_keyPressTwoState )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyPressSystem );
sendFirstCharAsInput( commands, KeyStatus::Down );
m_keyPressTwoState = true;
}
if ( m_keyPressTwoState && !m_actions.keyPressSystem() )
{
const auto commands = settings::getSetting(
settings::StringSetting::KEYBOARDSHORTCUT_keyPressSystem );
sendFirstCharAsInput( commands, KeyStatus::Up );
m_keyPressTwoState = false;
}
}
void OverlayController::processExclusiveInputBinding()
{
if ( m_actions.exclusiveInputToggle() && exclusiveInputEnabled() )
{
m_exclusiveState = !m_exclusiveState;
m_actions.systemActionSetOnlyEnabled( !m_exclusiveState );
m_actions.actionSetPriorityToggle( m_exclusiveState );
}
}
void OverlayController::processRotationBindings()
{
if ( m_actions.autoTurnToggle() )
{
m_rotationTabController.setAutoTurnEnabled(
!( m_rotationTabController.autoTurnEnabled() ) );
}
if ( m_actions.addAutoAlignPointLeft() )
{
m_rotationTabController.addAutoAlignPoint( false );
}
if ( m_actions.addAutoAlignPointRight() )
{
m_rotationTabController.addAutoAlignPoint( true );
}
}
/*!
Checks if an action has been activated and dispatches the related action if
it has been.
*/
void OverlayController::processInputBindings()
{
processExclusiveInputBinding();
processMediaKeyBindings();
processMotionBindings();
processPushToTalkBindings();
processChaperoneBindings();
processKeyboardBindings();
processRotationBindings();
}
bool OverlayController::exclusiveInputEnabled() const
{
return settings::getSetting(
settings::BoolSetting::APPLICATION_enableExclusiveInput );
}
void OverlayController::setExclusiveInputEnabled( bool value, bool notify )
{
settings::setSetting(
settings::BoolSetting::APPLICATION_enableExclusiveInput, value );
// Note: These Calls technically modify data that could be accessed
// elsewhere and cause threading issues. Since this should only be
// accessible in dashboard, and input is disabled while dashboard is up,
// there should be no reason to lock it. If it becomes an issue this needs
// to be locked with a mutex or similiar against the
// processexclusivebindings
if ( value )
{
// Re-Enable Required SteamVR key every toggle just in case.
ovr_settings_wrapper::setBool(
vr::k_pch_SteamVR_Section,
vr::k_pch_SteamVR_AllowGlobalActionSetPriority,
value );
// To setup Exclusive Input OVRAS actions should be off besides System
// (+haptics) which are always on.
m_actions.systemActionSetOnlyEnabled( true );
}
else
{
// Enable All Action Sets
m_actions.systemActionSetOnlyEnabled( false );
// Remove All priority
m_actions.actionSetPriorityToggle( false );
}
if ( notify )
{
emit exclusiveInputEnabledChanged( value );
}
}
bool OverlayController::crashRecoveryDisabled() const
{
return settings::getSetting(
settings::BoolSetting::APPLICATION_crashRecoveryDisabled );
}
void OverlayController::setCrashRecoveryDisabled( bool value, bool notify )
{
settings::setSetting(
settings::BoolSetting::APPLICATION_crashRecoveryDisabled, value );
if ( notify )
{
emit crashRecoveryDisabledChanged( value );
}
}
bool OverlayController::vsyncDisabled() const
{
return settings::getSetting(
settings::BoolSetting::APPLICATION_vsyncDisabled );
}
void OverlayController::setVsyncDisabled( bool value, bool notify )
{
settings::setSetting( settings::BoolSetting::APPLICATION_vsyncDisabled,
value );
if ( notify )
{
emit vsyncDisabledChanged( value );
}
}
bool OverlayController::enableDebug() const
{
return settings::getSetting(
settings::BoolSetting::APPLICATION_enableDebug );
}
void OverlayController::setEnableDebug( bool value, bool notify )
{
settings::setSetting( settings::BoolSetting::APPLICATION_enableDebug,
value );
if ( notify )
{
emit enableDebugChanged( value );
}
}
bool OverlayController::disableVersionCheck() const
{
return settings::getSetting(
settings::BoolSetting::APPLICATION_disableVersionCheck );
}
void OverlayController::setDisableVersionCheck( bool value, bool notify )
{
if ( !value )
{
QNetworkRequest netRequest;
netRequest.setUrl( QUrl( application_strings::versionCheckUrl ) );
netManager->get( netRequest );
}
settings::setSetting(
settings::BoolSetting::APPLICATION_disableVersionCheck, value );
if ( notify )
{
emit disableVersionCheckChanged( value );
}
}
bool OverlayController::newVersionDetected() const
{
return m_newVersionDetected;
}
void OverlayController::setNewVersionDetected( bool value, bool notify )
{
if ( m_newVersionDetected == value )
{
return;
}
m_newVersionDetected = value;
if ( notify )
{
emit newVersionDetectedChanged( m_newVersionDetected );
}
}
QString OverlayController::versionCheckText() const
{
return m_versionCheckText;
}
void OverlayController::setVersionCheckText( QString value, bool notify )
{
m_versionCheckText = value;
LOG( INFO ) << "m_versionCheckText = " << m_versionCheckText;
if ( notify )
{
emit versionCheckTextChanged( m_versionCheckText );
}
}
int OverlayController::debugState() const
{
return settings::getSetting( settings::IntSetting::APPLICATION_debugState );
}
void OverlayController::setDebugState( int value, bool notify )
{
settings::setSetting( settings::IntSetting::APPLICATION_debugState, value );
if ( notify )
{
emit debugStateChanged( value );
}
}
void OverlayController::setPreviousShutdownSafe( bool value )
{
settings::setSetting(
settings::BoolSetting::APPLICATION_previousShutdownSafe, value );
}
int OverlayController::customTickRateMs() const
{
return m_verifiedCustomTickRateMs;
}
void OverlayController::setCustomTickRateMs( int value, bool notify )
{
const auto verifiedTickRate = verifyCustomTickRate( value );
settings::setSetting( settings::IntSetting::APPLICATION_customTickRateMs,
verifiedTickRate );
m_verifiedCustomTickRateMs = verifiedTickRate;
if ( notify )
{
emit customTickRateMsChanged( verifiedTickRate );
}
}
// vsync implementation:
// this function triggers every 1ms
// this function should remain lightweight and only check if it's time to
// run mainEventLoop() or not.
void OverlayController::OnTimeoutPumpEvents()
{
if ( vsyncDisabled() )
{
// check if it's time for a custom tick rate tick
if ( m_customTickRateCounter > customTickRateMs() )
{
mainEventLoop();
m_customTickRateCounter = 0;
updateRate.incrementCounter();
}
else
{
m_customTickRateCounter++;
}
}
// vsync is enabled
else
{
// get the current frame number from the VRSystem frame counter
vr::VRSystem()->GetTimeSinceLastVsync( nullptr, &m_currentFrame );
// Check if we are in the next frame yet
if ( m_currentFrame > m_lastFrame )