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>
|
2013-04-13 19:24:07 +00:00
|
|
|
|
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-07-07 18:56:18 +00:00
|
|
|
#include "native/ext/stb_image_write/stb_image_writer.h"
|
2013-06-25 21:18:16 +00:00
|
|
|
#include "native/ext/jpge/jpge.h"
|
2012-12-05 03:45:28 +00:00
|
|
|
#include "gfx_es2/gl_state.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"
|
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"
|
|
|
|
#include "ui/screen.h"
|
|
|
|
#include "ui/ui.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"
|
|
|
|
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/LogManager.h"
|
|
|
|
#include "Core/PSPMixer.h"
|
|
|
|
#include "Core/CPU.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/HLE/sceCtrl.h"
|
|
|
|
#include "Core/Host.h"
|
|
|
|
#include "Core/SaveState.h"
|
|
|
|
#include "Core/HW/atrac3plus.h"
|
|
|
|
#include "Common/MemArena.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
#include "ui_atlas.h"
|
|
|
|
#include "EmuScreen.h"
|
|
|
|
#include "MenuScreens.h"
|
2013-04-13 19:24:07 +00:00
|
|
|
#include "GameInfoCache.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "UIShader.h"
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
#include "UI/PluginScreen.h"
|
2013-06-22 20:27:59 +00:00
|
|
|
#include "UI/OnScreenDisplay.h"
|
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-04-01 15:08:40 +00:00
|
|
|
#if defined(__APPLE__) && !defined(IOS)
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#endif
|
|
|
|
|
2013-06-25 21:18:16 +00:00
|
|
|
#ifdef IOS
|
|
|
|
#include "ios/iOSCoreAudio.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
Texture *uiTexture;
|
|
|
|
|
2012-11-04 10:54:45 +00:00
|
|
|
ScreenManager *screenManager;
|
2012-11-01 15:19:01 +00:00
|
|
|
std::string config_filename;
|
2013-01-02 20:00:10 +00:00
|
|
|
std::string game_title;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-04-24 08:43:00 +00:00
|
|
|
#ifdef IOS
|
|
|
|
bool isJailed;
|
|
|
|
#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-04-24 08:43:00 +00:00
|
|
|
|
2013-03-29 19:51:14 +00:00
|
|
|
recursive_mutex pendingMutex;
|
|
|
|
static bool isMessagePending;
|
|
|
|
static std::string pendingMessage;
|
|
|
|
static std::string pendingValue;
|
2013-03-30 18:23:20 +00:00
|
|
|
static UIContext *uiContext;
|
2013-03-29 19:51:14 +00:00
|
|
|
|
2013-04-13 19:24:07 +00:00
|
|
|
std::thread *graphicsLoadThread;
|
2013-03-29 19:51:14 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
class AndroidLogger : public LogListener
|
|
|
|
{
|
|
|
|
public:
|
2012-11-04 09:56:22 +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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Get rid of this junk
|
|
|
|
class NativeHost : public Host
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NativeHost() {
|
|
|
|
// hasRendered = false;
|
|
|
|
}
|
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void UpdateUI() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void UpdateMemView() {}
|
|
|
|
virtual void UpdateDisassembly() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void SetDebugMode(bool mode) { }
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-03-15 07:43:35 +00:00
|
|
|
virtual bool InitGL(std::string *error_message) { return true; }
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void ShutdownGL() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void InitSound(PMixer *mixer);
|
2013-03-04 13:29:51 +00:00
|
|
|
virtual void UpdateSound() {}
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual void ShutdownSound();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
// this is sent from EMU thread! Make sure that Host handles it properly!
|
|
|
|
virtual void BootDone() {}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
virtual bool IsDebuggingEnabled() {return false;}
|
|
|
|
virtual bool AttemptLoadSymbolMap() {return false;}
|
|
|
|
virtual void ResetSymbolMap() {}
|
|
|
|
virtual void AddSymbol(std::string name, u32 addr, u32 size, int type=0) {}
|
2013-01-02 20:00:10 +00:00
|
|
|
virtual void SetWindowTitle(const char *message) {
|
|
|
|
game_title = message;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// globals
|
|
|
|
static PMixer *g_mixer = 0;
|
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 = "";
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeHost::InitSound(PMixer *mixer) {
|
2012-11-01 15:19:01 +00:00
|
|
|
g_mixer = mixer;
|
2013-06-25 21:18:16 +00:00
|
|
|
|
|
|
|
#ifdef IOS
|
|
|
|
iOSCoreAudioInit();
|
|
|
|
#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
|
|
|
|
iOSCoreAudioShutdown();
|
|
|
|
#endif
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
g_mixer = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
int NativeMix(short *audio, int num_samples) {
|
2013-06-04 21:54:37 +00:00
|
|
|
// ILOG("Entering mixer");
|
2013-06-01 21:34:50 +00:00
|
|
|
if (g_mixer) {
|
2013-06-04 21:54:37 +00:00
|
|
|
num_samples = g_mixer->Mix(audio, num_samples);
|
2013-06-01 21:34:50 +00:00
|
|
|
} else {
|
2013-06-04 21:54:37 +00:00
|
|
|
memset(audio, 0, num_samples * 2 * sizeof(short));
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-06-04 21:54:37 +00:00
|
|
|
// ILOG("Leaving mixer");
|
|
|
|
return num_samples;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape) {
|
2012-11-01 15:19:01 +00:00
|
|
|
*app_nice_name = "PPSSPP";
|
|
|
|
*app_dir_name = "ppsspp";
|
|
|
|
*landscape = true;
|
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[],
|
|
|
|
const char *savegame_directory, const char *external_directory, const char *installID) {
|
2013-07-27 11:07:34 +00:00
|
|
|
bool skipLogo = false;
|
2013-01-10 22:49:33 +00:00
|
|
|
EnableFZ();
|
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;
|
2013-03-29 19:51:14 +00:00
|
|
|
isMessagePending = false;
|
2013-07-09 21:27:25 +00:00
|
|
|
|
|
|
|
#ifdef IOS
|
2013-03-16 06:52:52 +00:00
|
|
|
user_data_path += "/";
|
2013-04-01 15:08:40 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
char program_path[4090];
|
|
|
|
uint32_t program_path_size = sizeof(program_path);
|
|
|
|
_NSGetExecutablePath(program_path,&program_path_size);
|
|
|
|
*(strrchr(program_path, '/')+1) = '\0';
|
|
|
|
char assets_path[4096];
|
|
|
|
sprintf(assets_path,"%sassets/",program_path);
|
|
|
|
VFSRegister("", new DirectoryAssetReader(assets_path));
|
2013-07-09 21:27:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// We want this to be FIRST.
|
|
|
|
#ifndef USING_QT_UI
|
|
|
|
#if defined(BLACKBERRY) || defined(IOS)
|
|
|
|
// Packed assets are included in app
|
|
|
|
VFSRegister("", new DirectoryAssetReader(external_directory));
|
2012-11-07 17:22:10 +00:00
|
|
|
#else
|
2012-11-04 09:56:22 +00:00
|
|
|
VFSRegister("", new DirectoryAssetReader("assets/"));
|
2012-11-07 17:22:10 +00:00
|
|
|
#endif
|
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
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
host = new NativeHost();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
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();
|
|
|
|
ILOG("Logman: %p", logman);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-24 13:29:04 +00:00
|
|
|
config_filename = user_data_path + "/ppsspp.ini";
|
2012-12-25 07:34:19 +00:00
|
|
|
g_Config.Load(config_filename.c_str());
|
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,
|
|
|
|
// to hopefully reduce confusion a bit.
|
|
|
|
ILOG("Creating %s", (g_Config.externalDirectory + "/PSP").c_str());
|
|
|
|
mkDir((g_Config.externalDirectory + "/PSP").c_str());
|
|
|
|
mkDir((g_Config.externalDirectory + "/PSP/SAVEDATA").c_str());
|
|
|
|
mkDir((g_Config.externalDirectory + "/PSP/GAME").c_str());
|
|
|
|
#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=");
|
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
|
|
|
|
|
|
|
FileInfo info;
|
|
|
|
if (!getFileInfo(boot_filename.c_str(), &info) || info.exists == false) {
|
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;
|
2013-04-11 18:02:29 +00:00
|
|
|
#elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(MEEGO_EDITION_HARMATTAN) || 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
|
|
|
|
g_Config.currentDirectory = getenv("HOME");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-02 19:54:09 +00:00
|
|
|
#if defined(ANDROID)
|
2013-05-30 17:06:00 +00:00
|
|
|
g_Config.internalDataDirectory = savegame_directory;
|
2013-01-02 19:54:09 +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.memCardDirectory = std::string(external_directory) + "/";
|
2013-07-12 01:14:53 +00:00
|
|
|
g_Config.flashDirectory = std::string(external_directory)+"/flash0/";
|
2013-04-11 18:02:29 +00:00
|
|
|
#elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(MEEGO_EDITION_HARMATTAN) || defined(IOS) || defined(_WIN32)
|
2012-12-09 15:48:56 +00:00
|
|
|
g_Config.memCardDirectory = user_data_path;
|
2013-07-12 01:14:53 +00:00
|
|
|
g_Config.flashDirectory = std::string(external_directory)+"flash0/";
|
2012-12-09 15:48:56 +00:00
|
|
|
#else
|
|
|
|
g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/";
|
2013-07-12 01:14:53 +00:00
|
|
|
g_Config.flashDirectory = g_Config.memCardDirectory+"/flash0/";
|
2012-12-09 15:48:56 +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
|
|
|
}
|
2013-03-10 12:41:34 +00:00
|
|
|
#ifdef __SYMBIAN32__
|
|
|
|
g_Config.bHardwareTransform = true;
|
|
|
|
#endif
|
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);
|
2012-11-04 09:56:22 +00:00
|
|
|
INFO_LOG(BOOT, "Logger inited.");
|
2013-06-09 10:41:12 +00:00
|
|
|
#else
|
2013-08-17 04:59:28 +00:00
|
|
|
if (g_Config.currentDirectory.empty()) {
|
|
|
|
g_Config.currentDirectory = File::GetExeDirectory();
|
|
|
|
}
|
2013-06-09 10:41:12 +00:00
|
|
|
g_Config.memCardDirectory = "MemStick/";
|
2013-03-29 19:03:11 +00:00
|
|
|
#endif
|
2013-04-01 01:16:29 +00:00
|
|
|
|
2013-04-18 09:58:54 +00:00
|
|
|
i18nrepo.LoadIni(g_Config.languageIni);
|
|
|
|
|
2013-04-01 01:16:29 +00:00
|
|
|
if (!boot_filename.empty() && stateToLoad != NULL)
|
|
|
|
SaveState::Load(stateToLoad);
|
2013-04-18 09:58:54 +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-06-01 21:34:50 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
if (boot_filename.empty()) {
|
2013-06-16 10:41:41 +00:00
|
|
|
#if (defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))) || defined(ARMEABI) || defined(ARMEABI_V7A) || (defined(MACOSX) && defined(_M_IX64))
|
2013-06-01 21:34:50 +00:00
|
|
|
if (Atrac3plus_Decoder::CanAutoInstall()) {
|
|
|
|
Atrac3plus_Decoder::DoAutoInstall();
|
|
|
|
}
|
2013-06-04 22:03:37 +00:00
|
|
|
#endif
|
2012-11-04 09:56:22 +00:00
|
|
|
}
|
2013-07-26 12:42:38 +00:00
|
|
|
|
2013-07-27 11:07:34 +00:00
|
|
|
if (skipLogo) {
|
|
|
|
screenManager->switchScreen(new EmuScreen(boot_filename));
|
|
|
|
} else {
|
|
|
|
screenManager->switchScreen(new LogoScreen(boot_filename));
|
|
|
|
}
|
2013-07-16 20:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NativeInitGraphics() {
|
2013-07-27 09:45:40 +00:00
|
|
|
CheckGLExtensions();
|
2013-07-16 20:50:53 +00:00
|
|
|
gl_lost_manager_init();
|
|
|
|
ui_draw2d.SetAtlas(&ui_atlas);
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
UIShader_Init();
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
// Old style theme, to be removed later
|
2012-11-01 15:19:01 +00:00
|
|
|
UITheme theme = {0};
|
|
|
|
theme.uiFont = UBUNTU24;
|
|
|
|
theme.uiFontSmall = UBUNTU24;
|
|
|
|
theme.uiFontSmaller = UBUNTU24;
|
|
|
|
theme.buttonImage = I_BUTTON;
|
|
|
|
theme.buttonSelected = I_BUTTON_SELECTED;
|
2012-11-20 10:35:48 +00:00
|
|
|
theme.checkOn = I_CHECKEDBOX;
|
2012-11-01 15:19:01 +00:00
|
|
|
theme.checkOff = I_SQUARE;
|
|
|
|
|
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
|
|
|
|
ui_theme.uiFont = UBUNTU24;
|
|
|
|
ui_theme.uiFontSmall = UBUNTU24;
|
|
|
|
ui_theme.uiFontSmaller = UBUNTU24;
|
|
|
|
ui_theme.checkOn = I_CHECKEDBOX;
|
|
|
|
ui_theme.checkOff = I_SQUARE;
|
|
|
|
ui_theme.whiteImage = 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.buttonStyle.background = UI::Drawable(UI::DRAW_4GRID, I_BUTTON);
|
2013-06-02 21:46:03 +00:00
|
|
|
ui_theme.buttonStyle.fgColor = 0xFFFFFFFF;
|
2013-06-03 23:25:30 +00:00
|
|
|
ui_theme.buttonStyle.image = I_BUTTON;
|
2013-06-08 20:42:31 +00:00
|
|
|
ui_theme.buttonFocusedStyle.background = UI::Drawable(UI::DRAW_4GRID, I_BUTTON, 0xFFe0e0e0);
|
2013-06-02 21:46:03 +00:00
|
|
|
ui_theme.buttonFocusedStyle.fgColor = 0xFFFFFFFF;
|
2013-06-08 20:42:31 +00:00
|
|
|
ui_theme.buttonDownStyle.background = UI::Drawable(UI::DRAW_4GRID, I_BUTTON_SELECTED, 0xFFFFFFFF);
|
2013-06-02 21:46:03 +00:00
|
|
|
ui_theme.buttonDownStyle.fgColor = 0xFFFFFFFF;
|
2013-06-08 20:42:31 +00:00
|
|
|
ui_theme.buttonDisabledStyle.background = UI::Drawable(UI::DRAW_4GRID, I_BUTTON, 0xFF404040);
|
2013-06-02 21:46:03 +00:00
|
|
|
ui_theme.buttonDisabledStyle.fgColor = 0xFF707070;
|
2013-08-16 14:48:43 +00:00
|
|
|
|
2013-06-08 20:42:31 +00:00
|
|
|
ui_theme.itemStyle.background = UI::Drawable(0x55000000);
|
|
|
|
ui_theme.itemStyle.fgColor = 0xFFFFFFFF;
|
2013-08-16 14:48:43 +00:00
|
|
|
ui_theme.itemFocusedStyle.background = UI::Drawable(0xe0ECCA6D);
|
|
|
|
ui_theme.itemDownStyle.background = UI::Drawable(0xFFE1B12D);
|
2013-06-01 21:34:50 +00:00
|
|
|
ui_theme.itemDownStyle.fgColor = 0xFF000000;
|
2013-08-16 14:48:43 +00:00
|
|
|
ui_theme.itemDisabledStyle.background = UI::Drawable(0x55E0D4AF);
|
|
|
|
ui_theme.itemDisabledStyle.fgColor = 0xFFcccccc;
|
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;
|
|
|
|
|
|
|
|
ui_theme.popupTitle.fgColor = 0xFFE5B533;
|
2013-01-11 22:46:56 +00:00
|
|
|
ui_draw2d.Init();
|
|
|
|
ui_draw2d_front.Init();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
UIInit(&ui_atlas, theme);
|
|
|
|
|
|
|
|
uiTexture = new Texture();
|
2013-06-05 14:48:16 +00:00
|
|
|
if (!uiTexture->Load("ui_atlas.zim")) {
|
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");
|
2012-11-04 09:56:22 +00:00
|
|
|
}
|
|
|
|
uiTexture->Bind(0);
|
|
|
|
|
2013-03-30 18:23:20 +00:00
|
|
|
uiContext = new UIContext();
|
2013-06-01 21:34:50 +00:00
|
|
|
uiContext->theme = &ui_theme;
|
2013-03-30 18:23:20 +00:00
|
|
|
uiContext->Init(UIShader_Get(), UIShader_GetPlain(), uiTexture, &ui_draw2d, &ui_draw2d_front);
|
|
|
|
|
|
|
|
screenManager->setUIContext(uiContext);
|
|
|
|
|
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
|
|
|
|
|
|
|
glstate.viewport.set(0, 0, pixel_xres, pixel_yres);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
void NativeShutdownGraphics() {
|
|
|
|
screenManager->deviceLost();
|
|
|
|
|
|
|
|
g_gameInfoCache.Clear();
|
|
|
|
|
|
|
|
delete uiTexture;
|
|
|
|
uiTexture = NULL;
|
|
|
|
|
|
|
|
delete uiContext;
|
|
|
|
uiContext = NULL;
|
|
|
|
|
|
|
|
ui_draw2d.Shutdown();
|
|
|
|
ui_draw2d_front.Shutdown();
|
|
|
|
|
|
|
|
UIShader_Shutdown();
|
|
|
|
|
|
|
|
gl_lost_manager_shutdown();
|
|
|
|
}
|
|
|
|
|
2013-06-22 20:27:59 +00:00
|
|
|
void TakeScreenshot() {
|
|
|
|
#ifdef _WIN32
|
|
|
|
g_TakeScreenshot = false;
|
|
|
|
mkDir("screenshots");
|
|
|
|
|
|
|
|
// First, find a free filename.
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
char temp[256];
|
2013-07-07 18:56:18 +00:00
|
|
|
while (i < 10000){
|
2013-07-07 22:10:23 +00:00
|
|
|
if(g_Config.bScreenshotsAsPNG)
|
2013-07-07 18:56:18 +00:00
|
|
|
sprintf(temp, "screenshots/screen%05d.png", i);
|
|
|
|
else
|
|
|
|
sprintf(temp, "screenshots/screen%05d.jpg", i);
|
2013-06-22 20:27:59 +00:00
|
|
|
FileInfo info;
|
|
|
|
if (!getFileInfo(temp, &info))
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, allocate a buffer.
|
|
|
|
u8 *buffer = new u8[4 * pixel_xres * pixel_yres];
|
|
|
|
// Silly openGL reads upside down, we flip to another buffer for simplicity.
|
|
|
|
u8 *flipbuffer = new u8[4 * pixel_xres * pixel_yres];
|
|
|
|
|
|
|
|
glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
|
|
|
|
|
|
|
for (int y = 0; y < pixel_yres; y++) {
|
|
|
|
memcpy(flipbuffer + y * pixel_xres * 4, buffer + (pixel_yres - y - 1) * pixel_xres * 4, pixel_xres * 4);
|
|
|
|
}
|
|
|
|
|
2013-07-07 22:10:23 +00:00
|
|
|
if(g_Config.bScreenshotsAsPNG)
|
2013-07-07 18:56:18 +00:00
|
|
|
stbi_write_png(temp, pixel_xres, pixel_yres, 4, flipbuffer, pixel_xres * 4);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jpge::params params;
|
|
|
|
params.m_quality = 90;
|
|
|
|
compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 4, flipbuffer, params);
|
|
|
|
}
|
2013-06-22 20:27:59 +00:00
|
|
|
|
|
|
|
delete [] buffer;
|
|
|
|
delete [] flipbuffer;
|
|
|
|
|
|
|
|
osm.Show(temp);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeRender() {
|
2013-01-10 22:49:33 +00:00
|
|
|
EnableFZ();
|
2013-06-01 21:34:50 +00:00
|
|
|
|
2013-02-22 21:14:17 +00:00
|
|
|
glstate.depthWrite.set(GL_TRUE);
|
|
|
|
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
|
2013-01-10 22:49:33 +00:00
|
|
|
// Clearing the screen at the start of the frame is an optimization for tiled mobile GPUs, as it then doesn't need to keep it around between frames.
|
|
|
|
glClearColor(0,0,0,1);
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
|
2013-03-29 17:50:08 +00:00
|
|
|
glstate.viewport.set(0, 0, pixel_xres, pixel_yres);
|
2012-12-05 03:45:28 +00:00
|
|
|
glstate.Restore();
|
2013-03-29 17:50:08 +00:00
|
|
|
|
2012-11-04 09:56:22 +00:00
|
|
|
Matrix4x4 ortho;
|
2012-11-01 15:19:01 +00:00
|
|
|
ortho.setOrtho(0.0f, dp_xres, dp_yres, 0.0f, -1.0f, 1.0f);
|
|
|
|
glsl_bind(UIShader_Get());
|
|
|
|
glUniformMatrix4fv(UIShader_Get()->u_worldviewproj, 1, GL_FALSE, ortho.getReadPtr());
|
2012-11-04 10:54:45 +00:00
|
|
|
|
|
|
|
screenManager->render();
|
2013-06-22 20:27:59 +00:00
|
|
|
|
|
|
|
if (g_TakeScreenshot) {
|
|
|
|
TakeScreenshot();
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeUpdate(InputState &input) {
|
2013-03-29 19:51:14 +00:00
|
|
|
{
|
|
|
|
lock_guard lock(pendingMutex);
|
|
|
|
if (isMessagePending) {
|
|
|
|
screenManager->sendMessage(pendingMessage.c_str(), pendingValue.c_str());
|
|
|
|
isMessagePending = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
UIUpdateMouse(0, input.pointer_x[0], input.pointer_y[0], input.pointer_down[0]);
|
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-07-06 17:08:59 +00:00
|
|
|
return globalUIState == UISTATE_MENU;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 21:34:50 +00:00
|
|
|
void NativeTouch(const TouchInput &touch) {
|
2013-06-10 21:47:49 +00:00
|
|
|
if (screenManager)
|
|
|
|
screenManager->touch(touch);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
void NativeKey(const KeyInput &key) {
|
2013-07-15 15:41:24 +00:00
|
|
|
g_buttonTracker.Process(key);
|
2013-07-06 17:08:59 +00:00
|
|
|
if (screenManager)
|
|
|
|
screenManager->key(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NativeAxis(const AxisInput &key) {
|
|
|
|
if (screenManager)
|
|
|
|
screenManager->axis(key);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (!isMessagePending) {
|
|
|
|
pendingMessage = message;
|
|
|
|
pendingValue = value;
|
|
|
|
isMessagePending = true;
|
|
|
|
}
|
2012-12-01 09:39:20 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-07-16 20:50:53 +00:00
|
|
|
void NativeShutdown() {
|
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-03-29 22:10:40 +00:00
|
|
|
#endif
|
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
|
2013-07-20 10:06:06 +00:00
|
|
|
ILOG("NativeShutdown called");
|
2012-11-01 15:19:01 +00:00
|
|
|
exit(0);
|
2012-11-04 10:54:45 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|