From 2c529b9db12a60eb3640975f6ea4802237e118fa Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 23 Jan 2022 21:47:57 +0100 Subject: Android: Add new input mapping implementation --- Source/Android/jni/Input/MappingCommon.cpp | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Source/Android/jni/Input/MappingCommon.cpp (limited to 'Source/Android/jni/Input/MappingCommon.cpp') diff --git a/Source/Android/jni/Input/MappingCommon.cpp b/Source/Android/jni/Input/MappingCommon.cpp new file mode 100644 index 0000000000..c02f1c2ae5 --- /dev/null +++ b/Source/Android/jni/Input/MappingCommon.cpp @@ -0,0 +1,56 @@ +// Copyright 2022 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#include +#include + +#include + +#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 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(); +} +}; -- cgit v1.2.3