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();
@ -121,8 +98,8 @@ void Application::fadeOut() {
0, 0, 0, 255 0, 0, 0, 255
}); });
for(int32_t i = 0; i < 255; i += 10) { for (int32_t i = 0; i < 255; i += 10) {
if(i > 255) if (i > 255)
i = 255; i = 255;
fadeOut.setAlpha(i / 255.0f); fadeOut.setAlpha(i / 255.0f);
@ -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 {
@ -189,23 +166,23 @@ bool Application::procUI(void) {
break; break;
} }
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
@ -262,7 +231,7 @@ void Application::executeThread(void) {
video->tvDrawDone(); video->tvDrawDone();
//! enable screen after first frame render //! enable screen after first frame render
if(video->getFrameCount() == 0) { if (video->getFrameCount() == 0) {
video->tvEnable(true); video->tvEnable(true);
video->drcEnable(true); video->drcEnable(true);
} }
@ -274,33 +243,22 @@ void Application::executeThread(void) {
video->waitForVSync(); video->waitForVSync();
} }
if(bgMusic) { if (bgMusic) {
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

@ -26,21 +26,23 @@ class FreeTypeGX;
class Application : public CThread { class Application : public CThread {
public: public:
static Application * instance() { static Application *instance() {
if(!applicationInstance) if (!applicationInstance)
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,17 +7,17 @@
CFile::CFile() { CFile::CFile() {
iFd = -1; iFd = -1;
mem_file = NULL; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }
CFile::CFile(const std::string & filepath, eOpenTypes mode) { CFile::CFile(const std::string &filepath, eOpenTypes mode) {
iFd = -1; iFd = -1;
this->open(filepath, mode); this->open(filepath, mode);
} }
CFile::CFile(const uint8_t * mem, int32_t size) { CFile::CFile(const uint8_t *mem, int32_t size) {
iFd = -1; iFd = -1;
this->open(mem, size); this->open(mem, size);
} }
@ -26,14 +26,14 @@ CFile::~CFile() {
this->close(); this->close();
} }
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) { int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
this->close(); this->close();
int32_t openMode = 0; int32_t openMode = 0;
// This depend on the devoptab implementation. // This depend on the devoptab implementation.
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference // see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
switch(mode) { switch (mode) {
default: default:
case ReadOnly: // file must exist case ReadOnly: // file must exist
openMode = O_RDONLY; openMode = O_RDONLY;
@ -54,7 +54,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
//! the .data sections which is needed for a normal application to re-init //! the .data sections which is needed for a normal application to re-init
//! this will be added with launching as RPX //! this will be added with launching as RPX
iFd = ::open(filepath.c_str(), openMode); iFd = ::open(filepath.c_str(), openMode);
if(iFd < 0) if (iFd < 0)
return iFd; return iFd;
@ -64,7 +64,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
return 0; return 0;
} }
int32_t CFile::open(const uint8_t * mem, int32_t size) { int32_t CFile::open(const uint8_t *mem, int32_t size) {
this->close(); this->close();
mem_file = mem; mem_file = mem;
@ -74,33 +74,33 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) {
} }
void CFile::close() { void CFile::close() {
if(iFd >= 0) if (iFd >= 0)
::close(iFd); ::close(iFd);
iFd = -1; iFd = -1;
mem_file = NULL; mem_file = nullptr;
filesize = 0; filesize = 0;
pos = 0; pos = 0;
} }
int32_t CFile::read(uint8_t * ptr, size_t size) { int32_t CFile::read(uint8_t *ptr, size_t size) {
if(iFd >= 0) { if (iFd >= 0) {
int32_t ret = ::read(iFd, ptr,size); int32_t ret = ::read(iFd, ptr, size);
if(ret > 0) if (ret > 0)
pos += ret; pos += ret;
return ret; return ret;
} }
int32_t readsize = size; int32_t readsize = size;
if(readsize > (int64_t) (filesize-pos)) if (readsize > (int64_t) (filesize - pos))
readsize = filesize-pos; readsize = filesize - pos;
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;
} }
@ -108,12 +108,12 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
return -1; return -1;
} }
int32_t CFile::write(const uint8_t * ptr, size_t size) { int32_t CFile::write(const uint8_t *ptr, size_t size) {
if(iFd >= 0) { if (iFd >= 0) {
size_t done = 0; size_t done = 0;
while(done < size) { while (done < size) {
int32_t ret = ::write(iFd, ptr, size - done); int32_t ret = ::write(iFd, ptr, size - done);
if(ret <= 0) if (ret <= 0)
return ret; return ret;
ptr += ret; ptr += ret;
@ -130,25 +130,25 @@ int32_t CFile::seek(long int offset, int32_t origin) {
int32_t ret = 0; int32_t ret = 0;
int64_t newPos = pos; int64_t newPos = pos;
if(origin == SEEK_SET) { if (origin == SEEK_SET) {
newPos = offset; newPos = offset;
} else if(origin == SEEK_CUR) { } else if (origin == SEEK_CUR) {
newPos += offset; newPos += offset;
} else if(origin == SEEK_END) { } else if (origin == SEEK_END) {
newPos = filesize+offset; newPos = filesize + offset;
} }
if(newPos < 0) { if (newPos < 0) {
pos = 0; pos = 0;
} else { } else {
pos = newPos; pos = newPos;
} }
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;
} }
} }
@ -163,8 +163,8 @@ int32_t CFile::fwrite(const char *format, ...) {
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
result = this->write((uint8_t *)tmp, strlen(tmp)); result = this->write((uint8_t *) tmp, strlen(tmp));
} }
va_end(va); va_end(va);

View File

@ -18,18 +18,22 @@ public:
}; };
CFile(); CFile();
CFile(const std::string & filepath, eOpenTypes mode);
CFile(const uint8_t * memory, int32_t memsize); CFile(const std::string &filepath, eOpenTypes mode);
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 {
if(iFd >= 0) if (iFd >= 0)
return true; return true;
if(mem_file) if (mem_file)
return true; return true;
return false; return false;
@ -37,23 +41,29 @@ 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);
}; };
protected: protected:
int32_t iFd; int32_t iFd;
const uint8_t * mem_file; const uint8_t *mem_file;
uint64_t filesize; uint64_t filesize;
uint64_t pos; uint64_t pos;
}; };

View File

@ -42,7 +42,7 @@ DirList::DirList() {
Depth = 0; Depth = 0;
} }
DirList::DirList(const std::string & path, const char *filter, uint32_t flags, uint32_t maxDepth) { DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) {
this->LoadPath(path, filter, flags, maxDepth); this->LoadPath(path, filter, flags, maxDepth);
this->SortList(); this->SortList();
} }
@ -51,8 +51,8 @@ DirList::~DirList() {
ClearList(); ClearList();
} }
BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t flags, uint32_t maxDepth) { BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
if(folder.empty()) if (folder.empty())
return false; return false;
Flags = flags; Flags = flags;
@ -66,11 +66,11 @@ BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t
StringTools::RemoveDoubleSlashs(folderpath); StringTools::RemoveDoubleSlashs(folderpath);
//! remove last slash if exists //! remove last slash if exists
if(length > 0 && folderpath[length-1] == '/') if (length > 0 && folderpath[length - 1] == '/')
folderpath.erase(length-1); folderpath.erase(length - 1);
//! add root slash if missing //! add root slash if missing
if(folderpath.find('/') == std::string::npos) { if (folderpath.find('/') == std::string::npos) {
folderpath += '/'; folderpath += '/';
} }
@ -78,27 +78,27 @@ BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t
} }
BOOL DirList::InternalLoadPath(std::string &folderpath) { 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) {
BOOL isDir = dirent->d_type & DT_DIR; BOOL isDir = dirent->d_type & DT_DIR;
const char *filename = dirent->d_name; const char *filename = dirent->d_name;
if(isDir) { if (isDir) {
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0)
continue; continue;
if((Flags & CheckSubfolders) && (Depth > 0)) { if ((Flags & CheckSubfolders) && (Depth > 0)) {
int32_t length = folderpath.size(); int32_t length = folderpath.size();
if(length > 2 && folderpath[length-1] != '/') { if (length > 2 && folderpath[length - 1] != '/') {
folderpath += '/'; folderpath += '/';
} }
folderpath += filename; folderpath += filename;
@ -109,18 +109,18 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
Depth++; Depth++;
} }
if(!(Flags & Dirs)) if (!(Flags & Dirs))
continue; continue;
} else if(!(Flags & Files)) { } else if (!(Flags & Files)) {
continue; continue;
} }
if(Filter) { if (Filter) {
char * fileext = strrchr(filename, '.'); char *fileext = strrchr(filename, '.');
if(!fileext) if (!fileext)
continue; continue;
if(StringTools::strtokcmp(fileext, Filter, ",") == 0) if (StringTools::strtokcmp(fileext, Filter, ",") == 0)
AddEntrie(folderpath, filename, isDir); AddEntrie(folderpath, filename, isDir);
} else { } else {
AddEntrie(folderpath, filename, isDir); AddEntrie(folderpath, filename, isDir);
@ -131,16 +131,16 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
return true; return true;
} }
void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL isDir) { void DirList::AddEntrie(const std::string &filepath, const char *filename, BOOL isDir) {
if(!filename) if (!filename)
return; return;
int32_t pos = FileInfo.size(); int32_t pos = FileInfo.size();
FileInfo.resize(pos+1); FileInfo.resize(pos + 1);
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2); FileInfo[pos].FilePath = (char *) malloc(filepath.size() + strlen(filename) + 2);
if(!FileInfo[pos].FilePath) { if (!FileInfo[pos].FilePath) {
FileInfo.resize(pos); FileInfo.resize(pos);
return; return;
} }
@ -150,10 +150,10 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL
} }
void DirList::ClearList() { 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;
} }
} }
@ -161,37 +161,37 @@ void DirList::ClearList() {
std::vector<DirEntry>().swap(FileInfo); std::vector<DirEntry>().swap(FileInfo);
} }
const char * DirList::GetFilename(int32_t ind) const { const char *DirList::GetFilename(int32_t ind) const {
if (!valid(ind)) if (!valid(ind))
return ""; return "";
return StringTools::FullpathToFilename(FileInfo[ind].FilePath); return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
} }
static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) { static BOOL SortCallback(const DirEntry &f1, const DirEntry &f2) {
if(f1.isDir && !(f2.isDir)) if (f1.isDir && !(f2.isDir))
return true; return true;
if(!(f1.isDir) && f2.isDir) if (!(f1.isDir) && f2.isDir)
return false; return false;
if(f1.FilePath && !f2.FilePath) if (f1.FilePath && !f2.FilePath)
return true; return true;
if(!f1.FilePath) if (!f1.FilePath)
return false; return false;
if(strcasecmp(f1.FilePath, f2.FilePath) > 0) if (strcasecmp(f1.FilePath, f2.FilePath) > 0)
return false; return false;
return true; return true;
} }
void DirList::SortList() { void DirList::SortList() {
if(FileInfo.size() > 1) if (FileInfo.size() > 1)
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback); std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
} }
void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) { void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
if(FileInfo.size() > 1) if (FileInfo.size() > 1)
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc); std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
} }
@ -199,14 +199,14 @@ uint64_t DirList::GetFilesize(int32_t index) const {
struct stat st; struct stat st;
const char *path = GetFilepath(index); const char *path = GetFilepath(index);
if(!path || stat(path, &st) != 0) if (!path || stat(path, &st) != 0)
return 0; return 0;
return st.st_size; return st.st_size;
} }
int32_t DirList::GetFileIndex(const char *filename) const { int32_t DirList::GetFileIndex(const char *filename) const {
if(!filename) if (!filename)
return -1; return -1;
for (uint32_t i = 0; i < FileInfo.size(); ++i) { for (uint32_t i = 0; i < FileInfo.size(); ++i) {

View File

@ -32,7 +32,7 @@
#include <wut_types.h> #include <wut_types.h>
typedef struct { typedef struct {
char * FilePath; char *FilePath;
BOOL isDir; BOOL isDir;
} DirEntry; } DirEntry;
@ -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,26 +64,33 @@ 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 {
if(!valid(index)) if (!valid(index))
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,8 +9,8 @@
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;
int32_t iFd = open(filepath, O_RDONLY); int32_t iFd = open(filepath, O_RDONLY);
@ -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;
} }
@ -30,12 +30,12 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
uint32_t done = 0; uint32_t done = 0;
int32_t readBytes = 0; int32_t readBytes = 0;
while(done < filesize) { while (done < filesize) {
if(done + blocksize > filesize) { if (done + blocksize > filesize) {
blocksize = filesize - done; blocksize = filesize - done;
} }
readBytes = read(iFd, buffer + done, blocksize); readBytes = read(iFd, buffer + done, blocksize);
if(readBytes <= 0) if (readBytes <= 0)
break; break;
done += readBytes; done += readBytes;
} }
@ -44,34 +44,34 @@ 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;
} }
*inbuffer = buffer; *inbuffer = buffer;
//! sign is optional input //! sign is optional input
if(size) { if (size) {
*size = filesize; *size = filesize;
} }
return filesize; return filesize;
} }
int32_t FSUtils::CheckFile(const char * filepath) { int32_t FSUtils::CheckFile(const char *filepath) {
if(!filepath) if (!filepath)
return 0; return 0;
struct stat filestat; struct stat filestat;
char dirnoslash[strlen(filepath)+2]; char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
while(dirnoslash[strlen(dirnoslash)-1] == '/') while (dirnoslash[strlen(dirnoslash) - 1] == '/')
dirnoslash[strlen(dirnoslash)-1] = '\0'; dirnoslash[strlen(dirnoslash) - 1] = '\0';
char * notRoot = strrchr(dirnoslash, '/'); char *notRoot = strrchr(dirnoslash, '/');
if(!notRoot) { if (!notRoot) {
strcat(dirnoslash, "/"); strcat(dirnoslash, "/");
} }
@ -81,29 +81,29 @@ int32_t FSUtils::CheckFile(const char * filepath) {
return 0; return 0;
} }
int32_t FSUtils::CreateSubfolder(const char * fullpath) { int32_t FSUtils::CreateSubfolder(const char *fullpath) {
if(!fullpath) if (!fullpath)
return 0; return 0;
int32_t result = 0; int32_t result = 0;
char dirnoslash[strlen(fullpath)+1]; char dirnoslash[strlen(fullpath) + 1];
strcpy(dirnoslash, fullpath); strcpy(dirnoslash, fullpath);
int32_t pos = strlen(dirnoslash)-1; int32_t pos = strlen(dirnoslash) - 1;
while(dirnoslash[pos] == '/') { while (dirnoslash[pos] == '/') {
dirnoslash[pos] = '\0'; dirnoslash[pos] = '\0';
pos--; pos--;
} }
if(CheckFile(dirnoslash)) { if (CheckFile(dirnoslash)) {
return 1; return 1;
} else { } else {
char parentpath[strlen(dirnoslash)+2]; char parentpath[strlen(dirnoslash) + 2];
strcpy(parentpath, dirnoslash); strcpy(parentpath, dirnoslash);
char * ptr = strrchr(parentpath, '/'); char *ptr = strrchr(parentpath, '/');
if(!ptr) { if (!ptr) {
//!Device root directory (must be with '/') //!Device root directory (must be with '/')
strcat(parentpath, "/"); strcat(parentpath, "/");
struct stat filestat; struct stat filestat;
@ -119,7 +119,7 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
result = CreateSubfolder(parentpath); result = CreateSubfolder(parentpath);
} }
if(!result) if (!result)
return 0; return 0;
if (mkdir(dirnoslash, 0777) == -1) { if (mkdir(dirnoslash, 0777) == -1) {
@ -129,13 +129,13 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
return 1; return 1;
} }
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);
file.close(); file.close();
return written; return written;
} }

View File

@ -8,9 +8,11 @@ public:
static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size); static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);
//! 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 saveBufferToFile(const char * path, void * buffer, uint32_t size); static int32_t CheckFile(const char *filepath);
static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size);
}; };
#endif // __FS_UTILS_H_ #endif // __FS_UTILS_H_

