diff --git a/README.md b/README.md index d80caa1..726e638 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Clone the repository and **initialise the submodules** with `git submodule updat #### Oculus Mobile SDK - Download the [latest version](https://developer.oculus.com/downloads/package/oculus-mobile-sdk/) -(**Oculus Mobile SDK 27.0** (1.44.0) or higher) of the Oculus Mobile SDK and extract it into the +(**Oculus Mobile SDK 33.0** (1.50.0) or higher) of the Oculus Mobile SDK and extract it into the `plugin/libs/ovr_sdk_mobile` directory (create the directory if it doesn't exist). - If you change the default install location, update the `OVR_ROOT_DIR` cmake variable in the the `plugin/CMakeLists.txt` build file to point to the Oculus Mobile SDK install location. @@ -68,7 +68,7 @@ Clone the repository and **initialise the submodules** with `git submodule updat #### Android SDK & NDK - Download and setup - [Android Studio version **4.1** or higher](https://developer.android.com/studio). + [Android Studio version **4.2** or higher](https://developer.android.com/studio). - After setup, ensure you have the latest versions by checking the [SDK Manager](https://developer.android.com/studio/intro/update.html#sdk-manager) for updates. - Set the environment variable `ANDROID_HOME` to the Android SDK location. - Follow the instructions [here](https://developer.android.com/studio/projects/install-ndk#specific-version) and install version **21.1.6352462** of the NDK. diff --git a/build.gradle b/build.gradle index 3ea115c..bbf53c8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:$versions.gradlePluginVersion" @@ -16,7 +16,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } @@ -46,20 +46,20 @@ task generatePluginBinary(type: Copy) { * This is mostly to be used by maintainers to update the https://github.com/GodotVR/godot-oculus-mobile-asset repo. */ task generateSharedLibs(type: Copy) { - dependsOn(":OVRMobile:externalNativeBuildDebug") - dependsOn(":OVRMobile:externalNativeBuildRelease") + dependsOn(":OVRMobile:externalNativeBuildFullDebug") + dependsOn(":OVRMobile:externalNativeBuildFullRelease") // Specify the base directory. All following 'into' targets will be relative // to this directory. into("$outputDir/sharedLibs") // Copy the generated debug shared libs into the outputs directory - from("plugin/build/intermediates/cmake/debug/obj") { + from("plugin/build/intermediates/cmake/fullDebug/obj") { into("debug") } // Copy the generated release shared libs into the outputs directory - from("plugin/build/intermediates/cmake/release/obj") { + from("plugin/build/intermediates/cmake/fullRelease/obj") { into("release") } } diff --git a/config.gradle b/config.gradle index d259016..e2b4d35 100644 --- a/config.gradle +++ b/config.gradle @@ -1,9 +1,12 @@ ext.versions = [ - gradlePluginVersion: '4.1.0', + gradlePluginVersion: '4.2.1', compileSdk : 30, - minSdk : 18, + minSdk : 19, targetSdk : 30, - buildTools : '30.0.1', - kotlinVersion : '1.4.31', - ndkVersion : "21.3.6528147" + buildTools : '30.0.3', + kotlinVersion : '1.5.20', + ndkVersion : "21.4.7075529", + javaVersion : JavaVersion.VERSION_1_8, + libVersionCode : 30300, + libVersionName : '3.3.0' ] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6854969..610f1cd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Sep 23 18:33:41 PDT 2020 +#Wed Jun 23 23:40:19 PDT 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt index 240ab06..9d44b93 100644 --- a/plugin/CMakeLists.txt +++ b/plugin/CMakeLists.txt @@ -1,171 +1,5 @@ cmake_minimum_required(VERSION 3.6) -# Default android abi is arm64-v8a -if (NOT ANDROID_ABI) - set(ANDROID_ABI "arm64-v8a") -endif (NOT ANDROID_ABI) - -# Default android platform is android-24 -if (NOT ANDROID_PLATFORM) - set(ANDROID_PLATFORM "android-24") -endif (NOT ANDROID_PLATFORM) - -# Default build type is Debug -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Debug) -endif (NOT CMAKE_BUILD_TYPE) - -if (CMAKE_BUILD_TYPE MATCHES Debug) - add_definitions(-D_DEBUG) - set(VRAPI_LIB_BUILD_TYPE Debug) -else () - add_definitions(-DNDEBUG) - set(VRAPI_LIB_BUILD_TYPE Release) -endif (CMAKE_BUILD_TYPE MATCHES Debug) - -if (NOT (ANDROID_STL STREQUAL "c++_shared")) - set(ANDROID_STL "c++_shared") -endif (NOT (ANDROID_STL STREQUAL "c++_shared")) - -# Check if ANDROID_NDK is set. -if (NOT ANDROID_NDK) - # Set to ANDROID_NDK_HOME environment variable if it's set. - if (DEFINED ENV{ANDROID_NDK_HOME}) - set(ANDROID_NDK $ENV{ANDROID_NDK_HOME}) - else (DEFINED ENV{ANDROID_NDK_HOME}) - message(WARNING "ANDROID_NDK_HOME is not set") - endif (DEFINED ENV{ANDROID_NDK_HOME}) -endif (NOT ANDROID_NDK) - -# Check if CMAKE_TOOLCHAIN_FILE is set. -if (NOT CMAKE_TOOLCHAIN_FILE) - set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake") -endif (NOT CMAKE_TOOLCHAIN_FILE) - -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -project(godot_ovrmobile VERSION 2.0.0) - -############################################################################### -## PROJECT SETUP -## The variables below should be updated based on the setup instructions -## in the project README. - -# Sets the path to the VrApi containing directory. Update this variable if the api is in another location. -set(OVR_ROOT_DIR "${CMAKE_SOURCE_DIR}/libs/ovr_sdk_mobile") - -# Location to the Godot headers directory. -set(GODOT_CPP_DIR "${CMAKE_SOURCE_DIR}/libs/godot-cpp") -set(GODOT_HEADERS_DIR "${GODOT_CPP_DIR}/godot_headers") -############################################################################### - -set(OVR_HEADERS_DIR "${OVR_ROOT_DIR}/VrApi/Include" CACHE STRING "") - -set(GODOT_COMPILE_FLAGS) -set(GODOT_LINKER_FLAGS) - -set(GODOT_LINKER_FLAGS "-Wl") - -set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wchar-subscripts -Wcomment -Wdisabled-optimization") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wformat -Wformat=2 -Wformat-security -Wformat-y2k") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wimport -Winit-self -Winline -Winvalid-pch") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wlong-long -Wmissing-braces -Wmissing-format-attribute") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpointer-arith") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wredundant-decls -Wreturn-type -Wsequence-point") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wswitch -Wswitch-enum -Wtrigraphs") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused-label") -set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wunused-value -Wvariadic-macros -Wvolatile-register-var -Wno-error=attributes") - -if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android") - set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wno-ignored-attributes") +if (FLAVOR STREQUAL "FULL") + add_subdirectory(${CMAKE_SOURCE_DIR}/src/main/cpp) endif () - -if (CMAKE_BUILD_TYPE MATCHES Debug) - set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0") -else () - set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3") -endif (CMAKE_BUILD_TYPE MATCHES Debug) - -## OVR library -set(VRAPI_LIB_PATH "${OVR_ROOT_DIR}/VrApi/Libs/Android/${ANDROID_ABI}/${VRAPI_LIB_BUILD_TYPE}/libvrapi.so") -add_library(vrapi SHARED IMPORTED GLOBAL) -set_target_properties(vrapi PROPERTIES IMPORTED_LOCATION ${VRAPI_LIB_PATH}) - -## godot-cpp library -set(GODOT-CPP "godot-cpp") - -file(GLOB_RECURSE GODOT_CPP_SOURCES ${GODOT_CPP_DIR}/src/*.c**) -file(GLOB_RECURSE GODOT_CPP_HEADERS ${GODOT_CPP_DIR}/include/*.h**) - -add_library(${GODOT-CPP} - STATIC - ${GODOT_CPP_SOURCES} ${GODOT_CPP_HEADERS}) - -target_include_directories(${GODOT-CPP} - PUBLIC - ${GODOT_CPP_DIR}/include - ${GODOT_CPP_DIR}/include/core - ${GODOT_CPP_DIR}/include/gen - ) - -# Put godot headers as SYSTEM PUBLIC to exclude warnings from irrelevant headers -target_include_directories(${GODOT-CPP} - SYSTEM PUBLIC - ${GODOT_HEADERS_DIR} - ) - -# Add the compile flags -set_property(TARGET ${GODOT-CPP} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS}) -set_property(TARGET ${GODOT-CPP} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS}) - -## Setup the plugin library -# Get Sources -file(GLOB_RECURSE SOURCES src/main/cpp/*.c**) -file(GLOB_RECURSE HEADERS src/main/cpp/*.h**) - -add_library(${PROJECT_NAME} - SHARED - ${SOURCES} ${HEADERS} VRAPI_SO_LIB) - -target_include_directories(${PROJECT_NAME} - PRIVATE - src/main/cpp - ${GODOT_CPP_DIR}/src - ${GODOT_CPP_DIR}/src/core - ${GODOT_CPP_DIR}/src/gen - ${GODOT_CPP_DIR}/include - ${GODOT_CPP_DIR}/include/core - ${GODOT_CPP_DIR}/include/gen - ) - -# Put godot headers as SYSTEM PUBLIC to exclude warnings from irrelevant headers -target_include_directories(${PROJECT_NAME} - SYSTEM PUBLIC - ${GODOT_HEADERS_DIR} - ${OVR_HEADERS_DIR} - ) - -target_link_libraries(${PROJECT_NAME} - android - log - EGL - GLESv3 - vrapi - ${GODOT-CPP}) - -# Add the compile flags -set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS}) -set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS}) - -# Copy the VrApi shared library to the output directory. -add_custom_command(OUTPUT VRAPI_SO_LIB - COMMAND ${CMAKE_COMMAND} -E make_directory $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VRAPI_LIB_PATH} $) - -set(BITS 32) -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(BITS 64) -endif (CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/plugin/build.gradle b/plugin/build.gradle index e9003ce..52a2270 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdkVersion versions.minSdk targetSdkVersion versions.targetSdk - versionCode 8 - versionName '3.1.0' + versionCode versions.libVersionCode + versionName versions.libVersionName setProperty("archivesBaseName", "gdovrmobile.${versionName}") externalNativeBuild { @@ -18,10 +18,6 @@ android { cppFlags "-std=c++14" } } - - ndk { - abiFilters "arm64-v8a", "armeabi-v7a" - } } externalNativeBuild { @@ -31,17 +27,28 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - buildFeatures { - prefabPublishing true + sourceCompatibility versions.javaVersion + targetCompatibility versions.javaVersion } - prefab { - godot_ovrmobile { - headers "src/main/cpp" + flavorDimensions "functionality" + productFlavors { + full { + ndk { + abiFilters "arm64-v8a", "armeabi-v7a" + } + externalNativeBuild { + cmake { + arguments "-DFLAVOR=FULL" + } + } + } + stub { + externalNativeBuild { + cmake { + arguments "-DFLAVOR=STUB" + } + } } } } diff --git a/plugin/gdovrmobile.gdap b/plugin/gdovrmobile.gdap index ae44fbc..159479f 100644 --- a/plugin/gdovrmobile.gdap +++ b/plugin/gdovrmobile.gdap @@ -2,4 +2,4 @@ name="OVRMobile" binary_type="local" -binary="gdovrmobile.3.1.0-release.aar" +binary="gdovrmobile.3.3.0-full-release.aar" diff --git a/plugin/libs/godot-cpp b/plugin/libs/godot-cpp index 9ccbb80..8366761 160000 --- a/plugin/libs/godot-cpp +++ b/plugin/libs/godot-cpp @@ -1 +1 @@ -Subproject commit 9ccbb809ffcc4de6a315ce1fa928c4ecde6501b4 +Subproject commit 836676193031b706a9151f74959de7ae2fc1279b diff --git a/plugin/libs/godot-lib.3.3.stable.release.aar b/plugin/libs/godot-lib.3.4.stable.release.aar similarity index 75% rename from plugin/libs/godot-lib.3.3.stable.release.aar rename to plugin/libs/godot-lib.3.4.stable.release.aar index c82957e..d377024 100644 Binary files a/plugin/libs/godot-lib.3.3.stable.release.aar and b/plugin/libs/godot-lib.3.4.stable.release.aar differ diff --git a/plugin/src/main/AndroidManifest.xml b/plugin/src/main/AndroidManifest.xml index 64f95b7..dfe1d23 100644 --- a/plugin/src/main/AndroidManifest.xml +++ b/plugin/src/main/AndroidManifest.xml @@ -1,7 +1,12 @@ + package="org.godotengine.plugin.vr.oculus.mobile" + android:versionCode="30300" + android:versionName="3.3.0"> + + + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VRAPI_LIB_PATH} $) + +set(BITS 32) +if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(BITS 64) +endif (CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/plugin/src/main/cpp/api/ovr_input.cpp b/plugin/src/main/cpp/api/ovr_input.cpp index 5f11089..89d5a7c 100644 --- a/plugin/src/main/cpp/api/ovr_input.cpp +++ b/plugin/src/main/cpp/api/ovr_input.cpp @@ -12,6 +12,7 @@ void OvrInput::_init() {} void OvrInput::_register_methods() { register_method("get_primary_controller_id", &OvrInput::get_primary_controller_id); register_method("get_primary_controller_type", &OvrInput::get_primary_controller_type); + register_method("get_controller_type", &OvrInput::get_controller_type); } bool vibrate_controller(OvrMobileSession *session, @@ -43,6 +44,21 @@ int get_primary_controller_id(OvrMobileSession *session) { []() { return kInvalidGodotControllerId; }); } +int get_controller_id(OvrMobileSession *session, + OvrMobileController::ControllerHand controller_hand) { + return check_session_initialized( + session, + [&]() { + int controller_id = kInvalidGodotControllerId; + OvrMobileController *controller = session->get_ovr_mobile_controller(); + if (controller) { + controller_id = controller->get_controller_id(controller_hand); + } + return controller_id; + }, + []() { return kInvalidGodotControllerId; }); +} + ovrControllerType get_primary_controller_type(OvrMobileSession *session) { return check_session_initialized(session, [&]() { OvrMobileController *controller = session->get_ovr_mobile_controller(); @@ -56,4 +72,18 @@ ovrControllerType get_primary_controller_type(OvrMobileSession *session) { return ovrControllerType::ovrControllerType_None; }); } + +ovrControllerType get_controller_type(OvrMobileSession *session, int controller_id) { + return check_session_initialized(session, [&]() { + OvrMobileController *controller = session->get_ovr_mobile_controller(); + if (controller) { + const OvrMobileController::ControllerState *controller_state = + controller->get_controller_state_by_id(controller_id); + if (controller_state) { + return controller_state->capability_header.Type; + } + } + return ovrControllerType::ovrControllerType_None; + }); +} } // namespace ovrmobile diff --git a/plugin/src/main/cpp/api/ovr_input.h b/plugin/src/main/cpp/api/ovr_input.h index b9f6de0..19e4450 100644 --- a/plugin/src/main/cpp/api/ovr_input.h +++ b/plugin/src/main/cpp/api/ovr_input.h @@ -18,9 +18,16 @@ bool vibrate_controller(OvrMobileSession *session, /// Return the id for the primary controller. int get_primary_controller_id(OvrMobileSession *session); +/// Return the id for the controller corresponding to the given hand. +int get_controller_id(OvrMobileSession *session, + OvrMobileController::ControllerHand controller_hand); + /// Return the type for the primary controller. ovrControllerType get_primary_controller_type(OvrMobileSession *session); +/// Return the type for the controller corresponding to the given id. +ovrControllerType get_controller_type(OvrMobileSession *session, int controller_id); + class OvrInput : public Reference { GODOT_CLASS(OvrInput, Reference) @@ -40,6 +47,11 @@ class OvrInput : public Reference { inline int get_primary_controller_type() { return ovrmobile::get_primary_controller_type(OvrMobileSession::get_singleton_instance()); } + + inline int get_controller_type(int controller_id) { + return ovrmobile::get_controller_type(OvrMobileSession::get_singleton_instance(), + controller_id); + } }; } // namespace ovrmobile diff --git a/plugin/src/main/cpp/gdnative/arvr_interface.h b/plugin/src/main/cpp/gdnative/arvr_interface.h index b923944..81fc507 100644 --- a/plugin/src/main/cpp/gdnative/arvr_interface.h +++ b/plugin/src/main/cpp/gdnative/arvr_interface.h @@ -54,8 +54,7 @@ void godot_arvr_process(void *p_data); void godot_arvr_notification(void *p_data, godot_int p_what); const godot_arvr_interface_gdnative interface_struct = { - { GODOTVR_API_MAJOR, - GODOTVR_API_MINOR }, + { 1,1 }, godot_arvr_constructor, godot_arvr_destructor, godot_arvr_get_name, diff --git a/plugin/src/main/cpp/jni/ovr_input_jni.cpp b/plugin/src/main/cpp/jni/ovr_input_jni.cpp index 6a07975..f0e625d 100644 --- a/plugin/src/main/cpp/jni/ovr_input_jni.cpp +++ b/plugin/src/main/cpp/jni/ovr_input_jni.cpp @@ -4,6 +4,7 @@ #include "api/ovr_input.h" #include "jni_common.h" +#include "ovr_mobile_controller.h" #include #undef JNI_PACKAGE_NAME @@ -14,20 +15,40 @@ extern "C" { -JNIEXPORT void JNICALL JNI_METHOD(vibrateController)(JNIEnv *, +JNIEXPORT void JNICALL JNI_METHOD(nativeVibrateController)(JNIEnv *, jclass, - jobject, jint controller_id, jint duration_in_ms, jfloat intensity) { ovrmobile::vibrate_controller(get_session(), controller_id, duration_in_ms, intensity); } -JNIEXPORT jint JNICALL JNI_METHOD(getPrimaryControllerId)(JNIEnv *, jclass, jobject) { +JNIEXPORT void JNICALL JNI_METHOD(nativeVibrateControllerByHand)(JNIEnv *, + jclass, + jint controller_hand, + jint duration_in_ms, + jfloat intensity) { + int controller_id = ovrmobile::get_controller_id( + get_session(), + static_cast(controller_hand)); + ovrmobile::vibrate_controller(get_session(), controller_id, duration_in_ms, intensity); +} + +JNIEXPORT jint JNICALL JNI_METHOD(nativeGetPrimaryControllerId)(JNIEnv *, jclass) { return ovrmobile::get_primary_controller_id(get_session()); } JNIEXPORT jint JNICALL JNI_METHOD(nativeGetPrimaryControllerType)(JNIEnv *, jclass) { return ovrmobile::get_primary_controller_type(get_session()); } + +JNIEXPORT jint JNICALL JNI_METHOD(nativeGetControllerId)(JNIEnv *, jclass, jint controller_hand) { + return ovrmobile::get_controller_id( + get_session(), + static_cast(controller_hand)); +} + +JNIEXPORT jint JNICALL JNI_METHOD(nativeGetControllerType)(JNIEnv *, jclass, jint controller_id) { + return ovrmobile::get_controller_type(get_session(), controller_id); +} }; diff --git a/plugin/src/main/cpp/jni/ovr_performance_jni.cpp b/plugin/src/main/cpp/jni/ovr_performance_jni.cpp index cec9beb..c97deb9 100644 --- a/plugin/src/main/cpp/jni/ovr_performance_jni.cpp +++ b/plugin/src/main/cpp/jni/ovr_performance_jni.cpp @@ -39,9 +39,8 @@ JNIEXPORT jboolean JNICALL JNI_METHOD(nativeSetSwapInterval)(JNIEnv *env, return static_cast(ovrmobile::set_swap_interval(get_session(), swap_interval)); } -JNIEXPORT jboolean JNICALL JNI_METHOD(enableDynamicFoveation)(JNIEnv *, +JNIEXPORT jboolean JNICALL JNI_METHOD(nativeEnableDynamicFoveation)(JNIEnv *, jclass, - jobject, jboolean enable) { return static_cast(ovrmobile::set_enable_dynamic_foveation(get_session(), enable)); } diff --git a/plugin/src/main/cpp/ovr_mobile_controller.h b/plugin/src/main/cpp/ovr_mobile_controller.h index 63ebb6a..af9cb57 100644 --- a/plugin/src/main/cpp/ovr_mobile_controller.h +++ b/plugin/src/main/cpp/ovr_mobile_controller.h @@ -41,6 +41,8 @@ class OvrMobileController { ovrHandPose hand_pose; }; + enum ControllerHand { LEFT_HAND, RIGHT_HAND, MAX_HANDS }; + OvrMobileController(); ~OvrMobileController(); @@ -89,6 +91,16 @@ class OvrMobileController { return kInvalidGodotControllerId; } + int get_controller_id(ControllerHand hand) { + if (LEFT_HAND <= hand && hand < MAX_HANDS) { + auto *controller = &controllers[hand]; + if (controller->connected) { + return controller->godot_controller_id; + } + } + return kInvalidGodotControllerId; + } + private: struct ControllerVibration { float intensity; @@ -96,8 +108,6 @@ class OvrMobileController { bool is_vibrating; }; - enum ControllerHand { LEFT_HAND, RIGHT_HAND, MAX_HANDS }; - ControllerState controllers[MAX_HANDS]; std::map controllers_vibrations; diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/OvrMobilePlugin.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/OvrMobilePlugin.kt index e8beaa8..f895128 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/OvrMobilePlugin.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/OvrMobilePlugin.kt @@ -2,6 +2,7 @@ package org.godotengine.plugin.vr.oculus.mobile +import android.util.Log import org.godotengine.godot.Godot import org.godotengine.godot.plugin.GodotPlugin import org.godotengine.godot.plugin.SignalInfo @@ -55,8 +56,18 @@ class OvrMobilePlugin(godot: Godot) : GodotPlugin(godot) { } companion object { + + private val TAG = OvrMobilePlugin::class.java.simpleName + private var loadedSharedLib = false + init { - System.loadLibrary("godot_ovrmobile") + try { + System.loadLibrary("godot_ovrmobile") + loadedSharedLib = true + } catch (e: UnsatisfiedLinkError) { + Log.e(TAG, "Unable to load the godot_ovrmobile shared library") + loadedSharedLib = false + } } // Set of plugin signals @@ -86,15 +97,21 @@ class OvrMobilePlugin(godot: Godot) : GodotPlugin(godot) { POSE_RECENTERED_SIGNAL, ) + internal fun isSharedLibLoaded() = loadedSharedLib + override fun onGLSurfaceCreated(gl: GL10, config: EGLConfig) { super.onGLSurfaceCreated(gl, config) - initializeWrapper() + if (loadedSharedLib) { + initializeWrapper() + } } override fun onMainDestroy() { super.onMainDestroy() - runOnRenderThread { - uninitializeWrapper() + if (loadedSharedLib) { + runOnRenderThread { + uninitializeWrapper() + } } } diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrDisplay.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrDisplay.kt index d5e65f3..53a5812 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrDisplay.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrDisplay.kt @@ -50,7 +50,13 @@ enum class ColorSpace(internal val value: Int) { * This is a constant for each device type. * @see https://developer.oculus.com/documentation/native/android/mobile-colorspace/ */ -fun OvrMobilePlugin.getColorSpace() = ColorSpace.toColorSpace(nativeGetColorSpace()) +fun OvrMobilePlugin.getColorSpace(): ColorSpace { + return if (isSharedLibLoaded()) { + ColorSpace.toColorSpace(nativeGetColorSpace()) + } else { + ColorSpace.COLOR_SPACE_UNMANAGED + } +} /** * Used to update the device color space. @@ -58,12 +64,24 @@ fun OvrMobilePlugin.getColorSpace() = ColorSpace.toColorSpace(nativeGetColorSpac * @param[colorSpace] The new target color space. * @return True if the device's color space was updated, false otherwise. */ -fun OvrMobilePlugin.setColorSpace(colorSpace: ColorSpace) = nativeSetColorSpace(colorSpace.value) +fun OvrMobilePlugin.setColorSpace(colorSpace: ColorSpace): Boolean { + return if (isSharedLibLoaded()) { + nativeSetColorSpace(colorSpace.value) + } else { + false + } +} /** * Used to access the display refresh rates supported by the device. */ -fun OvrMobilePlugin.getSupportedDisplayRefreshRates() = nativeGetSupportedDisplayRefreshRates() +fun OvrMobilePlugin.getSupportedDisplayRefreshRates(): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetSupportedDisplayRefreshRates() + } else { + floatArrayOf() + } +} /** * Used to update the device display refresh rate. @@ -71,7 +89,13 @@ fun OvrMobilePlugin.getSupportedDisplayRefreshRates() = nativeGetSupportedDispla * @param[refreshRate] Target refresh rate. Must be one of the supported values returned by * [getSupportedDisplayRefreshRates]. */ -fun OvrMobilePlugin.setDisplayRefreshRate(refreshRate: Float) = nativeSetDisplayRefreshRate(refreshRate) +fun OvrMobilePlugin.setDisplayRefreshRate(refreshRate: Float): Boolean { + return if (isSharedLibLoaded()) { + nativeSetDisplayRefreshRate(refreshRate) + } else { + false + } +} private external fun nativeSetColorSpace(colorSpace: Int): Boolean diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrGuardianSystem.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrGuardianSystem.kt index 0d6a552..fd617e8 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrGuardianSystem.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrGuardianSystem.kt @@ -4,10 +4,22 @@ package org.godotengine.plugin.vr.oculus.mobile.api import org.godotengine.plugin.vr.oculus.mobile.OvrMobilePlugin -fun OvrMobilePlugin.isBoundaryVisible() = nativeIsBoundaryVisible() +fun OvrMobilePlugin.isBoundaryVisible(): Boolean { + return if (isSharedLibLoaded()) { + nativeIsBoundaryVisible() + } else { + false + } +} -fun OvrMobilePlugin.requestBoundaryVisible(visible: Boolean) = nativeRequestBoundaryVisible(visible) +fun OvrMobilePlugin.requestBoundaryVisible(visible: Boolean): Boolean { + return if (isSharedLibLoaded()) { + nativeRequestBoundaryVisible(visible) + } else { + false + } +} private external fun nativeIsBoundaryVisible(): Boolean -private external fun nativeRequestBoundaryVisible(visible: Boolean): Boolean \ No newline at end of file +private external fun nativeRequestBoundaryVisible(visible: Boolean): Boolean diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInitConfig.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInitConfig.kt index fbe715b..9c84ef2 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInitConfig.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInitConfig.kt @@ -12,7 +12,12 @@ import org.godotengine.plugin.vr.oculus.mobile.OvrMobilePlugin /** * Set the factor by which to multiply the recommended render target size for the app. */ -fun OvrMobilePlugin.setRenderTargetSizeMultiplier(multiplier: Double) = - nativeSetRenderTargetSizeMultiplier(multiplier) +fun OvrMobilePlugin.setRenderTargetSizeMultiplier(multiplier: Double): Boolean { + return if (isSharedLibLoaded()) { + nativeSetRenderTargetSizeMultiplier(multiplier) + } else { + false + } +} -private external fun nativeSetRenderTargetSizeMultiplier(multiplier: Double): Boolean \ No newline at end of file +private external fun nativeSetRenderTargetSizeMultiplier(multiplier: Double): Boolean diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInput.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInput.kt index 2c40c11..1b0cec6 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInput.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrInput.kt @@ -10,7 +10,7 @@ import org.godotengine.plugin.vr.oculus.mobile.OvrMobilePlugin private const val PRIMARY_CONTROLLER_ID = -1 /** - * Specifies which controller is connected + * Specifies which controller type is connected */ enum class ControllerType(internal val value: Int) { CONTROLLER_TYPE_NONE(0), @@ -45,25 +45,99 @@ enum class ControllerType(internal val value: Int) { } } +/** + * Specifies which hands the controller supports. + */ +enum class ControllerHand(internal val value: Int) { + LEFT(0), + RIGHT(1) +} + /** * Vibrate the controller at the given intensity. + * This should be invoked on the gl thread. * @param controllerId Id of the controller to vibrate. Defaults to the primary controller id. * @param durationInMs Vibration duration in milliseconds * @param intensity Vibration intensity */ @JvmOverloads -external fun OvrMobilePlugin.vibrateController(controllerId: Int = PRIMARY_CONTROLLER_ID, durationInMs: Int, intensity: Float) +fun OvrMobilePlugin.vibrateController(controllerId: Int = PRIMARY_CONTROLLER_ID, durationInMs: Int, intensity: Float) { + if (isSharedLibLoaded()) { + nativeVibrateController(controllerId, durationInMs, intensity) + } +} + +/** + * Vibrate the controller for the given hand at the given intensity. + * This should be invoked on the gl thread. + * @param hand Hand for which the controller should be vibrated. + * @param durationInMs Vibration duration in milliseconds + * @param intensity Vibration intensity + */ +fun OvrMobilePlugin.vibrateController(hand: ControllerHand, durationInMs: Int, intensity: Float) { + if (isSharedLibLoaded()) { + nativeVibrateControllerByHand(hand.value, durationInMs, intensity) + } +} /** * Return the id for the primary controller. + * This should be invoked on the gl thread. * Returns -1 if there is no primary controller. */ -external fun OvrMobilePlugin.getPrimaryControllerId(): Int +fun OvrMobilePlugin.getPrimaryControllerId(): Int { + return if (isSharedLibLoaded()) { + nativeGetPrimaryControllerId() + } else { + PRIMARY_CONTROLLER_ID + } +} + +/** + * Return the id of the controller for the given hand. + * This should be invoked on the gl thread. + * Returns -1 if the controller for that hand is not connected. + */ +fun OvrMobilePlugin.getControllerId(hand: ControllerHand): Int { + return if (isSharedLibLoaded()) { + nativeGetControllerId(hand.value) + } else { + PRIMARY_CONTROLLER_ID + } +} /** * Return the [ControllerType] type of the primary controller. + * This should be invoked on the gl thread. */ -fun OvrMobilePlugin.getPrimaryControllerType() = +fun OvrMobilePlugin.getPrimaryControllerType(): ControllerType { + return if (isSharedLibLoaded()) { ControllerType.toControllerType(nativeGetPrimaryControllerType()) + } else { + ControllerType.CONTROLLER_TYPE_NONE + } +} + +/** + * Return the [ControllerType] type of the controller with the given id. + * This should be invoked on the gl thread. + */ +fun OvrMobilePlugin.getControllerType(controllerId: Int): ControllerType { + return if (isSharedLibLoaded()) { + ControllerType.toControllerType(nativeGetControllerType(controllerId)) + } else { + ControllerType.CONTROLLER_TYPE_NONE + } +} + +private external fun nativeVibrateController(controllerId: Int, durationInMs: Int, intensity: Float) + +private external fun nativeGetPrimaryControllerId(): Int private external fun nativeGetPrimaryControllerType(): Int + +private external fun nativeVibrateControllerByHand(hand: Int, durationInMs: Int, intensity: Float) + +private external fun nativeGetControllerId(hand: Int): Int + +private external fun nativeGetControllerType(controllerId: Int): Int diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrPerformance.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrPerformance.kt index 518de8c..094a5f9 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrPerformance.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrPerformance.kt @@ -35,15 +35,25 @@ enum class FoveationLevel(internal val value: Int) { * Levels will be clamped to the expected range. * Default clock levels are cpuLevel = 2, gpuLevel = 2. */ -fun OvrMobilePlugin.setClockLevels(cpuLevel: Int, gpuLevel: Int) = +fun OvrMobilePlugin.setClockLevels(cpuLevel: Int, gpuLevel: Int): Boolean { + return if (isSharedLibLoaded()) { nativeSetClockLevels(cpuLevel, gpuLevel) + } else { + false + } +} /** * If [ExtraLatencyMode.ON] specified, adds an extra frame of latency for full GPU * utilization. Default is [ExtraLatencyMode.OFF]. */ -fun OvrMobilePlugin.setExtraLatencyMode(latencyMode: ExtraLatencyMode) = +fun OvrMobilePlugin.setExtraLatencyMode(latencyMode: ExtraLatencyMode): Boolean { + return if (isSharedLibLoaded()) { nativeSetExtraLatencyMode(latencyMode.value) + } else { + false + } +} /** * Set the fixed foveated rendering level if it's available. @@ -53,22 +63,41 @@ fun OvrMobilePlugin.setExtraLatencyMode(latencyMode: ExtraLatencyMode) = * * [Additional docs](https://developer.oculus.com/documentation/quest/latest/concepts/mobile-ffr/) */ -fun OvrMobilePlugin.setFoveationLevel(foveationLevel: FoveationLevel) = +fun OvrMobilePlugin.setFoveationLevel(foveationLevel: FoveationLevel): Boolean { + return if (isSharedLibLoaded()) { nativeSetFoveationLevel(foveationLevel.value) + } else { + false + } +} /** * Sets the swap interval to control the application frame timing. * * [Additional docs](https://developer.oculus.com/documentation/mobilesdk/latest/concepts/mobile-vrapi#frame-timing) */ -fun OvrMobilePlugin.setSwapInterval(swapInterval: Int) = nativeSetSwapInterval(swapInterval) +fun OvrMobilePlugin.setSwapInterval(swapInterval: Int): Boolean { + return if (isSharedLibLoaded()) { + nativeSetSwapInterval(swapInterval) + } else { + false + } +} /** * Enable dynamic foveation. * * [Additional docs](https://developer.oculus.com/documentation/native/android/mobile-ffr/) */ -external fun OvrMobilePlugin.enableDynamicFoveation(enable: Boolean): Boolean +fun OvrMobilePlugin.enableDynamicFoveation(enable: Boolean): Boolean { + return if (isSharedLibLoaded()) { + nativeEnableDynamicFoveation(enable) + } else { + false + } +} + +private external fun nativeEnableDynamicFoveation(enable: Boolean): Boolean private external fun nativeSetClockLevels(cpuLevel: Int, gpuLevel: Int): Boolean diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrSystem.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrSystem.kt index f2b30c0..27390b4 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrSystem.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrSystem.kt @@ -38,12 +38,24 @@ enum class DeviceType(internal val rangeStart: Int, internal val rangeEnd: Int = /** * Return the current [DeviceType] type. */ -fun OvrMobilePlugin.getDeviceType() = DeviceType.toDeviceType(nativeGetDeviceType()) +fun OvrMobilePlugin.getDeviceType(): DeviceType { + return if (isSharedLibLoaded()) { + DeviceType.toDeviceType(nativeGetDeviceType()) + } else { + DeviceType.UNKNOWN + } +} /** * Return the current driver version. */ -fun OvrMobilePlugin.getDriverVersion() = nativeGetDriverVersion() +fun OvrMobilePlugin.getDriverVersion(): String { + return if (isSharedLibLoaded()) { + nativeGetDriverVersion() + } else { + "" + } +} private external fun nativeGetDeviceType(): Int diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrTrackingTransform.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrTrackingTransform.kt index 6070749..61d4368 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrTrackingTransform.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrTrackingTransform.kt @@ -43,17 +43,28 @@ enum class TrackingSpace(internal val value: Int) { LOCAL_FIXED_YAW(7) } -fun OvrMobilePlugin.getTrackingSpace() = when (nativeGetTrackingSpace()) { - TrackingSpace.LOCAL.value -> TrackingSpace.LOCAL - TrackingSpace.LOCAL_FLOOR.value -> TrackingSpace.LOCAL_FLOOR - TrackingSpace.LOCAL_TILTED.value -> TrackingSpace.LOCAL_TILTED - TrackingSpace.STAGE.value -> TrackingSpace.STAGE - TrackingSpace.LOCAL_FIXED_YAW.value -> TrackingSpace.LOCAL_FIXED_YAW - else -> TrackingSpace.UNKNOWN +fun OvrMobilePlugin.getTrackingSpace(): TrackingSpace { + return if (isSharedLibLoaded()) { + when (nativeGetTrackingSpace()) { + TrackingSpace.LOCAL.value -> TrackingSpace.LOCAL + TrackingSpace.LOCAL_FLOOR.value -> TrackingSpace.LOCAL_FLOOR + TrackingSpace.LOCAL_TILTED.value -> TrackingSpace.LOCAL_TILTED + TrackingSpace.STAGE.value -> TrackingSpace.STAGE + TrackingSpace.LOCAL_FIXED_YAW.value -> TrackingSpace.LOCAL_FIXED_YAW + else -> TrackingSpace.UNKNOWN + } + } else { + TrackingSpace.UNKNOWN + } } -fun OvrMobilePlugin.setTrackingSpace(trackingSpace: TrackingSpace) = - nativeSetTrackingSpace(trackingSpace.value) +fun OvrMobilePlugin.setTrackingSpace(trackingSpace: TrackingSpace): Boolean { + return if (isSharedLibLoaded()) { + nativeSetTrackingSpace(trackingSpace.value) + } else { + false + } +} private external fun nativeGetTrackingSpace(): Int diff --git a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrUtilities.kt b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrUtilities.kt index b3916da..caa3af7 100644 --- a/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrUtilities.kt +++ b/plugin/src/main/java/org/godotengine/plugin/vr/oculus/mobile/api/OvrUtilities.kt @@ -18,60 +18,130 @@ enum class OvrEye(internal val eyeIndex: Int) { /** * Uses the internal left and right view matrix to compute the IPD. */ -fun OvrMobilePlugin.getIpd() = - nativeGetIpd() +fun OvrMobilePlugin.getIpd(): Float { + return if (isSharedLibLoaded()) { + nativeGetIpd() + } else { + 0F + } +} -fun OvrMobilePlugin.getRenderTargetWidth() = nativeGetRenderTargetWidth() +fun OvrMobilePlugin.getRenderTargetWidth(): Int { + return if (isSharedLibLoaded()) { + nativeGetRenderTargetWidth() + } else { + 1024 + } +} -fun OvrMobilePlugin.getRenderTargetHeight() = nativeGetRenderTargetHeight() +fun OvrMobilePlugin.getRenderTargetHeight(): Int { + return if (isSharedLibLoaded()) { + nativeGetRenderTargetHeight() + } else { + 1024 + } +} /** * Returns the fov for the given [OvrEye] in degrees. */ fun OvrMobilePlugin.getEyeFov(eye: OvrEye): RectF { - val fovArray = nativeGetEyeFov(eye.eyeIndex) - return RectF(fovArray[0], fovArray[3], fovArray[1], fovArray[2]) + if (isSharedLibLoaded()) { + val fovArray = nativeGetEyeFov(eye.eyeIndex) + return RectF(fovArray[0], fovArray[3], fovArray[1], fovArray[2]) + } else { + return RectF() + } } /** * Return the viewport bounds for the given [OvrEye]. */ fun OvrMobilePlugin.getEyeViewportBounds(eye: OvrEye): RectF { - val boundsArray = nativeGetEyeViewportBounds(eye.eyeIndex) - return RectF(boundsArray[0], boundsArray[3], boundsArray[2], boundsArray[1]) + if (isSharedLibLoaded()) { + val boundsArray = nativeGetEyeViewportBounds(eye.eyeIndex) + return RectF(boundsArray[0], boundsArray[3], boundsArray[2], boundsArray[1]) + } else { + return RectF() + } } -fun OvrMobilePlugin.setDefaultLayerColorScale(color: Int) = - nativeSetDefaultLayerColorScale( - Color.red(color).toFloat(), - Color.green(color).toFloat(), - Color.blue(color).toFloat(), - Color.alpha(color).toFloat() - ) +fun OvrMobilePlugin.setDefaultLayerColorScale(color: Int): Boolean { + return if (isSharedLibLoaded()) { + nativeSetDefaultLayerColorScale( + Color.red(color).toFloat(), + Color.green(color).toFloat(), + Color.blue(color).toFloat(), + Color.alpha(color).toFloat() + ) + } else { + false + } +} -fun OvrMobilePlugin.getControllerAngularVelocity(controllerId: Int) = - nativeGetControllerAngularVelocity(controllerId) +fun OvrMobilePlugin.getControllerAngularVelocity(controllerId: Int): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetControllerAngularVelocity(controllerId) + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getControllerLinearVelocity(controllerId: Int) = - nativeGetControllerLinearVelocity(controllerId) +fun OvrMobilePlugin.getControllerLinearVelocity(controllerId: Int): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetControllerLinearVelocity(controllerId) + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getControllerAngularAcceleration(controllerId: Int) = - nativeGetControllerAngularAcceleration(controllerId) +fun OvrMobilePlugin.getControllerAngularAcceleration(controllerId: Int): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetControllerAngularAcceleration(controllerId) + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getControllerLinearAcceleration(controllerId: Int) = - nativeGetControllerLinearAcceleration(controllerId) +fun OvrMobilePlugin.getControllerLinearAcceleration(controllerId: Int): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetControllerLinearAcceleration(controllerId) + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getHeadAngularVelocity() = - nativeGetHeadAngularVelocity() +fun OvrMobilePlugin.getHeadAngularVelocity(): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetHeadAngularVelocity() + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getHeadLinearVelocity() = - nativeGetHeadLinearVelocity() +fun OvrMobilePlugin.getHeadLinearVelocity(): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetHeadLinearVelocity() + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getHeadAngularAcceleration() = - nativeGetHeadAngularAcceleration() +fun OvrMobilePlugin.getHeadAngularAcceleration(): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetHeadAngularAcceleration() + } else { + floatArrayOf() + } +} -fun OvrMobilePlugin.getHeadLinearAcceleration() = - nativeGetHeadLinearAcceleration() +fun OvrMobilePlugin.getHeadLinearAcceleration(): FloatArray { + return if (isSharedLibLoaded()) { + nativeGetHeadLinearAcceleration() + } else { + floatArrayOf() + } +} private external fun nativeGetIpd(): Float diff --git a/samples/demo/build.gradle b/samples/demo/build.gradle index 1e0bc46..b0f5b56 100644 --- a/samples/demo/build.gradle +++ b/samples/demo/build.gradle @@ -29,12 +29,29 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility versions.javaVersion + targetCompatibility versions.javaVersion } kotlinOptions { jvmTarget = '1.8' } + + flavorDimensions "xrMode" + productFlavors { + ovr { + applicationIdSuffix ".ovr" + versionNameSuffix "-ovr" + ndk { + abiFilters "arm64-v8a", "armeabi-v7a" + } + missingDimensionStrategy 'functionality', 'full' + } + pancake { + applicationIdSuffix ".pancake" + versionNameSuffix "-pancake" + missingDimensionStrategy 'functionality', 'stub' + } + } } dependencies { @@ -42,5 +59,5 @@ dependencies { implementation project(":OVRMobile") implementation(fileTree(dir: "../../plugin/libs", include: ["godot-lib*.aar"])) implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlinVersion}" - implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.appcompat:appcompat:1.3.1' } diff --git a/samples/demo/src/main/java/org/godotengine/plugin/vr/oculus/mobile/demo/MainActivity.kt b/samples/demo/src/main/java/org/godotengine/plugin/vr/oculus/mobile/demo/MainActivity.kt index 89e94ef..f49a374 100644 --- a/samples/demo/src/main/java/org/godotengine/plugin/vr/oculus/mobile/demo/MainActivity.kt +++ b/samples/demo/src/main/java/org/godotengine/plugin/vr/oculus/mobile/demo/MainActivity.kt @@ -1,5 +1,6 @@ package org.godotengine.plugin.vr.oculus.mobile.demo +import java.util.Collections import org.godotengine.godot.FullScreenGodotApp import org.godotengine.godot.xr.XRMode @@ -7,6 +8,10 @@ class MainActivity : FullScreenGodotApp() { // Override the engine starting parameters to indicate we want VR mode. override fun getCommandLine(): List { - return listOf(XRMode.OVR.cmdLineArg) + return if (BuildConfig.FLAVOR == "ovr") { + listOf(XRMode.OVR.cmdLineArg) + } else { + Collections.emptyList() + } } }