mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-07 10:02:24 +02:00
Merge pull request #14787 from wayne-chen/oculusLoginFeature
MS20874: Only initialize plugin if started through Oculus Store
This commit is contained in:
commit
536a76a791
4 changed files with 96 additions and 68 deletions
|
@ -802,6 +802,10 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
|||
if (auto steamClient = pluginManager->getSteamClientPlugin()) {
|
||||
steamClient->init();
|
||||
}
|
||||
if (auto oculusPlatform = pluginManager->getOculusPlatformPlugin()) {
|
||||
oculusPlatform->init();
|
||||
}
|
||||
|
||||
PROFILE_SET_THREAD_NAME("Main Thread");
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
|
@ -2745,6 +2749,10 @@ Application::~Application() {
|
|||
steamClient->shutdown();
|
||||
}
|
||||
|
||||
if (auto oculusPlatform = PluginManager::getInstance()->getOculusPlatformPlugin()) {
|
||||
oculusPlatform->shutdown();
|
||||
}
|
||||
|
||||
DependencyManager::destroy<PluginManager>();
|
||||
|
||||
DependencyManager::destroy<CompositorHelper>(); // must be destroyed before the FramebufferCache
|
||||
|
|
|
@ -20,6 +20,9 @@ public:
|
|||
virtual QString getName() const = 0;
|
||||
virtual QString getOculusUserID() const = 0;
|
||||
|
||||
virtual bool init() = 0;
|
||||
virtual void shutdown() = 0;
|
||||
|
||||
virtual bool isRunning() const = 0;
|
||||
|
||||
virtual void requestNonceAndUserID(NonceUserIDCallback callback) = 0;
|
||||
|
|
|
@ -16,20 +16,31 @@
|
|||
|
||||
QString OculusAPIPlugin::NAME { "Oculus Rift" };
|
||||
|
||||
OculusAPIPlugin::OculusAPIPlugin() {
|
||||
_session = hifi::ovr::acquireRenderSession();
|
||||
bool OculusAPIPlugin::init() {
|
||||
if (qApp->property(hifi::properties::OCULUS_STORE).toBool()) {
|
||||
_session = hifi::ovr::acquireRenderSession();
|
||||
}
|
||||
return _session;
|
||||
}
|
||||
|
||||
OculusAPIPlugin::~OculusAPIPlugin() {
|
||||
hifi::ovr::releaseRenderSession(_session);
|
||||
void OculusAPIPlugin::shutdown() {
|
||||
if (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()) {
|
||||
qCWarning(oculusLog) << "Oculus request failed: Oculus platform plugin not running";
|
||||
callback("", "");
|
||||
return;
|
||||
}
|
||||
|
||||
_nonceUserIDCallback = callback;
|
||||
ovr_User_GetUserProof();
|
||||
ovr_User_GetLoggedInUser();
|
||||
|
@ -38,72 +49,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
|
||||
}
|
||||
|
|
|
@ -16,13 +16,17 @@
|
|||
|
||||
class OculusAPIPlugin : public OculusPlatformPlugin {
|
||||
public:
|
||||
OculusAPIPlugin();
|
||||
virtual ~OculusAPIPlugin();
|
||||
OculusAPIPlugin() = default;
|
||||
virtual ~OculusAPIPlugin() = default;
|
||||
QString getName() const { return NAME; }
|
||||
QString getOculusUserID() const { return _user; };
|
||||
|
||||
bool isRunning() const;
|
||||
|
||||
bool init();
|
||||
|
||||
void shutdown();
|
||||
|
||||
virtual void requestNonceAndUserID(NonceUserIDCallback callback);
|
||||
|
||||
virtual void handleOVREvents();
|
||||
|
|
Loading…
Reference in a new issue