View File

@ -24,27 +24,27 @@ 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;
} }
} }
fullGameList.clear(); fullGameList.clear();
//! Clear memory of the vector completely //! Clear memory of the vector completely
std::vector<gameInfo*>().swap(fullGameList); std::vector<gameInfo *>().swap(fullGameList);
unlock(); unlock();
titleListChanged(this); titleListChanged(this);
} }
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) {
result = fullGameList[i]; result = fullGameList[i];
break; break;
} }
@ -55,13 +55,13 @@ gameInfo * GameList::getGameInfo(uint64_t titleId){
int32_t GameList::readGameList() { int32_t GameList::readGameList() {
// Clear list // Clear list
for (auto const& x : fullGameList) { for (auto const &x: fullGameList) {
delete x; delete x;
} }
fullGameList.clear(); fullGameList.clear();
//! Clear memory of the vector completely //! Clear memory of the vector completely
std::vector<gameInfo*>().swap(fullGameList); std::vector<gameInfo *>().swap(fullGameList);
int32_t cnt = 0; int32_t cnt = 0;
@ -79,7 +79,7 @@ int32_t GameList::readGameList() {
std::vector<struct MCPTitleListType> titles(titleCount); std::vector<struct MCPTitleListType> titles(titleCount);
uint32_t realTitleCount = 0; uint32_t realTitleCount = 0;
static const std::vector<MCPAppType> menuAppTypes { static const std::vector<MCPAppType> menuAppTypes{
MCP_APP_TYPE_GAME, MCP_APP_TYPE_GAME,
MCP_APP_TYPE_GAME_WII, MCP_APP_TYPE_GAME_WII,
MCP_APP_TYPE_SYSTEM_APPS, MCP_APP_TYPE_SYSTEM_APPS,
@ -92,7 +92,7 @@ int32_t GameList::readGameList() {
MCP_APP_TYPE_ACCOUNT_APPS, MCP_APP_TYPE_ACCOUNT_APPS,
}; };
for (auto appType : menuAppTypes) { for (auto appType: menuAppTypes) {
uint32_t titleCountByType = 0; uint32_t titleCountByType = 0;
MCPError err = MCP_TitleListByAppType(mcp, appType, &titleCountByType, titles.data() + realTitleCount, MCPError err = MCP_TitleListByAppType(mcp, appType, &titleCountByType, titles.data() + realTitleCount,
(titles.size() - realTitleCount) * sizeof(decltype(titles)::value_type)); (titles.size() - realTitleCount) * sizeof(decltype(titles)::value_type));
@ -106,13 +106,13 @@ int32_t GameList::readGameList() {
titles.resize(realTitleCount); titles.resize(realTitleCount);
} }
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,35 +122,31 @@ 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) {
header->name = meta->shortname_en; header->name = meta->shortname_en;
} }
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);
@ -167,15 +163,15 @@ int32_t GameList::readGameList() {
void GameList::updateTitleInfo() { void GameList::updateTitleInfo() {
for (int i = 0; i < this->size(); i++) { for (int i = 0; i < this->size(); i++) {
gameInfo * newHeader = this->at(i); gameInfo *newHeader = this->at(i);
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) {
newHeader->name = meta->shortname_en; newHeader->name = meta->shortname_en;
hasChanged = true; hasChanged = true;
} }
@ -183,24 +179,22 @@ 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);
} }
} }
if(hasChanged) { if (hasChanged) {
DCFlushRange(newHeader, sizeof(gameInfo)); DCFlushRange(newHeader, sizeof(gameInfo));
titleUpdated(newHeader); titleUpdated(newHeader);
} }
@ -209,11 +203,11 @@ void GameList::updateTitleInfo() {
int32_t GameList::load() { int32_t GameList::load() {
lock(); lock();
if(fullGameList.size() == 0) { if (fullGameList.empty()) {
readGameList(); readGameList();
} }
AsyncExecutor::execute([&] { updateTitleInfo();}); AsyncExecutor::execute([&] { updateTitleInfo(); });
titleListChanged(this); titleListChanged(this);

View File

@ -14,12 +14,13 @@ typedef struct _gameInfo {
MCPAppType appType; MCPAppType appType;
std::string name; std::string name;
std::string gamePath; std::string gamePath;
GuiImageData * imageData; GuiImageData *imageData;
} gameInfo; } 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();
@ -35,25 +37,27 @@ public:
return res; return res;
} }
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();
std::vector<gameInfo *> & getFullGameList(void) { std::vector<gameInfo *> &getFullGameList(void) {
return fullGameList; return fullGameList;
} }
@ -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

@ -36,46 +36,46 @@ GameIcon::GameIcon(GuiImageData *preloadImage)
vtxCount = sizeof(cfGameIconPosVtxs) / (Shader3D::cuVertexAttrSize); vtxCount = sizeof(cfGameIconPosVtxs) / (Shader3D::cuVertexAttrSize);
//! texture and vertex coordinates //! texture and vertex coordinates
posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs)); posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs));
texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords)); texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords));
if(posVtxs) { if (posVtxs) {
memcpy((float*)posVtxs, cfGameIconPosVtxs, sizeof(cfGameIconPosVtxs)); memcpy((float *) posVtxs, cfGameIconPosVtxs, sizeof(cfGameIconPosVtxs));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float*)posVtxs, sizeof(cfGameIconPosVtxs)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float *) posVtxs, sizeof(cfGameIconPosVtxs));
} }
if(texCoords) { if (texCoords) {
memcpy((float*)texCoords, cfGameIconTexCoords, sizeof(cfGameIconTexCoords)); memcpy((float *) texCoords, cfGameIconTexCoords, sizeof(cfGameIconTexCoords));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float*)texCoords, sizeof(cfGameIconTexCoords)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float *) texCoords, sizeof(cfGameIconTexCoords));
} }
//! create vertexes for the mirror frame //! create vertexes for the mirror frame
texCoordsMirror = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords)); texCoordsMirror = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords));
if(texCoordsMirror) { if (texCoordsMirror) {
for(uint32_t i = 0; i < vtxCount; i++) { for (uint32_t i = 0; i < vtxCount; i++) {
texCoordsMirror[i*2 + 0] = texCoords[i*2 + 0] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f); texCoordsMirror[i * 2 + 0] = texCoords[i * 2 + 0] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f);
texCoordsMirror[i*2 + 1] = texCoords[i*2 + 1] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f); texCoordsMirror[i * 2 + 1] = texCoords[i * 2 + 1] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f);
} }
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoordsMirror, sizeof(cfGameIconTexCoords)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoordsMirror, sizeof(cfGameIconTexCoords));
} }
//! setup stroke of the icon //! setup stroke of the icon
strokePosVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconStrokeVtxs)); strokePosVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconStrokeVtxs));
if(strokePosVtxs) { if (strokePosVtxs) {
memcpy(strokePosVtxs, cfGameIconStrokeVtxs, sizeof(cfGameIconStrokeVtxs)); memcpy(strokePosVtxs, cfGameIconStrokeVtxs, sizeof(cfGameIconStrokeVtxs));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokePosVtxs, sizeof(cfGameIconStrokeVtxs)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokePosVtxs, sizeof(cfGameIconStrokeVtxs));
} }
strokeTexCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); strokeTexCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize);
if(strokeTexCoords) { if (strokeTexCoords) {
for(size_t i = 0, n = 0; i < cuGameIconStrokeVtxCount; n += 2, i += 3) { for (size_t i = 0, n = 0; i < cuGameIconStrokeVtxCount; n += 2, i += 3) {
strokeTexCoords[n] = (1.0f + strokePosVtxs[i]) * 0.5f; strokeTexCoords[n] = (1.0f + strokePosVtxs[i]) * 0.5f;
strokeTexCoords[n+1] = 1.0f - (1.0f + strokePosVtxs[i+1]) * 0.5f; strokeTexCoords[n + 1] = 1.0f - (1.0f + strokePosVtxs[i + 1]) * 0.5f;
} }
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeTexCoords, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeTexCoords, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize);
} }
strokeColorVtxs = (uint8_t*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); strokeColorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize);
if(strokeColorVtxs) { if (strokeColorVtxs) {
for(size_t i = 0; i < (cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); i++) for (size_t i = 0; i < (cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); i++)
strokeColorVtxs[i] = 0xff; strokeColorVtxs[i] = 0xff;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeColorVtxs, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeColorVtxs, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize);
} }
@ -83,47 +83,47 @@ 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;
} }
} }
bool GameIcon::checkRayIntersection(const glm::vec3 & rayOrigin, const glm::vec3 & rayDirFrac) { bool GameIcon::checkRayIntersection(const glm::vec3 &rayOrigin, const glm::vec3 &rayDirFrac) {
//! since we always face the camera we can just check the AABB intersection //! since we always face the camera we can just check the AABB intersection
//! otherwise an OOB intersection would be required //! otherwise an OOB intersection would be required
float currPosX = getCenterX() * Application::instance()->getVideo()->getWidthScaleFactor() * 2.0f; float currPosX = getCenterX() * Application::instance()->getVideo()->getWidthScaleFactor() * 2.0f;
float currPosY = getCenterY() * Application::instance()->getVideo()->getHeightScaleFactor() * 2.0f; float currPosY = getCenterY() * Application::instance()->getVideo()->getHeightScaleFactor() * 2.0f;
float currPosZ = getDepth() * Application::instance()->getVideo()->getDepthScaleFactor() * 2.0f; float currPosZ = getDepth() * Application::instance()->getVideo()->getDepthScaleFactor() * 2.0f;
float currScaleX = getScaleX() * (float)getWidth() * Application::instance()->getVideo()->getWidthScaleFactor(); float currScaleX = getScaleX() * (float) getWidth() * Application::instance()->getVideo()->getWidthScaleFactor();
float currScaleY = getScaleY() * (float)getHeight() * Application::instance()->getVideo()->getHeightScaleFactor(); float currScaleY = getScaleY() * (float) getHeight() * Application::instance()->getVideo()->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float)getWidth() * Application::instance()->getVideo()->getDepthScaleFactor(); float currScaleZ = getScaleZ() * (float) getWidth() * Application::instance()->getVideo()->getDepthScaleFactor();
//! lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner //! lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner
glm::vec3 lb(currPosX - currScaleX, currPosY - currScaleY, currPosZ - currScaleZ); glm::vec3 lb(currPosX - currScaleX, currPosY - currScaleY, currPosZ - currScaleZ);
glm::vec3 rt(currPosX + currScaleX, currPosY + currScaleY, currPosZ + currScaleZ); glm::vec3 rt(currPosX + currScaleX, currPosY + currScaleY, currPosZ + currScaleZ);
@ -154,29 +154,29 @@ bool GameIcon::checkRayIntersection(const glm::vec3 & rayOrigin, const glm::vec3
return true; return true;
} }
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
float currPosX = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f; float currPosX = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f;
float currPosY = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f; float currPosY = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f;
float currPosZ = getDepth() * pVideo->getDepthScaleFactor() * 2.0f; float currPosZ = getDepth() * pVideo->getDepthScaleFactor() * 2.0f;
float currScaleX = getScaleX() * (float)getWidth() * pVideo->getWidthScaleFactor(); float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor();
float currScaleY = getScaleY() * (float)getHeight() * pVideo->getHeightScaleFactor(); float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float)getWidth() * pVideo->getDepthScaleFactor(); float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor();
float strokeScaleX = pVideo->getWidthScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale; float strokeScaleX = pVideo->getWidthScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale;
float strokeScaleY = pVideo->getHeightScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale; float strokeScaleY = pVideo->getHeightScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale;
for(int32_t iDraw = 0; iDraw < 2; iDraw++) { for (int32_t iDraw = 0; iDraw < 2; iDraw++) {
glm::vec4 * alphaFadeOut; glm::vec4 *alphaFadeOut;
glm::mat4 m_iconView; glm::mat4 m_iconView;
glm::mat4 m_mirrorView; glm::mat4 m_mirrorView;
glm::mat4 m_strokeView; glm::mat4 m_strokeView;
if(iDraw == RENDER_REFLECTION) { if (iDraw == RENDER_REFLECTION) {
//! Reflection render //! Reflection render
if(!bRenderReflection) if (!bRenderReflection)
continue; continue;
m_iconView = glm::translate(modelView, glm::vec3(currPosX, -currScaleY * 2.0f - currPosY, currPosZ + cosf(DegToRad(rotationX)) * currScaleZ * 2.0f)); m_iconView = glm::translate(modelView, glm::vec3(currPosX, -currScaleY * 2.0f - currPosY, currPosZ + cosf(DegToRad(rotationX)) * currScaleZ * 2.0f));
m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f)); m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f));
@ -190,7 +190,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_ENABLE, GX2_DISABLE); GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_ENABLE, GX2_DISABLE);
} else { } else {
//! Normal render //! Normal render
m_iconView = glm::translate(modelView, glm::vec3(currPosX,currPosY, currPosZ)); m_iconView = glm::translate(modelView, glm::vec3(currPosX, currPosY, currPosZ));
m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f)); m_iconView = glm::rotate(m_iconView, DegToRad(rotationX), glm::vec3(1.0f, 0.0f, 0.0f));
m_iconView = glm::scale(m_iconView, glm::vec3(currScaleX, currScaleY, currScaleZ)); m_iconView = glm::scale(m_iconView, glm::vec3(currScaleX, currScaleY, currScaleZ));
@ -204,7 +204,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
colorIntensityMirror[3] = cfIconMirrorAlpha * colorIntensity[3]; colorIntensityMirror[3] = cfIconMirrorAlpha * colorIntensity[3];
if(!bIconLast) { if (!bIconLast) {
Shader3D::instance()->setShaders(); Shader3D::instance()->setShaders();
Shader3D::instance()->setProjectionMtx(projectionMtx); Shader3D::instance()->setProjectionMtx(projectionMtx);
Shader3D::instance()->setViewMtx(viewMtx); Shader3D::instance()->setViewMtx(viewMtx);
@ -220,7 +220,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
} }
if(bSelected) { if (bSelected) {
strokeFractalEnable = 0; strokeFractalEnable = 0;
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL); GX2SetDepthOnlyControl(GX2_ENABLE, GX2_DISABLE, GX2_COMPARE_FUNC_LEQUAL);
@ -243,7 +243,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL); GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
} }
if(iDraw == RENDER_NORMAL && bRenderStroke) { if (iDraw == RENDER_NORMAL && bRenderStroke) {
strokeFractalEnable = 1; strokeFractalEnable = 1;
//! now render the icon stroke //! now render the icon stroke
//! make the stroke a little bigger than the mirror, just by the line width on each side //! make the stroke a little bigger than the mirror, just by the line width on each side
@ -274,7 +274,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoordsMirror); Shader3D::instance()->setAttributeBuffer(vtxCount, posVtxs, texCoordsMirror);
Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount); Shader3D::instance()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount);
if(bIconLast) { if (bIconLast) {
Shader3D::instance()->setShaders(); Shader3D::instance()->setShaders();
Shader3D::instance()->setProjectionMtx(projectionMtx); Shader3D::instance()->setProjectionMtx(projectionMtx);
Shader3D::instance()->setViewMtx(viewMtx); Shader3D::instance()->setViewMtx(viewMtx);
@ -290,7 +290,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
} }
//! return back normal culling //! return back normal culling
if(iDraw == RENDER_REFLECTION) { if (iDraw == RENDER_REFLECTION) {
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_ENABLE); GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_ENABLE);
} }
} }

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);
bool checkRayIntersection(const glm::vec3 & rayOrigin, const glm::vec3 & rayDirFrac); 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);
private: private:
enum eRenderState enum eRenderState {
{
RENDER_REFLECTION, RENDER_REFLECTION,
RENDER_NORMAL RENDER_NORMAL
}; };

