2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-07-13 07:31:43 +00:00
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
#include "DolphinNoGUI/Platform.h"
|
|
|
|
|
2016-01-17 11:13:09 +00:00
|
|
|
#include <OptionParser.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstddef>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <cstdio>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstring>
|
2016-09-24 19:17:34 +00:00
|
|
|
#include <signal.h>
|
2014-03-12 19:33:41 +00:00
|
|
|
#include <string>
|
2018-10-24 05:50:54 +00:00
|
|
|
#ifndef _WIN32
|
2015-09-04 06:14:10 +00:00
|
|
|
#include <unistd.h>
|
2019-11-26 04:25:19 +00:00
|
|
|
#else
|
|
|
|
#include <Windows.h>
|
2018-10-24 05:50:54 +00:00
|
|
|
#endif
|
2009-05-15 08:55:46 +00:00
|
|
|
|
2019-11-26 04:25:19 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2017-05-27 13:43:40 +00:00
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/BootManager.h"
|
|
|
|
#include "Core/Core.h"
|
2020-09-15 10:13:10 +00:00
|
|
|
#include "Core/DolphinAnalytics.h"
|
2014-08-02 06:21:03 +00:00
|
|
|
#include "Core/Host.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
|
2016-01-17 11:13:09 +00:00
|
|
|
#include "UICommon/CommandLineParse.h"
|
2018-06-08 20:56:11 +00:00
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
#include "UICommon/DiscordPresence.h"
|
|
|
|
#endif
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2016-11-19 13:03:20 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
static std::unique_ptr<Platform> s_platform;
|
2016-09-24 19:17:34 +00:00
|
|
|
|
|
|
|
static void signal_handler(int)
|
|
|
|
{
|
|
|
|
const char message[] = "A signal was received. A second signal will force Dolphin to stop.\n";
|
2018-10-24 05:50:54 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
puts(message);
|
|
|
|
#else
|
2016-09-24 19:17:34 +00:00
|
|
|
if (write(STDERR_FILENO, message, sizeof(message)) < 0)
|
|
|
|
{
|
|
|
|
}
|
2018-10-24 05:50:54 +00:00
|
|
|
#endif
|
2016-10-01 19:35:29 +00:00
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
s_platform->RequestShutdown();
|
2016-09-24 19:17:34 +00:00
|
|
|
}
|
2010-05-26 21:23:44 +00:00
|
|
|
|
2011-02-08 15:36:15 +00:00
|
|
|
void Host_NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2019-03-18 16:30:33 +00:00
|
|
|
bool Host_UIBlocksControllerState()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
static Common::Event s_update_main_frame_event;
|
2018-05-28 17:03:29 +00:00
|
|
|
void Host_Message(HostMessageID id)
|
2010-03-16 13:18:52 +00:00
|
|
|
{
|
2018-05-28 17:03:29 +00:00
|
|
|
if (id == HostMessageID::WMUserStop)
|
2018-10-24 05:50:54 +00:00
|
|
|
s_platform->Stop();
|
2010-03-16 13:18:52 +00:00
|
|
|
}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2014-08-06 04:44:21 +00:00
|
|
|
void Host_UpdateTitle(const std::string& title)
|
|
|
|
{
|
2018-10-24 05:50:54 +00:00
|
|
|
s_platform->SetTitle(title);
|
2014-08-06 04:44:21 +00:00
|
|
|
}
|
2010-04-19 03:06:18 +00:00
|
|
|
|
2008-09-07 20:26:38 +00:00
|
|
|
void Host_UpdateDisasmDialog()
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2008-09-07 20:26:38 +00:00
|
|
|
}
|
|
|
|
|
2008-09-07 21:06:55 +00:00
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
2018-10-24 05:50:54 +00:00
|
|
|
s_update_main_frame_event.Set();
|
2008-09-07 21:06:55 +00:00
|
|
|
}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2011-01-25 12:52:20 +00:00
|
|
|
void Host_RequestRenderWindowSize(int width, int height)
|
|
|
|
{
|
|
|
|
}
|
2014-07-16 13:53:33 +00:00
|
|
|
|
2010-04-12 01:33:10 +00:00
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
2018-10-24 05:50:54 +00:00
|
|
|
return s_platform->IsWindowFocused();
|
2010-04-12 01:33:10 +00:00
|
|
|
}
|
2008-09-07 20:26:38 +00:00
|
|
|
|
2015-01-04 16:09:56 +00:00
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
2018-10-24 05:50:54 +00:00
|
|
|
return s_platform->IsWindowFullscreen();
|
2015-01-04 16:09:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 16:55:21 +00:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-14 02:31:31 +00:00
|
|
|
void Host_TitleChanged()
|
|
|
|
{
|
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
Discord::UpdateDiscordPresence();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
static std::unique_ptr<Platform> GetPlatform(const optparse::Values& options)
|
2014-08-06 04:34:31 +00:00
|
|
|
{
|
2018-10-24 05:50:54 +00:00
|
|
|
std::string platform_name = static_cast<const char*>(options.get("platform"));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
#if HAVE_X11
|
|
|
|
if (platform_name == "x11" || platform_name.empty())
|
|
|
|
return Platform::CreateX11Platform();
|
2010-04-22 04:28:34 +00:00
|
|
|
#endif
|
2010-11-25 02:26:46 +00:00
|
|
|
|
2019-04-10 14:44:21 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
if (platform_name == "fbdev" || platform_name.empty())
|
|
|
|
return Platform::CreateFBDevPlatform();
|
|
|
|
#endif
|
|
|
|
|
2019-11-26 04:25:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (platform_name == "win32" || platform_name.empty())
|
|
|
|
return Platform::CreateWin32Platform();
|
|
|
|
#endif
|
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
if (platform_name == "headless" || platform_name.empty())
|
|
|
|
return Platform::CreateHeadlessPlatform();
|
2009-01-12 20:52:45 +00:00
|
|
|
|
2014-08-06 04:34:31 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2016-01-17 11:13:09 +00:00
|
|
|
auto parser = CommandLineParse::CreateParser(CommandLineParse::ParserOptions::OmitGUIOptions);
|
2018-10-24 05:50:54 +00:00
|
|
|
parser->add_option("-p", "--platform")
|
|
|
|
.action("store")
|
|
|
|
.help("Window platform to use [%choices]")
|
|
|
|
.choices({
|
|
|
|
"headless"
|
2019-04-10 14:44:21 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
,
|
|
|
|
"fbdev"
|
|
|
|
#endif
|
2018-10-24 05:50:54 +00:00
|
|
|
#if HAVE_X11
|
|
|
|
,
|
|
|
|
"x11"
|
2019-11-26 04:25:19 +00:00
|
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
|
|
,
|
|
|
|
"win32"
|
2018-10-24 05:50:54 +00:00
|
|
|
#endif
|
|
|
|
});
|
|
|
|
|
2016-01-17 11:13:09 +00:00
|
|
|
optparse::Values& options = CommandLineParse::ParseArguments(parser.get(), argc, argv);
|
|
|
|
std::vector<std::string> args = parser->args();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-05-07 03:10:30 +00:00
|
|
|
std::optional<std::string> save_state_path;
|
|
|
|
if (options.is_set("save_state"))
|
|
|
|
{
|
|
|
|
save_state_path = static_cast<const char*>(options.get("save_state"));
|
|
|
|
}
|
|
|
|
|
2017-10-01 22:09:07 +00:00
|
|
|
std::unique_ptr<BootParameters> boot;
|
2020-05-07 03:10:30 +00:00
|
|
|
bool game_specified = false;
|
2016-01-17 11:13:09 +00:00
|
|
|
if (options.is_set("exec"))
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2018-11-05 18:20:45 +00:00
|
|
|
const std::list<std::string> paths_list = options.all("exec");
|
|
|
|
const std::vector<std::string> paths{std::make_move_iterator(std::begin(paths_list)),
|
|
|
|
std::make_move_iterator(std::end(paths_list))};
|
2020-05-07 03:10:30 +00:00
|
|
|
boot = BootParameters::GenerateFromFile(paths, save_state_path);
|
|
|
|
game_specified = true;
|
2017-10-01 22:09:07 +00:00
|
|
|
}
|
|
|
|
else if (options.is_set("nand_title"))
|
|
|
|
{
|
|
|
|
const std::string hex_string = static_cast<const char*>(options.get("nand_title"));
|
|
|
|
if (hex_string.length() != 16)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Invalid title ID\n");
|
|
|
|
parser->print_help();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const u64 title_id = std::stoull(hex_string, nullptr, 16);
|
|
|
|
boot = std::make_unique<BootParameters>(BootParameters::NANDTitle{title_id});
|
2011-01-15 10:33:07 +00:00
|
|
|
}
|
2016-01-17 11:13:09 +00:00
|
|
|
else if (args.size())
|
2014-02-17 04:51:41 +00:00
|
|
|
{
|
2020-05-07 03:10:30 +00:00
|
|
|
boot = BootParameters::GenerateFromFile(args.front(), save_state_path);
|
2016-01-17 11:13:09 +00:00
|
|
|
args.erase(args.begin());
|
2020-05-07 03:10:30 +00:00
|
|
|
game_specified = true;
|
2016-01-17 11:13:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parser->print_help();
|
|
|
|
return 0;
|
2008-09-07 21:02:57 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-02-28 19:36:11 +00:00
|
|
|
std::string user_directory;
|
|
|
|
if (options.is_set("user"))
|
|
|
|
user_directory = static_cast<const char*>(options.get("user"));
|
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
UICommon::SetUserDirectory(user_directory);
|
|
|
|
UICommon::Init();
|
|
|
|
|
|
|
|
s_platform = GetPlatform(options);
|
|
|
|
if (!s_platform || !s_platform->Init())
|
2014-08-06 04:34:31 +00:00
|
|
|
{
|
2018-10-24 05:50:54 +00:00
|
|
|
fprintf(stderr, "No platform found, or failed to initialize.\n");
|
2014-08-06 04:34:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-05-07 03:10:30 +00:00
|
|
|
if (save_state_path && !game_specified)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "A save state cannot be loaded without specifying a game to launch.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-09-04 17:57:42 +00:00
|
|
|
Core::SetOnStateChangedCallback([](Core::State state) {
|
|
|
|
if (state == Core::State::Uninitialized)
|
2018-10-24 05:50:54 +00:00
|
|
|
s_platform->Stop();
|
2017-09-04 17:57:42 +00:00
|
|
|
});
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-11-26 04:25:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
#else
|
2016-09-24 19:17:34 +00:00
|
|
|
// Shut down cleanly on SIGINT and SIGTERM
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = signal_handler;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_RESETHAND;
|
|
|
|
sigaction(SIGINT, &sa, nullptr);
|
|
|
|
sigaction(SIGTERM, &sa, nullptr);
|
2019-11-26 04:25:19 +00:00
|
|
|
#endif
|
2016-09-24 19:17:34 +00:00
|
|
|
|
2019-06-23 17:26:07 +00:00
|
|
|
DolphinAnalytics::Instance().ReportDolphinStart("nogui");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
if (!BootManager::BootCore(std::move(boot), s_platform->GetWindowSystemInfo()))
|
2014-08-06 04:34:31 +00:00
|
|
|
{
|
2017-10-01 22:09:07 +00:00
|
|
|
fprintf(stderr, "Could not boot the specified file\n");
|
2014-08-06 04:34:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2018-06-08 20:56:11 +00:00
|
|
|
#ifdef USE_DISCORD_PRESENCE
|
|
|
|
Discord::UpdateDiscordPresence();
|
|
|
|
#endif
|
|
|
|
|
2018-10-24 05:50:54 +00:00
|
|
|
s_platform->MainLoop();
|
2014-08-06 04:34:31 +00:00
|
|
|
Core::Stop();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-06-06 12:52:09 +00:00
|
|
|
Core::Shutdown();
|
2018-10-24 05:50:54 +00:00
|
|
|
s_platform.reset();
|
2014-10-04 19:12:15 +00:00
|
|
|
UICommon::Shutdown();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2011-01-15 10:33:07 +00:00
|
|
|
return 0;
|
2008-09-07 20:26:38 +00:00
|
|
|
}
|