Fix compiling with latest wut, formatting, remove hbl support

This commit is contained in:
Maschell 2022-01-09 13:37:16 +01:00
parent ed61489bda
commit 02d34db212
37 changed files with 1728 additions and 1761 deletions

View File

@ -17,7 +17,7 @@ include $(DEVKITPRO)/wut/share/wut_rules
# DATA is a list of directories containing data files # DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files # INCLUDES is a list of directories containing header files
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
TARGET := launchiine TARGET := men
BUILD := build BUILD := build
SOURCES := src \ SOURCES := src \
src/fs \ src/fs \

View File

@ -31,22 +31,12 @@
#include "utils/AsyncExecutor.h" #include "utils/AsyncExecutor.h"
#include <thread> #include <thread>
#define HBL_TITLE_ID (0x0005000013374842) Application *Application::applicationInstance = nullptr;
#define MII_MAKER_JPN_TITLE_ID (0x000500101004A000)
#define MII_MAKER_USA_TITLE_ID (0x000500101004A100)
#define MII_MAKER_EUR_TITLE_ID (0x000500101004A200)
Application *Application::applicationInstance = NULL;
bool Application::exitApplication = false; bool Application::exitApplication = false;
bool Application::quitRequest = false; bool Application::quitRequest = false;
Application::Application() Application::Application()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000) : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000), bgMusic(nullptr), video(nullptr), mainWindow(nullptr), fontSystem(nullptr), exitCode(0) {
, bgMusic(NULL)
, video(NULL)
, mainWindow(NULL)
, fontSystem(NULL)
, exitCode(0) {
controller[0] = new VPadController(GuiTrigger::CHANNEL_1); controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
controller[1] = new WPadController(GuiTrigger::CHANNEL_2); controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
controller[2] = new WPadController(GuiTrigger::CHANNEL_3); controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
@ -59,43 +49,30 @@ Application::Application()
bgMusic->Play(); bgMusic->Play();
bgMusic->SetVolume(50); bgMusic->SetVolume(50);
AsyncExecutor::execute([] {DEBUG_FUNCTION_LINE("Hello\n");}); AsyncExecutor::execute([] { DEBUG_FUNCTION_LINE("Hello"); });
exitApplication = false; exitApplication = false;
uint64_t titleID = OSGetTitleID();
// Homebrew Launcher does not like the standard ProcUI application loop,
// so instead we disable the home buttom menu and use the home button
// to trigger an exit.
if (titleID == HBL_TITLE_ID ||
titleID == MII_MAKER_JPN_TITLE_ID ||
titleID == MII_MAKER_USA_TITLE_ID ||
titleID == MII_MAKER_EUR_TITLE_ID) {
// Important: OSEnableHomeButtonMenu must come before ProcUIInitEx.
OSEnableHomeButtonMenu(FALSE);
sFromHBL = TRUE;
}
ProcUIInit(OSSavesDone_ReadyToRelease); ProcUIInit(OSSavesDone_ReadyToRelease);
} }
Application::~Application() { Application::~Application() {
DEBUG_FUNCTION_LINE("Destroy music\n"); DEBUG_FUNCTION_LINE("Destroy music");
delete bgMusic; delete bgMusic;
DEBUG_FUNCTION_LINE("Destroy controller\n"); DEBUG_FUNCTION_LINE("Destroy controller");
for(int32_t i = 0; i < 5; i++) for (auto &i: controller) {
delete controller[i]; delete i;
}
DEBUG_FUNCTION_LINE("Clear resources\n"); DEBUG_FUNCTION_LINE("Clear resources");
Resources::Clear(); Resources::Clear();
DEBUG_FUNCTION_LINE("Stop sound handler\n"); DEBUG_FUNCTION_LINE("Stop sound handler");
SoundHandler::DestroyInstance(); SoundHandler::DestroyInstance();
DEBUG_FUNCTION_LINE("Clear AsyncExecutor\n"); DEBUG_FUNCTION_LINE("Clear AsyncExecutor");
AsyncExecutor::destroyInstance(); AsyncExecutor::destroyInstance();
ProcUIShutdown(); ProcUIShutdown();
@ -155,32 +132,32 @@ void Application::fadeOut() {
} }
} }
bool Application::procUI(void) { bool Application::procUI() {
bool executeProcess = false; bool executeProcess = false;
switch (ProcUIProcessMessages(true)) { switch (ProcUIProcessMessages(true)) {
case PROCUI_STATUS_EXITING: { case PROCUI_STATUS_EXITING: {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING\n"); DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING");
exitCode = EXIT_SUCCESS; exitCode = EXIT_SUCCESS;
exitApplication = true; exitApplication = true;
break; break;
} }
case PROCUI_STATUS_RELEASE_FOREGROUND: { case PROCUI_STATUS_RELEASE_FOREGROUND: {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND\n"); DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND");
if(video != NULL) { if (video != nullptr) {
// we can turn ofF the screen but we don't need to and it will display the last image // we can turn ofF the screen but we don't need to and it will display the last image
video->tvEnable(true); video->tvEnable(true);
video->drcEnable(true); video->drcEnable(true);
DEBUG_FUNCTION_LINE("delete fontSystem\n"); DEBUG_FUNCTION_LINE("delete fontSystem");
delete fontSystem; delete fontSystem;
fontSystem = NULL; fontSystem = nullptr;
DEBUG_FUNCTION_LINE("delete video\n"); DEBUG_FUNCTION_LINE("delete video");
delete video; delete video;
video = NULL; video = nullptr;
DEBUG_FUNCTION_LINE("deinitialze memory\n"); DEBUG_FUNCTION_LINE("deinitialze memory");
libgui_memoryRelease(); libgui_memoryRelease();
ProcUIDrawDoneRelease(); ProcUIDrawDoneRelease();
} else { } else {
@ -190,22 +167,22 @@ bool Application::procUI(void) {
} }
case PROCUI_STATUS_IN_FOREGROUND: { case PROCUI_STATUS_IN_FOREGROUND: {
if (!quitRequest) { if (!quitRequest) {
if(video == NULL) { if (video == nullptr) {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND\n"); DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND");
DEBUG_FUNCTION_LINE("initialze memory\n"); DEBUG_FUNCTION_LINE("initialze memory");
libgui_memoryInitialize(); libgui_memoryInitialize();
DEBUG_FUNCTION_LINE("Initialize video\n"); DEBUG_FUNCTION_LINE("Initialize video");
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE); video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE);
DEBUG_FUNCTION_LINE("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight()); DEBUG_FUNCTION_LINE("Video size %i x %i", video->getTvWidth(), video->getTvHeight());
//! setup default Font //! setup default Font
DEBUG_FUNCTION_LINE("Initialize main font system\n"); DEBUG_FUNCTION_LINE("Initialize main font system");
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); auto *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem); GuiText::setPresetFont(fontSystem);
if(mainWindow == NULL) { if (mainWindow == nullptr) {
DEBUG_FUNCTION_LINE("Initialize main window\n"); DEBUG_FUNCTION_LINE("Initialize main window");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
} }
@ -222,12 +199,12 @@ bool Application::procUI(void) {
return executeProcess; return executeProcess;
} }
void Application::executeThread(void) { void Application::executeThread() {
DEBUG_FUNCTION_LINE("Entering main loop\n"); DEBUG_FUNCTION_LINE("Entering main loop");
//! main GX2 loop (60 Hz cycle with max priority on core 1) //! main GX2 loop (60 Hz cycle with max priority on core 1)
while (!exitApplication) { while (!exitApplication) {
if(procUI() == false) { if (!procUI()) {
continue; continue;
} }
@ -235,20 +212,12 @@ void Application::executeThread(void) {
mainWindow->process(); mainWindow->process();
//! Read out inputs //! Read out inputs
for(int32_t i = 0; i < 5; i++) { for (auto &i: controller) {
if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false) if (!i->update(video->getTvWidth(), video->getTvHeight()))
continue; continue;
//! update controller states //! update controller states
mainWindow->update(controller[i]); mainWindow->update(i);
if(controller[i]->data.buttons_d & VPAD_BUTTON_HOME) {
if (sFromHBL) {
fadeOut();
SYSRelaunchTitle(0, NULL);
continue;
}
}
} }
//! start rendering DRC //! start rendering DRC
@ -278,29 +247,18 @@ void Application::executeThread(void) {
bgMusic->SetVolume(0); bgMusic->SetVolume(0);
} }
//! in case we exit to a homebrew let's smoothly fade out DEBUG_FUNCTION_LINE("delete mainWindow");
if(video) {
uint64_t titleID = OSGetTitleID();
if (titleID == HBL_TITLE_ID ||
titleID == MII_MAKER_JPN_TITLE_ID ||
titleID == MII_MAKER_USA_TITLE_ID ||
titleID == MII_MAKER_EUR_TITLE_ID) {
fadeOut();
}
}
DEBUG_FUNCTION_LINE("delete mainWindow\n");
delete mainWindow; delete mainWindow;
mainWindow = NULL; mainWindow = nullptr;
DEBUG_FUNCTION_LINE("delete fontSystem\n"); DEBUG_FUNCTION_LINE("delete fontSystem");
delete fontSystem; delete fontSystem;
fontSystem = NULL; fontSystem = nullptr;
DEBUG_FUNCTION_LINE("delete video\n"); DEBUG_FUNCTION_LINE("delete video");
delete video; delete video;
video = NULL; video = nullptr;
DEBUG_FUNCTION_LINE("deinitialize memory\n"); DEBUG_FUNCTION_LINE("deinitialize memory");
libgui_memoryRelease(); libgui_memoryRelease();
} }

View File

@ -31,16 +31,18 @@ public:
applicationInstance = new Application(); applicationInstance = new Application();
return applicationInstance; return applicationInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if (applicationInstance) { if (applicationInstance) {
delete applicationInstance; delete applicationInstance;
applicationInstance = NULL; applicationInstance = nullptr;
} }
} }
CVideo *getVideo(void) const { CVideo *getVideo(void) const {
return video; return video;
} }
MainWindow *getMainWindow(void) const { MainWindow *getMainWindow(void) const {
return mainWindow; return mainWindow;
} }
@ -50,12 +52,14 @@ public:
} }
int exec(void); int exec(void);
void fadeOut(void); void fadeOut(void);
void quit(int code); void quit(int code);
private: private:
Application(); Application();
virtual ~Application(); virtual ~Application();
bool procUI(void); bool procUI(void);
@ -70,7 +74,7 @@ private:
CVideo *video; CVideo *video;
MainWindow *mainWindow; MainWindow *mainWindow;
FreeTypeGX *fontSystem; FreeTypeGX *fontSystem;
GuiController *controller[5]; GuiController *controller[5]{};
int exitCode; int exitCode;
BOOL sFromHBL = FALSE; BOOL sFromHBL = FALSE;

View File

@ -1,20 +1,39 @@
#include <string.h>
#include <nsysnet/socket.h>
#include "utils/logger.h"
#include "common/common.h" #include "common/common.h"
#include <whb/log_cafe.h>
#include <whb/log_udp.h>
#include <whb/log_module.h>
#include "utils/logger.h"
#include "Application.h" #include "Application.h"
int32_t main(int32_t argc, char **argv) { int32_t main(int32_t argc, char **argv) {
socket_lib_init(); bool moduleInit;
log_init(); bool cafeInit = false;
DEBUG_FUNCTION_LINE("Starting launchiine " LAUNCHIINE_VERSION "\n"); bool udpInit = false;
DEBUG_FUNCTION_LINE("Start main application\n"); if (!(moduleInit = WHBLogModuleInit())) {
cafeInit = WHBLogCafeInit();
udpInit = WHBLogUdpInit();
}
DEBUG_FUNCTION_LINE("Starting launchiine " LAUNCHIINE_VERSION "");
DEBUG_FUNCTION_LINE("Start main application");
Application::instance()->exec(); Application::instance()->exec();
DEBUG_FUNCTION_LINE("Main application stopped\n"); DEBUG_FUNCTION_LINE("Main application stopped");
Application::destroyInstance(); Application::destroyInstance();
DEBUG_FUNCTION_LINE("Peace out...\n"); DEBUG_FUNCTION_LINE("Peace out...");
if (cafeInit) {
WHBLogCafeDeinit();
}
if (udpInit) {
WHBLogUdpDeinit();
}
if (moduleInit) {
WHBLogModuleDeinit();
}
return 0; return 0;
} }

View File

@ -7,7 +7,7 @@
CFile::CFile() { CFile::CFile() {
iFd = -1; iFd = -1;
mem_file = NULL; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }
@ -78,7 +78,7 @@ void CFile::close() {
::close(iFd); ::close(iFd);
iFd = -1; iFd = -1;
mem_file = NULL; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }
@ -99,7 +99,7 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
if (readsize <= 0) if (readsize <= 0)
return readsize; return readsize;
if(mem_file != NULL) { if (mem_file != nullptr) {
memcpy(ptr, mem_file + pos, readsize); memcpy(ptr, mem_file + pos, readsize);
pos += readsize; pos += readsize;
return readsize; return readsize;
@ -147,7 +147,7 @@ int32_t CFile::seek(long int offset, int32_t origin) {
if (iFd >= 0) if (iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET); ret = ::lseek(iFd, pos, SEEK_SET);
if(mem_file != NULL) { if (mem_file != nullptr) {
if (pos > filesize) { if (pos > filesize) {
pos = filesize; pos = filesize;
} }

View File

@ -18,11 +18,15 @@ public:
}; };
CFile(); CFile();
CFile(const std::string &filepath, eOpenTypes mode); CFile(const std::string &filepath, eOpenTypes mode);
CFile(const uint8_t *memory, int32_t memsize); CFile(const uint8_t *memory, int32_t memsize);
virtual ~CFile(); virtual ~CFile();
int32_t open(const std::string &filepath, eOpenTypes mode); int32_t open(const std::string &filepath, eOpenTypes mode);
int32_t open(const uint8_t *memory, int32_t memsize); int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const { BOOL isOpen() const {
@ -38,15 +42,21 @@ public:
void close(); void close();
int32_t read(uint8_t *ptr, size_t size); int32_t read(uint8_t *ptr, size_t size);
int32_t write(const uint8_t *ptr, size_t size); int32_t write(const uint8_t *ptr, size_t size);
int32_t fwrite(const char *format, ...); int32_t fwrite(const char *format, ...);
int32_t seek(long int offset, int32_t origin); int32_t seek(long int offset, int32_t origin);
uint64_t tell() { uint64_t tell() {
return pos; return pos;
}; };
uint64_t size() { uint64_t size() {
return filesize; return filesize;
}; };
void rewind() { void rewind() {
this->seek(0, SEEK_SET); this->seek(0, SEEK_SET);
}; };

View File

@ -81,11 +81,11 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
if (folderpath.size() < 3) if (folderpath.size() < 3)
return false; return false;
struct dirent *dirent = NULL; struct dirent *dirent = nullptr;
DIR *dir = NULL; DIR *dir = nullptr;
dir = opendir(folderpath.c_str()); dir = opendir(folderpath.c_str());
if (dir == NULL) if (dir == nullptr)
return false; return false;
while ((dirent = readdir(dir)) != 0) { while ((dirent = readdir(dir)) != 0) {
@ -153,7 +153,7 @@ void DirList::ClearList() {
for (uint32_t i = 0; i < FileInfo.size(); ++i) { for (uint32_t i = 0; i < FileInfo.size(); ++i) {
if (FileInfo[i].FilePath) { if (FileInfo[i].FilePath) {
free(FileInfo[i].FilePath); free(FileInfo[i].FilePath);
FileInfo[i].FilePath = NULL; FileInfo[i].FilePath = nullptr;
} }
} }

View File

@ -40,17 +40,22 @@ class DirList {
public: public:
//!Constructor //!Constructor
DirList(void); DirList(void);
//!\param path Path from where to load the filelist of all files //!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered //!\param filter A fileext that needs to be filtered
//!\param flags search/filter flags from the enum //!\param flags search/filter flags from the enum
DirList(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//!Destructor //!Destructor
virtual ~DirList(); virtual ~DirList();
//! Load all the files from a directory //! Load all the files from a directory
BOOL LoadPath(const std::string & path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//! Get a filename of the list //! Get a filename of the list
//!\param list index //!\param list index
const char *GetFilename(int32_t index) const; const char *GetFilename(int32_t index) const;
//! Get the a filepath of the list //! Get the a filepath of the list
//!\param list index //!\param list index
const char *GetFilepath(int32_t index) const { const char *GetFilepath(int32_t index) const {
@ -59,9 +64,11 @@ public:
else else
return FileInfo[index].FilePath; return FileInfo[index].FilePath;
} }
//! Get the a filesize of the list //! Get the a filesize of the list
//!\param list index //!\param list index
uint64_t GetFilesize(int32_t index) const; uint64_t GetFilesize(int32_t index) const;
//! Is index a dir or a file //! Is index a dir or a file
//!\param list index //!\param list index
BOOL IsDir(int32_t index) const { BOOL IsDir(int32_t index) const {
@ -69,16 +76,21 @@ public:
return false; return false;
return FileInfo[index].isDir; return FileInfo[index].isDir;
}; };
//! Get the filecount of the whole list //! Get the filecount of the whole list
int32_t GetFilecount() const { int32_t GetFilecount() const {
return FileInfo.size(); return FileInfo.size();
}; };
//! Sort list by filepath //! Sort list by filepath
void SortList(); void SortList();
//! Custom sort command for custom sort functions definitions //! Custom sort command for custom sort functions definitions
void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)); void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b));
//! Get the index of the specified filename //! Get the index of the specified filename
int32_t GetFileIndex(const char *filename) const; int32_t GetFileIndex(const char *filename) const;
//! Enum for search/filter flags //! Enum for search/filter flags
enum { enum {
Files = 0x01, Files = 0x01,
@ -88,10 +100,13 @@ public:
protected: protected:
// Internal parser // Internal parser
BOOL InternalLoadPath(std::string &path); BOOL InternalLoadPath(std::string &path);
//!Add a list entrie //!Add a list entrie
void AddEntrie(const std::string &filepath, const char *filename, BOOL isDir); void AddEntrie(const std::string &filepath, const char *filename, BOOL isDir);
//! Clear the list //! Clear the list
void ClearList(); void ClearList();
//! Check if valid pos is requested //! Check if valid pos is requested
inline BOOL valid(uint32_t pos) const { inline BOOL valid(uint32_t pos) const {
return (pos < FileInfo.size()); return (pos < FileInfo.size());

View File

@ -9,7 +9,7 @@
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input //! always initialze input
*inbuffer = NULL; *inbuffer = nullptr;
if (size) if (size)
*size = 0; *size = 0;
@ -21,7 +21,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
lseek(iFd, 0, SEEK_SET); lseek(iFd, 0, SEEK_SET);
uint8_t *buffer = (uint8_t *) malloc(filesize); uint8_t *buffer = (uint8_t *) malloc(filesize);
if (buffer == NULL) { if (buffer == nullptr) {
close(iFd); close(iFd);
return -2; return -2;
} }
@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
if (done != filesize) { if (done != filesize) {
free(buffer); free(buffer);
buffer = NULL; buffer = nullptr;
return -3; return -3;
} }
@ -132,7 +132,7 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) { int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) {
CFile file(path, CFile::WriteOnly); CFile file(path, CFile::WriteOnly);
if (!file.isOpen()) { if (!file.isOpen()) {
DEBUG_FUNCTION_LINE("Failed to open %s\n",path); DEBUG_FUNCTION_LINE("Failed to open %s", path);
return 0; return 0;
} }
int32_t written = file.write((const uint8_t *) buffer, size); int32_t written = file.write((const uint8_t *) buffer, size);

View File

@ -9,7 +9,9 @@ public:
//! todo: C++ class //! todo: C++ class
static int32_t CreateSubfolder(const char *fullpath); static int32_t CreateSubfolder(const char *fullpath);
static int32_t CheckFile(const char *filepath); static int32_t CheckFile(const char *filepath);
static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size); static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size);
}; };

View File

@ -25,10 +25,10 @@ GameList::~GameList() {
void GameList::clear() { void GameList::clear() {
lock(); lock();
for (auto const &x: fullGameList) { for (auto const &x: fullGameList) {
if(x != NULL) { if (x != nullptr) {
if(x->imageData != NULL) { if (x->imageData != nullptr) {
AsyncExecutor::pushForDelete(x->imageData); AsyncExecutor::pushForDelete(x->imageData);
x->imageData = NULL; x->imageData = nullptr;
} }
delete x; delete x;
} }
@ -41,7 +41,7 @@ void GameList::clear() {
} }
gameInfo *GameList::getGameInfo(uint64_t titleId) { gameInfo *GameList::getGameInfo(uint64_t titleId) {
gameInfo * result = NULL; gameInfo *result = nullptr;
lock(); lock();
for (uint32_t i = 0; i < fullGameList.size(); ++i) { for (uint32_t i = 0; i < fullGameList.size(); ++i) {
if (titleId == fullGameList[i]->titleId) { if (titleId == fullGameList[i]->titleId) {
@ -107,12 +107,12 @@ int32_t GameList::readGameList() {
} }
for (auto title_candidate: titles) { for (auto title_candidate: titles) {
gameInfo* newGameInfo = new gameInfo; auto *newGameInfo = new gameInfo;
newGameInfo->titleId = title_candidate.titleId; newGameInfo->titleId = title_candidate.titleId;
newGameInfo->appType = title_candidate.appType; newGameInfo->appType = title_candidate.appType;
newGameInfo->gamePath = title_candidate.path; newGameInfo->gamePath = title_candidate.path;
newGameInfo->name = "<unknown>"; newGameInfo->name = "<unknown>";
newGameInfo->imageData = NULL; newGameInfo->imageData = nullptr;
DCFlushRange(newGameInfo, sizeof(gameInfo)); DCFlushRange(newGameInfo, sizeof(gameInfo));
fullGameList.push_back(newGameInfo); fullGameList.push_back(newGameInfo);
@ -122,17 +122,15 @@ int32_t GameList::readGameList() {
AsyncExecutor::execute([this] { AsyncExecutor::execute([this] {
lock(); lock();
for (uint32_t i = 0; i < fullGameList.size(); ++i) { for (auto header : fullGameList) {
gameInfo *header = fullGameList[i];
DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading)); DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading));
if (stopAsyncLoading) { if (stopAsyncLoading) {
DEBUG_FUNCTION_LINE("Stop async title loading\n"); DEBUG_FUNCTION_LINE("Stop async title loading");
break; break;
} }
DEBUG_FUNCTION_LINE("Load extra infos of %016llX\n",header->titleId); DEBUG_FUNCTION_LINE("Load extra infos of %016llX", header->titleId);
ACPMetaXml* meta = (ACPMetaXml*)calloc(1, 0x4000); //TODO fix wut auto *meta = (ACPMetaXml *) calloc(1, 0x4000); //TODO fix wut
if (meta) { if (meta) {
auto acp = ACPGetTitleMetaXml(header->titleId, meta); auto acp = ACPGetTitleMetaXml(header->titleId, meta);
if (acp >= 0) { if (acp >= 0) {
@ -141,16 +139,14 @@ int32_t GameList::readGameList() {
free(meta); free(meta);
} }
if(header->imageData == NULL) { if (header->imageData == nullptr) {
std::string filepath = "fs:" + header->gamePath + META_PATH + "/iconTex.tga"; std::string filepath = "fs:" + header->gamePath + META_PATH + "/iconTex.tga";
uint8_t *buffer = NULL; uint8_t *buffer = nullptr;
uint32_t bufferSize = 0; uint32_t bufferSize = 0;
int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize);
if (iResult > 0) { if (iResult > 0) {
GuiImageData * imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
if(imageData) {
header->imageData = imageData; header->imageData = imageData;
}
//! free original image buffer which is converted to texture now and not needed anymore //! free original image buffer which is converted to texture now and not needed anymore
free(buffer); free(buffer);
@ -172,7 +168,7 @@ void GameList::updateTitleInfo() {
bool hasChanged = false; bool hasChanged = false;
if (newHeader->name.empty()) { if (newHeader->name.empty()) {
ACPMetaXml* meta = (ACPMetaXml*)calloc(1, 0x4000); //TODO fix wut auto *meta = (ACPMetaXml *) calloc(1, 0x4000); //TODO fix wut
if (meta) { if (meta) {
auto acp = ACPGetTitleMetaXml(newHeader->titleId, meta); auto acp = ACPGetTitleMetaXml(newHeader->titleId, meta);
if (acp >= 0) { if (acp >= 0) {
@ -183,18 +179,16 @@ void GameList::updateTitleInfo() {
} }
} }
if(newHeader->imageData == NULL) { if (newHeader->imageData == nullptr) {
std::string filepath = "fs:" + newHeader->gamePath + META_PATH + "/iconTex.tga"; std::string filepath = "fs:" + newHeader->gamePath + META_PATH + "/iconTex.tga";
uint8_t *buffer = NULL; uint8_t *buffer = nullptr;
uint32_t bufferSize = 0; uint32_t bufferSize = 0;
int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize);
if (iResult > 0) { if (iResult > 0) {
GuiImageData * imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
if(imageData) {
newHeader->imageData = imageData; newHeader->imageData = imageData;
hasChanged = true; hasChanged = true;
}
//! free original image buffer which is converted to texture now and not needed anymore //! free original image buffer which is converted to texture now and not needed anymore
free(buffer); free(buffer);
@ -209,7 +203,7 @@ void GameList::updateTitleInfo() {
int32_t GameList::load() { int32_t GameList::load() {
lock(); lock();
if(fullGameList.size() == 0) { if (fullGameList.empty()) {
readGameList(); readGameList();
} }

View File

@ -20,6 +20,7 @@ typedef struct _gameInfo {
class GameList { class GameList {
public: public:
GameList(); GameList();
~GameList(); ~GameList();
int32_t size() { int32_t size() {
@ -28,6 +29,7 @@ public:
unlock(); unlock();
return res; return res;
} }
int32_t gameCount() { int32_t gameCount() {
lock(); lock();
int32_t res = fullGameList.size(); int32_t res = fullGameList.size();
@ -38,17 +40,19 @@ public:
gameInfo *at(int32_t i) { gameInfo *at(int32_t i) {
return operator[](i); return operator[](i);
} }
gameInfo *operator[](int32_t i) { gameInfo *operator[](int32_t i) {
lock(); lock();
gameInfo * res = NULL; gameInfo *res = nullptr;
if (i < 0 || i >= (int32_t) fullGameList.size()) { if (i < 0 || i >= (int32_t) fullGameList.size()) {
res = NULL; res = nullptr;
} else { } else {
res = fullGameList[i]; res = fullGameList[i];
} }
unlock(); unlock();
return res; return res;
} }
gameInfo *getGameInfo(uint64_t titleId); gameInfo *getGameInfo(uint64_t titleId);
void clear(); void clear();
@ -66,11 +70,14 @@ public:
void lock() { void lock() {
_lock.lock(); _lock.lock();
} }
void unlock() { void unlock() {
_lock.unlock(); _lock.unlock();
} }
protected: protected:
int32_t readGameList(); int32_t readGameList();
void updateTitleInfo(); void updateTitleInfo();
std::vector<gameInfo *> fullGameList; std::vector<gameInfo *> fullGameList;

View File

@ -83,34 +83,34 @@ GameIcon::GameIcon(GuiImageData *preloadImage)
GameIcon::~GameIcon() { GameIcon::~GameIcon() {
//! remove image so it can not be drawn anymore from this point on //! remove image so it can not be drawn anymore from this point on
imageData = NULL; imageData = nullptr;
//! main image vertexes //! main image vertexes
if (posVtxs) { if (posVtxs) {
free((void *) posVtxs); free((void *) posVtxs);
posVtxs = NULL; posVtxs = nullptr;
} }
if (texCoords) { if (texCoords) {
free((void *) texCoords); free((void *) texCoords);
texCoords = NULL; texCoords = nullptr;
} }
//! mirror image vertexes //! mirror image vertexes
if (texCoordsMirror) { if (texCoordsMirror) {
free(texCoordsMirror); free(texCoordsMirror);
texCoordsMirror = NULL; texCoordsMirror = nullptr;
} }
//! stroke image vertexes //! stroke image vertexes
if (strokePosVtxs) { if (strokePosVtxs) {
free(strokePosVtxs); free(strokePosVtxs);
strokePosVtxs = NULL; strokePosVtxs = nullptr;
} }
if (strokeTexCoords) { if (strokeTexCoords) {
free(strokeTexCoords); free(strokeTexCoords);
strokeTexCoords = NULL; strokeTexCoords = nullptr;
} }
if (strokeColorVtxs) { if (strokeColorVtxs) {
free(strokeColorVtxs); free(strokeColorVtxs);
strokeColorVtxs = NULL; strokeColorVtxs = nullptr;
} }
} }
@ -155,7 +155,7 @@ bool GameIcon::checkRayIntersection(const glm::vec3 & rayOrigin, const glm::vec3
} }
void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::mat4 &viewMtx, const glm::mat4 &modelView) { void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::mat4 &viewMtx, const glm::mat4 &modelView) {
if(imageData == NULL){ if (imageData == nullptr) {
return; return;
} }
//! first setup 2D GUI positions //! first setup 2D GUI positions

View File

@ -4,52 +4,62 @@
#include <gui/GuiImageAsync.h> #include <gui/GuiImageAsync.h>
#include <gui/video/shaders/Shader3D.h> #include <gui/video/shaders/Shader3D.h>
class GameIcon : public GuiImage class GameIcon : public GuiImage {
{
public: public:
GameIcon(GuiImageData *preloadImage); GameIcon(GuiImageData *preloadImage);
virtual ~GameIcon(); virtual ~GameIcon();
void setRotationX(float r) { void setRotationX(float r) {
rotationX = r; rotationX = r;
} }
void setColorIntensity(const glm::vec4 &color) { void setColorIntensity(const glm::vec4 &color) {
colorIntensity = color; colorIntensity = color;
colorIntensityMirror = colorIntensity; colorIntensityMirror = colorIntensity;
selectionBlurOuterColorIntensity = color * glm::vec4(0.09411764f * 1.15f, 0.56862745f * 1.15f, 0.96862745098f * 1.15f, 1.0f); selectionBlurOuterColorIntensity = color * glm::vec4(0.09411764f * 1.15f, 0.56862745f * 1.15f, 0.96862745098f * 1.15f, 1.0f);
selectionBlurInnerColorIntensity = color * glm::vec4(0.46666667f, 0.90588235f, 1.0f, 1.0f); selectionBlurInnerColorIntensity = color * glm::vec4(0.46666667f, 0.90588235f, 1.0f, 1.0f);
} }
const glm::vec4 &getColorIntensity() const { const glm::vec4 &getColorIntensity() const {
return colorIntensity; return colorIntensity;
} }
void setAlphaFadeOutNorm(const glm::vec4 &a) { void setAlphaFadeOutNorm(const glm::vec4 &a) {
alphaFadeOutNorm = a; alphaFadeOutNorm = a;
} }
void setAlphaFadeOutRefl(const glm::vec4 &a) { void setAlphaFadeOutRefl(const glm::vec4 &a) {
alphaFadeOutRefl = a; alphaFadeOutRefl = a;
} }
void setRenderReflection(bool enable) { void setRenderReflection(bool enable) {
bRenderReflection = enable; bRenderReflection = enable;
} }
void setSelected(bool enable) { void setSelected(bool enable) {
bSelected = enable; bSelected = enable;
} }
void setStrokeRender(bool enable) { void setStrokeRender(bool enable) {
bRenderStroke = enable; bRenderStroke = enable;
} }
void setRenderIconLast(bool enable) { void setRenderIconLast(bool enable) {
bIconLast = enable; bIconLast = enable;
} }
void draw(CVideo *pVideo) { void draw(CVideo *pVideo) {
static const glm::mat4 identity(1.0f); static const glm::mat4 identity(1.0f);
draw(pVideo, identity, identity, identity); draw(pVideo, identity, identity, identity);
} }
void draw(CVideo *pVideo, const glm::mat4 &projection, const glm::mat4 &view, const glm::mat4 &modelView); void draw(CVideo *pVideo, const glm::mat4 &projection, const glm::mat4 &view, const glm::mat4 &modelView);
bool checkRayIntersection(const glm::vec3 &rayOrigin, const glm::vec3 &rayDirFrac); bool checkRayIntersection(const glm::vec3 &rayOrigin, const glm::vec3 &rayDirFrac);
private: private:
enum eRenderState enum eRenderState {
{
RENDER_REFLECTION, RENDER_REFLECTION,
RENDER_NORMAL RENDER_NORMAL
}; };

View File

@ -28,32 +28,18 @@
GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex, bool sortByName) GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex, bool sortByName)
: GuiTitleBrowser(w, h, GameIndex), : GuiTitleBrowser(w, h, GameIndex),
sortByName(sortByName), sortByName(sortByName),
particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f) particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f), buttonClickSound(Resources::GetSound("button_click.mp3")), gameTitle((char *) nullptr, 52, glm::vec4(1.0f)),
, buttonClickSound(Resources::GetSound("button_click.mp3")) touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH),
, gameTitle((char*)NULL, 52, glm::vec4(1.0f)) wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A),
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH) leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true),
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, true),
, leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true) downTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true), upTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true),
, rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, true) buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true), buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true),
, downTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true) buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true), leftButton(w, h), rightButton(w, h), downButton(w, h), upButton(w, h), launchButton(w, h),
, upTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_UP | GuiTrigger::STICK_L_UP, true) arrowRightImageData(Resources::GetImageData("rightArrow.png")), arrowLeftImageData(Resources::GetImageData("leftArrow.png")), arrowRightImage(arrowRightImageData),
, buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true) arrowLeftImage(arrowLeftImageData), arrowRightButton(arrowRightImage.getWidth(), arrowRightImage.getHeight()), arrowLeftButton(arrowLeftImage.getWidth(), arrowLeftImage.getHeight()),
, buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true) noIcon(Resources::GetFile("noGameIcon.png"), Resources::GetFileSize("noGameIcon.png"), GX2_TEX_CLAMP_MODE_MIRROR),
, buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true) emptyIcon(Resources::GetFile("iconEmpty.png"), Resources::GetFileSize("iconEmpty.png"), GX2_TEX_CLAMP_MODE_MIRROR), dragListener(w, h) {
, leftButton(w, h)
, rightButton(w, h)
, downButton(w, h)
, upButton(w, h)
, launchButton(w, h)
, arrowRightImageData(Resources::GetImageData("rightArrow.png"))
, arrowLeftImageData(Resources::GetImageData("leftArrow.png"))
, arrowRightImage(arrowRightImageData)
, arrowLeftImage(arrowLeftImageData)
, arrowRightButton(arrowRightImage.getWidth(), arrowRightImage.getHeight())
, arrowLeftButton(arrowLeftImage.getWidth(), arrowLeftImage.getHeight())
, noIcon(Resources::GetFile("noGameIcon.png"), Resources::GetFileSize("noGameIcon.png"), GX2_TEX_CLAMP_MODE_MIRROR)
, emptyIcon(Resources::GetFile("iconEmpty.png"), Resources::GetFileSize("iconEmpty.png"), GX2_TEX_CLAMP_MODE_MIRROR)
, dragListener(w,h) {
particleBgImage.setParent(this); particleBgImage.setParent(this);
setSelectedGame(GameIndex); setSelectedGame(GameIndex);
@ -176,7 +162,7 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) {
this->selectedGame = idx; this->selectedGame = idx;
containerMutex.lock(); containerMutex.lock();
GameInfoContainer * container = NULL; GameInfoContainer *container = nullptr;
for (auto const &x: gameInfoContainers) { for (auto const &x: gameInfoContainers) {
container = x.second; container = x.second;
if (x.first == idx) { if (x.first == idx) {
@ -212,14 +198,14 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
bool wasFound = false; bool wasFound = false;
for (int32_t i = 0; i < gameList->size(); i++) { for (int32_t i = 0; i < gameList->size(); i++) {
gameInfo *info = gameList->at(i); gameInfo *info = gameList->at(i);
if(info != NULL && info->titleId == it->first) { if (info != nullptr && info->titleId == it->first) {
wasFound = true; wasFound = true;
break; break;
} }
} }
if (!wasFound) { if (!wasFound) {
DEBUG_FUNCTION_LINE("Removing %016llX\n", it->first); DEBUG_FUNCTION_LINE("Removing %016llX", it->first);
remove(it->second->button); remove(it->second->button);
delete it->second; delete it->second;
it = gameInfoContainers.erase(it); it = gameInfoContainers.erase(it);
@ -230,7 +216,7 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
for (int32_t i = 0; i < gameList->size(); i++) { for (int32_t i = 0; i < gameList->size(); i++) {
gameInfo *info = gameList->at(i); gameInfo *info = gameList->at(i);
GameInfoContainer * container = NULL; GameInfoContainer *container = nullptr;
for (auto const &x: gameInfoContainers) { for (auto const &x: gameInfoContainers) {
if (info->titleId == x.first) { if (info->titleId == x.first) {
@ -238,7 +224,7 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
break; break;
} }
} }
if(container == NULL) { if (container == nullptr) {
OnGameTitleAdded(info); OnGameTitleAdded(info);
} }
} }
@ -325,6 +311,7 @@ void GuiIconGrid::OnDownClick(GuiButton *button, const GuiController *controller
gameSelectionChanged(this, selectedGame); gameSelectionChanged(this, selectedGame);
} }
} }
void GuiIconGrid::OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
int32_t offset = offsetForTitleId(getSelectedGame()); int32_t offset = offsetForTitleId(getSelectedGame());
if (offset < 0) { if (offset < 0) {
@ -351,13 +338,13 @@ void GuiIconGrid::OnLaunchClick(GuiButton *button, const GuiController *controll
if ((trigger == &buttonATrigger) && (controller->chan & (GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5)) && controller->data.validPointer) { if ((trigger == &buttonATrigger) && (controller->chan & (GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5)) && controller->data.validPointer) {
return; return;
} }
DEBUG_FUNCTION_LINE("Tried to launch %s (%016llX)\n", gameInfoContainers[getSelectedGame()]->info->name.c_str(),getSelectedGame()); DEBUG_FUNCTION_LINE("Tried to launch %s (%016llX)", gameInfoContainers[getSelectedGame()]->info->name.c_str(), getSelectedGame());
gameLaunchClicked(this, getSelectedGame()); gameLaunchClicked(this, getSelectedGame());
} }
void GuiIconGrid::OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(currentlyHeld != NULL) { if (currentlyHeld != nullptr) {
if (lArrowHeldCounter++ > 30) { if (lArrowHeldCounter++ > 30) {
OnLeftArrowClick(button, controller, trigger); OnLeftArrowClick(button, controller, trigger);
lArrowHeldCounter = 0; lArrowHeldCounter = 0;
@ -372,9 +359,9 @@ void GuiIconGrid::OnLeftArrowReleased(GuiButton *button, const GuiController *co
} }
void GuiIconGrid::OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(currentlyHeld != NULL) { if (currentlyHeld != nullptr) {
if (rArrowHeldCounter++ > 30) { if (rArrowHeldCounter++ > 30) {
DEBUG_FUNCTION_LINE("CLICK\n"); DEBUG_FUNCTION_LINE("CLICK");
OnRightArrowClick(button, controller, trigger); OnRightArrowClick(button, controller, trigger);
rArrowHeldCounter = 0; rArrowHeldCounter = 0;
} }
@ -389,7 +376,7 @@ void GuiIconGrid::OnRightArrowReleased(GuiButton *button, const GuiController *c
void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(currentlyHeld == NULL) { if (currentlyHeld == nullptr) {
bool found = false; bool found = false;
// We don't want to drag empty buttons // We don't want to drag empty buttons
for (auto const &x: emptyButtons) { for (auto const &x: emptyButtons) {
@ -402,7 +389,7 @@ void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *contr
currentlyHeld = button; currentlyHeld = button;
} }
} }
if(currentlyHeld != NULL && currentlyHeld != button) { if (currentlyHeld != nullptr && currentlyHeld != button) {
dragTarget = button; dragTarget = button;
} }
} }
@ -416,11 +403,11 @@ void GuiIconGrid::OnGameButtonPointedOff(GuiButton *button, const GuiController
} }
void GuiIconGrid::OnDrag(GuiDragListener *element, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy) { void GuiIconGrid::OnDrag(GuiDragListener *element, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy) {
if(currentlyHeld != NULL) { if (currentlyHeld != nullptr) {
currentlyHeld->setPosition(currentlyHeld->getOffsetX() + dx, currentlyHeld->getOffsetY() + dy); currentlyHeld->setPosition(currentlyHeld->getOffsetX() + dx, currentlyHeld->getOffsetY() + dy);
} }
// reset the target when we move. // reset the target when we move.
dragTarget = NULL; dragTarget = nullptr;
} }
void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
@ -442,9 +429,9 @@ void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *cont
} }
void GuiIconGrid::OnGameTitleAdded(gameInfo *info) { void GuiIconGrid::OnGameTitleAdded(gameInfo *info) {
DEBUG_FUNCTION_LINE("Adding %016llX\n", info->titleId); DEBUG_FUNCTION_LINE("Adding %016llX", info->titleId);
GuiImageData *imageData = &noIcon; GuiImageData *imageData = &noIcon;
if(info->imageData != NULL) { if (info->imageData != nullptr) {
imageData = info->imageData; imageData = info->imageData;
} }
GameIcon *image = new GameIcon(imageData); GameIcon *image = new GameIcon(imageData);
@ -491,9 +478,10 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
bUpdatePositions = true; bUpdatePositions = true;
} }
void GuiIconGrid::OnGameTitleUpdated(gameInfo *info) { void GuiIconGrid::OnGameTitleUpdated(gameInfo *info) {
DEBUG_FUNCTION_LINE("Updating infos of %016llX\n", info->titleId); DEBUG_FUNCTION_LINE("Updating infos of %016llX", info->titleId);
GameInfoContainer * container = NULL; GameInfoContainer *container = nullptr;
containerMutex.lock(); containerMutex.lock();
for (auto const &x: gameInfoContainers) { for (auto const &x: gameInfoContainers) {
if (info->titleId == x.first) { if (info->titleId == x.first) {
@ -503,7 +491,7 @@ void GuiIconGrid::OnGameTitleUpdated(gameInfo * info) {
} }
// keep the lock to delay the draw() until the image data is ready. // keep the lock to delay the draw() until the image data is ready.
if(container != NULL) { if (container != nullptr) {
container->updateImageData(); container->updateImageData();
} }
@ -513,12 +501,12 @@ void GuiIconGrid::OnGameTitleUpdated(gameInfo * info) {
} }
void GuiIconGrid::process() { void GuiIconGrid::process() {
if(currentlyHeld != NULL) { if (currentlyHeld != nullptr) {
if (!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) { if (!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) {
DEBUG_FUNCTION_LINE("Not held anymore\n"); DEBUG_FUNCTION_LINE("Not held anymore");
positionMutex.lock(); positionMutex.lock();
if (dragTarget) { if (dragTarget) {
DEBUG_FUNCTION_LINE("Let's swap\n"); DEBUG_FUNCTION_LINE("Let's swap");
std::vector<std::pair<uint64_t, GameInfoContainer *>> vec; std::vector<std::pair<uint64_t, GameInfoContainer *>> vec;
containerMutex.lock(); containerMutex.lock();
@ -534,9 +522,9 @@ void GuiIconGrid::process() {
} }
for (uint32_t i = 0; i < positionButtons.size(); i++) { for (uint32_t i = 0; i < positionButtons.size(); i++) {
if (positionButtons[i] == dragTarget) { if (positionButtons[i] == dragTarget) {
if(i < position.size() && i != currentlyHeldPosition) { if (i < position.size() && (int32_t) i != currentlyHeldPosition) {
position[i] = currentlyHeldTitleId; position[i] = currentlyHeldTitleId;
DEBUG_FUNCTION_LINE("Set position to title id to %d\n", i, currentlyHeldPosition); DEBUG_FUNCTION_LINE("Set position to title id to %d", i, currentlyHeldPosition);
} else { } else {
targetTitleId = currentlyHeldTitleId; targetTitleId = currentlyHeldTitleId;
} }
@ -548,20 +536,20 @@ void GuiIconGrid::process() {
position[currentlyHeldPosition] = targetTitleId; position[currentlyHeldPosition] = targetTitleId;
} }
dragTarget = NULL; dragTarget = nullptr;
} else { } else {
if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) { if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
position[currentlyHeldPosition] = currentlyHeldTitleId; position[currentlyHeldPosition] = currentlyHeldTitleId;
} }
} }
positionMutex.unlock(); positionMutex.unlock();
currentlyHeld = NULL; currentlyHeld = nullptr;
currentlyHeldTitleId = 0; currentlyHeldTitleId = 0;
currentlyHeldPosition = -1; currentlyHeldPosition = -1;
bUpdatePositions = true; bUpdatePositions = true;
} else { } else {
//DEBUG_FUNCTION_LINE("Holding it\n"); //DEBUG_FUNCTION_LINE("Holding it");
bUpdatePositions = true; bUpdatePositions = true;
} }
} }
@ -693,31 +681,31 @@ void GuiIconGrid::updateButtonPositions() {
positionButtons.clear(); positionButtons.clear();
for (uint32_t i = 0; i < startValue; i++) { for (uint32_t i = 0; i < startValue; i++) {
positionButtons.push_back(NULL); positionButtons.push_back(nullptr);
} }
for (uint32_t i = startPage * (MAX_COLS * MAX_ROWS); i < (endPage + 1) * (MAX_COLS * MAX_ROWS); i++) { for (uint32_t i = startPage * (MAX_COLS * MAX_ROWS); i < (endPage + 1) * (MAX_COLS * MAX_ROWS); i++) {
listOff = i / (MAX_COLS * MAX_ROWS); listOff = i / (MAX_COLS * MAX_ROWS);
GuiButton * element = NULL; GuiButton *element = nullptr;
float posX = currentLeftPosition + listOff * width + (col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f)); float posX = currentLeftPosition + listOff * width + (col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f));
float posY = -row * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + (MAX_ROWS * 0.5f - 0.5f) * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + 30.0f; float posY = -row * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + (MAX_ROWS * 0.5f - 0.5f) * (noIcon.getHeight() + noIcon.getHeight() * 0.5f) + 30.0f;
if (i < position.size()) { if (i < position.size()) {
uint64_t titleID = position.at(i); uint64_t titleID = position.at(i);
if (titleID > 0) { if (titleID > 0) {
GameInfoContainer * container = NULL; GameInfoContainer *container = nullptr;
containerMutex.lock(); containerMutex.lock();
if (gameInfoContainers.find(titleID) != gameInfoContainers.end()) { if (gameInfoContainers.find(titleID) != gameInfoContainers.end()) {
container = gameInfoContainers[titleID]; container = gameInfoContainers[titleID];
} }
containerMutex.unlock(); containerMutex.unlock();
if(container != NULL) { if (container != nullptr) {
element = container->button; element = container->button;
} }
} }
} }
if(element == NULL) { if (element == nullptr) {
if (emptyButtons.size() <= emptyIconUse) { if (emptyButtons.size() <= emptyIconUse) {
break; break;
} }
@ -737,7 +725,7 @@ void GuiIconGrid::updateButtonPositions() {
row = 0; row = 0;
} }
} }
if(currentlyHeld != NULL) { if (currentlyHeld != nullptr) {
append(currentlyHeld); append(currentlyHeld);
} }
if (positionButtons.size() > position.size() && targetLeftPosition == currentLeftPosition) { if (positionButtons.size() > position.size() && targetLeftPosition == currentLeftPosition) {

View File

@ -27,19 +27,27 @@
class GuiIconGrid : public GuiTitleBrowser, public sigslot::has_slots<> { class GuiIconGrid : public GuiTitleBrowser, public sigslot::has_slots<> {
public: public:
GuiIconGrid(int32_t w, int32_t h, uint64_t selectedTitleId, bool sortByName); GuiIconGrid(int32_t w, int32_t h, uint64_t selectedTitleId, bool sortByName);
virtual ~GuiIconGrid(); virtual ~GuiIconGrid();
void setSelectedGame(uint64_t idx); void setSelectedGame(uint64_t idx);
uint64_t getSelectedGame(void); uint64_t getSelectedGame(void);
void update(GuiController *t); void update(GuiController *t);
void draw(CVideo *pVideo); void draw(CVideo *pVideo);
void process(); void process();
void OnGameTitleListUpdated(GameList *list); void OnGameTitleListUpdated(GameList *list);
void OnAddGameTitle(gameInfo *info); void OnAddGameTitle(gameInfo *info);
void OnGameTitleUpdated(gameInfo *info); void OnGameTitleUpdated(gameInfo *info);
void OnGameTitleAdded(gameInfo *info); void OnGameTitleAdded(gameInfo *info);
private: private:
static const int32_t MAX_ROWS = 3; static const int32_t MAX_ROWS = 3;
static const int32_t MAX_COLS = 5; static const int32_t MAX_COLS = 5;
@ -79,23 +87,35 @@ private:
GuiDragListener dragListener; GuiDragListener dragListener;
void OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnLeftArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnRightArrowClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnDownClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnDownClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnLaunchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnLaunchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnGameButtonPointedOn(GuiButton *button, const GuiController *controller); void OnGameButtonPointedOn(GuiButton *button, const GuiController *controller);
void OnGameButtonPointedOff(GuiButton *button, const GuiController *controller); void OnGameButtonPointedOff(GuiButton *button, const GuiController *controller);
void OnDrag(GuiDragListener *button, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy); void OnDrag(GuiDragListener *button, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy);
void OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnLeftArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnLeftArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void OnRightArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger); void OnRightArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void updateButtonPositions(); void updateButtonPositions();
@ -112,10 +132,10 @@ private:
int32_t targetLeftPosition; int32_t targetLeftPosition;
uint32_t gameLaunchTimer; uint32_t gameLaunchTimer;
bool bUpdatePositions = false; bool bUpdatePositions = false;
GuiButton * currentlyHeld = NULL; GuiButton *currentlyHeld = nullptr;
uint64_t currentlyHeldTitleId = 0; uint64_t currentlyHeldTitleId = 0;
int32_t currentlyHeldPosition = -1; int32_t currentlyHeldPosition = -1;
GuiButton * dragTarget = NULL; GuiButton *dragTarget = nullptr;
class GameInfoContainer { class GameInfoContainer {
public: public:
@ -126,16 +146,16 @@ private:
} }
~GameInfoContainer() { ~GameInfoContainer() {
if(button != NULL) { if (button != nullptr) {
AsyncExecutor::pushForDelete(button); AsyncExecutor::pushForDelete(button);
} }
if(image != NULL) { if (image != nullptr) {
AsyncExecutor::pushForDelete(image); AsyncExecutor::pushForDelete(image);
} }
} }
void updateImageData() { void updateImageData() {
if(image != NULL && info != NULL && info->imageData != NULL) { if (image != nullptr && info != nullptr && info->imageData != nullptr) {
image->setImageData(info->imageData); image->setImageData(info->imageData);
} }
} }

View File

@ -7,13 +7,17 @@
class GuiTitleBrowser : public GuiFrame { class GuiTitleBrowser : public GuiFrame {
public: public:
GuiTitleBrowser(int32_t w, int32_t h, uint64_t GameIndex) : GuiFrame(w, h) {} GuiTitleBrowser(int32_t w, int32_t h, uint64_t GameIndex) : GuiFrame(w, h) {}
virtual ~GuiTitleBrowser() {} virtual ~GuiTitleBrowser() {}
virtual void setSelectedGame(uint64_t idx) = 0; virtual void setSelectedGame(uint64_t idx) = 0;
virtual uint64_t getSelectedGame(void) = 0; virtual uint64_t getSelectedGame(void) = 0;
virtual void OnGameTitleListUpdated(GameList *list) = 0; virtual void OnGameTitleListUpdated(GameList *list) = 0;
virtual void OnGameTitleUpdated(gameInfo *info) = 0; virtual void OnGameTitleUpdated(gameInfo *info) = 0;
virtual void OnGameTitleAdded(gameInfo *info) = 0; virtual void OnGameTitleAdded(gameInfo *info) = 0;
sigslot::signal2<GuiTitleBrowser *, uint64_t> gameLaunchClicked; sigslot::signal2<GuiTitleBrowser *, uint64_t> gameLaunchClicked;

View File

@ -28,7 +28,7 @@ GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo * info, bool o
if (onTV) { if (onTV) {
filepath = "fs:" + info->gamePath + META_PATH + "/bootTVTex.tga"; filepath = "fs:" + info->gamePath + META_PATH + "/bootTVTex.tga";
} }
uint8_t *buffer = NULL; uint8_t *buffer = nullptr;
uint32_t bufferSize = 0; uint32_t bufferSize = 0;
int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize); int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize);
if (iResult > 0) { if (iResult > 0) {

View File

@ -1,18 +1,24 @@
#pragma once #pragma once
#include "game/GameList.h" #include "game/GameList.h"
#include <gui/GuiImage.h> #include <gui/GuiImage.h>
#include <gui/GuiFrame.h> #include <gui/GuiFrame.h>
class GameSplashScreen : public GuiFrame, public sigslot::has_slots<> { class GameSplashScreen : public GuiFrame, public sigslot::has_slots<> {
public: public:
GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV); GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV);
virtual ~GameSplashScreen(); virtual ~GameSplashScreen();
void OnSplashScreenFadeInDone(GuiElement *element); void OnSplashScreenFadeInDone(GuiElement *element);
virtual void draw(CVideo *v); virtual void draw(CVideo *v);
sigslot::signal3<GuiElement *, gameInfo *, bool> gameGameSplashScreenFinished; sigslot::signal3<GuiElement *, gameInfo *, bool> gameGameSplashScreenFinished;
private: private:
GuiImage bgImageColor; GuiImage bgImageColor;
GuiImageData* splashScreenData = NULL; GuiImageData *splashScreenData = nullptr;
gameInfo * info = NULL; gameInfo *info = nullptr;
bool launchGame = false; bool launchGame = false;
uint32_t frameCounter = 0; uint32_t frameCounter = 0;
bool onTV = false; bool onTV = false;

View File

@ -4,8 +4,8 @@
#include <coreinit/memdefaultheap.h> #include <coreinit/memdefaultheap.h>
KeyboardHelper::KeyboardHelper() { KeyboardHelper::KeyboardHelper() {
FSClient *fsClient = (FSClient *)MEMAllocFromDefaultHeap(sizeof(FSClient)); auto *_fsClient = (FSClient *) MEMAllocFromDefaultHeap(sizeof(FSClient));
FSAddClient(fsClient, 0); FSAddClient(_fsClient, FS_ERROR_FLAG_ALL);
// Create swkbd // Create swkbd
nn::swkbd::CreateArg createArg; nn::swkbd::CreateArg createArg;
@ -13,11 +13,11 @@ KeyboardHelper::KeyboardHelper() {
createArg.workMemory = MEMAllocFromDefaultHeap(nn::swkbd::GetWorkMemorySize(0)); createArg.workMemory = MEMAllocFromDefaultHeap(nn::swkbd::GetWorkMemorySize(0));
memset(createArg.workMemory, 0, sizeof(nn::swkbd::GetWorkMemorySize(0))); memset(createArg.workMemory, 0, sizeof(nn::swkbd::GetWorkMemorySize(0)));
this->workMemory = createArg.workMemory; this->workMemory = createArg.workMemory;
createArg.fsClient = fsClient; createArg.fsClient = _fsClient;
this->fsClient = createArg.fsClient; this->fsClient = createArg.fsClient;
DEBUG_FUNCTION_LINE("Calling create\n"); DEBUG_FUNCTION_LINE("Calling create");
if (!nn::swkbd::Create(createArg)) { if (!nn::swkbd::Create(createArg)) {
DEBUG_FUNCTION_LINE("Failed to create keyboard\n"); DEBUG_FUNCTION_LINE("Failed to create keyboard");
return; return;
} }
@ -28,9 +28,9 @@ KeyboardHelper::~KeyboardHelper() {
if (keyboardCreated) { if (keyboardCreated) {
nn::swkbd::Destroy(); nn::swkbd::Destroy();
MEMFreeToDefaultHeap(this->workMemory); MEMFreeToDefaultHeap(this->workMemory);
this->workMemory = NULL; this->workMemory = nullptr;
FSDelClient(fsClient, 0); FSDelClient(fsClient, FS_ERROR_FLAG_ALL);
MEMFreeToDefaultHeap(this->fsClient); MEMFreeToDefaultHeap(this->fsClient);
keyboardCreated = false; keyboardCreated = false;
} }
@ -42,7 +42,7 @@ bool KeyboardHelper::openKeyboard() {
nn::swkbd::AppearArg appearArg; nn::swkbd::AppearArg appearArg;
appearArg.keyboardArg.configArg.languageType = nn::swkbd::LanguageType::English; appearArg.keyboardArg.configArg.languageType = nn::swkbd::LanguageType::English;
if (!nn::swkbd::AppearInputForm(appearArg)) { if (!nn::swkbd::AppearInputForm(appearArg)) {
DEBUG_FUNCTION_LINE("nn::swkbd::AppearInputForm failed\n"); DEBUG_FUNCTION_LINE("nn::swkbd::AppearInputForm failed");
return false; return false;
} }
keyboardOpen = true; keyboardOpen = true;

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <string> #include <string>
#include <coreinit/filesystem.h> #include <coreinit/filesystem.h>
@ -10,9 +11,9 @@ public:
bool checkResult(); bool checkResult();
void drawTV(); static void drawTV();
void drawDRC(); static void drawDRC();
bool openKeyboard(); bool openKeyboard();
@ -24,8 +25,8 @@ public:
private: private:
void * workMemory = NULL; void *workMemory = nullptr;
FSClient * fsClient = NULL; FSClient *fsClient = nullptr;
bool keyboardOpen = false; bool keyboardOpen = false;
bool keyboardCreated = false; bool keyboardCreated = false;
std::string resultStr = ""; std::string resultStr = "";

View File

@ -20,26 +20,16 @@
#include "gui/Gui.h" #include "gui/Gui.h"
#include "resources/Resources.h" #include "resources/Resources.h"
class MainDrcButtonsFrame : public GuiFrame, public sigslot::has_slots<> class MainDrcButtonsFrame : public GuiFrame, public sigslot::has_slots<> {
{
public: public:
MainDrcButtonsFrame(int32_t w, int32_t h) MainDrcButtonsFrame(int32_t w, int32_t h)
: GuiFrame(w, h) : GuiFrame(w, h), buttonClickSound(Resources::GetSound("settings_click_2.mp3")), screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3")),
, buttonClickSound(Resources::GetSound("settings_click_2.mp3")) switchIconData(Resources::GetImageData("layoutSwitchButton.png")), settingsIconData(Resources::GetImageData("settingsButton.png")), switchIcon(switchIconData),
, screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3")) settingsIcon(settingsIconData), switchLayoutButton(switchIcon.getWidth(), switchIcon.getHeight()), settingsButton(settingsIcon.getWidth(), settingsIcon.getHeight()),
, switchIconData(Resources::GetImageData("layoutSwitchButton.png")) gameListFilterButton(w, h), touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH),
, settingsIconData(Resources::GetImageData("settingsButton.png")) wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A),
, switchIcon(switchIconData) settingsTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZL, true), switchLayoutTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZR, true),
, settingsIcon(settingsIconData) plusTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_PLUS, true) {
, switchLayoutButton(switchIcon.getWidth(), switchIcon.getHeight())
, settingsButton(settingsIcon.getWidth(), settingsIcon.getHeight())
, gameListFilterButton(w, h)
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
, settingsTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZL, true)
, switchLayoutTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_ZR, true)
, plusTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_PLUS, true)
{
settingsButton.setClickable(true); settingsButton.setClickable(true);
settingsButton.setImage(&settingsIcon); settingsButton.setImage(&settingsIcon);
settingsButton.setTrigger(&touchTrigger); settingsButton.setTrigger(&touchTrigger);
@ -68,8 +58,8 @@ public:
gameListFilterButton.clicked.connect(this, &MainDrcButtonsFrame::OnGameListFilterButtonClicked); gameListFilterButton.clicked.connect(this, &MainDrcButtonsFrame::OnGameListFilterButtonClicked);
append(&gameListFilterButton); append(&gameListFilterButton);
} }
virtual ~MainDrcButtonsFrame()
{ virtual ~MainDrcButtonsFrame() {
Resources::RemoveImageData(switchIconData); Resources::RemoveImageData(switchIconData);
Resources::RemoveImageData(settingsIconData); Resources::RemoveImageData(settingsIconData);
Resources::RemoveSound(buttonClickSound); Resources::RemoveSound(buttonClickSound);
@ -83,9 +73,11 @@ private:
void OnSettingsButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *) { void OnSettingsButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *) {
settingsButtonClicked(this); settingsButtonClicked(this);
} }
void OnLayoutSwithClick(GuiButton *button, const GuiController *controller, GuiTrigger *) { void OnLayoutSwithClick(GuiButton *button, const GuiController *controller, GuiTrigger *) {
layoutSwitchClicked(this); layoutSwitchClicked(this);
} }
void OnGameListFilterButtonClicked(GuiButton *button, const GuiController *controller, GuiTrigger *) { void OnGameListFilterButtonClicked(GuiButton *button, const GuiController *controller, GuiTrigger *) {
gameListFilterClicked(this); gameListFilterClicked(this);
} }

View File

@ -29,12 +29,7 @@
#include "GameSplashScreen.h" #include "GameSplashScreen.h"
MainWindow::MainWindow(int32_t w, int32_t h) MainWindow::MainWindow(int32_t w, int32_t h)
: width(w) : width(w), height(h), gameClickSound(Resources::GetSound("game_click.mp3")), mainSwitchButtonFrame(nullptr), currentTvFrame(nullptr), currentDrcFrame(nullptr) {
, height(h)
, gameClickSound(Resources::GetSound("game_click.mp3"))
, mainSwitchButtonFrame(NULL)
, currentTvFrame(NULL)
, currentDrcFrame(NULL) {
for (int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
std::string filename = StringTools::strfmt("player%i_point.png", i + 1); std::string filename = StringTools::strfmt("player%i_point.png", i + 1);
pointerImgData[i] = Resources::GetImageData(filename.c_str()); pointerImgData[i] = Resources::GetImageData(filename.c_str());
@ -113,7 +108,7 @@ void MainWindow::process() {
} }
} }
if(keyboardInstance != NULL) { if (keyboardInstance != nullptr) {
if (keyboardInstance->checkResult()) { if (keyboardInstance->checkResult()) {
std::string result = keyboardInstance->getResult(); std::string result = keyboardInstance->getResult();
@ -202,7 +197,7 @@ void MainWindow::drawDrc(CVideo *video) {
} }
} }
if(keyboardInstance != NULL) { if (keyboardInstance != nullptr) {
keyboardInstance->drawDRC(); keyboardInstance->drawDRC();
} }
} }
@ -218,7 +213,7 @@ void MainWindow::drawTv(CVideo *video) {
pointerValid[i] = false; pointerValid[i] = false;
} }
} }
if(keyboardInstance != NULL) { if (keyboardInstance != nullptr) {
keyboardInstance->drawTV(); keyboardInstance->drawTV();
} }
} }
@ -295,7 +290,7 @@ void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) {
return; return;
} }
if(keyboardInstance == NULL) { if (keyboardInstance == nullptr) {
keyboardInstance = new KeyboardHelper(); keyboardInstance = new KeyboardHelper();
} }
if (keyboardInstance->isReady()) { if (keyboardInstance->isReady()) {
@ -380,7 +375,7 @@ extern "C" void _SYSLaunchTitleByPathFromLauncher(const char * path, int len, in
void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleID) { void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleID) {
gameInfo *info = gameList.getGameInfo(titleID); gameInfo *info = gameList.getGameInfo(titleID);
if(info != NULL) { if (info != nullptr) {
uint64_t ownTitleId = OSGetTitleID(); uint64_t ownTitleId = OSGetTitleID();
if (ownTitleId == HBL_TITLE_ID || if (ownTitleId == HBL_TITLE_ID ||
ownTitleId == MII_MAKER_JPN_TITLE_ID || ownTitleId == MII_MAKER_JPN_TITLE_ID ||
@ -408,7 +403,7 @@ void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser * element, uint64_t ti
} }
void MainWindow::OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame) { void MainWindow::OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame) {
if(info == NULL) { if (info == nullptr) {
return; return;
} }
if (launchGame) { if (launchGame) {
@ -420,9 +415,10 @@ void MainWindow::OnGameLaunchSplashScreenFinished(GuiElement * element, gameInfo
element->effectFinished.connect(this, &MainWindow::OnCloseEffectFinish); element->effectFinished.connect(this, &MainWindow::OnCloseEffectFinish);
} }
} }
void MainWindow::OnGameLaunch(uint64_t titleID) { void MainWindow::OnGameLaunch(uint64_t titleID) {
gameInfo *info = gameList.getGameInfo(titleID); gameInfo *info = gameList.getGameInfo(titleID);
if(info != NULL) { if (info != nullptr) {
uint64_t titleID = OSGetTitleID(); uint64_t titleID = OSGetTitleID();
if (titleID == HBL_TITLE_ID || if (titleID == HBL_TITLE_ID ||
titleID == MII_MAKER_JPN_TITLE_ID || titleID == MII_MAKER_JPN_TITLE_ID ||

View File

@ -30,6 +30,7 @@ class CVideo;
class MainWindow : public sigslot::has_slots<> { class MainWindow : public sigslot::has_slots<> {
public: public:
MainWindow(int32_t w, int32_t h); MainWindow(int32_t w, int32_t h);
virtual ~MainWindow(); virtual ~MainWindow();
void appendTv(GuiElement *e) { void appendTv(GuiElement *e) {
@ -39,6 +40,7 @@ public:
removeTv(e); removeTv(e);
tvElements.push_back(e); tvElements.push_back(e);
} }
void appendDrc(GuiElement *e) { void appendDrc(GuiElement *e) {
if (!e) if (!e)
return; return;
@ -59,6 +61,7 @@ public:
removeTv(e); removeTv(e);
tvElements.insert(tvElements.begin() + pos, e); tvElements.insert(tvElements.begin() + pos, e);
} }
void insertDrc(uint32_t pos, GuiElement *e) { void insertDrc(uint32_t pos, GuiElement *e) {
if (!e) if (!e)
return; return;
@ -80,6 +83,7 @@ public:
} }
} }
} }
void removeDrc(GuiElement *e) { void removeDrc(GuiElement *e) {
for (uint32_t i = 0; i < drcElements.size(); ++i) { for (uint32_t i = 0; i < drcElements.size(); ++i) {
if (e == drcElements[i]) { if (e == drcElements[i]) {
@ -93,20 +97,26 @@ public:
removeTv(e); removeTv(e);
removeDrc(e); removeDrc(e);
} }
void removeAll() { void removeAll() {
tvElements.clear(); tvElements.clear();
drcElements.clear(); drcElements.clear();
} }
void drawDrc(CVideo *video); void drawDrc(CVideo *video);
void drawTv(CVideo *video); void drawTv(CVideo *video);
void update(GuiController *controller); void update(GuiController *controller);
void updateEffects(); void updateEffects();
void process(); void process();
void lockGUI() { void lockGUI() {
guiMutex.lock(); guiMutex.lock();
} }
void unlockGUI() { void unlockGUI() {
guiMutex.unlock(); guiMutex.unlock();
} }
@ -115,21 +125,29 @@ private:
void SetupMainView(void); void SetupMainView(void);
void OnOpenEffectFinish(GuiElement *element); void OnOpenEffectFinish(GuiElement *element);
void OnCloseEffectFinish(GuiElement *element); void OnCloseEffectFinish(GuiElement *element);
void OnGameLaunch(uint64_t titleId); void OnGameLaunch(uint64_t titleId);
void OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame); void OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame);
void OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleId); void OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleId);
void OnGameSelectionChange(GuiTitleBrowser *element, uint64_t titleId); void OnGameSelectionChange(GuiTitleBrowser *element, uint64_t titleId);
void OnSettingsButtonClicked(GuiElement *element); void OnSettingsButtonClicked(GuiElement *element);
void OnLayoutSwitchClicked(GuiElement *element); void OnLayoutSwitchClicked(GuiElement *element);
void OnLayoutSwitchEffectFinish(GuiElement *element); void OnLayoutSwitchEffectFinish(GuiElement *element);
void OnGameListFilterButtonClicked(GuiElement *element); void OnGameListFilterButtonClicked(GuiElement *element);
void OnGameTitleListChanged(GameList *list); void OnGameTitleListChanged(GameList *list);
void OnGameTitleUpdated(gameInfo *info); void OnGameTitleUpdated(gameInfo *info);
void OnGameTitleAdded(gameInfo *info); void OnGameTitleAdded(gameInfo *info);
int32_t width, height; int32_t width, height;
@ -150,7 +168,7 @@ private:
GameList gameList; GameList gameList;
std::recursive_mutex guiMutex; std::recursive_mutex guiMutex;
KeyboardHelper * keyboardInstance = NULL; KeyboardHelper *keyboardInstance = nullptr;
}; };
#endif //_MAIN_WINDOW_H_ #endif //_MAIN_WINDOW_H_

View File

@ -15,13 +15,13 @@
#include <strings.h> #include <strings.h>
Resources * Resources::instance = NULL; Resources *Resources::instance = nullptr;
void Resources::Clear() { void Resources::Clear() {
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) { for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (RecourceList[i].CustomFile) { if (RecourceList[i].CustomFile) {
free(RecourceList[i].CustomFile); free(RecourceList[i].CustomFile);
RecourceList[i].CustomFile = NULL; RecourceList[i].CustomFile = nullptr;
} }
if (RecourceList[i].CustomFileSize != 0) if (RecourceList[i].CustomFileSize != 0)
@ -31,7 +31,7 @@ void Resources::Clear() {
if (instance) if (instance)
delete instance; delete instance;
instance = NULL; instance = nullptr;
} }
bool Resources::LoadFiles(const char *path) { bool Resources::LoadFiles(const char *path) {
@ -41,12 +41,12 @@ bool Resources::LoadFiles(const char * path) {
bool result = false; bool result = false;
Clear(); Clear();
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) { for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
std::string fullpath(path); std::string fullpath(path);
fullpath += "/"; fullpath += "/";
fullpath += RecourceList[i].filename; fullpath += RecourceList[i].filename;
uint8_t * buffer = NULL; uint8_t *buffer = nullptr;
uint32_t filesize = 0; uint32_t filesize = 0;
FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize); FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize);
@ -60,17 +60,17 @@ bool Resources::LoadFiles(const char * path) {
} }
const uint8_t *Resources::GetFile(const char *filename) { const uint8_t *Resources::GetFile(const char *filename) {
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) { for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) { if (strcasecmp(filename, RecourceList[i].filename) == 0) {
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile); return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
} }
} }
return NULL; return nullptr;
} }
uint32_t Resources::GetFileSize(const char *filename) { uint32_t Resources::GetFileSize(const char *filename) {
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) { for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) { if (strcasecmp(filename, RecourceList[i].filename) == 0) {
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize); return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize);
} }
@ -88,13 +88,13 @@ GuiImageData * Resources::GetImageData(const char * filename) {
return itr->second.second; return itr->second.second;
} }
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) { for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) { if (strcasecmp(filename, RecourceList[i].filename) == 0) {
const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile; const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize; const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
if(buff == NULL) if (buff == nullptr)
return NULL; return nullptr;
GuiImageData *image = new GuiImageData(buff, size); GuiImageData *image = new GuiImageData(buff, size);
instance->imageDataMap[std::string(filename)].first = 1; instance->imageDataMap[std::string(filename)].first = 1;
@ -104,7 +104,7 @@ GuiImageData * Resources::GetImageData(const char * filename) {
} }
} }
return NULL; return nullptr;
} }
void Resources::RemoveImageData(GuiImageData *image) { void Resources::RemoveImageData(GuiImageData *image) {
@ -134,13 +134,13 @@ GuiSound * Resources::GetSound(const char * filename) {
return itr->second.second; return itr->second.second;
} }
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) { for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) { if (strcasecmp(filename, RecourceList[i].filename) == 0) {
const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile; const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize; const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
if(buff == NULL) if (buff == nullptr)
return NULL; return nullptr;
GuiSound *sound = new GuiSound(buff, size); GuiSound *sound = new GuiSound(buff, size);
instance->soundDataMap[std::string(filename)].first = 1; instance->soundDataMap[std::string(filename)].first = 1;
@ -150,7 +150,7 @@ GuiSound * Resources::GetSound(const char * filename) {
} }
} }
return NULL; return nullptr;
} }
void Resources::RemoveSound(GuiSound *sound) { void Resources::RemoveSound(GuiSound *sound) {

View File

@ -5,24 +5,32 @@
//! forward declaration //! forward declaration
class GuiImageData; class GuiImageData;
class GuiSound; class GuiSound;
class Resources { class Resources {
public: public:
static void Clear(); static void Clear();
static bool LoadFiles(const char *path); static bool LoadFiles(const char *path);
static const uint8_t *GetFile(const char *filename); static const uint8_t *GetFile(const char *filename);
static uint32_t GetFileSize(const char *filename); static uint32_t GetFileSize(const char *filename);
static GuiImageData *GetImageData(const char *filename); static GuiImageData *GetImageData(const char *filename);
static void RemoveImageData(GuiImageData *image); static void RemoveImageData(GuiImageData *image);
static GuiSound *GetSound(const char *filename); static GuiSound *GetSound(const char *filename);
static void RemoveSound(GuiSound *sound); static void RemoveSound(GuiSound *sound);
private: private:
static Resources *instance; static Resources *instance;
Resources() {} Resources() {}
~Resources() {} ~Resources() {}
std::map<std::string, std::pair<uint32_t, GuiImageData *> > imageDataMap; std::map<std::string, std::pair<uint32_t, GuiImageData *> > imageDataMap;

View File

@ -26,9 +26,9 @@ public:
typedef void (* Callback)(CThread *thread, void *arg); typedef void (* Callback)(CThread *thread, void *arg);
//! constructor //! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL) CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr)
: pThread(NULL) : pThread(nullptr)
, pThreadStack(NULL) , pThreadStack(nullptr)
, pCallback(callback) , pCallback(callback)
, pCallbackArg(callbackArg) { , pCallbackArg(callbackArg) {
//! save attribute assignment //! save attribute assignment
@ -102,7 +102,7 @@ public:
if(isThreadSuspended()) if(isThreadSuspended())
resumeThread(); resumeThread();
OSJoinThread(pThread, NULL); OSJoinThread(pThread, nullptr);
} }
//! free the thread stack buffer //! free the thread stack buffer
if(pThreadStack) if(pThreadStack)
@ -110,8 +110,8 @@ public:
if(pThread) if(pThread)
free(pThread); free(pThread);
pThread = NULL; pThread = nullptr;
pThreadStack = NULL; pThreadStack = nullptr;
} }
//! Thread attributes //! Thread attributes
enum eCThreadAttributes { enum eCThreadAttributes {

View File

@ -1,13 +1,14 @@
#include "AsyncExecutor.h" #include "AsyncExecutor.h"
#include "utils/logger.h" #include "utils/logger.h"
AsyncExecutor * AsyncExecutor::instance = NULL; AsyncExecutor *AsyncExecutor::instance = nullptr;
void AsyncExecutor::pushForDeleteInternal(GuiElement *ptr) { void AsyncExecutor::pushForDeleteInternal(GuiElement *ptr) {
deleteListMutex.lock(); deleteListMutex.lock();
deleteList.push(ptr); deleteList.push(ptr);
deleteListMutex.unlock(); deleteListMutex.unlock();
} }
AsyncExecutor::AsyncExecutor() { AsyncExecutor::AsyncExecutor() {
thread = new std::thread([&]() { thread = new std::thread([&]() {
while (!exitThread) { while (!exitThread) {
@ -24,7 +25,7 @@ AsyncExecutor::AsyncExecutor() {
} }
} }
if (!emptyList && elements.empty()) { if (!emptyList && elements.empty()) {
DEBUG_FUNCTION_LINE("All tasks are done\n"); DEBUG_FUNCTION_LINE("All tasks are done");
} }
mutex.unlock(); mutex.unlock();
deleteListMutex.lock(); deleteListMutex.lock();
@ -49,10 +50,10 @@ AsyncExecutor::~AsyncExecutor() {
void AsyncExecutor::executeInternal(std::function<void()> func) { void AsyncExecutor::executeInternal(std::function<void()> func) {
if (elements.size() > 10) { if (elements.size() > 10) {
DEBUG_FUNCTION_LINE("Warning, many tasks running currently\n"); DEBUG_FUNCTION_LINE("Warning, many tasks running currently");
//std::this_thread::sleep_for(std::chrono::milliseconds(16)); //std::this_thread::sleep_for(std::chrono::milliseconds(16));
} }
DEBUG_FUNCTION_LINE("Add new task\n"); DEBUG_FUNCTION_LINE("Add new task");
mutex.lock(); mutex.lock();
elements.push_back(std::async(std::launch::async, func)); elements.push_back(std::async(std::launch::async, func));
mutex.unlock(); mutex.unlock();

View File

@ -16,6 +16,7 @@ public:
} }
instance->pushForDeleteInternal(element); instance->pushForDeleteInternal(element);
} }
static void execute(std::function<void()> func) { static void execute(std::function<void()> func) {
if (!instance) { if (!instance) {
instance = new AsyncExecutor(); instance = new AsyncExecutor();
@ -26,7 +27,7 @@ public:
static void destroyInstance() { static void destroyInstance() {
if (instance) { if (instance) {
delete instance; delete instance;
instance = NULL; instance = nullptr;
} }
} }
@ -34,9 +35,11 @@ private:
static AsyncExecutor *instance; static AsyncExecutor *instance;
AsyncExecutor(); AsyncExecutor();
~AsyncExecutor(); ~AsyncExecutor();
void pushForDeleteInternal(GuiElement *element); void pushForDeleteInternal(GuiElement *element);
void executeInternal(std::function<void()> func); void executeInternal(std::function<void()> func);
std::recursive_mutex mutex; std::recursive_mutex mutex;

View File

@ -78,7 +78,7 @@ const char * StringTools::fmt(const char * format, ...) {
} }
va_end(va); va_end(va);
return NULL; return nullptr;
} }
const wchar_t *StringTools::wfmt(const char *format, ...) { const wchar_t *StringTools::wfmt(const char *format, ...) {
@ -107,7 +107,7 @@ const wchar_t * StringTools::wfmt(const char * format, ...) {
} }
va_end(va); va_end(va);
return NULL; return nullptr;
} }
int32_t StringTools::strprintf(std::string &str, const char *format, ...) { int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
@ -165,11 +165,11 @@ int32_t StringTools::strtokcmp(const char * string, const char * compare, const
char *strTok = strtok(TokCopy, separator); char *strTok = strtok(TokCopy, separator);
while (strTok != NULL) { while (strTok != nullptr) {
if (strcasecmp(string, strTok) == 0) { if (strcasecmp(string, strTok) == 0) {
return 0; return 0;
} }
strTok = strtok(NULL,separator); strTok = strtok(nullptr, separator);
} }
return -1; return -1;
@ -210,8 +210,7 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
return result; return result;
} }
bool StringTools::findStringIC(const std::string & strHaystack, const std::string & strNeedle) bool StringTools::findStringIC(const std::string &strHaystack, const std::string &strNeedle) {
{
auto it = std::search( auto it = std::search(
strHaystack.begin(), strHaystack.end(), strHaystack.begin(), strHaystack.end(),
strNeedle.begin(), strNeedle.end(), strNeedle.begin(), strNeedle.end(),

View File

@ -35,14 +35,23 @@
class StringTools { class StringTools {
public: public:
static BOOL EndsWith(const std::string &a, const std::string &b); static BOOL EndsWith(const std::string &a, const std::string &b);
static const char *byte_to_binary(int32_t x); static const char *byte_to_binary(int32_t x);
static std::string removeCharFromString(std::string &input, char toBeRemoved); static std::string removeCharFromString(std::string &input, char toBeRemoved);
static const char *fmt(const char *format, ...); static const char *fmt(const char *format, ...);
static const wchar_t *wfmt(const char *format, ...); static const wchar_t *wfmt(const char *format, ...);
static int32_t strprintf(std::string &str, const char *format, ...); static int32_t strprintf(std::string &str, const char *format, ...);
static std::string strfmt(const char *format, ...); static std::string strfmt(const char *format, ...);
static BOOL char2wchar_t(const char *src, wchar_t *dest); static BOOL char2wchar_t(const char *src, wchar_t *dest);
static int32_t strtokcmp(const char *string, const char *compare, const char *separator); static int32_t strtokcmp(const char *string, const char *compare, const char *separator);
static int32_t strextcmp(const char *string, const char *extension, char seperator); static int32_t strextcmp(const char *string, const char *extension, char seperator);
static const char *FullpathToFilename(const char *path) { static const char *FullpathToFilename(const char *path) {

View File

@ -1,83 +0,0 @@
#include <thread>
#include <mutex>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <utils/logger.h>
#include <nsysnet/socket.h>
#include <coreinit/debug.h>
#include <coreinit/systeminfo.h>
#include <coreinit/thread.h>
static int32_t log_socket __attribute__((section(".data")))= -1;
static struct sockaddr_in connect_addr __attribute__((section(".data")));
static volatile int32_t log_lock __attribute__((section(".data"))) = 0;
static std::recursive_mutex _lock;
void log_init_() {
int32_t broadcastEnable = 1;
log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (log_socket < 0)
return;
setsockopt(log_socket, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
memset(&connect_addr, 0, sizeof(struct sockaddr_in));
connect_addr.sin_family = AF_INET;
connect_addr.sin_port = 4405;
connect_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
}
void log_print_(const char *str) {
// socket is always 0 initially as it is in the BSS
if(log_socket < 0) {
return;
}
_lock.lock();
int32_t len = strlen(str);
int32_t ret;
while (len > 0) {
int32_t block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
ret = sendto(log_socket, str, block, 0, (struct sockaddr *)&connect_addr, sizeof(struct sockaddr_in));
if(ret < 0)
break;
len -= ret;
str += ret;
}
_lock.unlock();
}
void OSFatal_printf(const char *format, ...) {
char tmp[512];
tmp[0] = 0;
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
OSFatal(tmp);
}
va_end(va);
}
void log_printf_(const char *format, ...) {
if(log_socket < 0) {
return;
}
char tmp[512];
tmp[0] = 0;
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
log_print_(tmp);
}
va_end(va);
}

View File

@ -1,38 +1,24 @@
#ifndef __LOGGER_H_ #pragma once
#define __LOGGER_H_
#include <whb/log.h>
#include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <string.h>
void log_init_();
//void log_deinit_(void);
void log_print_(const char *str);
void log_printf_(const char *format, ...);
void OSFatal_printf(const char *format, ...);
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define log_init() log_init_()
//#define log_deinit() log_deinit_()
#define log_print(str) log_print_(str)
#define log_printf(FMT, ARGS...) log_printf_(FMT, ## ARGS);
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0) } while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif

View File

@ -11,30 +11,30 @@ void dumpHex(const void* data, size_t size) {
char ascii[17]; char ascii[17];
size_t i, j; size_t i, j;
ascii[16] = '\0'; ascii[16] = '\0';
DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data); DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x0000): ", data);
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
log_printf("%02X ", ((unsigned char*)data)[i]); WHBLogWritef("%02X ", ((unsigned char *) data)[i]);
if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') {
ascii[i % 16] = ((unsigned char *) data)[i]; ascii[i % 16] = ((unsigned char *) data)[i];
} else { } else {
ascii[i % 16] = '.'; ascii[i % 16] = '.';
} }
if ((i + 1) % 8 == 0 || i + 1 == size) { if ((i + 1) % 8 == 0 || i + 1 == size) {
log_printf(" "); WHBLogWritef(" ");
if ((i + 1) % 16 == 0) { if ((i + 1) % 16 == 0) {
log_printf("| %s \n", ascii); WHBLogWritef("| %s \n", ascii);
if (i + 1 < size) { if (i + 1 < size) {
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1,i+1); WHBLogWritef("0x%08X (0x%04X); ", data + i + 1, i + 1);
} }
} else if (i + 1 == size) { } else if (i + 1 == size) {
ascii[(i + 1) % 16] = '\0'; ascii[(i + 1) % 16] = '\0';
if ((i + 1) % 16 <= 8) { if ((i + 1) % 16 <= 8) {
log_printf(" "); WHBLogWritef(" ");
} }
for (j = (i + 1) % 16; j < 16; ++j) { for (j = (i + 1) % 16; j < 16; ++j) {
log_printf(" "); WHBLogWritef(" ");
} }
log_printf("| %s \n", ascii); WHBLogWritef("| %s \n", ascii);
} }
} }
} }