File diff suppressed because it is too large Load Diff

View File

@ -25,35 +25,21 @@
#include "utils/logger.h" #include "utils/logger.h"
#include "gui/GameIcon.h" #include "gui/GameIcon.h"
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);
@ -112,10 +98,10 @@ GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex,bool sortByNam
append(&arrowRightButton); append(&arrowRightButton);
// at most we are rendering 2 screens at the same time // at most we are rendering 2 screens at the same time
for(int i = 0; i< MAX_COLS * MAX_ROWS *2; i++) { for (int i = 0; i < MAX_COLS * MAX_ROWS * 2; i++) {
GameIcon * image = new GameIcon(&emptyIcon); GameIcon *image = new GameIcon(&emptyIcon);
emptyIcons.push_back(image); emptyIcons.push_back(image);
GuiButton * button = new GuiButton(emptyIcon.getWidth(), emptyIcon.getHeight()); GuiButton *button = new GuiButton(emptyIcon.getWidth(), emptyIcon.getHeight());
button->setImage(image); button->setImage(image);
button->setPosition(0, 0); button->setPosition(0, 0);
//button->setEffectGrow(); //button->setEffectGrow();
@ -140,18 +126,18 @@ GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex,bool sortByNam
GuiIconGrid::~GuiIconGrid() { GuiIconGrid::~GuiIconGrid() {
containerMutex.lock(); containerMutex.lock();
for (auto const& x : gameInfoContainers) { for (auto const &x: gameInfoContainers) {
remove(x.second->button); remove(x.second->button);
delete x.second; delete x.second;
} }
gameInfoContainers.clear(); gameInfoContainers.clear();
containerMutex.unlock(); containerMutex.unlock();
for (auto const& x : emptyButtons) { for (auto const &x: emptyButtons) {
delete x; delete x;
} }
for (auto const& x : emptyIcons) { for (auto const &x: emptyIcons) {
delete x; delete x;
} }
@ -162,8 +148,8 @@ GuiIconGrid::~GuiIconGrid() {
int32_t GuiIconGrid::offsetForTitleId(uint64_t titleId) { int32_t GuiIconGrid::offsetForTitleId(uint64_t titleId) {
int32_t offset = -1; int32_t offset = -1;
positionMutex.lock(); positionMutex.lock();
for(uint32_t i = 0; i < position.size(); i++) { for (uint32_t i = 0; i < position.size(); i++) {
if(position.at(i) == titleId) { if (position.at(i) == titleId) {
offset = i; offset = i;
break; break;
} }
@ -176,10 +162,10 @@ 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) {
container->image->setSelected(true); container->image->setSelected(true);
gameTitle.setText(container->info->name.c_str()); gameTitle.setText(container->info->name.c_str());
} else { } else {
@ -189,9 +175,9 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) {
containerMutex.unlock(); containerMutex.unlock();
int32_t offset = offsetForTitleId(getSelectedGame()); int32_t offset = offsetForTitleId(getSelectedGame());
if(offset > 0) { if (offset > 0) {
uint32_t newPage = offset / (MAX_COLS * MAX_ROWS); uint32_t newPage = offset / (MAX_COLS * MAX_ROWS);
if(newPage != (uint32_t) curPage) { if (newPage != (uint32_t) curPage) {
curPage = newPage; curPage = newPage;
bUpdatePositions = true; bUpdatePositions = true;
} }
@ -202,7 +188,7 @@ uint64_t GuiIconGrid::getSelectedGame(void) {
return selectedGame; return selectedGame;
} }
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) { void GuiIconGrid::OnGameTitleListUpdated(GameList *gameList) {
gameList->lock(); gameList->lock();
containerMutex.lock(); containerMutex.lock();
positionMutex.lock(); positionMutex.lock();
@ -210,16 +196,16 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
auto it = gameInfoContainers.begin(); auto it = gameInfoContainers.begin();
while (it != gameInfoContainers.end()) { while (it != gameInfoContainers.end()) {
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);
@ -228,17 +214,17 @@ 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) {
container = x.second; container = x.second;
break; break;
} }
} }
if(container == NULL) { if (container == nullptr) {
OnGameTitleAdded(info); OnGameTitleAdded(info);
} }
} }
@ -266,19 +252,19 @@ void GuiIconGrid::OnRightArrowClick(GuiButton *button, const GuiController *cont
void GuiIconGrid::OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
int32_t offset = offsetForTitleId(getSelectedGame()); int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) { if (offset < 0) {
return; return;
} }
if((offset % MAX_COLS) == 0) { if ((offset % MAX_COLS) == 0) {
offset -= ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1; offset -= ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1;
} else { } else {
offset--; offset--;
} }
if(offset < 0 || position.empty()) { if (offset < 0 || position.empty()) {
return; return;
} }
uint64_t newTitleId = position.at(offset); uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) { if (newTitleId > 0) {
setSelectedGame(newTitleId); setSelectedGame(newTitleId);
gameSelectionChanged(this, selectedGame); gameSelectionChanged(this, selectedGame);
} }
@ -287,19 +273,19 @@ void GuiIconGrid::OnLeftClick(GuiButton *button, const GuiController *controller
void GuiIconGrid::OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
int32_t offset = offsetForTitleId(getSelectedGame()); int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) { if (offset < 0) {
return; return;
} }
if((offset % MAX_COLS) == MAX_COLS - 1) { if ((offset % MAX_COLS) == MAX_COLS - 1) {
offset += ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1; offset += ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1;
} else { } else {
offset++; offset++;
} }
if((uint32_t) offset >= position.size()) { if ((uint32_t) offset >= position.size()) {
return; return;
} }
uint64_t newTitleId = position.at(offset); uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) { if (newTitleId > 0) {
setSelectedGame(newTitleId); setSelectedGame(newTitleId);
gameSelectionChanged(this, selectedGame); gameSelectionChanged(this, selectedGame);
} }
@ -307,40 +293,41 @@ void GuiIconGrid::OnRightClick(GuiButton *button, const GuiController *controlle
void GuiIconGrid::OnDownClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnDownClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
int32_t offset = offsetForTitleId(getSelectedGame()); int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) { if (offset < 0) {
return; return;
} }
if(offset % (MAX_COLS * MAX_ROWS) < (MAX_COLS * MAX_ROWS) - MAX_COLS) { if (offset % (MAX_COLS * MAX_ROWS) < (MAX_COLS * MAX_ROWS) - MAX_COLS) {
offset = offset + MAX_COLS; offset = offset + MAX_COLS;
} else { } else {
return; return;
} }
if((uint32_t) offset >= position.size()) { if ((uint32_t) offset >= position.size()) {
return; return;
} }
uint64_t newTitleId = position.at(offset); uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) { if (newTitleId > 0) {
setSelectedGame(newTitleId); setSelectedGame(newTitleId);
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) {
return; return;
} }
if(offset % (MAX_COLS * MAX_ROWS) >= MAX_COLS) { if (offset % (MAX_COLS * MAX_ROWS) >= MAX_COLS) {
offset = offset - MAX_COLS; offset = offset - MAX_COLS;
} else { } else {
return; return;
} }
if(offset < 0) { if (offset < 0) {
return; return;
} }
uint64_t newTitleId = position.at(offset); uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) { if (newTitleId > 0) {
setSelectedGame(newTitleId); setSelectedGame(newTitleId);
gameSelectionChanged(this, selectedGame); gameSelectionChanged(this, selectedGame);
} }
@ -348,18 +335,18 @@ void GuiIconGrid::OnUpClick(GuiButton *button, const GuiController *controller,
void GuiIconGrid::OnLaunchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { void GuiIconGrid::OnLaunchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
//! do not auto launch when wiimote is pointing to screen and presses A //! do not auto launch when wiimote is pointing to screen and presses A
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;
} }
} else { } else {
@ -372,10 +359,10 @@ 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;
} }
} else { } else {
@ -389,20 +376,20 @@ 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) {
if(x == button) { if (x == button) {
found = true; found = true;
break; break;
} }
} }
if(!found) { if (!found) {
currentlyHeld = button; currentlyHeld = button;
} }
} }
if(currentlyHeld != NULL && currentlyHeld != button) { if (currentlyHeld != nullptr && currentlyHeld != button) {
dragTarget = button; dragTarget = button;
} }
} }
@ -415,20 +402,20 @@ 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) {
containerMutex.lock(); containerMutex.lock();
for (auto const& x : gameInfoContainers) { for (auto const &x: gameInfoContainers) {
if(x.second->button == button) { if (x.second->button == button) {
if(selectedGame == (x.second->info->titleId)) { if (selectedGame == (x.second->info->titleId)) {
if(gameLaunchTimer < 30) if (gameLaunchTimer < 30)
OnLaunchClick(button, controller, trigger); OnLaunchClick(button, controller, trigger);
} else { } else {
setSelectedGame(x.second->info->titleId); setSelectedGame(x.second->info->titleId);
@ -441,19 +428,19 @@ void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *cont
containerMutex.unlock(); containerMutex.unlock();
} }
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);
image->setRenderReflection(false); image->setRenderReflection(false);
image->setStrokeRender(false); image->setStrokeRender(false);
image->setSelected(info->titleId == selectedGame); image->setSelected(info->titleId == selectedGame);
image->setRenderIconLast(true); image->setRenderIconLast(true);
GuiButton * button = new GuiButton(noIcon.getWidth(), noIcon.getHeight()); GuiButton *button = new GuiButton(noIcon.getWidth(), noIcon.getHeight());
button->setImage(image); button->setImage(image);
button->setPosition(0, 0); button->setPosition(0, 0);
button->setEffectGrow(); button->setEffectGrow();
@ -469,7 +456,7 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
button->pointedOff.connect(this, &GuiIconGrid::OnGameButtonPointedOff); button->pointedOff.connect(this, &GuiIconGrid::OnGameButtonPointedOff);
//button->dragged.connect(this, &GuiIconGrid::OnGameButtonDragged); //button->dragged.connect(this, &GuiIconGrid::OnGameButtonDragged);
GameInfoContainer * container = new GameInfoContainer(button, image, info); GameInfoContainer *container = new GameInfoContainer(button, image, info);
containerMutex.lock(); containerMutex.lock();
gameInfoContainers[info->titleId] = container; gameInfoContainers[info->titleId] = container;
containerMutex.unlock(); containerMutex.unlock();
@ -477,33 +464,34 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
positionMutex.lock(); positionMutex.lock();
bool foundFreePlace = false; bool foundFreePlace = false;
for(uint32_t i = 0; i < position.size(); i++) { for (uint32_t i = 0; i < position.size(); i++) {
if(position[i] == 0) { if (position[i] == 0) {
position[i] = info->titleId; position[i] = info->titleId;
foundFreePlace = true; foundFreePlace = true;
break; break;
} }
} }
if(!foundFreePlace) { if (!foundFreePlace) {
position.push_back(info->titleId); position.push_back(info->titleId);
} }
positionMutex.unlock(); positionMutex.unlock();
bUpdatePositions = true; bUpdatePositions = true;
} }
void GuiIconGrid::OnGameTitleUpdated(gameInfo * info) {
DEBUG_FUNCTION_LINE("Updating infos of %016llX\n", info->titleId); void GuiIconGrid::OnGameTitleUpdated(gameInfo *info) {
GameInfoContainer * container = NULL; DEBUG_FUNCTION_LINE("Updating infos of %016llX", info->titleId);
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) {
container = x.second; container = x.second;
break; break;
} }
} }
// 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,30 +501,30 @@ 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();
// copy key-value pairs from the map to the vector // copy key-value pairs from the map to the vector
std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter<std::vector<std::pair<uint64_t,GameInfoContainer*>>>(vec)); std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter<std::vector<std::pair<uint64_t, GameInfoContainer *>>>(vec));
containerMutex.unlock(); containerMutex.unlock();
uint64_t targetTitleId = 0; uint64_t targetTitleId = 0;
for (auto const& x : vec) { for (auto const &x: vec) {
if(x.second->button == dragTarget) { if (x.second->button == dragTarget) {
targetTitleId = x.first; targetTitleId = x.first;
break; break;
} }
} }
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;
} }
@ -544,45 +532,45 @@ void GuiIconGrid::process() {
break; break;
} }
} }
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) { if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
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;
} }
} }
if(currentLeftPosition < targetLeftPosition) { if (currentLeftPosition < targetLeftPosition) {
currentLeftPosition += 35; currentLeftPosition += 35;
if(currentLeftPosition > targetLeftPosition) if (currentLeftPosition > targetLeftPosition)
currentLeftPosition = targetLeftPosition; currentLeftPosition = targetLeftPosition;
bUpdatePositions = true; bUpdatePositions = true;
} else if(currentLeftPosition > targetLeftPosition) { } else if (currentLeftPosition > targetLeftPosition) {
currentLeftPosition -= 35; currentLeftPosition -= 35;
if(currentLeftPosition < targetLeftPosition) if (currentLeftPosition < targetLeftPosition)
currentLeftPosition = targetLeftPosition; currentLeftPosition = targetLeftPosition;
bUpdatePositions = true; bUpdatePositions = true;
} }
if(bUpdatePositions) { if (bUpdatePositions) {
bUpdatePositions = false; bUpdatePositions = false;
updateButtonPositions(); updateButtonPositions();
} }
@ -591,7 +579,7 @@ void GuiIconGrid::process() {
GuiFrame::process(); GuiFrame::process();
} }
void GuiIconGrid::update(GuiController * c) { void GuiIconGrid::update(GuiController *c) {
GuiFrame::update(c); GuiFrame::update(c);
} }
@ -605,31 +593,31 @@ void GuiIconGrid::updateButtonPositions() {
int32_t col = 0, row = 0, listOff = 0; int32_t col = 0, row = 0, listOff = 0;
// create an empty vector of pairs // create an empty vector of pairs
std::vector<std::pair<uint64_t,GameInfoContainer*>> vec; std::vector<std::pair<uint64_t, GameInfoContainer *>> vec;
containerMutex.lock(); containerMutex.lock();
// copy key-value pairs from the map to the vector // copy key-value pairs from the map to the vector
std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter<std::vector<std::pair<uint64_t,GameInfoContainer*>>>(vec)); std::copy(gameInfoContainers.begin(), gameInfoContainers.end(), std::back_inserter<std::vector<std::pair<uint64_t, GameInfoContainer *>>>(vec));
containerMutex.unlock(); containerMutex.unlock();
for (auto const& x : vec) { for (auto const &x: vec) {
if(x.second->button == currentlyHeld) { if (x.second->button == currentlyHeld) {
currentlyHeldTitleId = x.first; currentlyHeldTitleId = x.first;
} }
remove(x.second->button); remove(x.second->button);
} }
for (auto const& x : emptyButtons) { for (auto const &x: emptyButtons) {
remove(x); remove(x);
} }
if(sortByName) { if (sortByName) {
std::sort(vec.begin(), vec.end(), std::sort(vec.begin(), vec.end(),
[](const std::pair<uint64_t,GameInfoContainer*>& l, const std::pair<uint64_t,GameInfoContainer*>& r) { [](const std::pair<uint64_t, GameInfoContainer *> &l, const std::pair<uint64_t, GameInfoContainer *> &r) {
if (l.second != r.second) if (l.second != r.second)
return l.second->info->name.compare(r.second->info->name) <0; return l.second->info->name.compare(r.second->info->name) < 0;
return l.first < r.first; return l.first < r.first;
}); });
@ -638,36 +626,36 @@ void GuiIconGrid::updateButtonPositions() {
// TODO somehow be able to adjust the positions. // TODO somehow be able to adjust the positions.
//position.clear(); //position.clear();
for(uint32_t i = 0; i<position.size(); i++) { for (uint32_t i = 0; i < position.size(); i++) {
if(position[i] == currentlyHeldTitleId) { if (position[i] == currentlyHeldTitleId) {
currentlyHeldPosition = i; currentlyHeldPosition = i;
position[i] = 0; position[i] = 0;
} }
} }
uint32_t elementSize = position.size(); uint32_t elementSize = position.size();
uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) +1; uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) + 1;
if(elementSize % (MAX_COLS * MAX_ROWS) == 0) { if (elementSize % (MAX_COLS * MAX_ROWS) == 0) {
pages--; pages--;
} }
uint32_t emptyIconUse = 0; uint32_t emptyIconUse = 0;
if(curPage < 0) { if (curPage < 0) {
curPage = 0; curPage = 0;
} }
if((uint32_t) curPage > pages) { if ((uint32_t) curPage > pages) {
curPage = 0; curPage = 0;
} }
targetLeftPosition = -curPage * getWidth(); targetLeftPosition = -curPage * getWidth();
if((uint32_t) curPage < (pages - 1)) { if ((uint32_t) curPage < (pages - 1)) {
arrowRightButton.clearState(GuiElement::STATE_DISABLED); arrowRightButton.clearState(GuiElement::STATE_DISABLED);
arrowRightButton.setVisible(true); arrowRightButton.setVisible(true);
bringToFront(&arrowRightButton); bringToFront(&arrowRightButton);
} }
if(curPage > 0) { if (curPage > 0) {
arrowLeftButton.clearState(GuiElement::STATE_DISABLED); arrowLeftButton.clearState(GuiElement::STATE_DISABLED);
arrowLeftButton.setVisible(true); arrowLeftButton.setVisible(true);
bringToFront(&arrowLeftButton); bringToFront(&arrowLeftButton);
@ -676,49 +664,49 @@ void GuiIconGrid::updateButtonPositions() {
uint32_t startPage = -(currentLeftPosition / getWidth()); uint32_t startPage = -(currentLeftPosition / getWidth());
uint32_t endPage = startPage; uint32_t endPage = startPage;
if(targetLeftPosition != currentLeftPosition) { if (targetLeftPosition != currentLeftPosition) {
for (auto const& x : vec) { for (auto const &x: vec) {
x.second->button->setHoldable(false); x.second->button->setHoldable(false);
} }
endPage++; endPage++;
if(endPage > pages) { if (endPage > pages) {
endPage = pages; endPage = pages;
} }
} else { } else {
for (auto const& x : vec) { for (auto const &x: vec) {
x.second->button->setHoldable(true); x.second->button->setHoldable(true);
} }
} }
uint32_t startValue = startPage * (MAX_COLS * MAX_ROWS); uint32_t startValue = startPage * (MAX_COLS * MAX_ROWS);
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;
} }
element = emptyButtons.at(emptyIconUse); element = emptyButtons.at(emptyIconUse);
@ -729,19 +717,19 @@ void GuiIconGrid::updateButtonPositions() {
append(element); append(element);
col++; col++;
if(col >= MAX_COLS) { if (col >= MAX_COLS) {
col = 0; col = 0;
row++; row++;
} }
if(row >= MAX_ROWS) { if (row >= MAX_ROWS) {
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) {
for(uint32_t i = 0; i < positionButtons.size() - position.size(); i++) { for (uint32_t i = 0; i < positionButtons.size() - position.size(); i++) {
position.push_back(0); position.push_back(0);
} }
} }

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 OnGameTitleUpdated(gameInfo * info); void OnAddGameTitle(gameInfo *info);
void OnGameTitleAdded(gameInfo * info);
void OnGameTitleUpdated(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;
@ -66,8 +74,8 @@ private:
GuiButton upButton; GuiButton upButton;
GuiButton launchButton; GuiButton launchButton;
GuiImageData* arrowRightImageData; GuiImageData *arrowRightImageData;
GuiImageData* arrowLeftImageData; GuiImageData *arrowLeftImageData;
GuiImage arrowRightImage; GuiImage arrowRightImage;
GuiImage arrowLeftImage; GuiImage arrowLeftImage;
GuiButton arrowRightButton; GuiButton arrowRightButton;
@ -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,44 +132,44 @@ 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:
GameInfoContainer(GuiButton* button, GameIcon * image, gameInfo * info) { GameInfoContainer(GuiButton *button, GameIcon *image, gameInfo *info) {
this->image = image; this->image = image;
this->info = info; this->info = info;
this->button = button; this->button = button;
} }
~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);
} }
} }
GameIcon * image; GameIcon *image;
gameInfo * info; gameInfo *info;
GuiButton * button; GuiButton *button;
}; };
std::recursive_mutex positionMutex; std::recursive_mutex positionMutex;
std::recursive_mutex containerMutex; std::recursive_mutex containerMutex;
std::map<uint64_t, GameInfoContainer *> gameInfoContainers; std::map<uint64_t, GameInfoContainer *> gameInfoContainers;
std::vector<uint64_t> position; std::vector<uint64_t> position;
std::vector<GuiButton*> positionButtons; std::vector<GuiButton *> positionButtons;
std::vector<GuiImage *> emptyIcons; std::vector<GuiImage *> emptyIcons;
std::vector<GuiButton *> emptyButtons; std::vector<GuiButton *> emptyButtons;

