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 14, 2021
1 parent 52372a9 commit cc986d7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Refer to the license.txt file included.

#include <EGL/egl.h>
#include <UICommon/GameFile.h>
#include <android/log.h>
#include <android/native_window_jni.h>
#include <cinttypes>
Expand Down Expand Up @@ -55,13 +54,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 @@ -467,6 +466,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 @@ -43,8 +43,6 @@ constexpr const char* DUBOIS_ALGORITHM_SHADER = "dubois";

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

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

g_controller_interface.Initialize(GetWindowSystemInfo(windowHandle()));
Pad::Initialize();
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 @@ -330,12 +327,7 @@ void MainWindow::ShutdownControllers()
{
m_hotkey_scheduler->Stop();

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

m_hotkey_scheduler->deleteLater();
}
Expand Down
30 changes: 30 additions & 0 deletions Source/Core/UICommon/UICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@
#include "Core/ConfigLoaders/BaseConfigLoader.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/FreeLookManager.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 +119,31 @@ void Shutdown()
Config::Shutdown();
}

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

g_controller_interface.Initialize(wsi);

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

void ShutdownControllers()
{
Pad::Shutdown();
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 @@ -8,11 +8,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 cc986d7

Please sign in to comment.