2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-11-04 09:56:22 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-11-01 15:19:01 +00:00
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// NativeApp implementation for platforms that will use that framework, like:
|
|
|
|
// Android, Linux, MacOSX.
|
|
|
|
//
|
|
|
|
// Native is a cross platform framework. It's not very mature and mostly
|
|
|
|
// just built according to the needs of my own apps.
|
|
|
|
//
|
|
|
|
// Windows has its own code that bypasses the framework entirely.
|
|
|
|
|
2017-02-24 19:50:27 +00:00
|
|
|
#include "ppsspp_config.h"
|
2013-04-13 19:24:07 +00:00
|
|
|
|
|
|
|
// Background worker threads should be spawned in NativeInit and joined
|
|
|
|
// in NativeShutdown.
|
|
|
|
|
2013-04-25 08:41:43 +00:00
|
|
|
#include <locale.h>
|
2014-04-26 06:32:43 +00:00
|
|
|
#include <algorithm>
|
2021-01-30 16:08:29 +00:00
|
|
|
#include <cstdlib>
|
2014-11-25 19:58:19 +00:00
|
|
|
#include <memory>
|
2017-02-27 20:57:46 +00:00
|
|
|
#include <mutex>
|
2018-09-01 20:57:20 +00:00
|
|
|
#include <thread>
|
2014-04-26 06:32:43 +00:00
|
|
|
|
2014-06-18 05:36:49 +00:00
|
|
|
#if defined(_WIN32)
|
2017-06-27 09:46:10 +00:00
|
|
|
#include "Windows/WindowsAudio.h"
|
2015-09-19 11:14:05 +00:00
|
|
|
#include "Windows/MainWindow.h"
|
2020-01-14 09:15:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
2020-01-13 07:06:02 +00:00
|
|
|
#include "Windows/CaptureDevice.h"
|
2013-12-07 17:06:15 +00:00
|
|
|
#endif
|
2013-04-13 19:24:07 +00:00
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/Net/HTTPClient.h"
|
|
|
|
#include "Common/Net/Resolve.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/Render/TextureAtlas.h"
|
2020-10-04 22:05:28 +00:00
|
|
|
#include "Common/Render/Text/draw_text.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/OpenGL/GLFeatures.h"
|
|
|
|
#include "Common/GPU/thin3d.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/UI/UI.h"
|
|
|
|
#include "Common/UI/Screen.h"
|
|
|
|
#include "Common/UI/Context.h"
|
|
|
|
#include "Common/UI/View.h"
|
2020-08-15 17:01:16 +00:00
|
|
|
#include "android/jni/app-android.h"
|
|
|
|
|
2020-10-04 08:30:18 +00:00
|
|
|
#include "Common/System/Display.h"
|
|
|
|
#include "Common/System/System.h"
|
|
|
|
#include "Common/System/NativeApp.h"
|
|
|
|
#include "Common/Data/Text/I18n.h"
|
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
#include "Common/Math/fast/fast_math.h"
|
|
|
|
#include "Common/Math/math_util.h"
|
|
|
|
#include "Common/Math/lin/matrix4x4.h"
|
|
|
|
#include "Common/Profiler/Profiler.h"
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
|
|
|
#include "Common/File/VFS/VFS.h"
|
|
|
|
#include "Common/File/VFS/AssetReader.h"
|
2014-03-22 08:26:28 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/FileUtil.h"
|
2020-09-29 10:19:22 +00:00
|
|
|
#include "Common/TimeUtil.h"
|
|
|
|
#include "Common/StringUtils.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Common/LogManager.h"
|
2014-12-20 16:31:56 +00:00
|
|
|
#include "Common/MemArena.h"
|
2015-12-31 16:25:48 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2020-01-13 07:06:02 +00:00
|
|
|
#include "Common/OSVersion.h"
|
2021-01-04 22:51:34 +00:00
|
|
|
#include "Common/GPU/ShaderTranslation.h"
|
2020-08-15 17:01:16 +00:00
|
|
|
|
2021-07-08 19:30:23 +00:00
|
|
|
#include "Core/ControlMapper.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Core/Config.h"
|
2018-06-17 01:42:31 +00:00
|
|
|
#include "Core/ConfigValues.h"
|
2014-06-22 12:17:57 +00:00
|
|
|
#include "Core/Core.h"
|
2015-06-28 01:32:21 +00:00
|
|
|
#include "Core/FileLoaders/DiskCachingFileLoader.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Core/Host.h"
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Core/KeyMap.h"
|
2016-09-29 05:35:09 +00:00
|
|
|
#include "Core/Reporting.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Core/SaveState.h"
|
2014-12-21 07:14:46 +00:00
|
|
|
#include "Core/Screenshot.h"
|
2013-12-29 23:11:29 +00:00
|
|
|
#include "Core/System.h"
|
2015-01-11 11:02:49 +00:00
|
|
|
#include "Core/HLE/__sceAudio.h"
|
2013-12-29 23:11:29 +00:00
|
|
|
#include "Core/HLE/sceCtrl.h"
|
2017-08-20 18:03:06 +00:00
|
|
|
#include "Core/HLE/sceUsbCam.h"
|
|
|
|
#include "Core/HLE/sceUsbGps.h"
|
2016-10-23 17:49:12 +00:00
|
|
|
#include "Core/HLE/proAdhoc.h"
|
2013-11-20 13:42:48 +00:00
|
|
|
#include "Core/Util/GameManager.h"
|
2015-01-11 21:50:52 +00:00
|
|
|
#include "Core/Util/AudioFormat.h"
|
2018-04-21 20:51:18 +00:00
|
|
|
#include "Core/WebServer.h"
|
2020-11-27 23:12:06 +00:00
|
|
|
#include "Core/ThreadPools.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2020-08-15 17:01:16 +00:00
|
|
|
#include "GPU/GPUInterface.h"
|
2020-05-09 20:52:04 +00:00
|
|
|
#include "UI/BackgroundAudio.h"
|
|
|
|
#include "UI/ControlMappingScreen.h"
|
|
|
|
#include "UI/DiscordIntegration.h"
|
2016-09-29 05:35:09 +00:00
|
|
|
#include "UI/EmuScreen.h"
|
|
|
|
#include "UI/GameInfoCache.h"
|
2020-05-09 20:52:04 +00:00
|
|
|
#include "UI/GPUDriverTestScreen.h"
|
2016-09-29 05:35:09 +00:00
|
|
|
#include "UI/HostTypes.h"
|
2013-10-17 14:15:04 +00:00
|
|
|
#include "UI/MiscScreens.h"
|
2020-05-09 20:52:04 +00:00
|
|
|
#include "UI/OnScreenDisplay.h"
|
2017-12-11 02:30:28 +00:00
|
|
|
#include "UI/RemoteISOScreen.h"
|
2013-11-11 11:52:04 +00:00
|
|
|
#include "UI/TiltEventProcessor.h"
|
2016-12-27 21:26:49 +00:00
|
|
|
#include "UI/TextureUtil.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
|
2018-03-03 07:46:12 +00:00
|
|
|
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
|
|
|
|
#include "Qt/QtHost.h"
|
|
|
|
#endif
|
2018-06-09 18:34:12 +00:00
|
|
|
#if defined(USING_QT_UI)
|
|
|
|
#include <QFontDatabase>
|
|
|
|
#endif
|
2019-06-06 21:16:27 +00:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
#include <dwrite_3.h>
|
|
|
|
#endif
|
2021-02-28 12:44:35 +00:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
|
|
|
#include "android/jni/app-android.h"
|
|
|
|
#endif
|
2018-03-03 07:46:12 +00:00
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
// The new UI framework, for initialization
|
|
|
|
|
|
|
|
static UI::Theme ui_theme;
|
|
|
|
|
2020-02-29 20:51:14 +00:00
|
|
|
Atlas g_ui_atlas;
|
|
|
|
|
2020-08-29 15:45:50 +00:00
|
|
|
#if PPSSPP_ARCH(ARM) && defined(__ANDROID__)
|
2013-03-30 20:14:18 +00:00
|
|
|
#include "../../android/jni/ArmEmitterTest.h"
|
2020-08-29 15:45:50 +00:00
|
|
|
#elif PPSSPP_ARCH(ARM64) && defined(__ANDROID__)
|
2015-03-21 18:22:24 +00:00
|
|
|
#include "../../android/jni/Arm64EmitterTest.h"
|
2013-03-21 19:52:33 +00:00
|
|
|
#endif
|
2012-11-23 18:41:35 +00:00
|
|
|
|
2021-03-03 04:57:25 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2013-06-25 21:18:16 +00:00
|
|
|
#include "ios/iOSCoreAudio.h"
|
2013-12-07 05:06:12 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <mach-o/dyld.h>
|
2013-06-25 21:18:16 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
ScreenManager *screenManager;
|
2012-11-01 15:19:01 +00:00
|
|
|
std::string config_filename;
|
|
|
|
|
2013-06-22 20:27:59 +00:00
|
|
|
// Really need to clean this mess of globals up... but instead I add more :P
|
|
|
|
bool g_TakeScreenshot;
|
2013-10-31 10:06:54 +00:00
|
|
|
static bool isOuya;
|
2014-12-25 16:41:12 +00:00
|
|
|
static bool resized = false;
|
2017-04-15 23:30:37 +00:00
|
|
|
static bool restarting = false;
|
2014-02-13 16:47:02 +00:00
|
|
|
|
2018-09-07 01:31:09 +00:00
|
|
|
static int renderCounter = 0;
|
2018-03-24 11:51:54 +00:00
|
|
|
|
2014-02-13 16:47:02 +00:00
|
|
|
struct PendingMessage {
|
|
|
|
std::string msg;
|
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
2020-03-09 02:54:24 +00:00
|
|
|
struct PendingInputBox {
|
|
|
|
std::function<void(bool, const std::string &)> cb;
|
|
|
|
bool result;
|
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
2017-02-27 20:57:46 +00:00
|
|
|
static std::mutex pendingMutex;
|
2014-02-13 16:47:02 +00:00
|
|
|
static std::vector<PendingMessage> pendingMessages;
|
2020-03-09 02:54:24 +00:00
|
|
|
static std::vector<PendingInputBox> pendingInputBoxes;
|
2017-01-30 13:33:38 +00:00
|
|
|
static Draw::DrawContext *g_draw;
|
2016-12-26 12:42:53 +00:00
|
|
|
static Draw::Pipeline *colorPipeline;
|
|
|
|
static Draw::Pipeline *texColorPipeline;
|
2013-03-30 18:23:20 +00:00
|
|
|
static UIContext *uiContext;
|
2013-03-29 19:51:14 +00:00
|
|
|
|
2015-01-11 20:00:56 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
WindowsAudioBackend *winAudioBackend;
|
|
|
|
#endif
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
std::thread *graphicsLoadThread;
|
2013-03-29 19:51:14 +00:00
|
|
|
|
2020-08-15 17:01:16 +00:00
|
|
|
class PrintfLogger : public LogListener {
|
2012-11-01 15:19:01 +00:00
|
|
|
public:
|
2017-03-18 09:47:10 +00:00
|
|
|
void Log(const LogMessage &message) override {
|
|
|
|
// Log with simplified headers as Android already provides timestamp etc.
|
|
|
|
switch (message.level) {
|
2013-03-11 05:31:47 +00:00
|
|
|
case LogTypes::LVERBOSE:
|
2012-11-04 09:56:22 +00:00
|
|
|
case LogTypes::LDEBUG:
|
|
|
|
case LogTypes::LINFO:
|
2020-08-15 17:01:16 +00:00
|
|
|
printf("INFO [%s] %s", message.log, message.msg.c_str());
|
2012-11-04 09:56:22 +00:00
|
|
|
break;
|
|
|
|
case LogTypes::LERROR:
|
2020-08-15 17:01:16 +00:00
|
|
|
printf("ERR [%s] %s", message.log, message.msg.c_str());
|
2012-11-04 09:56:22 +00:00
|
|
|
break;
|
|
|
|
case LogTypes::LWARNING:
|
2020-08-15 17:01:16 +00:00
|
|
|
printf("WARN [%s] %s", message.log, message.msg.c_str());
|
2012-11-04 09:56:22 +00:00
|
|
|
break;
|
|
|
|
case LogTypes::LNOTICE:
|
|
|
|
default:
|
2020-08-15 17:01:16 +00:00
|
|
|
printf("NOTE [%s] !!! %s", message.log, message.msg.c_str());
|
2012-11-04 09:56:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
2014-06-22 12:17:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
int Win32Mix(short *buffer, int numSamples, int bits, int rate, int channels) {
|
|
|
|
return NativeMix(buffer, numSamples);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// globals
|
2020-08-15 17:01:16 +00:00
|
|
|
static LogListener *logger = nullptr;
|
2021-05-09 16:38:48 +00:00
|
|
|
Path boot_filename;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2015-01-11 11:02:49 +00:00
|
|
|
void NativeHost::InitSound() {
|
2021-03-03 04:57:25 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2013-11-29 15:33:17 +00:00
|
|
|
iOSCoreAudioInit();
|
2013-06-25 21:18:16 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeHost::ShutdownSound() {
|
2021-03-03 04:57:25 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2013-11-29 15:33:17 +00:00
|
|
|
iOSCoreAudioShutdown();
|
2013-06-25 21:18:16 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-03-01 15:09:16 +00:00
|
|
|
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
|
2015-01-11 11:02:49 +00:00
|
|
|
void QtHost::InitSound() { }
|
|
|
|
void QtHost::ShutdownSound() { }
|
2014-03-01 15:09:16 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-04 11:09:14 +00:00
|
|
|
std::string NativeQueryConfig(std::string query) {
|
2014-07-18 19:49:54 +00:00
|
|
|
char temp[128];
|
2014-02-04 11:58:37 +00:00
|
|
|
if (query == "screenRotation") {
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(G3D, "g_Config.screenRotation = %d", g_Config.iScreenRotation);
|
2015-12-13 21:25:58 +00:00
|
|
|
snprintf(temp, sizeof(temp), "%d", g_Config.iScreenRotation);
|
2014-07-18 19:49:54 +00:00
|
|
|
return std::string(temp);
|
2014-02-09 22:16:08 +00:00
|
|
|
} else if (query == "immersiveMode") {
|
2014-07-18 19:49:54 +00:00
|
|
|
return std::string(g_Config.bImmersiveMode ? "1" : "0");
|
|
|
|
} else if (query == "hwScale") {
|
2014-07-18 22:42:22 +00:00
|
|
|
int scale = g_Config.iAndroidHwScale;
|
2018-10-06 11:43:11 +00:00
|
|
|
// Override hw scale for TV type devices.
|
|
|
|
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_TV)
|
|
|
|
scale = 0;
|
|
|
|
|
2014-07-18 22:42:22 +00:00
|
|
|
if (scale == 1) {
|
|
|
|
// If g_Config.iInternalResolution is also set to Auto (1), we fall back to "Device resolution" (0). It works out.
|
|
|
|
scale = g_Config.iInternalResolution;
|
|
|
|
} else if (scale >= 2) {
|
|
|
|
scale -= 1;
|
|
|
|
}
|
|
|
|
|
2015-01-29 23:28:53 +00:00
|
|
|
int max_res = std::max(System_GetPropertyInt(SYSPROP_DISPLAY_XRES), System_GetPropertyInt(SYSPROP_DISPLAY_YRES)) / 480 + 1;
|
2015-12-13 21:25:58 +00:00
|
|
|
snprintf(temp, sizeof(temp), "%d", std::min(scale, max_res));
|
2014-07-18 19:49:54 +00:00
|
|
|
return std::string(temp);
|
2016-07-01 18:06:06 +00:00
|
|
|
} else if (query == "androidJavaGL") {
|
|
|
|
// If we're using Vulkan, we say no... need C++ to use Vulkan.
|
|
|
|
if (GetGPUBackend() == GPUBackend::VULKAN) {
|
|
|
|
return "false";
|
|
|
|
}
|
|
|
|
// Otherwise, some devices prefer the Java init so play it safe.
|
|
|
|
return "true";
|
2017-08-16 08:23:27 +00:00
|
|
|
} else if (query == "sustainedPerformanceMode") {
|
|
|
|
return std::string(g_Config.bSustainedPerformanceMode ? "1" : "0");
|
2014-02-04 11:58:37 +00:00
|
|
|
} else {
|
2015-01-11 16:28:46 +00:00
|
|
|
return "";
|
2014-02-04 11:58:37 +00:00
|
|
|
}
|
2014-02-04 11:09:14 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
int NativeMix(short *audio, int num_samples) {
|
2015-01-29 13:58:03 +00:00
|
|
|
if (GetUIState() != UISTATE_INGAME) {
|
2020-08-02 17:44:48 +00:00
|
|
|
g_BackgroundAudio.Play();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2014-06-22 12:17:57 +00:00
|
|
|
|
2015-01-29 13:58:03 +00:00
|
|
|
int sample_rate = System_GetPropertyInt(SYSPROP_AUDIO_SAMPLE_RATE);
|
|
|
|
num_samples = __AudioMix(audio, num_samples, sample_rate > 0 ? sample_rate : 44100);
|
|
|
|
|
2014-06-22 12:17:57 +00:00
|
|
|
#ifdef _WIN32
|
2017-08-08 14:32:56 +00:00
|
|
|
winAudioBackend->Update();
|
2014-06-22 12:17:57 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-04 21:54:37 +00:00
|
|
|
return num_samples;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 11:09:14 +00:00
|
|
|
// This is called before NativeInit so we do a little bit of initialization here.
|
2014-12-18 21:43:54 +00:00
|
|
|
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape, std::string *version) {
|
2012-11-01 15:19:01 +00:00
|
|
|
*app_nice_name = "PPSSPP";
|
|
|
|
*app_dir_name = "ppsspp";
|
|
|
|
*landscape = true;
|
2014-12-18 21:43:54 +00:00
|
|
|
*version = PPSSPP_GIT_VERSION;
|
2012-11-23 18:41:35 +00:00
|
|
|
|
2020-08-29 15:45:50 +00:00
|
|
|
#if PPSSPP_ARCH(ARM) && defined(__ANDROID__)
|
2013-02-11 22:10:11 +00:00
|
|
|
ArmEmitterTest();
|
2020-08-29 15:45:50 +00:00
|
|
|
#elif PPSSPP_ARCH(ARM64) && defined(__ANDROID__)
|
2015-03-21 18:22:24 +00:00
|
|
|
Arm64EmitterTest();
|
2013-03-02 00:36:18 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 18:34:12 +00:00
|
|
|
#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
|
2018-04-29 18:45:32 +00:00
|
|
|
static bool CheckFontIsUsable(const wchar_t *fontFace) {
|
2015-10-04 22:11:36 +00:00
|
|
|
wchar_t actualFontFace[1024] = { 0 };
|
|
|
|
|
|
|
|
HFONT f = CreateFont(0, 0, 0, 0, FW_LIGHT, 0, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, fontFace);
|
|
|
|
if (f != nullptr) {
|
|
|
|
HDC hdc = CreateCompatibleDC(nullptr);
|
|
|
|
if (hdc != nullptr) {
|
|
|
|
SelectObject(hdc, f);
|
|
|
|
GetTextFace(hdc, 1024, actualFontFace);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
}
|
|
|
|
DeleteObject(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were able to get the font name, did it load?
|
|
|
|
if (actualFontFace[0] != 0) {
|
|
|
|
return wcsncmp(actualFontFace, fontFace, ARRAY_SIZE(actualFontFace)) == 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-29 18:45:32 +00:00
|
|
|
static void PostLoadConfig() {
|
|
|
|
// On Windows, we deal with currentDirectory in InitSysDirectories().
|
2021-05-29 22:20:41 +00:00
|
|
|
#if !PPSSPP_PLATFORM(WINDOWS)
|
2018-04-29 18:45:32 +00:00
|
|
|
if (g_Config.currentDirectory.empty()) {
|
2021-05-29 22:20:41 +00:00
|
|
|
g_Config.currentDirectory = g_Config.defaultCurrentDirectory;
|
2018-04-29 18:45:32 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to
|
|
|
|
// test new languages without recompiling the entire app, which is a hassle).
|
2021-05-05 23:31:38 +00:00
|
|
|
const Path langOverridePath = GetSysDirectory(DIRECTORY_SYSTEM) / "lang";
|
2018-04-29 18:45:32 +00:00
|
|
|
|
|
|
|
// If we run into the unlikely case that "lang" is actually a file, just use the built-in translations.
|
|
|
|
if (!File::Exists(langOverridePath) || !File::IsDirectory(langOverridePath))
|
|
|
|
i18nrepo.LoadIni(g_Config.sLanguageIni);
|
|
|
|
else
|
|
|
|
i18nrepo.LoadIni(g_Config.sLanguageIni, langOverridePath);
|
2020-11-27 23:12:06 +00:00
|
|
|
|
2021-06-12 19:06:59 +00:00
|
|
|
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
|
2018-04-29 18:45:32 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 20:55:43 +00:00
|
|
|
static bool CreateDirectoriesAndroid() {
|
2018-05-10 17:32:28 +00:00
|
|
|
// On Android, create a PSP directory tree in the external_dir,
|
|
|
|
// to hopefully reduce confusion a bit.
|
2021-05-29 20:55:43 +00:00
|
|
|
|
2021-06-06 22:49:31 +00:00
|
|
|
Path pspDir = g_Config.memStickDirectory;
|
|
|
|
if (pspDir.GetFilename() != "PSP") {
|
|
|
|
pspDir /= "PSP";
|
|
|
|
}
|
2021-05-29 20:55:43 +00:00
|
|
|
|
|
|
|
INFO_LOG(IO, "Creating '%s' and subdirs:", pspDir.c_str());
|
|
|
|
File::CreateFullPath(pspDir);
|
|
|
|
if (!File::Exists(pspDir)) {
|
|
|
|
INFO_LOG(IO, "Not a workable memstick directory. Giving up");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-02 17:27:11 +00:00
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_SAVEDATA));
|
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_SAVESTATE));
|
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_GAME));
|
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_SYSTEM));
|
2019-02-05 14:57:43 +00:00
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_TEXTURES));
|
2020-08-26 02:54:51 +00:00
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_PLUGINS));
|
2018-05-10 18:52:21 +00:00
|
|
|
|
2019-02-05 14:57:43 +00:00
|
|
|
// Avoid media scanners in PPSSPP_STATE and SAVEDATA directories,
|
|
|
|
// and in the root PSP directory as well.
|
2021-05-05 23:31:38 +00:00
|
|
|
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_SAVESTATE) / ".nomedia");
|
|
|
|
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_SAVEDATA) / ".nomedia");
|
|
|
|
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_SYSTEM) / ".nomedia");
|
|
|
|
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_TEXTURES) / ".nomedia");
|
|
|
|
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_PLUGINS) / ".nomedia");
|
2021-05-29 20:55:43 +00:00
|
|
|
return true;
|
2018-05-10 17:32:28 +00:00
|
|
|
}
|
|
|
|
|
2018-09-01 20:57:20 +00:00
|
|
|
static void CheckFailedGPUBackends() {
|
2018-10-08 11:33:21 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
// If you're in debug mode, you probably don't want a fallback. If you're in release mode, use IGNORE below.
|
2020-08-16 20:22:58 +00:00
|
|
|
NOTICE_LOG(LOADER, "Not checking for failed graphics backends in debug mode");
|
2018-10-08 11:33:21 +00:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2018-09-06 14:31:15 +00:00
|
|
|
// We only want to do this once per process run and backend, to detect process crashes.
|
|
|
|
// If NativeShutdown is called before we finish, we might call this multiple times.
|
|
|
|
static int lastBackend = -1;
|
|
|
|
if (lastBackend == g_Config.iGPUBackend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastBackend = g_Config.iGPUBackend;
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
Path cache = GetSysDirectory(DIRECTORY_APP_CACHE) / "FailedGraphicsBackends.txt";
|
2018-09-01 20:57:20 +00:00
|
|
|
|
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
std::string data;
|
2021-05-09 13:02:46 +00:00
|
|
|
if (File::ReadFileToString(true, cache, data))
|
2018-09-01 20:57:20 +00:00
|
|
|
g_Config.sFailedGPUBackends = data;
|
|
|
|
}
|
|
|
|
|
2018-09-01 21:16:39 +00:00
|
|
|
// Use this if you want to debug a graphics crash...
|
|
|
|
if (g_Config.sFailedGPUBackends == "IGNORE")
|
|
|
|
return;
|
2018-09-06 06:13:15 +00:00
|
|
|
else if (!g_Config.sFailedGPUBackends.empty())
|
|
|
|
ERROR_LOG(LOADER, "Failed graphics backends: %s", g_Config.sFailedGPUBackends.c_str());
|
2018-09-01 21:16:39 +00:00
|
|
|
|
2018-09-01 20:57:20 +00:00
|
|
|
// Okay, let's not try a backend in the failed list.
|
2018-09-06 14:31:15 +00:00
|
|
|
g_Config.iGPUBackend = g_Config.NextValidBackend();
|
2020-03-28 13:19:11 +00:00
|
|
|
if (lastBackend != g_Config.iGPUBackend) {
|
|
|
|
std::string param = GPUBackendToString((GPUBackend)lastBackend) + " -> " + GPUBackendToString((GPUBackend)g_Config.iGPUBackend);
|
|
|
|
System_SendMessage("graphics_failedBackend", param.c_str());
|
|
|
|
WARN_LOG(LOADER, "Failed graphics backend switched from %s (%d to %d)", param.c_str(), lastBackend, g_Config.iGPUBackend);
|
|
|
|
}
|
2018-09-01 20:57:20 +00:00
|
|
|
// And then let's - for now - add the current to the failed list.
|
|
|
|
if (g_Config.sFailedGPUBackends.empty()) {
|
2019-06-22 18:20:01 +00:00
|
|
|
g_Config.sFailedGPUBackends = GPUBackendToString((GPUBackend)g_Config.iGPUBackend);
|
2018-09-01 20:57:20 +00:00
|
|
|
} else if (g_Config.sFailedGPUBackends.find("ALL") == std::string::npos) {
|
2019-06-22 18:20:01 +00:00
|
|
|
g_Config.sFailedGPUBackends += "," + GPUBackendToString((GPUBackend)g_Config.iGPUBackend);
|
2018-09-01 20:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
// Let's try to create, in case it doesn't exist.
|
|
|
|
if (!File::Exists(GetSysDirectory(DIRECTORY_APP_CACHE)))
|
|
|
|
File::CreateDir(GetSysDirectory(DIRECTORY_APP_CACHE));
|
2021-05-09 13:02:46 +00:00
|
|
|
File::WriteStringToFile(true, g_Config.sFailedGPUBackends, cache);
|
2018-09-01 20:57:20 +00:00
|
|
|
} else {
|
|
|
|
// Just save immediately, since we have storage.
|
2019-02-23 09:49:49 +00:00
|
|
|
g_Config.Save("got storage permission");
|
2018-09-01 20:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearFailedGPUBackends() {
|
2018-09-01 21:16:39 +00:00
|
|
|
if (g_Config.sFailedGPUBackends == "IGNORE")
|
|
|
|
return;
|
|
|
|
|
2018-09-01 20:57:20 +00:00
|
|
|
// We've successfully started graphics without crashing, hurray.
|
|
|
|
// In case they update drivers and have totally different problems much later, clear the failed list.
|
|
|
|
g_Config.sFailedGPUBackends.clear();
|
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
2021-05-15 05:48:04 +00:00
|
|
|
File::Delete(GetSysDirectory(DIRECTORY_APP_CACHE) / "FailedGraphicsBackends.txt");
|
2018-09-01 20:57:20 +00:00
|
|
|
} else {
|
2019-02-23 09:49:49 +00:00
|
|
|
g_Config.Save("clearFailedGPUBackends");
|
2018-09-01 20:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-09 23:28:15 +00:00
|
|
|
void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir) {
|
2017-03-12 16:24:46 +00:00
|
|
|
net::Init(); // This needs to happen before we load the config. So on Windows we also run it in Main. It's fine to call multiple times.
|
2017-03-06 09:51:28 +00:00
|
|
|
|
2021-01-04 22:51:34 +00:00
|
|
|
ShaderTranslationInit();
|
|
|
|
|
2014-03-22 08:26:28 +00:00
|
|
|
InitFastMath(cpu_info.bNEON);
|
2015-01-11 21:50:52 +00:00
|
|
|
SetupAudioFormats();
|
2014-03-22 08:26:28 +00:00
|
|
|
|
2018-08-12 22:08:56 +00:00
|
|
|
g_Discord.SetPresenceMenu();
|
|
|
|
|
2017-08-08 13:58:25 +00:00
|
|
|
// Make sure UI state is MENU.
|
|
|
|
ResetUIState();
|
|
|
|
|
2013-07-27 11:07:34 +00:00
|
|
|
bool skipLogo = false;
|
2013-04-25 08:41:43 +00:00
|
|
|
setlocale( LC_ALL, "C" );
|
2016-01-17 21:11:28 +00:00
|
|
|
std::string user_data_path = savegame_dir;
|
2014-02-13 16:47:02 +00:00
|
|
|
pendingMessages.clear();
|
2020-03-09 02:54:24 +00:00
|
|
|
pendingInputBoxes.clear();
|
2013-07-09 21:27:25 +00:00
|
|
|
|
2021-05-29 22:20:41 +00:00
|
|
|
// external_dir has all kinds of meanings depending on platform.
|
|
|
|
// on iOS it's even the path to bundled app assets. It's a mess.
|
|
|
|
|
2013-07-09 21:27:25 +00:00
|
|
|
// We want this to be FIRST.
|
2021-03-03 04:57:25 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2013-07-09 21:27:25 +00:00
|
|
|
// Packed assets are included in app
|
2021-05-15 16:54:28 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(Path(external_dir)));
|
2017-03-19 15:21:54 +00:00
|
|
|
#endif
|
2020-12-06 01:49:21 +00:00
|
|
|
#if defined(ASSETS_DIR)
|
2021-05-15 16:54:28 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(Path(ASSETS_DIR)));
|
2020-12-06 01:49:21 +00:00
|
|
|
#endif
|
2019-09-28 16:23:18 +00:00
|
|
|
#if !defined(MOBILE_DEVICE) && !defined(_WIN32) && !PPSSPP_PLATFORM(SWITCH)
|
2021-05-15 16:59:25 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(File::GetExeDirectory() / "assets"));
|
|
|
|
VFSRegister("", new DirectoryAssetReader(File::GetExeDirectory()));
|
2021-05-15 16:54:28 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(Path("/usr/local/share/ppsspp/assets")));
|
|
|
|
VFSRegister("", new DirectoryAssetReader(Path("/usr/local/share/games/ppsspp/assets")));
|
|
|
|
VFSRegister("", new DirectoryAssetReader(Path("/usr/share/ppsspp/assets")));
|
|
|
|
VFSRegister("", new DirectoryAssetReader(Path("/usr/share/games/ppsspp/assets")));
|
2013-04-11 05:14:44 +00:00
|
|
|
#endif
|
2021-02-28 12:44:35 +00:00
|
|
|
|
2019-09-28 16:23:18 +00:00
|
|
|
#if PPSSPP_PLATFORM(SWITCH)
|
2021-05-15 16:54:28 +00:00
|
|
|
Path assetPath = Path(user_data_path) / "assets";
|
|
|
|
VFSRegister("", new DirectoryAssetReader(assetPath));
|
2019-09-28 16:23:18 +00:00
|
|
|
#else
|
2021-05-15 16:54:28 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(Path("assets")));
|
2019-09-28 16:23:18 +00:00
|
|
|
#endif
|
2021-05-15 16:54:28 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(Path(savegame_dir)));
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-05-05 13:53:48 +00:00
|
|
|
#if (defined(MOBILE_DEVICE) || !defined(USING_QT_UI)) && !PPSSPP_PLATFORM(UWP)
|
2017-04-29 19:02:07 +00:00
|
|
|
if (host == nullptr) {
|
|
|
|
host = new NativeHost();
|
|
|
|
}
|
2014-03-01 15:09:16 +00:00
|
|
|
#endif
|
2021-02-28 12:46:08 +00:00
|
|
|
|
2021-05-29 22:20:41 +00:00
|
|
|
g_Config.defaultCurrentDirectory = Path("/");
|
2021-05-15 16:32:41 +00:00
|
|
|
g_Config.internalDataDirectory = Path(savegame_dir);
|
2018-04-29 18:45:32 +00:00
|
|
|
|
2021-04-26 21:34:20 +00:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
2021-05-29 20:55:43 +00:00
|
|
|
// In Android 12 with scoped storage, due to the above, the external directory
|
|
|
|
// is no longer the plain root of external storage, but it's an app specific directory
|
|
|
|
// on external storage (g_extFilesDir).
|
2021-05-16 14:43:14 +00:00
|
|
|
if (System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
|
2021-05-29 20:55:43 +00:00
|
|
|
g_Config.defaultCurrentDirectory = Path(g_extFilesDir);
|
2021-05-16 14:43:14 +00:00
|
|
|
} else {
|
2021-05-29 20:55:43 +00:00
|
|
|
// Maybe there should be an option to use internal memory instead, but I think
|
|
|
|
// that for most people, using external memory (SDCard/USB Storage) makes the
|
|
|
|
// most sense.
|
|
|
|
g_Config.defaultCurrentDirectory = Path(external_dir);
|
2021-05-16 14:43:14 +00:00
|
|
|
}
|
2021-02-28 12:44:35 +00:00
|
|
|
|
2021-05-29 20:55:43 +00:00
|
|
|
// Might also add an option to move it to internal / non-visible storage, but there's
|
|
|
|
// little point, really.
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
g_Config.memStickDirectory = Path(external_dir);
|
|
|
|
g_Config.flash0Directory = Path(external_dir) / "flash0";
|
2019-02-18 17:15:15 +00:00
|
|
|
|
2021-05-15 16:32:41 +00:00
|
|
|
Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
|
2019-02-18 17:15:15 +00:00
|
|
|
if (File::Exists(memstickDirFile)) {
|
|
|
|
std::string memstickDir;
|
2021-05-16 14:43:14 +00:00
|
|
|
if (File::ReadFileToString(true, memstickDirFile, memstickDir)) {
|
|
|
|
Path memstickPath(memstickDir);
|
|
|
|
if (!memstickPath.empty() && File::Exists(memstickPath)) {
|
|
|
|
g_Config.memStickDirectory = memstickPath;
|
2021-05-29 20:55:43 +00:00
|
|
|
INFO_LOG(SYSTEM, "Memstick Directory from memstick_dir.txt: '%s'", g_Config.memStickDirectory.c_str());
|
2021-05-16 14:43:14 +00:00
|
|
|
} else {
|
|
|
|
ERROR_LOG(SYSTEM, "Couldn't read directory '%s' specified by memstick_dir.txt.", memstickDir.c_str());
|
2021-05-29 20:55:43 +00:00
|
|
|
if (System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
|
2021-06-06 22:49:31 +00:00
|
|
|
// TODO: Gotta resolve this somehow...
|
2021-06-07 20:49:53 +00:00
|
|
|
// I think we wanna pop up the memstick dir chooser before any other screen in this case.
|
|
|
|
// For now we just choose a default.
|
|
|
|
g_Config.memStickDirectory = g_Config.defaultCurrentDirectory;
|
2021-05-29 20:55:43 +00:00
|
|
|
}
|
2021-05-16 14:43:14 +00:00
|
|
|
}
|
2019-02-18 17:15:15 +00:00
|
|
|
}
|
2021-04-26 21:34:20 +00:00
|
|
|
} else {
|
|
|
|
INFO_LOG(SYSTEM, "No memstick directory file found. Using '%s'", memstickDirFile.c_str());
|
2019-02-18 17:15:15 +00:00
|
|
|
}
|
2021-04-24 20:47:57 +00:00
|
|
|
|
2021-03-03 04:57:25 +00:00
|
|
|
#elif PPSSPP_PLATFORM(IOS)
|
2021-05-30 00:32:22 +00:00
|
|
|
g_Config.defaultCurrentDirectory = g_Config.internalDataDirectory;
|
2021-05-09 13:25:12 +00:00
|
|
|
g_Config.memStickDirectory = Path(user_data_path);
|
|
|
|
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
|
2019-09-28 16:23:18 +00:00
|
|
|
#elif PPSSPP_PLATFORM(SWITCH)
|
2021-05-15 16:32:41 +00:00
|
|
|
g_Config.memStickDirectory = g_Config.internalDataDirectory / "config/ppsspp";
|
|
|
|
g_Config.flash0Directory = g_Config.internalDataDirectory / "assets/flash0";
|
2021-05-05 23:31:38 +00:00
|
|
|
#elif !PPSSPP_PLATFORM(WINDOWS)
|
2014-06-25 06:10:00 +00:00
|
|
|
std::string config;
|
|
|
|
if (getenv("XDG_CONFIG_HOME") != NULL)
|
|
|
|
config = getenv("XDG_CONFIG_HOME");
|
|
|
|
else if (getenv("HOME") != NULL)
|
|
|
|
config = getenv("HOME") + std::string("/.config");
|
|
|
|
else // Just in case
|
|
|
|
config = "./config";
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
g_Config.memStickDirectory = Path(config) / "ppsspp";
|
2021-05-15 16:59:25 +00:00
|
|
|
g_Config.flash0Directory = File::GetExeDirectory() / "assets/flash0";
|
2021-05-29 22:20:41 +00:00
|
|
|
if (getenv("HOME") != nullptr) {
|
|
|
|
g_Config.defaultCurrentDirectory = Path(getenv("HOME"));
|
|
|
|
} else {
|
|
|
|
// Hm, should probably actually explicitly set the current directory..
|
|
|
|
// Though it's not many platforms that'll land us here.
|
|
|
|
g_Config.currentDirectory = Path(".");
|
|
|
|
}
|
2013-10-12 23:02:03 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-27 21:10:08 +00:00
|
|
|
if (cache_dir && strlen(cache_dir)) {
|
2021-05-15 16:32:41 +00:00
|
|
|
g_Config.appCacheDirectory = Path(cache_dir);
|
|
|
|
DiskCachingFileLoaderCache::SetCacheDir(g_Config.appCacheDirectory);
|
2016-02-27 21:10:08 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 23:30:37 +00:00
|
|
|
if (!LogManager::GetInstance())
|
2020-08-15 16:40:50 +00:00
|
|
|
LogManager::Init(&g_Config.bEnableLogging);
|
2017-04-15 23:30:37 +00:00
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
#if !PPSSPP_PLATFORM(WINDOWS)
|
2021-05-30 10:45:12 +00:00
|
|
|
g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
|
2018-03-24 11:51:54 +00:00
|
|
|
|
|
|
|
// Note that if we don't have storage permission here, loading the config will
|
|
|
|
// fail and it will be set to the default. Later, we load again when we get permission.
|
2013-10-12 23:02:03 +00:00
|
|
|
g_Config.Load();
|
2013-04-01 01:22:27 +00:00
|
|
|
#endif
|
2021-05-30 10:45:12 +00:00
|
|
|
|
2016-01-10 12:08:19 +00:00
|
|
|
LogManager *logman = LogManager::GetInstance();
|
2012-12-25 07:34:19 +00:00
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
2019-09-17 08:50:25 +00:00
|
|
|
// On early versions of Android we don't need to ask permission.
|
2018-05-10 17:32:28 +00:00
|
|
|
CreateDirectoriesAndroid();
|
2013-06-19 11:13:23 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
const char *fileToLog = 0;
|
2021-05-05 23:31:38 +00:00
|
|
|
Path stateToLoad;
|
2012-12-26 23:18:45 +00:00
|
|
|
|
2017-11-21 11:22:38 +00:00
|
|
|
bool gotBootFilename = false;
|
2020-05-09 20:52:04 +00:00
|
|
|
bool gotoGameSettings = false;
|
|
|
|
bool gotoTouchScreenTest = false;
|
2021-05-09 16:38:48 +00:00
|
|
|
boot_filename.clear();
|
2017-11-21 11:22:38 +00:00
|
|
|
|
2012-11-04 10:31:06 +00:00
|
|
|
// Parse command line
|
|
|
|
LogTypes::LOG_LEVELS logLevel = LogTypes::LINFO;
|
2021-01-30 19:51:35 +00:00
|
|
|
bool forceLogLevel = false;
|
|
|
|
const auto setLogLevel = [&logLevel, &forceLogLevel](LogTypes::LOG_LEVELS level) {
|
|
|
|
logLevel = level;
|
|
|
|
forceLogLevel = true;
|
|
|
|
};
|
|
|
|
|
2012-11-04 10:31:06 +00:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (argv[i][0] == '-') {
|
|
|
|
switch (argv[i][1]) {
|
|
|
|
case 'd':
|
|
|
|
// Enable debug logging
|
2013-01-08 23:12:02 +00:00
|
|
|
// Note that you must also change the max log level in Log.h.
|
2021-01-30 19:51:35 +00:00
|
|
|
setLogLevel(LogTypes::LDEBUG);
|
2012-11-04 10:31:06 +00:00
|
|
|
break;
|
2016-09-10 15:16:53 +00:00
|
|
|
case 'v':
|
|
|
|
// Enable verbose logging
|
|
|
|
// Note that you must also change the max log level in Log.h.
|
2021-01-30 19:51:35 +00:00
|
|
|
setLogLevel(LogTypes::LVERBOSE);
|
2012-12-01 22:20:08 +00:00
|
|
|
break;
|
2012-12-05 06:55:24 +00:00
|
|
|
case 'j':
|
2017-03-02 11:36:54 +00:00
|
|
|
g_Config.iCpuCore = (int)CPUCore::JIT;
|
2012-12-25 07:34:19 +00:00
|
|
|
g_Config.bSaveSettings = false;
|
2012-12-22 17:49:59 +00:00
|
|
|
break;
|
2012-12-05 06:55:24 +00:00
|
|
|
case 'i':
|
2017-03-02 11:36:54 +00:00
|
|
|
g_Config.iCpuCore = (int)CPUCore::INTERPRETER;
|
2016-05-07 23:43:27 +00:00
|
|
|
g_Config.bSaveSettings = false;
|
|
|
|
break;
|
|
|
|
case 'r':
|
2017-03-02 11:36:54 +00:00
|
|
|
g_Config.iCpuCore = (int)CPUCore::IR_JIT;
|
2012-12-25 07:34:19 +00:00
|
|
|
g_Config.bSaveSettings = false;
|
2012-12-05 06:55:24 +00:00
|
|
|
break;
|
2012-12-26 23:18:45 +00:00
|
|
|
case '-':
|
2021-01-30 16:08:29 +00:00
|
|
|
if (!strncmp(argv[i], "--loglevel=", strlen("--loglevel=")) && strlen(argv[i]) > strlen("--loglevel="))
|
2021-01-30 19:51:35 +00:00
|
|
|
setLogLevel(static_cast<LogTypes::LOG_LEVELS>(std::atoi(argv[i] + strlen("--loglevel="))));
|
2012-12-26 23:18:45 +00:00
|
|
|
if (!strncmp(argv[i], "--log=", strlen("--log=")) && strlen(argv[i]) > strlen("--log="))
|
|
|
|
fileToLog = argv[i] + strlen("--log=");
|
2013-04-01 07:28:40 +00:00
|
|
|
if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state="))
|
2021-05-05 23:31:38 +00:00
|
|
|
stateToLoad = Path(std::string(argv[i] + strlen("--state=")));
|
2014-04-26 05:00:45 +00:00
|
|
|
#if !defined(MOBILE_DEVICE)
|
2014-04-26 05:14:08 +00:00
|
|
|
if (!strncmp(argv[i], "--escape-exit", strlen("--escape-exit")))
|
2014-04-26 05:54:32 +00:00
|
|
|
g_Config.bPauseExitsEmulator = true;
|
2014-04-26 05:00:45 +00:00
|
|
|
#endif
|
2018-04-02 14:31:26 +00:00
|
|
|
if (!strncmp(argv[i], "--pause-menu-exit", strlen("--pause-menu-exit")))
|
|
|
|
g_Config.bPauseMenuExitsEmulator = true;
|
2020-10-10 13:22:59 +00:00
|
|
|
if (!strcmp(argv[i], "--fullscreen")) {
|
2018-06-09 23:28:15 +00:00
|
|
|
g_Config.bFullScreen = true;
|
2020-10-10 13:22:59 +00:00
|
|
|
System_SendMessage("toggle_fullscreen", "1");
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--windowed")) {
|
|
|
|
g_Config.bFullScreen = false;
|
|
|
|
System_SendMessage("toggle_fullscreen", "0");
|
|
|
|
}
|
2020-05-09 20:52:04 +00:00
|
|
|
if (!strcmp(argv[i], "--touchscreentest"))
|
|
|
|
gotoTouchScreenTest = true;
|
|
|
|
if (!strcmp(argv[i], "--gamesettings"))
|
|
|
|
gotoGameSettings = true;
|
2012-12-26 23:18:45 +00:00
|
|
|
break;
|
2012-11-04 10:31:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-21 11:22:38 +00:00
|
|
|
// This parameter should be a boot filename. Only accept it if we
|
|
|
|
// don't already have one.
|
|
|
|
if (!gotBootFilename) {
|
|
|
|
gotBootFilename = true;
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "Boot filename found in args: '%s'", argv[i]);
|
2017-11-21 11:22:38 +00:00
|
|
|
|
|
|
|
bool okToLoad = true;
|
2018-04-02 06:28:36 +00:00
|
|
|
bool okToCheck = true;
|
2017-11-21 11:22:38 +00:00
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
PermissionStatus status = System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE);
|
2018-04-02 06:28:36 +00:00
|
|
|
if (status == PERMISSION_STATUS_DENIED) {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(IO, "Storage permission denied. Launching without argument.");
|
2017-11-21 11:22:38 +00:00
|
|
|
okToLoad = false;
|
2018-04-02 06:28:36 +00:00
|
|
|
okToCheck = false;
|
|
|
|
} else if (status != PERMISSION_STATUS_GRANTED) {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(IO, "Storage permission not granted. Launching without argument check.");
|
2018-04-02 06:28:36 +00:00
|
|
|
okToCheck = false;
|
2017-11-21 11:22:38 +00:00
|
|
|
} else {
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(IO, "Storage permission granted.");
|
2017-11-21 11:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (okToLoad) {
|
2021-05-09 16:38:48 +00:00
|
|
|
boot_filename = Path(std::string(argv[i]));
|
2017-11-21 11:22:38 +00:00
|
|
|
skipLogo = true;
|
2018-04-02 06:28:36 +00:00
|
|
|
}
|
|
|
|
if (okToLoad && okToCheck) {
|
2017-11-21 11:22:38 +00:00
|
|
|
std::unique_ptr<FileLoader> fileLoader(ConstructFileLoader(boot_filename));
|
|
|
|
if (!fileLoader->Exists()) {
|
|
|
|
fprintf(stderr, "File not found: %s\n", boot_filename.c_str());
|
2020-05-09 20:52:04 +00:00
|
|
|
#if defined(_WIN32) || defined(__ANDROID__)
|
2018-05-09 22:59:21 +00:00
|
|
|
// Ignore and proceed.
|
|
|
|
#else
|
|
|
|
// Bail.
|
2017-11-21 11:22:38 +00:00
|
|
|
exit(1);
|
2018-05-09 22:59:21 +00:00
|
|
|
#endif
|
2017-11-21 11:22:38 +00:00
|
|
|
}
|
2012-12-01 22:38:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Can only boot one file");
|
2020-05-09 20:52:04 +00:00
|
|
|
#if defined(_WIN32) || defined(__ANDROID__)
|
2018-05-09 22:59:21 +00:00
|
|
|
// Ignore and proceed.
|
|
|
|
#else
|
|
|
|
// Bail.
|
2012-11-04 10:31:06 +00:00
|
|
|
exit(1);
|
2018-05-09 22:59:21 +00:00
|
|
|
#endif
|
2012-11-04 10:31:06 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 13:59:37 +00:00
|
|
|
if (fileToLog)
|
2012-12-26 23:18:45 +00:00
|
|
|
LogManager::GetInstance()->ChangeFileLog(fileToLog);
|
|
|
|
|
2021-01-30 19:51:35 +00:00
|
|
|
if (forceLogLevel)
|
|
|
|
LogManager::GetInstance()->SetAllLogLevels(logLevel);
|
2021-01-30 16:08:29 +00:00
|
|
|
|
2018-04-29 18:45:32 +00:00
|
|
|
PostLoadConfig();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2020-08-15 17:01:16 +00:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
|
|
|
logger = new AndroidLogger();
|
|
|
|
logman->AddListener(logger);
|
|
|
|
#elif (defined(MOBILE_DEVICE) && !defined(_DEBUG))
|
2017-12-31 08:12:34 +00:00
|
|
|
// Enable basic logging for any kind of mobile device, since LogManager doesn't.
|
|
|
|
// The MOBILE_DEVICE/_DEBUG condition matches LogManager.cpp.
|
2020-08-15 17:01:16 +00:00
|
|
|
logger = new PrintfLogger();
|
2017-12-31 08:12:34 +00:00
|
|
|
logman->AddListener(logger);
|
2016-01-10 12:08:19 +00:00
|
|
|
#endif
|
2016-09-10 15:16:53 +00:00
|
|
|
|
2018-03-24 11:51:54 +00:00
|
|
|
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
|
|
|
if (System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE) != PERMISSION_STATUS_GRANTED) {
|
|
|
|
System_AskForPermission(SYSTEM_PERMISSION_STORAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-21 21:02:11 +00:00
|
|
|
if (System_GetPropertyBool(SYSPROP_CAN_JIT) == false && g_Config.iCpuCore == (int)CPUCore::JIT) {
|
|
|
|
// Just gonna force it to the IR interpreter on startup.
|
|
|
|
// We don't hide the option, but we make sure it's off on bootup. In case someone wants
|
|
|
|
// to experiment in future iOS versions or something...
|
|
|
|
g_Config.iCpuCore = (int)CPUCore::IR_JIT;
|
|
|
|
}
|
2018-03-24 11:51:54 +00:00
|
|
|
|
2020-01-26 18:43:18 +00:00
|
|
|
auto des = GetI18NCategory("DesktopUI");
|
2013-11-29 15:33:17 +00:00
|
|
|
// Note to translators: do not translate this/add this to PPSSPP-lang's files.
|
|
|
|
// It's intended to be custom for every user.
|
2013-08-30 17:52:15 +00:00
|
|
|
// Only add it to your own personal copies of PPSSPP.
|
2019-06-06 21:16:27 +00:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
// Roboto font is loaded in TextDrawerUWP.
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto");
|
|
|
|
#elif defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)
|
2013-08-31 08:36:52 +00:00
|
|
|
// TODO: Could allow a setting to specify a font file to load?
|
|
|
|
// TODO: Make this a constant if we can sanely load the font on other systems?
|
|
|
|
AddFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL);
|
2015-10-04 22:11:36 +00:00
|
|
|
// The font goes by two names, let's allow either one.
|
|
|
|
if (CheckFontIsUsable(L"Roboto Condensed")) {
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto Condensed");
|
|
|
|
} else {
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto");
|
|
|
|
}
|
2018-06-09 18:34:12 +00:00
|
|
|
#elif defined(USING_QT_UI)
|
|
|
|
size_t fontSize = 0;
|
|
|
|
uint8_t *fontData = VFSReadFile("Roboto-Condensed.ttf", &fontSize);
|
|
|
|
if (fontData) {
|
|
|
|
int fontID = QFontDatabase::addApplicationFontFromData(QByteArray((const char *)fontData, fontSize));
|
|
|
|
delete [] fontData;
|
|
|
|
|
|
|
|
QStringList fontsFound = QFontDatabase::applicationFontFamilies(fontID);
|
|
|
|
if (fontsFound.size() >= 1) {
|
|
|
|
// Might be "Roboto" or "Roboto Condensed".
|
|
|
|
g_Config.sFont = des->T("Font", fontsFound.at(0).toUtf8().constData());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Let's try for it being a system font.
|
|
|
|
g_Config.sFont = des->T("Font", "Roboto Condensed");
|
|
|
|
}
|
2013-08-30 18:19:03 +00:00
|
|
|
#endif
|
2013-04-18 09:58:54 +00:00
|
|
|
|
2020-08-04 21:36:35 +00:00
|
|
|
// TODO: Load these in the background instead of synchronously.
|
|
|
|
g_BackgroundAudio.LoadSamples();
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
if (!boot_filename.empty() && stateToLoad.Valid()) {
|
2020-05-16 13:20:22 +00:00
|
|
|
SaveState::Load(stateToLoad, -1, [](SaveState::Status status, const std::string &message, void *) {
|
2019-06-03 10:21:22 +00:00
|
|
|
if (!message.empty() && (!g_Config.bDumpFrames || !g_Config.bDumpVideoOutput)) {
|
2018-06-15 00:52:44 +00:00
|
|
|
osm.Show(message, status == SaveState::Status::SUCCESS ? 2.0 : 5.0);
|
2016-05-28 04:25:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-10-17 14:44:09 +00:00
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager = new ScreenManager();
|
2020-05-09 20:52:04 +00:00
|
|
|
if (gotoGameSettings) {
|
|
|
|
screenManager->switchScreen(new LogoScreen(true));
|
|
|
|
} else if (gotoTouchScreenTest) {
|
|
|
|
screenManager->switchScreen(new MainScreen());
|
|
|
|
screenManager->push(new TouchTestScreen());
|
|
|
|
} else if (skipLogo) {
|
2021-05-09 16:38:48 +00:00
|
|
|
screenManager->switchScreen(new EmuScreen(boot_filename));
|
2013-07-27 11:07:34 +00:00
|
|
|
} else {
|
2013-11-03 03:18:12 +00:00
|
|
|
screenManager->switchScreen(new LogoScreen());
|
2013-07-27 11:07:34 +00:00
|
|
|
}
|
2013-10-31 10:06:54 +00:00
|
|
|
|
2018-12-18 22:56:36 +00:00
|
|
|
// Easy testing
|
|
|
|
// screenManager->push(new GPUDriverTestScreen());
|
2018-12-18 08:35:53 +00:00
|
|
|
|
2018-04-21 20:54:44 +00:00
|
|
|
if (g_Config.bRemoteShareOnStartup && g_Config.bRemoteDebuggerOnStartup)
|
2018-04-21 20:51:18 +00:00
|
|
|
StartWebServer(WebServerFlags::ALL);
|
2018-04-21 20:54:44 +00:00
|
|
|
else if (g_Config.bRemoteShareOnStartup)
|
|
|
|
StartWebServer(WebServerFlags::DISCS);
|
|
|
|
else if (g_Config.bRemoteDebuggerOnStartup)
|
|
|
|
StartWebServer(WebServerFlags::DEBUGGER);
|
2017-12-11 02:30:28 +00:00
|
|
|
|
2013-10-31 10:06:54 +00:00
|
|
|
std::string sysName = System_GetProperty(SYSPROP_NAME);
|
|
|
|
isOuya = KeyMap::IsOuya(sysName);
|
2014-03-01 15:09:16 +00:00
|
|
|
|
|
|
|
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
|
2018-06-09 23:28:15 +00:00
|
|
|
MainWindow *mainWindow = new MainWindow(nullptr, g_Config.bFullScreen);
|
2014-03-01 15:09:16 +00:00
|
|
|
mainWindow->show();
|
2017-04-29 19:02:07 +00:00
|
|
|
if (host == nullptr) {
|
|
|
|
host = new QtHost(mainWindow);
|
|
|
|
}
|
2014-03-01 15:09:16 +00:00
|
|
|
#endif
|
2014-06-29 08:09:15 +00:00
|
|
|
|
|
|
|
// We do this here, instead of in NativeInitGraphics, because the display may be reset.
|
|
|
|
// When it's reset we don't want to forget all our managed things.
|
2018-09-01 20:57:20 +00:00
|
|
|
CheckFailedGPUBackends();
|
2016-01-06 06:37:28 +00:00
|
|
|
SetGPUBackend((GPUBackend) g_Config.iGPUBackend);
|
2018-09-07 01:31:09 +00:00
|
|
|
renderCounter = 0;
|
2017-04-15 23:30:37 +00:00
|
|
|
|
|
|
|
// Must be done restarting by now.
|
|
|
|
restarting = false;
|
2013-07-16 20:50:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 16:51:33 +00:00
|
|
|
static UI::Style MakeStyle(uint32_t fg, uint32_t bg) {
|
|
|
|
UI::Style s;
|
|
|
|
s.background = UI::Drawable(bg);
|
|
|
|
s.fgColor = fg;
|
2014-08-17 10:19:04 +00:00
|
|
|
|
2017-03-26 16:51:33 +00:00
|
|
|
return s;
|
|
|
|
}
|
2013-07-16 20:50:53 +00:00
|
|
|
|
2017-03-26 16:51:33 +00:00
|
|
|
static void UIThemeInit() {
|
2019-06-06 21:16:27 +00:00
|
|
|
#if defined(USING_WIN_UI) || PPSSPP_PLATFORM(UWP) || defined(USING_QT_UI)
|
2020-02-29 20:51:14 +00:00
|
|
|
ui_theme.uiFont = UI::FontStyle(FontID("UBUNTU24"), g_Config.sFont.c_str(), 22);
|
|
|
|
ui_theme.uiFontSmall = UI::FontStyle(FontID("UBUNTU24"), g_Config.sFont.c_str(), 15);
|
|
|
|
ui_theme.uiFontSmaller = UI::FontStyle(FontID("UBUNTU24"), g_Config.sFont.c_str(), 12);
|
2013-08-30 18:19:03 +00:00
|
|
|
#else
|
2020-02-29 20:51:14 +00:00
|
|
|
ui_theme.uiFont = UI::FontStyle(FontID("UBUNTU24"), "", 20);
|
|
|
|
ui_theme.uiFontSmall = UI::FontStyle(FontID("UBUNTU24"), "", 14);
|
|
|
|
ui_theme.uiFontSmaller = UI::FontStyle(FontID("UBUNTU24"), "", 11);
|
2013-08-30 18:19:03 +00:00
|
|
|
#endif
|
2013-08-30 12:47:28 +00:00
|
|
|
|
2020-02-29 20:51:14 +00:00
|
|
|
ui_theme.checkOn = ImageID("I_CHECKEDBOX");
|
|
|
|
ui_theme.checkOff = ImageID("I_SQUARE");
|
|
|
|
ui_theme.whiteImage = ImageID("I_SOLIDWHITE");
|
|
|
|
ui_theme.sliderKnob = ImageID("I_CIRCLE");
|
|
|
|
ui_theme.dropShadow4Grid = ImageID("I_DROP_SHADOW");
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2017-03-26 16:51:33 +00:00
|
|
|
ui_theme.itemStyle = MakeStyle(g_Config.uItemStyleFg, g_Config.uItemStyleBg);
|
|
|
|
ui_theme.itemFocusedStyle = MakeStyle(g_Config.uItemFocusedStyleFg, g_Config.uItemFocusedStyleBg);
|
|
|
|
ui_theme.itemDownStyle = MakeStyle(g_Config.uItemDownStyleFg, g_Config.uItemDownStyleBg);
|
|
|
|
ui_theme.itemDisabledStyle = MakeStyle(g_Config.uItemDisabledStyleFg, g_Config.uItemDisabledStyleBg);
|
|
|
|
ui_theme.itemHighlightedStyle = MakeStyle(g_Config.uItemHighlightedStyleFg, g_Config.uItemHighlightedStyleBg);
|
|
|
|
|
|
|
|
ui_theme.buttonStyle = MakeStyle(g_Config.uButtonStyleFg, g_Config.uButtonStyleBg);
|
|
|
|
ui_theme.buttonFocusedStyle = MakeStyle(g_Config.uButtonFocusedStyleFg, g_Config.uButtonFocusedStyleBg);
|
|
|
|
ui_theme.buttonDownStyle = MakeStyle(g_Config.uButtonDownStyleFg, g_Config.uButtonDownStyleBg);
|
|
|
|
ui_theme.buttonDisabledStyle = MakeStyle(g_Config.uButtonDisabledStyleFg, g_Config.uButtonDisabledStyleBg);
|
|
|
|
ui_theme.buttonHighlightedStyle = MakeStyle(g_Config.uButtonHighlightedStyleFg, g_Config.uButtonHighlightedStyleBg);
|
|
|
|
|
|
|
|
ui_theme.headerStyle.fgColor = g_Config.uHeaderStyleFg;
|
|
|
|
ui_theme.infoStyle = MakeStyle(g_Config.uInfoStyleFg, g_Config.uInfoStyleBg);
|
|
|
|
|
|
|
|
ui_theme.popupTitle.fgColor = g_Config.uPopupTitleStyleFg;
|
|
|
|
ui_theme.popupStyle = MakeStyle(g_Config.uPopupStyleFg, g_Config.uPopupStyleBg);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:15 +00:00
|
|
|
void RenderOverlays(UIContext *dc, void *userdata);
|
2020-07-28 17:06:29 +00:00
|
|
|
bool CreateGlobalPipelines();
|
2017-05-16 12:09:15 +00:00
|
|
|
|
2017-11-29 17:53:52 +00:00
|
|
|
bool NativeInitGraphics(GraphicsContext *graphicsContext) {
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "NativeInitGraphics");
|
2017-03-26 16:51:33 +00:00
|
|
|
|
2020-03-01 03:31:58 +00:00
|
|
|
// We set this now so any resize during init is processed later.
|
|
|
|
resized = false;
|
|
|
|
|
2017-03-26 16:51:33 +00:00
|
|
|
Core_SetGraphicsContext(graphicsContext);
|
|
|
|
g_draw = graphicsContext->GetDrawContext();
|
|
|
|
|
2020-07-28 17:06:29 +00:00
|
|
|
if (!CreateGlobalPipelines()) {
|
|
|
|
ERROR_LOG(G3D, "Failed to create global pipelines");
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-29 20:51:14 +00:00
|
|
|
|
2020-07-28 17:06:29 +00:00
|
|
|
// Load the atlas.
|
2020-02-29 20:51:14 +00:00
|
|
|
size_t atlas_data_size = 0;
|
|
|
|
if (!g_ui_atlas.IsMetadataLoaded()) {
|
|
|
|
const uint8_t *atlas_data = VFSReadFile("ui_atlas.meta", &atlas_data_size);
|
2020-03-22 04:10:20 +00:00
|
|
|
bool load_success = atlas_data != nullptr && g_ui_atlas.Load(atlas_data, atlas_data_size);
|
2020-07-28 17:06:29 +00:00
|
|
|
if (!load_success) {
|
|
|
|
ERROR_LOG(G3D, "Failed to load ui_atlas.meta - graphics will be broken.");
|
|
|
|
// Stumble along with broken visuals instead of dying.
|
|
|
|
}
|
2020-02-29 20:51:14 +00:00
|
|
|
delete[] atlas_data;
|
|
|
|
}
|
2020-07-28 17:06:29 +00:00
|
|
|
|
2020-02-29 20:51:14 +00:00
|
|
|
ui_draw2d.SetAtlas(&g_ui_atlas);
|
|
|
|
ui_draw2d_front.SetAtlas(&g_ui_atlas);
|
2017-03-26 16:51:33 +00:00
|
|
|
|
|
|
|
UIThemeInit();
|
2013-12-10 22:19:37 +00:00
|
|
|
|
2013-03-30 18:23:20 +00:00
|
|
|
uiContext = new UIContext();
|
2013-06-01 21:34:50 +00:00
|
|
|
uiContext->theme = &ui_theme;
|
2014-08-17 10:19:04 +00:00
|
|
|
|
2017-01-30 13:33:38 +00:00
|
|
|
ui_draw2d.Init(g_draw, texColorPipeline);
|
|
|
|
ui_draw2d_front.Init(g_draw, texColorPipeline);
|
2016-12-26 16:03:01 +00:00
|
|
|
|
2017-01-30 13:33:38 +00:00
|
|
|
uiContext->Init(g_draw, texColorPipeline, colorPipeline, &ui_draw2d, &ui_draw2d_front);
|
2013-08-30 16:15:45 +00:00
|
|
|
if (uiContext->Text())
|
|
|
|
uiContext->Text()->SetFont("Tahoma", 20, 0);
|
2014-02-10 14:14:45 +00:00
|
|
|
|
2013-03-30 18:23:20 +00:00
|
|
|
screenManager->setUIContext(uiContext);
|
2017-01-30 13:33:38 +00:00
|
|
|
screenManager->setDrawContext(g_draw);
|
2017-05-16 12:09:15 +00:00
|
|
|
screenManager->setPostRenderCallback(&RenderOverlays, nullptr);
|
2018-03-27 21:10:33 +00:00
|
|
|
screenManager->deviceRestored();
|
2013-03-30 18:23:20 +00:00
|
|
|
|
2014-06-22 12:23:06 +00:00
|
|
|
#ifdef _WIN32
|
2015-01-24 12:50:27 +00:00
|
|
|
winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend);
|
2017-02-24 23:25:46 +00:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2017-03-01 11:51:06 +00:00
|
|
|
winAudioBackend->Init(0, &Win32Mix, 44100);
|
2017-02-24 23:25:46 +00:00
|
|
|
#else
|
2015-01-11 20:00:56 +00:00
|
|
|
winAudioBackend->Init(MainWindow::GetHWND(), &Win32Mix, 44100);
|
2017-02-24 23:25:46 +00:00
|
|
|
#endif
|
2014-06-22 12:23:06 +00:00
|
|
|
#endif
|
2016-02-14 21:07:10 +00:00
|
|
|
|
2020-01-14 09:15:11 +00:00
|
|
|
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
|
|
|
if (IsWin7OrHigher()) {
|
2020-01-13 07:06:02 +00:00
|
|
|
winCamera = new WindowsCaptureDevice(CAPTUREDEVIDE_TYPE::VIDEO);
|
|
|
|
winCamera->sendMessage({ CAPTUREDEVIDE_COMMAND::INITIALIZE, nullptr });
|
2020-07-31 02:24:17 +00:00
|
|
|
winMic = new WindowsCaptureDevice(CAPTUREDEVIDE_TYPE::AUDIO);
|
|
|
|
winMic->sendMessage({ CAPTUREDEVIDE_COMMAND::INITIALIZE, nullptr });
|
2020-01-13 07:06:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-14 21:07:10 +00:00
|
|
|
g_gameInfoCache = new GameInfoCache();
|
2017-11-10 12:13:56 +00:00
|
|
|
|
2020-07-28 17:06:29 +00:00
|
|
|
if (gpu) {
|
2017-12-07 13:56:19 +00:00
|
|
|
gpu->DeviceRestore();
|
2020-07-28 17:06:29 +00:00
|
|
|
}
|
2017-12-07 13:56:19 +00:00
|
|
|
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "NativeInitGraphics completed");
|
2017-11-29 17:53:52 +00:00
|
|
|
return true;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 17:06:29 +00:00
|
|
|
bool CreateGlobalPipelines() {
|
|
|
|
using namespace Draw;
|
|
|
|
|
|
|
|
InputLayout *inputLayout = ui_draw2d.CreateInputLayout(g_draw);
|
|
|
|
BlendState *blendNormal = g_draw->CreateBlendState({ true, 0xF, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA });
|
|
|
|
DepthStencilState *depth = g_draw->CreateDepthStencilState({ false, false, Comparison::LESS });
|
|
|
|
RasterState *rasterNoCull = g_draw->CreateRasterState({});
|
|
|
|
|
|
|
|
PipelineDesc colorDesc{
|
|
|
|
Primitive::TRIANGLE_LIST,
|
|
|
|
{ g_draw->GetVshaderPreset(VS_COLOR_2D), g_draw->GetFshaderPreset(FS_COLOR_2D) },
|
|
|
|
inputLayout, depth, blendNormal, rasterNoCull, &vsColBufDesc,
|
|
|
|
};
|
|
|
|
PipelineDesc texColorDesc{
|
|
|
|
Primitive::TRIANGLE_LIST,
|
|
|
|
{ g_draw->GetVshaderPreset(VS_TEXTURE_COLOR_2D), g_draw->GetFshaderPreset(FS_TEXTURE_COLOR_2D) },
|
|
|
|
inputLayout, depth, blendNormal, rasterNoCull, &vsTexColBufDesc,
|
|
|
|
};
|
|
|
|
|
|
|
|
colorPipeline = g_draw->CreateGraphicsPipeline(colorDesc);
|
|
|
|
if (!colorPipeline) {
|
|
|
|
// Something really critical is wrong, don't care much about correct releasing of the states.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
texColorPipeline = g_draw->CreateGraphicsPipeline(texColorDesc);
|
|
|
|
if (!texColorPipeline) {
|
|
|
|
// Something really critical is wrong, don't care much about correct releasing of the states.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release these now, reference counting should ensure that they get completely released
|
|
|
|
// once we delete both pipelines.
|
|
|
|
inputLayout->Release();
|
|
|
|
rasterNoCull->Release();
|
|
|
|
blendNormal->Release();
|
|
|
|
depth->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
void NativeShutdownGraphics() {
|
2018-03-27 21:10:33 +00:00
|
|
|
screenManager->deviceLost();
|
|
|
|
|
2017-12-07 13:56:19 +00:00
|
|
|
if (gpu)
|
|
|
|
gpu->DeviceLost();
|
|
|
|
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "NativeShutdownGraphics");
|
2017-03-18 14:20:36 +00:00
|
|
|
|
2020-07-28 17:06:29 +00:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
2015-01-11 20:00:56 +00:00
|
|
|
delete winAudioBackend;
|
2017-03-25 22:01:33 +00:00
|
|
|
winAudioBackend = nullptr;
|
2014-06-22 12:23:06 +00:00
|
|
|
#endif
|
2014-06-22 12:17:57 +00:00
|
|
|
|
2020-07-28 17:06:29 +00:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
|
2020-01-14 00:19:44 +00:00
|
|
|
if (winCamera) {
|
2021-01-03 06:49:06 +00:00
|
|
|
winCamera->waitShutDown();
|
2020-01-14 00:19:44 +00:00
|
|
|
delete winCamera;
|
|
|
|
winCamera = nullptr;
|
|
|
|
}
|
2020-07-31 02:24:17 +00:00
|
|
|
if (winMic) {
|
2021-01-03 06:49:06 +00:00
|
|
|
winMic->waitShutDown();
|
2020-07-31 02:24:17 +00:00
|
|
|
delete winMic;
|
|
|
|
winMic = nullptr;
|
|
|
|
}
|
2020-01-13 07:06:02 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-28 18:12:12 +00:00
|
|
|
UIBackgroundShutdown();
|
|
|
|
|
2016-02-14 21:07:10 +00:00
|
|
|
delete g_gameInfoCache;
|
|
|
|
g_gameInfoCache = nullptr;
|
2013-07-16 20:50:53 +00:00
|
|
|
|
|
|
|
delete uiContext;
|
2017-03-25 22:01:33 +00:00
|
|
|
uiContext = nullptr;
|
2013-07-16 20:50:53 +00:00
|
|
|
|
|
|
|
ui_draw2d.Shutdown();
|
|
|
|
ui_draw2d_front.Shutdown();
|
|
|
|
|
2018-01-20 20:47:16 +00:00
|
|
|
if (colorPipeline) {
|
|
|
|
colorPipeline->Release();
|
|
|
|
colorPipeline = nullptr;
|
|
|
|
}
|
|
|
|
if (texColorPipeline) {
|
|
|
|
texColorPipeline->Release();
|
|
|
|
texColorPipeline = nullptr;
|
|
|
|
}
|
2017-03-18 14:20:36 +00:00
|
|
|
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "NativeShutdownGraphics done");
|
2013-07-16 20:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-22 20:27:59 +00:00
|
|
|
void TakeScreenshot() {
|
|
|
|
g_TakeScreenshot = false;
|
2014-08-17 14:07:14 +00:00
|
|
|
|
2021-05-15 05:48:04 +00:00
|
|
|
Path path = GetSysDirectory(DIRECTORY_SCREENSHOT);
|
2014-12-29 04:52:44 +00:00
|
|
|
if (!File::Exists(path)) {
|
|
|
|
File::CreateDir(path);
|
|
|
|
}
|
2013-06-22 20:27:59 +00:00
|
|
|
|
|
|
|
// First, find a free filename.
|
|
|
|
int i = 0;
|
|
|
|
|
2017-06-03 03:54:28 +00:00
|
|
|
std::string gameId = g_paramSFO.GetDiscID();
|
2014-02-17 22:43:58 +00:00
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
Path filename;
|
2013-07-07 18:56:18 +00:00
|
|
|
while (i < 10000){
|
2014-02-17 22:43:58 +00:00
|
|
|
if (g_Config.bScreenshotsAsPNG)
|
2021-05-30 17:29:16 +00:00
|
|
|
filename = path / StringFromFormat("%s_%05d.png", gameId.c_str(), i);
|
2013-07-07 18:56:18 +00:00
|
|
|
else
|
2021-05-30 17:29:16 +00:00
|
|
|
filename = path / StringFromFormat("%s_%05d.jpg", gameId.c_str(), i);
|
2021-04-25 18:38:22 +00:00
|
|
|
File::FileInfo info;
|
|
|
|
if (!File::Exists(filename))
|
2013-06-22 20:27:59 +00:00
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2017-12-21 23:44:49 +00:00
|
|
|
bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? ScreenshotFormat::PNG : ScreenshotFormat::JPG, SCREENSHOT_OUTPUT);
|
2014-11-02 21:29:44 +00:00
|
|
|
if (success) {
|
2021-05-05 23:31:38 +00:00
|
|
|
osm.Show(filename.ToVisualString());
|
2014-11-02 21:29:44 +00:00
|
|
|
} else {
|
2020-01-26 18:43:18 +00:00
|
|
|
auto err = GetI18NCategory("Error");
|
2014-11-02 21:29:44 +00:00
|
|
|
osm.Show(err->T("Could not save screenshot file"));
|
|
|
|
}
|
2013-06-22 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:15 +00:00
|
|
|
void RenderOverlays(UIContext *dc, void *userdata) {
|
2013-11-29 15:33:17 +00:00
|
|
|
// Thin bar at the top of the screen like Chrome.
|
|
|
|
std::vector<float> progress = g_DownloadManager.GetCurrentProgress();
|
2017-06-02 03:40:21 +00:00
|
|
|
if (!progress.empty()) {
|
|
|
|
static const uint32_t colors[4] = {
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFCCCCCC,
|
|
|
|
0xFFAAAAAA,
|
|
|
|
0xFF777777,
|
|
|
|
};
|
|
|
|
|
|
|
|
dc->Begin();
|
|
|
|
int h = 5;
|
|
|
|
for (size_t i = 0; i < progress.size(); i++) {
|
|
|
|
float barWidth = 10 + (dc->GetBounds().w - 10) * progress[i];
|
|
|
|
Bounds bounds(0, h * i, barWidth, h);
|
|
|
|
UI::Drawable solid(colors[i & 3]);
|
|
|
|
dc->FillRect(solid, bounds);
|
|
|
|
}
|
|
|
|
dc->Flush();
|
2017-05-16 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_TakeScreenshot) {
|
|
|
|
TakeScreenshot();
|
2013-11-29 15:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-31 15:59:40 +00:00
|
|
|
void NativeRender(GraphicsContext *graphicsContext) {
|
2021-02-13 20:49:48 +00:00
|
|
|
_assert_(graphicsContext != nullptr);
|
|
|
|
_assert_(screenManager != nullptr);
|
|
|
|
|
2013-11-20 13:42:48 +00:00
|
|
|
g_GameManager.Update();
|
2017-05-16 12:09:15 +00:00
|
|
|
|
2019-09-27 21:53:31 +00:00
|
|
|
if (GetUIState() != UISTATE_INGAME) {
|
|
|
|
// Note: We do this from NativeRender so that the graphics context is
|
|
|
|
// guaranteed valid, to be safe - g_gameInfoCache messes around with textures.
|
2020-08-02 17:44:48 +00:00
|
|
|
g_BackgroundAudio.Update();
|
2019-09-27 21:53:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 14:14:45 +00:00
|
|
|
float xres = dp_xres;
|
|
|
|
float yres = dp_yres;
|
|
|
|
|
2014-02-10 11:38:23 +00:00
|
|
|
// Apply the UIContext bounds as a 2D transformation matrix.
|
2017-05-16 12:09:15 +00:00
|
|
|
// TODO: This should be moved into the draw context...
|
2012-11-04 09:56:22 +00:00
|
|
|
Matrix4x4 ortho;
|
2016-01-03 11:37:05 +00:00
|
|
|
switch (GetGPUBackend()) {
|
|
|
|
case GPUBackend::VULKAN:
|
|
|
|
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
|
|
|
|
break;
|
|
|
|
case GPUBackend::DIRECT3D9:
|
2014-08-23 08:49:40 +00:00
|
|
|
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
2014-08-25 19:33:24 +00:00
|
|
|
Matrix4x4 translation;
|
2017-12-03 14:58:16 +00:00
|
|
|
// Account for the small window adjustment.
|
|
|
|
translation.setTranslation(Vec3(-0.5f * g_dpi_scale_x / g_dpi_scale_real_x, -0.5f * g_dpi_scale_y / g_dpi_scale_real_y, 0.0f));
|
2014-08-25 19:33:24 +00:00
|
|
|
ortho = translation * ortho;
|
2016-01-03 11:37:05 +00:00
|
|
|
break;
|
2017-02-08 16:09:59 +00:00
|
|
|
case GPUBackend::DIRECT3D11:
|
|
|
|
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
break;
|
2016-01-03 11:37:05 +00:00
|
|
|
case GPUBackend::OPENGL:
|
2019-09-17 08:50:25 +00:00
|
|
|
default:
|
2014-08-23 08:49:40 +00:00
|
|
|
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
2016-01-03 11:37:05 +00:00
|
|
|
break;
|
2014-08-23 08:49:40 +00:00
|
|
|
}
|
2014-02-10 14:55:21 +00:00
|
|
|
|
2019-08-04 16:00:33 +00:00
|
|
|
// Compensate for rotated display if needed.
|
2017-03-05 00:39:26 +00:00
|
|
|
if (g_display_rotation != DisplayRotation::ROTATE_0) {
|
|
|
|
ortho = ortho * g_display_rot_matrix;
|
|
|
|
}
|
|
|
|
|
2017-03-19 21:28:24 +00:00
|
|
|
ui_draw2d.PushDrawMatrix(ortho);
|
|
|
|
ui_draw2d_front.PushDrawMatrix(ortho);
|
2014-08-17 10:19:04 +00:00
|
|
|
|
2017-05-16 12:09:15 +00:00
|
|
|
// All actual rendering happen in here.
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->render();
|
2013-11-15 12:11:44 +00:00
|
|
|
if (screenManager->getUIContext()->Text()) {
|
2013-08-30 16:15:45 +00:00
|
|
|
screenManager->getUIContext()->Text()->OncePerFrame();
|
2013-11-15 12:11:44 +00:00
|
|
|
}
|
2013-06-22 20:27:59 +00:00
|
|
|
|
2015-02-01 17:04:06 +00:00
|
|
|
if (resized) {
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(G3D, "Resized flag set - recalculating bounds");
|
2015-02-01 17:04:06 +00:00
|
|
|
resized = false;
|
2017-02-23 08:25:33 +00:00
|
|
|
|
|
|
|
if (uiContext) {
|
|
|
|
// Modifying the bounds here can be used to "inset" the whole image to gain borders for TV overscan etc.
|
|
|
|
// The UI now supports any offset but not the EmuScreen yet.
|
|
|
|
uiContext->SetBounds(Bounds(0, 0, dp_xres, dp_yres));
|
|
|
|
// uiContext->SetBounds(Bounds(dp_xres/2, 0, dp_xres / 2, dp_yres / 2));
|
|
|
|
|
|
|
|
// OSX 10.6 and SDL 1.2 bug.
|
|
|
|
#if defined(__APPLE__) && !defined(USING_QT_UI)
|
|
|
|
static int dp_xres_old = dp_xres;
|
|
|
|
if (dp_xres != dp_xres_old) {
|
|
|
|
// uiTexture->Load("ui_atlas.zim");
|
|
|
|
dp_xres_old = dp_xres;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-07 13:56:19 +00:00
|
|
|
graphicsContext->Resize();
|
|
|
|
screenManager->resized();
|
|
|
|
|
2020-06-23 23:04:41 +00:00
|
|
|
// TODO: Move this to the GraphicsContext objects for each backend.
|
2020-07-28 17:06:29 +00:00
|
|
|
#if !PPSSPP_PLATFORM(WINDOWS) && !defined(ANDROID)
|
2020-06-23 23:04:41 +00:00
|
|
|
PSP_CoreParameter().pixelWidth = pixel_xres;
|
|
|
|
PSP_CoreParameter().pixelHeight = pixel_yres;
|
|
|
|
NativeMessageReceived("gpu_resized", "");
|
2015-12-31 15:59:40 +00:00
|
|
|
#endif
|
2020-06-21 20:34:37 +00:00
|
|
|
} else {
|
2020-08-15 14:25:50 +00:00
|
|
|
// INFO_LOG(G3D, "Polling graphics context");
|
2020-06-21 20:34:37 +00:00
|
|
|
graphicsContext->Poll();
|
2015-02-01 17:04:06 +00:00
|
|
|
}
|
2017-03-19 21:28:24 +00:00
|
|
|
|
|
|
|
ui_draw2d.PopDrawMatrix();
|
|
|
|
ui_draw2d_front.PopDrawMatrix();
|
2018-09-01 20:57:20 +00:00
|
|
|
|
|
|
|
if (renderCounter < 10 && ++renderCounter == 10) {
|
|
|
|
// We're rendering fine, clear out failure info.
|
|
|
|
ClearFailedGPUBackends();
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 21:29:35 +00:00
|
|
|
void HandleGlobalMessage(const std::string &msg, const std::string &value) {
|
|
|
|
if (msg == "inputDeviceConnected") {
|
|
|
|
KeyMap::NotifyPadConnected(value);
|
|
|
|
}
|
2017-03-25 22:08:43 +00:00
|
|
|
if (msg == "bgImage_updated") {
|
2017-04-29 18:06:37 +00:00
|
|
|
if (!value.empty()) {
|
2021-05-05 23:31:38 +00:00
|
|
|
Path dest = GetSysDirectory(DIRECTORY_SYSTEM) / (endsWithNoCase(value, ".jpg") ? "background.jpg" : "background.png");
|
2021-05-09 13:02:46 +00:00
|
|
|
File::Copy(Path(value), dest);
|
2017-04-29 18:06:37 +00:00
|
|
|
}
|
2017-03-25 22:08:43 +00:00
|
|
|
UIBackgroundShutdown();
|
2021-04-17 03:49:46 +00:00
|
|
|
// It will init again automatically. We can't init outside a frame on Vulkan.
|
2017-03-25 22:08:43 +00:00
|
|
|
}
|
2016-05-28 03:53:20 +00:00
|
|
|
if (msg == "savestate_displayslot") {
|
2020-01-26 18:43:18 +00:00
|
|
|
auto sy = GetI18NCategory("System");
|
2016-05-28 03:53:20 +00:00
|
|
|
std::string msg = StringFromFormat("%s: %d", sy->T("Savestate Slot"), SaveState::GetCurrentSlot() + 1);
|
2016-05-28 03:53:58 +00:00
|
|
|
// Show for the same duration as the preview.
|
2016-05-28 03:55:44 +00:00
|
|
|
osm.Show(msg, 2.0f, 0xFFFFFF, -1, true, "savestate_slot");
|
2016-05-28 03:53:20 +00:00
|
|
|
}
|
2017-04-28 03:03:50 +00:00
|
|
|
if (msg == "gpu_resized" || msg == "gpu_clearCache") {
|
2016-09-29 05:35:09 +00:00
|
|
|
if (gpu) {
|
|
|
|
gpu->ClearCacheNextFrame();
|
|
|
|
gpu->Resized();
|
|
|
|
}
|
|
|
|
Reporting::UpdateConfig();
|
|
|
|
}
|
2016-07-25 00:04:06 +00:00
|
|
|
if (msg == "core_powerSaving") {
|
|
|
|
if (value != "false") {
|
2020-01-26 18:43:18 +00:00
|
|
|
auto sy = GetI18NCategory("System");
|
2020-07-28 17:06:29 +00:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
2016-10-11 00:32:25 +00:00
|
|
|
osm.Show(sy->T("WARNING: Android battery save mode is on"), 2.0f, 0xFFFFFF, -1, true, "core_powerSaving");
|
|
|
|
#else
|
2016-07-25 00:04:06 +00:00
|
|
|
osm.Show(sy->T("WARNING: Battery save mode is on"), 2.0f, 0xFFFFFF, -1, true, "core_powerSaving");
|
2016-10-11 00:32:25 +00:00
|
|
|
#endif
|
2016-07-25 00:04:06 +00:00
|
|
|
}
|
|
|
|
Core_SetPowerSaving(value != "false");
|
|
|
|
}
|
2018-03-24 11:51:54 +00:00
|
|
|
if (msg == "permission_granted" && value == "storage") {
|
2020-07-28 17:06:29 +00:00
|
|
|
#if PPSSPP_PLATFORM(ANDROID)
|
2018-05-10 17:32:28 +00:00
|
|
|
CreateDirectoriesAndroid();
|
|
|
|
#endif
|
2018-03-24 11:51:54 +00:00
|
|
|
// We must have failed to load the config before, so load it now to avoid overwriting the old config
|
|
|
|
// with a freshly generated one.
|
2019-09-17 08:50:25 +00:00
|
|
|
// NOTE: If graphics backend isn't what's in the config (due to error fallback, or not matching the default
|
|
|
|
// and then getting permission), it will get out of sync. So we save and restore g_Config.iGPUBackend.
|
|
|
|
// Ideally we should simply reinitialize graphics to the mode from the config, but there are potential issues
|
|
|
|
// and I can't risk it before 1.9.0.
|
|
|
|
int gpuBackend = g_Config.iGPUBackend;
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(IO, "Reloading config after storage permission grant.");
|
2020-03-08 22:25:20 +00:00
|
|
|
g_Config.Reload();
|
2018-04-29 18:45:32 +00:00
|
|
|
PostLoadConfig();
|
2019-09-17 08:50:25 +00:00
|
|
|
g_Config.iGPUBackend = gpuBackend;
|
2018-03-24 11:51:54 +00:00
|
|
|
}
|
2014-05-19 21:29:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 05:01:18 +00:00
|
|
|
void NativeUpdate() {
|
2015-05-15 15:14:54 +00:00
|
|
|
PROFILE_END_FRAME();
|
|
|
|
|
2017-12-10 10:28:27 +00:00
|
|
|
std::vector<PendingMessage> toProcess;
|
2020-03-09 02:54:24 +00:00
|
|
|
std::vector<PendingInputBox> inputToProcess;
|
2013-03-29 19:51:14 +00:00
|
|
|
{
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(pendingMutex);
|
2017-12-10 10:28:27 +00:00
|
|
|
toProcess = std::move(pendingMessages);
|
2020-03-09 02:54:24 +00:00
|
|
|
inputToProcess = std::move(pendingInputBoxes);
|
2014-02-13 16:47:02 +00:00
|
|
|
pendingMessages.clear();
|
2020-03-09 02:54:24 +00:00
|
|
|
pendingInputBoxes.clear();
|
2013-03-29 19:51:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 02:54:24 +00:00
|
|
|
for (const auto &item : toProcess) {
|
|
|
|
HandleGlobalMessage(item.msg, item.value);
|
|
|
|
screenManager->sendMessage(item.msg.c_str(), item.value.c_str());
|
|
|
|
}
|
|
|
|
for (const auto &item : inputToProcess) {
|
|
|
|
item.cb(item.result, item.value);
|
2017-12-10 10:28:27 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 13:04:29 +00:00
|
|
|
g_DownloadManager.Update();
|
2017-03-15 05:01:18 +00:00
|
|
|
screenManager->update();
|
2018-08-12 22:08:56 +00:00
|
|
|
|
|
|
|
g_Discord.Update();
|
2020-08-03 09:58:55 +00:00
|
|
|
|
|
|
|
UI::SetSoundEnabled(g_Config.bUISound);
|
2013-07-11 12:29:56 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
bool NativeIsAtTopLevel() {
|
2018-05-26 15:50:37 +00:00
|
|
|
// This might need some synchronization?
|
|
|
|
if (!screenManager) {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(SYSTEM, "No screen manager active");
|
2018-05-26 15:50:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-09-04 08:51:14 +00:00
|
|
|
Screen *currentScreen = screenManager->topScreen();
|
|
|
|
if (currentScreen) {
|
|
|
|
bool top = currentScreen->isTopLevel();
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "Screen toplevel: %i", (int)top);
|
2013-09-04 08:51:14 +00:00
|
|
|
return currentScreen->isTopLevel();
|
|
|
|
} else {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(SYSTEM, "No current screen");
|
2013-09-04 08:51:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 10:13:59 +00:00
|
|
|
bool NativeTouch(const TouchInput &touch) {
|
|
|
|
if (screenManager) {
|
2017-05-03 22:30:04 +00:00
|
|
|
// Brute force prevent NaNs from getting into the UI system
|
|
|
|
if (my_isnan(touch.x) || my_isnan(touch.y)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-10 21:47:49 +00:00
|
|
|
screenManager->touch(touch);
|
2014-06-15 10:13:59 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 10:13:59 +00:00
|
|
|
bool NativeKey(const KeyInput &key) {
|
2020-08-15 14:25:50 +00:00
|
|
|
// INFO_LOG(SYSTEM, "Key code: %i flags: %i", key.keyCode, key.flags);
|
2014-04-26 05:00:45 +00:00
|
|
|
#if !defined(MOBILE_DEVICE)
|
2014-04-26 05:54:32 +00:00
|
|
|
if (g_Config.bPauseExitsEmulator) {
|
|
|
|
static std::vector<int> pspKeys;
|
|
|
|
pspKeys.clear();
|
|
|
|
if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys)) {
|
|
|
|
if (std::find(pspKeys.begin(), pspKeys.end(), VIRTKEY_PAUSE) != pspKeys.end()) {
|
|
|
|
System_SendMessage("finish", "");
|
2014-06-15 10:13:59 +00:00
|
|
|
return true;
|
2014-04-26 05:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 05:00:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-06-15 11:04:59 +00:00
|
|
|
bool retval = false;
|
2013-07-06 17:08:59 +00:00
|
|
|
if (screenManager)
|
2014-06-15 11:04:59 +00:00
|
|
|
retval = screenManager->key(key);
|
|
|
|
return retval;
|
2013-07-06 17:08:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-27 03:16:52 +00:00
|
|
|
static bool AnalogStickAxis(const AxisInput &axis) {
|
|
|
|
static float history[JOYSTICK_AXIS_MAX+1] = { 0.0f };
|
|
|
|
|
|
|
|
history[axis.axisId] = axis.value;
|
|
|
|
AxisInput axisA = axis;
|
|
|
|
AxisInput axisB = axis;
|
|
|
|
|
|
|
|
switch (axis.axisId) {
|
|
|
|
case JOYSTICK_AXIS_X:
|
|
|
|
case JOYSTICK_AXIS_Y:
|
|
|
|
axisA.axisId = JOYSTICK_AXIS_X;
|
|
|
|
axisB.axisId = JOYSTICK_AXIS_Y;
|
|
|
|
axisA.value = history[JOYSTICK_AXIS_X];
|
|
|
|
axisB.value = history[JOYSTICK_AXIS_Y];
|
|
|
|
break;
|
|
|
|
case JOYSTICK_AXIS_Z:
|
|
|
|
case JOYSTICK_AXIS_RZ:
|
|
|
|
axisA.axisId = JOYSTICK_AXIS_Z;
|
|
|
|
axisB.axisId = JOYSTICK_AXIS_RZ;
|
|
|
|
axisA.value = history[JOYSTICK_AXIS_Z];
|
|
|
|
axisB.value = history[JOYSTICK_AXIS_RZ];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvertAnalogStick(axisA.value, axisB.value);
|
|
|
|
bool retA = screenManager->axis(axisA);
|
|
|
|
bool retB = screenManager->axis(axisB);
|
|
|
|
return retA && retB;
|
|
|
|
}
|
|
|
|
|
2014-07-20 16:30:43 +00:00
|
|
|
bool NativeAxis(const AxisInput &axis) {
|
2021-07-05 10:37:52 +00:00
|
|
|
if (!screenManager) {
|
|
|
|
// Too early.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-11 11:52:04 +00:00
|
|
|
using namespace TiltEventProcessor;
|
|
|
|
|
2021-06-27 03:16:52 +00:00
|
|
|
switch (axis.axisId) {
|
|
|
|
case JOYSTICK_AXIS_X:
|
|
|
|
case JOYSTICK_AXIS_Y:
|
|
|
|
case JOYSTICK_AXIS_Z:
|
|
|
|
case JOYSTICK_AXIS_RZ:
|
|
|
|
return AnalogStickAxis(axis);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-15 10:13:59 +00:00
|
|
|
// only handle tilt events if tilt is enabled.
|
2014-07-20 16:30:43 +00:00
|
|
|
if (g_Config.iTiltInputType == TILT_NULL) {
|
2014-06-15 10:13:59 +00:00
|
|
|
// if tilt events are disabled, then run it through the usual way.
|
2013-11-11 12:37:17 +00:00
|
|
|
if (screenManager) {
|
2014-07-20 16:30:43 +00:00
|
|
|
return screenManager->axis(axis);
|
2014-06-15 10:13:59 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2013-11-11 12:37:17 +00:00
|
|
|
}
|
2013-08-17 11:41:04 +00:00
|
|
|
}
|
2014-06-15 10:13:59 +00:00
|
|
|
|
2014-07-20 16:30:43 +00:00
|
|
|
// create the base coordinate tilt system from the calibration data.
|
|
|
|
// This is static for no particular reason, can be un-static'ed
|
2013-11-11 11:52:04 +00:00
|
|
|
static Tilt baseTilt;
|
2014-06-15 10:13:59 +00:00
|
|
|
baseTilt.x_ = g_Config.fTiltBaseX;
|
|
|
|
baseTilt.y_ = g_Config.fTiltBaseY;
|
2013-11-11 11:52:04 +00:00
|
|
|
|
2014-07-20 16:30:43 +00:00
|
|
|
// figure out what the current tilt orientation is by checking the axis event
|
|
|
|
// This is static, since we need to remember where we last were (in terms of orientation)
|
2013-11-11 11:52:04 +00:00
|
|
|
static Tilt currentTilt;
|
|
|
|
|
2014-07-20 16:30:43 +00:00
|
|
|
// x and y are flipped if we are in landscape orientation. The events are
|
|
|
|
// sent with respect to the portrait coordinate system, while we
|
|
|
|
// take all events in landscape.
|
|
|
|
// see [http://developer.android.com/guide/topics/sensors/sensors_overview.html] for details
|
|
|
|
bool portrait = dp_yres > dp_xres;
|
|
|
|
switch (axis.axisId) {
|
2013-11-11 11:52:04 +00:00
|
|
|
case JOYSTICK_AXIS_ACCELEROMETER_X:
|
2014-07-20 16:30:43 +00:00
|
|
|
if (portrait) {
|
|
|
|
currentTilt.x_ = axis.value;
|
|
|
|
} else {
|
|
|
|
currentTilt.y_ = axis.value;
|
|
|
|
}
|
2013-11-11 11:52:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case JOYSTICK_AXIS_ACCELEROMETER_Y:
|
2014-07-20 16:30:43 +00:00
|
|
|
if (portrait) {
|
|
|
|
currentTilt.y_ = axis.value;
|
|
|
|
} else {
|
|
|
|
currentTilt.x_ = axis.value;
|
|
|
|
}
|
2013-11-11 11:52:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case JOYSTICK_AXIS_ACCELEROMETER_Z:
|
|
|
|
//don't handle this now as only landscape is enabled.
|
|
|
|
//TODO: make this generic.
|
2014-06-15 10:13:59 +00:00
|
|
|
return false;
|
2013-11-11 11:52:04 +00:00
|
|
|
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN1:
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN2:
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN3:
|
|
|
|
case JOYSTICK_AXIS_OUYA_UNKNOWN4:
|
|
|
|
//Don't know how to handle these. Someone should figure it out.
|
|
|
|
//Does the Ouya even have an accelerometer / gyro? I can't find any reference to these
|
|
|
|
//in the Ouya docs...
|
2014-06-15 10:13:59 +00:00
|
|
|
return false;
|
2013-11-11 11:52:04 +00:00
|
|
|
|
|
|
|
default:
|
2015-04-03 09:48:58 +00:00
|
|
|
// Don't take over completely!
|
|
|
|
return screenManager->axis(axis);
|
2013-10-31 10:06:54 +00:00
|
|
|
}
|
2013-11-11 11:52:04 +00:00
|
|
|
|
|
|
|
//figure out the sensitivity of the tilt. (sensitivity is originally 0 - 100)
|
|
|
|
//We divide by 50, so that the rest of the 50 units can be used to overshoot the
|
|
|
|
//target. If you want control, you'd keep the sensitivity ~50.
|
|
|
|
//For games that don't need much control but need fast reactions,
|
|
|
|
//then a value of 70-80 is the way to go.
|
|
|
|
float xSensitivity = g_Config.iTiltSensitivityX / 50.0;
|
|
|
|
float ySensitivity = g_Config.iTiltSensitivityY / 50.0;
|
|
|
|
|
|
|
|
//now transform out current tilt to the calibrated coordinate system
|
|
|
|
Tilt trueTilt = GenTilt(baseTilt, currentTilt, g_Config.bInvertTiltX, g_Config.bInvertTiltY, g_Config.fDeadzoneRadius, xSensitivity, ySensitivity);
|
|
|
|
|
2015-12-21 07:03:34 +00:00
|
|
|
TranslateTiltToInput(trueTilt);
|
2014-06-15 10:13:59 +00:00
|
|
|
return true;
|
2013-07-06 17:08:59 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeMessageReceived(const char *message, const char *value) {
|
2013-03-29 19:51:14 +00:00
|
|
|
// We can only have one message queued.
|
2017-02-27 20:57:46 +00:00
|
|
|
std::lock_guard<std::mutex> lock(pendingMutex);
|
2014-02-13 16:47:02 +00:00
|
|
|
PendingMessage pendingMessage;
|
|
|
|
pendingMessage.msg = message;
|
|
|
|
pendingMessage.value = value;
|
|
|
|
pendingMessages.push_back(pendingMessage);
|
2012-12-01 09:39:20 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 02:54:24 +00:00
|
|
|
void NativeInputBoxReceived(std::function<void(bool, const std::string &)> cb, bool result, const std::string &value) {
|
|
|
|
std::lock_guard<std::mutex> lock(pendingMutex);
|
|
|
|
PendingInputBox pendingMessage;
|
|
|
|
pendingMessage.cb = cb;
|
|
|
|
pendingMessage.result = result;
|
|
|
|
pendingMessage.value = value;
|
|
|
|
pendingInputBoxes.push_back(pendingMessage);
|
|
|
|
}
|
|
|
|
|
2013-12-16 15:21:10 +00:00
|
|
|
void NativeResized() {
|
2017-02-23 08:25:33 +00:00
|
|
|
// NativeResized can come from any thread so we just set a flag, then process it later.
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(G3D, "NativeResized - setting flag");
|
2020-03-01 03:31:58 +00:00
|
|
|
resized = true;
|
2013-12-16 15:21:10 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-04-15 23:30:37 +00:00
|
|
|
void NativeSetRestarting() {
|
|
|
|
restarting = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NativeIsRestarting() {
|
|
|
|
return restarting;
|
|
|
|
}
|
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
void NativeShutdown() {
|
2018-06-01 19:16:07 +00:00
|
|
|
if (screenManager)
|
|
|
|
screenManager->shutdown();
|
2017-04-29 19:02:07 +00:00
|
|
|
delete screenManager;
|
|
|
|
screenManager = nullptr;
|
|
|
|
|
|
|
|
host->ShutdownGraphics();
|
2014-06-29 08:09:15 +00:00
|
|
|
|
2017-05-05 13:53:48 +00:00
|
|
|
#if !PPSSPP_PLATFORM(UWP)
|
2012-11-04 09:56:22 +00:00
|
|
|
delete host;
|
2017-04-29 19:02:07 +00:00
|
|
|
host = nullptr;
|
2017-04-05 12:13:25 +00:00
|
|
|
#endif
|
2019-02-23 09:49:49 +00:00
|
|
|
g_Config.Save("NativeShutdown");
|
2017-04-15 23:30:37 +00:00
|
|
|
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "NativeShutdown called");
|
2014-02-09 22:16:08 +00:00
|
|
|
|
2020-03-01 02:45:14 +00:00
|
|
|
ShutdownWebServer();
|
|
|
|
|
2014-02-09 22:16:08 +00:00
|
|
|
System_SendMessage("finish", "");
|
2017-03-06 09:51:28 +00:00
|
|
|
|
|
|
|
net::Shutdown();
|
|
|
|
|
2018-08-12 22:08:56 +00:00
|
|
|
g_Discord.Shutdown();
|
|
|
|
|
2021-01-04 22:51:34 +00:00
|
|
|
ShaderTranslationShutdown();
|
|
|
|
|
2021-01-01 16:38:27 +00:00
|
|
|
// Avoid shutting this down when restarting core.
|
|
|
|
if (!restarting)
|
|
|
|
LogManager::Shutdown();
|
|
|
|
|
2020-08-15 18:02:07 +00:00
|
|
|
if (logger) {
|
|
|
|
delete logger;
|
|
|
|
logger = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-31 09:12:11 +00:00
|
|
|
// Previously we did exit() here on Android but that makes it hard to do things like restart on backend change.
|
|
|
|
// I think we handle most globals correctly or correct-enough now.
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|