Qt code refactor. Stage 1 in a code refactor. Removed NativeApp.cpp redundancy (since the Qt code reimplemented almost all of it). Changed to Qt types where logical. Cleaned up globals. Start of work at integrating more of the Qt code in to native/ (where GUI should be).

This commit is contained in:
Sacha 2013-01-16 02:16:07 +10:00
parent 4371e3a58e
commit 4ab88cad12
11 changed files with 314 additions and 216 deletions

View File

@ -50,7 +50,7 @@ public:
virtual void ShutdownGL() = 0;
virtual void InitSound(PMixer *mixer) = 0;
virtual void UpdateSound() {};
virtual void UpdateSound() {}
virtual void ShutdownSound() = 0;
//this is sent from EMU thread! Make sure that Host handles it properly!

View File

@ -18,17 +18,14 @@
#include "GPU/GPUState.h"
#include "qtemugl.h"
QString fileToStart;
QtEmuGL* glWindow;
#include "QtHost.h"
void EmuThread_Start(QString filename, QtEmuGL* w)
{
//_dbg_clear_();
fileToStart = filename;
glWindow = w;
w->start_rendering();
glWindow->start_rendering();
}
void EmuThread_Stop()
@ -39,14 +36,8 @@ void EmuThread_Stop()
host->UpdateUI();
}
QString GetCurrentFilename()
void EmuThread::init(InputState *inputState)
{
return fileToStart;
}
void EmuThread::init(QtEmuGL *_glw, InputState *inputState)
{
glw = _glw;
input_state = inputState;
}
@ -60,7 +51,7 @@ void EmuThread::run()
host->UpdateUI();
host->InitGL();
glw->makeCurrent();
glWindow->makeCurrent();
#ifndef USING_GLES2
glewInit();
@ -181,9 +172,9 @@ void EmuThread::run()
}
#endif
glw->swapBuffers();
glWindow->swapBuffers();
}
glw->doneCurrent();
glWindow->doneCurrent();
}
void EmuThread::Shutdown()

View File

@ -7,21 +7,17 @@ class QtEmuGL;
class EmuThread : public QThread
{
public:
EmuThread() : running(false) {}
void init(QtEmuGL* _glw, InputState* inputState);
void init(InputState* inputState);
void run();
void FinalShutdown();
void setRunning(bool value);
public slots:
void Shutdown();
private:
QtEmuGL* glw;
InputState* input_state;
bool running;
};
void EmuThread_Start(QString filename, QtEmuGL* glWindow);
void EmuThread_Start(QString filename, QtEmuGL* w);
void EmuThread_Stop();
QString GetCurrentFilename();

View File

