Skip to content

Commit

Permalink
Android: Initialize ControllerInterface before launching emulation
Browse files Browse the repository at this point in the history
This simplifies the next commit, and we have to do this sooner
or later anyway if we want Android to make proper use of
ControllerInterface.
  • Loading branch information
JosJuice committed May 8, 2022
1 parent e70bcdd commit 3fcdcfb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <EGL/egl.h>
#include <UICommon/GameFile.h>
#include <android/log.h>
#include <android/native_window_jni.h>
#include <cstdio>
Expand Down Expand Up @@ -56,13 +55,13 @@
#include "InputCommon/ControllerInterface/Touch/ButtonManager.h"
#include "InputCommon/GCAdapter.h"

#include "UICommon/GameFile.h"
#include "UICommon/UICommon.h"

#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"

#include "../../Core/Common/WindowSystemInfo.h"
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/AndroidCommon/IDCache.h"

Expand Down Expand Up @@ -522,6 +521,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(J
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
UICommon::Init();
GCAdapter::Init();
UICommon::InitControllers(WindowSystemInfo(WindowSystemType::Android, nullptr, nullptr, nullptr));
}

JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/DolphinQt/HotkeyScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ constexpr const char* DUBOIS_ALGORITHM_SHADER = "dubois";

HotkeyScheduler::HotkeyScheduler() : m_stop_requested(false)
{
HotkeyManagerEmu::Initialize();
HotkeyManagerEmu::LoadConfig();
HotkeyManagerEmu::Enable(true);
}

Expand Down
25 changes: 4 additions & 21 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,24 +321,13 @@ void MainWindow::InitControllers()
if (g_controller_interface.IsInit())
return;

g_controller_interface.Initialize(GetWindowSystemInfo(windowHandle()));
if (!g_controller_interface.HasDefaultDevice())
{
// Note that the CI default device could be still temporarily removed at any time
WARN_LOG(CONTROLLERINTERFACE,
"No default device has been added in time. EmulatedController(s) defaulting adds"
" input mappings made for a specific default device depending on the platform");
}
GCAdapter::Init();
Pad::Initialize();
Pad::InitializeGBA();
Keyboard::Initialize();
Wiimote::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
FreeLook::Initialize();
UICommon::InitControllers(GetWindowSystemInfo(windowHandle()));

m_hotkey_scheduler = new HotkeyScheduler();
m_hotkey_scheduler->Start();

// Defaults won't work reliabily without loading and saving the config first
// Defaults won't work reliably without loading and saving the config first

Wiimote::LoadConfig();
Wiimote::GetConfig()->SaveConfig();
Expand All @@ -360,13 +349,7 @@ void MainWindow::ShutdownControllers()
{
m_hotkey_scheduler->Stop();

Pad::Shutdown();
Pad::ShutdownGBA();
Keyboard::Shutdown();
Wiimote::Shutdown();
HotkeyManagerEmu::Shutdown();
FreeLook::Shutdown();
g_controller_interface.Shutdown();
UICommon::ShutdownControllers();

m_hotkey_scheduler->deleteLater();
}
Expand Down
40 changes: 40 additions & 0 deletions Source/Core/UICommon/UICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@
#include "Core/ConfigLoaders/BaseConfigLoader.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/FreeLookManager.h"
#include "Core/HW/GBAPad.h"
#include "Core/HW/GCKeyboard.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/ProcessorInterface.h"
#include "Core/HW/Wiimote.h"
#include "Core/HotkeyManager.h"
#include "Core/IOS/IOS.h"
#include "Core/IOS/STM/STM.h"
#include "Core/WiiRoot.h"

#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCAdapter.h"

#include "UICommon/DiscordPresence.h"
Expand Down Expand Up @@ -124,6 +130,40 @@ void Shutdown()
Config::Shutdown();
}

void InitControllers(const WindowSystemInfo& wsi)
{
if (g_controller_interface.IsInit())
return;

g_controller_interface.Initialize(wsi);

if (!g_controller_interface.HasDefaultDevice())
{
// Note that the CI default device could be still temporarily removed at any time
WARN_LOG(CONTROLLERINTERFACE, "No default device has been added in time. Premade control "
"mappings intended for the default device may not work.");
}

Pad::Initialize();
Pad::InitializeGBA();
Keyboard::Initialize();
Wiimote::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
HotkeyManagerEmu::Initialize();
FreeLook::Initialize();
}

void ShutdownControllers()
{
Pad::Shutdown();
Pad::ShutdownGBA();
Keyboard::Shutdown();
Wiimote::Shutdown();
HotkeyManagerEmu::Shutdown();
FreeLook::Shutdown();

g_controller_interface.Shutdown();
}

void SetLocale(std::string locale_name)
{
auto set_locale = [](const std::string& locale) {
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/UICommon/UICommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

#include "Common/CommonTypes.h"

struct WindowSystemInfo;

namespace UICommon
{
void Init();
void Shutdown();

void InitControllers(const WindowSystemInfo& wsi);
void ShutdownControllers();

#ifdef HAVE_X11
void InhibitScreenSaver(unsigned long win, bool enable);
#else
Expand Down

0 comments on commit 3fcdcfb

Please sign in to comment.