Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Add input related apis #96

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ buildscript {

}
dependencies {
classpath("com.android.tools.build:gradle:3.6.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.70")
classpath("com.android.tools.build:gradle:3.5.3")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlinVersion}")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repositories {
google()
jcenter()
}

plugins {
`kotlin-dsl`
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Versions {
val kotlinVersion = "1.3.71"
val compileSdk = 29
val buildTools = "29.0.1"
val minSdk = 18
val targetSdk = 29

}
10 changes: 5 additions & 5 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
}

android {
compileSdkVersion(29)
buildToolsVersion = "29.0.1"
compileSdkVersion(Versions.compileSdk)
buildToolsVersion = Versions.buildTools
defaultConfig {
minSdkVersion(18)
targetSdkVersion(29)
minSdkVersion(Versions.minSdk)
targetSdkVersion(Versions.targetSdk)
versionName = "1.0"
versionCode = 1
externalNativeBuild {
Expand All @@ -32,7 +32,7 @@ android {
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.70")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlinVersion}")
if (rootProject.findProject(":godot:lib") != null) {
compileOnly(project(":godot:lib"))
} else {
Expand Down
Binary file modified plugin/libs/godot-lib.3.2.2.alpha.release.aar
Binary file not shown.
8 changes: 8 additions & 0 deletions plugin/src/main/assets/addons/godot_ovrmobile/OvrInput.gdns
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="NativeScript" load_steps=2 format=2]

[ext_resource path="res://addons/godot_ovrmobile/godot_ovrmobile.gdnlib" type="GDNativeLibrary" id=1]

[resource]
resource_name = "OvrInput"
class_name = "OvrInput"
library = ExtResource( 1 )
4 changes: 3 additions & 1 deletion plugin/src/main/cpp/api/ovr_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "ovr_mobile_session.h"

namespace ovrmobile {
bool vibrate_controller(OvrMobileSession *session, int controller_id, float intensity);
// Vibrate the controller matching the given controller ID.
// Returns true if the controller was vibrated, false otherwise.
bool vibrate_controller(OvrMobileSession *session, int controller_id, float intensity);
} // namespace ovrmobile

#endif // OVR_INPUT_H
42 changes: 42 additions & 0 deletions plugin/src/main/cpp/gdnative/nativescript/ovr_input_ns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "ovr_input_ns.h"
#include "api/ovr_input.h"
#include "nativescript_common.h"

static const char *kClassName = "OvrInput";

void register_gdnative_input(void *handle) {
// register the constructor and destructor of the OvrInput class for use in GDScript
godot_instance_create_func create = { NULL, NULL, NULL };
create.create_func = &ovr_input_constructor;

godot_instance_destroy_func destroy = { NULL, NULL, NULL };
destroy.destroy_func = &ovr_input_destructor;

nativescript_api->godot_nativescript_register_class(handle, kClassName, "Reference", create, destroy);

// register all the functions that we want to expose via the OvrInput class in GDScript
godot_instance_method method = { NULL, NULL, NULL };
godot_method_attributes attributes = { GODOT_METHOD_RPC_MODE_DISABLED };

method.method = &vibrate_controller;
nativescript_api->godot_nativescript_register_method(handle, kClassName, "vibrate_controller", attributes, method);
}

GDCALLINGCONV void *ovr_input_constructor(godot_object *instance, void *method_data) {
return init_ovr_config_data_struct();
}

GDCALLINGCONV void ovr_input_destructor(godot_object *instance, void *method_data, void *user_data) {
if (user_data) {
reset_ovr_config_data_struct(static_cast<ovr_config_data_struct *>(user_data));
}
}

GDCALLINGCONV godot_variant vibrate_controller(godot_object *instance, void *method_data, void *p_user_data, int num_args, godot_variant **args) {
CHECK_USER_DATA(
const int controller_id = api->godot_variant_as_int(args[0]);
const double intensity = api->godot_variant_as_real(args[1]);
api->godot_variant_new_bool(&ret, ovrmobile::vibrate_controller(ovr_mobile_session, controller_id, intensity));

)
}
22 changes: 22 additions & 0 deletions plugin/src/main/cpp/gdnative/nativescript/ovr_input_ns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef OVR_INPUT_NS_H
#define OVR_INPUT_NS_H

#include "gdnative/godot_calls.h"

#ifdef __cplusplus
extern "C" {
#endif

// Registers the OvrInput class and functions to GDNative and should be called from godot_ovrmobile_nativescript_init
void register_gdnative_input(void *handle);

GDCALLINGCONV void *ovr_input_constructor(godot_object *instance, void *method_data);
GDCALLINGCONV void ovr_input_destructor(godot_object *instance, void *method_data, void *user_data);

GDCALLINGCONV godot_variant vibrate_controller(godot_object *instance, void *method_data, void *p_user_data, int num_args, godot_variant **args);

#ifdef __cplusplus
};
#endif

#endif // OVR_INPUT_NS_H
23 changes: 23 additions & 0 deletions plugin/src/main/cpp/jni/ovr_input_jni.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Created by Fredia Huya-Kouadio.
*/

#include <jni.h>
#include "api/ovr_input.h"
#include "jni_common.h"

#undef JNI_PACKAGE_NAME
#define JNI_PACKAGE_NAME org_godotengine_plugin_vr_oculus_mobile_api

#undef JNI_CLASS_NAME
#define JNI_CLASS_NAME OvrInput

extern "C" {

JNIEXPORT void JNICALL
JNI_METHOD(nativeVibrateController)(JNIEnv *env, jclass clazz, jint controller_id,
jfloat intensity) {
ovrmobile::vibrate_controller(get_session(), controller_id, intensity);
}

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Vrapi input functions
*/
@file:JvmName("OvrInput")

package org.godotengine.plugin.vr.oculus.mobile.api

import org.godotengine.plugin.vr.oculus.mobile.OvrMobilePlugin

/**
* Vibrate the controller at the given intensity.
* @param controllerId Id of the controller to vibrate
* @param intensity Vibration intensity
*/
fun OvrMobilePlugin.vibrateController(controllerId: Int, intensity: Float) = nativeVibrateController(controllerId, intensity)

private external fun nativeVibrateController(controllerId: Int, intensity: Float)