View File

@ -7,14 +7,18 @@
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 OnGameTitleAdded(gameInfo * info) = 0; virtual void OnGameTitleUpdated(gameInfo *info) = 0;
virtual void OnGameTitleAdded(gameInfo *info) = 0;
sigslot::signal2<GuiTitleBrowser *, uint64_t> gameLaunchClicked; sigslot::signal2<GuiTitleBrowser *, uint64_t> gameLaunchClicked;
sigslot::signal2<GuiTitleBrowser *, uint64_t> gameSelectionChanged; sigslot::signal2<GuiTitleBrowser *, uint64_t> gameSelectionChanged;

View File

@ -4,10 +4,10 @@
#include "fs/FSUtils.h" #include "fs/FSUtils.h"
#include "utils/AsyncExecutor.h" #include "utils/AsyncExecutor.h"
GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo * info, bool onTV) : GuiFrame(w, h), GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV) : GuiFrame(w, h),
bgImageColor(w, h, (GX2Color) { bgImageColor(w, h, (GX2Color) {
0, 0, 0, 0 0, 0, 0, 0
}) { }) {
bgImageColor.setImageColor((GX2Color) { bgImageColor.setImageColor((GX2Color) {
79, 153, 239, 255 79, 153, 239, 255
}, 0); }, 0);
@ -25,15 +25,15 @@ GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo * info, bool o
this->info = info; this->info = info;
std::string filepath = "fs:" + info->gamePath + META_PATH + "/bootDRCTex.tga"; std::string filepath = "fs:" + info->gamePath + META_PATH + "/bootDRCTex.tga";
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) {
splashScreenData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR); splashScreenData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
if(splashScreenData) { if (splashScreenData) {
bgImageColor.setImageData(splashScreenData); bgImageColor.setImageData(splashScreenData);
bgImageColor.setScale(((float) h) / splashScreenData->getHeight()); bgImageColor.setScale(((float) h) / splashScreenData->getHeight());
} }
@ -50,9 +50,9 @@ void GameSplashScreen::OnSplashScreenFadeInDone(GuiElement *element) {
} }
void GameSplashScreen::draw(CVideo * v) { void GameSplashScreen::draw(CVideo *v) {
GuiFrame::draw(v); GuiFrame::draw(v);
if(launchGame && frameCounter++ > 1) { if (launchGame && frameCounter++ > 1) {
DEBUG_FUNCTION_LINE("Launch game %d\n", onTV); DEBUG_FUNCTION_LINE("Launch game %d\n", onTV);
gameGameSplashScreenFinished(this, info, onTV); gameGameSplashScreenFinished(this, info, onTV);
} }
@ -60,7 +60,7 @@ void GameSplashScreen::draw(CVideo * v) {
GameSplashScreen::~GameSplashScreen() { GameSplashScreen::~GameSplashScreen() {
DEBUG_FUNCTION_LINE("Destroy me\n"); DEBUG_FUNCTION_LINE("Destroy me\n");
if(splashScreenData) { if (splashScreenData) {
AsyncExecutor::pushForDelete(splashScreenData); AsyncExecutor::pushForDelete(splashScreenData);
} }
} }

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);
virtual void draw(CVideo * v); void OnSplashScreenFadeInDone(GuiElement *element);
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,20 +4,20 @@
#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;
createArg.regionType = nn::swkbd::RegionType::Europe; createArg.regionType = nn::swkbd::RegionType::Europe;
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;
} }
@ -25,24 +25,24 @@ KeyboardHelper::KeyboardHelper() {
} }
KeyboardHelper::~KeyboardHelper() { 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;
} }
} }
bool KeyboardHelper::openKeyboard() { bool KeyboardHelper::openKeyboard() {
if(keyboardCreated) { if (keyboardCreated) {
// Show the keyboard // Show the keyboard
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;
@ -56,9 +56,9 @@ std::string KeyboardHelper::getResult() {
} }
bool KeyboardHelper::checkResult() { bool KeyboardHelper::checkResult() {
if(keyboardCreated) { if (keyboardCreated) {
VPADStatus vpadStatus; VPADStatus vpadStatus;
if(keyboardOpen) { if (keyboardOpen) {
VPADRead(VPAD_CHAN_0, &vpadStatus, 1, nullptr); VPADRead(VPAD_CHAN_0, &vpadStatus, 1, nullptr);
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &vpadStatus.tpNormal, &vpadStatus.tpNormal); VPADGetTPCalibratedPoint(VPAD_CHAN_0, &vpadStatus.tpNormal, &vpadStatus.tpNormal);
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <string> #include <string>
#include <coreinit/filesystem.h> #include <coreinit/filesystem.h>
@ -10,13 +11,13 @@ public:
bool checkResult(); bool checkResult();
void drawTV(); static void drawTV();
void drawDRC(); static void drawDRC();
bool openKeyboard(); bool openKeyboard();
bool isReady(){ bool isReady() {
return keyboardCreated; return keyboardCreated;
} }
@ -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,14 +29,9 @@
#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) for (int32_t i = 0; i < 4; i++) {
, gameClickSound(Resources::GetSound("game_click.mp3")) std::string filename = StringTools::strfmt("player%i_point.png", i + 1);
, mainSwitchButtonFrame(NULL)
, currentTvFrame(NULL)
, currentDrcFrame(NULL) {
for(int32_t i = 0; i < 4; i++) {
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());
pointerImg[i] = new GuiImage(pointerImgData[i]); pointerImg[i] = new GuiImage(pointerImgData[i]);
pointerImg[i]->setScale(1.5f); pointerImg[i]->setScale(1.5f);
@ -46,7 +41,7 @@ MainWindow::MainWindow(int32_t w, int32_t h)
gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged); gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged);
gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated); gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated);
gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded); gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded);
AsyncExecutor::execute([&] {gameList.load();}); AsyncExecutor::execute([&] { gameList.load(); });
} }
@ -54,15 +49,15 @@ MainWindow::~MainWindow() {
gameList.titleListChanged.disconnect(this); gameList.titleListChanged.disconnect(this);
gameList.titleUpdated.disconnect(this); gameList.titleUpdated.disconnect(this);
gameList.titleAdded.disconnect(this); gameList.titleAdded.disconnect(this);
while(!tvElements.empty()) { while (!tvElements.empty()) {
delete tvElements[0]; delete tvElements[0];
remove(tvElements[0]); remove(tvElements[0]);
} }
while(!drcElements.empty()) { while (!drcElements.empty()) {
delete drcElements[0]; delete drcElements[0];
remove(drcElements[0]); remove(drcElements[0]);
} }
for(int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
delete pointerImg[i]; delete pointerImg[i];
Resources::RemoveImageData(pointerImgData[i]); Resources::RemoveImageData(pointerImgData[i]);
} }
@ -75,18 +70,18 @@ void MainWindow::updateEffects() {
uint32_t tvSize = tvElements.size(); uint32_t tvSize = tvElements.size();
uint32_t drcSize = drcElements.size(); uint32_t drcSize = drcElements.size();
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
drcElements[i]->updateEffects(); drcElements[i]->updateEffects();
} }
//! only update TV elements that are not updated yet because they are on DRC //! only update TV elements that are not updated yet because they are on DRC
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) { for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
uint32_t n; uint32_t n;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) { for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if(tvElements[i] == drcElements[n]) if (tvElements[i] == drcElements[n])
break; break;
} }
if(n == drcElements.size()) { if (n == drcElements.size()) {
tvElements[i]->updateEffects(); tvElements[i]->updateEffects();
} }
} }
@ -97,24 +92,24 @@ void MainWindow::process() {
uint32_t tvSize = tvElements.size(); uint32_t tvSize = tvElements.size();
uint32_t drcSize = drcElements.size(); uint32_t drcSize = drcElements.size();
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
drcElements[i]->process(); drcElements[i]->process();
} }
//! only update TV elements that are not updated yet because they are on DRC //! only update TV elements that are not updated yet because they are on DRC
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) { for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
uint32_t n; uint32_t n;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) { for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if(tvElements[i] == drcElements[n]) if (tvElements[i] == drcElements[n])
break; break;
} }
if(n == drcElements.size()) { if (n == drcElements.size()) {
tvElements[i]->process(); tvElements[i]->process();
} }
} }
if(keyboardInstance != NULL) { if (keyboardInstance != nullptr) {
if(keyboardInstance->checkResult()) { if (keyboardInstance->checkResult()) {
std::string result = keyboardInstance->getResult(); std::string result = keyboardInstance->getResult();
currentTvFrame->clearState(GuiElement::STATE_DISABLED); currentTvFrame->clearState(GuiElement::STATE_DISABLED);
@ -125,23 +120,23 @@ void MainWindow::process() {
} }
} }
void MainWindow::OnGameTitleListChanged(GameList * list) { void MainWindow::OnGameTitleListChanged(GameList *list) {
currentTvFrame->OnGameTitleListUpdated(list); currentTvFrame->OnGameTitleListUpdated(list);
if(currentTvFrame != currentDrcFrame) { if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->OnGameTitleListUpdated(list); currentDrcFrame->OnGameTitleListUpdated(list);
} }
} }
void MainWindow::OnGameTitleUpdated(gameInfo * info) { void MainWindow::OnGameTitleUpdated(gameInfo *info) {
currentTvFrame->OnGameTitleUpdated(info); currentTvFrame->OnGameTitleUpdated(info);
if(currentTvFrame != currentDrcFrame) { if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->OnGameTitleUpdated(info); currentDrcFrame->OnGameTitleUpdated(info);
} }
} }
void MainWindow::OnGameTitleAdded(gameInfo * info) { void MainWindow::OnGameTitleAdded(gameInfo *info) {
currentTvFrame->OnGameTitleAdded(info); currentTvFrame->OnGameTitleAdded(info);
if(currentTvFrame != currentDrcFrame) { if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->OnGameTitleAdded(info); currentDrcFrame->OnGameTitleAdded(info);
} }
} }
@ -150,16 +145,16 @@ void MainWindow::update(GuiController *controller) {
//! dont read behind the initial elements in case one was added //! dont read behind the initial elements in case one was added
//uint32_t tvSize = tvElements.size(); //uint32_t tvSize = tvElements.size();
if(controller->chan & GuiTrigger::CHANNEL_1) { if (controller->chan & GuiTrigger::CHANNEL_1) {
uint32_t drcSize = drcElements.size(); uint32_t drcSize = drcElements.size();
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) { for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
drcElements[i]->update(controller); drcElements[i]->update(controller);
} }
} else { } else {
uint32_t tvSize = tvElements.size(); uint32_t tvSize = tvElements.size();
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) { for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
tvElements[i]->update(controller); tvElements[i]->update(controller);
} }
} }
@ -179,7 +174,7 @@ void MainWindow::update(GuiController *controller) {
// } // }
// } // }
if(controller->chanIdx >= 1 && controller->chanIdx <= 4 && controller->data.validPointer) { if (controller->chanIdx >= 1 && controller->chanIdx <= 4 && controller->data.validPointer) {
int32_t wpadIdx = controller->chanIdx - 1; int32_t wpadIdx = controller->chanIdx - 1;
float posX = controller->data.x; float posX = controller->data.x;
float posY = controller->data.y; float posY = controller->data.y;
@ -190,41 +185,41 @@ void MainWindow::update(GuiController *controller) {
} }
void MainWindow::drawDrc(CVideo *video) { void MainWindow::drawDrc(CVideo *video) {
for(uint32_t i = 0; i < drcElements.size(); ++i) { for (uint32_t i = 0; i < drcElements.size(); ++i) {
drcElements[i]->draw(video); drcElements[i]->draw(video);
} }
for(int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
if(pointerValid[i]) { if (pointerValid[i]) {
pointerImg[i]->setAlpha(0.5f); pointerImg[i]->setAlpha(0.5f);
pointerImg[i]->draw(video); pointerImg[i]->draw(video);
pointerImg[i]->setAlpha(1.0f); pointerImg[i]->setAlpha(1.0f);
} }
} }
if(keyboardInstance != NULL) { if (keyboardInstance != nullptr) {
keyboardInstance->drawDRC(); keyboardInstance->drawDRC();
} }
} }
void MainWindow::drawTv(CVideo *video) { void MainWindow::drawTv(CVideo *video) {
for(uint32_t i = 0; i < tvElements.size(); ++i) { for (uint32_t i = 0; i < tvElements.size(); ++i) {
tvElements[i]->draw(video); tvElements[i]->draw(video);
} }
for(int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {
if(pointerValid[i]) { if (pointerValid[i]) {
pointerImg[i]->draw(video); pointerImg[i]->draw(video);
pointerValid[i] = false; pointerValid[i] = false;
} }
} }
if(keyboardInstance != NULL) { if (keyboardInstance != nullptr) {
keyboardInstance->drawTV(); keyboardInstance->drawTV();
} }
} }
void MainWindow::SetupMainView() { void MainWindow::SetupMainView() {
currentTvFrame = new GuiIconGrid(width, height,0, true); currentTvFrame = new GuiIconGrid(width, height, 0, true);
currentTvFrame->setEffect(EFFECT_FADE, 10, 255); currentTvFrame->setEffect(EFFECT_FADE, 10, 255);
currentTvFrame->setState(GuiElement::STATE_DISABLED); currentTvFrame->setState(GuiElement::STATE_DISABLED);
@ -232,12 +227,12 @@ void MainWindow::SetupMainView() {
appendTv(currentTvFrame); appendTv(currentTvFrame);
currentDrcFrame = new GuiIconGrid(width, height,0, false); currentDrcFrame = new GuiIconGrid(width, height, 0, false);
currentDrcFrame->setEffect(EFFECT_FADE, 10, 255); currentDrcFrame->setEffect(EFFECT_FADE, 10, 255);
currentDrcFrame->setState(GuiElement::STATE_DISABLED); currentDrcFrame->setState(GuiElement::STATE_DISABLED);
currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
if(currentTvFrame != currentDrcFrame) { if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->setEffect(EFFECT_FADE, 10, 255); currentDrcFrame->setEffect(EFFECT_FADE, 10, 255);
currentDrcFrame->setState(GuiElement::STATE_DISABLED); currentDrcFrame->setState(GuiElement::STATE_DISABLED);
currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
@ -250,7 +245,7 @@ void MainWindow::SetupMainView() {
currentDrcFrame->gameLaunchClicked.disconnect(this); currentDrcFrame->gameLaunchClicked.disconnect(this);
if(currentTvFrame != currentDrcFrame) { if (currentTvFrame != currentDrcFrame) {
currentTvFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange); currentTvFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange);
currentTvFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen); currentTvFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen);
} }
@ -272,11 +267,11 @@ void MainWindow::SetupMainView() {
} }
void MainWindow::OnLayoutSwitchClicked(GuiElement *element) { void MainWindow::OnLayoutSwitchClicked(GuiElement *element) {
if(!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) { if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) {
return; return;
} }
if(currentTvFrame == currentDrcFrame) { if (currentTvFrame == currentDrcFrame) {
return; return;
} }
@ -291,15 +286,15 @@ void MainWindow::OnLayoutSwitchClicked(GuiElement *element) {
} }
void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) { void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) {
if(!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) { if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) {
return; return;
} }
if(keyboardInstance == NULL) { if (keyboardInstance == nullptr) {
keyboardInstance = new KeyboardHelper(); keyboardInstance = new KeyboardHelper();
} }
if(keyboardInstance->isReady()) { if (keyboardInstance->isReady()) {
if(keyboardInstance->openKeyboard()) { if (keyboardInstance->openKeyboard()) {
currentTvFrame->setState(GuiElement::STATE_DISABLED); currentTvFrame->setState(GuiElement::STATE_DISABLED);
currentDrcFrame->setState(GuiElement::STATE_DISABLED); currentDrcFrame->setState(GuiElement::STATE_DISABLED);
mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED); mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED);
@ -308,7 +303,7 @@ void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) {
} }
void MainWindow::OnLayoutSwitchEffectFinish(GuiElement *element) { void MainWindow::OnLayoutSwitchEffectFinish(GuiElement *element) {
if(!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame)
return; return;
element->effectFinished.disconnect(this); element->effectFinished.disconnect(this);
@ -361,12 +356,12 @@ void MainWindow::OnSettingsButtonClicked(GuiElement *element) {
} }
void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t selectedIdx) { void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t selectedIdx) {
if(!currentDrcFrame || !currentTvFrame) if (!currentDrcFrame || !currentTvFrame)
return; return;
if(element == currentDrcFrame && currentDrcFrame != currentTvFrame) { if (element == currentDrcFrame && currentDrcFrame != currentTvFrame) {
currentTvFrame->setSelectedGame(selectedIdx); currentTvFrame->setSelectedGame(selectedIdx);
} else if(element == currentTvFrame && currentDrcFrame != currentTvFrame) { } else if (element == currentTvFrame && currentDrcFrame != currentTvFrame) {
currentDrcFrame->setSelectedGame(selectedIdx); currentDrcFrame->setSelectedGame(selectedIdx);
} }
} }
@ -376,11 +371,11 @@ void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t select
#define MII_MAKER_USA_TITLE_ID (0x000500101004A100) #define MII_MAKER_USA_TITLE_ID (0x000500101004A100)
#define MII_MAKER_EUR_TITLE_ID (0x000500101004A200) #define MII_MAKER_EUR_TITLE_ID (0x000500101004A200)
extern "C" void _SYSLaunchTitleByPathFromLauncher(const char * path, int len, int); extern "C" void _SYSLaunchTitleByPathFromLauncher(const char *path, int len, int);
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 ||
@ -388,14 +383,14 @@ void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser * element, uint64_t ti
ownTitleId == MII_MAKER_EUR_TITLE_ID) { ownTitleId == MII_MAKER_EUR_TITLE_ID) {
OnGameLaunch(titleID); OnGameLaunch(titleID);
} else { } else {
GameSplashScreen * gameSettingsDRC = new GameSplashScreen(width,height,info, false); GameSplashScreen *gameSettingsDRC = new GameSplashScreen(width, height, info, false);
gameSettingsDRC->setEffect(EFFECT_FADE, 15, 255); gameSettingsDRC->setEffect(EFFECT_FADE, 15, 255);
gameSettingsDRC->setState(GuiElement::STATE_DISABLED); gameSettingsDRC->setState(GuiElement::STATE_DISABLED);
gameSettingsDRC->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); gameSettingsDRC->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
gameSettingsDRC->gameGameSplashScreenFinished.connect(this, &MainWindow::OnGameLaunchSplashScreenFinished); gameSettingsDRC->gameGameSplashScreenFinished.connect(this, &MainWindow::OnGameLaunchSplashScreenFinished);
appendDrc(gameSettingsDRC); appendDrc(gameSettingsDRC);
GameSplashScreen * gameSettingsTV = new GameSplashScreen(width,height,info, true); GameSplashScreen *gameSettingsTV = new GameSplashScreen(width, height, info, true);
gameSettingsTV->setEffect(EFFECT_FADE, 15, 255); gameSettingsTV->setEffect(EFFECT_FADE, 15, 255);
gameSettingsTV->setState(GuiElement::STATE_DISABLED); gameSettingsTV->setState(GuiElement::STATE_DISABLED);
gameSettingsTV->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish); gameSettingsTV->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
@ -407,22 +402,23 @@ 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) {
OnGameLaunch(info->titleId); OnGameLaunch(info->titleId);
} }
if(element) { if (element) {
element->setState(GuiElement::STATE_DISABLED); element->setState(GuiElement::STATE_DISABLED);
element->setEffect(EFFECT_FADE, 15, 255); element->setEffect(EFFECT_FADE, 15, 255);
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 ||
@ -430,8 +426,8 @@ void MainWindow::OnGameLaunch(uint64_t titleID) {
titleID == MII_MAKER_EUR_TITLE_ID) { titleID == MII_MAKER_EUR_TITLE_ID) {
SYSLaunchTitle(info->titleId); SYSLaunchTitle(info->titleId);
} else { } else {
const char* path = info->gamePath.c_str(); const char *path = info->gamePath.c_str();
_SYSLaunchTitleByPathFromLauncher(path, strlen(path),0); _SYSLaunchTitleByPathFromLauncher(path, strlen(path), 0);
} }
} else { } else {
DEBUG_FUNCTION_LINE("Failed to find gameInfo for titleId %016llX\n", titleID); DEBUG_FUNCTION_LINE("Failed to find gameInfo for titleId %016llX\n", titleID);

View File

@ -30,17 +30,19 @@ 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) {
if(!e) if (!e)
return; return;
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;
removeDrc(e); removeDrc(e);
@ -53,14 +55,15 @@ public:
} }
void insertTv(uint32_t pos, GuiElement *e) { void insertTv(uint32_t pos, GuiElement *e) {
if(!e) if (!e)
return; return;
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;
removeDrc(e); removeDrc(e);
@ -73,16 +76,17 @@ public:
} }
void removeTv(GuiElement *e) { void removeTv(GuiElement *e) {
for(uint32_t i = 0; i < tvElements.size(); ++i) { for (uint32_t i = 0; i < tvElements.size(); ++i) {
if(e == tvElements[i]) { if (e == tvElements[i]) {
tvElements.erase(tvElements.begin() + i); tvElements.erase(tvElements.begin() + i);
break; break;
} }
} }
} }
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]) {
drcElements.erase(drcElements.begin() + i); drcElements.erase(drcElements.begin() + i);
break; break;
} }
@ -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,22 +125,30 @@ 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 OnGameTitleAdded(gameInfo * info); void OnGameTitleUpdated(gameInfo *info);
void OnGameTitleAdded(gameInfo *info);
int32_t width, height; int32_t width, height;
std::vector<GuiElement *> drcElements; std::vector<GuiElement *> drcElements;
@ -140,8 +158,8 @@ private:
MainDrcButtonsFrame *mainSwitchButtonFrame; MainDrcButtonsFrame *mainSwitchButtonFrame;
GuiTitleBrowser * currentTvFrame; GuiTitleBrowser *currentTvFrame;
GuiTitleBrowser * currentDrcFrame; GuiTitleBrowser *currentDrcFrame;
GuiImageData *pointerImgData[4]; GuiImageData *pointerImgData[4];
GuiImage *pointerImg[4]; GuiImage *pointerImg[4];
@ -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,38 +15,38 @@
#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)
RecourceList[i].CustomFileSize = 0; RecourceList[i].CustomFileSize = 0;
} }
if(instance) if (instance)
delete instance; delete instance;
instance = NULL; instance = nullptr;
} }
bool Resources::LoadFiles(const char * path) { bool Resources::LoadFiles(const char *path) {
if(!path) if (!path)
return false; return false;
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);
@ -59,44 +59,44 @@ bool Resources::LoadFiles(const char * path) {
return result; return result;
} }
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);
} }
} }
return 0; return 0;
} }
GuiImageData * Resources::GetImageData(const char * filename) { GuiImageData *Resources::GetImageData(const char *filename) {
if(!instance) if (!instance)
instance = new Resources; instance = new Resources;
std::map<std::string, std::pair<uint32_t, GuiImageData *> >::iterator itr = instance->imageDataMap.find(std::string(filename)); std::map<std::string, std::pair<uint32_t, GuiImageData *> >::iterator itr = instance->imageDataMap.find(std::string(filename));
if(itr != instance->imageDataMap.end()) { if (itr != instance->imageDataMap.end()) {
itr->second.first++; itr->second.first++;
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;
instance->imageDataMap[std::string(filename)].second = image; instance->imageDataMap[std::string(filename)].second = image;
@ -104,17 +104,17 @@ GuiImageData * Resources::GetImageData(const char * filename) {
} }
} }
return NULL; return nullptr;
} }
void Resources::RemoveImageData(GuiImageData * image) { void Resources::RemoveImageData(GuiImageData *image) {
std::map<std::string, std::pair<uint32_t, GuiImageData *> >::iterator itr; std::map<std::string, std::pair<uint32_t, GuiImageData *> >::iterator itr;
for(itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) { for (itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) {
if(itr->second.second == image) { if (itr->second.second == image) {
itr->second.first--; itr->second.first--;
if(itr->second.first == 0) { if (itr->second.first == 0) {
AsyncExecutor::pushForDelete(itr->second.second); AsyncExecutor::pushForDelete(itr->second.second);
instance->imageDataMap.erase(itr); instance->imageDataMap.erase(itr);
@ -124,25 +124,25 @@ void Resources::RemoveImageData(GuiImageData * image) {
} }
} }
GuiSound * Resources::GetSound(const char * filename) { GuiSound *Resources::GetSound(const char *filename) {
if(!instance) if (!instance)
instance = new Resources; instance = new Resources;
std::map<std::string, std::pair<uint32_t, GuiSound *> >::iterator itr = instance->soundDataMap.find(std::string(filename)); std::map<std::string, std::pair<uint32_t, GuiSound *> >::iterator itr = instance->soundDataMap.find(std::string(filename));
if(itr != instance->soundDataMap.end()) { if (itr != instance->soundDataMap.end()) {
itr->second.first++; itr->second.first++;
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;
instance->soundDataMap[std::string(filename)].second = sound; instance->soundDataMap[std::string(filename)].second = sound;
@ -150,17 +150,17 @@ GuiSound * Resources::GetSound(const char * filename) {
} }
} }
return NULL; return nullptr;
} }
void Resources::RemoveSound(GuiSound * sound) { void Resources::RemoveSound(GuiSound *sound) {
std::map<std::string, std::pair<uint32_t, GuiSound *> >::iterator itr; std::map<std::string, std::pair<uint32_t, GuiSound *> >::iterator itr;
for(itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) { for (itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) {
if(itr->second.second == sound) { if (itr->second.second == sound) {
itr->second.first--; itr->second.first--;
if(itr->second.first == 0) { if (itr->second.first == 0) {
AsyncExecutor::pushForDelete(itr->second.second); AsyncExecutor::pushForDelete(itr->second.second);
instance->soundDataMap.erase(itr); instance->soundDataMap.erase(itr);
} }

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 const uint8_t * GetFile(const char * filename);
static uint32_t GetFileSize(const char * filename);
static GuiImageData * GetImageData(const char * filename); static bool LoadFiles(const char *path);
static void RemoveImageData(GuiImageData * image);
static const uint8_t *GetFile(const char *filename);
static uint32_t GetFileSize(const char *filename);
static GuiImageData *GetImageData(const char *filename);
static void RemoveImageData(GuiImageData *image);
static GuiSound *GetSound(const char *filename);
static void RemoveSound(GuiSound *sound);
static GuiSound * GetSound(const char * filename);
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,16 +1,17 @@
#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) {
mutex.lock(); mutex.lock();
bool emptyList = elements.empty(); bool emptyList = elements.empty();
auto it = elements.begin(); auto it = elements.begin();
@ -23,37 +24,37 @@ AsyncExecutor::AsyncExecutor() {
++it; ++it;
} }
} }
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();
while(!deleteList.empty()) { while (!deleteList.empty()) {
GuiElement * ptr = deleteList.front(); GuiElement *ptr = deleteList.front();
deleteList.pop(); deleteList.pop();
delete ptr; delete ptr;
} }
deleteListMutex.unlock(); deleteListMutex.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(16)); std::this_thread::sleep_for(std::chrono::milliseconds(16));
DCFlushRange((void*)&exitThread, sizeof(exitThread)); DCFlushRange((void *) &exitThread, sizeof(exitThread));
} }
}); });
} }
AsyncExecutor::~AsyncExecutor() { AsyncExecutor::~AsyncExecutor() {
exitThread = true; exitThread = true;
DCFlushRange((void*)&exitThread, sizeof(exitThread)); DCFlushRange((void *) &exitThread, sizeof(exitThread));
thread->join(); thread->join();
} }
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