@ -24,8 +24,7 @@ SOURCES += ../native/base/QtMain.cpp
HEADERS += ../native/base/QtMain.h
# Native
SOURCES += ../android/jni/NativeApp.cpp \
../android/jni/EmuScreen.cpp \
SOURCES += ../android/jni/EmuScreen.cpp \
../android/jni/MenuScreens.cpp \
../android/jni/GamepadEmu.cpp \
../android/jni/UIShader.cpp \
@ -37,7 +36,7 @@ linux:!mobile_platform {
SOURCES += mainwindow.cpp \
debugger_disasm.cpp \
EmuThread.cpp\
qtapp.cpp \
QtHost.cpp \
qtemugl.cpp \
ctrldisasmview.cpp \
ctrlregisterlist.cpp \
@ -45,7 +44,7 @@ linux:!mobile_platform {
HEADERS += mainwindow.h \
debugger_disasm.h \
EmuThread.h \
qtapp.h \
QtHost.h \
qtemugl.h \
ctrldisasmview.h \
ctrlregisterlist.h \

232
Qt/QtHost.cpp Normal file
View File

@ -0,0 +1,232 @@
// This file is Qt's equivalent of NativeApp.cpp
#include <QFileInfo>
#include <QDebug>
#include "QtHost.h"
#include "LogManager.h"
#include "Core/Debugger/SymbolMap.h"
#include "Core/Config.h"
#include "base/NativeApp.h"
#include "android/jni/MenuScreens.h"
#include "android/jni/EmuScreen.h"
#include "android/jni/UIShader.h"
#include "android/jni/ui_atlas.h"
std::string boot_filename = "";
Texture *uiTexture;
ScreenManager *screenManager;
std::string config_filename;
std::string game_title;
QtHost::QtHost(MainWindow *mainWindow_)
: mainWindow(mainWindow_)
{
QObject::connect(this,SIGNAL(BootDoneSignal()),mainWindow,SLOT(Boot()));
}
void QtHost::InitGL()
{
}
void QtHost::ShutdownGL()
{
//GL_Shutdown();
}
void QtHost::SetWindowTitle(const char *message)
{
// Really need a better way to deal with versions.
QString title = "PPSSPP v0.5 - " + QString::fromUtf8(message);
mainWindow->setWindowTitle(title);
}
void QtHost::UpdateUI()
{
//mainWindow->Update();
mainWindow->UpdateMenus();
}
void QtHost::UpdateMemView()
{
/*for (int i=0; i<numCPUs; i++)
if (memoryWindow[i])
memoryWindow[i]->Update();*/
}
void QtHost::UpdateDisassembly()
{
/*for (int i=0; i<numCPUs; i++)
if (disasmWindow[i])
disasmWindow[i]->Update();*/
/*if(dialogDisasm)
dialogDisasm->Update();*/
}
void QtHost::SetDebugMode(bool mode)
{
/*for (int i=0; i<numCPUs; i++)*/
if(mainWindow->GetDialogDisasm())
mainWindow->GetDialogDisasm()->SetDebugMode(mode);
}
void QtHost::BeginFrame()
{
/*for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
if ((*iter)->UpdateState() == 0)
break; // *iter is std::shared_ptr, **iter is InputDevice
GL_BeginFrame();*/
}
void QtHost::EndFrame()
{
//GL_EndFrame();
}
void QtHost::InitSound(PMixer *mixer)
{
g_mixer = mixer;
}
void QtHost::ShutdownSound()
{
g_mixer = 0;
}
void QtHost::BootDone()
{
symbolMap.SortSymbols();
emit BootDoneSignal();
}
bool QtHost::AttemptLoadSymbolMap()
{
QFileInfo currentFile(fileToStart);
QString ret = currentFile.baseName() + ".map";
return symbolMap.LoadSymbolMap(ret.toAscii().constData());
}
void QtHost::PrepareShutdown()
{
QFileInfo currentFile(fileToStart);
QString ret = currentFile.baseName() + ".map";
symbolMap.SaveSymbolMap(ret.toAscii().constData());
}
void QtHost::AddSymbol(std::string name, u32 addr, u32 size, int type=0)
{
symbolMap.AddSymbol(name.c_str(), addr, size, (SymbolType)type);
}
bool QtHost::IsDebuggingEnabled()
{
#ifdef _DEBUG
return true;
#else
return false;
#endif
}
void NativeMix(short *audio, int num_samples)
{
if (g_mixer)
g_mixer->Mix(audio, num_samples);
}
void NativeInitGraphics()
{
INFO_LOG(BOOT, "NativeInitGraphics - should only be called once!");
gl_lost_manager_init();
ui_draw2d.SetAtlas(&ui_atlas);
screenManager = new ScreenManager();
if (boot_filename.empty()) {
screenManager->switchScreen(new LogoScreen(boot_filename));
} else {
// Go directly into the game.
screenManager->switchScreen(new EmuScreen(boot_filename));
}
// screenManager->switchScreen(new FileSelectScreen());
UIShader_Init();
UITheme theme = {0};
theme.uiFont = UBUNTU24;
theme.uiFontSmall = UBUNTU24;
theme.uiFontSmaller = UBUNTU24;
theme.buttonImage = I_BUTTON;
theme.buttonSelected = I_BUTTON_SELECTED;
theme.checkOn = I_CHECKEDBOX;
theme.checkOff = I_SQUARE;
UIInit(&ui_atlas, theme);
uiTexture = new Texture();
if (!uiTexture->Load("ui_atlas.zim"))
{
qDebug() << "Failed to load texture";
}
uiTexture->Bind(0);
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()
{
EnableFZ();
// 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();
}
void NativeUpdate(InputState &input)
{
UIUpdateMouse(0, input.pointer_x[0], input.pointer_y[0], input.pointer_down[0]);
screenManager->update(input);
}
void NativeShutdownGraphics()
{
delete uiTexture;
uiTexture = NULL;
screenManager->shutdown();
delete screenManager;
screenManager = 0;
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
}

View File

@ -1,15 +1,30 @@
#ifndef QTAPP_H
#define QTAPP_H
#ifndef QTHOST_H
#define QTHOST_H
#include <QObject>
#include "../Core/Host.h"
#include "mainwindow.h"
class QtApp : public QObject, public Host
#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 <QGLWidget>
// Globals
static PMixer *g_mixer;
static QString fileToStart;
static QtEmuGL* glWindow;
class QtHost : public QObject, public Host
{
Q_OBJECT
public:
QtApp(MainWindow* mainWindow);
QtHost(MainWindow* mainWindow);
void UpdateMemView();
void UpdateDisassembly();
@ -24,7 +39,7 @@ public:
void ShutdownGL();
void InitSound(PMixer *mixer);
void UpdateSound();
void UpdateSound() { }
void ShutdownSound();
bool IsDebuggingEnabled();

View File

@ -11,12 +11,11 @@
#include "Core/SaveState.h"
#include "Core/System.h"
#include "Core/Config.h"
#include "file/zip_read.h"
#include "ConsoleListener.h"
#include "base/display.h"
#include "qtapp.h"
#include "qtemugl.h"
#include "QtHost.h"
#include "EmuThread.h"
// Input
const int buttonMappings[18] = {
@ -40,27 +39,59 @@ const int buttonMappings[18] = {
Qt::Key_L, //JOY RIGHT
};
const char *stateToLoad = NULL;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
QMainWindow(parent),
ui(new Ui::MainWindow),
nextState(CORE_POWERDOWN),
dialogDisasm(0),
g_bFullScreen(false)
{
ui->setupUi(this);
qApp->installEventFilter( this );
ui->setupUi(this);
qApp->installEventFilter(this);
controls = new Controls(this);
host = new QtHost(this);
w = ui->widget;
w->init(&input_state);
w->resize(pixel_xres, pixel_yres);
w->setMinimumSize(pixel_xres, pixel_yres);
w->setMaximumSize(pixel_xres, pixel_yres);
/*
DialogManager::AddDlg(memoryWindow[0] = new CMemoryDlg(_hInstance, hwndMain, currentDebugMIPS));
DialogManager::AddDlg(vfpudlg = new CVFPUDlg(_hInstance, hwndMain, currentDebugMIPS));
*/
// Update();
UpdateMenus();
int zoom = g_Config.iWindowZoom;
if (zoom < 1) zoom = 1;
if (zoom > 4) zoom = 4;
SetZoom(zoom);
if (!fileToStart.isNull())
{
SetPlaying(fileToStart);
//Update();
UpdateMenus();
EmuThread_Start(fileToStart, w);
}
else
BrowseAndBoot();
if (!fileToStart.isNull() && stateToLoad != NULL)
SaveState::Load(stateToLoad);
}
MainWindow::~MainWindow()
{
delete ui;
delete ui;
}
void MainWindow::Create(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID)
void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID)
{
std::string config_filename;
Common::EnableCrashingOnCrashes();
@ -74,8 +105,6 @@ void MainWindow::Create(int argc, const char *argv[], const char *savegame_direc
g_Config.Load(config_filename.c_str());
const char *fileToLog = 0;
const char *stateToLoad = NULL;
const char *fileToStart = NULL;
bool hideLog = true;
#ifdef _DEBUG
@ -126,19 +155,18 @@ void MainWindow::Create(int argc, const char *argv[], const char *savegame_direc
break;
}
}
else if (fileToStart == NULL)
else if (fileToStart.isNull())
{
fileToStart = argv[i];
if (!File::Exists(fileToStart))
fileToStart = QString(argv[i]);
if (!QFile::exists(fileToStart))
{
fprintf(stderr, "File not found: %s\n", fileToStart);
qCritical("File '%s' does not exist!", qPrintable(fileToStart));
exit(1);
}
}
else
{
fprintf(stderr, "Can only boot one file");
exit(1);
qCritical("Can only boot one file. Ignoring file '%s'", qPrintable(fileToStart));
}
}
@ -156,44 +184,9 @@ void MainWindow::Create(int argc, const char *argv[], const char *savegame_direc
LogManager::GetInstance()->ChangeFileLog(fileToLog);
//LogManager::GetInstance()->GetConsoleListener()->Open(hideLog, 150, 120, "PPSSPP Debug Console");
LogManager::GetInstance()->SetLogLevel(LogTypes::G3D, LogTypes::LERROR);
w = ui->widget;
w->init(&input_state);
w->resize(pixel_xres, pixel_yres);
w->setMinimumSize(pixel_xres, pixel_yres);
w->setMaximumSize(pixel_xres, pixel_yres);
host = new QtApp(this);
/*
DialogManager::AddDlg(memoryWindow[0] = new CMemoryDlg(_hInstance, hwndMain, currentDebugMIPS));
DialogManager::AddDlg(vfpudlg = new CVFPUDlg(_hInstance, hwndMain, currentDebugMIPS));
*/
// Update();
UpdateMenus();
if (fileToStart != NULL)
{
SetPlaying(fileToStart);
//Update();
UpdateMenus();
EmuThread_Start(fileToStart, w);
}
else
BrowseAndBoot();
if (fileToStart != NULL && stateToLoad != NULL)
SaveState::Load(stateToLoad);
int zoom = g_Config.iWindowZoom;
if (zoom < 1) zoom = 1;
if (zoom > 4) zoom = 4;
SetZoom(zoom);
}
void MainWindow::SetPlaying(const char *text)
void MainWindow::SetPlaying(QString text)
{
// TODO
/*if (text == 0)
@ -366,7 +359,7 @@ void SaveStateActionFinished(bool result, void *userdata)
{
QMessageBox msgBox;
msgBox.setWindowTitle("Load Save State");
msgBox.setText("Savestate failure. Please try again later");
msgBox.setText("Savestate failure. Please try again later");
msgBox.exec();
return;
}

View File

@ -26,7 +26,7 @@ public:
void Create(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID);
void BrowseAndBoot();
void SetNextState(CoreState state);
void SetPlaying(const char *text);
void SetPlaying(QString text);
Debugger_Disasm* GetDialogDisasm() { return dialogDisasm; }
CoreState GetNextState() { return nextState; }

View File

@ -1,123 +0,0 @@
#include <QFileInfo>
#include "qtapp.h"
#include "EmuThread.h"
#include "Core/Debugger/SymbolMap.h"
#include "native/base/NativeApp.h"
QtApp::QtApp(MainWindow *mainWindow_)
: mainWindow(mainWindow_),
QObject(0)
{
QObject::connect(this,SIGNAL(BootDoneSignal()),mainWindow,SLOT(Boot()));
}
void QtApp::InitGL()
{
}
void QtApp::ShutdownGL()
{
//GL_Shutdown();
}
void QtApp::SetWindowTitle(const char *message)
{
// Really need a better way to deal with versions.
QString title = "PPSSPP v0.5 - ";
title += QString::fromUtf8(message);
mainWindow->setWindowTitle(title);
}
void QtApp::InitSound(PMixer *mixer)
{
// NativeSetMixer(mixer);
}
void QtApp::UpdateSound()
{
}
void QtApp::ShutdownSound()
{
// NativeSetMixer(0);
}
void QtApp::UpdateUI()
{
//mainWindow->Update();
mainWindow->UpdateMenus();
}
void QtApp::UpdateMemView()
{
/*for (int i=0; i<numCPUs; i++)
if (memoryWindow[i])
memoryWindow[i]->Update();*/
}
void QtApp::UpdateDisassembly()
{
/*for (int i=0; i<numCPUs; i++)
if (disasmWindow[i])
disasmWindow[i]->Update();*/
/*if(dialogDisasm)
dialogDisasm->Update();*/
}
void QtApp::SetDebugMode(bool mode)
{
/*for (int i=0; i<numCPUs; i++)*/
if(mainWindow->GetDialogDisasm())
mainWindow->GetDialogDisasm()->SetDebugMode(mode);
}
void QtApp::BeginFrame()
{
/*for (auto iter = this->input.begin(); iter != this->input.end(); iter++)
if ((*iter)->UpdateState() == 0)
break; // *iter is std::shared_ptr, **iter is InputDevice
GL_BeginFrame();*/
}
void QtApp::EndFrame()
{
//GL_EndFrame();
}
void QtApp::BootDone()
{
symbolMap.SortSymbols();
emit BootDoneSignal();
}
bool QtApp::AttemptLoadSymbolMap()
{
QFileInfo currentFile(GetCurrentFilename());
QString ret = currentFile.baseName() + ".map";
return symbolMap.LoadSymbolMap(ret.toAscii().constData());
}
void QtApp::PrepareShutdown()
{
QFileInfo currentFile(GetCurrentFilename());
QString ret = currentFile.baseName() + ".map";
symbolMap.SaveSymbolMap(ret.toAscii().constData());
}
void QtApp::AddSymbol(std::string name, u32 addr, u32 size, int type=0)
{
symbolMap.AddSymbol(name.c_str(), addr, size, (SymbolType)type);
}
bool QtApp::IsDebuggingEnabled()
{
#ifdef _DEBUG
return true;
#else
return false;
#endif
}

View File

@ -10,7 +10,7 @@ QtEmuGL::QtEmuGL(QWidget *parent) :
void QtEmuGL::init(InputState *inputState)
{
thread.init(this, inputState);
thread.init(inputState);
}
void QtEmuGL::SetRunning(bool value)

View File

@ -135,11 +135,6 @@ void NativeHost::ShutdownSound()
g_mixer = 0;
}
void NativeSetMixer(void* mix)
{
g_mixer = (PMixer*)mix;
}
void NativeMix(short *audio, int num_samples)
{
if (g_mixer)