JNI side finished

This commit is contained in:
Grant Bagwell 2021-05-03 21:58:50 +02:00
parent 0a97fa4b4f
commit 44abd7b7a1
9 changed files with 186 additions and 63 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drbeef.rtcwquest"
android:versionCode="47"
android:versionName="1.1.9" android:installLocation="auto" >
android:versionCode="48"
android:versionName="1.2.0" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030001" android:required="true"/>
@ -10,12 +10,13 @@
<uses-feature android:name="android.hardware.vr.headtracking" android:version="1"
android:required="true" />
<!-- Network access needed for OVRMonitor -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Volume Control -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:allowBackup="false" android:icon="@drawable/ic_rtcwquest" android:label="@string/rtcwquest">
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
<meta-data android:name="com.oculus.supportedDevices" android:value="quest|quest2"/>

View file

@ -23,7 +23,7 @@ android {
abiFilters 'armeabi-v7a'
}
}
minSdkVersion 24
minSdkVersion 26
targetSdkVersion 26
}
@ -40,13 +40,14 @@ android {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
compileSdkVersion = 24
compileSdkVersion = 26
buildToolsVersion = '29.0.1'
}
dependencies {
implementation "com.android.support:support-compat:24.2.0"
implementation "com.android.support:support-core-utils:24.2.0"
implementation "com.android.support:support-compat:26.1.0"
implementation "com.android.support:support-core-utils:26.1.0"
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
repositories {

View file

@ -1882,8 +1882,14 @@ Activity lifecycle
jmethodID android_shutdown;
jmethodID android_haptic_event;
jmethodID android_haptic_updateevent;
jmethodID android_haptic_stopevent;
jmethodID android_haptic_endframe;
jmethodID android_haptic_enable;
jmethodID android_haptic_disable;
static JavaVM *jVM;
static jobject shutdownCallbackObj=0;
static jobject jniCallbackObj=0;
void jni_shutdown()
{
@ -1894,7 +1900,88 @@ void jni_shutdown()
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
return (*env)->CallVoidMethod(env, shutdownCallbackObj, android_shutdown);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_shutdown);
}
void jni_haptic_event(const char* event, int position, int flags, int intensity, float angle, float yHeight)
{
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
jstring StringArg1 = (*env)->NewStringUTF(env, event);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_event, StringArg1, position, flags, intensity, angle, yHeight);
}
void jni_haptic_updateevent(const char* event, int intensity, float angle)
{
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
jstring StringArg1 = (*env)->NewStringUTF(env, event);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_updateevent, StringArg1, intensity, angle);
}
void jni_haptic_stopevent(const char* event)
{
ALOGV("Calling: jni_haptic_stopevent");
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
jstring StringArg1 = (*env)->NewStringUTF(env, event);
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_stopevent, StringArg1);
}
void jni_haptic_endframe()
{
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_endframe);
}
void jni_haptic_enable()
{
ALOGV("Calling: jni_haptic_enable");
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_enable);
}
void jni_haptic_disable()
{
ALOGV("Calling: jni_haptic_disable");
JNIEnv *env;
jobject tmp;
if (((*jVM)->GetEnv(jVM, (void**) &env, JNI_VERSION_1_4))<0)
{
(*jVM)->AttachCurrentThread(jVM,&env, NULL);
}
return (*env)->CallVoidMethod(env, jniCallbackObj, android_haptic_disable);
}
int JNI_OnLoad(JavaVM* vm, void* reserved)
@ -1990,8 +2077,8 @@ JNIEXPORT void JNICALL Java_com_drbeef_rtcwquest_GLES3JNILib_onStart( JNIEnv * e
ALOGV( " GLES3JNILib::onStart()" );
shutdownCallbackObj = (jobject)(*env)->NewGlobalRef(env, obj1);
jclass callbackClass = (*env)->GetObjectClass(env, shutdownCallbackObj);
jniCallbackObj = (jobject)(*env)->NewGlobalRef(env, obj1);
jclass callbackClass = (*env)->GetObjectClass(env, jniCallbackObj);
android_shutdown = (*env)->GetMethodID(env,callbackClass,"shutdown","()V");

View file

@ -60,6 +60,12 @@ int GetRefresh();
qboolean RTCWVR_useScreenLayer();
void RTCWVR_GetScreenRes(int *width, int *height);
void RTCWVR_Vibrate(int duration, int channel, float intensity );
void RTCWVR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
void RTCWVR_HapticUpdateEvent(const char* event, int intensity, float angle );
void RTCWVR_HapticEndFrame();
void RTCWVR_HapticStopEvent(const char* event);
void RTCWVR_HapticEnable();
void RTCWVR_HapticDisable();
qboolean RTCWVR_processMessageQueue();
void RTCWVR_FrameSetup();
void RTCWVR_setUseScreenLayer(qboolean use);

View file

@ -45,7 +45,12 @@ extern qboolean getCameraInfo( int camNum, int time, vec3_t *origin, vec3_t *ang
extern void SV_SendMoveSpeedsToGame( int entnum, char *text );
extern qboolean SV_GetModelInfo( int clientNum, char *modelName, animModelInfo_t **modelInfo );
void RTCWVR_Vibrate(int duration, int channel, float intensity );
void RTCWVR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
void RTCWVR_HapticUpdateEvent(const char* event, int intensity, float angle );
void RTCWVR_HapticEndFrame();
void RTCWVR_HapticStopEvent(const char* event);
void RTCWVR_HapticEnable();
void RTCWVR_HapticDisable();
/*
====================

View file

@ -304,6 +304,12 @@ static int FloatAsInt( float f ) {
}
void RTCWVR_Vibrate(int duration, int channel, float intensity );
void RTCWVR_HapticEvent(const char* event, int position, int flags, int intensity, float angle, float yHeight );
void RTCWVR_HapticUpdateEvent(const char* event, int intensity, float angle );
void RTCWVR_HapticEndFrame();
void RTCWVR_HapticStopEvent(const char* event);
void RTCWVR_HapticEnable();
void RTCWVR_HapticDisable();
/*
====================

Binary file not shown.

View file

@ -30,7 +30,7 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;
import com.drbeef.hapticsservice.IHapticsService;
import com.drbeef.externalhapticsservice.HapticServiceClient;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
@ -45,10 +45,10 @@ import static android.system.Os.setenv;
System.loadLibrary( "rtcw_client" );
}
private boolean hasHapticService = false;
private IHapticsService hapticsService = null;
private HapticServiceClient externalHapticsServiceClient = null;
private static final String TAG = "RTCWQuest";
private static final String APPLICATION = "RTCWQuest";
private int permissionCount = 0;
private static final int READ_EXTERNAL_STORAGE_PERMISSION_ID = 1;
@ -81,66 +81,78 @@ import static android.system.Os.setenv;
public void haptic_event(String event, int position, int flags, int intensity, float angle, float yHeight) {
if (hasHapticService) {
if (externalHapticsServiceClient.hasService()) {
try {
hapticsService.hapticEvent(APPLICATION, event, position, flags, intensity, angle, yHeight);
} catch (RemoteException e) {
e.printStackTrace();
externalHapticsServiceClient.getHapticsService().hapticEvent(APPLICATION, event, position, flags, intensity, angle, yHeight);
}
catch (RemoteException r)
{
Log.v(APPLICATION, r.toString());
}
}
}
public void haptic_updateevent(String event, int intensity, float angle) {
if (hasHapticService) {
if (externalHapticsServiceClient.hasService()) {
try {
hapticsService.hapticUpdateEvent(APPLICATION, event, intensity, angle);
} catch (RemoteException e) {
e.printStackTrace();
externalHapticsServiceClient.getHapticsService().hapticUpdateEvent(APPLICATION, event, intensity, angle);
}
catch (RemoteException r)
{
Log.v(APPLICATION, r.toString());
}
}
}
public void haptic_stopevent(String event) {
if (hasHapticService) {
if (externalHapticsServiceClient.hasService()) {
try {
hapticsService.hapticStopEvent(APPLICATION, event);
} catch (RemoteException e) {
e.printStackTrace();
externalHapticsServiceClient.getHapticsService().hapticStopEvent(APPLICATION, event);
}
catch (RemoteException r)
{
Log.v(APPLICATION, r.toString());
}
}
}
public void haptic_endframe() {
if (hasHapticService) {
if (externalHapticsServiceClient.hasService()) {
try {
hapticsService.hapticFrameTick();
} catch (RemoteException e) {
e.printStackTrace();
externalHapticsServiceClient.getHapticsService().hapticFrameTick();
}
catch (RemoteException r)
{
Log.v(APPLICATION, r.toString());
}
}
}
public void haptic_enable() {
if (hasHapticService) {
if (externalHapticsServiceClient.hasService()) {
try {
hapticsService.hapticEnable();
} catch (RemoteException e) {
e.printStackTrace();
externalHapticsServiceClient.getHapticsService().hapticEnable();
}
catch (RemoteException r)
{
Log.v(APPLICATION, r.toString());
}
}
}
public void haptic_disable() {
if (hasHapticService) {
if (externalHapticsServiceClient.hasService()) {
try {
hapticsService.hapticDisable();
} catch (RemoteException e) {
e.printStackTrace();
externalHapticsServiceClient.getHapticsService().hapticDisable();
}
catch (RemoteException r)
{
Log.v(APPLICATION, r.toString());
}
}
}
@ -288,6 +300,12 @@ import static android.system.Os.setenv;
}
externalHapticsServiceClient = new HapticServiceClient(this, (state, desc) -> {
Log.v(APPLICATION, "ExternalHapticsService is:" + desc);
});
externalHapticsServiceClient.bindService();
mNativeHandle = GLES3JNILib.onCreate( this, commandLineParams );
}
@ -338,11 +356,10 @@ import static android.system.Os.setenv;
Log.v( TAG, "GLES3JNIActivity::onStart()" );
super.onStart();
// Bind to the service - Make this a config file thing
bindService(new Intent("com.drbeef.hapticservice.HapticService_bHaptics").setPackage("com.drbeef.hapticservice"), this,
Context.BIND_AUTO_CREATE);
GLES3JNILib.onStart( mNativeHandle, this );
if ( mNativeHandle != 0 )
{
GLES3JNILib.onStart(mNativeHandle, this);
}
}
@Override protected void onResume()
@ -350,20 +367,29 @@ import static android.system.Os.setenv;
Log.v( TAG, "GLES3JNIActivity::onResume()" );
super.onResume();
GLES3JNILib.onResume( mNativeHandle );
if ( mNativeHandle != 0 )
{
GLES3JNILib.onResume(mNativeHandle);
}
}
@Override protected void onPause()
{
Log.v( TAG, "GLES3JNIActivity::onPause()" );
GLES3JNILib.onPause( mNativeHandle );
if ( mNativeHandle != 0 )
{
GLES3JNILib.onPause(mNativeHandle);
}
super.onPause();
}
@Override protected void onStop()
{
Log.v( TAG, "GLES3JNIActivity::onStop()" );
GLES3JNILib.onStop( mNativeHandle );
if ( mNativeHandle != 0 )
{
GLES3JNILib.onStop(mNativeHandle);
}
super.onStop();
}
@ -376,7 +402,12 @@ import static android.system.Os.setenv;
GLES3JNILib.onSurfaceDestroyed( mNativeHandle );
}
GLES3JNILib.onDestroy( mNativeHandle );
if ( mNativeHandle != 0 )
{
GLES3JNILib.onDestroy(mNativeHandle);
}
externalHapticsServiceClient.stopBinding();
super.onDestroy();
// Reset everything in case the user re opens the app
@ -413,18 +444,4 @@ import static android.system.Os.setenv;
mSurfaceHolder = null;
}
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
hapticsService = IHapticsService.Stub.asInterface(service);
hasHapticService = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
stopService(new Intent("com.drbeef.hapticservice.HapticService_bHaptics").setPackage("com.drbeef.hapticservice"));
hasHapticService = false;
hapticsService = null;
}
}