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 <clombardo169@gmail.com>
This commit is contained in:
JosJuice
2022-12-27 16:29:01 +01:00
parent 42943672bb
commit c2779aef06
24 changed files with 772 additions and 5 deletions

View File

@ -103,6 +103,14 @@ static jclass s_emulated_controller_class;
static jfieldID s_emulated_controller_pointer;
static jmethodID s_emulated_controller_constructor;
static jclass s_core_device_class;
static jfieldID s_core_device_pointer;
static jmethodID s_core_device_constructor;
static jclass s_core_device_control_class;
static jfieldID s_core_device_control_pointer;
static jmethodID s_core_device_control_constructor;
namespace IDCache
{
JNIEnv* GetEnvForThread()
@ -478,6 +486,36 @@ jmethodID GetNumericSettingConstructor()
return s_numeric_setting_constructor;
}
jclass GetCoreDeviceClass()
{
return s_core_device_class;
}
jfieldID GetCoreDevicePointer()
{
return s_core_device_pointer;
}
jmethodID GetCoreDeviceConstructor()
{
return s_core_device_constructor;
}
jclass GetCoreDeviceControlClass()
{
return s_core_device_control_class;
}
jfieldID GetCoreDeviceControlPointer()
{
return s_core_device_control_pointer;
}
jmethodID GetCoreDeviceControlConstructor()
{
return s_core_device_control_constructor;
}
} // namespace IDCache
extern "C" {
@ -672,6 +710,23 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
s_numeric_setting_constructor = env->GetMethodID(numeric_setting_class, "<init>", "(J)V");
env->DeleteLocalRef(numeric_setting_class);
const jclass core_device_class =
env->FindClass("org/dolphinemu/dolphinemu/features/input/model/CoreDevice");
s_core_device_class = reinterpret_cast<jclass>(env->NewGlobalRef(core_device_class));
s_core_device_pointer = env->GetFieldID(core_device_class, "mPointer", "J");
s_core_device_constructor = env->GetMethodID(core_device_class, "<init>", "(J)V");
env->DeleteLocalRef(core_device_class);
const jclass core_device_control_class =
env->FindClass("org/dolphinemu/dolphinemu/features/input/model/CoreDevice$Control");
s_core_device_control_class =
reinterpret_cast<jclass>(env->NewGlobalRef(core_device_control_class));
s_core_device_control_pointer = env->GetFieldID(core_device_control_class, "mPointer", "J");
s_core_device_control_constructor =
env->GetMethodID(core_device_control_class, "<init>",
"(Lorg/dolphinemu/dolphinemu/features/input/model/CoreDevice;J)V");
env->DeleteLocalRef(core_device_control_class);
return JNI_VERSION;
}
@ -704,5 +759,7 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
env->DeleteGlobalRef(s_control_reference_class);
env->DeleteGlobalRef(s_emulated_controller_class);
env->DeleteGlobalRef(s_numeric_setting_class);
env->DeleteGlobalRef(s_core_device_class);
env->DeleteGlobalRef(s_core_device_control_class);
}
}

View File

@ -102,4 +102,12 @@ jclass GetNumericSettingClass();
jfieldID GetNumericSettingPointer();
jmethodID GetNumericSettingConstructor();
jclass GetCoreDeviceClass();
jfieldID GetCoreDevicePointer();
jmethodID GetCoreDeviceConstructor();
jclass GetCoreDeviceControlClass();
jfieldID GetCoreDeviceControlPointer();
jmethodID GetCoreDeviceControlConstructor();
} // namespace IDCache

View File

@ -16,6 +16,8 @@ add_library(main SHARED
Input/ControlGroup.h
Input/ControlReference.cpp
Input/ControlReference.h
Input/CoreDevice.cpp
Input/CoreDevice.h
Input/EmulatedController.cpp
Input/EmulatedController.h
Input/InputOverrider.cpp

View File

@ -51,4 +51,11 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlReferen
ControlReferenceFromJava(env, obj)->SetExpression(GetJString(env, expr));
return result ? ToJString(env, *result) : nullptr;
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlReference_isInput(
JNIEnv* env, jobject obj)
{
return static_cast<jboolean>(ControlReferenceFromJava(env, obj)->IsInput());
}
}

View File

@ -0,0 +1,84 @@
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "jni/Input/CoreDevice.h"
#include <memory>
#include <utility>
#include <vector>
#include <jni.h>
#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<ciface::Core::Device::Control*>(
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<jlong>(control));
}
template <typename T>
static jobjectArray CoreDeviceControlVectorToJava(JNIEnv* env, jobject device,
const std::vector<T*>& controls)
{
return VectorToJObjectArray(
env, controls, IDCache::GetCoreDeviceControlClass(),
[device](JNIEnv* env, T* control) { return CoreDeviceControlToJava(env, device, control); });
}
static std::shared_ptr<ciface::Core::Device>* GetDevicePointer(JNIEnv* env, jobject obj)
{
return reinterpret_cast<std::shared_ptr<ciface::Core::Device>*>(
env->GetLongField(obj, IDCache::GetCoreDevicePointer()));
}
jobject CoreDeviceToJava(JNIEnv* env, std::shared_ptr<ciface::Core::Device> device)
{
if (!device)
return nullptr;
return env->NewObject(
IDCache::GetCoreDeviceClass(), IDCache::GetCoreDeviceConstructor(),
reinterpret_cast<jlong>(new std::shared_ptr<ciface::Core::Device>(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());
}
}

View File

@ -0,0 +1,15 @@
// Copyright 2022 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <jni.h>
namespace ciface::Core
{
class Device;
}
jobject CoreDeviceToJava(JNIEnv* env, std::shared_ptr<ciface::Core::Device> device);

View File

@ -53,6 +53,19 @@ Java_org_dolphinemu_dolphinemu_features_input_model_MappingCommon_detectInput(
ciface::MappingCommon::Quote::On));
}
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_MappingCommon_getExpressionForControl(
JNIEnv* env, jclass, jstring j_control, jstring j_device, jstring j_default_device)
{
ciface::Core::DeviceQualifier device_qualifier, default_device_qualifier;
device_qualifier.FromString(GetJString(env, j_device));
default_device_qualifier.FromString(GetJString(env, j_default_device));
return ToJString(env, ciface::MappingCommon::GetExpressionForControl(GetJString(env, j_control),
device_qualifier,
default_device_qualifier));
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_MappingCommon_save(JNIEnv* env, jclass)
{