From c2779aef060137d9062cfd29babb3c43fc5fa2b5 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 27 Dec 2022 16:29:01 +0100 Subject: Android: Add the advanced input mapping dialog It's missing a lot of features from the PC version for now, like buttons for inserting functions and the ability to see what the expression evaluates to. I mostly just wanted to get something in place so you can set up rumble. Co-authored-by: Charles Lombardo --- Source/Android/jni/Input/CoreDevice.cpp | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 Source/Android/jni/Input/CoreDevice.cpp (limited to 'Source/Android/jni/Input/CoreDevice.cpp') diff --git a/Source/Android/jni/Input/CoreDevice.cpp b/Source/Android/jni/Input/CoreDevice.cpp new file mode 100644 index 0000000000..4fd4758ebb --- /dev/null +++ b/Source/Android/jni/Input/CoreDevice.cpp @@ -0,0 +1,84 @@ +// Copyright 2022 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "jni/Input/CoreDevice.h" + +#include +#include +#include + +#include + +#include "InputCommon/ControllerInterface/CoreDevice.h" +#include "jni/AndroidCommon/AndroidCommon.h" +#include "jni/AndroidCommon/IDCache.h" + +static ciface::Core::Device::Control* GetControlPointer(JNIEnv* env, jobject obj) +{ + return reinterpret_cast( + env->GetLongField(obj, IDCache::GetCoreDeviceControlPointer())); +} + +static jobject CoreDeviceControlToJava(JNIEnv* env, jobject device, + ciface::Core::Device::Control* control) +{ + if (!control) + return nullptr; + + return env->NewObject(IDCache::GetCoreDeviceControlClass(), + IDCache::GetCoreDeviceControlConstructor(), device, + reinterpret_cast(control)); +} + +template +static jobjectArray CoreDeviceControlVectorToJava(JNIEnv* env, jobject device, + const std::vector& controls) +{ + return VectorToJObjectArray( + env, controls, IDCache::GetCoreDeviceControlClass(), + [device](JNIEnv* env, T* control) { return CoreDeviceControlToJava(env, device, control); }); +} + +static std::shared_ptr* GetDevicePointer(JNIEnv* env, jobject obj) +{ + return reinterpret_cast*>( + env->GetLongField(obj, IDCache::GetCoreDevicePointer())); +} + +jobject CoreDeviceToJava(JNIEnv* env, std::shared_ptr device) +{ + if (!device) + return nullptr; + + return env->NewObject( + IDCache::GetCoreDeviceClass(), IDCache::GetCoreDeviceConstructor(), + reinterpret_cast(new std::shared_ptr(std::move(device)))); +} + +extern "C" { + +JNIEXPORT jstring JNICALL +Java_org_dolphinemu_dolphinemu_features_input_model_CoreDevice_00024Control_getName(JNIEnv* env, + jobject obj) +{ + return ToJString(env, GetControlPointer(env, obj)->GetName()); +} + +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_features_input_model_CoreDevice_finalize(JNIEnv* env, jobject obj) +{ + delete GetDevicePointer(env, obj); +} + +JNIEXPORT jobjectArray JNICALL +Java_org_dolphinemu_dolphinemu_features_input_model_CoreDevice_getInputs(JNIEnv* env, jobject obj) +{ + return CoreDeviceControlVectorToJava(env, obj, (*GetDevicePointer(env, obj))->Inputs()); +} + +JNIEXPORT jobjectArray JNICALL +Java_org_dolphinemu_dolphinemu_features_input_model_CoreDevice_getOutputs(JNIEnv* env, jobject obj) +{ + return CoreDeviceControlVectorToJava(env, obj, (*GetDevicePointer(env, obj))->Outputs()); +} +} -- cgit v1.2.3