2015-11-27 08:33:07 +00:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/Host.h"
|
2018-01-20 20:00:28 +00:00
|
|
|
|
2016-05-12 01:18:30 +00:00
|
|
|
#include <QAbstractEventDispatcher>
|
|
|
|
#include <QApplication>
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2019-03-17 00:09:06 +00:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "Common/Common.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2019-03-03 04:41:50 +00:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2018-01-20 20:00:28 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Debugger/PPCDebugInterface.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
#include "Core/Host.h"
|
2019-02-14 02:31:31 +00:00
|
|
|
#include "Core/NetPlayProto.h"
|
2018-02-14 22:25:01 +00:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2020-04-14 22:12:35 +00:00
|
|
|
#include "Core/State.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2018-07-06 22:40:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2018-05-28 01:48:04 +00:00
|
|
|
|
2018-10-27 11:22:55 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
|
2019-02-14 02:31:31 +00:00
|
|
|
#include "UICommon/DiscordPresence.h"
|
|
|
|
|
2018-01-20 20:00:28 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2018-05-03 12:16:21 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2015-11-27 08:33:07 +00:00
|
|
|
|
2020-04-14 22:12:35 +00:00
|
|
|
Host::Host()
|
|
|
|
{
|
|
|
|
State::SetOnAfterLoadCallback([this] { Host_UpdateDisasmDialog(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
Host::~Host()
|
|
|
|
{
|
|
|
|
State::SetOnAfterLoadCallback(nullptr);
|
|
|
|
}
|
2015-11-27 08:33:07 +00:00
|
|
|
|
|
|
|
Host* Host::GetInstance()
|
|
|
|
{
|
2017-07-13 19:58:26 +00:00
|
|
|
static Host* s_instance = new Host();
|
|
|
|
return s_instance;
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Host::SetRenderHandle(void* handle)
|
|
|
|
{
|
2018-10-27 11:18:54 +00:00
|
|
|
if (m_render_handle == handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_render_handle = handle;
|
2018-10-03 13:03:13 +00:00
|
|
|
if (g_renderer)
|
2018-10-27 11:22:55 +00:00
|
|
|
{
|
2018-10-03 13:03:13 +00:00
|
|
|
g_renderer->ChangeSurface(handle);
|
2018-10-27 11:22:55 +00:00
|
|
|
if (g_controller_interface.IsInit())
|
|
|
|
g_controller_interface.ChangeWindow(handle);
|
|
|
|
}
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::GetRenderFocus()
|
|
|
|
{
|
|
|
|
return m_render_focus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::SetRenderFocus(bool focus)
|
|
|
|
{
|
|
|
|
m_render_focus = focus;
|
2018-05-03 12:16:21 +00:00
|
|
|
if (g_renderer && m_render_fullscreen && g_ActiveConfig.ExclusiveFullscreenEnabled())
|
2018-05-15 16:22:26 +00:00
|
|
|
Core::RunAsCPUThread([focus] {
|
2019-03-03 04:41:50 +00:00
|
|
|
if (!Config::Get(Config::MAIN_RENDER_TO_MAIN))
|
2018-05-15 16:22:26 +00:00
|
|
|
g_renderer->SetFullscreen(focus);
|
|
|
|
});
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Host::GetRenderFullscreen()
|
|
|
|
{
|
|
|
|
return m_render_fullscreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host::SetRenderFullscreen(bool fullscreen)
|
|
|
|
{
|
|
|
|
m_render_fullscreen = fullscreen;
|
2018-05-03 12:16:21 +00:00
|
|
|
|
|
|
|
if (g_renderer && g_renderer->IsFullscreen() != fullscreen &&
|
|
|
|
g_ActiveConfig.ExclusiveFullscreenEnabled())
|
|
|
|
Core::RunAsCPUThread([fullscreen] { g_renderer->SetFullscreen(fullscreen); });
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 06:23:24 +00:00
|
|
|
void Host::ResizeSurface(int new_width, int new_height)
|
2018-01-20 20:00:28 +00:00
|
|
|
{
|
|
|
|
if (g_renderer)
|
2018-10-03 13:03:16 +00:00
|
|
|
g_renderer->ResizeSurface();
|
2018-01-20 20:00:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 17:03:29 +00:00
|
|
|
void Host_Message(HostMessageID id)
|
2015-11-27 08:33:07 +00:00
|
|
|
{
|
2018-05-28 17:03:29 +00:00
|
|
|
if (id == HostMessageID::WMUserStop)
|
2016-05-12 01:18:30 +00:00
|
|
|
{
|
2015-11-27 08:33:07 +00:00
|
|
|
emit Host::GetInstance()->RequestStop();
|
2016-05-12 01:18:30 +00:00
|
|
|
}
|
2018-05-28 17:03:29 +00:00
|
|
|
else if (id == HostMessageID::WMUserJobDispatch)
|
2016-05-12 01:18:30 +00:00
|
|
|
{
|
|
|
|
// Just poke the main thread to get it to wake up, job dispatch
|
|
|
|
// will happen automatically before it goes back to sleep again.
|
|
|
|
QAbstractEventDispatcher::instance(qApp->thread())->wakeUp();
|
|
|
|
}
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Host_UpdateTitle(const std::string& title)
|
|
|
|
{
|
|
|
|
emit Host::GetInstance()->RequestTitle(QString::fromStdString(title));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
|
|
|
return Host::GetInstance()->GetRenderFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
|
|
|
return Host::GetInstance()->GetRenderFullscreen();
|
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
|
2016-11-10 16:55:21 +00:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
2016-11-11 12:39:50 +00:00
|
|
|
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
2016-11-10 16:55:21 +00:00
|
|
|
}
|
2018-02-14 22:25:01 +00:00
|
|
|
|
|
|
|
void Host_UpdateDisasmDialog()
|
|
|
|
{
|
2018-05-16 04:10:40 +00:00
|
|
|
QueueOnObject(QApplication::instance(), [] { emit Host::GetInstance()->UpdateDisasmDialog(); });
|
2018-02-14 22:25:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 01:43:18 +00:00
|
|
|
void Host::RequestNotifyMapLoaded()
|
|
|
|
{
|
|
|
|
QueueOnObject(QApplication::instance(), [this] { emit NotifyMapLoaded(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host_NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
Host::GetInstance()->RequestNotifyMapLoaded();
|
|
|
|
}
|
|
|
|
|
2015-11-27 08:33:07 +00:00
|
|
|
// We ignore these, and their purpose should be questioned individually.
|
|
|
|
// In particular, RequestRenderWindowSize, RequestFullscreen, and
|
|
|
|
// UpdateMainFrame should almost certainly be removed.
|
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
|
|
|
}
|
2018-03-24 15:40:47 +00:00
|
|
|
|
2015-11-27 08:33:07 +00:00
|
|
|
void Host_RequestRenderWindowSize(int w, int h)
|
|
|
|
{
|
2018-03-24 15:40:47 +00:00
|
|
|
emit Host::GetInstance()->RequestRenderSize(w, h);
|
2015-11-27 08:33:07 +00:00
|
|
|
}
|
2018-03-24 15:40:47 +00:00
|
|
|
|
2019-03-18 16:30:33 +00:00
|
|
|
bool Host_UIBlocksControllerState()
|
|
|
|
{
|
|
|
|
return ImGui::GetCurrentContext() && ImGui::GetIO().WantCaptureKeyboard;
|
|
|
|
}
|
|
|
|
|
2015-11-27 08:33:07 +00:00
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2019-02-14 02:31:31 +00:00
|
|
|
|
|
|
|
void Host_TitleChanged()
|
|
|
|
{
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
// TODO: Not sure if the NetPlay check is needed.
|
|
|
|
if (!NetPlay::IsNetPlayRunning())
|
|
|
|
Discord::UpdateDiscordPresence();
|
|
|
|
#endif
|
|
|
|
}
|