diff --git a/Qt/PPSSPP.pro b/Qt/PPSSPP.pro index 1042dec598..57cdd7a676 100755 --- a/Qt/PPSSPP.pro +++ b/Qt/PPSSPP.pro @@ -82,6 +82,7 @@ SOURCES += $$P/UI/*Screen.cpp \ $$P/UI/Store.cpp \ $$P/UI/GamepadEmu.cpp \ $$P/UI/GameInfoCache.cpp \ + $$P/UI/NativeApp.cpp \ $$P/UI/OnScreenDisplay.cpp \ $$P/UI/TiltEventProcessor.cpp \ $$P/UI/UIShader.cpp \ @@ -112,7 +113,6 @@ INCLUDEPATH += $$P $$P/Common $$P/native $$P/native/ext } else { # Desktop handles the Init separately RESOURCES += $$P/Qt/assets.qrc - SOURCES += $$P/UI/NativeApp.cpp } # Packaging diff --git a/Qt/QtHost.cpp b/Qt/QtHost.cpp deleted file mode 100644 index 238e4991d4..0000000000 --- a/Qt/QtHost.cpp +++ /dev/null @@ -1,585 +0,0 @@ -// This file is Qt Desktop's equivalent of NativeApp.cpp -// It's really quite nasty that this isn't shared with the other ports... - -#include -#include -#include -#include -#include - -#include "QtHost.h" -#include "LogManager.h" -#include "Core/Debugger/SymbolMap.h" -#include "Core/Config.h" -#include "base/NativeApp.h" -#include "i18n/i18n.h" -#include "UI/EmuScreen.h" -#include "UI/UIShader.h" -#include "UI/MiscScreens.h" -#include "UI/GameInfoCache.h" -#include "UI/OnScreenDisplay.h" -#include "UI/ui_atlas.h" -#include "ui/ui.h" -#include "ui/ui_context.h" -#include "gfx_es2/draw_text.h" -#include "GPU/ge_constants.h" -#include "ext/jpge/jpge.h" - -static UI::Theme ui_theme; - -const char *stateToLoad = NULL; - -std::string boot_filename = ""; -Texture *uiTexture; -UIContext *uiContext; - -ScreenManager *screenManager; -std::string game_title; - -event m_hGPUStepEvent; -recursive_mutex m_hGPUStepMutex; - -recursive_mutex pendingMutex; -static bool isMessagePending; -static std::string pendingMessage; -static std::string pendingValue; - -bool g_TakeScreenshot; - -QtHost::QtHost(MainWindow *mainWindow_) - : mainWindow(mainWindow_) - , m_GPUStep(false) - , m_GPUFlag(0) -{ - QObject::connect(this,SIGNAL(BootDoneSignal()),mainWindow,SLOT(Boot())); -} - -bool QtHost::InitGL(std::string *error_string) -{ - return true; -} - -void QtHost::ShutdownGL() -{ -} - -void QtHost::SetWindowTitle(const char *message) -{ - QString title = "PPSSPP " + QString(PPSSPP_GIT_VERSION) + " - " + QString::fromUtf8(message); - - mainWindow->setWindowTitle(title); -} - -void QtHost::UpdateUI() -{ - mainWindow->updateMenus(); -} - - -void QtHost::UpdateMemView() -{ - if(mainWindow->GetDialogMemory()) - mainWindow->GetDialogMemory()->Update(); -} - -void QtHost::UpdateDisassembly() -{ - if(mainWindow->GetDialogDisasm()) - { - mainWindow->GetDialogDisasm()->Update(); - } - if(mainWindow->GetDialogDisplaylist()) - { - mainWindow->GetDialogDisplaylist()->Update(); - } -} - -void QtHost::SetDebugMode(bool mode) -{ - if(mainWindow->GetDialogDisasm()) - mainWindow->GetDialogDisasm()->SetDebugMode(mode); -} - - -void QtHost::BeginFrame() -{ -} - -void QtHost::EndFrame() -{ -} - -void QtHost::InitSound(PMixer *mixer) -{ - g_mixer = mixer; -} - -void QtHost::ShutdownSound() -{ - g_mixer = 0; -} - -void QtHost::BootDone() -{ - symbolMap.SortSymbols(); - emit BootDoneSignal(); -} - - -static const char* SymbolMapFilename(std::string currentFilename) -{ - std::string result = currentFilename; - size_t dot = result.rfind('.'); - if (dot == result.npos) - return (result + ".map").c_str(); - - result.replace(dot, result.npos, ".map"); - return result.c_str(); -} - -bool QtHost::AttemptLoadSymbolMap() -{ - return symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart)); -} - -void QtHost::PrepareShutdown() -{ - symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart)); -} - -void QtHost::AddSymbol(std::string name, u32 addr, u32 size, int type=0) -{ - -} - -bool QtHost::IsDebuggingEnabled() -{ -#ifdef _DEBUG - return true; -#else - return false; -#endif -} - -bool QtHost::GPUDebuggingActive() -{ - auto dialogDisplayList = mainWindow->GetDialogDisplaylist(); - if (dialogDisplayList && dialogDisplayList->isVisible()) - { - if (GpuStep()) - SendGPUStart(); - - return true; - } - return false; -} - -void QtHost::GPUNotifyCommand(u32 pc) -{ - u32 op = Memory::ReadUnchecked_U32(pc); - u32 cmd = op >> 24; - if (GpuStep()) - SendGPUWait(cmd, pc, &gstate); -} - -void QtHost::SendCoreWait(bool isWaiting) -{ -} - -bool QtHost::GpuStep() -{ - return m_GPUStep; -} - -void QtHost::SendGPUStart() -{ - if(m_GPUFlag == -1) - { - m_GPUFlag = 0; - } -} - -void QtHost::SendGPUWait(u32 cmd, u32 addr, void *data) -{ - if((m_GPUFlag == 1 && (cmd == GE_CMD_PRIM || cmd == GE_CMD_BEZIER || cmd == GE_CMD_SPLINE))) - { - // Break after the draw - m_GPUFlag = 0; - } - else if(m_GPUFlag == 0) - { - mainWindow->GetDialogDisasm()->UpdateDisplayList(); - mainWindow->GetDialogDisplaylist()->Update(); - m_hGPUStepEvent.wait(m_hGPUStepMutex); - } - else if(m_GPUFlag == 2 && addr == m_GPUData) - { - mainWindow->GetDialogDisasm()->UpdateDisplayList(); - mainWindow->GetDialogDisplaylist()->Update(); - m_hGPUStepEvent.wait(m_hGPUStepMutex); - } - else if(m_GPUFlag == 3 && (cmd == GE_CMD_PRIM || cmd == GE_CMD_BEZIER || cmd == GE_CMD_SPLINE)) - { - GPUgstate *state = (GPUgstate*)data; - u32 texAddr = (state->texaddr[0] & 0xFFFFF0) | ((state->texbufwidth[0]<<8) & 0x0F000000); - if(texAddr == m_GPUData) - { - mainWindow->GetDialogDisasm()->UpdateDisplayList(); - mainWindow->GetDialogDisplaylist()->Update(); - m_hGPUStepEvent.wait(m_hGPUStepMutex); - } - } -} - -void QtHost::SetGPUStep(bool value, int flag, u32 data) -{ - m_GPUStep = value; - m_GPUFlag = flag; - m_GPUData = data; -} - -void QtHost::NextGPUStep() -{ - m_hGPUStepEvent.notify_one(); -} - -void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID) -{ - isMessagePending = false; - - std::string user_data_path = savegame_directory; -#ifdef Q_OS_LINUX - char* config = getenv("XDG_CONFIG_HOME"); - if (!config) { - config = getenv("HOME"); - strcat(config, "/.config"); - } - std::string memcard_path = std::string(config) + "/ppsspp/"; -#else - std::string memcard_path = QDir::homePath().toStdString() + "/.ppsspp/"; -#endif - - VFSRegister("", new DirectoryAssetReader("assets/")); - VFSRegister("", new DirectoryAssetReader(user_data_path.c_str())); - VFSRegister("", new AssetsAssetReader()); - - g_Config.AddSearchPath(user_data_path); - g_Config.AddSearchPath(memcard_path + "PSP/SYSTEM/"); - g_Config.SetDefaultPath(memcard_path + "PSP/SYSTEM/"); - g_Config.Load(); - i18nrepo.LoadIni(g_Config.sLanguageIni); - - const char *fileToLog = 0; - - // Parse command line - for (int i = 1; i < argc; i++) { - if (argv[i][0] == '-') { - switch (argv[i][1]) { - case 'j': - g_Config.bJit = true; - g_Config.bSaveSettings = false; - break; - case 'i': - g_Config.bJit = false; - g_Config.bSaveSettings = false; - break; - case 's': - g_Config.bAutoRun = false; - g_Config.bSaveSettings = false; - break; - case '-': - if (!strcmp(argv[i], "--log") && i < argc - 1) - fileToLog = argv[++i]; - if (!strncmp(argv[i], "--log=", strlen("--log=")) && strlen(argv[i]) > strlen("--log=")) - fileToLog = argv[i] + strlen("--log="); - if (!strcmp(argv[i], "--state") && i < argc - 1) - stateToLoad = argv[++i]; - if (!strncmp(argv[i], "--state=", strlen("--state=")) && strlen(argv[i]) > strlen("--state=")) - stateToLoad = argv[i] + strlen("--state="); - break; - } - } - else if (fileToStart.isNull()) - { - fileToStart = QString(argv[i]); - if (!QFile::exists(fileToStart)) - { - qCritical("File '%s' does not exist!", qPrintable(fileToStart)); - exit(1); - } - } - else - { - qCritical("Can only boot one file. Ignoring file '%s'", qPrintable(fileToStart)); - } - } - - if (g_Config.currentDirectory == "") - { - g_Config.currentDirectory = QDir::homePath().toStdString(); - } - - g_Config.memCardDirectory = memcard_path; - -#if defined(Q_OS_LINUX) - std::string program_path = QCoreApplication::applicationDirPath().toStdString(); - if (File::Exists(program_path + "/flash0")) - g_Config.flash0Directory = program_path + "/flash0/"; - else if (File::Exists(program_path + "/../flash0")) - g_Config.flash0Directory = program_path + "/../flash0/"; - else - g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; -#else - g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; -#endif - - LogManager::Init(); - if (fileToLog != NULL) - LogManager::GetInstance()->ChangeFileLog(fileToLog); - - g_gameInfoCache.Init(); - - // Start Desktop UI - MainWindow* mainWindow = new MainWindow(); - mainWindow->show(); -} - -int NativeMix(short *audio, int num_samples) -{ - if (g_mixer) - return g_mixer->Mix(audio, num_samples); - else - return 0; -} - -void TakeScreenshot() { - g_TakeScreenshot = false; - mkDir(g_Config.memCardDirectory + "/PSP/SCREENSHOT"); - - // First, find a free filename. - int i = 0; - - char temp[256]; - while (i < 10000){ - if(g_Config.bScreenshotsAsPNG) - sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.png", g_Config.memCardDirectory.c_str(), i); - else - sprintf(temp, "%s/PSP/SCREENSHOT/screen%05d.jpg", g_Config.memCardDirectory.c_str(), i); - FileInfo info; - if (!getFileInfo(temp, &info)) - break; - i++; - } - - // Okay, allocate a buffer. - u8 *buffer = new u8[3 * pixel_xres * pixel_yres]; - // Silly openGL reads upside down, we flip to another buffer for simplicity. - u8 *flipbuffer = new u8[3 * pixel_xres * pixel_yres]; - - glReadPixels(0, 0, pixel_xres, pixel_yres, GL_RGB, GL_UNSIGNED_BYTE, buffer); - - for (int y = 0; y < pixel_yres; y++) { - memcpy(flipbuffer + y * pixel_xres * 3, buffer + (pixel_yres - y - 1) * pixel_xres * 3, pixel_xres * 3); - } - - if (g_Config.bScreenshotsAsPNG) { - png_image png; - memset(&png, 0, sizeof(png)); - png.version = PNG_IMAGE_VERSION; - png.format = PNG_FORMAT_RGB; - png.width = pixel_xres; - png.height = pixel_yres; - png_image_write_to_file(&png, temp, 0, flipbuffer, pixel_xres * 3, NULL); - png_image_free(&png); - } else { - jpge::params params; - params.m_quality = 90; - compress_image_to_jpeg_file(temp, pixel_xres, pixel_yres, 3, flipbuffer, params); - } - - delete [] buffer; - delete [] flipbuffer; - - osm.Show(temp); -} - -void NativeInitGraphics() -{ - gl_lost_manager_init(); - ui_draw2d.SetAtlas(&ui_atlas); - - screenManager = new ScreenManager(); - if (boot_filename.empty()) { - screenManager->switchScreen(new LogoScreen()); - } else { - // Go directly into the game. - screenManager->switchScreen(new EmuScreen(boot_filename)); - } - - UIShader_Init(); - - UITheme theme = {0}; - theme.uiFont = UBUNTU24; - theme.uiFontSmall = UBUNTU24; - theme.uiFontSmaller = UBUNTU24; - theme.buttonImage = I_SOLIDWHITE; // not using classic buttons - theme.buttonSelected = I_SOLIDWHITE; - theme.checkOn = I_CHECKEDBOX; - theme.checkOff = I_SQUARE; - -#ifdef _WIN32 - 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); -#else - ui_theme.uiFont = UI::FontStyle(UBUNTU24, "", 20); - ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, "", 14); - ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, "", 11); -#endif - ui_theme.checkOn = I_CHECKEDBOX; - ui_theme.checkOff = I_SQUARE; - ui_theme.whiteImage = I_SOLIDWHITE; - ui_theme.sliderKnob = I_CIRCLE; - ui_theme.dropShadow4Grid = I_DROP_SHADOW; - - ui_theme.itemStyle.background = UI::Drawable(0x55000000); - ui_theme.itemStyle.fgColor = 0xFFFFFFFF; - ui_theme.itemFocusedStyle.background = UI::Drawable(0xFFedc24c); - ui_theme.itemDownStyle.background = UI::Drawable(0xFFbd9939); - ui_theme.itemDownStyle.fgColor = 0xFFFFFFFF; - ui_theme.itemDisabledStyle.background = UI::Drawable(0x55E0D4AF); - ui_theme.itemDisabledStyle.fgColor = 0xFFcccccc; - - 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 = 0xFFE3BE59; - - ui_draw2d.Init(); - ui_draw2d_front.Init(); - - UIInit(&ui_atlas, theme); - - uiTexture = new Texture(); - if (!uiTexture->Load("ui_atlas_lowmem.zim")) - { - qDebug() << "Failed to load texture"; - } - uiTexture->Bind(0); - - uiContext = new UIContext(); - uiContext->theme = &ui_theme; - uiContext->Init(UIShader_Get(), UIShader_GetPlain(), uiTexture, &ui_draw2d, &ui_draw2d_front); - - screenManager->setUIContext(uiContext); - - 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); - - glstate.viewport.set(0, 0, pixel_xres, pixel_yres); -} - -void NativeRender() -{ - // 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); - - glstate.Restore(); - glViewport(0, 0, pixel_xres, pixel_yres); - Matrix4x4 ortho; - 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()); - - screenManager->render(); - if (screenManager->getUIContext()->Text()) { - screenManager->getUIContext()->Text()->OncePerFrame(); - } - - if (g_TakeScreenshot) - TakeScreenshot(); -} - -void NativeResized() { - 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)); - } -} - -void NativeMessageReceived(const char *message, const char *value) -{ - lock_guard lock(pendingMutex); - if (!isMessagePending) { - pendingMessage = message; - pendingValue = value; - isMessagePending = true; - } -} - -void NativeUpdate(InputState &input) -{ - { - lock_guard lock(pendingMutex); - if (isMessagePending) { - screenManager->sendMessage(pendingMessage.c_str(), pendingValue.c_str()); - isMessagePending = false; - } - } - - UIUpdateMouse(0, input.pointer_x[0], input.pointer_y[0], input.pointer_down[0]); - screenManager->update(input); -} - -void NativeTouch(const TouchInput &touch) { - if (screenManager) - screenManager->touch(touch); -} - -void NativeKey(const KeyInput &key) { - g_buttonTracker.Process(key); - if (screenManager) - screenManager->key(key); -} - -void NativeAxis(const AxisInput &key) { - if (screenManager) - screenManager->axis(key); -} - -void NativeShutdownGraphics() -{ - delete uiTexture; - uiTexture = NULL; - - screenManager->shutdown(); - delete screenManager; - screenManager = 0; - - ui_draw2d.Shutdown(); - ui_draw2d_front.Shutdown(); - - UIShader_Shutdown(); - - gl_lost_manager_shutdown(); -} - -void NativeShutdown() -{ - delete host; - host = 0; - g_Config.Save(); - LogManager::Shutdown(); - // 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. -#ifdef ANDROID - exit(0); -#endif -} diff --git a/Qt/QtHost.h b/Qt/QtHost.h deleted file mode 100644 index 002d4b4a27..0000000000 --- a/Qt/QtHost.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef QTHOST_H -#define QTHOST_H - -#include -#include "../Core/Host.h" -#include "mainwindow.h" - -#include "base/NativeApp.h" -#include "file/vfs.h" -#include "file/zip_read.h" -#include "gfx_es2/gl_state.h" -#include "gfx/texture.h" -#include "input/input_state.h" -#include "math/math_util.h" -#include "math/lin/matrix4x4.h" -#include - -// Globals -static PMixer *g_mixer; -static QString fileToStart; - -class QtHost : public QObject, public Host -{ - Q_OBJECT -public: - QtHost(MainWindow* mainWindow); - - void UpdateMemView(); - void UpdateDisassembly(); - void UpdateUI(); - void SetDebugMode(bool mode); - - void AddSymbol(std::string name, u32 addr, u32 size, int type); - - bool InitGL(std::string *error_string); - void BeginFrame(); - void EndFrame(); - void ShutdownGL(); - - void InitSound(PMixer *mixer); - void UpdateSound() { } - void ShutdownSound(); - - bool IsDebuggingEnabled(); - bool GPUDebuggingActive(); - void BootDone(); - void PrepareShutdown(); - bool AttemptLoadSymbolMap(); - void SetWindowTitle(const char *message); - - void GPUNotifyCommand(u32 pc); - - void SendCoreWait(bool); - bool GpuStep(); - void SendGPUWait(u32 cmd, u32 addr, void* data); - void SendGPUStart(); - void SetGPUStep(bool value, int flag = 0, u32 data = 0); - void NextGPUStep(); - -signals: - void BootDoneSignal(); -private: - MainWindow* mainWindow; - bool m_GPUStep; - int m_GPUFlag; - u32 m_GPUData; -}; - -#endif // QTAPP_H diff --git a/Qt/debugger_displaylist.cpp b/Qt/debugger_displaylist.cpp index bf4a30a239..94875f0288 100644 --- a/Qt/debugger_displaylist.cpp +++ b/Qt/debugger_displaylist.cpp @@ -10,7 +10,7 @@ #include "Core/Host.h" #include "base/display.h" #include "mainwindow.h" -#include "QtHost.h" +#include "UI/HostTypes.h" #include "GPU/GLES/VertexDecoder.h" #include "ext/glew/GL/glew.h" @@ -1436,24 +1436,19 @@ void Debugger_DisplayList::on_displayList_itemClicked(QTreeWidgetItem *item, int void Debugger_DisplayList::on_stepBtn_clicked() { - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(true); - qthost->NextGPUStep(); + ((QtHost*)host)->SetGPUStep(true); } void Debugger_DisplayList::on_runBtn_clicked() { ui->displayList->clear(); ui->displayListData->clear(); - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(false); - qthost->NextGPUStep(); + ((QtHost*)host)->SetGPUStep(false); } void Debugger_DisplayList::on_stopBtn_clicked() { - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(true); + ((QtHost*)host)->SetGPUStep(true); } void Debugger_DisplayList::UpdateRenderBuffer() @@ -1513,9 +1508,7 @@ void Debugger_DisplayList::UpdateRenderBufferGUI() void Debugger_DisplayList::on_nextDrawBtn_clicked() { - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(true, 1); - qthost->NextGPUStep(); + ((QtHost*)host)->SetGPUStep(true, 1); } void Debugger_DisplayList::on_gotoPCBtn_clicked() @@ -1588,9 +1581,7 @@ void Debugger_DisplayList::on_fboList_itemClicked(QTreeWidgetItem *item, int col void Debugger_DisplayList::on_nextDLBtn_clicked() { - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(true,-1); - qthost->NextGPUStep(); + ((QtHost*)host)->SetGPUStep(true,-1); } void Debugger_DisplayList::setCurrentFBO(u32 addr) @@ -1779,9 +1770,7 @@ void Debugger_DisplayList::on_displayListData_customContextMenuRequested(const Q void Debugger_DisplayList::RunToDLPC() { u32 addr = displayListDataSelected->text(0).toUInt(0,16); - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(true, 2, addr); - qthost->NextGPUStep(); + ((QtHost*)host)->SetGPUStep(true, 2, addr); } void Debugger_DisplayList::on_texturesList_customContextMenuRequested(const QPoint &pos) @@ -1803,7 +1792,5 @@ void Debugger_DisplayList::on_texturesList_customContextMenuRequested(const QPoi void Debugger_DisplayList::RunToDrawTex() { u32 addr = textureDataSelected->text(0).toUInt(0,16); - QtHost *qthost = (QtHost *)host; - qthost->SetGPUStep(true, 3, addr); - qthost->NextGPUStep(); + ((QtHost*)host)->SetGPUStep(true, 3, addr); } diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index 65f37d6bc7..31013b1d1b 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -15,8 +15,6 @@ #include "GPU/GPUInterface.h" #include "UI/GamepadEmu.h" -#include "QtHost.h" - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), currentLanguage("en"), @@ -27,7 +25,6 @@ MainWindow::MainWindow(QWidget *parent) : memoryTexWindow(0), displaylistWindow(0) { - host = new QtHost(this); emugl = new MainUI(this); setCentralWidget(emugl); @@ -36,8 +33,6 @@ MainWindow::MainWindow(QWidget *parent) : SetZoom(g_Config.iInternalResolution); - SetGameTitle(fileToStart); - QObject::connect(emugl, SIGNAL(doubleClick()), this, SLOT(fullscrAct())); QObject::connect(emugl, SIGNAL(newFrame()), this, SLOT(newFrame())); } diff --git a/UI/HostTypes.h b/UI/HostTypes.h new file mode 100644 index 0000000000..3c6fc92923 --- /dev/null +++ b/UI/HostTypes.h @@ -0,0 +1,156 @@ +// Copyright (c) 2014- 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 +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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/. + +#pragma once + +#include "Core/Host.h" + +#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) +#include "Core/Debugger/SymbolMap.h" +#include "Qt/mainwindow.h" +#endif + +// TODO: Get rid of this junk +class NativeHost : public Host { +public: + NativeHost() { + // hasRendered = false; + } + + virtual void UpdateUI() {} + + virtual void UpdateMemView() {} + virtual void UpdateDisassembly() {} + + virtual void SetDebugMode(bool mode) { } + + virtual bool InitGL(std::string *error_message) { return true; } + virtual void ShutdownGL() {} + + virtual void InitSound(PMixer *mixer); + virtual void UpdateSound() {} + virtual void ShutdownSound(); + + // this is sent from EMU thread! Make sure that Host handles it properly! + virtual void BootDone() {} + + 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) {} + virtual void SetWindowTitle(const char *message) {} +}; + +#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) +static const char* SymbolMapFilename(std::string currentFilename) +{ + std::string result = currentFilename; + size_t dot = result.rfind('.'); + if (dot == result.npos) + return (result + ".map").c_str(); + + result.replace(dot, result.npos, ".map"); + return result.c_str(); +} + +class QtHost : public Host { +public: + QtHost(MainWindow *mainWindow_) + { + mainWindow = mainWindow_; + m_GPUStep = false; + m_GPUFlag = 0; + } + + virtual void UpdateUI() { + mainWindow->updateMenus(); + } + + virtual void UpdateMemView() { + if(mainWindow->GetDialogMemory()) + mainWindow->GetDialogMemory()->Update(); + } + virtual void UpdateDisassembly() { + if(mainWindow->GetDialogDisasm()) + mainWindow->GetDialogDisasm()->Update(); + if(mainWindow->GetDialogDisplaylist()) + mainWindow->GetDialogDisplaylist()->Update(); + } + + virtual void SetDebugMode(bool mode) { + if(mainWindow->GetDialogDisasm()) + mainWindow->GetDialogDisasm()->SetDebugMode(mode); + } + + virtual bool InitGL(std::string *error_message) { return true; } + virtual void ShutdownGL() {} + + virtual void InitSound(PMixer *mixer); + virtual void UpdateSound() {} + virtual void ShutdownSound(); + + // this is sent from EMU thread! Make sure that Host handles it properly! + virtual void BootDone() { + symbolMap.SortSymbols(); + mainWindow->Boot(); + } + + virtual bool IsDebuggingEnabled() { +#ifdef _DEBUG + return true; +#else + return false; +#endif + } + virtual bool AttemptLoadSymbolMap() { + return symbolMap.LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart)); + } + virtual void PrepareShutdown() { + symbolMap.SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart)); + } + virtual void ResetSymbolMap() {} + virtual void AddSymbol(std::string name, u32 addr, u32 size, int type=0) {} + virtual void SetWindowTitle(const char *message) { + QString title = "PPSSPP " + QString(PPSSPP_GIT_VERSION) + " - " + QString::fromUtf8(message); + + mainWindow->setWindowTitle(title); + } + bool GPUDebuggingActive() + { + auto dialogDisplayList = mainWindow->GetDialogDisplaylist(); + if (dialogDisplayList && dialogDisplayList->isVisible()) + { + if (m_GPUStep && m_GPUFlag == -1) + m_GPUFlag = 0; + + return true; + } + return false; + } + void SetGPUStep(bool value, int flag = 0, u32 data = 0) + { + m_GPUStep = value; + m_GPUFlag = flag; + m_GPUData = data; + } +private: + MainWindow* mainWindow; + bool m_GPUStep; + int m_GPUFlag; + u32 m_GPUData; +}; +#endif diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index d04f0a67ca..4eac439207 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -71,6 +71,7 @@ #include "EmuScreen.h" #include "GameInfoCache.h" #include "UIShader.h" +#include "HostTypes.h" #include "UI/OnScreenDisplay.h" #include "UI/MiscScreens.h" @@ -100,7 +101,6 @@ Texture *uiTexture; ScreenManager *screenManager; std::string config_filename; -std::string game_title; #ifdef IOS bool iosCanUseJit; @@ -144,43 +144,6 @@ public: } }; - -// TODO: Get rid of this junk -class NativeHost : public Host { -public: - NativeHost() { - // hasRendered = false; - } - - virtual void UpdateUI() {} - - virtual void UpdateMemView() {} - virtual void UpdateDisassembly() {} - - virtual void SetDebugMode(bool mode) { } - - virtual bool InitGL(std::string *error_message) { return true; } - virtual void ShutdownGL() {} - - virtual void InitSound(PMixer *mixer); - virtual void UpdateSound() {} - virtual void ShutdownSound(); - - // this is sent from EMU thread! Make sure that Host handles it properly! - virtual void BootDone() {} - - 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) {} - virtual void SetWindowTitle(const char *message) { - if (message) - game_title = message; - else - game_title = ""; - } -}; - // globals static PMixer *g_mixer = 0; #ifndef _WIN32 @@ -203,6 +166,11 @@ void NativeHost::ShutdownSound() { g_mixer = 0; } +#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) +void QtHost::InitSound(PMixer *mixer) { g_mixer = mixer; } +void QtHost::ShutdownSound() { g_mixer = 0; } +#endif + std::string NativeQueryConfig(std::string query) { if (query == "screenRotation") { char temp[128]; @@ -266,7 +234,9 @@ void NativeInit(int argc, const char *argv[], #endif VFSRegister("", new DirectoryAssetReader(savegame_directory)); +#if defined(MOBILE_DEVICE) || !defined(USING_QT_UI) host = new NativeHost(); +#endif #if defined(ANDROID) g_Config.internalDataDirectory = savegame_directory; @@ -421,6 +391,12 @@ void NativeInit(int argc, const char *argv[], std::string sysName = System_GetProperty(SYSPROP_NAME); isOuya = KeyMap::IsOuya(sysName); + +#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) + MainWindow* mainWindow = new MainWindow(0); + mainWindow->show(); + host = new QtHost(mainWindow); +#endif } void NativeInitGraphics() {