mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
adding code for if oculus is running
This commit is contained in:
parent
09770920a8
commit
c06f2f337e
1 changed files with 70 additions and 64 deletions
|
@ -17,23 +17,27 @@
|
|||
QString OculusAPIPlugin::NAME { "Oculus Rift" };
|
||||
|
||||
OculusAPIPlugin::OculusAPIPlugin() {
|
||||
if (isRunning()) {
|
||||
if (hifi::ovr::available()) {
|
||||
_session = hifi::ovr::acquireRenderSession();
|
||||
}
|
||||
}
|
||||
|
||||
OculusAPIPlugin::~OculusAPIPlugin() {
|
||||
if (isRunning()) {
|
||||
if (hifi::ovr::available() && isRunning()) {
|
||||
hifi::ovr::releaseRenderSession(_session);
|
||||
}
|
||||
}
|
||||
|
||||
bool OculusAPIPlugin::isRunning() const {
|
||||
return (qApp->property(hifi::properties::OCULUS_STORE).toBool());
|
||||
return _session;
|
||||
}
|
||||
|
||||
void OculusAPIPlugin::requestNonceAndUserID(NonceUserIDCallback callback) {
|
||||
#ifdef OCULUS_APP_ID
|
||||
if (!isRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_nonceUserIDCallback = callback;
|
||||
ovr_User_GetUserProof();
|
||||
ovr_User_GetLoggedInUser();
|
||||
|
@ -42,72 +46,74 @@ void OculusAPIPlugin::requestNonceAndUserID(NonceUserIDCallback callback) {
|
|||
|
||||
void OculusAPIPlugin::handleOVREvents() {
|
||||
#ifdef OCULUS_APP_ID
|
||||
if (qApp->property(hifi::properties::OCULUS_STORE).toBool()) {
|
||||
// pop messages to see if we got a return for an entitlement check
|
||||
ovrMessageHandle message { nullptr };
|
||||
if (!isRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// pop the next message to check, if there is one
|
||||
while ((message = ovr_PopMessage())) {
|
||||
switch (ovr_Message_GetType(message)) {
|
||||
case ovrMessage_Entitlement_GetIsViewerEntitled: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
// this viewer is entitled, no need to flag anything
|
||||
qCDebug(oculusLog) << "Oculus Platform entitlement check succeeded, proceeding normally";
|
||||
} else {
|
||||
// we failed the entitlement check, quit
|
||||
qCDebug(oculusLog) << "Oculus Platform entitlement check failed, app will now quit" << OCULUS_APP_ID;
|
||||
QMetaObject::invokeMethod(qApp, "quit");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ovrMessage_User_Get: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
qCDebug(oculusLog) << "Oculus Platform user retrieval succeeded";
|
||||
ovrUserHandle user = ovr_Message_GetUser(message);
|
||||
_user = ovr_User_GetOculusID(user);
|
||||
// went all the way through the `requestNonceAndUserID()` pipeline successfully.
|
||||
} else {
|
||||
qCDebug(oculusLog) << "Oculus Platform user retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
|
||||
// emit the signal so we don't hang for it anywhere else.
|
||||
_user = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ovrMessage_User_GetLoggedInUser: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
ovrUserHandle user = ovr_Message_GetUser(message);
|
||||
_userID = ovr_User_GetID(user);
|
||||
ovr_User_Get(_userID);
|
||||
} else {
|
||||
qCDebug(oculusLog) << "Oculus Platform user ID retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
|
||||
// emit the signal so we don't hang for it anywhere else.
|
||||
}
|
||||
_userIDChanged = true;
|
||||
break;
|
||||
}
|
||||
case ovrMessage_User_GetUserProof: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
ovrUserProofHandle userProof = ovr_Message_GetUserProof(message);
|
||||
_nonce = ovr_UserProof_GetNonce(userProof);
|
||||
qCDebug(oculusLog) << "Oculus Platform nonce retrieval succeeded: " << _nonce;
|
||||
} else {
|
||||
qCDebug(oculusLog) << "Oculus Platform nonce retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
|
||||
_nonce = "";
|
||||
// emit the signal so we don't hang for it anywhere else.
|
||||
}
|
||||
_nonceChanged = true;
|
||||
break;
|
||||
// pop messages to see if we got a return for an entitlement check
|
||||
ovrMessageHandle message { nullptr };
|
||||
|
||||
// pop the next message to check, if there is one
|
||||
while ((message = ovr_PopMessage())) {
|
||||
switch (ovr_Message_GetType(message)) {
|
||||
case ovrMessage_Entitlement_GetIsViewerEntitled: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
// this viewer is entitled, no need to flag anything
|
||||
qCDebug(oculusLog) << "Oculus Platform entitlement check succeeded, proceeding normally";
|
||||
} else {
|
||||
// we failed the entitlement check, quit
|
||||
qCDebug(oculusLog) << "Oculus Platform entitlement check failed, app will now quit" << OCULUS_APP_ID;
|
||||
QMetaObject::invokeMethod(qApp, "quit");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (_nonceChanged && _userIDChanged) {
|
||||
_nonceUserIDCallback(_nonce, QString::number(_userID));
|
||||
_nonceChanged = _userIDChanged = false;
|
||||
case ovrMessage_User_Get: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
qCDebug(oculusLog) << "Oculus Platform user retrieval succeeded";
|
||||
ovrUserHandle user = ovr_Message_GetUser(message);
|
||||
_user = ovr_User_GetOculusID(user);
|
||||
// went all the way through the `requestNonceAndUserID()` pipeline successfully.
|
||||
} else {
|
||||
qCDebug(oculusLog) << "Oculus Platform user retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
|
||||
// emit the signal so we don't hang for it anywhere else.
|
||||
_user = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ovrMessage_User_GetLoggedInUser: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
ovrUserHandle user = ovr_Message_GetUser(message);
|
||||
_userID = ovr_User_GetID(user);
|
||||
ovr_User_Get(_userID);
|
||||
} else {
|
||||
qCDebug(oculusLog) << "Oculus Platform user ID retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
|
||||
// emit the signal so we don't hang for it anywhere else.
|
||||
}
|
||||
_userIDChanged = true;
|
||||
break;
|
||||
}
|
||||
case ovrMessage_User_GetUserProof: {
|
||||
if (!ovr_Message_IsError(message)) {
|
||||
ovrUserProofHandle userProof = ovr_Message_GetUserProof(message);
|
||||
_nonce = ovr_UserProof_GetNonce(userProof);
|
||||
qCDebug(oculusLog) << "Oculus Platform nonce retrieval succeeded: " << _nonce;
|
||||
} else {
|
||||
qCDebug(oculusLog) << "Oculus Platform nonce retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
|
||||
_nonce = "";
|
||||
// emit the signal so we don't hang for it anywhere else.
|
||||
}
|
||||
_nonceChanged = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// free the message handle to cleanup and not leak
|
||||
ovr_FreeMessage(message);
|
||||
}
|
||||
|
||||
if (_nonceChanged && _userIDChanged) {
|
||||
_nonceUserIDCallback(_nonce, QString::number(_userID));
|
||||
_nonceChanged = _userIDChanged = false;
|
||||
}
|
||||
|
||||
// free the message handle to cleanup and not leak
|
||||
ovr_FreeMessage(message);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue