mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Android: Add new input mapping implementation
This commit is contained in:
51
Source/Android/jni/Input/Control.cpp
Normal file
51
Source/Android/jni/Input/Control.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "jni/Input/Control.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "InputCommon/ControlReference/ControlReference.h"
|
||||
#include "InputCommon/ControllerEmu/Control/Control.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
#include "jni/Input/ControlReference.h"
|
||||
|
||||
static ControllerEmu::Control* GetPointer(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return reinterpret_cast<ControllerEmu::Control*>(
|
||||
env->GetLongField(obj, IDCache::GetControlPointer()));
|
||||
}
|
||||
|
||||
jobject ControlToJava(JNIEnv* env, ControllerEmu::Control* control)
|
||||
{
|
||||
if (!control)
|
||||
return nullptr;
|
||||
|
||||
return env->NewObject(IDCache::GetControlClass(), IDCache::GetControlConstructor(),
|
||||
reinterpret_cast<jlong>(control));
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_Control_getUiName(JNIEnv* env,
|
||||
jobject obj)
|
||||
{
|
||||
ControllerEmu::Control* control = GetPointer(env, obj);
|
||||
std::string ui_name = control->ui_name;
|
||||
if (control->translate == ControllerEmu::Translatability::Translate)
|
||||
ui_name = Common::GetStringT(ui_name.c_str());
|
||||
return ToJString(env, ui_name);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_Control_getControlReference(
|
||||
JNIEnv* env, jobject obj)
|
||||
{
|
||||
return ControlReferenceToJava(env, GetPointer(env, obj)->control_ref.get());
|
||||
}
|
||||
}
|
13
Source/Android/jni/Input/Control.h
Normal file
13
Source/Android/jni/Input/Control.h
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace ControllerEmu
|
||||
{
|
||||
class Control;
|
||||
}
|
||||
|
||||
jobject ControlToJava(JNIEnv* env, ControllerEmu::Control* control);
|
51
Source/Android/jni/Input/ControlGroup.cpp
Normal file
51
Source/Android/jni/Input/ControlGroup.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "jni/Input/ControlGroup.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
#include "jni/Input/Control.h"
|
||||
|
||||
static ControllerEmu::ControlGroup* GetPointer(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return reinterpret_cast<ControllerEmu::ControlGroup*>(
|
||||
env->GetLongField(obj, IDCache::GetControlGroupPointer()));
|
||||
}
|
||||
|
||||
jobject ControlGroupToJava(JNIEnv* env, ControllerEmu::ControlGroup* group)
|
||||
{
|
||||
if (!group)
|
||||
return nullptr;
|
||||
|
||||
return env->NewObject(IDCache::GetControlGroupClass(), IDCache::GetControlGroupConstructor(),
|
||||
reinterpret_cast<jlong>(group));
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getUiName(
|
||||
JNIEnv* env, jobject obj)
|
||||
{
|
||||
return ToJString(env, Common::GetStringT(GetPointer(env, obj)->ui_name.c_str()));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getControlCount(
|
||||
JNIEnv* env, jobject obj)
|
||||
{
|
||||
return static_cast<jint>(GetPointer(env, obj)->controls.size());
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getControl(
|
||||
JNIEnv* env, jobject obj, jint i)
|
||||
{
|
||||
return ControlToJava(env, GetPointer(env, obj)->controls[i].get());
|
||||
}
|
||||
}
|
13
Source/Android/jni/Input/ControlGroup.h
Normal file
13
Source/Android/jni/Input/ControlGroup.h
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
namespace ControllerEmu
|
||||
{
|
||||
class ControlGroup;
|
||||
}
|
||||
|
||||
jobject ControlGroupToJava(JNIEnv* env, ControllerEmu::ControlGroup* group);
|
54
Source/Android/jni/Input/ControlReference.cpp
Normal file
54
Source/Android/jni/Input/ControlReference.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "jni/Input/ControlReference.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "InputCommon/ControlReference/ControlReference.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
ControlReference* ControlReferenceFromJava(JNIEnv* env, jobject control_reference)
|
||||
{
|
||||
return reinterpret_cast<ControlReference*>(
|
||||
env->GetLongField(control_reference, IDCache::GetControlReferencePointer()));
|
||||
}
|
||||
|
||||
jobject ControlReferenceToJava(JNIEnv* env, ControlReference* control_reference)
|
||||
{
|
||||
if (!control_reference)
|
||||
return nullptr;
|
||||
|
||||
return env->NewObject(IDCache::GetControlReferenceClass(),
|
||||
IDCache::GetControlReferenceConstructor(),
|
||||
reinterpret_cast<jlong>(control_reference));
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlReference_getState(
|
||||
JNIEnv* env, jobject obj)
|
||||
{
|
||||
return ControlReferenceFromJava(env, obj)->GetState<double>();
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlReference_getExpression(
|
||||
JNIEnv* env, jobject obj)
|
||||
{
|
||||
return ToJString(env, ControlReferenceFromJava(env, obj)->GetExpression());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlReference_setExpression(
|
||||
JNIEnv* env, jobject obj, jstring expr)
|
||||
{
|
||||
const std::optional<std::string> result =
|
||||
ControlReferenceFromJava(env, obj)->SetExpression(GetJString(env, expr));
|
||||
return result ? ToJString(env, *result) : nullptr;
|
||||
}
|
||||
}
|
11
Source/Android/jni/Input/ControlReference.h
Normal file
11
Source/Android/jni/Input/ControlReference.h
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
class ControlReference;
|
||||
|
||||
jobject ControlReferenceToJava(JNIEnv* env, ControlReference* control_reference);
|
||||
ControlReference* ControlReferenceFromJava(JNIEnv* env, jobject control_reference);
|
81
Source/Android/jni/Input/EmulatedController.cpp
Normal file
81
Source/Android/jni/Input/EmulatedController.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "Core/HW/GCPad.h"
|
||||
#include "Core/HW/Wiimote.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
|
||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
#include "InputCommon/InputConfig.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
#include "jni/Input/Control.h"
|
||||
#include "jni/Input/ControlGroup.h"
|
||||
#include "jni/Input/ControlReference.h"
|
||||
|
||||
static ControllerEmu::EmulatedController* GetPointer(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return reinterpret_cast<ControllerEmu::EmulatedController*>(
|
||||
env->GetLongField(obj, IDCache::GetEmulatedControllerPointer()));
|
||||
}
|
||||
|
||||
static jobject EmulatedControllerToJava(JNIEnv* env, ControllerEmu::EmulatedController* controller)
|
||||
{
|
||||
if (!controller)
|
||||
return nullptr;
|
||||
|
||||
return env->NewObject(IDCache::GetEmulatedControllerClass(),
|
||||
IDCache::GetEmulatedControllerConstructor(),
|
||||
reinterpret_cast<jlong>(controller));
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGroupCount(
|
||||
JNIEnv* env, jobject obj)
|
||||
{
|
||||
return static_cast<jint>(GetPointer(env, obj)->groups.size());
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGroup(
|
||||
JNIEnv* env, jobject obj, jint controller_index)
|
||||
{
|
||||
return ControlGroupToJava(env, GetPointer(env, obj)->groups[controller_index].get());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_updateSingleControlReference(
|
||||
JNIEnv* env, jobject obj, jobject control_reference)
|
||||
{
|
||||
return GetPointer(env, obj)->UpdateSingleControlReference(
|
||||
g_controller_interface, ControlReferenceFromJava(env, control_reference));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcPad(
|
||||
JNIEnv* env, jclass, jint controller_index)
|
||||
{
|
||||
return EmulatedControllerToJava(env, Pad::GetConfig()->GetController(controller_index));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getWiimote(
|
||||
JNIEnv* env, jclass, jint controller_index)
|
||||
{
|
||||
return EmulatedControllerToJava(env, Wiimote::GetConfig()->GetController(controller_index));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getWiimoteAttachment(
|
||||
JNIEnv* env, jclass, jint controller_index, jint attachment_index)
|
||||
{
|
||||
auto* attachments = static_cast<ControllerEmu::Attachments*>(
|
||||
Wiimote::GetWiimoteGroup(controller_index, WiimoteEmu::WiimoteGroup::Attachments));
|
||||
return EmulatedControllerToJava(env, attachments->GetAttachmentList()[attachment_index].get());
|
||||
}
|
||||
}
|
56
Source/Android/jni/Input/MappingCommon.cpp
Normal file
56
Source/Android/jni/Input/MappingCommon.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "Core/FreeLookManager.h"
|
||||
#include "Core/HW/GBAPad.h"
|
||||
#include "Core/HW/GCKeyboard.h"
|
||||
#include "Core/HW/GCPad.h"
|
||||
#include "Core/HW/Wiimote.h"
|
||||
#include "Core/HotkeyManager.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
#include "InputCommon/ControllerInterface/MappingCommon.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto INPUT_DETECT_INITIAL_TIME = std::chrono::seconds(3);
|
||||
constexpr auto INPUT_DETECT_CONFIRMATION_TIME = std::chrono::milliseconds(0);
|
||||
constexpr auto INPUT_DETECT_MAXIMUM_TIME = std::chrono::seconds(5);
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_MappingCommon_detectInput(JNIEnv* env, jclass)
|
||||
{
|
||||
const std::vector<std::string> device_strings = g_controller_interface.GetAllDeviceStrings();
|
||||
const ciface::Core::DeviceQualifier default_device{};
|
||||
|
||||
auto detections =
|
||||
g_controller_interface.DetectInput(device_strings, INPUT_DETECT_INITIAL_TIME,
|
||||
INPUT_DETECT_CONFIRMATION_TIME, INPUT_DETECT_MAXIMUM_TIME);
|
||||
|
||||
ciface::MappingCommon::RemoveSpuriousTriggerCombinations(&detections);
|
||||
|
||||
return ToJString(env, ciface::MappingCommon::BuildExpression(detections, default_device,
|
||||
ciface::MappingCommon::Quote::On));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_input_model_MappingCommon_save(JNIEnv* env, jclass)
|
||||
{
|
||||
Pad::GetConfig()->SaveConfig();
|
||||
Pad::GetGBAConfig()->SaveConfig();
|
||||
Keyboard::GetConfig()->SaveConfig();
|
||||
Wiimote::GetConfig()->SaveConfig();
|
||||
HotkeyManagerEmu::GetConfig()->SaveConfig();
|
||||
FreeLook::GetInputConfig()->SaveConfig();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user