mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Merge pull request #10783 from JosJuice/frontend-controller-init
Require frontend to initialize controllers
This commit is contained in:
@ -2,7 +2,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <UICommon/GameFile.h>
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android/native_window_jni.h>
|
#include <android/native_window_jni.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -56,13 +55,13 @@
|
|||||||
#include "InputCommon/ControllerInterface/Touch/ButtonManager.h"
|
#include "InputCommon/ControllerInterface/Touch/ButtonManager.h"
|
||||||
#include "InputCommon/GCAdapter.h"
|
#include "InputCommon/GCAdapter.h"
|
||||||
|
|
||||||
|
#include "UICommon/GameFile.h"
|
||||||
#include "UICommon/UICommon.h"
|
#include "UICommon/UICommon.h"
|
||||||
|
|
||||||
#include "VideoCommon/OnScreenDisplay.h"
|
#include "VideoCommon/OnScreenDisplay.h"
|
||||||
#include "VideoCommon/RenderBase.h"
|
#include "VideoCommon/RenderBase.h"
|
||||||
#include "VideoCommon/VideoBackendBase.h"
|
#include "VideoCommon/VideoBackendBase.h"
|
||||||
|
|
||||||
#include "../../Core/Common/WindowSystemInfo.h"
|
|
||||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||||
#include "jni/AndroidCommon/IDCache.h"
|
#include "jni/AndroidCommon/IDCache.h"
|
||||||
|
|
||||||
@ -521,7 +520,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(J
|
|||||||
Common::AndroidSetReportHandler(&ReportSend);
|
Common::AndroidSetReportHandler(&ReportSend);
|
||||||
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
||||||
UICommon::Init();
|
UICommon::Init();
|
||||||
GCAdapter::Init();
|
UICommon::InitControllers(WindowSystemInfo(WindowSystemType::Android, nullptr, nullptr, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "AudioCommon/AudioCommon.h"
|
#include "AudioCommon/AudioCommon.h"
|
||||||
|
|
||||||
|
#include "Common/Assert.h"
|
||||||
#include "Common/CPUDetect.h"
|
#include "Common/CPUDetect.h"
|
||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
@ -470,26 +471,14 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
|||||||
DeclareAsCPUThread();
|
DeclareAsCPUThread();
|
||||||
s_frame_step = false;
|
s_frame_step = false;
|
||||||
|
|
||||||
// The frontend will likely have initialized the controller interface, as it needs
|
// Switch the window used for inputs to the render window. This way, the cursor position
|
||||||
// it to provide the configuration dialogs. In this case, instead of re-initializing
|
// is relative to the render window, instead of the main window.
|
||||||
// entirely, we switch the window used for inputs to the render window. This way, the
|
ASSERT(g_controller_interface.IsInit());
|
||||||
// cursor position is relative to the render window, instead of the main window.
|
g_controller_interface.ChangeWindow(wsi.render_window);
|
||||||
bool init_controllers = false;
|
|
||||||
if (!g_controller_interface.IsInit())
|
Pad::LoadConfig();
|
||||||
{
|
Pad::LoadGBAConfig();
|
||||||
g_controller_interface.Initialize(wsi);
|
Keyboard::LoadConfig();
|
||||||
Pad::Initialize();
|
|
||||||
Pad::InitializeGBA();
|
|
||||||
Keyboard::Initialize();
|
|
||||||
init_controllers = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_controller_interface.ChangeWindow(wsi.render_window);
|
|
||||||
Pad::LoadConfig();
|
|
||||||
Pad::LoadGBAConfig();
|
|
||||||
Keyboard::LoadConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
BootSessionData boot_session_data = std::move(boot->boot_session_data);
|
BootSessionData boot_session_data = std::move(boot->boot_session_data);
|
||||||
const std::optional<std::string>& savestate_path = boot_session_data.GetSavestatePath();
|
const std::optional<std::string>& savestate_path = boot_session_data.GetSavestatePath();
|
||||||
@ -506,53 +495,16 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
|||||||
Common::SyncSDImageToSDFolder();
|
Common::SyncSDImageToSDFolder();
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// Load and Init Wiimotes - only if we are booting in Wii mode
|
// Load Wiimotes - only if we are booting in Wii mode
|
||||||
bool init_wiimotes = false;
|
|
||||||
if (core_parameter.bWii && !Config::Get(Config::MAIN_BLUETOOTH_PASSTHROUGH_ENABLED))
|
if (core_parameter.bWii && !Config::Get(Config::MAIN_BLUETOOTH_PASSTHROUGH_ENABLED))
|
||||||
{
|
{
|
||||||
if (init_controllers)
|
Wiimote::LoadConfig();
|
||||||
{
|
|
||||||
Wiimote::Initialize(savestate_path ? Wiimote::InitializeMode::DO_WAIT_FOR_WIIMOTES :
|
|
||||||
Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
|
|
||||||
init_wiimotes = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Wiimote::LoadConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NetPlay::IsNetPlayRunning())
|
if (NetPlay::IsNetPlayRunning())
|
||||||
NetPlay::SetupWiimotes();
|
NetPlay::SetupWiimotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_controllers)
|
FreeLook::LoadInputConfig();
|
||||||
{
|
|
||||||
FreeLook::Initialize();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FreeLook::LoadInputConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
Common::ScopeGuard controller_guard{[init_controllers, init_wiimotes] {
|
|
||||||
if (!init_controllers)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (init_wiimotes)
|
|
||||||
{
|
|
||||||
Wiimote::ResetAllWiimotes();
|
|
||||||
Wiimote::Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
FreeLook::Shutdown();
|
|
||||||
|
|
||||||
ResetRumble();
|
|
||||||
|
|
||||||
Keyboard::Shutdown();
|
|
||||||
Pad::Shutdown();
|
|
||||||
Pad::ShutdownGBA();
|
|
||||||
g_controller_interface.Shutdown();
|
|
||||||
}};
|
|
||||||
|
|
||||||
Movie::Init(*boot);
|
Movie::Init(*boot);
|
||||||
Common::ScopeGuard movie_guard{&Movie::Shutdown};
|
Common::ScopeGuard movie_guard{&Movie::Shutdown};
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Common/ScopeGuard.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "Core/Boot/Boot.h"
|
#include "Core/Boot/Boot.h"
|
||||||
#include "Core/BootManager.h"
|
#include "Core/BootManager.h"
|
||||||
@ -226,10 +227,6 @@ int main(int argc, char* argv[])
|
|||||||
if (options.is_set("user"))
|
if (options.is_set("user"))
|
||||||
user_directory = static_cast<const char*>(options.get("user"));
|
user_directory = static_cast<const char*>(options.get("user"));
|
||||||
|
|
||||||
UICommon::SetUserDirectory(user_directory);
|
|
||||||
UICommon::Init();
|
|
||||||
GCAdapter::Init();
|
|
||||||
|
|
||||||
s_platform = GetPlatform(options);
|
s_platform = GetPlatform(options);
|
||||||
if (!s_platform || !s_platform->Init())
|
if (!s_platform || !s_platform->Init())
|
||||||
{
|
{
|
||||||
@ -237,6 +234,17 @@ int main(int argc, char* argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WindowSystemInfo wsi = s_platform->GetWindowSystemInfo();
|
||||||
|
|
||||||
|
UICommon::SetUserDirectory(user_directory);
|
||||||
|
UICommon::Init();
|
||||||
|
UICommon::InitControllers(wsi);
|
||||||
|
|
||||||
|
Common::ScopeGuard ui_common_guard([] {
|
||||||
|
UICommon::ShutdownControllers();
|
||||||
|
UICommon::Shutdown();
|
||||||
|
});
|
||||||
|
|
||||||
if (save_state_path && !game_specified)
|
if (save_state_path && !game_specified)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "A save state cannot be loaded without specifying a game to launch.\n");
|
fprintf(stderr, "A save state cannot be loaded without specifying a game to launch.\n");
|
||||||
@ -263,7 +271,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
DolphinAnalytics::Instance().ReportDolphinStart("nogui");
|
DolphinAnalytics::Instance().ReportDolphinStart("nogui");
|
||||||
|
|
||||||
if (!BootManager::BootCore(std::move(boot), s_platform->GetWindowSystemInfo()))
|
if (!BootManager::BootCore(std::move(boot), wsi))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Could not boot the specified file\n");
|
fprintf(stderr, "Could not boot the specified file\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -278,7 +286,6 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
Core::Shutdown();
|
Core::Shutdown();
|
||||||
s_platform.reset();
|
s_platform.reset();
|
||||||
UICommon::Shutdown();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,6 @@ constexpr const char* DUBOIS_ALGORITHM_SHADER = "dubois";
|
|||||||
|
|
||||||
HotkeyScheduler::HotkeyScheduler() : m_stop_requested(false)
|
HotkeyScheduler::HotkeyScheduler() : m_stop_requested(false)
|
||||||
{
|
{
|
||||||
HotkeyManagerEmu::Initialize();
|
|
||||||
HotkeyManagerEmu::LoadConfig();
|
|
||||||
HotkeyManagerEmu::Enable(true);
|
HotkeyManagerEmu::Enable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,24 +321,12 @@ void MainWindow::InitControllers()
|
|||||||
if (g_controller_interface.IsInit())
|
if (g_controller_interface.IsInit())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_controller_interface.Initialize(GetWindowSystemInfo(windowHandle()));
|
UICommon::InitControllers(GetWindowSystemInfo(windowHandle()));
|
||||||
if (!g_controller_interface.HasDefaultDevice())
|
|
||||||
{
|
|
||||||
// Note that the CI default device could be still temporarily removed at any time
|
|
||||||
WARN_LOG_FMT(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();
|
|
||||||
m_hotkey_scheduler = new HotkeyScheduler();
|
m_hotkey_scheduler = new HotkeyScheduler();
|
||||||
m_hotkey_scheduler->Start();
|
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::LoadConfig();
|
||||||
Wiimote::GetConfig()->SaveConfig();
|
Wiimote::GetConfig()->SaveConfig();
|
||||||
@ -362,13 +350,7 @@ void MainWindow::ShutdownControllers()
|
|||||||
|
|
||||||
Settings::Instance().UnregisterDevicesChangedCallback();
|
Settings::Instance().UnregisterDevicesChangedCallback();
|
||||||
|
|
||||||
Pad::Shutdown();
|
UICommon::ShutdownControllers();
|
||||||
Pad::ShutdownGBA();
|
|
||||||
Keyboard::Shutdown();
|
|
||||||
Wiimote::Shutdown();
|
|
||||||
HotkeyManagerEmu::Shutdown();
|
|
||||||
FreeLook::Shutdown();
|
|
||||||
g_controller_interface.Shutdown();
|
|
||||||
|
|
||||||
m_hotkey_scheduler->deleteLater();
|
m_hotkey_scheduler->deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,18 @@
|
|||||||
#include "Core/ConfigLoaders/BaseConfigLoader.h"
|
#include "Core/ConfigLoaders/BaseConfigLoader.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/Core.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/ProcessorInterface.h"
|
||||||
#include "Core/HW/Wiimote.h"
|
#include "Core/HW/Wiimote.h"
|
||||||
|
#include "Core/HotkeyManager.h"
|
||||||
#include "Core/IOS/IOS.h"
|
#include "Core/IOS/IOS.h"
|
||||||
#include "Core/IOS/STM/STM.h"
|
#include "Core/IOS/STM/STM.h"
|
||||||
#include "Core/WiiRoot.h"
|
#include "Core/WiiRoot.h"
|
||||||
|
|
||||||
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
#include "InputCommon/GCAdapter.h"
|
#include "InputCommon/GCAdapter.h"
|
||||||
|
|
||||||
#include "UICommon/DiscordPresence.h"
|
#include "UICommon/DiscordPresence.h"
|
||||||
@ -128,6 +134,41 @@ void Shutdown()
|
|||||||
Config::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_FMT(CONTROLLERINTERFACE, "No default device has been added in time. Premade control "
|
||||||
|
"mappings intended for the default device may not work.");
|
||||||
|
}
|
||||||
|
|
||||||
|
GCAdapter::Init();
|
||||||
|
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)
|
void SetLocale(std::string locale_name)
|
||||||
{
|
{
|
||||||
auto set_locale = [](const std::string& locale) {
|
auto set_locale = [](const std::string& locale) {
|
||||||
|
@ -7,11 +7,16 @@
|
|||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
struct WindowSystemInfo;
|
||||||
|
|
||||||
namespace UICommon
|
namespace UICommon
|
||||||
{
|
{
|
||||||
void Init();
|
void Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
|
void InitControllers(const WindowSystemInfo& wsi);
|
||||||
|
void ShutdownControllers();
|
||||||
|
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
void InhibitScreenSaver(unsigned long win, bool enable);
|
void InhibitScreenSaver(unsigned long win, bool enable);
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user