@ -10,23 +10,24 @@
class AsyncExecutor { class AsyncExecutor {
public: public:
static void pushForDelete(GuiElement * element) { static void pushForDelete(GuiElement *element) {
if(!instance) { if (!instance) {
instance = new AsyncExecutor(); instance = new AsyncExecutor();
} }
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();
} }
instance->executeInternal(func); instance->executeInternal(func);
} }
static void destroyInstance() { static void destroyInstance() {
if(instance) { if (instance) {
delete instance; delete instance;
instance = NULL; instance = nullptr;
} }
} }
@ -34,17 +35,19 @@ 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;
std::thread * thread; std::thread *thread;
volatile bool exitThread = false; volatile bool exitThread = false;
std::vector<std::future<void>> elements; std::vector<std::future<void>> elements;
std::recursive_mutex deleteListMutex; std::recursive_mutex deleteListMutex;
std::queue<GuiElement*> deleteList; std::queue<GuiElement *> deleteList;
}; };

View File

@ -36,13 +36,13 @@
#include <utils/StringTools.h> #include <utils/StringTools.h>
BOOL StringTools::EndsWith(const std::string& a, const std::string& b) { BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
if (b.size() > a.size()) if (b.size() > a.size())
return false; return false;
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
} }
const char * StringTools::byte_to_binary(int32_t x) { const char *StringTools::byte_to_binary(int32_t x) {
static char b[9]; static char b[9];
b[0] = '\0'; b[0] = '\0';
@ -54,70 +54,70 @@ const char * StringTools::byte_to_binary(int32_t x) {
return b; return b;
} }
std::string StringTools::removeCharFromString(std::string& input,char toBeRemoved) { std::string StringTools::removeCharFromString(std::string &input, char toBeRemoved) {
std::string output = input; std::string output = input;
size_t position; size_t position;
while(1) { while (1) {
position = output.find(toBeRemoved); position = output.find(toBeRemoved);
if(position == std::string::npos) if (position == std::string::npos)
break; break;
output.erase(position, 1); output.erase(position, 1);
} }
return output; return output;
} }
const char * StringTools::fmt(const char * format, ...) { const char *StringTools::fmt(const char *format, ...) {
static char strChar[512]; static char strChar[512];
strChar[0] = 0; strChar[0] = 0;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsprintf(strChar, format, va) >= 0)) { if ((vsprintf(strChar, format, va) >= 0)) {
va_end(va); va_end(va);
return (const char *) strChar; return (const char *) strChar;
} }
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, ...) {
static char tmp[512]; static char tmp[512];
static wchar_t strWChar[512]; static wchar_t strWChar[512];
strWChar[0] = 0; strWChar[0] = 0;
tmp[0] = 0; tmp[0] = 0;
if(!format) if (!format)
return (const wchar_t *) strWChar; return (const wchar_t *) strWChar;
if(strcmp(format, "") == 0) if (strcmp(format, "") == 0)
return (const wchar_t *) strWChar; return (const wchar_t *) strWChar;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
int32_t bt; int32_t bt;
int32_t strlength = strlen(tmp); int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 ); bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
if(bt > 0) { if (bt > 0) {
strWChar[bt] = 0; strWChar[bt] = 0;
return (const wchar_t *) strWChar; return (const wchar_t *) strWChar;
} }
} }
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, ...) {
static char tmp[512]; static char tmp[512];
tmp[0] = 0; tmp[0] = 0;
int32_t result = 0; int32_t result = 0;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp; str = tmp;
result = str.size(); result = str.size();
} }
@ -126,14 +126,14 @@ int32_t StringTools::strprintf(std::string &str, const char * format, ...) {
return result; return result;
} }
std::string StringTools::strfmt(const char * format, ...) { std::string StringTools::strfmt(const char *format, ...) {
std::string str; std::string str;
static char tmp[512]; static char tmp[512];
tmp[0] = 0; tmp[0] = 0;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp; str = tmp;
} }
va_end(va); va_end(va);
@ -141,8 +141,8 @@ std::string StringTools::strfmt(const char * format, ...) {
return str; return str;
} }
BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) { BOOL StringTools::char2wchar_t(const char *strChar, wchar_t *dest) {
if(!strChar || !dest) if (!strChar || !dest)
return false; return false;
int32_t bt; int32_t bt;
@ -155,39 +155,39 @@ BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
return false; return false;
} }
int32_t StringTools::strtokcmp(const char * string, const char * compare, const char * separator) { int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) {
if(!string || !compare) if (!string || !compare)
return -1; return -1;
char TokCopy[512]; char TokCopy[512];
strncpy(TokCopy, compare, sizeof(TokCopy)); strncpy(TokCopy, compare, sizeof(TokCopy));
TokCopy[511] = '\0'; TokCopy[511] = '\0';
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;
} }
int32_t StringTools::strextcmp(const char * string, const char * extension, char seperator) { int32_t StringTools::strextcmp(const char *string, const char *extension, char seperator) {
if(!string || !extension) if (!string || !extension)
return -1; return -1;
char *ptr = strrchr(string, seperator); char *ptr = strrchr(string, seperator);
if(!ptr) if (!ptr)
return -1; return -1;
return strcasecmp(ptr + 1, extension); return strcasecmp(ptr + 1, extension);
} }
std::vector<std::string> StringTools::stringSplit(const std::string & inValue, const std::string & splitter) { std::vector<std::string> StringTools::stringSplit(const std::string &inValue, const std::string &splitter) {
std::string value = inValue; std::string value = inValue;
std::vector<std::string> result; std::vector<std::string> result;
while (true) { while (true) {
@ -202,7 +202,7 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
result.push_back(""); result.push_back("");
break; break;
} }
if(index + splitter.size() > value.length()) { if (index + splitter.size() > value.length()) {
break; break;
} }
value = value.substr(index + splitter.size(), value.length()); value = value.substr(index + splitter.size(), value.length());
@ -210,12 +210,11 @@ 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(),
[](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); } [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }
); );
return (it != strHaystack.end() ); return (it != strHaystack.end());
} }

View File

@ -34,27 +34,36 @@
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 std::string removeCharFromString(std::string& input,char toBeRemoved);
static const char * fmt(const char * format, ...);
static const wchar_t * wfmt(const char * format, ...);
static int32_t strprintf(std::string &str, const char * format, ...);
static std::string strfmt(const char * format, ...);
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 strextcmp(const char * string, const char * extension, char seperator);
static const char * FullpathToFilename(const char *path) { static const char *byte_to_binary(int32_t x);
if(!path)
static std::string removeCharFromString(std::string &input, char toBeRemoved);
static const char *fmt(const char *format, ...);
static const wchar_t *wfmt(const char *format, ...);
static int32_t strprintf(std::string &str, const char *format, ...);
static std::string strfmt(const char *format, ...);
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 strextcmp(const char *string, const char *extension, char seperator);
static const char *FullpathToFilename(const char *path) {
if (!path)
return path; return path;
const char * ptr = path; const char *ptr = path;
const char * Filename = ptr; const char *Filename = ptr;
while(*ptr != '\0') { while (*ptr != '\0') {
if(ptr[0] == '/' && ptr[1] != '\0') if (ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr+1; Filename = ptr + 1;
++ptr; ++ptr;
} }
@ -66,8 +75,8 @@ public:
uint32_t length = str.size(); uint32_t length = str.size();
//! clear path of double slashes //! clear path of double slashes
for(uint32_t i = 1; i < length; ++i) { for (uint32_t i = 1; i < length; ++i) {
if(str[i-1] == '/' && str[i] == '/') { if (str[i - 1] == '/' && str[i] == '/') {
str.erase(i, 1); str.erase(i, 1);
i--; i--;
length--; length--;
@ -75,10 +84,10 @@ public:
} }
} }
static std::vector<std::string> stringSplit(const std::string & value, const std::string & splitter); static std::vector<std::string> stringSplit(const std::string &value, const std::string &splitter);
// https://stackoverflow.com/a/19839371 // https://stackoverflow.com/a/19839371
static bool findStringIC(const std::string & strHaystack, const std::string & strNeedle); static bool findStringIC(const std::string &strHaystack, const std::string &strNeedle);
}; };
#endif /* __STRING_TOOLS_H */ #endif /* __STRING_TOOLS_H */

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

@ -7,34 +7,34 @@
#include <utils/logger.h> #include <utils/logger.h>
// https://gist.github.com/ccbrown/9722406 // https://gist.github.com/ccbrown/9722406
void dumpHex(const void* data, size_t size) { 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);
} }
} }
} }

View File

@ -26,7 +26,7 @@ extern "C" {
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) #define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
//Needs to have log_init() called beforehand. //Needs to have log_init() called beforehand.
void dumpHex(const void* data, size_t size); void dumpHex(const void *data, size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }