even more work

This commit is contained in:
Rosalie Wanders
2020-09-17 20:49:13 +02:00
parent f0e1318cef
commit 6fbe4c8ecc
50 changed files with 1527 additions and 943 deletions
+3
View File
@@ -19,6 +19,9 @@ install(FILES ${MUPEN64PLUSCORE_LIB}
install(FILES ${MUPEN64PLUSCORE_INI} ${MUPEN64PLUSCORE_CHT}
DESTINATION rmg/Data
)
install(FILES Config/stylesheet.qss
DESTINATION rmg/Config
)
install(FILES ${MUPEN64PLUS_PLUGIN_AUDIO}
DESTINATION rmg/Plugin/Audio
)
+9
View File
@@ -0,0 +1,9 @@
/* Rosalie's Mupen GUI Stylesheet */
QTableView
{
border: none;
color: #006600;
selection-color: #FFFFFF;
selection-background-color: #006600;
}
+2 -2
View File
@@ -88,8 +88,8 @@ ExternalProject_Add(mupen64plus-input-raphnetraw
ExternalProject_Add(mupen64plus-video-GLideN64
SOURCE_DIR mupen64plus-video-GLideN64
GIT_REPOSITORY https://github.com/Rosalie241/GLideN64
GIT_TAG 2021a8e674dbcd744fd7fddeb1eff9e3beb9deb8
GIT_REPOSITORY https://github.com/gonetz/GLideN64
GIT_TAG 229a6bc788fe4601fbe00288fcccdedb9396340f
INSTALL_COMMAND ""
+10 -4
View File
@@ -11,9 +11,17 @@ add_executable(RMG
UserInterface/MainWindow.cpp
UserInterface/RomBrowserWidget.cpp
Thread/RomSearcherThread.cpp
Mupen/Mupen.cpp
Mupen/VidExt.cpp
Thread/EmulationThread.cpp
M64P/CoreApi.cpp
M64P/ConfigApi.cpp
M64P/PluginApi.cpp
M64P/Api.cpp
M64P/Wrapper/Config.cpp
M64P/Wrapper/Core.cpp
M64P/Wrapper/Plugin.cpp
M64P/Wrapper/Api.cpp
Util/Logger.cpp
Globals.cpp
main.cpp
)
@@ -24,6 +32,4 @@ endif(UNIX)
target_link_libraries(RMG ${SDL2_LIBRARIES})
target_include_directories(RMG PRIVATE ${SDL2_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
message(${CMAKE_SOURCE_DIR})
target_link_libraries(RMG Qt5::Widgets)
+1
View File
@@ -16,6 +16,7 @@
#define APP_SETTINGS_GEOMETRY "geometry"
#define APP_ROMSEARCHER_MAX 50
#define APP_STYLESHEET_FILE "Config/stylesheet.qss"
#ifdef _WIN32
#define MUPEN_CORE_FILE "Core\\mupen64plus.dll"
+4
View File
@@ -0,0 +1,4 @@
#include <Globals.hpp>
Util::Logger g_Logger;
M64P::Wrapper::Api g_MupenApi;
+10
View File
@@ -0,0 +1,10 @@
#ifndef GLOBALS_HPP
#define GLOBALS_HPP
#include "Util/Logger.hpp"
#include "M64P/Wrapper/Api.hpp"
extern Util::Logger g_Logger;
extern M64P::Wrapper::Api g_MupenApi;
#endif // GLOBALS_HPP
+7
View File
@@ -0,0 +1,7 @@
#include <M64P/Api.hpp>
namespace M64P
{
M64P::CoreApi Core;
M64P::ConfigApi Config;
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef M64P_API_HPP
#define M64P_API_HPP
#include "CoreApi.hpp"
#include "ConfigApi.hpp"
namespace M64P
{
extern M64P::CoreApi Core;
extern M64P::ConfigApi Config;
} // namespace M64P
#endif // M64P_API_HPP
+61
View File
@@ -0,0 +1,61 @@
#include "ConfigApi.hpp"
#include "Macros.hpp"
using namespace M64P;
ConfigApi::ConfigApi(void)
{
}
ConfigApi::~ConfigApi(void)
{
}
bool ConfigApi::Hook(m64p_dynlib_handle handle)
{
this->error_Message = "ConfigApi::Hook Failed: ";
HOOK_FUNC(handle, Config, ListSections);
HOOK_FUNC(handle, Config, OpenSection);
HOOK_FUNC(handle, Config, ListParameters);
HOOK_FUNC(handle, Config, SaveFile);
HOOK_FUNC(handle, Config, SaveSection);
HOOK_FUNC(handle, Config, HasUnsavedChanges);
HOOK_FUNC(handle, Config, DeleteSection);
HOOK_FUNC(handle, Config, RevertChanges);
HOOK_FUNC(handle, Config, SetParameter);
HOOK_FUNC(handle, Config, SetParameterHelp);
HOOK_FUNC(handle, Config, GetParameter);
HOOK_FUNC(handle, Config, GetParameterType);
HOOK_FUNC(handle, Config, GetParameterHelp);
HOOK_FUNC(handle, Config, SetDefaultInt);
HOOK_FUNC(handle, Config, SetDefaultFloat);
HOOK_FUNC(handle, Config, SetDefaultBool);
HOOK_FUNC(handle, Config, SetDefaultString);
HOOK_FUNC(handle, Config, GetParamInt);
HOOK_FUNC(handle, Config, GetParamFloat);
HOOK_FUNC(handle, Config, GetParamBool);
HOOK_FUNC(handle, Config, GetParamString);
HOOK_FUNC(handle, Config, GetSharedDataFilepath);
HOOK_FUNC(handle, Config, GetUserConfigPath);
HOOK_FUNC(handle, Config, GetUserDataPath);
HOOK_FUNC(handle, Config, GetUserCachePath);
HOOK_FUNC(handle, Config, ExternalOpen);
HOOK_FUNC(handle, Config, ExternalClose);
HOOK_FUNC(handle, Config, ExternalGetParameter);
HOOK_FUNC(handle, Config, SendNetplayConfig);
HOOK_FUNC(handle, Config, ReceiveNetplayConfig);
this->hooked = true;
return true;
}
bool ConfigApi::IsHooked(void)
{
return this->hooked;
}
QString ConfigApi::GetLastError(void)
{
return this->error_Message;
}
+59
View File
@@ -0,0 +1,59 @@
#ifndef M64P_CONFIGAPI_HPP
#define M64P_CONFIGAPI_HPP
#include "api/m64p_config.h"
#include <QString>
namespace M64P
{
class ConfigApi
{
public:
ConfigApi(void);
~ConfigApi(void);
bool Hook(m64p_dynlib_handle handle);
bool IsHooked(void);
QString GetLastError(void);
ptr_ConfigListSections ListSections;
ptr_ConfigOpenSection OpenSection;
ptr_ConfigListParameters ListParameters;
ptr_ConfigSaveFile SaveFile;
ptr_ConfigSaveSection SaveSection;
ptr_ConfigHasUnsavedChanges HasUnsavedChanges;
ptr_ConfigDeleteSection DeleteSection;
ptr_ConfigRevertChanges RevertChanges;
ptr_ConfigSetParameter SetParameter;
ptr_ConfigSetParameterHelp SetParameterHelp;
ptr_ConfigGetParameter GetParameter;
ptr_ConfigGetParameterType GetParameterType;
ptr_ConfigGetParameterHelp GetParameterHelp;
ptr_ConfigSetDefaultInt SetDefaultInt;
ptr_ConfigSetDefaultFloat SetDefaultFloat;
ptr_ConfigSetDefaultBool SetDefaultBool;
ptr_ConfigSetDefaultString SetDefaultString;
ptr_ConfigGetParamInt GetParamInt;
ptr_ConfigGetParamFloat GetParamFloat;
ptr_ConfigGetParamBool GetParamBool;
ptr_ConfigGetParamString GetParamString;
ptr_ConfigGetSharedDataFilepath GetSharedDataFilepath;
ptr_ConfigGetUserConfigPath GetUserConfigPath;
ptr_ConfigGetUserDataPath GetUserDataPath;
ptr_ConfigGetUserCachePath GetUserCachePath;
ptr_ConfigExternalOpen ExternalOpen;
ptr_ConfigExternalClose ExternalClose;
ptr_ConfigExternalGetParameter ExternalGetParameter;
ptr_ConfigSendNetplayConfig SendNetplayConfig;
ptr_ConfigReceiveNetplayConfig ReceiveNetplayConfig;
private:
bool hooked = false;
QString error_Message;
};
} // namespace M64P
#endif // M64P_CONFIGAPI_HPP
+42
View File
@@ -0,0 +1,42 @@
#include "CoreApi.hpp"
#include "Macros.hpp"
using namespace M64P;
CoreApi::CoreApi(void)
{
}
CoreApi::~CoreApi(void)
{
}
bool CoreApi::Hook(m64p_dynlib_handle handle)
{
this->error_Message = "CoreApi::Hook Failed: ";
HOOK_FUNC(handle, Core, Startup);
HOOK_FUNC(handle, Core, Shutdown);
HOOK_FUNC(handle, Core, AttachPlugin);
HOOK_FUNC(handle, Core, DetachPlugin);
HOOK_FUNC(handle, Core, DoCommand);
HOOK_FUNC(handle, Core, OverrideVidExt);
HOOK_FUNC(handle, Core, AddCheat);
HOOK_FUNC(handle, Core, CheatEnabled);
HOOK_FUNC(handle, Core, GetRomSettings);
HOOK_FUNC(handle, Core, GetAPIVersions);
HOOK_FUNC(handle, Core, ErrorMessage);
this->hooked = true;
return true;
}
bool CoreApi::IsHooked(void)
{
return this->hooked;
}
QString CoreApi::GetLastError(void)
{
return this->error_Message;
}
+41
View File
@@ -0,0 +1,41 @@
#ifndef M64P_COREAPI_HPP
#define M64P_COREAPI_HPP
#include "api/m64p_frontend.h"
#include "api/m64p_common.h"
#include <QString>
namespace M64P
{
class CoreApi
{
public:
CoreApi();
~CoreApi();
bool Hook(m64p_dynlib_handle handle);
bool IsHooked(void);
QString GetLastError(void);
ptr_CoreStartup Startup;
ptr_CoreShutdown Shutdown;
ptr_CoreAttachPlugin AttachPlugin;
ptr_CoreDetachPlugin DetachPlugin;
ptr_CoreDoCommand DoCommand;
ptr_CoreOverrideVidExt OverrideVidExt;
ptr_CoreAddCheat AddCheat;
ptr_CoreCheatEnabled CheatEnabled;
ptr_CoreGetRomSettings GetRomSettings;
ptr_CoreGetAPIVersions GetAPIVersions;
ptr_CoreErrorMessage ErrorMessage;
private:
bool hooked = false;
QString error_Message;
};
} // namespace M64P
#endif // M64P_COREAPI_HPP
+29
View File
@@ -0,0 +1,29 @@
#ifndef M64P_MACROS_HPP
#define M64P_MACROS_HPP
#ifdef _WIN32
#include <windows.h>
#define DLOPEN(lib) LoadLibrary(lib)
#define DLCLOSE(lib) FreeLibrary(lib)
#define DLSYM(lib, func) GetProcAddress(lib, func)
#define DLGETERRSTR() GetLastError()
#else
#include <dlfcn.h>
#define DLOPEN(lib) dlopen(lib, RTLD_LAZY)
#define DLCLOSE(lib) dlclose(lib)
#define DLSYM(lib, func) dlsym(lib, func)
#define DLGETERRSTR() dlerror()
#endif
#define HOOK_FUNC_OPT(handle, prevar, var) \
this->var = (ptr_##prevar##var)DLSYM(handle, #prevar#var);
#define HOOK_FUNC(handle, prevar, var) \
this->var = (ptr_##prevar##var)DLSYM(handle, #prevar#var); \
if (this->var == nullptr) \
{ \
this->error_Message += DLGETERRSTR(); \
return false; \
}
#endif // M64P_MACROS_HPP
+29
View File
@@ -0,0 +1,29 @@
#include "PluginApi.hpp"
#include "Macros.hpp"
using namespace M64P;
PluginApi::PluginApi(void)
{
}
PluginApi::~PluginApi(void)
{
}
bool PluginApi::Hook(m64p_dynlib_handle handle)
{
this->error_Message = "PluginApi::Hook Failed: ";
HOOK_FUNC(handle, Plugin, Startup);
HOOK_FUNC(handle, Plugin, Shutdown);
HOOK_FUNC_OPT(handle, Plugin, Config);
HOOK_FUNC(handle, Plugin, GetVersion);
return true;
}
QString PluginApi::GetLastError(void)
{
return this->error_Message;
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef M64P_PLUGINAPI_HPP
#define M64P_PLUGINAPI_HPP
#include "api/m64p_common.h"
#include "api/m64p_custom.h"
#include <QString>
namespace M64P
{
class PluginApi
{
public:
PluginApi(void);
~PluginApi(void);
bool Hook(m64p_dynlib_handle);
QString GetLastError(void);
ptr_PluginStartup Startup;
ptr_PluginShutdown Shutdown;
ptr_PluginConfig Config;
ptr_PluginGetVersion GetVersion;
private:
QString error_Message;
};
} // namespace M64P
#endif // M64P_PLUGINAPI_HPP
+78
View File
@@ -0,0 +1,78 @@
#include "Api.hpp"
#include "../Api.hpp"
#include "../Macros.hpp"
using namespace M64P::Wrapper;
Api::Api(void)
{
}
Api::~Api(void)
{
this->core_Handle_Close();
}
bool Api::Init(QString file)
{
this->error_Message = "Api::Init Failed: ";
if (!this->core_Handle_Open(file))
return false;
if (!M64P::Core.Hook(this->core_Handle))
{
this->error_Message += M64P::Core.GetLastError();
return false;
}
if (!M64P::Config.Hook(this->core_Handle))
{
this->error_Message += M64P::Config.GetLastError();
return false;
}
if (!this->Core.Init(this->core_Handle))
{
this->error_Message += this->Core.GetLastError();
return false;
}
if (!this->Config.Init())
{
this->error_Message += this->Config.GetLastError();
return false;
}
return true;
}
QString Api::GetLastError(void)
{
return this->error_Message;
}
bool Api::core_Handle_Open(QString file)
{
this->core_Handle_Close();
this->core_Handle = DLOPEN(file.toStdString().c_str());
if (this->core_Handle == NULL)
{
this->error_Message += DLGETERRSTR();
return false;
}
this->core_Handle_Opened = true;
return true;
}
void Api::core_Handle_Close(void)
{
if (!this->core_Handle_Opened)
return;
DLCLOSE(this->core_Handle);
this->core_Handle_Opened = false;
}
+39
View File
@@ -0,0 +1,39 @@
#ifndef M64P_WRAPPER_API
#define M64P_WRAPPER_API
#include "Core.hpp"
#include "Config.hpp"
#include "Plugin.hpp"
#include "Types.hpp"
#include <QString>
namespace M64P
{
namespace Wrapper
{
class Api
{
public:
Api(void);
~Api(void);
M64P::Wrapper::Core Core;
M64P::Wrapper::Config Config;
bool Init(QString);
QString GetLastError(void);
private:
QString error_Message;
m64p_dynlib_handle core_Handle;
bool core_Handle_Opened;
bool core_Handle_Open(QString);
void core_Handle_Close(void);
};
} // namespace Wrapper
} // namespace M64P
#endif // M64P_WRAPPER_API
+48
View File
@@ -0,0 +1,48 @@
#include <M64P/Wrapper/Config.hpp>
#include <M64P/Api.hpp>
using namespace M64P::Wrapper;
Config::Config(void)
{
}
Config::~Config(void)
{
}
bool Config::Init()
{
if (!M64P::Config.IsHooked())
{
this->error_Message = "M64P::Config is not hooked!";
return false;
}
return true;
}
bool Config::SetOption(QString section, QString key, int value)
{
}
bool Config::SetOption(QString section, QString key, float value)
{
}
bool Config::SetOption(QString section, QString key, bool value)
{
}
bool Config::SetOption(QString section, QString key, QString value)
{
}
QString Config::GetLastError(void)
{
return this->error_Message;
}
+33
View File
@@ -0,0 +1,33 @@
#ifndef M64P_WRAPPER_CONFIG_HPP
#define M64P_WRAPPER_CONFIG_HPP
#include <M64P/ConfigApi.hpp>
#include <QString>
namespace M64P
{
namespace Wrapper
{
class Config
{
public:
Config(void);
~Config(void);
bool Init();
bool SetOption(QString section, QString key, int value);
bool SetOption(QString section, QString key, float value);
bool SetOption(QString section, QString key, bool value);
bool SetOption(QString section, QString key, QString value);
QString GetLastError(void);
private:
QString error_Message;
};
} // namespace Wrapper
} // namespace M64P
#endif // M64P_WRAPPER_CONFIG_HPP
+299
View File
@@ -0,0 +1,299 @@
#include "Core.hpp"
#include "Plugin.hpp"
#include "../Api.hpp"
#include "../api/version.h"
#include "../../Config.hpp"
using namespace M64P::Wrapper;
Core::Core(void)
{
}
Core::~Core(void)
{
}
#include <iostream>
void DebugCallback(void *Context, int level, const char *message)
{
std::cout << level << ": " << message << std::endl;
}
void StateCallback(void *Context2, m64p_core_param ParamChanged, int NewValue)
{
std::cout << ParamChanged << ": " << NewValue << std::endl;
}
bool Core::Init(m64p_dynlib_handle handle)
{
m64p_error ret;
if (!M64P::Core.IsHooked())
{
this->error_Message = "M64P::Core is not hooked!";
return false;
}
ret = M64P::Core.Startup(FRONTEND_API_VERSION, MUPEN_CONFIG_DIR, MUPEN_DATA_DIR, NULL, DebugCallback, NULL, StateCallback);
if (ret != M64ERR_SUCCESS)
{
this->error_Message = "Core::Init M64P::Core.Startup() Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
return false;
}
this->handle = handle;
return true;
}
#include <iostream>
bool Core::HasPluginConfig(PluginType type)
{
return this->plugin_Get(type)->HasConfig();
}
bool Core::OpenPluginConfig(PluginType type)
{
return this->plugin_Get(type)->OpenConfig();
}
M64P::Wrapper::Plugin* Core::plugin_Get(PluginType type)
{
switch(type)
{
case PluginType::Gfx:
return &this->plugin_Gfx;
case PluginType::Rsp:
return &this->plugin_Rsp;
case PluginType::Audio:
return &this->plugin_Audio;
case PluginType::Input:
return &this->plugin_Input;
default:
return nullptr;
}
}
#include <QDir>
QList<Plugin_t> Core::GetPlugins(PluginType type)
{
QList<Plugin_t> plugins;
QString dir;
switch (type)
{
case PluginType::Gfx:
dir = "Plugin/GFX";
break;
case PluginType::Rsp:
dir = "Plugin/RSP";
break;
case PluginType::Audio:
dir = "Plugin/Audio";
break;
case PluginType::Input:
dir = "Plugin/Input";
break;
}
std::cout << dir.toStdString() << std::endl;
QDir qDir(dir);
QFileInfoList fileList = qDir.entryInfoList(QStringList() << "*.so");
Plugin p;
Plugin_t pInfo;
for (const QFileInfo& info : fileList)
{
std::cout << info.absoluteFilePath().toStdString() << std::endl;
if (p.Init(info.absoluteFilePath(), this->handle))
{
pInfo = p.GetPlugin_t();
if (pInfo.Type != type)
continue;
plugins.append(pInfo);
}
else
{
std::cout << "Init failed??" << std::endl;
std::cout << p.GetLastError().toStdString() << std::endl;
}
p.Shutdown();
}
for (const Plugin_t& plugin : plugins)
{
std::cout << "Name: " << plugin.Name.toStdString() << std::endl;
std::cout << "FileName: " << plugin.FileName.toStdString() << std::endl;
std::cout << "Version: " << plugin.Version << std::endl;
this->SetPlugin(plugin);
}
return plugins;
}
bool Core::plugin_Attach(Plugin* p)
{
m64p_error ret;
ret = M64P::Core.AttachPlugin(p->GetType(), p->GetHandle());
if (ret != M64ERR_SUCCESS)
{
this->error_Message = "Core::plugin_Attach Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
}
return ret == M64ERR_SUCCESS;
}
bool Core::plugins_Attach(void)
{
return this->plugin_Attach(&this->plugin_Gfx) &&
this->plugin_Attach(&this->plugin_Audio) &&
this->plugin_Attach(&this->plugin_Input) &&
this->plugin_Attach(&this->plugin_Rsp);
}
bool Core::plugins_Detach(void)
{
M64P::Core.DetachPlugin(M64PLUGIN_GFX);
M64P::Core.DetachPlugin(M64PLUGIN_AUDIO);
M64P::Core.DetachPlugin(M64PLUGIN_INPUT);
M64P::Core.DetachPlugin(M64PLUGIN_RSP);
return true;
}
bool Core::SetPlugin(Plugin_t plugin)
{
bool ret;
Plugin* p = this->plugin_Get(plugin.Type);
ret = p->Init(plugin.FileName, this->handle);
if (!ret)
{
std::cout << "Init failed?????" << std::endl;
std::cout << p->GetLastError().toStdString() << std::endl;
return false;
}
return true;
}
bool Core::GetRomInfo(QString file, RomInfo_t* info)
{
m64p_error ret;
if (!this->rom_Open(file))
return false;
ret = M64P::Core.DoCommand(M64CMD_ROM_GET_HEADER, sizeof(m64p_rom_header), &info->Header);
if (ret != M64ERR_SUCCESS)
{
this->rom_Close();
this->error_Message = "Core::GetRomInfo: M64P::Core.DoCommand(M64CMD_ROM_GET_HEADER) Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
return false;
}
ret = M64P::Core.DoCommand(M64CMD_ROM_GET_SETTINGS, sizeof(m64p_rom_settings), &info->Settings);
if (ret != M64ERR_SUCCESS)
{
this->rom_Close();
this->error_Message = "Core::GetRomInfo: M64P::Core.DoCommand(M64CMD_ROM_GET_SETTINGS) Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
return false;
}
if (!this->rom_Close())
return false;
return true;
}
bool Core::LaunchEmulation(QString file)
{
m64p_error ret;
if (!this->rom_Open(file))
return false;
if (!this->plugins_Attach())
return false;
ret = M64P::Core.DoCommand(M64CMD_EXECUTE, 0, NULL);
this->plugins_Detach();
if (ret != M64ERR_SUCCESS)
{
this->rom_Close();
this->error_Message = "Core::LaunchEmulation M64P::Core.DoCommand(M64CMD_EXECUTE) Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
return false;
}
if (!this->rom_Close())
return false;
return true;
}
QString Core::GetLastError(void)
{
return this->error_Message;
}
bool Core::rom_Open(QString file)
{
m64p_error ret;
QByteArray buffer;
QFile qFile(file);
if (!qFile.open(QIODevice::ReadOnly))
{
this->error_Message = "Core::rom_Open: QFile::open Failed";
return false;
}
buffer = qFile.readAll();
if (buffer.data() == NULL)
std::cout << "WARNING" << std::endl;
ret = M64P::Core.DoCommand(M64CMD_ROM_OPEN, buffer.size(), buffer.data());
if (ret != M64ERR_SUCCESS)
{
this->error_Message = "Core::rom_Open: M64P::Core.DoCommand(M64CMD_ROM_OPEN) Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
}
buffer.clear();
qFile.close();
return ret == M64ERR_SUCCESS;
}
bool Core::rom_Close(void)
{
m64p_error ret;
ret = M64P::Core.DoCommand(M64CMD_ROM_CLOSE, 0, NULL);
if (ret != M64ERR_SUCCESS)
{
this->error_Message = "Core::rom_Close: M64P::Core.DoCommand(M64CMD_ROM_CLOSE) Failed: ";
this->error_Message += M64P::Core.ErrorMessage(ret);
}
return ret == M64ERR_SUCCESS;
}
+55
View File
@@ -0,0 +1,55 @@
#ifndef M64P_WRAPPER_CORE_HPP
#define M64P_WRAPPER_CORE_HPP
#include "Types.hpp"
#include "Plugin.hpp"
#include <QString>
#include <QList>
namespace M64P
{
namespace Wrapper
{
class Core
{
public:
Core(void);
~Core(void);
bool Init(m64p_dynlib_handle);
bool HasPluginConfig(PluginType);
bool OpenPluginConfig(PluginType);
QList<Plugin_t> GetPlugins(PluginType);
bool SetPlugin(Plugin_t);
bool GetRomInfo(QString, RomInfo_t*);
bool LaunchEmulation(QString);
QString GetLastError(void);
private:
QString error_Message;
m64p_dynlib_handle handle;
M64P::Wrapper::Plugin plugin_Rsp;
M64P::Wrapper::Plugin plugin_Gfx;
M64P::Wrapper::Plugin plugin_Audio;
M64P::Wrapper::Plugin plugin_Input;
M64P::Wrapper::Plugin* plugin_Get(PluginType);
bool plugin_Attach(Plugin*);
bool plugins_Attach(void);
bool plugins_Detach(void);
bool rom_Open(QString);
bool rom_Close(void);
};
} // namespace Wrapper
} // namespace M64P
#endif // M64P_WRAPPER_CORE_HPP
+121
View File
@@ -0,0 +1,121 @@
#include "Plugin.hpp"
#include "Types.hpp"
#include "../Macros.hpp"
#include "../Api.hpp"
using namespace M64P::Wrapper;
Plugin::Plugin(void)
{
}
Plugin::~Plugin(void)
{
}
bool Plugin::Init(QString file, m64p_dynlib_handle coreHandle)
{
m64p_error ret;
this->fileName = file;
this->handle = DLOPEN(file.toStdString().c_str());
this->error_Message = "Plugin::Init Failed: ";
if (this->handle == NULL)
{
this->error_Message += DLGETERRSTR();
return false;
}
if (!this->plugin.Hook(this->handle))
{
this->error_Message += this->plugin.GetLastError();
return false;
}
ret = this->plugin.Startup(coreHandle, NULL, NULL);
if (ret != M64ERR_SUCCESS)
{
this->error_Message += M64P::Core.ErrorMessage(ret);
return false;
}
if (!this->plugin_t_Get())
return false;
return true;
}
bool Plugin::Shutdown(void)
{
return this->plugin.Shutdown() == M64ERR_SUCCESS;
}
bool Plugin::HasConfig(void)
{
return this->plugin.Config != NULL;
}
bool Plugin::OpenConfig(void)
{
return this->plugin.Config() == M64ERR_SUCCESS;
}
m64p_dynlib_handle Plugin::GetHandle(void)
{
return this->handle;
}
m64p_plugin_type Plugin::GetType(void)
{
return this->type;
}
Plugin_t Plugin::GetPlugin_t(void)
{
return this->plugin_t;
}
bool Plugin::plugin_t_Get(void)
{
const char* name;
m64p_error ret;
ret = this->plugin.GetVersion(&this->type, &this->plugin_t.Version, &this->plugin_t.ApiVersion, &name, &this->plugin_t.Capabilities);
if (ret != M64ERR_SUCCESS)
{
this->error_Message += this->plugin.GetLastError();
return false;
}
this->plugin_t.FileName = this->fileName;
this->plugin_t.Name = QString::fromStdString(name);
// TODO
switch (this->type)
{
case M64PLUGIN_GFX:
this->plugin_t.Type = PluginType::Gfx;
break;
case M64PLUGIN_AUDIO:
this->plugin_t.Type = PluginType::Audio;
break;
case M64PLUGIN_RSP:
this->plugin_t.Type = PluginType::Rsp;
break;
case M64PLUGIN_INPUT:
this->plugin_t.Type = PluginType::Input;
break;
default:
this->plugin_t.Type = PluginType::Invalid;
break;
}
return true;
}
QString Plugin::GetLastError(void)
{
return this->error_Message;
}
+51
View File
@@ -0,0 +1,51 @@
#ifndef M64P_WRAPPER_PLUGIN_HPP
#define M64P_WRAPPER_PLUGIN_HPP
#include "../api/m64p_types.h"
#include "../PluginApi.hpp"
#include "Types.hpp"
#include <QString>
namespace M64P
{
namespace Wrapper
{
class Plugin
{
public:
Plugin(void);
~Plugin(void);
bool Init(QString, m64p_dynlib_handle);
bool Shutdown(void);
bool HasConfig(void);
bool OpenConfig(void);
m64p_dynlib_handle GetHandle(void);
m64p_plugin_type GetType(void);
Plugin_t GetPlugin_t(void);
QString GetLastError(void);
private:
QString error_Message;
QString fileName;
m64p_dynlib_handle handle;
m64p_plugin_type type;
M64P::PluginApi plugin;
Plugin_t plugin_t;
bool plugin_t_Get(void);
};
} // namespace Wrapper
} // namespace M64P
#endif // M64P_WRAPPER_PLUGIN_HPP
+40
View File
@@ -0,0 +1,40 @@
#ifndef M64P_WRAPPER_TYPES_HPP
#define M64P_WRAPPER_TYPES_HPP
#include "../api/m64p_types.h"
#include <QString>
namespace M64P
{
namespace Wrapper
{
enum PluginType
{
Rsp,
Gfx,
Audio,
Input,
Invalid
};
struct RomInfo_t
{
QString FileName;
m64p_rom_settings Settings;
m64p_rom_header Header;
};
struct Plugin_t
{
QString Name;
QString FileName;
PluginType Type;
int Version;
int ApiVersion;
int Capabilities;
};
} // namespace Wrapper
} // namespace M64P
#endif // M64P_WRAPPER_TYPES_HPP
-296
View File
@@ -1,296 +0,0 @@
#include <Mupen/Mupen.hpp>
#include <Mupen/MupenMacros.hpp>
#include <QFile>
Mupen g_MupenApi;
Mupen::Mupen()
{
}
Mupen::~Mupen()
{
if (this->core_Hooked)
{
this->plugin_Unhook();
this->m64p_CoreShutdown();
DLCLOSE(this->m64p_handle);
}
}
bool Mupen::Init(void)
{
if (!this->core_Hook())
return false;
if (!this->core_Init())
return false;
return true;
}
bool Mupen::Setup(void)
{
return this->plugin_Hook();
}
bool Mupen::SetupVidExt(VidExtFuncs funcs)
{
m64p_error ret;
m64p_VidExt.VidExt_Register(funcs);
ret = m64p_CoreOverrideVidExt(m64p_VidExt.VidExt_GetFuncs());
if (ret != M64ERR_SUCCESS)
{
this->error_message = "Mupen::SetupVidExt Failed: ";
this->error_message += m64p_CoreErrorMessage(ret);
return false;
}
return true;
}
bool Mupen::OpenRom(QString file)
{
m64p_error ret;
if (!this->rom_Open(file))
return false;
if (!this->plugin_Attach())
return false;
ret = m64p_CoreDoCommand(M64CMD_EXECUTE, 0, NULL);
this->rom_Close();
if (ret != M64ERR_SUCCESS)
{
this->error_message = "Mupen::OpenRom Failed: ";
this->error_message += m64p_CoreErrorMessage(ret);
}
return ret == M64ERR_SUCCESS;
}
bool Mupen::HasPluginConfig(PluginType type)
{
ptr_PluginConfig pluginConfig = this->plugin_Config_Get(type);
return pluginConfig != nullptr;
}
bool Mupen::OpenPluginConfig(PluginType type)
{
ptr_PluginConfig pluginConfig = this->plugin_Config_Get(type);
if (pluginConfig == nullptr)
return false;
return pluginConfig() == M64ERR_SUCCESS;
}
bool Mupen::GetRomInfo(QString file, m64p_rom_header* header, m64p_rom_settings* settings)
{
m64p_error ret;
if (!this->rom_Open(file))
return false;
ret = m64p_CoreDoCommand(M64CMD_ROM_GET_HEADER, sizeof(m64p_rom_header), header);
if (ret != M64ERR_SUCCESS)
{
this->rom_Close();
this->error_message = "Mupen::GetRomInfo: m64p_CoreDoCommand(M64CMD_ROM_GET_HEADER) Failed: ";
this->error_message += m64p_CoreErrorMessage(ret);
return false;
}
ret = m64p_CoreDoCommand(M64CMD_ROM_GET_SETTINGS, sizeof(m64p_rom_settings), settings);
if (ret != M64ERR_SUCCESS)
{
this->rom_Close();
this->error_message = "Mupen::GetRomInfo: m64p_CoreDoCommand(M64CMD_ROM_GET_SETTINGS) Failed: ";
this->error_message += m64p_CoreErrorMessage(ret);
return false;
}
if (!this->rom_Close())
return false;
return true;
}
QString Mupen::GetLastError(void)
{
return this->error_message;
}
bool Mupen::core_Hook(void)
{
this->m64p_handle = DLOPEN(MUPEN_CORE_FILE);
if (!this->m64p_handle)
{
this->error_message = "Mupen::core_Hook: DLOPEN Failed: " + QString::fromStdString(DLGETERRSTR());
return false;
}
this->core_Hooked = false;
this->error_message = "Mupen::core_Hook: DLSYM Failed: ";
MUPEN_HOOK_FUNC(CoreStartup);
MUPEN_HOOK_FUNC(CoreShutdown);
MUPEN_HOOK_FUNC(CoreAttachPlugin);
MUPEN_HOOK_FUNC(CoreDetachPlugin);
MUPEN_HOOK_FUNC(CoreDetachPlugin);
MUPEN_HOOK_FUNC(CoreDoCommand);
MUPEN_HOOK_FUNC(CoreOverrideVidExt);
MUPEN_HOOK_FUNC(CoreAddCheat);
MUPEN_HOOK_FUNC(CoreCheatEnabled);
MUPEN_HOOK_FUNC(CoreGetRomSettings);
MUPEN_HOOK_FUNC(CoreErrorMessage);
this->core_Hooked = true;
return true;
}
bool Mupen::core_Init(void)
{
m64p_error ret;
ret = m64p_CoreStartup(FRONTEND_API_VERSION, MUPEN_CONFIG_DIR, MUPEN_DATA_DIR, NULL, NULL, NULL, NULL);
if (ret != M64ERR_SUCCESS)
{
this->error_message = "Mupen::core_Init: m64p_CoreStartup Failed: ";
this->error_message += this->m64p_CoreErrorMessage(ret);
return false;
}
return true;
}
bool Mupen::core_Setup(void)
{
return true;
}
ptr_PluginConfig Mupen::plugin_Config_Get(PluginType type)
{
ptr_PluginConfig pluginConfig;
switch (type)
{
case PluginType::Rsp:
pluginConfig = this->plugin_Config_Rsp;
break;
case PluginType::Gfx:
pluginConfig = this->plugin_Config_Gfx;
break;
case PluginType::Audio:
pluginConfig = this->plugin_Config_Audio;
break;
case PluginType::Input:
pluginConfig = this->plugin_Config_Input;
break;
default:
pluginConfig = nullptr;
break;
}
return pluginConfig;
}
bool Mupen::plugin_Hook(void)
{
m64p_error ret;
this->error_message = "Mupen::plugin_Hook Failed: ";
MUPEN_PLUGIN_HOOK(MUPEN_PLUGIN_RSP, Rsp);
MUPEN_PLUGIN_HOOK(MUPEN_PLUGIN_GFX, Gfx);
MUPEN_PLUGIN_HOOK(MUPEN_PLUGIN_AUDIO, Audio);
MUPEN_PLUGIN_HOOK(MUPEN_PLUGIN_INPUT, Input);
MUPEN_PLUGIN_CONFIG_HOOK(Rsp);
MUPEN_PLUGIN_CONFIG_HOOK(Gfx);
MUPEN_PLUGIN_CONFIG_HOOK(Audio);
MUPEN_PLUGIN_CONFIG_HOOK(Input);
return true;
}
bool Mupen::plugin_Unhook(void)
{
m64p_error ret;
this->error_message = "Mupen::plugin_Unhook Failed: ";
MUPEN_PLUGIN_UNHOOK(MUPEN_PLUGIN_RSP, Rsp);
MUPEN_PLUGIN_UNHOOK(MUPEN_PLUGIN_GFX, Gfx);
MUPEN_PLUGIN_UNHOOK(MUPEN_PLUGIN_AUDIO, Audio);
MUPEN_PLUGIN_UNHOOK(MUPEN_PLUGIN_INPUT, Input);
return true;
}
bool Mupen::plugin_Attach(void)
{
m64p_error ret;
this->error_message = "Mupen::plugin_Attach Failed: ";
MUPEN_PLUGIN_ATTACH(M64PLUGIN_GFX, Gfx);
MUPEN_PLUGIN_ATTACH(M64PLUGIN_AUDIO, Audio);
MUPEN_PLUGIN_ATTACH(M64PLUGIN_INPUT, Input);
MUPEN_PLUGIN_ATTACH(M64PLUGIN_RSP, Rsp);
return true;
}
bool Mupen::plugin_Detach(void)
{
}
bool Mupen::rom_Open(QString file)
{
m64p_error ret;
QByteArray buffer;
QFile qFile(file);
if (!qFile.open(QIODevice::ReadOnly))
{
this->error_message = "Mupen::rom_Open: QFile::open Failed";
return false;
}
buffer = qFile.readAll();
ret = m64p_CoreDoCommand(M64CMD_ROM_OPEN, buffer.size(), buffer.data());
if (ret != M64ERR_SUCCESS)
{
this->error_message = "Mupen::rom_Open: m64p_CoreDoCommand(M64CMD_ROM_OPEN) Failed: ";
this->error_message += this->m64p_CoreErrorMessage(ret);
}
buffer.clear();
qFile.close();
return ret == M64ERR_SUCCESS;
}
bool Mupen::rom_Close(void)
{
m64p_error ret;
ret = m64p_CoreDoCommand(M64CMD_ROM_CLOSE, 0, NULL);
if (ret != M64ERR_SUCCESS)
{
this->error_message = "Mupen::rom_Close: m64p_CoreDoCommand(M64CMD_ROM_CLOSE) Failed: ";
this->error_message += this->m64p_CoreErrorMessage(ret);
}
return ret == M64ERR_SUCCESS;
}
-89
View File
@@ -1,89 +0,0 @@
#ifndef MUPEN_HPP
#define MUPEN_HPP
#include <Mupen/api/m64p_frontend.h>
#include <Mupen/api/m64p_common.h>
#include <Mupen/api/m64p_custom.h>
#include <Mupen/api/version.h>
#include <Mupen/VidExt.hpp>
#include <Config.hpp>
#include <QString>
enum PluginType
{
Rsp,
Gfx,
Audio,
Input
};
class Mupen
{
public:
Mupen();
~Mupen();
bool Init();
bool Setup();
bool SetupVidExt(VidExtFuncs funcs);
bool OpenRom(QString);
bool HasPluginConfig(PluginType);
bool OpenPluginConfig(PluginType);
bool GetRomInfo(QString, m64p_rom_header*, m64p_rom_settings*);
QString GetLastError();
private:
QString error_message;
m64p_dynlib_handle m64p_handle;
ptr_CoreStartup m64p_CoreStartup;
ptr_CoreShutdown m64p_CoreShutdown;
ptr_CoreAttachPlugin m64p_CoreAttachPlugin;
ptr_CoreDetachPlugin m64p_CoreDetachPlugin;
ptr_CoreDoCommand m64p_CoreDoCommand;
ptr_CoreOverrideVidExt m64p_CoreOverrideVidExt;
ptr_CoreAddCheat m64p_CoreAddCheat;
ptr_CoreCheatEnabled m64p_CoreCheatEnabled;
ptr_CoreGetRomSettings m64p_CoreGetRomSettings;
ptr_CoreErrorMessage m64p_CoreErrorMessage;
bool core_Hooked;
bool core_Hook(void);
bool core_Init(void);
bool core_Setup(void);
m64p_dynlib_handle plugin_Rsp;
m64p_dynlib_handle plugin_Gfx;
m64p_dynlib_handle plugin_Audio;
m64p_dynlib_handle plugin_Input;
ptr_PluginConfig plugin_Config_Rsp;
ptr_PluginConfig plugin_Config_Gfx;
ptr_PluginConfig plugin_Config_Audio;
ptr_PluginConfig plugin_Config_Input;
ptr_PluginConfig plugin_Config_Get(PluginType);
ptr_PluginStartup plugin_PluginStartup;
ptr_PluginShutdown plugin_PluginShutdown;
bool plugin_Hook(void);
bool plugin_Unhook(void);
bool plugin_Attach(void);
bool plugin_Detach(void);
bool rom_Open(QString);
bool rom_Close(void);
VidExt m64p_VidExt;
};
extern Mupen g_MupenApi;
#endif // MUPEN_HPP
-90
View File
@@ -1,90 +0,0 @@
#ifndef MUPENMACROS_HPP
#define MUPENMACROS_HPP
#ifdef _WIN32
#include <windows.h>
#define DLOPEN(lib) LoadLibrary(lib)
#define DLCLOSE(lib) FreeLibrary(lib)
#define DLSYM(lib, func) GetProcAddress(lib, func)
#define DLGETERRSTR() GetLastError()
#else
#include <dlfcn.h>
#define DLOPEN(lib) dlopen(lib, RTLD_LAZY)
#define DLCLOSE(lib) dlclose(lib)
#define DLSYM(lib, func) dlsym(lib, func)
#define DLGETERRSTR() dlerror()
#endif
//
// This macro binds m64p_func from m64p_handle (using DLSYM)
// if it fails, appends DLGETERRSTR() to error_message and return false
//
#define MUPEN_HOOK_FUNC(func) \
this->m64p_##func = (ptr_##func)DLSYM(this->m64p_handle, #func); \
if (this->m64p_##func == NULL) \
{ \
this->error_message += DLGETERRSTR(); \
return false; \
}
//
// This macro binds plugin_name from file (using DLOPEN),
// it also binds "PluginStartup" to plugin_PluginStartup (using DLSYM) and
// executes that function (with m64p_handle),
// if it fails, appends DLGETERRSTR() to error_message and return false
//
#define MUPEN_PLUGIN_HOOK(file, name) \
this->plugin_##name = DLOPEN(file); \
if (this->plugin_##name == NULL) \
{ \
this->error_message += DLGETERRSTR(); \
return false; \
}; \
this->plugin_PluginStartup = (ptr_PluginStartup)DLSYM(this->plugin_##name, "PluginStartup"); \
if (this->plugin_PluginStartup == NULL) \
{ \
this->error_message += DLGETERRSTR(); \
return false; \
} \
ret = this->plugin_PluginStartup(this->m64p_handle, NULL, NULL); \
if (ret != M64ERR_SUCCESS) \
{ \
this->error_message += this->m64p_CoreErrorMessage(ret); \
return false; \
}
#define MUPEN_PLUGIN_UNHOOK(file, name) \
this->plugin_PluginShutdown = (ptr_PluginShutdown)DLSYM(this->plugin_##name, "PluginShutdown"); \
if (this->plugin_PluginShutdown == NULL) \
{ \
this->error_message += DLGETERRSTR(); \
return false; \
} \
ret = this->plugin_PluginShutdown(); \
if (ret != M64ERR_SUCCESS) \
{ \
this->error_message += this->m64p_CoreErrorMessage(ret); \
return false; \
} \
DLCLOSE(this->plugin_##name); \
//
// This macro binds "PluginConfig" to plugin_Config_name (using DLSYM)
//
#define MUPEN_PLUGIN_CONFIG_HOOK(name) \
this->plugin_Config_##name = (ptr_PluginConfig)DLSYM(this->plugin_##name, "PluginConfig");
//
// This macro attachs plugin_name with type to mupen using m64p_CoreAttachPlugin,
// if it fails, appends m64p_CoreErrorMessage(ret) to error_message and return false
//
#define MUPEN_PLUGIN_ATTACH(type, name) \
ret = this->m64p_CoreAttachPlugin(type, this->plugin_##name); \
if (ret != M64ERR_SUCCESS) \
{ \
this->error_message += this->m64p_CoreErrorMessage(ret); \
return false; \
}
#endif // MUPENMACROS_HPP
-200
View File
@@ -1,200 +0,0 @@
#include <Mupen/VidExt.hpp>
#include <iostream>
#include <SDL.h>
static VidExtFuncs func;
m64p_error VidExtFuncInit(void)
{
std::cout << "VidExtFuncInit" << std::endl;
// func.VidExtFuncInit();
}
m64p_error VidExtFuncQuit(void)
{
std::cout << "VidExtFuncQuit" << std::endl;
// func.VidExtFuncQuit();
}
m64p_error VidExtFuncListModes(m64p_2d_size *SizeArray, int *NumSizes)
{
SDL_Init(SDL_INIT_VIDEO);
std::cout << "VidExtFuncListModes" << std::endl;
int display = 0; //GetVideoDisplay();
int modeCount = SDL_GetNumDisplayModes(display);
SDL_DisplayMode displayMode;
if (modeCount < 1)
{
std::cout << SDL_GetError() << std::endl;
std::cout << "aa" << modeCount << std::endl;
// DebugMessage(M64MSG_ERROR, "SDL_GetNumDisplayModes failed: %s", SDL_GetError());
return M64ERR_SYSTEM_FAIL;
}
int displayModeCount = 0;
int duplicateFound = 0;
for (int i = 0; (i < modeCount) && (displayModeCount < *NumSizes); i++)
{
if (SDL_GetDisplayMode(display, i, &displayMode) < 0)
{
std::cout << SDL_GetError() << std::endl;
// DebugMessage(M64MSG_ERROR, "SDL_GetDisplayMode failed: %s", SDL_GetError());
return M64ERR_SYSTEM_FAIL;
}
// Check for duplicates
duplicateFound = 0;
for (int x = 0; x <= displayModeCount; x++)
{
if (SizeArray[x].uiHeight == displayMode.h &&
SizeArray[x].uiWidth == displayMode.w)
{
duplicateFound = 1;
break;
}
}
// Skip duplicate
if (duplicateFound == 1)
continue;
SizeArray[displayModeCount].uiHeight = displayMode.h;
SizeArray[displayModeCount].uiWidth = displayMode.w;
displayModeCount++;
}
std::cout << displayModeCount << std::endl;
*NumSizes = displayModeCount;
return M64ERR_SUCCESS;
}
m64p_error VidExtFuncListRates(m64p_2d_size Size, int *NumRates, int *Rates)
{
std::cout << "VidExtFuncListRates" << std::endl;
if (!SDL_WasInit(SDL_INIT_VIDEO))
return M64ERR_NOT_INIT;
int display = 0; //GetVideoDisplay();
int modeCount = SDL_GetNumDisplayModes(display);
SDL_DisplayMode displayMode;
if (modeCount < 1)
{
// DebugMessage(M64MSG_ERROR, "SDL_GetNumDisplayModes failed: %s", SDL_GetError());
return M64ERR_SYSTEM_FAIL;
}
int rateCount = 0;
for (int i = 0; (i < modeCount) && (rateCount < *NumRates); i++)
{
if (SDL_GetDisplayMode(display, i, &displayMode) < 0)
{
// DebugMessage(M64MSG_ERROR, "SDL_GetDisplayMode failed: %s", SDL_GetError());
return M64ERR_SYSTEM_FAIL;
}
/* skip when we're not at the right resolution */
if (displayMode.w != Size.uiWidth ||
displayMode.h != Size.uiHeight)
continue;
Rates[rateCount] = displayMode.refresh_rate;
rateCount++;
}
*NumRates = rateCount;
return M64ERR_SUCCESS;
}
m64p_error VidExtFuncSetMode(int, int, int, int, int)
{
std::cout << "VidExtFuncSetMode" << std::endl;
}
m64p_error VidExtFuncSetModeWithRate(int, int, int, int, int, int)
{
std::cout << "VidExtFuncSetModeWithRate" << std::endl;
}
m64p_function VidExtFuncGLGetProc(const char *)
{
std::cout << "VidExtFuncGLGetProc" << std::endl;
}
m64p_error VidExtFuncGLSetAttr(m64p_GLattr, int)
{
std::cout << "VidExtFuncGLSetAttr" << std::endl;
}
m64p_error VidExtFuncGLGetAttr(m64p_GLattr, int *)
{
std::cout << "VidExtFuncGLGetAttr" << std::endl;
}
m64p_error VidExtFuncGLSwapBuf(void)
{
std::cout << "VidExtFuncGLSwapBuf" << std::endl;
}
m64p_error VidExtFuncSetCaption(const char *)
{
std::cout << "VidExtFuncSetCaption" << std::endl;
}
m64p_error VidExtFuncToggleFS(void)
{
std::cout << "VidExtFuncToggleFS" << std::endl;
}
m64p_error VidExtFuncResizeWindow(int, int)
{
std::cout << "VidExtFuncResizeWindow" << std::endl;
}
uint32_t VidExtFuncGLGetDefaultFramebuffer(void)
{
std::cout << "VidExtFuncGLGetDefaultFramebuffer" << std::endl;
}
VidExt::VidExt(void)
{
this->m64p_vidext_funcs.Functions = 14;
this->m64p_vidext_funcs.VidExtFuncInit = &VidExtFuncInit;
this->m64p_vidext_funcs.VidExtFuncQuit = &VidExtFuncQuit;
this->m64p_vidext_funcs.VidExtFuncListModes = &VidExtFuncListModes;
this->m64p_vidext_funcs.VidExtFuncListRates = &VidExtFuncListRates;
this->m64p_vidext_funcs.VidExtFuncSetMode = &VidExtFuncSetMode;
this->m64p_vidext_funcs.VidExtFuncSetModeWithRate = &VidExtFuncSetModeWithRate;
this->m64p_vidext_funcs.VidExtFuncGLGetProc = &VidExtFuncGLGetProc;
this->m64p_vidext_funcs.VidExtFuncGLSetAttr = &VidExtFuncGLSetAttr;
this->m64p_vidext_funcs.VidExtFuncGLGetAttr = &VidExtFuncGLGetAttr;
this->m64p_vidext_funcs.VidExtFuncGLSwapBuf = &VidExtFuncGLSwapBuf;
this->m64p_vidext_funcs.VidExtFuncSetCaption = &VidExtFuncSetCaption;
this->m64p_vidext_funcs.VidExtFuncToggleFS = &VidExtFuncToggleFS;
this->m64p_vidext_funcs.VidExtFuncResizeWindow = &VidExtFuncResizeWindow;
this->m64p_vidext_funcs.VidExtFuncGLGetDefaultFramebuffer = &VidExtFuncGLGetDefaultFramebuffer;
}
VidExt::~VidExt(void)
{
}
m64p_video_extension_functions *VidExt::VidExt_GetFuncs()
{
return &this->m64p_vidext_funcs;
}
void VidExt::VidExt_Register(VidExtFuncs funcs)
{
func = funcs;
}
-28
View File
@@ -1,28 +0,0 @@
#ifndef VIDEXT_HPP
#define VIDEXT_HPP
#include "api/m64p_types.h"
#include <functional>
struct VidExtFuncs
{
std::function<m64p_error(void)> VidExtFuncInit;
std::function<m64p_error(void)> VidExtFuncQuit;
};
class VidExt
{
public:
VidExt();
~VidExt();
void VidExt_Register(VidExtFuncs funcs);
m64p_video_extension_functions* VidExt_GetFuncs();
private:
VidExtFuncs funcs;
m64p_video_extension_functions m64p_vidext_funcs;
};
#endif // VIDEXT_HPP
+35
View File
@@ -0,0 +1,35 @@
#include "EmulationThread.hpp"
using namespace Thread;
EmulationThread::EmulationThread(void)
{
}
EmulationThread::~EmulationThread(void)
{
}
void EmulationThread::SetRomFile(QString file)
{
this->rom_File = file;
}
void EmulationThread::run(void)
{
emit this->on_Emulation_Started();
bool ret;
ret = g_MupenApi.Core.LaunchEmulation(this->rom_File);
if (!ret)
this->error_Message = g_MupenApi.Core.GetLastError();
emit this->on_Emulation_Finished(ret);
}
QString EmulationThread::GetLastError(void)
{
return this->error_Message;
}
+35
View File
@@ -0,0 +1,35 @@
#ifndef EMULATIONTHREAD_HPP
#define EMULATIONTHREAD_HPP
#include "../Globals.hpp"
#include <QThread>
#include <QString>
namespace Thread
{
class EmulationThread : public QThread
{
Q_OBJECT
public:
EmulationThread(void);
~EmulationThread(void);
void SetRomFile(QString);
void run(void) override;
QString GetLastError(void);
private:
QString rom_File;
QString error_Message;
signals:
void on_Emulation_Started(void);
void on_Emulation_Finished(bool);
};
} // namespace Thread
#endif // EMULATIONTHREAD_HPP
+13 -21
View File
@@ -1,12 +1,17 @@
#include <Thread/RomSearcherThread.hpp>
#include <Mupen/Mupen.hpp>
#include <Util/Logger.hpp>
#include "RomSearcherThread.hpp"
#include "../Globals.hpp"
#include <QDir>
using namespace Thread;
RomSearcherThread::RomSearcherThread(void)
{
qRegisterMetaType<m64p_rom_info>("m64p_rom_info");
qRegisterMetaType<M64P::Wrapper::RomInfo_t>("M64P::Wrapper::RomInfo_t");
}
RomSearcherThread::~RomSearcherThread(void)
{
}
void RomSearcherThread::SetDirectory(QString directory)
@@ -24,7 +29,7 @@ void RomSearcherThread::SetMaximumFiles(int value)
this->rom_Search_MaxItems = value;
}
void RomSearcherThread::run()
void RomSearcherThread::run(void)
{
this->rom_Search_Count = 0;
this->rom_Search(this->rom_Directory);
@@ -42,7 +47,7 @@ void RomSearcherThread::rom_Search(QString directory)
QFileInfoList fileList = dir.entryInfoList(filter, QDir::Files);
QFileInfo fileInfo;
m64p_rom_info romInfo;
M64P::Wrapper::RomInfo_t romInfo;
bool ret;
for (int i = 0; i < fileList.size(); i++)
@@ -72,20 +77,7 @@ void RomSearcherThread::rom_Search(QString directory)
}
}
bool RomSearcherThread::rom_Get_Info(QString file, m64p_rom_info *info)
bool RomSearcherThread::rom_Get_Info(QString file, M64P::Wrapper::RomInfo_t* info)
{
m64p_rom_header header;
m64p_rom_settings settings;
if (!g_MupenApi.GetRomInfo(file, &header, &settings))
{
g_Logger.AddText("RomSearcherThread::rom_Get_Info: " + g_MupenApi.GetLastError());
return false;
}
info->file = file;
info->m64p_header = header;
info->m64p_settings = settings;
return true;
return g_MupenApi.Core.GetRomInfo(file, info);
}
+23 -27
View File
@@ -1,43 +1,39 @@
#ifndef ROMSEARCHERTHREAD_HPP
#define ROMSEARCHERTHREAD_HPP
#include <Mupen/Mupen.hpp>
#include "../Globals.hpp"
#include <QThread>
#include <QString>
struct m64p_rom_info
namespace Thread
{
QString file;
m64p_rom_settings m64p_settings;
m64p_rom_header m64p_header;
};
class RomSearcherThread : public QThread
{
Q_OBJECT
class RomSearcherThread : public QThread
{
Q_OBJECT
public:
RomSearcherThread(void);
~RomSearcherThread(void);
public:
RomSearcherThread(void);
void SetDirectory(QString);
void SetRecursive(bool);
void SetMaximumFiles(int);
void SetDirectory(QString);
void SetRecursive(bool);
void SetMaximumFiles(int);
void run(void) override;
void run() override;
private:
QString rom_Directory;
bool rom_Search_Recursive;
int rom_Search_MaxItems;
int rom_Search_Count;
private:
QString rom_Directory;
bool rom_Search_Recursive;
int rom_Search_MaxItems;
int rom_Search_Count;
void rom_Search(QString);
bool rom_Get_Info(QString, m64p_rom_info*);
signals:
void on_Rom_Found(m64p_rom_info);
};
void rom_Search(QString);
bool rom_Get_Info(QString, M64P::Wrapper::RomInfo_t*);
signals:
void on_Rom_Found(M64P::Wrapper::RomInfo_t);
};
} // namespace Thread
#endif // ROMSEARCHERTHREAD_HPP
+101 -44
View File
@@ -1,6 +1,6 @@
#include <UserInterface/MainWindow.hpp>
#include <Util/Logger.hpp>
#include <Config.hpp>
#include "MainWindow.hpp"
#include "../Util/Logger.hpp"
#include "../Config.hpp"
#include <QMenuBar>
#include <QStatusBar>
@@ -11,6 +11,8 @@
#include <QString>
#include <QSettings>
using namespace UserInterface;
MainWindow::MainWindow() : QMainWindow(nullptr)
{
}
@@ -18,13 +20,17 @@ MainWindow::MainWindow() : QMainWindow(nullptr)
MainWindow::~MainWindow()
{
// Delete all UI elements
delete this->menuBar;
delete this->ui_Widget_OpenGL;
delete this->ui_Widget_RomBrowser;
delete this->ui_Settings;
/*if (this->menuBar)
delete this->menuBar;
if (this->ui_Widgets)
delete this->ui_Widgets;
if (this->ui_Settings)
delete this->ui_Settings; */
}
bool MainWindow::Init()
bool MainWindow::Init(void)
{
if (!g_Logger.Init())
{
@@ -32,17 +38,16 @@ bool MainWindow::Init()
return false;
}
if (!g_MupenApi.Init())
if (!g_MupenApi.Init(MUPEN_CORE_FILE))
{
this->ui_MessageBox("Error", "Mupen::Init Failed", g_MupenApi.GetLastError());
this->ui_MessageBox("Error", "M64P::Wrapper::Api::Init Failed", g_MupenApi.GetLastError());
return false;
}
if (!g_MupenApi.Setup())
{
this->ui_MessageBox("Error", "Mupen::Setup Failed", g_MupenApi.GetLastError());
return false;
}
g_MupenApi.Core.GetPlugins(M64P::Wrapper::PluginType::Gfx);
g_MupenApi.Core.GetPlugins(M64P::Wrapper::PluginType::Rsp);
g_MupenApi.Core.GetPlugins(M64P::Wrapper::PluginType::Audio);
g_MupenApi.Core.GetPlugins(M64P::Wrapper::PluginType::Input);
this->ui_Init();
this->ui_Setup();
@@ -50,6 +55,9 @@ bool MainWindow::Init()
this->menuBar_Init();
this->menuBar_Setup(false);
this->emulationThread_Init();
this->emulationThread_Connect();
return true;
}
@@ -70,6 +78,8 @@ void MainWindow::ui_Init(void)
void MainWindow::ui_Setup(void)
{
this->ui_Stylesheet_Setup();
this->setWindowTitle(WINDOW_TITLE);
this->setCentralWidget(this->ui_Widgets);
this->restoreGeometry(this->ui_Settings->value(APP_SETTINGS_GEOMETRY).toByteArray());
@@ -82,28 +92,56 @@ void MainWindow::ui_Setup(void)
this->ui_Widgets->setCurrentIndex(1);
}
void MainWindow::ui_Stylesheet_Setup(void)
{
QFile stylesheet(APP_STYLESHEET_FILE);
if (!stylesheet.open(QIODevice::ReadOnly))
return;
this->setStyleSheet(stylesheet.readAll());
}
void MainWindow::ui_MessageBox(QString title, QString text, QString details = "")
{
g_Logger.AddText("MainWindow::ui_MessageBox: " + title + ", " + text + ", " + details + "\n");
g_Logger.AddText("MainWindow::ui_MessageBox: " + title + ", " + text + ", " + details);
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Icon::Critical);
msgBox.setWindowTitle(title);
msgBox.setText("<p align='center'>" + text + "</p>");
msgBox.setText(text);
msgBox.setDetailedText(details);
msgBox.addButton(QMessageBox::Ok);
msgBox.show();
msgBox.exec();
}
void MainWindow::ui_InEmulation(bool inEmulation)
{
int index;
if (inEmulation)
index = 0;
else
index = 1;
this->ui_Widgets->setCurrentIndex(index);
this->menuBar_Setup(inEmulation);
}
void MainWindow::menuBar_Init(void)
{
this->menuBar = new QMenuBar();
this->menuBar_Actions_Init();
this->menuBar_Actions_Connect();
}
void MainWindow::menuBar_Setup(bool inEmulation)
{
this->menuBar_Actions_Setup(inEmulation);
this->menuBar_Actions_Connect();
this->menuBar->clear();
this->menuBar_Menu = this->menuBar->addMenu("File");
this->menuBar_Menu->addAction(this->action_File_OpenRom);
@@ -115,10 +153,13 @@ void MainWindow::menuBar_Setup(bool inEmulation)
this->menuBar_Menu->addSeparator();
this->menuBar_Menu->addAction(this->action_File_Exit);
this->menuBar_Menu = this->menuBar->addMenu("System");
this->menuBar_Menu->setEnabled(inEmulation);
this->menuBar_Menu->addAction(action_System_Reset);
this->menuBar_Menu->addAction(action_System_Pause);
if (inEmulation)
{
this->menuBar_Menu = this->menuBar->addMenu("System");
this->menuBar_Menu->setEnabled(inEmulation);
this->menuBar_Menu->addAction(action_System_Reset);
this->menuBar_Menu->addAction(action_System_Pause);
}
this->menuBar_Menu = this->menuBar->addMenu("Options");
this->menuBar_Menu->addAction(this->action_Options_FullScreen);
@@ -139,6 +180,17 @@ void MainWindow::menuBar_Setup(bool inEmulation)
this->setMenuBar(menuBar);
}
void MainWindow::emulationThread_Init(void)
{
this->emulationThread = new Thread::EmulationThread();
}
void MainWindow::emulationThread_Connect(void)
{
connect(this->emulationThread, &Thread::EmulationThread::on_Emulation_Finished, this, &MainWindow::on_Emulation_Finished);
connect(this->emulationThread, &Thread::EmulationThread::on_Emulation_Started, this, &MainWindow::on_Emulation_Started);
}
void MainWindow::menuBar_Actions_Init(void)
{
this->action_File_OpenRom = new QAction();
@@ -186,13 +238,13 @@ void MainWindow::menuBar_Actions_Setup(bool inEmulation)
this->action_Options_FullScreen->setEnabled(inEmulation);
this->action_Options_FullScreen->setShortcut(QKeySequence("Alt+Return"));
this->action_Options_ConfigGfx->setText("Configure Graphics Plugin...");
this->action_Options_ConfigGfx->setEnabled(g_MupenApi.HasPluginConfig(PluginType::Gfx));
this->action_Options_ConfigGfx->setEnabled(g_MupenApi.Core.HasPluginConfig(M64P::Wrapper::PluginType::Gfx));
this->action_Options_ConfigAudio->setText("Configure Audio Plugin...");
this->action_Options_ConfigAudio->setEnabled(g_MupenApi.HasPluginConfig(PluginType::Audio));
this->action_Options_ConfigAudio->setEnabled(g_MupenApi.Core.HasPluginConfig(M64P::Wrapper::PluginType::Audio));
this->action_Options_ConfigRsp->setText("Configure RSP...");
this->action_Options_ConfigRsp->setEnabled(g_MupenApi.HasPluginConfig(PluginType::Rsp));
this->action_Options_ConfigRsp->setEnabled(g_MupenApi.Core.HasPluginConfig(M64P::Wrapper::PluginType::Rsp));
this->action_Options_ConfigControl->setText("Configure Controller Plugin...");
this->action_Options_ConfigControl->setEnabled(g_MupenApi.HasPluginConfig(PluginType::Input));
this->action_Options_ConfigControl->setEnabled(g_MupenApi.Core.HasPluginConfig(M64P::Wrapper::PluginType::Input));
this->action_Options_Settings->setText("Settings...");
this->action_Options_Settings->setShortcut(QKeySequence("Ctrl+T"));
@@ -224,34 +276,26 @@ void MainWindow::menuBar_Actions_Connect(void)
connect(this->action_Help_About, &QAction::triggered, this, &MainWindow::on_Action_Help_About);
}
bool aa = false;
#include <iostream>
void MainWindow::on_Action_File_OpenRom(void)
{
if (aa)
this->ui_Widgets->setCurrentIndex(0);
else
this->ui_Widgets->setCurrentIndex(1);
aa = !aa;
/*if (!m64p.OpenRom("/home/rosalie/Downloads/Resident Evil 2 (USA) (Rev A).n64"))
{
this->ui_MessageBox("Error", "Mupen::OpenRom Failed", m64p.GetLastError());
}*/
if (this->emulationThread->isRunning())
return;
this->emulationThread->SetRomFile("/home/rosalie/Downloads/n64_roms/Super Mario 64 (U) [!].z64");
this->emulationThread->start();
}
void MainWindow::on_Action_File_OpenCombo(void)
{
}
void MainWindow::on_Action_File_EndEmulation(void)
{
}
void MainWindow::on_Action_File_ChooseDirectory(void)
{
}
void MainWindow::on_Action_File_RefreshRomList(void)
@@ -278,22 +322,22 @@ void MainWindow::on_Action_Options_FullScreen(void)
void MainWindow::on_Action_Options_ConfigGfx(void)
{
g_MupenApi.OpenPluginConfig(PluginType::Gfx);
g_MupenApi.Core.OpenPluginConfig(M64P::Wrapper::PluginType::Gfx);
}
void MainWindow::on_Action_Options_ConfigAudio(void)
{
g_MupenApi.OpenPluginConfig(PluginType::Audio);
g_MupenApi.Core.OpenPluginConfig(M64P::Wrapper::PluginType::Audio);
}
void MainWindow::on_Action_Options_ConfigRsp(void)
{
g_MupenApi.OpenPluginConfig(PluginType::Rsp);
g_MupenApi.Core.OpenPluginConfig(M64P::Wrapper::PluginType::Rsp);
}
void MainWindow::on_Action_Options_ConfigControl(void)
{
g_MupenApi.OpenPluginConfig(PluginType::Input);
g_MupenApi.Core.OpenPluginConfig(M64P::Wrapper::PluginType::Input);
}
void MainWindow::on_Action_Options_Settings(void)
@@ -313,3 +357,16 @@ void MainWindow::on_Action_Help_HomePage(void)
void MainWindow::on_Action_Help_About(void)
{
}
void MainWindow::on_Emulation_Started(void)
{
this->ui_InEmulation(true);
}
void MainWindow::on_Emulation_Finished(bool ret)
{
if (!ret)
this->ui_MessageBox("Error", "EmulationThread::run Failed", this->emulationThread->GetLastError());
this->ui_InEmulation(false);
}
+76 -62
View File
@@ -1,9 +1,9 @@
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <UserInterface/RomBrowserWidget.hpp>
#include <Util/Logger.hpp>
#include <Mupen/Mupen.hpp>
#include "../Thread/EmulationThread.hpp"
#include "RomBrowserWidget.hpp"
#include "../Globals.hpp"
#include <QMainWindow>
#include <QOpenGLWidget>
@@ -12,75 +12,89 @@
#include <QSettings>
#include <QStackedWidget>
class MainWindow : public QMainWindow
namespace UserInterface
{
Q_OBJECT
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
bool Init();
public:
MainWindow(void);
~MainWindow(void);
private:
QOpenGLWidget* ui_Widget_OpenGL;
RomBrowserWidget* ui_Widget_RomBrowser;
QStackedWidget* ui_Widgets;
bool Init(void);
QMenuBar* menuBar;
QMenu* menuBar_Menu;
QAction* action_File_OpenRom;
QAction* action_File_OpenCombo;
QAction* action_File_EndEmulation;
QAction* action_File_ChooseDirectory;
QAction* action_File_RefreshRomList;
QAction* action_File_Exit;
QAction* action_System_Reset;
QAction* action_System_Pause;
QAction* action_Options_FullScreen;
QAction* action_Options_ConfigGfx;
QAction* action_Options_ConfigAudio;
QAction* action_Options_ConfigRsp;
QAction* action_Options_ConfigControl;
QAction* action_Options_Settings;
QAction* action_Help_Support;
QAction* action_Help_HomePage;
QAction* action_Help_About;
private:
Thread::EmulationThread* emulationThread;
QOpenGLWidget *ui_Widget_OpenGL;
RomBrowserWidget *ui_Widget_RomBrowser;
QStackedWidget *ui_Widgets;
QSettings* ui_Settings;
QMenuBar *menuBar;
QMenu *menuBar_Menu;
QAction *action_File_OpenRom;
QAction *action_File_OpenCombo;
QAction *action_File_EndEmulation;
QAction *action_File_ChooseDirectory;
QAction *action_File_RefreshRomList;
QAction *action_File_Exit;
QAction *action_System_Reset;
QAction *action_System_Pause;
QAction *action_Options_FullScreen;
QAction *action_Options_ConfigGfx;
QAction *action_Options_ConfigAudio;
QAction *action_Options_ConfigRsp;
QAction *action_Options_ConfigControl;
QAction *action_Options_Settings;
QAction *action_Help_Support;
QAction *action_Help_HomePage;
QAction *action_Help_About;
void closeEvent(QCloseEvent*);
QSettings *ui_Settings;
void ui_Init();
void ui_Setup();
void ui_MessageBox(QString, QString, QString);
void closeEvent(QCloseEvent *);
void menuBar_Init(void);
void menuBar_Setup(bool);
void ui_Init();
void ui_Setup();
void ui_Stylesheet_Setup();
void ui_MessageBox(QString, QString, QString);
void ui_InEmulation(bool);
void menuBar_Actions_Init(void);
void menuBar_Actions_Setup(bool);
void menuBar_Actions_Connect(void);
void menuBar_Init(void);
void menuBar_Setup(bool);
void on_VidExt_Quit(void);
void emulationThread_Init(void);
void emulationThread_Connect(void);
public slots:
void on_Action_File_OpenRom(void);
void on_Action_File_OpenCombo(void);
void on_Action_File_EndEmulation(void);
void on_Action_File_ChooseDirectory(void);
void on_Action_File_RefreshRomList(void);
void on_Action_File_Exit(void);
void on_Action_System_Reset(void);
void on_Action_System_Pause(void);
void on_Action_Options_FullScreen(void);
void on_Action_Options_ConfigGfx(void);
void on_Action_Options_ConfigAudio(void);
void on_Action_Options_ConfigRsp(void);
void on_Action_Options_ConfigControl(void);
void on_Action_Options_Settings(void);
void on_Action_Help_Support(void);
void on_Action_Help_HomePage(void);
void on_Action_Help_About(void);
};
void menuBar_Actions_Init(void);
void menuBar_Actions_Setup(bool);
void menuBar_Actions_Connect(void);
void on_VidExt_Quit(void);
public slots:
void on_Action_File_OpenRom(void);
void on_Action_File_OpenCombo(void);
void on_Action_File_EndEmulation(void);
void on_Action_File_ChooseDirectory(void);
void on_Action_File_RefreshRomList(void);
void on_Action_File_Exit(void);
void on_Action_System_Reset(void);
void on_Action_System_Pause(void);
void on_Action_Options_FullScreen(void);
void on_Action_Options_ConfigGfx(void);
void on_Action_Options_ConfigAudio(void);
void on_Action_Options_ConfigRsp(void);
void on_Action_Options_ConfigControl(void);
void on_Action_Options_Settings(void);
void on_Action_Help_Support(void);
void on_Action_Help_HomePage(void);
void on_Action_Help_About(void);
void on_Emulation_Started(void);
void on_Emulation_Finished(bool);
};
} // namespace UserInterface
#endif // MAINWINDOW_HPP
+69 -27
View File
@@ -1,15 +1,16 @@
#include <UserInterface/RomBrowserWidget.hpp>
#include <Util/Logger.hpp>
#include <Config.hpp>
#include "RomBrowserWidget.hpp"
#include "../Globals.hpp"
#include "../Config.hpp"
#include <QDir>
using namespace UserInterface;
RomBrowserWidget::RomBrowserWidget(void) : QTableView(nullptr)
{
this->model_Init();
this->model_Setup();
this->widget_Init();
}
RomBrowserWidget::~RomBrowserWidget()
@@ -37,20 +38,22 @@ void RomBrowserWidget::model_Setup(void)
this->rom_List_Fill("/home/rosalie/Downloads/n64_roms/");
QStringList list;
list.append("Name");
list.append("Internal Name");
list.append("MD5");
this->model_LabelList_Setup();
// this->model_Model->setRowCount(this->rom_List_Index);
this->model_Model->setColumnCount(list.size());
this->model_Model->setHorizontalHeaderLabels(list);
this->model_Model->setColumnCount(this->model_LabelList.size());
this->model_Model->setHorizontalHeaderLabels(this->model_LabelList);
}
void RomBrowserWidget::model_LabelList_Setup(void)
{
this->model_LabelList.clear();
this->model_LabelList.append("Name");
this->model_LabelList.append("Internal Name");
this->model_LabelList.append("MD5");
}
#include <iostream>
void RomBrowserWidget::widget_Init(void)
{
this->setModel(this->model_Model);
this->setShowGrid(false);
this->setSelectionBehavior(QTableView::SelectRows);
@@ -58,34 +61,42 @@ void RomBrowserWidget::widget_Init(void)
this->verticalHeader()->hide();
this->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
this->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
this->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
this->horizontalHeader()->setSortIndicatorShown(false);
this->horizontalHeader()->setHighlightSections(false);
this->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
this->verticalHeader()->setSectionResizeMode(QHeaderView::Interactive);
this->verticalHeader()->setMaximumSectionSize(20);
this->column_SetSize();
QFont f = this->font();
f.setPixelSize(11);
this->setFont(f);
}
void RomBrowserWidget::rom_List_Init()
void RomBrowserWidget::rom_Searcher_Init(void)
{
this->rom_Searcher_Thread = new RomSearcherThread();
this->rom_Searcher_Thread = new Thread::RomSearcherThread();
this->rom_Searcher_Thread->SetMaximumFiles(APP_ROMSEARCHER_MAX);
// TODO
this->rom_Searcher_Thread->SetRecursive(true);
connect(rom_Searcher_Thread, &RomSearcherThread::on_Rom_Found, this, &RomBrowserWidget::on_RomBrowserThread_Received);
connect(rom_Searcher_Thread, &RomSearcherThread::finished, this, &RomBrowserWidget::on_RomBrowserThread_Finished);
connect(rom_Searcher_Thread, &Thread::RomSearcherThread::on_Rom_Found, this, &RomBrowserWidget::on_RomBrowserThread_Received);
connect(rom_Searcher_Thread, &Thread::RomSearcherThread::finished, this, &RomBrowserWidget::on_RomBrowserThread_Finished);
}
bool init = false;
void RomBrowserWidget::rom_List_Fill(QString directory)
{
if (!this->rom_List_Fill_Thread_Init)
this->rom_List_Init();
if (!init)
{
this->rom_Searcher_Init();
init = true;
}
if (this->rom_List_Fill_Thread_Running)
return;
@@ -95,18 +106,49 @@ void RomBrowserWidget::rom_List_Fill(QString directory)
this->rom_Searcher_Thread->start();
}
void RomBrowserWidget::on_RomBrowserThread_Received(m64p_rom_info romInfo)
void RomBrowserWidget::column_SetSize(void)
{
for (int i = 0; i < this->model_LabelList.size(); i++)
{
QString label = this->model_LabelList.at(i);
int oldSize = this->columnWidth(i);
int newSize = 0;
if (label == "Name")
{
newSize = 150;
} else if (label == "Internal Name")
{
newSize = 100;
} else if (label == "MD5")
{
newSize = 100;
}
if (oldSize != newSize)
{
this->setColumnWidth(i, oldSize);
}
else
{
this->setColumnWidth(i, newSize);
}
}
}
void RomBrowserWidget::on_RomBrowserThread_Received(M64P::Wrapper::RomInfo_t romInfo)
{
QList<QStandardItem*> list;
list.append(new QStandardItem(romInfo.m64p_settings.goodname));
list.append(new QStandardItem(QString((char*)romInfo.m64p_header.Name)));
list.append(new QStandardItem(romInfo.m64p_settings.MD5));
list.append(new QStandardItem(romInfo.Settings.goodname));
list.append(new QStandardItem(QString((char*)romInfo.Header.Name)));
list.append(new QStandardItem(romInfo.Settings.MD5));
this->model_Model->appendRow(list);
this->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
this->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
this->column_SetSize();
this->horizontalHeader()->setStretchLastSection(true);
}
void RomBrowserWidget::on_RomBrowserThread_Finished(void)
+35 -29
View File
@@ -1,10 +1,10 @@
#ifndef ROMBROWSERWIDGET_HPP
#define ROMBROWSERWIDGET_HPP
#include <Thread/RomSearcherThread.hpp>
#include <Mupen/Mupen.hpp>
#include "../Thread/RomSearcherThread.hpp"
#include "../Globals.hpp"
#include <QTableView>
#include <QTableView>
#include <QStandardItemModel>
#include <QHeaderView>
#include <QString>
@@ -12,42 +12,48 @@
#define MAX_ROM_INFO 50
class RomBrowserWidget: public QTableView
namespace UserInterface
{
Q_OBJECT
class RomBrowserWidget : public QTableView
{
Q_OBJECT
public:
RomBrowserWidget(void);
~RomBrowserWidget(void);
public:
RomBrowserWidget(void);
~RomBrowserWidget(void);
void RefreshRomList(void);
void RefreshRomList(void);
private:
QStandardItemModel* model_Model;
void model_Init(void);
void model_Setup(void);
private:
QStandardItemModel *model_Model;
QStringList model_LabelList;
void model_Init(void);
void model_Setup(void);
void model_LabelList_Setup(void);
void widget_Init(void);
void widget_Init(void);
RomSearcherThread* rom_Searcher_Thread;
bool rom_Searcher_Recursive;
bool rom_Searcher_MaxItems;
bool rom_Searcher_Running;
Thread::RomSearcherThread *rom_Searcher_Thread;
bool rom_Searcher_Recursive;
bool rom_Searcher_MaxItems;
bool rom_Searcher_Running;
m64p_rom_info rom_List[MAX_ROM_INFO];
int rom_List_Index = 0;
void rom_Searcher_Init(void);
bool rom_List_Recursive;
bool rom_List_Fill_Thread_Init;
bool rom_List_Fill_Thread_Running;
void rom_List_Init();
void rom_List_Fill(QString);
M64P::Wrapper::RomInfo_t rom_List[MAX_ROM_INFO];
int rom_List_Index = 0;
bool rom_List_Recursive;
bool rom_List_Fill_Thread_Running;
void rom_List_Init();
void rom_List_Fill(QString);
void column_SetSize();
public slots:
void on_RomBrowserThread_Received(m64p_rom_info info);
void on_RomBrowserThread_Finished(void);
};
public slots:
void on_RomBrowserThread_Received(M64P::Wrapper::RomInfo_t info);
void on_RomBrowserThread_Finished(void);
};
} // namespace UserInterface
#endif // ROMBROWSERWIDGET_HPP
+7 -10
View File
@@ -2,28 +2,27 @@
#include <QDir>
Logger g_Logger;
using namespace Util;
Logger::Logger()
Logger::Logger(void)
{
}
Logger::~Logger()
Logger::~Logger(void)
{
if (this->init)
if (!this->init_Failed)
{
this->logfile.flush();
this->logfile.close();
}
}
bool Logger::Init()
bool Logger::Init(void)
{
if (!QDir().exists(APP_LOG_DIR))
{
if (!QDir().mkdir(APP_LOG_DIR))
{
this->init = false;
this->error_message = "QDir::mkdir Failed";
return false;
}
@@ -33,19 +32,17 @@ bool Logger::Init()
if (!this->logfile.open(QIODevice::WriteOnly | QIODevice::Append))
{
this->init = false;
this->error_message = "QFile::Open Failed";
return false;
}
this->init = true;
this->init_Failed = false;
return true;
}
#include <iostream>
void Logger::AddText(QString text)
{
if (!this->init)
if (this->init_Failed)
return;
if (text[text.size() - 1] != "\n")
+17 -13
View File
@@ -6,25 +6,29 @@
#include <QString>
#include <QFile>
class Logger
namespace Util
{
public:
Logger();
~Logger();
class Logger
{
public:
Logger(void);
~Logger(void);
bool Init(void);
bool Init(void);
void AddText(QString text);
void AddText(QString);
QString GetLastError(void);
QString GetLastError(void);
private:
bool init;
private:
bool init_Failed = true;
QString error_message;
QFile logfile;
};
QString error_message;
QFile logfile;
};
extern Logger g_Logger;
} // namespace Util
extern Util::Logger g_Logger;
#endif // LOGGER_HPP
+1 -1
View File
@@ -8,7 +8,7 @@ int main(int argc, char** argv)
{
QApplication app(argc, argv);
MainWindow window;
UserInterface::MainWindow window;
QDir::setCurrent(app.applicationDirPath());