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 Aug 14, 2021
1 parent dbb58ff commit 96c280c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 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 <cinttypes>
Expand Down Expand Up @@ -54,13 +53,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 @@ -485,6 +484,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(J
Common::AndroidSetReportHandler(&ReportSend);
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
UICommon::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 @@ -47,8 +47,6 @@ constexpr const char* DUBOIS_ALGORITHM_SHADER = "dubois";

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

Expand Down
18 changes: 4 additions & 14 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,12 @@ void MainWindow::InitControllers()
if (g_controller_interface.IsInit())
return;

g_controller_interface.Initialize(GetWindowSystemInfo(windowHandle()));
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 @@ -336,13 +332,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
33 changes: 33 additions & 0 deletions Source/Core/UICommon/UICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,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 @@ -114,6 +120,33 @@ void Shutdown()
Config::Shutdown();
}

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

g_controller_interface.Initialize(wsi);

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 96c280c

Please sign in to comment.