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.
|
|
|
|
|
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
|
|
|
// Linux doesn't like using std::find with std::vector<int> without this :/
|
|
|
|
#if !defined(MOBILE_DEVICE)
|
|
|
|
#include <algorithm>
|
|
|
|
#endif
|
2014-11-25 19:58:19 +00:00
|
|
|
#include <memory>
|
2014-04-26 06:32:43 +00:00
|
|
|
|
2014-06-18 05:36:49 +00:00
|
|
|
#if defined(_WIN32)
|
2014-06-22 12:17:57 +00:00
|
|
|
#include "Windows/DSoundStream.h"
|
|
|
|
#include "Windows/WndMainWindow.h"
|
2014-08-17 14:07:14 +00:00
|
|
|
#include "Windows/D3D9Base.h"
|
2013-12-07 17:06:15 +00:00
|
|
|
#endif
|
2013-04-13 19:24:07 +00:00
|
|
|
|
2014-02-10 11:38:23 +00:00
|
|
|
#include "base/display.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "base/logging.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "base/mutex.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "base/NativeApp.h"
|
|
|
|
#include "file/vfs.h"
|
|
|
|
#include "file/zip_read.h"
|
2013-11-26 13:04:29 +00:00
|
|
|
#include "thread/thread.h"
|
|
|
|
#include "net/http_client.h"
|
2014-12-21 07:14:46 +00:00
|
|
|
#include "gfx_es2/gl_state.h" // should've been only for screenshot - but actually not, cleanup?
|
2013-08-30 12:47:28 +00:00
|
|
|
#include "gfx_es2/draw_text.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "gfx/gl_lost_manager.h"
|
|
|
|
#include "gfx/texture.h"
|
2013-04-18 09:58:54 +00:00
|
|
|
#include "i18n/i18n.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "input/input_state.h"
|
2014-03-22 08:26:28 +00:00
|
|
|
#include "math/fast/fast_math.h"
|
2013-01-10 22:49:33 +00:00
|
|
|
#include "math/math_util.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "math/lin/matrix4x4.h"
|
2014-08-17 10:19:04 +00:00
|
|
|
#include "thin3d/thin3d.h"
|
2013-10-17 14:15:04 +00:00
|
|
|
#include "ui/ui.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "ui/screen.h"
|
2013-03-30 18:23:20 +00:00
|
|
|
#include "ui/ui_context.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "ui/view.h"
|
2013-11-26 13:04:29 +00:00
|
|
|
#include "util/text/utf8.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
|
2014-03-22 08:26:28 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/LogManager.h"
|
2014-12-20 16:31:56 +00:00
|
|
|
#include "Common/MemArena.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Core/Config.h"
|
2014-06-22 12:17:57 +00:00
|
|
|
#include "Core/Core.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "Core/Host.h"
|
|
|
|
#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"
|
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"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "ui_atlas.h"
|
|
|
|
#include "EmuScreen.h"
|
2013-04-13 19:24:07 +00:00
|
|
|
#include "GameInfoCache.h"
|
2014-03-01 15:09:16 +00:00
|
|
|
#include "HostTypes.h"
|
2014-08-22 23:52:46 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "GPU/Directx9/helper/dx_state.h"
|
|
|
|
#endif
|
2013-06-22 20:27:59 +00:00
|
|
|
#include "UI/OnScreenDisplay.h"
|
2013-10-17 14:15:04 +00:00
|
|
|
#include "UI/MiscScreens.h"
|
2013-11-11 11:52:04 +00:00
|
|
|
#include "UI/TiltEventProcessor.h"
|
2014-06-22 15:02:04 +00:00
|
|
|
#include "UI/BackgroundAudio.h"
|
2013-06-01 21:34:50 +00:00
|
|
|
|
2014-04-26 05:54:32 +00:00
|
|
|
#if !defined(MOBILE_DEVICE)
|
|
|
|
#include "Common/KeyMap.h"
|
|
|
|
#endif
|
|
|
|
|
2014-12-06 00:17:54 +00:00
|
|
|
#ifdef __SYMBIAN32__
|
2014-11-25 20:00:35 +00:00
|
|
|
#define unique_ptr auto_ptr
|
|
|
|
#endif
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
// The new UI framework, for initialization
|
|
|
|
|
|
|
|
static UI::Theme ui_theme;
|
|
|
|
|
2013-03-21 19:52:33 +00:00
|
|
|
#ifdef ARM
|
2013-03-30 20:14:18 +00:00
|
|
|
#include "../../android/jni/ArmEmitterTest.h"
|
2013-03-21 19:52:33 +00:00
|
|
|
#endif
|
2012-11-23 18:41:35 +00:00
|
|
|
|
2013-06-25 21:18:16 +00:00
|
|
|
#ifdef IOS
|
|
|
|
#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
|
|
|
|
|
2013-11-03 00:13:17 +00:00
|
|
|
// https://github.com/richq/android-ndk-profiler
|
|
|
|
#ifdef ANDROID_NDK_PROFILER
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "android/android-ndk-profiler/prof.h"
|
|
|
|
#endif
|
|
|
|
|
2014-08-17 14:07:14 +00:00
|
|
|
Thin3DTexture *uiTexture;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
ScreenManager *screenManager;
|
2012-11-01 15:19:01 +00:00
|
|
|
std::string config_filename;
|
|
|
|
|
2013-04-24 08:43:00 +00:00
|
|
|
#ifdef IOS
|
2013-12-01 19:28:20 +00:00
|
|
|
bool iosCanUseJit;
|
2013-04-24 08:43:00 +00:00
|
|
|
#endif
|
|
|
|
|
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;
|
2014-02-13 16:47:02 +00:00
|
|
|
|
|
|
|
struct PendingMessage {
|
|
|
|
std::string msg;
|
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static recursive_mutex pendingMutex;
|
|
|
|
static std::vector<PendingMessage> pendingMessages;
|
2014-08-17 10:19:04 +00:00
|
|
|
static Thin3DContext *thin3d;
|
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
|
|
|
|
|
2014-11-09 11:03:04 +00:00
|
|
|
Thin3DContext *GetThin3D() {
|
|
|
|
return thin3d;
|
|
|
|
}
|
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
std::thread *graphicsLoadThread;
|
2013-03-29 19:51:14 +00:00
|
|
|
|
2014-02-04 11:09:14 +00:00
|
|
|
class AndroidLogger : public LogListener {
|
2012-11-01 15:19:01 +00:00
|
|
|
public:
|
2014-02-04 11:09:14 +00:00
|
|
|
void Log(LogTypes::LOG_LEVELS level, const char *msg) {
|
|
|
|
switch (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:
|
|
|
|
ILOG("%s", msg);
|
|
|
|
break;
|
|
|
|
case LogTypes::LERROR:
|
|
|
|
ELOG("%s", msg);
|
|
|
|
break;
|
|
|
|
case LogTypes::LWARNING:
|
|
|
|
WLOG("%s", msg);
|
|
|
|
break;
|
|
|
|
case LogTypes::LNOTICE:
|
|
|
|
default:
|
|
|
|
ILOG("%s", msg);
|
|
|
|
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
|
2013-03-29 19:03:11 +00:00
|
|
|
#ifndef _WIN32
|
2012-11-01 15:19:01 +00:00
|
|
|
static AndroidLogger *logger = 0;
|
2013-03-29 19:03:11 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
std::string boot_filename = "";
|
|
|
|
|
2015-01-11 11:02:49 +00:00
|
|
|
void NativeHost::InitSound() {
|
2013-06-25 21:18:16 +00:00
|
|
|
#ifdef 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() {
|
2013-06-25 21:18:16 +00:00
|
|
|
#ifdef 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") {
|
|
|
|
sprintf(temp, "%i", 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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(temp, "%i", scale);
|
2014-07-18 19:49:54 +00:00
|
|
|
return std::string(temp);
|
2015-01-11 16:28:46 +00:00
|
|
|
} else if (query == "force44khz") {
|
|
|
|
return std::string("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) {
|
|
|
|
PlayBackgroundAudio();
|
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
|
2015-01-11 20:00: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
|
|
|
|
2013-03-21 19:52:33 +00:00
|
|
|
#if defined(ARM) && defined(ANDROID)
|
2013-02-11 22:10:11 +00:00
|
|
|
ArmEmitterTest();
|
2013-03-02 00:36:18 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeInit(int argc, const char *argv[],
|
2014-09-24 21:24:23 +00:00
|
|
|
const char *savegame_directory, const char *external_directory, const char *installID, bool fs) {
|
2013-11-03 00:13:17 +00:00
|
|
|
#ifdef ANDROID_NDK_PROFILER
|
|
|
|
setenv("CPUPROFILE_FREQUENCY", "500", 1);
|
|
|
|
setenv("CPUPROFILE", "/sdcard/gmon.out", 1);
|
|
|
|
monstartup("ppsspp_jni.so");
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2014-03-23 09:05:11 +00:00
|
|
|
// Sets both FZ and DefaultNaN on ARM, flipping some ARM implementations into "RunFast" mode for VFP.
|
|
|
|
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0274h/Babffifj.html
|
|
|
|
// Do we need to do this on all threads?
|
|
|
|
// Also, the FZ thing may actually be a little bit dangerous, I'm not sure how compliant the MIPS
|
|
|
|
// CPU is with denormal handling. Needs testing. Default-NAN should be reasonably safe though.
|
|
|
|
FPU_SetFastMode();
|
|
|
|
|
2013-07-27 11:07:34 +00:00
|
|
|
bool skipLogo = false;
|
2013-04-25 08:41:43 +00:00
|
|
|
setlocale( LC_ALL, "C" );
|
2012-11-04 09:56:22 +00:00
|
|
|
std::string user_data_path = savegame_directory;
|
2014-02-13 16:47:02 +00:00
|
|
|
pendingMessages.clear();
|
2013-07-09 21:27:25 +00:00
|
|
|
#ifdef IOS
|
2013-03-16 06:52:52 +00:00
|
|
|
user_data_path += "/";
|
2013-07-09 21:27:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// We want this to be FIRST.
|
2013-11-21 10:11:14 +00:00
|
|
|
#ifdef USING_QT_UI
|
|
|
|
VFSRegister("", new AssetsAssetReader());
|
2013-11-24 06:57:59 +00:00
|
|
|
#elif defined(BLACKBERRY) || defined(IOS)
|
2013-07-09 21:27:25 +00:00
|
|
|
// Packed assets are included in app
|
|
|
|
VFSRegister("", new DirectoryAssetReader(external_directory));
|
2013-12-07 05:06:12 +00:00
|
|
|
#elif defined(__APPLE__) || (defined(__linux__) && !defined(ANDROID))
|
|
|
|
VFSRegister("", new DirectoryAssetReader((File::GetExeDirectory() + "assets/").c_str()));
|
|
|
|
VFSRegister("", new DirectoryAssetReader((File::GetExeDirectory()).c_str()));
|
2014-08-05 09:04:34 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader("/usr/share/ppsspp/assets/"));
|
2012-11-07 17:22:10 +00:00
|
|
|
#else
|
2012-11-04 09:56:22 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader("assets/"));
|
2013-04-11 05:14:44 +00:00
|
|
|
#endif
|
2013-07-10 01:46:27 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader(savegame_directory));
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-03-01 15:09:16 +00:00
|
|
|
#if defined(MOBILE_DEVICE) || !defined(USING_QT_UI)
|
2012-11-04 09:56:22 +00:00
|
|
|
host = new NativeHost();
|
2014-03-01 15:09:16 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-10-12 23:02:03 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
g_Config.internalDataDirectory = savegame_directory;
|
|
|
|
// 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.
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.memStickDirectory = std::string(external_directory) + "/";
|
2013-10-12 23:08:39 +00:00
|
|
|
g_Config.flash0Directory = std::string(external_directory) + "/flash0/";
|
2014-06-17 17:42:31 +00:00
|
|
|
#elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(MAEMO) || defined(IOS)
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.memStickDirectory = user_data_path;
|
2013-10-12 23:08:39 +00:00
|
|
|
g_Config.flash0Directory = std::string(external_directory) + "/flash0/";
|
2013-10-12 23:02:03 +00:00
|
|
|
#elif !defined(_WIN32)
|
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";
|
|
|
|
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.memStickDirectory = config + "/ppsspp/";
|
2013-12-07 05:06:12 +00:00
|
|
|
g_Config.flash0Directory = File::GetExeDirectory() + "/flash0/";
|
2013-10-12 23:02:03 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-29 19:03:11 +00:00
|
|
|
#ifndef _WIN32
|
2012-11-04 09:56:22 +00:00
|
|
|
logger = new AndroidLogger();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
LogManager::Init();
|
|
|
|
LogManager *logman = LogManager::GetInstance();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-10-12 23:02:03 +00:00
|
|
|
g_Config.AddSearchPath(user_data_path);
|
2014-10-19 21:20:51 +00:00
|
|
|
g_Config.AddSearchPath(g_Config.memStickDirectory + "PSP/SYSTEM/");
|
|
|
|
g_Config.SetDefaultPath(g_Config.memStickDirectory + "PSP/SYSTEM/");
|
2013-10-12 23:02:03 +00:00
|
|
|
g_Config.Load();
|
2013-06-17 23:21:20 +00:00
|
|
|
g_Config.externalDirectory = external_directory;
|
2013-04-01 01:22:27 +00:00
|
|
|
#endif
|
2012-12-25 07:34:19 +00:00
|
|
|
|
2013-06-19 11:13:23 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
// On Android, create a PSP directory tree in the external_directory,
|
2013-11-29 15:33:17 +00:00
|
|
|
// to hopefully reduce confusion a bit.
|
2014-10-19 21:20:51 +00:00
|
|
|
ILOG("Creating %s", (g_Config.memStickDirectory + "PSP").c_str());
|
|
|
|
mkDir((g_Config.memStickDirectory + "PSP").c_str());
|
|
|
|
mkDir((g_Config.memStickDirectory + "PSP/SAVEDATA").c_str());
|
|
|
|
mkDir((g_Config.memStickDirectory + "PSP/GAME").c_str());
|
2013-06-19 11:13:23 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
const char *fileToLog = 0;
|
2013-04-01 01:16:29 +00:00
|
|
|
const char *stateToLoad = 0;
|
2012-12-26 23:18:45 +00:00
|
|
|
|
2012-12-01 22:20:08 +00:00
|
|
|
bool gfxLog = false;
|
2012-11-04 10:31:06 +00:00
|
|
|
// Parse command line
|
|
|
|
LogTypes::LOG_LEVELS logLevel = LogTypes::LINFO;
|
|
|
|
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.
|
2012-11-04 10:31:06 +00:00
|
|
|
logLevel = LogTypes::LDEBUG;
|
|
|
|
break;
|
2012-12-01 22:20:08 +00:00
|
|
|
case 'g':
|
|
|
|
gfxLog = true;
|
|
|
|
break;
|
2012-12-05 06:55:24 +00:00
|
|
|
case 'j':
|
2013-02-16 08:49:33 +00:00
|
|
|
g_Config.bJit = true;
|
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':
|
2013-02-16 08:49:33 +00:00
|
|
|
g_Config.bJit = false;
|
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 '-':
|
|
|
|
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="))
|
|
|
|
stateToLoad = 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
|
2012-12-26 23:18:45 +00:00
|
|
|
break;
|
2012-11-04 10:31:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-01 22:38:18 +00:00
|
|
|
if (boot_filename.empty()) {
|
|
|
|
boot_filename = argv[i];
|
2013-07-27 11:07:34 +00:00
|
|
|
skipLogo = true;
|
2013-07-26 12:42:38 +00:00
|
|
|
|
2014-11-25 19:58:19 +00:00
|
|
|
std::unique_ptr<FileLoader> fileLoader(ConstructFileLoader(boot_filename));
|
|
|
|
if (!fileLoader->Exists()) {
|
2012-12-01 22:38:18 +00:00
|
|
|
fprintf(stderr, "File not found: %s\n", boot_filename.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Can only boot one file");
|
2012-11-04 10:31:06 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-26 23:18:45 +00:00
|
|
|
if (fileToLog != NULL)
|
|
|
|
LogManager::GetInstance()->ChangeFileLog(fileToLog);
|
|
|
|
|
2013-04-01 01:22:27 +00:00
|
|
|
#ifndef _WIN32
|
2012-11-01 15:19:01 +00:00
|
|
|
if (g_Config.currentDirectory == "") {
|
2013-02-20 03:12:03 +00:00
|
|
|
#if defined(ANDROID)
|
2012-11-01 15:19:01 +00:00
|
|
|
g_Config.currentDirectory = external_directory;
|
2014-06-17 17:42:31 +00:00
|
|
|
#elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(MAEMO) || defined(IOS) || defined(_WIN32)
|
2013-02-20 03:12:03 +00:00
|
|
|
g_Config.currentDirectory = savegame_directory;
|
2012-11-01 15:19:01 +00:00
|
|
|
#else
|
2014-06-25 06:10:00 +00:00
|
|
|
if (getenv("HOME") != NULL)
|
|
|
|
g_Config.currentDirectory = getenv("HOME");
|
|
|
|
else
|
|
|
|
g_Config.currentDirectory = "./";
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
{
|
|
|
|
LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i;
|
|
|
|
logman->SetEnable(type, true);
|
2012-12-05 03:45:28 +00:00
|
|
|
logman->SetLogLevel(type, gfxLog && i == LogTypes::G3D ? LogTypes::LDEBUG : logLevel);
|
2012-11-01 15:19:01 +00:00
|
|
|
#ifdef ANDROID
|
2012-11-04 09:56:22 +00:00
|
|
|
logman->AddListener(type, logger);
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif
|
2012-11-04 09:56:22 +00:00
|
|
|
}
|
2012-11-04 10:31:06 +00:00
|
|
|
// Special hack for G3D as it's very spammy. Need to make a flag for this.
|
2012-12-01 22:20:08 +00:00
|
|
|
if (!gfxLog)
|
|
|
|
logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR);
|
2013-11-29 15:33:17 +00:00
|
|
|
#endif
|
2014-02-12 23:31:54 +00:00
|
|
|
// 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).
|
2014-10-19 21:20:51 +00:00
|
|
|
const std::string langOverridePath = g_Config.memStickDirectory + "PSP/SYSTEM/lang/";
|
2014-02-12 23:31:54 +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);
|
2013-04-01 01:16:29 +00:00
|
|
|
|
2013-08-30 17:33:12 +00:00
|
|
|
I18NCategory *d = 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.
|
2013-08-30 18:19:03 +00:00
|
|
|
#ifdef _WIN32
|
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);
|
|
|
|
g_Config.sFont = d->T("Font", "Roboto");
|
2013-08-30 18:19:03 +00:00
|
|
|
#endif
|
2013-04-18 09:58:54 +00:00
|
|
|
|
2013-04-01 01:16:29 +00:00
|
|
|
if (!boot_filename.empty() && stateToLoad != NULL)
|
|
|
|
SaveState::Load(stateToLoad);
|
2013-10-17 14:44:09 +00:00
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
g_gameInfoCache.Init();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager = new ScreenManager();
|
2013-07-27 11:07:34 +00:00
|
|
|
if (skipLogo) {
|
|
|
|
screenManager->switchScreen(new EmuScreen(boot_filename));
|
|
|
|
} 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
|
|
|
|
|
|
|
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)
|
2014-09-24 21:24:23 +00:00
|
|
|
MainWindow* mainWindow = new MainWindow(0,fs);
|
2014-03-01 15:09:16 +00:00
|
|
|
mainWindow->show();
|
|
|
|
host = new QtHost(mainWindow);
|
|
|
|
#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.
|
|
|
|
gl_lost_manager_init();
|
2013-07-16 20:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeInitGraphics() {
|
2014-03-23 09:05:11 +00:00
|
|
|
FPU_SetFastMode();
|
|
|
|
|
2014-08-23 07:48:08 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
// Force backend to GL
|
|
|
|
g_Config.iGPUBackend = GPU_BACKEND_OPENGL;
|
|
|
|
#endif
|
|
|
|
|
2014-08-17 14:07:14 +00:00
|
|
|
if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) {
|
|
|
|
thin3d = T3DCreateGLContext();
|
|
|
|
CheckGLExtensions();
|
|
|
|
} else {
|
2014-08-23 07:48:08 +00:00
|
|
|
#ifdef _WIN32
|
2014-08-17 14:07:14 +00:00
|
|
|
thin3d = D3D9_CreateThin3DContext();
|
2014-08-23 07:48:08 +00:00
|
|
|
#endif
|
2014-08-17 14:07:14 +00:00
|
|
|
}
|
2014-08-17 10:19:04 +00:00
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
ui_draw2d.SetAtlas(&ui_atlas);
|
2013-08-30 12:47:28 +00:00
|
|
|
ui_draw2d_front.SetAtlas(&ui_atlas);
|
2013-07-16 20:50:53 +00:00
|
|
|
|
2013-06-02 21:46:03 +00:00
|
|
|
// memset(&ui_theme, 0, sizeof(ui_theme));
|
2013-06-01 21:34:50 +00:00
|
|
|
// New style theme
|
2013-08-30 18:19:03 +00:00
|
|
|
#ifdef _WIN32
|
2013-08-31 08:36:52 +00:00
|
|
|
ui_theme.uiFont = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 22);
|
|
|
|
ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 15);
|
|
|
|
ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 12);
|
2013-08-30 18:19:03 +00:00
|
|
|
#else
|
|
|
|
ui_theme.uiFont = UI::FontStyle(UBUNTU24, "", 20);
|
|
|
|
ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, "", 14);
|
|
|
|
ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, "", 11);
|
|
|
|
#endif
|
2013-08-30 12:47:28 +00:00
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
ui_theme.checkOn = I_CHECKEDBOX;
|
|
|
|
ui_theme.checkOff = I_SQUARE;
|
2013-08-19 22:49:25 +00:00
|
|
|
ui_theme.whiteImage = I_SOLIDWHITE;
|
2013-07-18 08:26:29 +00:00
|
|
|
ui_theme.sliderKnob = I_CIRCLE;
|
2013-08-16 14:48:43 +00:00
|
|
|
ui_theme.dropShadow4Grid = I_DROP_SHADOW;
|
|
|
|
|
2013-06-08 20:42:31 +00:00
|
|
|
ui_theme.itemStyle.background = UI::Drawable(0x55000000);
|
|
|
|
ui_theme.itemStyle.fgColor = 0xFFFFFFFF;
|
2013-08-20 11:04:20 +00:00
|
|
|
ui_theme.itemFocusedStyle.background = UI::Drawable(0xFFedc24c);
|
|
|
|
ui_theme.itemDownStyle.background = UI::Drawable(0xFFbd9939);
|
2013-08-20 16:18:30 +00:00
|
|
|
ui_theme.itemDownStyle.fgColor = 0xFFFFFFFF;
|
2013-08-16 14:48:43 +00:00
|
|
|
ui_theme.itemDisabledStyle.background = UI::Drawable(0x55E0D4AF);
|
2013-10-29 09:21:47 +00:00
|
|
|
ui_theme.itemDisabledStyle.fgColor = 0x80EEEEEE;
|
2013-10-08 13:52:21 +00:00
|
|
|
ui_theme.itemHighlightedStyle.background = UI::Drawable(0x55bdBB39);
|
2013-10-08 13:38:50 +00:00
|
|
|
ui_theme.itemHighlightedStyle.fgColor = 0xFFFFFFFF;
|
2013-06-01 21:34:50 +00:00
|
|
|
|
2013-08-16 14:48:43 +00:00
|
|
|
ui_theme.buttonStyle = ui_theme.itemStyle;
|
|
|
|
ui_theme.buttonFocusedStyle = ui_theme.itemFocusedStyle;
|
|
|
|
ui_theme.buttonDownStyle = ui_theme.itemDownStyle;
|
|
|
|
ui_theme.buttonDisabledStyle = ui_theme.itemDisabledStyle;
|
2013-10-07 16:16:02 +00:00
|
|
|
ui_theme.buttonHighlightedStyle = ui_theme.itemHighlightedStyle;
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2013-08-20 11:04:20 +00:00
|
|
|
ui_theme.popupTitle.fgColor = 0xFFE3BE59;
|
2013-12-10 22:19:37 +00:00
|
|
|
|
|
|
|
#ifdef GOLD
|
|
|
|
ui_theme.itemFocusedStyle.background = UI::Drawable(0xFF4cc2ed);
|
|
|
|
ui_theme.itemDownStyle.background = UI::Drawable(0xFF39a9ee);
|
|
|
|
ui_theme.itemDisabledStyle.background = UI::Drawable(0x55AFD4E0);
|
|
|
|
ui_theme.itemHighlightedStyle.background = UI::Drawable(0x5539BBbd);
|
|
|
|
|
|
|
|
ui_theme.popupTitle.fgColor = 0xFF59BEE3;
|
|
|
|
#endif
|
|
|
|
|
2014-08-17 10:19:04 +00:00
|
|
|
ui_draw2d.Init(thin3d);
|
|
|
|
ui_draw2d_front.Init(thin3d);
|
2013-01-11 22:46:56 +00:00
|
|
|
|
2013-12-19 15:30:39 +00:00
|
|
|
#ifdef USING_QT_UI
|
2014-09-06 11:50:00 +00:00
|
|
|
uiTexture = thin3d->CreateTextureFromFile("ui_atlas_lowmem.zim", T3DImageType::ZIM);
|
2014-08-17 14:07:14 +00:00
|
|
|
if (!uiTexture) {
|
2013-12-19 15:30:39 +00:00
|
|
|
#else
|
2014-09-06 11:50:00 +00:00
|
|
|
uiTexture = thin3d->CreateTextureFromFile("ui_atlas.zim", T3DImageType::ZIM);
|
2014-08-17 14:07:14 +00:00
|
|
|
if (!uiTexture) {
|
2013-12-19 15:30:39 +00:00
|
|
|
#endif
|
2013-03-30 07:34:27 +00:00
|
|
|
PanicAlert("Failed to load ui_atlas.zim.\n\nPlace it in the directory \"assets\" under your PPSSPP directory.");
|
|
|
|
ELOG("Failed to load ui_atlas.zim");
|
2014-10-15 20:33:38 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
UINT ExitCode = 0;
|
|
|
|
ExitProcess(ExitCode);
|
|
|
|
#endif
|
2012-11-04 09:56:22 +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
|
|
|
|
|
|
|
uiContext->Init(thin3d, thin3d->GetShaderSetPreset(SS_TEXTURE_COLOR_2D), thin3d->GetShaderSetPreset(SS_COLOR_2D), uiTexture, &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);
|
2014-08-17 10:19:04 +00:00
|
|
|
screenManager->setThin3DContext(thin3d);
|
2013-03-30 18:23:20 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2013-01-11 23:00:18 +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);
|
2015-01-11 20:00:56 +00:00
|
|
|
winAudioBackend->Init(MainWindow::GetHWND(), &Win32Mix, 44100);
|
2014-06-22 12:23:06 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
void NativeShutdownGraphics() {
|
2014-06-22 12:23:06 +00:00
|
|
|
#ifdef _WIN32
|
2015-01-11 20:00:56 +00:00
|
|
|
delete winAudioBackend;
|
|
|
|
winAudioBackend = NULL;
|
2014-06-22 12:23:06 +00:00
|
|
|
#endif
|
2014-06-22 12:17:57 +00:00
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
screenManager->deviceLost();
|
|
|
|
|
|
|
|
g_gameInfoCache.Clear();
|
|
|
|
|
2014-08-17 14:07:14 +00:00
|
|
|
uiTexture->Release();
|
2013-07-16 20:50:53 +00:00
|
|
|
|
|
|
|
delete uiContext;
|
|
|
|
uiContext = NULL;
|
|
|
|
|
|
|
|
ui_draw2d.Shutdown();
|
|
|
|
ui_draw2d_front.Shutdown();
|
|
|
|
|
2014-08-17 10:19:04 +00:00
|
|
|
thin3d->Release();
|
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
|
|
|
|
2014-12-21 07:14:46 +00:00
|
|
|
#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE))
|
2014-12-29 04:52:44 +00:00
|
|
|
std::string path = GetSysDirectory(DIRECTORY_SCREENSHOT);
|
|
|
|
while (path.length() > 0 && path.back() == '/') {
|
|
|
|
path.resize(path.size() - 1);
|
|
|
|
}
|
|
|
|
if (!File::Exists(path)) {
|
|
|
|
File::CreateDir(path);
|
|
|
|
}
|
2013-06-22 20:27:59 +00:00
|
|
|
|
|
|
|
// First, find a free filename.
|
|
|
|
int i = 0;
|
|
|
|
|
2014-02-17 22:43:58 +00:00
|
|
|
std::string gameId = g_paramSFO.GetValueString("DISC_ID");
|
2014-03-01 21:31:23 +00:00
|
|
|
if (gameId.empty()) {
|
|
|
|
gameId = "MENU";
|
|
|
|
}
|
2014-02-17 22:43:58 +00:00
|
|
|
|
2014-09-13 22:14:11 +00:00
|
|
|
char filename[2048];
|
2013-07-07 18:56:18 +00:00
|
|
|
while (i < 10000){
|
2014-02-17 22:43:58 +00:00
|
|
|
if (g_Config.bScreenshotsAsPNG)
|
2014-12-29 04:52:44 +00:00
|
|
|
snprintf(filename, sizeof(filename), "%s/%s_%05d.png", path.c_str(), gameId.c_str(), i);
|
2013-07-07 18:56:18 +00:00
|
|
|
else
|
2014-12-29 04:52:44 +00:00
|
|
|
snprintf(filename, sizeof(filename), "%s/%s_%05d.jpg", path.c_str(), gameId.c_str(), i);
|
2013-06-22 20:27:59 +00:00
|
|
|
FileInfo info;
|
2014-02-17 22:43:58 +00:00
|
|
|
if (!getFileInfo(filename, &info))
|
2013-06-22 20:27:59 +00:00
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2014-12-21 07:14:46 +00:00
|
|
|
bool success = TakeGameScreenshot(filename, g_Config.bScreenshotsAsPNG ? SCREENSHOT_PNG : SCREENSHOT_JPG, SCREENSHOT_DISPLAY);
|
2014-11-02 21:29:44 +00:00
|
|
|
if (success) {
|
|
|
|
osm.Show(filename);
|
|
|
|
} else {
|
|
|
|
I18NCategory *err = GetI18NCategory("Error");
|
|
|
|
osm.Show(err->T("Could not save screenshot file"));
|
|
|
|
}
|
2013-06-22 20:27:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-10 11:38:23 +00:00
|
|
|
void DrawDownloadsOverlay(UIContext &dc) {
|
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();
|
|
|
|
if (progress.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t colors[4] = {
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFCCCCCC,
|
|
|
|
0xFFAAAAAA,
|
|
|
|
0xFF777777,
|
|
|
|
};
|
|
|
|
|
2014-02-10 11:38:23 +00:00
|
|
|
dc.Begin();
|
2013-11-29 15:33:17 +00:00
|
|
|
int h = 5;
|
2013-12-08 20:02:37 +00:00
|
|
|
for (size_t i = 0; i < progress.size(); i++) {
|
2014-02-10 11:38:23 +00:00
|
|
|
float barWidth = 10 + (dc.GetBounds().w - 10) * progress[i];
|
2013-11-29 15:33:17 +00:00
|
|
|
Bounds bounds(0, h * i, barWidth, h);
|
|
|
|
UI::Drawable solid(colors[i & 3]);
|
2014-02-10 11:38:23 +00:00
|
|
|
dc.FillRect(solid, bounds);
|
2013-11-29 15:33:17 +00:00
|
|
|
}
|
2014-02-10 11:38:23 +00:00
|
|
|
dc.End();
|
|
|
|
dc.Flush();
|
2013-11-29 15:33:17 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeRender() {
|
2013-11-20 13:42:48 +00:00
|
|
|
g_GameManager.Update();
|
|
|
|
|
2015-01-25 23:25:48 +00:00
|
|
|
thin3d->Clear(T3DClear::COLOR | T3DClear::DEPTH | T3DClear::STENCIL, 0xFF000000, 0.0f, 0);
|
|
|
|
|
2014-08-17 14:07:14 +00:00
|
|
|
T3DViewport viewport;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
viewport.Width = pixel_xres;
|
|
|
|
viewport.Height = pixel_yres;
|
|
|
|
viewport.MaxDepth = 1.0;
|
|
|
|
viewport.MinDepth = 0.0;
|
|
|
|
thin3d->SetViewports(1, &viewport);
|
|
|
|
|
|
|
|
if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) {
|
|
|
|
glstate.depthWrite.set(GL_TRUE);
|
|
|
|
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
glstate.Restore();
|
2014-08-17 19:29:36 +00:00
|
|
|
} else {
|
2014-08-23 07:48:08 +00:00
|
|
|
#ifdef _WIN32
|
2014-08-22 23:52:46 +00:00
|
|
|
DX9::dxstate.depthWrite.set(true);
|
|
|
|
DX9::dxstate.colorMask.set(true, true, true, true);
|
|
|
|
DX9::dxstate.Restore();
|
2014-08-23 07:48:08 +00:00
|
|
|
#endif
|
2014-08-17 14:07:14 +00:00
|
|
|
}
|
2013-01-10 22:49:33 +00:00
|
|
|
|
2014-08-17 14:07:14 +00:00
|
|
|
thin3d->SetTargetSize(pixel_xres, pixel_yres);
|
2013-03-29 17:50:08 +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.
|
2012-11-04 09:56:22 +00:00
|
|
|
Matrix4x4 ortho;
|
2014-08-23 08:49:40 +00:00
|
|
|
if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) {
|
|
|
|
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
2014-08-25 19:33:24 +00:00
|
|
|
Matrix4x4 translation;
|
|
|
|
translation.setTranslation(Vec3(-0.5f, -0.5f, 0.0f));
|
|
|
|
ortho = translation * ortho;
|
2014-08-23 08:49:40 +00:00
|
|
|
} else {
|
|
|
|
ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
}
|
2014-02-10 14:55:21 +00:00
|
|
|
|
2014-08-17 10:19:04 +00:00
|
|
|
ui_draw2d.SetDrawMatrix(ortho);
|
|
|
|
ui_draw2d_front.SetDrawMatrix(ortho);
|
|
|
|
|
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
|
|
|
|
2013-11-29 15:33:17 +00:00
|
|
|
DrawDownloadsOverlay(*screenManager->getUIContext());
|
|
|
|
|
2013-06-22 20:27:59 +00:00
|
|
|
if (g_TakeScreenshot) {
|
|
|
|
TakeScreenshot();
|
|
|
|
}
|
2014-12-25 16:41:12 +00:00
|
|
|
|
2014-12-27 17:56:21 +00:00
|
|
|
if (resized) {
|
|
|
|
resized = false;
|
|
|
|
if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) {
|
2014-12-25 18:10:26 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
D3D9_Resize(0);
|
|
|
|
#endif
|
|
|
|
}
|
2014-12-25 16:41:12 +00:00
|
|
|
}
|
2015-01-25 23:25:48 +00:00
|
|
|
|
|
|
|
thin3d->SetScissorEnabled(false);
|
|
|
|
if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) {
|
|
|
|
glstate.depthWrite.set(GL_TRUE);
|
|
|
|
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
} else {
|
|
|
|
#ifdef _WIN32
|
|
|
|
DX9::dxstate.depthWrite.set(true);
|
|
|
|
DX9::dxstate.colorMask.set(true, true, true, true);
|
|
|
|
#endif
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeUpdate(InputState &input) {
|
2013-03-29 19:51:14 +00:00
|
|
|
{
|
|
|
|
lock_guard lock(pendingMutex);
|
2014-02-13 16:47:02 +00:00
|
|
|
for (size_t i = 0; i < pendingMessages.size(); i++) {
|
2014-05-19 21:29:35 +00:00
|
|
|
HandleGlobalMessage(pendingMessages[i].msg, pendingMessages[i].value);
|
2014-02-13 16:47:02 +00:00
|
|
|
screenManager->sendMessage(pendingMessages[i].msg.c_str(), pendingMessages[i].value.c_str());
|
2013-03-29 19:51:14 +00:00
|
|
|
}
|
2014-02-13 16:47:02 +00:00
|
|
|
pendingMessages.clear();
|
2013-03-29 19:51:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 13:04:29 +00:00
|
|
|
g_DownloadManager.Update();
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->update(input);
|
2013-07-11 12:29:56 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeDeviceLost() {
|
2013-04-14 09:58:28 +00:00
|
|
|
g_gameInfoCache.Clear();
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->deviceLost();
|
2012-11-01 15:19:01 +00:00
|
|
|
gl_lost();
|
2013-03-10 16:50:25 +00:00
|
|
|
glstate.Restore();
|
2012-11-01 15:19:01 +00:00
|
|
|
// Should dirty EVERYTHING
|
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
bool NativeIsAtTopLevel() {
|
2013-09-04 08:51:14 +00:00
|
|
|
Screen *currentScreen = screenManager->topScreen();
|
|
|
|
if (currentScreen) {
|
|
|
|
bool top = currentScreen->isTopLevel();
|
|
|
|
ILOG("Screen toplevel: %i", (int)top);
|
|
|
|
return currentScreen->isTopLevel();
|
|
|
|
} else {
|
|
|
|
ELOG("No current screen");
|
|
|
|
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) {
|
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) {
|
2013-10-31 10:06:54 +00:00
|
|
|
// ILOG("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
|
2013-07-15 15:41:24 +00:00
|
|
|
g_buttonTracker.Process(key);
|
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
|
|
|
}
|
|
|
|
|
2014-07-20 16:30:43 +00:00
|
|
|
bool NativeAxis(const AxisInput &axis) {
|
2013-11-11 11:52:04 +00:00
|
|
|
using namespace TiltEventProcessor;
|
|
|
|
|
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:
|
2014-06-15 10:13:59 +00:00
|
|
|
return false;
|
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);
|
|
|
|
|
|
|
|
//now send the appropriate tilt event
|
|
|
|
switch (g_Config.iTiltInputType) {
|
|
|
|
case TILT_ANALOG:
|
|
|
|
GenerateAnalogStickEvent(trueTilt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TILT_DPAD:
|
|
|
|
GenerateDPadEvent(trueTilt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TILT_ACTION_BUTTON:
|
|
|
|
GenerateActionButtonEvent(trueTilt);
|
|
|
|
break;
|
2013-10-31 10:06:54 +00:00
|
|
|
}
|
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.
|
|
|
|
lock_guard 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
|
|
|
}
|
|
|
|
|
2013-12-16 15:21:10 +00:00
|
|
|
void NativeResized() {
|
2014-12-25 16:41:12 +00:00
|
|
|
resized = true;
|
|
|
|
|
2014-02-10 14:55:21 +00:00
|
|
|
if (uiContext) {
|
2014-02-10 15:08:19 +00:00
|
|
|
// 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.
|
2014-02-10 14:55:21 +00:00
|
|
|
uiContext->SetBounds(Bounds(0, 0, dp_xres, dp_yres));
|
2014-02-10 15:08:19 +00:00
|
|
|
// uiContext->SetBounds(Bounds(dp_xres/2, 0, dp_xres / 2, dp_yres / 2));
|
2014-07-15 10:26:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// OSX 10.6 and SDL 1.2 bug.
|
2014-07-25 15:36:21 +00:00
|
|
|
#if defined(__APPLE__) && !defined(USING_QT_UI)
|
2014-07-15 10:26:15 +00:00
|
|
|
static int dp_xres_old=dp_xres;
|
|
|
|
if (dp_xres != dp_xres_old) {
|
2014-08-23 12:24:24 +00:00
|
|
|
// uiTexture->Load("ui_atlas.zim");
|
2014-07-15 10:26:15 +00:00
|
|
|
dp_xres_old = dp_xres;
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-10 14:55:21 +00:00
|
|
|
}
|
2013-12-16 15:21:10 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
void NativeShutdown() {
|
2014-06-29 08:09:15 +00:00
|
|
|
gl_lost_manager_shutdown();
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
screenManager->shutdown();
|
|
|
|
delete screenManager;
|
|
|
|
screenManager = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
g_gameInfoCache.Shutdown();
|
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
delete host;
|
|
|
|
host = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
g_Config.Save();
|
2013-03-29 22:10:40 +00:00
|
|
|
#ifndef _WIN32
|
2012-11-04 10:54:45 +00:00
|
|
|
LogManager::Shutdown();
|
2013-11-03 00:13:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ANDROID_NDK_PROFILER
|
|
|
|
moncleanup();
|
2013-03-29 22:10:40 +00:00
|
|
|
#endif
|
2014-02-09 22:16:08 +00:00
|
|
|
|
|
|
|
ILOG("NativeShutdown called");
|
|
|
|
|
|
|
|
System_SendMessage("finish", "");
|
2012-11-01 15:19:01 +00:00
|
|
|
// This means that the activity has been completely destroyed. PPSSPP does not
|
|
|
|
// boot up correctly with "dirty" global variables currently, so we hack around that
|
|
|
|
// by simply exiting.
|
2012-11-04 10:54:45 +00:00
|
|
|
#ifdef ANDROID
|
2012-11-01 15:19:01 +00:00
|
|
|
exit(0);
|
2012-11-04 10:54:45 +00:00
|
|
|
#endif
|
2013-08-31 08:36:52 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
RemoveFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL);
|
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|