2020-05-25 19:34:42 +00:00
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition, an emulator front-end
|
|
|
|
// with controller navigation and theming support.
|
|
|
|
//
|
|
|
|
// Originally created by Alec "Aloshi" Lofquist.
|
|
|
|
// http://www.aloshi.com
|
|
|
|
// Improved and extended by the RetroPie community.
|
|
|
|
// Desktop Edition fork by Leon Styhre.
|
|
|
|
//
|
2020-06-06 14:48:05 +00:00
|
|
|
// The line length limit is 100 characters and the tab width is 4 spaces.
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-05-25 19:34:42 +00:00
|
|
|
// main.cpp
|
|
|
|
//
|
|
|
|
// Main program loop. Interprets command-line arguments, checks for the
|
|
|
|
// home folder and es_settings.cfg configuration file, sets up the application
|
|
|
|
// environment and starts listening to SDL events.
|
|
|
|
//
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
#include "guis/GuiDetectDevice.h"
|
|
|
|
#include "guis/GuiMsgBox.h"
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "CollectionSystemManager.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "EmulationStation.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "InputManager.h"
|
|
|
|
#include "Log.h"
|
2018-02-09 17:23:58 +00:00
|
|
|
#include "MameNames.h"
|
2020-06-21 10:26:21 +00:00
|
|
|
#include "Platform.h"
|
2017-07-20 07:07:02 +00:00
|
|
|
#include "PowerSaver.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
#include "SystemData.h"
|
|
|
|
#include "SystemScreenSaver.h"
|
|
|
|
#include <SDL_events.h>
|
|
|
|
#include <SDL_main.h>
|
|
|
|
#include <SDL_timer.h>
|
|
|
|
#include <iostream>
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <time.h>
|
2014-11-25 02:49:11 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <FreeImage.h>
|
|
|
|
|
2020-06-18 17:49:47 +00:00
|
|
|
enum eErrorCodes {
|
|
|
|
NO_ERRORS,
|
|
|
|
NO_SYSTEMS_FILE,
|
|
|
|
NO_ROMS
|
|
|
|
};
|
|
|
|
|
2017-12-01 17:42:27 +00:00
|
|
|
bool parseArgs(int argc, char* argv[])
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2019-08-16 07:47:37 +00:00
|
|
|
Utils::FileSystem::setExePath(argv[0]);
|
2018-02-08 18:27:44 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// We need to process --home before any call to Settings::getInstance(),
|
|
|
|
// because settings are loaded from the home path.
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (strcmp(argv[i], "--home") == 0) {
|
|
|
|
if (i >= argc - 1) {
|
|
|
|
std::cerr << "Error: No home path supplied with \'--home'.\n";
|
2019-08-16 07:47:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
if(!Utils::FileSystem::exists(argv[i + 1])) {
|
|
|
|
std::cerr << "Error: Home path \'" << argv[i + 1] << "\' does not exist.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(Utils::FileSystem::isRegularFile(argv[i + 1])) {
|
|
|
|
std::cerr << "Error: Home path \'" << argv[i + 1] <<
|
|
|
|
"\' is a file and not a directory.\n";
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-16 07:47:37 +00:00
|
|
|
Utils::FileSystem::setHomePath(argv[i + 1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
for(int i = 1; i < argc; i++) {
|
|
|
|
// Skip past --home flag as we already processed it.
|
|
|
|
if (strcmp(argv[i], "--home") == 0) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(argv[i], "--resolution") == 0) {
|
|
|
|
if (i >= argc - 2) {
|
|
|
|
std::cerr << "Error: Invalid resolution values supplied.\n";
|
2014-06-25 16:29:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-01 17:42:27 +00:00
|
|
|
int width = atoi(argv[i + 1]);
|
|
|
|
int height = atoi(argv[i + 2]);
|
2014-06-25 16:29:58 +00:00
|
|
|
i += 2; // skip the argument value
|
2017-12-01 17:42:27 +00:00
|
|
|
Settings::getInstance()->setInt("WindowWidth", width);
|
|
|
|
Settings::getInstance()->setInt("WindowHeight", height);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--screensize") == 0) {
|
|
|
|
if (i >= argc - 2) {
|
|
|
|
std::cerr << "Error: Invalid screensize values supplied.\n";
|
2017-12-01 17:42:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = atoi(argv[i + 1]);
|
|
|
|
int height = atoi(argv[i + 2]);
|
|
|
|
i += 2; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("ScreenWidth", width);
|
|
|
|
Settings::getInstance()->setInt("ScreenHeight", height);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--screenoffset") == 0) {
|
|
|
|
if (i >= argc - 2) {
|
|
|
|
std::cerr << "Error: Invalid screenoffset values supplied.\n";
|
2017-12-01 17:42:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x = atoi(argv[i + 1]);
|
|
|
|
int y = atoi(argv[i + 2]);
|
|
|
|
i += 2; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("ScreenOffsetX", x);
|
|
|
|
Settings::getInstance()->setInt("ScreenOffsetY", y);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--screenrotate") == 0) {
|
|
|
|
if (i >= argc - 1) {
|
|
|
|
std::cerr << "Error: Invalid screenrotate value supplied.\n";
|
2018-01-18 17:30:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rotate = atoi(argv[i + 1]);
|
|
|
|
++i; // skip the argument value
|
|
|
|
Settings::getInstance()->setInt("ScreenRotate", rotate);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--max-vram") == 0) {
|
|
|
|
if (i >= argc - 1) {
|
|
|
|
std::cerr << "Error: Invalid VRAM value supplied.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int maxVRAM = atoi(argv[i + 1]);
|
|
|
|
Settings::getInstance()->setInt("MaxVRAM", maxVRAM);
|
|
|
|
++i; // skip the argument value
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--gamelist-only") == 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
Settings::getInstance()->setBool("ParseGamelistOnly", true);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--ignore-gamelist") == 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
Settings::getInstance()->setBool("IgnoreGamelist", true);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--show-hidden-files") == 0) {
|
2017-08-02 19:56:33 +00:00
|
|
|
Settings::getInstance()->setBool("ShowHiddenFiles", true);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--draw-framerate") == 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
Settings::getInstance()->setBool("DrawFramerate", true);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--no-exit") == 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
Settings::getInstance()->setBool("ShowExit", false);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--no-splash") == 0) {
|
2017-01-12 19:17:53 +00:00
|
|
|
Settings::getInstance()->setBool("SplashScreen", false);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--debug") == 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
Settings::getInstance()->setBool("Debug", true);
|
2014-11-25 02:49:11 +00:00
|
|
|
Settings::getInstance()->setBool("HideConsole", false);
|
2014-06-25 16:29:58 +00:00
|
|
|
Log::setReportingLevel(LogDebug);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--fullscreen-normal") == 0) {
|
2020-05-15 15:51:32 +00:00
|
|
|
Settings::getInstance()->setString("FullscreenMode", "normal");
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--fullscreen-borderless") == 0) {
|
2020-05-15 15:51:32 +00:00
|
|
|
Settings::getInstance()->setString("FullscreenMode", "borderless");
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--windowed") == 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
Settings::getInstance()->setBool("Windowed", true);
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--vsync") == 0) {
|
|
|
|
bool vsync = (strcmp(argv[i + 1], "on") == 0 ||
|
|
|
|
strcmp(argv[i + 1], "1") == 0) ? true : false;
|
2014-11-23 15:52:37 +00:00
|
|
|
Settings::getInstance()->setBool("VSync", vsync);
|
2020-05-25 19:34:42 +00:00
|
|
|
i++; // Skip vsync value.
|
2017-09-08 14:49:47 +00:00
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
else if (strcmp(argv[i], "--force-kiosk") == 0) {
|
2017-09-08 14:49:47 +00:00
|
|
|
Settings::getInstance()->setBool("ForceKiosk", true);
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
else if (strcmp(argv[i], "--force-kid") == 0) {
|
2017-09-08 13:20:07 +00:00
|
|
|
Settings::getInstance()->setBool("ForceKid", true);
|
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
else if (strcmp(argv[i], "--force-disable-filters") == 0) {
|
2018-05-10 20:08:04 +00:00
|
|
|
Settings::getInstance()->setBool("ForceDisableFilters", true);
|
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-v") == 0) {
|
|
|
|
std::cout <<
|
|
|
|
"EmulationStation Desktop Edition v" << PROGRAM_VERSION_STRING << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
2014-11-25 03:08:22 +00:00
|
|
|
#ifdef WIN32
|
2020-05-25 19:34:42 +00:00
|
|
|
// This is a bit of a hack, but otherwise output will go to nowhere when the
|
|
|
|
// application is compiled with the "WINDOWS" subsystem (which we usually are).
|
2014-11-25 03:08:22 +00:00
|
|
|
// If you're an experienced Windows programmer and know how to do this
|
|
|
|
// the right way, please submit a pull request!
|
|
|
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
|
|
|
freopen("CONOUT$", "wb", stdout);
|
|
|
|
#endif
|
2017-08-02 19:56:33 +00:00
|
|
|
std::cout <<
|
2020-05-25 19:34:42 +00:00
|
|
|
"EmulationStation Desktop Edition\n"
|
|
|
|
"An Emulator Front-end\n\n"
|
|
|
|
"Options:\n"
|
|
|
|
"--resolution [width] [height] Try to force a particular resolution\n"
|
|
|
|
"--gamelist-only Skip automatic game ROM search, only read from gamelist.xml\n"
|
|
|
|
"--ignore-gamelist Ignore the gamelist files (useful for troubleshooting)\n"
|
|
|
|
"--draw-framerate Display the framerate\n"
|
|
|
|
"--no-exit Don't show the exit option in the menu\n"
|
|
|
|
"--no-splash Don't show the splash screen\n"
|
|
|
|
#ifdef WIN32
|
|
|
|
"--debug Show console and print debug information\n"
|
|
|
|
#else
|
|
|
|
"--debug Print debug information\n"
|
|
|
|
#endif
|
|
|
|
"--windowed Windowed mode, should be combined with --resolution\n"
|
|
|
|
"--fullscreen-normal Normal fullscreen mode\n"
|
|
|
|
"--fullscreen-borderless Borderless fullscreen mode (always on top)\n"
|
|
|
|
"--vsync [1/on or 0/off] Turn vsync on or off (default is on)\n"
|
|
|
|
"--max-vram [size] Max VRAM to use in Mb before swapping\n"
|
|
|
|
" Set to at least 20 to avoid unpredictable behavior\n"
|
|
|
|
"--force-kid Force the UI mode to Kid\n"
|
|
|
|
"--force-kiosk Force the UI mode to Kiosk\n"
|
|
|
|
"--force-disable-filters Force the UI to ignore applied filters in gamelist\n"
|
|
|
|
"--home [path] Directory to use as home path\n"
|
|
|
|
"--version, -v Displays version information\n"
|
|
|
|
"--help, -h Summon a sentient, angry tuba\n";
|
|
|
|
return false; // Exit after printing help.
|
|
|
|
}
|
|
|
|
else {
|
2020-05-15 16:46:06 +00:00
|
|
|
std::string argv_unknown = argv[i];
|
2020-05-25 19:34:42 +00:00
|
|
|
std::cout << "Unknown option '" << argv_unknown << "'.\n";
|
2020-05-15 16:46:06 +00:00
|
|
|
std::cout << "Try 'emulationstation --help' for more information.\n";
|
2020-05-25 19:34:42 +00:00
|
|
|
return false; // Exit after printing message.
|
2020-05-15 16:46:06 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool verifyHomeFolderExists()
|
|
|
|
{
|
2020-05-25 19:34:42 +00:00
|
|
|
// Make sure the config directory exists.
|
2018-01-27 20:04:08 +00:00
|
|
|
std::string home = Utils::FileSystem::getHomePath();
|
2014-06-25 16:29:58 +00:00
|
|
|
std::string configDir = home + "/.emulationstation";
|
2020-05-25 19:34:42 +00:00
|
|
|
if (!Utils::FileSystem::exists(configDir)) {
|
2014-06-25 16:29:58 +00:00
|
|
|
std::cout << "Creating config directory \"" << configDir << "\"\n";
|
2018-01-09 22:55:09 +00:00
|
|
|
Utils::FileSystem::createDirectory(configDir);
|
2020-05-25 19:34:42 +00:00
|
|
|
if (!Utils::FileSystem::exists(configDir)) {
|
2014-06-25 16:29:58 +00:00
|
|
|
std::cerr << "Config directory could not be created!\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-18 17:49:47 +00:00
|
|
|
// Returns NO_ERRORS if everything is OK.
|
|
|
|
// Otherwise returns either NO_SYSTEMS_FILE or NO_ROMS.
|
|
|
|
unsigned int loadSystemConfigFile(std::string& errorMsg)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-05-25 19:34:42 +00:00
|
|
|
if (!SystemData::loadConfig()) {
|
2014-06-25 16:29:58 +00:00
|
|
|
LOG(LogError) << "Error while parsing systems configuration file!";
|
2020-06-18 17:49:47 +00:00
|
|
|
errorMsg = "COULDN'T FIND THE SYSTEMS CONFIGURATION FILE.\n"
|
|
|
|
"WILL ATTEMPT TO INSTALL A TEMPLATE ES_SYSTEMS.CFG FILE FROM "
|
|
|
|
"THE EMULATIONSTATION RESOURCES DIRECTORY.\n"
|
|
|
|
"PLEASE RESTART THE APPLICATION.";
|
|
|
|
return NO_SYSTEMS_FILE;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
if (SystemData::sSystemVector.size() == 0)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-05-25 19:34:42 +00:00
|
|
|
LOG(LogError) << "No systems found! Does at least one system have a game present? (check "
|
2020-06-18 17:49:47 +00:00
|
|
|
"that extensions match!)\n";
|
|
|
|
errorMsg = "THE SYSTEMS CONFIGURATION FILE EXISTS BUT NO GAME "
|
|
|
|
"ROM FILES WERE FOUND. PLEASE MAKE SURE THAT THE 'ROMDIRECTORY' "
|
|
|
|
"SETTING IN ES_SYSTEMS.CFG IS POINTING TO YOUR ROM DIRECTORY "
|
|
|
|
"AND THAT YOUR GAME ROMS ARE USING SUPPORTED FILE EXTENSIONS. "
|
|
|
|
"THIS IS THE CURRENTLY CONFIGURED ROM DIRECTORY:\n";
|
|
|
|
errorMsg += FileData::getROMDirectory();
|
|
|
|
return NO_ROMS;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 17:49:47 +00:00
|
|
|
return NO_ERRORS;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Called on exit, assuming we get far enough to have the log initialized.
|
2014-06-25 16:29:58 +00:00
|
|
|
void onExit()
|
|
|
|
{
|
|
|
|
Log::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2016-12-20 20:25:35 +00:00
|
|
|
srand((unsigned int)time(NULL));
|
|
|
|
|
2017-11-09 22:08:51 +00:00
|
|
|
std::locale::global(std::locale("C"));
|
2014-10-18 21:31:10 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
if (!parseArgs(argc, argv))
|
2014-06-25 16:29:58 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Only show the console on Windows if HideConsole is false.
|
2014-11-25 02:49:11 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
// MSVC has a "SubSystem" option, with two primary options: "WINDOWS" and "CONSOLE".
|
2017-08-02 19:56:33 +00:00
|
|
|
// In "WINDOWS" mode, no console is automatically created for us. This is good,
|
|
|
|
// because we can choose to only create the console window if the user explicitly
|
2014-11-25 02:49:11 +00:00
|
|
|
// asks for it, preventing it from flashing open and then closing.
|
|
|
|
// In "CONSOLE" mode, a console is always automatically created for us before we
|
|
|
|
// enter main. In this case, we can only hide the console after the fact, which
|
|
|
|
// will leave a brief flash.
|
|
|
|
// TL;DR: You should compile ES under the "WINDOWS" subsystem.
|
|
|
|
// I have no idea how this works with non-MSVC compilers.
|
2020-05-25 19:34:42 +00:00
|
|
|
if (!Settings::getInstance()->getBool("HideConsole")) {
|
|
|
|
// We want to show the console.
|
|
|
|
// If we're compiled in "CONSOLE" mode, this is already done.
|
|
|
|
// If we're compiled in "WINDOWS" mode, no console is created for us automatically;
|
|
|
|
// the user asked for one, so make one and then hook stdin/stdout/sterr up to it.
|
|
|
|
if (AllocConsole()) { // Should only pass in "WINDOWS" mode.
|
2014-11-25 02:49:11 +00:00
|
|
|
freopen("CONIN$", "r", stdin);
|
|
|
|
freopen("CONOUT$", "wb", stdout);
|
|
|
|
freopen("CONOUT$", "wb", stderr);
|
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We want to hide the console.
|
|
|
|
// If we're compiled with the "WINDOWS" subsystem, this is already done.
|
|
|
|
// If we're compiled with the "CONSOLE" subsystem, a console is already created;
|
|
|
|
// it'll flash open, but we hide it nearly immediately.
|
|
|
|
if (GetConsoleWindow()) // Should only pass in "CONSOLE" mode.
|
2014-11-25 02:49:11 +00:00
|
|
|
ShowWindow(GetConsoleWindow(), SW_HIDE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Call this ONLY when linking with FreeImage as a static library.
|
2017-10-17 20:05:12 +00:00
|
|
|
#ifdef FREEIMAGE_LIB
|
|
|
|
FreeImage_Initialise();
|
|
|
|
#endif
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// If ~/.emulationstation doesn't exist and cannot be created, bail.
|
|
|
|
if (!verifyHomeFolderExists())
|
2014-06-25 16:29:58 +00:00
|
|
|
return 1;
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Start the logger.
|
2017-08-01 10:34:49 +00:00
|
|
|
Log::init();
|
2014-06-25 16:29:58 +00:00
|
|
|
Log::open();
|
2020-05-25 19:34:42 +00:00
|
|
|
LOG(LogInfo) << "EmulationStation - v" << PROGRAM_VERSION_STRING <<
|
|
|
|
", built " << PROGRAM_BUILT_STRING;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Always close the log on exit.
|
2014-06-25 16:29:58 +00:00
|
|
|
atexit(&onExit);
|
|
|
|
|
|
|
|
Window window;
|
2016-12-14 08:30:54 +00:00
|
|
|
SystemScreenSaver screensaver(&window);
|
2017-07-20 07:07:02 +00:00
|
|
|
PowerSaver::init();
|
2014-06-25 16:29:58 +00:00
|
|
|
ViewController::init(&window);
|
2017-06-12 16:38:59 +00:00
|
|
|
CollectionSystemManager::init(&window);
|
2018-02-09 17:23:58 +00:00
|
|
|
MameNames::init();
|
2014-06-25 16:29:58 +00:00
|
|
|
window.pushGui(ViewController::get());
|
|
|
|
|
2019-01-31 20:19:34 +00:00
|
|
|
bool splashScreen = Settings::getInstance()->getBool("SplashScreen");
|
|
|
|
bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress");
|
|
|
|
|
2020-06-09 18:03:31 +00:00
|
|
|
if (!window.init()) {
|
|
|
|
LOG(LogError) << "Window failed to initialize!";
|
|
|
|
return 1;
|
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
|
2020-06-09 18:03:31 +00:00
|
|
|
if (splashScreen) {
|
|
|
|
std::string progressText = "Loading...";
|
|
|
|
if (splashScreenProgress)
|
|
|
|
progressText = "Loading system config...";
|
|
|
|
window.renderLoadingScreen(progressText);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 17:49:47 +00:00
|
|
|
std::string errorMsg;
|
|
|
|
|
|
|
|
if (loadSystemConfigFile(errorMsg) != NO_ERRORS) {
|
2020-05-25 19:34:42 +00:00
|
|
|
// Something went terribly wrong.
|
2020-06-18 17:49:47 +00:00
|
|
|
if (errorMsg == "")
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
LOG(LogError) << "Unknown error occured while parsing system config file.";
|
2020-06-09 18:03:31 +00:00
|
|
|
Renderer::deinit();
|
2014-06-25 16:29:58 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-06-07 18:09:02 +00:00
|
|
|
HelpStyle helpStyle = HelpStyle();
|
2020-06-18 17:49:47 +00:00
|
|
|
|
|
|
|
if (errorMsg == "")
|
|
|
|
helpStyle.applyTheme(ViewController::get()->
|
|
|
|
getState().getSystem()->getTheme(), "system");
|
2020-06-07 18:09:02 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// We can't handle es_systems.cfg file problems inside ES itself,
|
|
|
|
// so display the error message and then quit.
|
2020-06-07 18:09:02 +00:00
|
|
|
window.pushGui(new GuiMsgBox(&window, helpStyle,
|
2020-06-18 17:49:47 +00:00
|
|
|
errorMsg.c_str(),
|
2017-08-02 19:56:33 +00:00
|
|
|
"QUIT", [] {
|
2014-06-25 16:29:58 +00:00
|
|
|
SDL_Event* quit = new SDL_Event();
|
|
|
|
quit->type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(quit);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-06-18 17:49:47 +00:00
|
|
|
std::vector<HelpPrompt> prompts;
|
|
|
|
prompts.push_back(HelpPrompt("a", "Quit"));
|
|
|
|
window.setHelpPrompts(prompts, HelpStyle());
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Dont generate joystick events while we're loading.
|
|
|
|
// (Hopefully fixes "automatically started emulator" bug.)
|
2014-06-25 16:29:58 +00:00
|
|
|
SDL_JoystickEventState(SDL_DISABLE);
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Preload what we can right away instead of waiting for the user to select it.
|
|
|
|
// This makes for no delays when accessing content, but a longer startup time.
|
2014-06-25 16:29:58 +00:00
|
|
|
ViewController::get()->preload();
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
if (splashScreen && splashScreenProgress)
|
2019-01-31 20:19:34 +00:00
|
|
|
window.renderLoadingScreen("Done.");
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Choose which GUI to open depending on if an input configuration already exists.
|
2020-06-18 17:49:47 +00:00
|
|
|
if (errorMsg == "") {
|
2020-05-25 19:34:42 +00:00
|
|
|
if (Utils::FileSystem::exists(InputManager::getConfigPath()) &&
|
|
|
|
InputManager::getInstance()->getNumConfiguredDevices() > 0) {
|
2014-06-25 16:29:58 +00:00
|
|
|
ViewController::get()->goToStart();
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.pushGui(new GuiDetectDevice(&window, true, [] {
|
|
|
|
ViewController::get()->goToStart(); }));
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Generate joystick events since we're done loading.
|
2014-06-25 16:29:58 +00:00
|
|
|
SDL_JoystickEventState(SDL_ENABLE);
|
|
|
|
|
|
|
|
int lastTime = SDL_GetTicks();
|
2017-07-20 07:07:02 +00:00
|
|
|
int ps_time = SDL_GetTicks();
|
2017-08-02 19:56:33 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
bool running = true;
|
2017-07-20 07:07:02 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
while (running) {
|
2014-06-25 16:29:58 +00:00
|
|
|
SDL_Event event;
|
2020-05-25 19:34:42 +00:00
|
|
|
bool ps_standby = PowerSaver::getState() && (int) SDL_GetTicks() -
|
|
|
|
ps_time > PowerSaver::getMode();
|
2017-08-02 19:56:33 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
if (ps_standby ? SDL_WaitEventTimeout(&event, PowerSaver::getTimeout())
|
|
|
|
: SDL_PollEvent(&event)) {
|
|
|
|
do {
|
2017-11-08 22:22:15 +00:00
|
|
|
InputManager::getInstance()->parseEvent(event, &window);
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
if (event.type == SDL_QUIT)
|
2017-11-08 22:22:15 +00:00
|
|
|
running = false;
|
2020-05-25 19:34:42 +00:00
|
|
|
}
|
|
|
|
while (SDL_PollEvent(&event));
|
2017-08-02 19:56:33 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Triggered if exiting from SDL_WaitEvent due to event.
|
2017-07-20 07:07:02 +00:00
|
|
|
if (ps_standby)
|
2020-05-25 19:34:42 +00:00
|
|
|
// Show as if continuing from last event.
|
2017-07-20 07:07:02 +00:00
|
|
|
lastTime = SDL_GetTicks();
|
2017-08-02 19:56:33 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Reset counter.
|
2017-07-20 07:07:02 +00:00
|
|
|
ps_time = SDL_GetTicks();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2020-05-25 19:34:42 +00:00
|
|
|
else if (ps_standby) {
|
|
|
|
// If exiting SDL_WaitEventTimeout due to timeout.
|
|
|
|
// Trail considering timeout as an event.
|
2017-08-11 17:03:12 +00:00
|
|
|
ps_time = SDL_GetTicks();
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
if (window.isSleeping()) {
|
2014-06-25 16:29:58 +00:00
|
|
|
lastTime = SDL_GetTicks();
|
2020-05-25 19:34:42 +00:00
|
|
|
// This doesn't need to be accurate, we're just giving up
|
|
|
|
// our CPU time until something wakes us up.
|
2014-06-25 16:29:58 +00:00
|
|
|
continue;
|
2020-05-25 19:34:42 +00:00
|
|
|
SDL_Delay(1);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int curTime = SDL_GetTicks();
|
|
|
|
int deltaTime = curTime - lastTime;
|
|
|
|
lastTime = curTime;
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Cap deltaTime if it ever goes negative.
|
|
|
|
if (deltaTime < 0)
|
2014-06-25 16:29:58 +00:00
|
|
|
deltaTime = 1000;
|
|
|
|
|
|
|
|
window.update(deltaTime);
|
|
|
|
window.render();
|
|
|
|
Renderer::swapBuffers();
|
|
|
|
|
|
|
|
Log::flush();
|
|
|
|
}
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
while (window.peekGui() != ViewController::get())
|
2014-06-25 16:29:58 +00:00
|
|
|
delete window.peekGui();
|
|
|
|
window.deinit();
|
|
|
|
|
2018-02-09 17:23:58 +00:00
|
|
|
MameNames::deinit();
|
2017-07-18 09:45:50 +00:00
|
|
|
CollectionSystemManager::deinit();
|
2014-06-25 16:29:58 +00:00
|
|
|
SystemData::deleteSystems();
|
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// Call this ONLY when linking with FreeImage as a static library.
|
2017-10-17 20:05:12 +00:00
|
|
|
#ifdef FREEIMAGE_LIB
|
|
|
|
FreeImage_DeInitialise();
|
|
|
|
#endif
|
|
|
|
|
2019-08-14 23:50:23 +00:00
|
|
|
processQuitMode();
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
LOG(LogInfo) << "EmulationStation cleanly shutting down.";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|