mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 20:58:38 +02: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" };
|
QString OculusAPIPlugin::NAME { "Oculus Rift" };
|
||||||
|
|
||||||
OculusAPIPlugin::OculusAPIPlugin() {
|
OculusAPIPlugin::OculusAPIPlugin() {
|
||||||
if (isRunning()) {
|
if (hifi::ovr::available()) {
|
||||||
_session = hifi::ovr::acquireRenderSession();
|
_session = hifi::ovr::acquireRenderSession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OculusAPIPlugin::~OculusAPIPlugin() {
|
OculusAPIPlugin::~OculusAPIPlugin() {
|
||||||
if (isRunning()) {
|
if (hifi::ovr::available() && isRunning()) {
|
||||||
hifi::ovr::releaseRenderSession(_session);
|
hifi::ovr::releaseRenderSession(_session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OculusAPIPlugin::isRunning() const {
|
bool OculusAPIPlugin::isRunning() const {
|
||||||
return (qApp->property(hifi::properties::OCULUS_STORE).toBool());
|
return _session;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OculusAPIPlugin::requestNonceAndUserID(NonceUserIDCallback callback) {
|
void OculusAPIPlugin::requestNonceAndUserID(NonceUserIDCallback callback) {
|
||||||
#ifdef OCULUS_APP_ID
|
#ifdef OCULUS_APP_ID
|
||||||
|
if (!isRunning()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_nonceUserIDCallback = callback;
|
_nonceUserIDCallback = callback;
|
||||||
ovr_User_GetUserProof();
|
ovr_User_GetUserProof();
|
||||||
ovr_User_GetLoggedInUser();
|
ovr_User_GetLoggedInUser();
|
||||||
|
@ -42,72 +46,74 @@ void OculusAPIPlugin::requestNonceAndUserID(NonceUserIDCallback callback) {
|
||||||
|
|
||||||
void OculusAPIPlugin::handleOVREvents() {
|
void OculusAPIPlugin::handleOVREvents() {
|
||||||
#ifdef OCULUS_APP_ID
|
#ifdef OCULUS_APP_ID
|
||||||
if (qApp->property(hifi::properties::OCULUS_STORE).toBool()) {
|
if (!isRunning()) {
|
||||||
// pop messages to see if we got a return for an entitlement check
|
return;
|
||||||
ovrMessageHandle message { nullptr };
|
}
|
||||||
|
|
||||||
// pop the next message to check, if there is one
|
// pop messages to see if we got a return for an entitlement check
|
||||||
while ((message = ovr_PopMessage())) {
|
ovrMessageHandle message { nullptr };
|
||||||
switch (ovr_Message_GetType(message)) {
|
|
||||||
case ovrMessage_Entitlement_GetIsViewerEntitled: {
|
// pop the next message to check, if there is one
|
||||||
if (!ovr_Message_IsError(message)) {
|
while ((message = ovr_PopMessage())) {
|
||||||
// this viewer is entitled, no need to flag anything
|
switch (ovr_Message_GetType(message)) {
|
||||||
qCDebug(oculusLog) << "Oculus Platform entitlement check succeeded, proceeding normally";
|
case ovrMessage_Entitlement_GetIsViewerEntitled: {
|
||||||
} else {
|
if (!ovr_Message_IsError(message)) {
|
||||||
// we failed the entitlement check, quit
|
// this viewer is entitled, no need to flag anything
|
||||||
qCDebug(oculusLog) << "Oculus Platform entitlement check failed, app will now quit" << OCULUS_APP_ID;
|
qCDebug(oculusLog) << "Oculus Platform entitlement check succeeded, proceeding normally";
|
||||||
QMetaObject::invokeMethod(qApp, "quit");
|
} else {
|
||||||
}
|
// we failed the entitlement check, quit
|
||||||
break;
|
qCDebug(oculusLog) << "Oculus Platform entitlement check failed, app will now quit" << OCULUS_APP_ID;
|
||||||
}
|
QMetaObject::invokeMethod(qApp, "quit");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case ovrMessage_User_Get: {
|
||||||
if (_nonceChanged && _userIDChanged) {
|
if (!ovr_Message_IsError(message)) {
|
||||||
_nonceUserIDCallback(_nonce, QString::number(_userID));
|
qCDebug(oculusLog) << "Oculus Platform user retrieval succeeded";
|
||||||
_nonceChanged = _userIDChanged = false;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue