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
# INCLUDES is a list of directories containing header files
#-------------------------------------------------------------------------------
TARGET := launchiine
TARGET := men
BUILD := build
SOURCES := src \
src/fs \

View File

@ -31,22 +31,12 @@
#include "utils/AsyncExecutor.h"
#include <thread>
#define HBL_TITLE_ID (0x0005000013374842)
#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;
Application *Application::applicationInstance = nullptr;
bool Application::exitApplication = false;
bool Application::quitRequest = false;
Application::Application()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000)
, bgMusic(NULL)
, video(NULL)
, mainWindow(NULL)
, fontSystem(NULL)
, exitCode(0) {
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x800000), bgMusic(nullptr), video(nullptr), mainWindow(nullptr), fontSystem(nullptr), exitCode(0) {
controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
@ -59,43 +49,30 @@ Application::Application()
bgMusic->Play();
bgMusic->SetVolume(50);
AsyncExecutor::execute([] {DEBUG_FUNCTION_LINE("Hello\n");});
AsyncExecutor::execute([] { DEBUG_FUNCTION_LINE("Hello"); });
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);
}
Application::~Application() {
DEBUG_FUNCTION_LINE("Destroy music\n");
DEBUG_FUNCTION_LINE("Destroy music");
delete bgMusic;
DEBUG_FUNCTION_LINE("Destroy controller\n");
DEBUG_FUNCTION_LINE("Destroy controller");
for(int32_t i = 0; i < 5; i++)
delete controller[i];
for (auto &i: controller) {
delete i;
}
DEBUG_FUNCTION_LINE("Clear resources\n");
DEBUG_FUNCTION_LINE("Clear resources");
Resources::Clear();
DEBUG_FUNCTION_LINE("Stop sound handler\n");
DEBUG_FUNCTION_LINE("Stop sound handler");
SoundHandler::DestroyInstance();
DEBUG_FUNCTION_LINE("Clear AsyncExecutor\n");
DEBUG_FUNCTION_LINE("Clear AsyncExecutor");
AsyncExecutor::destroyInstance();
ProcUIShutdown();
@ -118,11 +95,11 @@ void Application::quit(int32_t code) {
void Application::fadeOut() {
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) {
0, 0, 0, 255
0, 0, 0, 255
});
for(int32_t i = 0; i < 255; i += 10) {
if(i > 255)
for (int32_t i = 0; i < 255; i += 10) {
if (i > 255)
i = 255;
fadeOut.setAlpha(i / 255.0f);
@ -155,79 +132,79 @@ void Application::fadeOut() {
}
}
bool Application::procUI(void) {
bool Application::procUI() {
bool executeProcess = false;
switch(ProcUIProcessMessages(true)) {
case PROCUI_STATUS_EXITING: {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING\n");
exitCode = EXIT_SUCCESS;
exitApplication = true;
break;
}
case PROCUI_STATUS_RELEASE_FOREGROUND: {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND\n");
if(video != NULL) {
// we can turn ofF the screen but we don't need to and it will display the last image
video->tvEnable(true);
video->drcEnable(true);
DEBUG_FUNCTION_LINE("delete fontSystem\n");
delete fontSystem;
fontSystem = NULL;
DEBUG_FUNCTION_LINE("delete video\n");
delete video;
video = NULL;
DEBUG_FUNCTION_LINE("deinitialze memory\n");
libgui_memoryRelease();
ProcUIDrawDoneRelease();
} else {
ProcUIDrawDoneRelease();
switch (ProcUIProcessMessages(true)) {
case PROCUI_STATUS_EXITING: {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING");
exitCode = EXIT_SUCCESS;
exitApplication = true;
break;
}
break;
}
case PROCUI_STATUS_IN_FOREGROUND: {
if(!quitRequest) {
if(video == NULL) {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND\n");
DEBUG_FUNCTION_LINE("initialze memory\n");
libgui_memoryInitialize();
case PROCUI_STATUS_RELEASE_FOREGROUND: {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND");
if (video != nullptr) {
// we can turn ofF the screen but we don't need to and it will display the last image
video->tvEnable(true);
video->drcEnable(true);
DEBUG_FUNCTION_LINE("Initialize video\n");
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("delete fontSystem");
delete fontSystem;
fontSystem = nullptr;
//! setup default Font
DEBUG_FUNCTION_LINE("Initialize main font system\n");
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem);
if(mainWindow == NULL) {
DEBUG_FUNCTION_LINE("Initialize main window\n");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
}
DEBUG_FUNCTION_LINE("delete video");
delete video;
video = nullptr;
DEBUG_FUNCTION_LINE("deinitialze memory");
libgui_memoryRelease();
ProcUIDrawDoneRelease();
} else {
ProcUIDrawDoneRelease();
}
executeProcess = true;
break;
}
break;
}
case PROCUI_STATUS_IN_BACKGROUND:
default:
break;
case PROCUI_STATUS_IN_FOREGROUND: {
if (!quitRequest) {
if (video == nullptr) {
DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND");
DEBUG_FUNCTION_LINE("initialze memory");
libgui_memoryInitialize();
DEBUG_FUNCTION_LINE("Initialize video");
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE);
DEBUG_FUNCTION_LINE("Video size %i x %i", video->getTvWidth(), video->getTvHeight());
//! setup default Font
DEBUG_FUNCTION_LINE("Initialize main font system");
auto *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem);
if (mainWindow == nullptr) {
DEBUG_FUNCTION_LINE("Initialize main window");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
}
}
executeProcess = true;
}
break;
}
case PROCUI_STATUS_IN_BACKGROUND:
default:
break;
}
return executeProcess;
}
void Application::executeThread(void) {
DEBUG_FUNCTION_LINE("Entering main loop\n");
void Application::executeThread() {
DEBUG_FUNCTION_LINE("Entering main loop");
//! main GX2 loop (60 Hz cycle with max priority on core 1)
while(!exitApplication) {
if(procUI() == false) {
while (!exitApplication) {
if (!procUI()) {
continue;
}
@ -235,20 +212,12 @@ void Application::executeThread(void) {
mainWindow->process();
//! Read out inputs
for(int32_t i = 0; i < 5; i++) {
if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
for (auto &i: controller) {
if (!i->update(video->getTvWidth(), video->getTvHeight()))
continue;
//! update controller states
mainWindow->update(controller[i]);
if(controller[i]->data.buttons_d & VPAD_BUTTON_HOME) {
if (sFromHBL) {
fadeOut();
SYSRelaunchTitle(0, NULL);
continue;
}
}
mainWindow->update(i);
}
//! start rendering DRC
@ -262,7 +231,7 @@ void Application::executeThread(void) {
video->tvDrawDone();
//! enable screen after first frame render
if(video->getFrameCount() == 0) {
if (video->getFrameCount() == 0) {
video->tvEnable(true);
video->drcEnable(true);
}
@ -274,33 +243,22 @@ void Application::executeThread(void) {
video->waitForVSync();
}
if(bgMusic) {
if (bgMusic) {
bgMusic->SetVolume(0);
}
//! in case we exit to a homebrew let's smoothly fade out
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");
DEBUG_FUNCTION_LINE("delete mainWindow");
delete mainWindow;
mainWindow = NULL;
mainWindow = nullptr;
DEBUG_FUNCTION_LINE("delete fontSystem\n");
DEBUG_FUNCTION_LINE("delete fontSystem");
delete fontSystem;
fontSystem = NULL;
fontSystem = nullptr;
DEBUG_FUNCTION_LINE("delete video\n");
DEBUG_FUNCTION_LINE("delete video");
delete video;
video = NULL;
video = nullptr;
DEBUG_FUNCTION_LINE("deinitialize memory\n");
DEBUG_FUNCTION_LINE("deinitialize memory");
libgui_memoryRelease();
}

View File

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

View File

@ -1,5 +1,5 @@
#ifndef COMMON_H
#define COMMON_H
#define COMMON_H
#ifdef __cplusplus
extern "C" {
@ -12,5 +12,5 @@ extern "C" {
}
#endif
#endif /* COMMON_H */
#endif /* COMMON_H */

View File

@ -1,20 +1,39 @@
#include <string.h>
#include <nsysnet/socket.h>
#include "utils/logger.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"
int32_t main(int32_t argc, char **argv) {
socket_lib_init();
log_init();
DEBUG_FUNCTION_LINE("Starting launchiine " LAUNCHIINE_VERSION "\n");
bool moduleInit;
bool cafeInit = false;
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();
DEBUG_FUNCTION_LINE("Main application stopped\n");
DEBUG_FUNCTION_LINE("Main application stopped");
Application::destroyInstance();
DEBUG_FUNCTION_LINE("Peace out...\n");
DEBUG_FUNCTION_LINE("Peace out...");
if (cafeInit) {
WHBLogCafeDeinit();
}
if (udpInit) {
WHBLogUdpDeinit();
}
if (moduleInit) {
WHBLogModuleDeinit();
}
return 0;
}

View File

@ -7,17 +7,17 @@
CFile::CFile() {
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
CFile::CFile(const std::string & filepath, eOpenTypes mode) {
CFile::CFile(const std::string &filepath, eOpenTypes mode) {
iFd = -1;
this->open(filepath, mode);
}
CFile::CFile(const uint8_t * mem, int32_t size) {
CFile::CFile(const uint8_t *mem, int32_t size) {
iFd = -1;
this->open(mem, size);
}
@ -26,27 +26,27 @@ CFile::~CFile() {
this->close();
}
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
this->close();
int32_t openMode = 0;
// This depend on the devoptab implementation.
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
switch(mode) {
default:
case ReadOnly: // file must exist
openMode = O_RDONLY;
break;
case WriteOnly: // file will be created / zerod
openMode = O_TRUNC | O_CREAT | O_WRONLY;
break;
case ReadWrite: // file must exist
openMode = O_RDWR;
break;
case Append: // append to file, file will be created if missing. write only
openMode = O_CREAT | O_APPEND | O_WRONLY;
break;
switch (mode) {
default:
case ReadOnly: // file must exist
openMode = O_RDONLY;
break;
case WriteOnly: // file will be created / zerod
openMode = O_TRUNC | O_CREAT | O_WRONLY;
break;
case ReadWrite: // file must exist
openMode = O_RDWR;
break;
case Append: // append to file, file will be created if missing. write only
openMode = O_CREAT | O_APPEND | O_WRONLY;
break;
}
//! Using fopen works only on the first launch as expected
@ -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
//! this will be added with launching as RPX
iFd = ::open(filepath.c_str(), openMode);
if(iFd < 0)
if (iFd < 0)
return iFd;
@ -64,7 +64,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
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();
mem_file = mem;
@ -74,33 +74,33 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) {
}
void CFile::close() {
if(iFd >= 0)
if (iFd >= 0)
::close(iFd);
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
int32_t CFile::read(uint8_t * ptr, size_t size) {
if(iFd >= 0) {
int32_t ret = ::read(iFd, ptr,size);
if(ret > 0)
int32_t CFile::read(uint8_t *ptr, size_t size) {
if (iFd >= 0) {
int32_t ret = ::read(iFd, ptr, size);
if (ret > 0)
pos += ret;
return ret;
}
int32_t readsize = size;
if(readsize > (int64_t) (filesize-pos))
readsize = filesize-pos;
if (readsize > (int64_t) (filesize - pos))
readsize = filesize - pos;
if(readsize <= 0)
if (readsize <= 0)
return readsize;
if(mem_file != NULL) {
memcpy(ptr, mem_file+pos, readsize);
if (mem_file != nullptr) {
memcpy(ptr, mem_file + pos, readsize);
pos += readsize;
return readsize;
}
@ -108,12 +108,12 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
return -1;
}
int32_t CFile::write(const uint8_t * ptr, size_t size) {
if(iFd >= 0) {
int32_t CFile::write(const uint8_t *ptr, size_t size) {
if (iFd >= 0) {
size_t done = 0;
while(done < size) {
while (done < size) {
int32_t ret = ::write(iFd, ptr, size - done);
if(ret <= 0)
if (ret <= 0)
return ret;
ptr += ret;
@ -130,25 +130,25 @@ int32_t CFile::seek(long int offset, int32_t origin) {
int32_t ret = 0;
int64_t newPos = pos;
if(origin == SEEK_SET) {
if (origin == SEEK_SET) {
newPos = offset;
} else if(origin == SEEK_CUR) {
} else if (origin == SEEK_CUR) {
newPos += offset;
} else if(origin == SEEK_END) {
newPos = filesize+offset;
} else if (origin == SEEK_END) {
newPos = filesize + offset;
}
if(newPos < 0) {
if (newPos < 0) {
pos = 0;
} else {
pos = newPos;
}
if(iFd >= 0)
if (iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET);
if(mem_file != NULL) {
if(pos > filesize) {
if (mem_file != nullptr) {
if (pos > filesize) {
pos = filesize;
}
}
@ -163,8 +163,8 @@ int32_t CFile::fwrite(const char *format, ...) {
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
result = this->write((uint8_t *)tmp, strlen(tmp));
if ((vsprintf(tmp, format, va) >= 0)) {
result = this->write((uint8_t *) tmp, strlen(tmp));
}
va_end(va);

View File

@ -18,18 +18,22 @@ public:
};
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();
int32_t open(const std::string & filepath, eOpenTypes mode);
int32_t open(const uint8_t * memory, int32_t memsize);
int32_t open(const std::string &filepath, eOpenTypes mode);
int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const {
if(iFd >= 0)
if (iFd >= 0)
return true;
if(mem_file)
if (mem_file)
return true;
return false;
@ -37,23 +41,29 @@ public:
void close();
int32_t read(uint8_t * ptr, size_t size);
int32_t write(const 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 fwrite(const char *format, ...);
int32_t seek(long int offset, int32_t origin);
uint64_t tell() {
return pos;
};
uint64_t size() {
return filesize;
};
void rewind() {
this->seek(0, SEEK_SET);
};
protected:
int32_t iFd;
const uint8_t * mem_file;
const uint8_t *mem_file;
uint64_t filesize;
uint64_t pos;
};

View File

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

View File

@ -32,7 +32,7 @@
#include <wut_types.h>
typedef struct {
char * FilePath;
char *FilePath;
BOOL isDir;
} DirEntry;
@ -40,17 +40,22 @@ class DirList {
public:
//!Constructor
DirList(void);
//!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered
//!\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
virtual ~DirList();
//! 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
//!\param list index
const char * GetFilename(int32_t index) const;
const char *GetFilename(int32_t index) const;
//! Get the a filepath of the list
//!\param list index
const char *GetFilepath(int32_t index) const {
@ -59,26 +64,33 @@ public:
else
return FileInfo[index].FilePath;
}
//! Get the a filesize of the list
//!\param list index
uint64_t GetFilesize(int32_t index) const;
//! Is index a dir or a file
//!\param list index
BOOL IsDir(int32_t index) const {
if(!valid(index))
if (!valid(index))
return false;
return FileInfo[index].isDir;
};
//! Get the filecount of the whole list
int32_t GetFilecount() const {
return FileInfo.size();
};
//! Sort list by filepath
void SortList();
//! Custom sort command for custom sort functions definitions
void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b));
//! Get the index of the specified filename
int32_t GetFileIndex(const char *filename) const;
//! Enum for search/filter flags
enum {
Files = 0x01,
@ -88,10 +100,13 @@ public:
protected:
// Internal parser
BOOL InternalLoadPath(std::string &path);
//!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
void ClearList();
//! Check if valid pos is requested
inline BOOL valid(uint32_t pos) const {
return (pos < FileInfo.size());

View File

@ -9,8 +9,8 @@
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input
*inbuffer = NULL;
if(size)
*inbuffer = nullptr;
if (size)
*size = 0;
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);
uint8_t *buffer = (uint8_t *) malloc(filesize);
if (buffer == NULL) {
if (buffer == nullptr) {
close(iFd);
return -2;
}
@ -30,12 +30,12 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
uint32_t done = 0;
int32_t readBytes = 0;
while(done < filesize) {
if(done + blocksize > filesize) {
while (done < filesize) {
if (done + blocksize > filesize) {
blocksize = filesize - done;
}
readBytes = read(iFd, buffer + done, blocksize);
if(readBytes <= 0)
if (readBytes <= 0)
break;
done += readBytes;
}
@ -44,34 +44,34 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
if (done != filesize) {
free(buffer);
buffer = NULL;
buffer = nullptr;
return -3;
}
*inbuffer = buffer;
//! sign is optional input
if(size) {
if (size) {
*size = filesize;
}
return filesize;
}
int32_t FSUtils::CheckFile(const char * filepath) {
if(!filepath)
int32_t FSUtils::CheckFile(const char *filepath) {
if (!filepath)
return 0;
struct stat filestat;
char dirnoslash[strlen(filepath)+2];
char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
while(dirnoslash[strlen(dirnoslash)-1] == '/')
dirnoslash[strlen(dirnoslash)-1] = '\0';
while (dirnoslash[strlen(dirnoslash) - 1] == '/')
dirnoslash[strlen(dirnoslash) - 1] = '\0';
char * notRoot = strrchr(dirnoslash, '/');
if(!notRoot) {
char *notRoot = strrchr(dirnoslash, '/');
if (!notRoot) {
strcat(dirnoslash, "/");
}
@ -81,29 +81,29 @@ int32_t FSUtils::CheckFile(const char * filepath) {
return 0;
}
int32_t FSUtils::CreateSubfolder(const char * fullpath) {
if(!fullpath)
int32_t FSUtils::CreateSubfolder(const char *fullpath) {
if (!fullpath)
return 0;
int32_t result = 0;
char dirnoslash[strlen(fullpath)+1];
char dirnoslash[strlen(fullpath) + 1];
strcpy(dirnoslash, fullpath);
int32_t pos = strlen(dirnoslash)-1;
while(dirnoslash[pos] == '/') {
int32_t pos = strlen(dirnoslash) - 1;
while (dirnoslash[pos] == '/') {
dirnoslash[pos] = '\0';
pos--;
}
if(CheckFile(dirnoslash)) {
if (CheckFile(dirnoslash)) {
return 1;
} else {
char parentpath[strlen(dirnoslash)+2];
char parentpath[strlen(dirnoslash) + 2];
strcpy(parentpath, dirnoslash);
char * ptr = strrchr(parentpath, '/');
char *ptr = strrchr(parentpath, '/');
if(!ptr) {
if (!ptr) {
//!Device root directory (must be with '/')
strcat(parentpath, "/");
struct stat filestat;
@ -119,7 +119,7 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
result = CreateSubfolder(parentpath);
}
if(!result)
if (!result)
return 0;
if (mkdir(dirnoslash, 0777) == -1) {
@ -129,13 +129,13 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
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);
if (!file.isOpen()) {
DEBUG_FUNCTION_LINE("Failed to open %s\n",path);
DEBUG_FUNCTION_LINE("Failed to open %s", path);
return 0;
}
int32_t written = file.write((const uint8_t*) buffer, size);
int32_t written = file.write((const uint8_t *) buffer, size);
file.close();
return written;
}

View File

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

View File

@ -24,27 +24,27 @@ GameList::~GameList() {
void GameList::clear() {
lock();
for (auto const& x : fullGameList) {
if(x != NULL) {
if(x->imageData != NULL) {
for (auto const &x: fullGameList) {
if (x != nullptr) {
if (x->imageData != nullptr) {
AsyncExecutor::pushForDelete(x->imageData);
x->imageData = NULL;
x->imageData = nullptr;
}
delete x;
}
}
fullGameList.clear();
//! Clear memory of the vector completely
std::vector<gameInfo*>().swap(fullGameList);
std::vector<gameInfo *>().swap(fullGameList);
unlock();
titleListChanged(this);
}
gameInfo * GameList::getGameInfo(uint64_t titleId){
gameInfo * result = NULL;
gameInfo *GameList::getGameInfo(uint64_t titleId) {
gameInfo *result = nullptr;
lock();
for (uint32_t i = 0; i < fullGameList.size(); ++i) {
if(titleId == fullGameList[i]->titleId){
if (titleId == fullGameList[i]->titleId) {
result = fullGameList[i];
break;
}
@ -55,13 +55,13 @@ gameInfo * GameList::getGameInfo(uint64_t titleId){
int32_t GameList::readGameList() {
// Clear list
for (auto const& x : fullGameList) {
for (auto const &x: fullGameList) {
delete x;
}
fullGameList.clear();
//! Clear memory of the vector completely
std::vector<gameInfo*>().swap(fullGameList);
std::vector<gameInfo *>().swap(fullGameList);
int32_t cnt = 0;
@ -79,23 +79,23 @@ int32_t GameList::readGameList() {
std::vector<struct MCPTitleListType> titles(titleCount);
uint32_t realTitleCount = 0;
static const std::vector<MCPAppType> menuAppTypes {
MCP_APP_TYPE_GAME,
MCP_APP_TYPE_GAME_WII,
MCP_APP_TYPE_SYSTEM_APPS,
MCP_APP_TYPE_SYSTEM_SETTINGS,
MCP_APP_TYPE_FRIEND_LIST,
MCP_APP_TYPE_MIIVERSE,
MCP_APP_TYPE_ESHOP,
MCP_APP_TYPE_BROWSER,
MCP_APP_TYPE_DOWNLOAD_MANAGEMENT,
MCP_APP_TYPE_ACCOUNT_APPS,
static const std::vector<MCPAppType> menuAppTypes{
MCP_APP_TYPE_GAME,
MCP_APP_TYPE_GAME_WII,
MCP_APP_TYPE_SYSTEM_APPS,
MCP_APP_TYPE_SYSTEM_SETTINGS,
MCP_APP_TYPE_FRIEND_LIST,
MCP_APP_TYPE_MIIVERSE,
MCP_APP_TYPE_ESHOP,
MCP_APP_TYPE_BROWSER,
MCP_APP_TYPE_DOWNLOAD_MANAGEMENT,
MCP_APP_TYPE_ACCOUNT_APPS,
};
for (auto appType : menuAppTypes) {
for (auto appType: menuAppTypes) {
uint32_t titleCountByType = 0;
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));
if (err < 0) {
MCP_Close(mcp);
return 0;
@ -106,13 +106,13 @@ int32_t GameList::readGameList() {
titles.resize(realTitleCount);
}
for (auto title_candidate : titles) {
gameInfo* newGameInfo = new gameInfo;
for (auto title_candidate: titles) {
auto *newGameInfo = new gameInfo;
newGameInfo->titleId = title_candidate.titleId;
newGameInfo->appType = title_candidate.appType;
newGameInfo->gamePath = title_candidate.path;
newGameInfo->name = "<unknown>";
newGameInfo->imageData = NULL;
newGameInfo->imageData = nullptr;
DCFlushRange(newGameInfo, sizeof(gameInfo));
fullGameList.push_back(newGameInfo);
@ -122,35 +122,31 @@ int32_t GameList::readGameList() {
AsyncExecutor::execute([this] {
lock();
for (uint32_t i = 0; i < fullGameList.size(); ++i) {
gameInfo *header = fullGameList[i];
for (auto header : fullGameList) {
DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading));
if(stopAsyncLoading) {
DEBUG_FUNCTION_LINE("Stop async title loading\n");
if (stopAsyncLoading) {
DEBUG_FUNCTION_LINE("Stop async title loading");
break;
}
DEBUG_FUNCTION_LINE("Load extra infos of %016llX\n",header->titleId);
ACPMetaXml* meta = (ACPMetaXml*)calloc(1, 0x4000); //TODO fix wut
if(meta) {
DEBUG_FUNCTION_LINE("Load extra infos of %016llX", header->titleId);
auto *meta = (ACPMetaXml *) calloc(1, 0x4000); //TODO fix wut
if (meta) {
auto acp = ACPGetTitleMetaXml(header->titleId, meta);
if(acp >= 0) {
if (acp >= 0) {
header->name = meta->shortname_en;
}
free(meta);
}
if(header->imageData == NULL) {
if (header->imageData == nullptr) {
std::string filepath = "fs:" + header->gamePath + META_PATH + "/iconTex.tga";
uint8_t *buffer = NULL;
uint8_t *buffer = nullptr;
uint32_t bufferSize = 0;
int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize);
if(iResult > 0) {
GuiImageData * imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
if(imageData) {
header->imageData = imageData;
}
if (iResult > 0) {
auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
header->imageData = imageData;
//! free original image buffer which is converted to texture now and not needed anymore
free(buffer);
@ -167,15 +163,15 @@ int32_t GameList::readGameList() {
void GameList::updateTitleInfo() {
for (int i = 0; i < this->size(); i++) {
gameInfo * newHeader = this->at(i);
gameInfo *newHeader = this->at(i);
bool hasChanged = false;
if(newHeader->name.empty()) {
ACPMetaXml* meta = (ACPMetaXml*)calloc(1, 0x4000); //TODO fix wut
if(meta) {
if (newHeader->name.empty()) {
auto *meta = (ACPMetaXml *) calloc(1, 0x4000); //TODO fix wut
if (meta) {
auto acp = ACPGetTitleMetaXml(newHeader->titleId, meta);
if(acp >= 0) {
if (acp >= 0) {
newHeader->name = meta->shortname_en;
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";
uint8_t *buffer = NULL;
uint8_t *buffer = nullptr;
uint32_t bufferSize = 0;
int iResult = FSUtils::LoadFileToMem(filepath.c_str(), &buffer, &bufferSize);
if(iResult > 0) {
GuiImageData * imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
if(imageData) {
newHeader->imageData = imageData;
hasChanged = true;
}
if (iResult > 0) {
auto *imageData = new GuiImageData(buffer, bufferSize, GX2_TEX_CLAMP_MODE_MIRROR);
newHeader->imageData = imageData;
hasChanged = true;
//! free original image buffer which is converted to texture now and not needed anymore
free(buffer);
}
}
if(hasChanged) {
if (hasChanged) {
DCFlushRange(newHeader, sizeof(gameInfo));
titleUpdated(newHeader);
}
@ -209,11 +203,11 @@ void GameList::updateTitleInfo() {
int32_t GameList::load() {
lock();
if(fullGameList.size() == 0) {
if (fullGameList.empty()) {
readGameList();
}
AsyncExecutor::execute([&] { updateTitleInfo();});
AsyncExecutor::execute([&] { updateTitleInfo(); });
titleListChanged(this);

View File

@ -14,12 +14,13 @@ typedef struct _gameInfo {
MCPAppType appType;
std::string name;
std::string gamePath;
GuiImageData * imageData;
GuiImageData *imageData;
} gameInfo;
class GameList {
public:
GameList();
~GameList();
int32_t size() {
@ -28,6 +29,7 @@ public:
unlock();
return res;
}
int32_t gameCount() {
lock();
int32_t res = fullGameList.size();
@ -35,25 +37,27 @@ public:
return res;
}
gameInfo * at(int32_t i) {
gameInfo *at(int32_t i) {
return operator[](i);
}
gameInfo * operator[](int32_t i) {
gameInfo *operator[](int32_t i) {
lock();
gameInfo * res = NULL;
gameInfo *res = nullptr;
if (i < 0 || i >= (int32_t) fullGameList.size()) {
res = NULL;
res = nullptr;
} else {
res = fullGameList[i];
}
unlock();
return res;
}
gameInfo * getGameInfo(uint64_t titleId);
gameInfo *getGameInfo(uint64_t titleId);
void clear();
std::vector<gameInfo *> & getFullGameList(void) {
std::vector<gameInfo *> &getFullGameList(void) {
return fullGameList;
}
@ -66,11 +70,14 @@ public:
void lock() {
_lock.lock();
}
void unlock() {
_lock.unlock();
}
protected:
int32_t readGameList();
void updateTitleInfo();
std::vector<gameInfo *> fullGameList;

View File

@ -11,7 +11,7 @@ static const float cfIconMirrorScale = 1.15f;
static const float cfIconMirrorAlpha = 0.45f;
GameIcon::GameIcon(GuiImageData *preloadImage)
: GuiImage(preloadImage) {
: GuiImage(preloadImage) {
bSelected = false;
bRenderStroke = true;
bRenderReflection = false;
@ -36,46 +36,46 @@ GameIcon::GameIcon(GuiImageData *preloadImage)
vtxCount = sizeof(cfGameIconPosVtxs) / (Shader3D::cuVertexAttrSize);
//! texture and vertex coordinates
posVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs));
texCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords));
posVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconPosVtxs));
texCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconTexCoords));
if(posVtxs) {
memcpy((float*)posVtxs, cfGameIconPosVtxs, sizeof(cfGameIconPosVtxs));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float*)posVtxs, sizeof(cfGameIconPosVtxs));
if (posVtxs) {
memcpy((float *) posVtxs, cfGameIconPosVtxs, sizeof(cfGameIconPosVtxs));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float *) posVtxs, sizeof(cfGameIconPosVtxs));
}
if(texCoords) {
memcpy((float*)texCoords, cfGameIconTexCoords, sizeof(cfGameIconTexCoords));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float*)texCoords, sizeof(cfGameIconTexCoords));
if (texCoords) {
memcpy((float *) texCoords, cfGameIconTexCoords, sizeof(cfGameIconTexCoords));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, (float *) texCoords, sizeof(cfGameIconTexCoords));
}
//! 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) {
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 + 1] = texCoords[i*2 + 1] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f);
if (texCoordsMirror) {
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 + 1] = texCoords[i * 2 + 1] * cfIconMirrorScale - ((cfIconMirrorScale - 1.0f) - (cfIconMirrorScale - 1.0f) * 0.5f);
}
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, texCoordsMirror, sizeof(cfGameIconTexCoords));
}
//! setup stroke of the icon
strokePosVtxs = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconStrokeVtxs));
if(strokePosVtxs) {
strokePosVtxs = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, sizeof(cfGameIconStrokeVtxs));
if (strokePosVtxs) {
memcpy(strokePosVtxs, cfGameIconStrokeVtxs, sizeof(cfGameIconStrokeVtxs));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokePosVtxs, sizeof(cfGameIconStrokeVtxs));
}
strokeTexCoords = (float*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize);
if(strokeTexCoords) {
for(size_t i = 0, n = 0; i < cuGameIconStrokeVtxCount; n += 2, i += 3) {
strokeTexCoords = (float *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuTexCoordAttrSize);
if (strokeTexCoords) {
for (size_t i = 0, n = 0; i < cuGameIconStrokeVtxCount; n += 2, i += 3) {
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);
}
strokeColorVtxs = (uint8_t*)memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize);
if(strokeColorVtxs) {
for(size_t i = 0; i < (cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); i++)
strokeColorVtxs = (uint8_t *) memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize);
if (strokeColorVtxs) {
for (size_t i = 0; i < (cuGameIconStrokeVtxCount * Shader::cuColorAttrSize); i++)
strokeColorVtxs[i] = 0xff;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, strokeColorVtxs, cuGameIconStrokeVtxCount * Shader::cuColorAttrSize);
}
@ -83,47 +83,47 @@ GameIcon::GameIcon(GuiImageData *preloadImage)
GameIcon::~GameIcon() {
//! remove image so it can not be drawn anymore from this point on
imageData = NULL;
imageData = nullptr;
//! main image vertexes
if(posVtxs) {
free((void*)posVtxs);
posVtxs = NULL;
if (posVtxs) {
free((void *) posVtxs);
posVtxs = nullptr;
}
if(texCoords) {
free((void*)texCoords);
texCoords = NULL;
if (texCoords) {
free((void *) texCoords);
texCoords = nullptr;
}
//! mirror image vertexes
if(texCoordsMirror) {
if (texCoordsMirror) {
free(texCoordsMirror);
texCoordsMirror = NULL;
texCoordsMirror = nullptr;
}
//! stroke image vertexes
if(strokePosVtxs) {
if (strokePosVtxs) {
free(strokePosVtxs);
strokePosVtxs = NULL;
strokePosVtxs = nullptr;
}
if(strokeTexCoords) {
if (strokeTexCoords) {
free(strokeTexCoords);
strokeTexCoords = NULL;
strokeTexCoords = nullptr;
}
if(strokeColorVtxs) {
if (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
//! otherwise an OOB intersection would be required
float currPosX = getCenterX() * Application::instance()->getVideo()->getWidthScaleFactor() * 2.0f;
float currPosY = getCenterY() * Application::instance()->getVideo()->getHeightScaleFactor() * 2.0f;
float currPosZ = getDepth() * Application::instance()->getVideo()->getDepthScaleFactor() * 2.0f;
float currScaleX = getScaleX() * (float)getWidth() * Application::instance()->getVideo()->getWidthScaleFactor();
float currScaleY = getScaleY() * (float)getHeight() * Application::instance()->getVideo()->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float)getWidth() * Application::instance()->getVideo()->getDepthScaleFactor();
float currScaleX = getScaleX() * (float) getWidth() * Application::instance()->getVideo()->getWidthScaleFactor();
float currScaleY = getScaleY() * (float) getHeight() * Application::instance()->getVideo()->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float) getWidth() * Application::instance()->getVideo()->getDepthScaleFactor();
//! 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 rt(currPosX + currScaleX, currPosY + currScaleY, currPosZ + currScaleZ);
@ -154,29 +154,29 @@ bool GameIcon::checkRayIntersection(const glm::vec3 & rayOrigin, const glm::vec3
return true;
}
void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::mat4 & viewMtx, const glm::mat4 & modelView) {
if(imageData == NULL){
void GameIcon::draw(CVideo *pVideo, const glm::mat4 &projectionMtx, const glm::mat4 &viewMtx, const glm::mat4 &modelView) {
if (imageData == nullptr) {
return;
}
//! first setup 2D GUI positions
float currPosX = getCenterX() * pVideo->getWidthScaleFactor() * 2.0f;
float currPosY = getCenterY() * pVideo->getHeightScaleFactor() * 2.0f;
float currPosZ = getDepth() * pVideo->getDepthScaleFactor() * 2.0f;
float currScaleX = getScaleX() * (float)getWidth() * pVideo->getWidthScaleFactor();
float currScaleY = getScaleY() * (float)getHeight() * pVideo->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float)getWidth() * pVideo->getDepthScaleFactor();
float currScaleX = getScaleX() * (float) getWidth() * pVideo->getWidthScaleFactor();
float currScaleY = getScaleY() * (float) getHeight() * pVideo->getHeightScaleFactor();
float currScaleZ = getScaleZ() * (float) getWidth() * pVideo->getDepthScaleFactor();
float strokeScaleX = pVideo->getWidthScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale;
float strokeScaleY = pVideo->getHeightScaleFactor() * strokeWidth * 0.25f + cfIconMirrorScale;
for(int32_t iDraw = 0; iDraw < 2; iDraw++) {
glm::vec4 * alphaFadeOut;
for (int32_t iDraw = 0; iDraw < 2; iDraw++) {
glm::vec4 *alphaFadeOut;
glm::mat4 m_iconView;
glm::mat4 m_mirrorView;
glm::mat4 m_strokeView;
if(iDraw == RENDER_REFLECTION) {
if (iDraw == RENDER_REFLECTION) {
//! Reflection render
if(!bRenderReflection)
if (!bRenderReflection)
continue;
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));
@ -190,7 +190,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_ENABLE, GX2_DISABLE);
} else {
//! 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::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];
if(!bIconLast) {
if (!bIconLast) {
Shader3D::instance()->setShaders();
Shader3D::instance()->setProjectionMtx(projectionMtx);
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;
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);
}
if(iDraw == RENDER_NORMAL && bRenderStroke) {
if (iDraw == RENDER_NORMAL && bRenderStroke) {
strokeFractalEnable = 1;
//! now render the icon stroke
//! 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()->draw(GX2_PRIMITIVE_MODE_QUADS, vtxCount);
if(bIconLast) {
if (bIconLast) {
Shader3D::instance()->setShaders();
Shader3D::instance()->setProjectionMtx(projectionMtx);
Shader3D::instance()->setViewMtx(viewMtx);
@ -290,7 +290,7 @@ void GameIcon::draw(CVideo *pVideo, const glm::mat4 & projectionMtx, const glm::
}
//! return back normal culling
if(iDraw == RENDER_REFLECTION) {
if (iDraw == RENDER_REFLECTION) {
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_ENABLE);
}
}

View File

@ -4,52 +4,62 @@
#include <gui/GuiImageAsync.h>
#include <gui/video/shaders/Shader3D.h>
class GameIcon : public GuiImage
{
class GameIcon : public GuiImage {
public:
GameIcon(GuiImageData *preloadImage);
virtual ~GameIcon();
void setRotationX(float r) {
rotationX = r;
}
void setColorIntensity(const glm::vec4 & color) {
void setColorIntensity(const glm::vec4 &color) {
colorIntensity = color;
colorIntensityMirror = colorIntensity;
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);
}
const glm::vec4 & getColorIntensity() const {
const glm::vec4 &getColorIntensity() const {
return colorIntensity;
}
void setAlphaFadeOutNorm(const glm::vec4 & a) {
void setAlphaFadeOutNorm(const glm::vec4 &a) {
alphaFadeOutNorm = a;
}
void setAlphaFadeOutRefl(const glm::vec4 & a) {
void setAlphaFadeOutRefl(const glm::vec4 &a) {
alphaFadeOutRefl = a;
}
void setRenderReflection(bool enable) {
bRenderReflection = enable;
}
void setSelected(bool enable) {
bSelected = enable;
}
void setStrokeRender(bool enable) {
bRenderStroke = enable;
}
void setRenderIconLast(bool enable) {
bIconLast = enable;
}
void draw(CVideo *pVideo) {
static const glm::mat4 identity(1.0f);
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:
enum eRenderState
{
enum eRenderState {
RENDER_REFLECTION,
RENDER_NORMAL
};

File diff suppressed because it is too large Load Diff

View File

@ -25,35 +25,21 @@
#include "utils/logger.h"
#include "gui/GameIcon.h"
GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex,bool sortByName)
: GuiTitleBrowser(w, h, GameIndex),
sortByName(sortByName),
particleBgImage(w, h, 50, 60.0f, 90.0f, 0.6f, 1.0f)
, buttonClickSound(Resources::GetSound("button_click.mp3"))
, gameTitle((char*)NULL, 52, glm::vec4(1.0f))
, touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A)
, leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true)
, rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, 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)
, buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true)
, buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true)
, buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true)
, 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) {
GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex, bool sortByName)
: GuiTitleBrowser(w, h, GameIndex),
sortByName(sortByName),
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)),
touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH),
wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A),
leftTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_LEFT | GuiTrigger::STICK_L_LEFT, true),
rightTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_RIGHT | GuiTrigger::STICK_L_RIGHT, 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),
buttonATrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_A, true), buttonLTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_L, true),
buttonRTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_R, true), 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);
setSelectedGame(GameIndex);
@ -112,10 +98,10 @@ GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex,bool sortByNam
append(&arrowRightButton);
// at most we are rendering 2 screens at the same time
for(int i = 0; i< MAX_COLS * MAX_ROWS *2; i++) {
GameIcon * image = new GameIcon(&emptyIcon);
for (int i = 0; i < MAX_COLS * MAX_ROWS * 2; i++) {
GameIcon *image = new GameIcon(&emptyIcon);
emptyIcons.push_back(image);
GuiButton * button = new GuiButton(emptyIcon.getWidth(), emptyIcon.getHeight());
GuiButton *button = new GuiButton(emptyIcon.getWidth(), emptyIcon.getHeight());
button->setImage(image);
button->setPosition(0, 0);
//button->setEffectGrow();
@ -140,18 +126,18 @@ GuiIconGrid::GuiIconGrid(int32_t w, int32_t h, uint64_t GameIndex,bool sortByNam
GuiIconGrid::~GuiIconGrid() {
containerMutex.lock();
for (auto const& x : gameInfoContainers) {
for (auto const &x: gameInfoContainers) {
remove(x.second->button);
delete x.second;
}
gameInfoContainers.clear();
containerMutex.unlock();
for (auto const& x : emptyButtons) {
for (auto const &x: emptyButtons) {
delete x;
}
for (auto const& x : emptyIcons) {
for (auto const &x: emptyIcons) {
delete x;
}
@ -162,8 +148,8 @@ GuiIconGrid::~GuiIconGrid() {
int32_t GuiIconGrid::offsetForTitleId(uint64_t titleId) {
int32_t offset = -1;
positionMutex.lock();
for(uint32_t i = 0; i < position.size(); i++) {
if(position.at(i) == titleId) {
for (uint32_t i = 0; i < position.size(); i++) {
if (position.at(i) == titleId) {
offset = i;
break;
}
@ -176,10 +162,10 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) {
this->selectedGame = idx;
containerMutex.lock();
GameInfoContainer * container = NULL;
for (auto const& x : gameInfoContainers) {
GameInfoContainer *container = nullptr;
for (auto const &x: gameInfoContainers) {
container = x.second;
if(x.first == idx) {
if (x.first == idx) {
container->image->setSelected(true);
gameTitle.setText(container->info->name.c_str());
} else {
@ -189,9 +175,9 @@ void GuiIconGrid::setSelectedGame(uint64_t idx) {
containerMutex.unlock();
int32_t offset = offsetForTitleId(getSelectedGame());
if(offset > 0) {
if (offset > 0) {
uint32_t newPage = offset / (MAX_COLS * MAX_ROWS);
if(newPage != (uint32_t) curPage) {
if (newPage != (uint32_t) curPage) {
curPage = newPage;
bUpdatePositions = true;
}
@ -202,7 +188,7 @@ uint64_t GuiIconGrid::getSelectedGame(void) {
return selectedGame;
}
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
void GuiIconGrid::OnGameTitleListUpdated(GameList *gameList) {
gameList->lock();
containerMutex.lock();
positionMutex.lock();
@ -210,16 +196,16 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
auto it = gameInfoContainers.begin();
while (it != gameInfoContainers.end()) {
bool wasFound = false;
for(int32_t i = 0; i < gameList->size(); i++) {
gameInfo * info = gameList->at(i);
if(info != NULL && info->titleId == it->first) {
for (int32_t i = 0; i < gameList->size(); i++) {
gameInfo *info = gameList->at(i);
if (info != nullptr && info->titleId == it->first) {
wasFound = true;
break;
}
}
if (!wasFound) {
DEBUG_FUNCTION_LINE("Removing %016llX\n", it->first);
DEBUG_FUNCTION_LINE("Removing %016llX", it->first);
remove(it->second->button);
delete it->second;
it = gameInfoContainers.erase(it);
@ -228,17 +214,17 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
}
}
for(int32_t i = 0; i < gameList->size(); i++) {
gameInfo * info = gameList->at(i);
GameInfoContainer * container = NULL;
for (int32_t i = 0; i < gameList->size(); i++) {
gameInfo *info = gameList->at(i);
GameInfoContainer *container = nullptr;
for (auto const& x : gameInfoContainers) {
if(info->titleId == x.first) {
for (auto const &x: gameInfoContainers) {
if (info->titleId == x.first) {
container = x.second;
break;
}
}
if(container == NULL) {
if (container == nullptr) {
OnGameTitleAdded(info);
}
}
@ -266,19 +252,19 @@ void GuiIconGrid::OnRightArrowClick(GuiButton *button, const GuiController *cont
void GuiIconGrid::OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) {
if (offset < 0) {
return;
}
if((offset % MAX_COLS) == 0) {
if ((offset % MAX_COLS) == 0) {
offset -= ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1;
} else {
offset--;
}
if(offset < 0 || position.empty()) {
if (offset < 0 || position.empty()) {
return;
}
uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) {
if (newTitleId > 0) {
setSelectedGame(newTitleId);
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) {
int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) {
if (offset < 0) {
return;
}
if((offset % MAX_COLS) == MAX_COLS - 1) {
if ((offset % MAX_COLS) == MAX_COLS - 1) {
offset += ((MAX_COLS * MAX_ROWS) - MAX_COLS) + 1;
} else {
offset++;
}
if((uint32_t) offset >= position.size()) {
if ((uint32_t) offset >= position.size()) {
return;
}
uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) {
if (newTitleId > 0) {
setSelectedGame(newTitleId);
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) {
int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) {
if (offset < 0) {
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;
} else {
return;
}
if((uint32_t) offset >= position.size()) {
if ((uint32_t) offset >= position.size()) {
return;
}
uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) {
if (newTitleId > 0) {
setSelectedGame(newTitleId);
gameSelectionChanged(this, selectedGame);
}
}
void GuiIconGrid::OnUpClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
int32_t offset = offsetForTitleId(getSelectedGame());
if(offset < 0) {
if (offset < 0) {
return;
}
if(offset % (MAX_COLS * MAX_ROWS) >= MAX_COLS) {
if (offset % (MAX_COLS * MAX_ROWS) >= MAX_COLS) {
offset = offset - MAX_COLS;
} else {
return;
}
if(offset < 0) {
if (offset < 0) {
return;
}
uint64_t newTitleId = position.at(offset);
if(newTitleId > 0) {
if (newTitleId > 0) {
setSelectedGame(newTitleId);
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) {
//! 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;
}
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());
}
void GuiIconGrid::OnLeftArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(currentlyHeld != NULL) {
if(lArrowHeldCounter++ > 30) {
OnLeftArrowClick(button,controller,trigger);
if (currentlyHeld != nullptr) {
if (lArrowHeldCounter++ > 30) {
OnLeftArrowClick(button, controller, trigger);
lArrowHeldCounter = 0;
}
} else {
@ -372,10 +359,10 @@ void GuiIconGrid::OnLeftArrowReleased(GuiButton *button, const GuiController *co
}
void GuiIconGrid::OnRightArrowHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(currentlyHeld != NULL) {
if(rArrowHeldCounter++ > 30) {
DEBUG_FUNCTION_LINE("CLICK\n");
OnRightArrowClick(button,controller,trigger);
if (currentlyHeld != nullptr) {
if (rArrowHeldCounter++ > 30) {
DEBUG_FUNCTION_LINE("CLICK");
OnRightArrowClick(button, controller, trigger);
rArrowHeldCounter = 0;
}
} else {
@ -389,20 +376,20 @@ void GuiIconGrid::OnRightArrowReleased(GuiButton *button, const GuiController *c
void GuiIconGrid::OnGameButtonHeld(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
if(currentlyHeld == NULL) {
if (currentlyHeld == nullptr) {
bool found = false;
// We don't want to drag empty buttons
for(auto const & x : emptyButtons) {
if(x == button) {
found = true;
for (auto const &x: emptyButtons) {
if (x == button) {
found = true;
break;
}
}
if(!found) {
if (!found) {
currentlyHeld = button;
}
}
if(currentlyHeld != NULL && currentlyHeld != button) {
if (currentlyHeld != nullptr && currentlyHeld != 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) {
if(currentlyHeld != NULL) {
void GuiIconGrid::OnDrag(GuiDragListener *element, const GuiController *controller, GuiTrigger *trigger, int32_t dx, int32_t dy) {
if (currentlyHeld != nullptr) {
currentlyHeld->setPosition(currentlyHeld->getOffsetX() + dx, currentlyHeld->getOffsetY() + dy);
}
// reset the target when we move.
dragTarget = NULL;
dragTarget = nullptr;
}
void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) {
containerMutex.lock();
for (auto const& x : gameInfoContainers) {
if(x.second->button == button) {
if(selectedGame == (x.second->info->titleId)) {
if(gameLaunchTimer < 30)
for (auto const &x: gameInfoContainers) {
if (x.second->button == button) {
if (selectedGame == (x.second->info->titleId)) {
if (gameLaunchTimer < 30)
OnLaunchClick(button, controller, trigger);
} else {
setSelectedGame(x.second->info->titleId);
@ -441,19 +428,19 @@ void GuiIconGrid::OnGameButtonClick(GuiButton *button, const GuiController *cont
containerMutex.unlock();
}
void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
DEBUG_FUNCTION_LINE("Adding %016llX\n", info->titleId);
GuiImageData * imageData = &noIcon;
if(info->imageData != NULL) {
void GuiIconGrid::OnGameTitleAdded(gameInfo *info) {
DEBUG_FUNCTION_LINE("Adding %016llX", info->titleId);
GuiImageData *imageData = &noIcon;
if (info->imageData != nullptr) {
imageData = info->imageData;
}
GameIcon * image = new GameIcon(imageData);
GameIcon *image = new GameIcon(imageData);
image->setRenderReflection(false);
image->setStrokeRender(false);
image->setSelected(info->titleId == selectedGame);
image->setRenderIconLast(true);
GuiButton * button = new GuiButton(noIcon.getWidth(), noIcon.getHeight());
GuiButton *button = new GuiButton(noIcon.getWidth(), noIcon.getHeight());
button->setImage(image);
button->setPosition(0, 0);
button->setEffectGrow();
@ -469,7 +456,7 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
button->pointedOff.connect(this, &GuiIconGrid::OnGameButtonPointedOff);
//button->dragged.connect(this, &GuiIconGrid::OnGameButtonDragged);
GameInfoContainer * container = new GameInfoContainer(button, image, info);
GameInfoContainer *container = new GameInfoContainer(button, image, info);
containerMutex.lock();
gameInfoContainers[info->titleId] = container;
containerMutex.unlock();
@ -477,33 +464,34 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
positionMutex.lock();
bool foundFreePlace = false;
for(uint32_t i = 0; i < position.size(); i++) {
if(position[i] == 0) {
for (uint32_t i = 0; i < position.size(); i++) {
if (position[i] == 0) {
position[i] = info->titleId;
foundFreePlace = true;
break;
}
}
if(!foundFreePlace) {
if (!foundFreePlace) {
position.push_back(info->titleId);
}
positionMutex.unlock();
bUpdatePositions = true;
}
void GuiIconGrid::OnGameTitleUpdated(gameInfo * info) {
DEBUG_FUNCTION_LINE("Updating infos of %016llX\n", info->titleId);
GameInfoContainer * container = NULL;
void GuiIconGrid::OnGameTitleUpdated(gameInfo *info) {
DEBUG_FUNCTION_LINE("Updating infos of %016llX", info->titleId);
GameInfoContainer *container = nullptr;
containerMutex.lock();
for (auto const& x : gameInfoContainers) {
if(info->titleId == x.first) {
for (auto const &x: gameInfoContainers) {
if (info->titleId == x.first) {
container = x.second;
break;
}
}
// keep the lock to delay the draw() until the image data is ready.
if(container != NULL) {
if (container != nullptr) {
container->updateImageData();
}
@ -513,30 +501,30 @@ void GuiIconGrid::OnGameTitleUpdated(gameInfo * info) {
}
void GuiIconGrid::process() {
if(currentlyHeld != NULL) {
if(!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) {
DEBUG_FUNCTION_LINE("Not held anymore\n");
if (currentlyHeld != nullptr) {
if (!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) {
DEBUG_FUNCTION_LINE("Not held anymore");
positionMutex.lock();
if(dragTarget) {
DEBUG_FUNCTION_LINE("Let's swap\n");
if (dragTarget) {
DEBUG_FUNCTION_LINE("Let's swap");
std::vector<std::pair<uint64_t,GameInfoContainer*>> vec;
std::vector<std::pair<uint64_t, GameInfoContainer *>> vec;
containerMutex.lock();
// 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();
uint64_t targetTitleId = 0;
for (auto const& x : vec) {
if(x.second->button == dragTarget) {
for (auto const &x: vec) {
if (x.second->button == dragTarget) {
targetTitleId = x.first;
break;
}
}
for(uint32_t i = 0; i< positionButtons.size(); i++) {
if(positionButtons[i] == dragTarget) {
if(i < position.size() && i != currentlyHeldPosition) {
for (uint32_t i = 0; i < positionButtons.size(); i++) {
if (positionButtons[i] == dragTarget) {
if (i < position.size() && (int32_t) i != currentlyHeldPosition) {
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 {
targetTitleId = currentlyHeldTitleId;
}
@ -544,45 +532,45 @@ void GuiIconGrid::process() {
break;
}
}
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
position[currentlyHeldPosition] = targetTitleId;
}
dragTarget = NULL;
dragTarget = nullptr;
} else {
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
if (currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
position[currentlyHeldPosition] = currentlyHeldTitleId;
}
}
positionMutex.unlock();
currentlyHeld = NULL;
currentlyHeld = nullptr;
currentlyHeldTitleId = 0;
currentlyHeldPosition = -1;
bUpdatePositions = true;
} else {
//DEBUG_FUNCTION_LINE("Holding it\n");
//DEBUG_FUNCTION_LINE("Holding it");
bUpdatePositions = true;
}
}
if(currentLeftPosition < targetLeftPosition) {
if (currentLeftPosition < targetLeftPosition) {
currentLeftPosition += 35;
if(currentLeftPosition > targetLeftPosition)
if (currentLeftPosition > targetLeftPosition)
currentLeftPosition = targetLeftPosition;
bUpdatePositions = true;
} else if(currentLeftPosition > targetLeftPosition) {
} else if (currentLeftPosition > targetLeftPosition) {
currentLeftPosition -= 35;
if(currentLeftPosition < targetLeftPosition)
if (currentLeftPosition < targetLeftPosition)
currentLeftPosition = targetLeftPosition;
bUpdatePositions = true;
}
if(bUpdatePositions) {
if (bUpdatePositions) {
bUpdatePositions = false;
updateButtonPositions();
}
@ -591,7 +579,7 @@ void GuiIconGrid::process() {
GuiFrame::process();
}
void GuiIconGrid::update(GuiController * c) {
void GuiIconGrid::update(GuiController *c) {
GuiFrame::update(c);
}
@ -605,69 +593,69 @@ void GuiIconGrid::updateButtonPositions() {
int32_t col = 0, row = 0, listOff = 0;
// create an empty vector of pairs
std::vector<std::pair<uint64_t,GameInfoContainer*>> vec;
std::vector<std::pair<uint64_t, GameInfoContainer *>> vec;
containerMutex.lock();
// 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();
for (auto const& x : vec) {
if(x.second->button == currentlyHeld) {
for (auto const &x: vec) {
if (x.second->button == currentlyHeld) {
currentlyHeldTitleId = x.first;
}
remove(x.second->button);
}
for (auto const& x : emptyButtons) {
for (auto const &x: emptyButtons) {
remove(x);
}
if(sortByName) {
if (sortByName) {
std::sort(vec.begin(), vec.end(),
[](const std::pair<uint64_t,GameInfoContainer*>& l, const std::pair<uint64_t,GameInfoContainer*>& r) {
if (l.second != r.second)
return l.second->info->name.compare(r.second->info->name) <0;
[](const std::pair<uint64_t, GameInfoContainer *> &l, const std::pair<uint64_t, GameInfoContainer *> &r) {
if (l.second != r.second)
return l.second->info->name.compare(r.second->info->name) < 0;
return l.first < r.first;
});
return l.first < r.first;
});
}
// TODO somehow be able to adjust the positions.
//position.clear();
for(uint32_t i = 0; i<position.size(); i++) {
if(position[i] == currentlyHeldTitleId) {
for (uint32_t i = 0; i < position.size(); i++) {
if (position[i] == currentlyHeldTitleId) {
currentlyHeldPosition = i;
position[i] = 0;
}
}
uint32_t elementSize = position.size();
uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) +1;
if(elementSize % (MAX_COLS * MAX_ROWS) == 0) {
uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) + 1;
if (elementSize % (MAX_COLS * MAX_ROWS) == 0) {
pages--;
}
uint32_t emptyIconUse = 0;
if(curPage < 0) {
if (curPage < 0) {
curPage = 0;
}
if((uint32_t) curPage > pages) {
if ((uint32_t) curPage > pages) {
curPage = 0;
}
targetLeftPosition = -curPage * getWidth();
if((uint32_t) curPage < (pages - 1)) {
if ((uint32_t) curPage < (pages - 1)) {
arrowRightButton.clearState(GuiElement::STATE_DISABLED);
arrowRightButton.setVisible(true);
bringToFront(&arrowRightButton);
}
if(curPage > 0) {
if (curPage > 0) {
arrowLeftButton.clearState(GuiElement::STATE_DISABLED);
arrowLeftButton.setVisible(true);
bringToFront(&arrowLeftButton);
@ -676,49 +664,49 @@ void GuiIconGrid::updateButtonPositions() {
uint32_t startPage = -(currentLeftPosition / getWidth());
uint32_t endPage = startPage;
if(targetLeftPosition != currentLeftPosition) {
for (auto const& x : vec) {
if (targetLeftPosition != currentLeftPosition) {
for (auto const &x: vec) {
x.second->button->setHoldable(false);
}
endPage++;
if(endPage > pages) {
if (endPage > pages) {
endPage = pages;
}
} else {
for (auto const& x : vec) {
for (auto const &x: vec) {
x.second->button->setHoldable(true);
}
}
uint32_t startValue = startPage * (MAX_COLS * MAX_ROWS);
positionButtons.clear();
for(uint32_t i = 0; i<startValue; i++) {
positionButtons.push_back(NULL);
for (uint32_t i = 0; i < startValue; i++) {
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);
GuiButton * element = NULL;
float posX = currentLeftPosition + listOff * width + ( col * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) - (MAX_COLS * 0.5f - 0.5f) * (noIcon.getWidth() + noIcon.getWidth() * 0.5f) );
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 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);
if(titleID > 0) {
GameInfoContainer * container = NULL;
if (titleID > 0) {
GameInfoContainer *container = nullptr;
containerMutex.lock();
if(gameInfoContainers.find(titleID) != gameInfoContainers.end()) {
if (gameInfoContainers.find(titleID) != gameInfoContainers.end()) {
container = gameInfoContainers[titleID];
}
containerMutex.unlock();
if(container != NULL) {
if (container != nullptr) {
element = container->button;
}
}
}
if(element == NULL) {
if(emptyButtons.size() <= emptyIconUse) {
if (element == nullptr) {
if (emptyButtons.size() <= emptyIconUse) {
break;
}
element = emptyButtons.at(emptyIconUse);
@ -729,19 +717,19 @@ void GuiIconGrid::updateButtonPositions() {
append(element);
col++;
if(col >= MAX_COLS) {
if (col >= MAX_COLS) {
col = 0;
row++;
}
if(row >= MAX_ROWS) {
if (row >= MAX_ROWS) {
row = 0;
}
}
if(currentlyHeld != NULL) {
if (currentlyHeld != nullptr) {
append(currentlyHeld);
}
if(positionButtons.size() > position.size() && targetLeftPosition == currentLeftPosition) {
for(uint32_t i = 0; i < positionButtons.size() - position.size(); i++) {
if (positionButtons.size() > position.size() && targetLeftPosition == currentLeftPosition) {
for (uint32_t i = 0; i < positionButtons.size() - position.size(); i++) {
position.push_back(0);
}
}

View File

@ -27,19 +27,27 @@
class GuiIconGrid : public GuiTitleBrowser, public sigslot::has_slots<> {
public:
GuiIconGrid(int32_t w, int32_t h, uint64_t selectedTitleId, bool sortByName);
virtual ~GuiIconGrid();
void setSelectedGame(uint64_t idx);
uint64_t getSelectedGame(void);
void update(GuiController * t);
void update(GuiController *t);
void draw(CVideo *pVideo);
void process();
void OnGameTitleListUpdated(GameList * list);
void OnAddGameTitle(gameInfo * info);
void OnGameTitleUpdated(gameInfo * info);
void OnGameTitleAdded(gameInfo * info);
void OnGameTitleListUpdated(GameList *list);
void OnAddGameTitle(gameInfo *info);
void OnGameTitleUpdated(gameInfo *info);
void OnGameTitleAdded(gameInfo *info);
private:
static const int32_t MAX_ROWS = 3;
static const int32_t MAX_COLS = 5;
@ -66,8 +74,8 @@ private:
GuiButton upButton;
GuiButton launchButton;
GuiImageData* arrowRightImageData;
GuiImageData* arrowLeftImageData;
GuiImageData *arrowRightImageData;
GuiImageData *arrowLeftImageData;
GuiImage arrowRightImage;
GuiImage arrowLeftImage;
GuiButton arrowRightButton;
@ -79,23 +87,35 @@ private:
GuiDragListener dragListener;
void OnLeftArrowClick(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 OnRightClick(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 OnLaunchClick(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 OnGameButtonPointedOn(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 OnLeftArrowHeld(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 OnRightArrowReleased(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
void updateButtonPositions();
@ -112,44 +132,44 @@ private:
int32_t targetLeftPosition;
uint32_t gameLaunchTimer;
bool bUpdatePositions = false;
GuiButton * currentlyHeld = NULL;
GuiButton *currentlyHeld = nullptr;
uint64_t currentlyHeldTitleId = 0;
int32_t currentlyHeldPosition = -1;
GuiButton * dragTarget = NULL;
GuiButton *dragTarget = nullptr;
class GameInfoContainer {
public:
GameInfoContainer(GuiButton* button, GameIcon * image, gameInfo * info) {
GameInfoContainer(GuiButton *button, GameIcon *image, gameInfo *info) {
this->image = image;
this->info = info;
this->button = button;
}
~GameInfoContainer() {
if(button != NULL) {
if (button != nullptr) {
AsyncExecutor::pushForDelete(button);
}
if(image != NULL) {
if (image != nullptr) {
AsyncExecutor::pushForDelete(image);
}
}
void updateImageData() {
if(image != NULL && info != NULL && info->imageData != NULL) {
if (image != nullptr && info != nullptr && info->imageData != nullptr) {
image->setImageData(info->imageData);
}
}
GameIcon * image;
gameInfo * info;
GuiButton * button;
GameIcon *image;
gameInfo *info;
GuiButton *button;
};
std::recursive_mutex positionMutex;
std::recursive_mutex containerMutex;
std::map<uint64_t, GameInfoContainer *> gameInfoContainers;
std::vector<uint64_t> position;
std::vector<GuiButton*> positionButtons;
std::vector<GuiButton *> positionButtons;
std::vector<GuiImage *> emptyIcons;
std::vector<GuiButton *> emptyButtons;

View File

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

View File

@ -4,36 +4,36 @@
#include "fs/FSUtils.h"
#include "utils/AsyncExecutor.h"
GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo * info, bool onTV) : GuiFrame(w, h),
bgImageColor(w, h, (GX2Color) {
0, 0, 0, 0
}) {
GameSplashScreen::GameSplashScreen(int32_t w, int32_t h, gameInfo *info, bool onTV) : GuiFrame(w, h),
bgImageColor(w, h, (GX2Color) {
0, 0, 0, 0
}) {
bgImageColor.setImageColor((GX2Color) {
79, 153, 239, 255
79, 153, 239, 255
}, 0);
bgImageColor.setImageColor((GX2Color) {
79, 153, 239, 255
79, 153, 239, 255
}, 1);
bgImageColor.setImageColor((GX2Color) {
59, 159, 223, 255
59, 159, 223, 255
}, 2);
bgImageColor.setImageColor((GX2Color) {
59, 159, 223, 255
59, 159, 223, 255
}, 3);
append(&bgImageColor);
this->onTV = onTV;
this->info = info;
std::string filepath = "fs:" + info->gamePath + META_PATH + "/bootDRCTex.tga";
if(onTV) {
if (onTV) {
filepath = "fs:" + info->gamePath + META_PATH + "/bootTVTex.tga";
}
uint8_t *buffer = NULL;
uint8_t *buffer = nullptr;
uint32_t bufferSize = 0;
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);
if(splashScreenData) {
if (splashScreenData) {
bgImageColor.setImageData(splashScreenData);
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);
if(launchGame && frameCounter++ > 1) {
if (launchGame && frameCounter++ > 1) {
DEBUG_FUNCTION_LINE("Launch game %d\n", onTV);
gameGameSplashScreenFinished(this, info, onTV);
}
@ -60,7 +60,7 @@ void GameSplashScreen::draw(CVideo * v) {
GameSplashScreen::~GameSplashScreen() {
DEBUG_FUNCTION_LINE("Destroy me\n");
if(splashScreenData) {
if (splashScreenData) {
AsyncExecutor::pushForDelete(splashScreenData);
}
}

View File

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

View File

@ -4,20 +4,20 @@
#include <coreinit/memdefaultheap.h>
KeyboardHelper::KeyboardHelper() {
FSClient *fsClient = (FSClient *)MEMAllocFromDefaultHeap(sizeof(FSClient));
FSAddClient(fsClient, 0);
auto *_fsClient = (FSClient *) MEMAllocFromDefaultHeap(sizeof(FSClient));
FSAddClient(_fsClient, FS_ERROR_FLAG_ALL);
// Create swkbd
nn::swkbd::CreateArg createArg;
createArg.regionType = nn::swkbd::RegionType::Europe;
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;
createArg.fsClient = fsClient;
createArg.fsClient = _fsClient;
this->fsClient = createArg.fsClient;
DEBUG_FUNCTION_LINE("Calling create\n");
DEBUG_FUNCTION_LINE("Calling create");
if (!nn::swkbd::Create(createArg)) {
DEBUG_FUNCTION_LINE("Failed to create keyboard\n");
DEBUG_FUNCTION_LINE("Failed to create keyboard");
return;
}
@ -25,24 +25,24 @@ KeyboardHelper::KeyboardHelper() {
}
KeyboardHelper::~KeyboardHelper() {
if(keyboardCreated) {
if (keyboardCreated) {
nn::swkbd::Destroy();
MEMFreeToDefaultHeap(this->workMemory);
this->workMemory = NULL;
this->workMemory = nullptr;
FSDelClient(fsClient, 0);
FSDelClient(fsClient, FS_ERROR_FLAG_ALL);
MEMFreeToDefaultHeap(this->fsClient);
keyboardCreated = false;
}
}
bool KeyboardHelper::openKeyboard() {
if(keyboardCreated) {
if (keyboardCreated) {
// Show the keyboard
nn::swkbd::AppearArg appearArg;
appearArg.keyboardArg.configArg.languageType = nn::swkbd::LanguageType::English;
if (!nn::swkbd::AppearInputForm(appearArg)) {
DEBUG_FUNCTION_LINE("nn::swkbd::AppearInputForm failed\n");
DEBUG_FUNCTION_LINE("nn::swkbd::AppearInputForm failed");
return false;
}
keyboardOpen = true;
@ -56,9 +56,9 @@ std::string KeyboardHelper::getResult() {
}
bool KeyboardHelper::checkResult() {
if(keyboardCreated) {
if (keyboardCreated) {
VPADStatus vpadStatus;
if(keyboardOpen) {
if (keyboardOpen) {
VPADRead(VPAD_CHAN_0, &vpadStatus, 1, nullptr);
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &vpadStatus.tpNormal, &vpadStatus.tpNormal);
}

View File

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

View File

@ -20,26 +20,16 @@
#include "gui/Gui.h"
#include "resources/Resources.h"
class MainDrcButtonsFrame : public GuiFrame, public sigslot::has_slots<>
{
class MainDrcButtonsFrame : public GuiFrame, public sigslot::has_slots<> {
public:
MainDrcButtonsFrame(int32_t w, int32_t h)
: GuiFrame(w, h)
, buttonClickSound(Resources::GetSound("settings_click_2.mp3"))
, screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3"))
, switchIconData(Resources::GetImageData("layoutSwitchButton.png"))
, settingsIconData(Resources::GetImageData("settingsButton.png"))
, switchIcon(switchIconData)
, settingsIcon(settingsIconData)
, 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)
{
: GuiFrame(w, h), buttonClickSound(Resources::GetSound("settings_click_2.mp3")), screenSwitchSound(Resources::GetSound("screenSwitchSound.mp3")),
switchIconData(Resources::GetImageData("layoutSwitchButton.png")), settingsIconData(Resources::GetImageData("settingsButton.png")), switchIcon(switchIconData),
settingsIcon(settingsIconData), 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.setImage(&settingsIcon);
settingsButton.setTrigger(&touchTrigger);
@ -68,8 +58,8 @@ public:
gameListFilterButton.clicked.connect(this, &MainDrcButtonsFrame::OnGameListFilterButtonClicked);
append(&gameListFilterButton);
}
virtual ~MainDrcButtonsFrame()
{
virtual ~MainDrcButtonsFrame() {
Resources::RemoveImageData(switchIconData);
Resources::RemoveImageData(settingsIconData);
Resources::RemoveSound(buttonClickSound);
@ -83,9 +73,11 @@ private:
void OnSettingsButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *) {
settingsButtonClicked(this);
}
void OnLayoutSwithClick(GuiButton *button, const GuiController *controller, GuiTrigger *) {
layoutSwitchClicked(this);
}
void OnGameListFilterButtonClicked(GuiButton *button, const GuiController *controller, GuiTrigger *) {
gameListFilterClicked(this);
}

View File

@ -29,14 +29,9 @@
#include "GameSplashScreen.h"
MainWindow::MainWindow(int32_t w, int32_t h)
: width(w)
, height(h)
, gameClickSound(Resources::GetSound("game_click.mp3"))
, 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);
: width(w), height(h), gameClickSound(Resources::GetSound("game_click.mp3")), mainSwitchButtonFrame(nullptr), currentTvFrame(nullptr), currentDrcFrame(nullptr) {
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());
pointerImg[i] = new GuiImage(pointerImgData[i]);
pointerImg[i]->setScale(1.5f);
@ -46,7 +41,7 @@ MainWindow::MainWindow(int32_t w, int32_t h)
gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged);
gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated);
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.titleUpdated.disconnect(this);
gameList.titleAdded.disconnect(this);
while(!tvElements.empty()) {
while (!tvElements.empty()) {
delete tvElements[0];
remove(tvElements[0]);
}
while(!drcElements.empty()) {
while (!drcElements.empty()) {
delete drcElements[0];
remove(drcElements[0]);
}
for(int32_t i = 0; i < 4; i++) {
for (int32_t i = 0; i < 4; i++) {
delete pointerImg[i];
Resources::RemoveImageData(pointerImgData[i]);
}
@ -75,18 +70,18 @@ void MainWindow::updateEffects() {
uint32_t tvSize = tvElements.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();
}
//! 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;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if(tvElements[i] == drcElements[n])
for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if (tvElements[i] == drcElements[n])
break;
}
if(n == drcElements.size()) {
if (n == drcElements.size()) {
tvElements[i]->updateEffects();
}
}
@ -97,24 +92,24 @@ void MainWindow::process() {
uint32_t tvSize = tvElements.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();
}
//! 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;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if(tvElements[i] == drcElements[n])
for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if (tvElements[i] == drcElements[n])
break;
}
if(n == drcElements.size()) {
if (n == drcElements.size()) {
tvElements[i]->process();
}
}
if(keyboardInstance != NULL) {
if(keyboardInstance->checkResult()) {
if (keyboardInstance != nullptr) {
if (keyboardInstance->checkResult()) {
std::string result = keyboardInstance->getResult();
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);
if(currentTvFrame != currentDrcFrame) {
if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->OnGameTitleListUpdated(list);
}
}
void MainWindow::OnGameTitleUpdated(gameInfo * info) {
void MainWindow::OnGameTitleUpdated(gameInfo *info) {
currentTvFrame->OnGameTitleUpdated(info);
if(currentTvFrame != currentDrcFrame) {
if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->OnGameTitleUpdated(info);
}
}
void MainWindow::OnGameTitleAdded(gameInfo * info) {
void MainWindow::OnGameTitleAdded(gameInfo *info) {
currentTvFrame->OnGameTitleAdded(info);
if(currentTvFrame != currentDrcFrame) {
if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->OnGameTitleAdded(info);
}
}
@ -150,16 +145,16 @@ void MainWindow::update(GuiController *controller) {
//! dont read behind the initial elements in case one was added
//uint32_t tvSize = tvElements.size();
if(controller->chan & GuiTrigger::CHANNEL_1) {
if (controller->chan & GuiTrigger::CHANNEL_1) {
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);
}
} else {
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);
}
}
@ -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;
float posX = controller->data.x;
float posY = controller->data.y;
@ -190,41 +185,41 @@ void MainWindow::update(GuiController *controller) {
}
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);
}
for(int32_t i = 0; i < 4; i++) {
if(pointerValid[i]) {
for (int32_t i = 0; i < 4; i++) {
if (pointerValid[i]) {
pointerImg[i]->setAlpha(0.5f);
pointerImg[i]->draw(video);
pointerImg[i]->setAlpha(1.0f);
}
}
if(keyboardInstance != NULL) {
if (keyboardInstance != nullptr) {
keyboardInstance->drawDRC();
}
}
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);
}
for(int32_t i = 0; i < 4; i++) {
if(pointerValid[i]) {
for (int32_t i = 0; i < 4; i++) {
if (pointerValid[i]) {
pointerImg[i]->draw(video);
pointerValid[i] = false;
}
}
if(keyboardInstance != NULL) {
if (keyboardInstance != nullptr) {
keyboardInstance->drawTV();
}
}
void MainWindow::SetupMainView() {
currentTvFrame = new GuiIconGrid(width, height,0, true);
currentTvFrame = new GuiIconGrid(width, height, 0, true);
currentTvFrame->setEffect(EFFECT_FADE, 10, 255);
currentTvFrame->setState(GuiElement::STATE_DISABLED);
@ -232,12 +227,12 @@ void MainWindow::SetupMainView() {
appendTv(currentTvFrame);
currentDrcFrame = new GuiIconGrid(width, height,0, false);
currentDrcFrame = new GuiIconGrid(width, height, 0, false);
currentDrcFrame->setEffect(EFFECT_FADE, 10, 255);
currentDrcFrame->setState(GuiElement::STATE_DISABLED);
currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
if(currentTvFrame != currentDrcFrame) {
if (currentTvFrame != currentDrcFrame) {
currentDrcFrame->setEffect(EFFECT_FADE, 10, 255);
currentDrcFrame->setState(GuiElement::STATE_DISABLED);
currentDrcFrame->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
@ -250,7 +245,7 @@ void MainWindow::SetupMainView() {
currentDrcFrame->gameLaunchClicked.disconnect(this);
if(currentTvFrame != currentDrcFrame) {
if (currentTvFrame != currentDrcFrame) {
currentTvFrame->gameSelectionChanged.connect(this, &MainWindow::OnGameSelectionChange);
currentTvFrame->gameLaunchClicked.connect(this, &MainWindow::OnGameLaunchSplashScreen);
}
@ -272,11 +267,11 @@ void MainWindow::SetupMainView() {
}
void MainWindow::OnLayoutSwitchClicked(GuiElement *element) {
if(!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) {
if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) {
return;
}
if(currentTvFrame == currentDrcFrame) {
if (currentTvFrame == currentDrcFrame) {
return;
}
@ -291,15 +286,15 @@ void MainWindow::OnLayoutSwitchClicked(GuiElement *element) {
}
void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) {
if(!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) {
if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame) {
return;
}
if(keyboardInstance == NULL) {
if (keyboardInstance == nullptr) {
keyboardInstance = new KeyboardHelper();
}
if(keyboardInstance->isReady()) {
if(keyboardInstance->openKeyboard()) {
if (keyboardInstance->isReady()) {
if (keyboardInstance->openKeyboard()) {
currentTvFrame->setState(GuiElement::STATE_DISABLED);
currentDrcFrame->setState(GuiElement::STATE_DISABLED);
mainSwitchButtonFrame->setState(GuiElement::STATE_DISABLED);
@ -308,7 +303,7 @@ void MainWindow::OnGameListFilterButtonClicked(GuiElement *element) {
}
void MainWindow::OnLayoutSwitchEffectFinish(GuiElement *element) {
if(!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame)
if (!currentTvFrame || !currentDrcFrame || !mainSwitchButtonFrame)
return;
element->effectFinished.disconnect(this);
@ -361,12 +356,12 @@ void MainWindow::OnSettingsButtonClicked(GuiElement *element) {
}
void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t selectedIdx) {
if(!currentDrcFrame || !currentTvFrame)
if (!currentDrcFrame || !currentTvFrame)
return;
if(element == currentDrcFrame && currentDrcFrame != currentTvFrame) {
if (element == currentDrcFrame && currentDrcFrame != currentTvFrame) {
currentTvFrame->setSelectedGame(selectedIdx);
} else if(element == currentTvFrame && currentDrcFrame != currentTvFrame) {
} else if (element == currentTvFrame && currentDrcFrame != currentTvFrame) {
currentDrcFrame->setSelectedGame(selectedIdx);
}
}
@ -376,26 +371,26 @@ void MainWindow::OnGameSelectionChange(GuiTitleBrowser *element, uint64_t select
#define MII_MAKER_USA_TITLE_ID (0x000500101004A100)
#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) {
gameInfo * info = gameList.getGameInfo(titleID);
if(info != NULL) {
void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser *element, uint64_t titleID) {
gameInfo *info = gameList.getGameInfo(titleID);
if (info != nullptr) {
uint64_t ownTitleId = OSGetTitleID();
if (ownTitleId == HBL_TITLE_ID ||
ownTitleId == MII_MAKER_JPN_TITLE_ID ||
ownTitleId == MII_MAKER_USA_TITLE_ID ||
ownTitleId == MII_MAKER_EUR_TITLE_ID) {
ownTitleId == MII_MAKER_JPN_TITLE_ID ||
ownTitleId == MII_MAKER_USA_TITLE_ID ||
ownTitleId == MII_MAKER_EUR_TITLE_ID) {
OnGameLaunch(titleID);
} else {
GameSplashScreen * gameSettingsDRC = new GameSplashScreen(width,height,info, false);
GameSplashScreen *gameSettingsDRC = new GameSplashScreen(width, height, info, false);
gameSettingsDRC->setEffect(EFFECT_FADE, 15, 255);
gameSettingsDRC->setState(GuiElement::STATE_DISABLED);
gameSettingsDRC->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
gameSettingsDRC->gameGameSplashScreenFinished.connect(this, &MainWindow::OnGameLaunchSplashScreenFinished);
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->setState(GuiElement::STATE_DISABLED);
gameSettingsTV->effectFinished.connect(this, &MainWindow::OnOpenEffectFinish);
@ -407,31 +402,32 @@ void MainWindow::OnGameLaunchSplashScreen(GuiTitleBrowser * element, uint64_t ti
}
}
void MainWindow::OnGameLaunchSplashScreenFinished(GuiElement * element, gameInfo * info, bool launchGame) {
if(info == NULL) {
void MainWindow::OnGameLaunchSplashScreenFinished(GuiElement *element, gameInfo *info, bool launchGame) {
if (info == nullptr) {
return;
}
if(launchGame) {
if (launchGame) {
OnGameLaunch(info->titleId);
}
if(element) {
if (element) {
element->setState(GuiElement::STATE_DISABLED);
element->setEffect(EFFECT_FADE, 15, 255);
element->effectFinished.connect(this, &MainWindow::OnCloseEffectFinish);
}
}
void MainWindow::OnGameLaunch(uint64_t titleID) {
gameInfo * info = gameList.getGameInfo(titleID);
if(info != NULL) {
gameInfo *info = gameList.getGameInfo(titleID);
if (info != nullptr) {
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) {
titleID == MII_MAKER_JPN_TITLE_ID ||
titleID == MII_MAKER_USA_TITLE_ID ||
titleID == MII_MAKER_EUR_TITLE_ID) {
SYSLaunchTitle(info->titleId);
} else {
const char* path = info->gamePath.c_str();
_SYSLaunchTitleByPathFromLauncher(path, strlen(path),0);
const char *path = info->gamePath.c_str();
_SYSLaunchTitleByPathFromLauncher(path, strlen(path), 0);
}
} else {
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<> {
public:
MainWindow(int32_t w, int32_t h);
virtual ~MainWindow();
void appendTv(GuiElement *e) {
if(!e)
if (!e)
return;
removeTv(e);
tvElements.push_back(e);
}
void appendDrc(GuiElement *e) {
if(!e)
if (!e)
return;
removeDrc(e);
@ -53,14 +55,15 @@ public:
}
void insertTv(uint32_t pos, GuiElement *e) {
if(!e)
if (!e)
return;
removeTv(e);
tvElements.insert(tvElements.begin() + pos, e);
}
void insertDrc(uint32_t pos, GuiElement *e) {
if(!e)
if (!e)
return;
removeDrc(e);
@ -73,16 +76,17 @@ public:
}
void removeTv(GuiElement *e) {
for(uint32_t i = 0; i < tvElements.size(); ++i) {
if(e == tvElements[i]) {
for (uint32_t i = 0; i < tvElements.size(); ++i) {
if (e == tvElements[i]) {
tvElements.erase(tvElements.begin() + i);
break;
}
}
}
void removeDrc(GuiElement *e) {
for(uint32_t i = 0; i < drcElements.size(); ++i) {
if(e == drcElements[i]) {
for (uint32_t i = 0; i < drcElements.size(); ++i) {
if (e == drcElements[i]) {
drcElements.erase(drcElements.begin() + i);
break;
}
@ -93,20 +97,26 @@ public:
removeTv(e);
removeDrc(e);
}
void removeAll() {
tvElements.clear();
drcElements.clear();
}
void drawDrc(CVideo *video);
void drawTv(CVideo *video);
void update(GuiController *controller);
void updateEffects();
void process();
void lockGUI() {
guiMutex.lock();
}
void unlockGUI() {
guiMutex.unlock();
}
@ -115,22 +125,30 @@ private:
void SetupMainView(void);
void OnOpenEffectFinish(GuiElement *element);
void OnCloseEffectFinish(GuiElement *element);
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 OnGameSelectionChange(GuiTitleBrowser *element, uint64_t titleId);
void OnSettingsButtonClicked(GuiElement *element);
void OnLayoutSwitchClicked(GuiElement *element);
void OnLayoutSwitchEffectFinish(GuiElement *element);
void OnGameListFilterButtonClicked(GuiElement *element);
void OnGameTitleListChanged(GameList * list);
void OnGameTitleUpdated(gameInfo * info);
void OnGameTitleAdded(gameInfo * info);
void OnGameTitleListChanged(GameList *list);
void OnGameTitleUpdated(gameInfo *info);
void OnGameTitleAdded(gameInfo *info);
int32_t width, height;
std::vector<GuiElement *> drcElements;
@ -140,8 +158,8 @@ private:
MainDrcButtonsFrame *mainSwitchButtonFrame;
GuiTitleBrowser * currentTvFrame;
GuiTitleBrowser * currentDrcFrame;
GuiTitleBrowser *currentTvFrame;
GuiTitleBrowser *currentDrcFrame;
GuiImageData *pointerImgData[4];
GuiImage *pointerImg[4];
@ -150,7 +168,7 @@ private:
GameList gameList;
std::recursive_mutex guiMutex;
KeyboardHelper * keyboardInstance = NULL;
KeyboardHelper *keyboardInstance = nullptr;
};
#endif //_MAIN_WINDOW_H_

View File

@ -15,38 +15,38 @@
#include <strings.h>
Resources * Resources::instance = NULL;
Resources *Resources::instance = nullptr;
void Resources::Clear() {
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) {
if(RecourceList[i].CustomFile) {
for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (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;
}
if(instance)
if (instance)
delete instance;
instance = NULL;
instance = nullptr;
}
bool Resources::LoadFiles(const char * path) {
if(!path)
bool Resources::LoadFiles(const char *path) {
if (!path)
return false;
bool result = false;
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);
fullpath += "/";
fullpath += RecourceList[i].filename;
uint8_t * buffer = NULL;
uint8_t *buffer = nullptr;
uint32_t filesize = 0;
FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize);
@ -59,44 +59,44 @@ bool Resources::LoadFiles(const char * path) {
return result;
}
const uint8_t * Resources::GetFile(const char * filename) {
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) {
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
const uint8_t *Resources::GetFile(const char *filename) {
for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) {
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
}
}
return NULL;
return nullptr;
}
uint32_t Resources::GetFileSize(const char * filename) {
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) {
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
uint32_t Resources::GetFileSize(const char *filename) {
for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) {
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize);
}
}
return 0;
}
GuiImageData * Resources::GetImageData(const char * filename) {
if(!instance)
GuiImageData *Resources::GetImageData(const char *filename) {
if (!instance)
instance = new Resources;
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++;
return itr->second.second;
}
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) {
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
const uint8_t * buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) {
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;
if(buff == NULL)
return NULL;
if (buff == nullptr)
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)].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;
for(itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) {
if(itr->second.second == image) {
for (itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) {
if (itr->second.second == image) {
itr->second.first--;
if(itr->second.first == 0) {
if (itr->second.first == 0) {
AsyncExecutor::pushForDelete(itr->second.second);
instance->imageDataMap.erase(itr);
@ -124,25 +124,25 @@ void Resources::RemoveImageData(GuiImageData * image) {
}
}
GuiSound * Resources::GetSound(const char * filename) {
if(!instance)
GuiSound *Resources::GetSound(const char *filename) {
if (!instance)
instance = new Resources;
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++;
return itr->second.second;
}
for(int32_t i = 0; RecourceList[i].filename != NULL; ++i) {
if(strcasecmp(filename, RecourceList[i].filename) == 0) {
const uint8_t * buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
for (int32_t i = 0; RecourceList[i].filename != nullptr; ++i) {
if (strcasecmp(filename, RecourceList[i].filename) == 0) {
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;
if(buff == NULL)
return NULL;
if (buff == nullptr)
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)].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;
for(itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) {
if(itr->second.second == sound) {
for (itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) {
if (itr->second.second == sound) {
itr->second.first--;
if(itr->second.first == 0) {
if (itr->second.first == 0) {
AsyncExecutor::pushForDelete(itr->second.second);
instance->soundDataMap.erase(itr);
}

View File

@ -5,24 +5,32 @@
//! forward declaration
class GuiImageData;
class GuiSound;
class Resources {
public:
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 void RemoveImageData(GuiImageData * image);
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 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:
static Resources *instance;
Resources() {}
~Resources() {}
std::map<std::string, std::pair<uint32_t, GuiImageData *> > imageDataMap;

View File

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

View File

@ -1,16 +1,17 @@
#include "AsyncExecutor.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();
deleteList.push(ptr);
deleteListMutex.unlock();
}
AsyncExecutor::AsyncExecutor() {
thread = new std::thread([&]() {
while(!exitThread) {
while (!exitThread) {
mutex.lock();
bool emptyList = elements.empty();
auto it = elements.begin();
@ -23,37 +24,37 @@ AsyncExecutor::AsyncExecutor() {
++it;
}
}
if(!emptyList && elements.empty()){
DEBUG_FUNCTION_LINE("All tasks are done\n");
if (!emptyList && elements.empty()) {
DEBUG_FUNCTION_LINE("All tasks are done");
}
mutex.unlock();
deleteListMutex.lock();
while(!deleteList.empty()) {
GuiElement * ptr = deleteList.front();
while (!deleteList.empty()) {
GuiElement *ptr = deleteList.front();
deleteList.pop();
delete ptr;
}
deleteListMutex.unlock();
std::this_thread::sleep_for(std::chrono::milliseconds(16));
DCFlushRange((void*)&exitThread, sizeof(exitThread));
DCFlushRange((void *) &exitThread, sizeof(exitThread));
}
});
}
AsyncExecutor::~AsyncExecutor() {
exitThread = true;
DCFlushRange((void*)&exitThread, sizeof(exitThread));
DCFlushRange((void *) &exitThread, sizeof(exitThread));
thread->join();
}
void AsyncExecutor::executeInternal(std::function<void()> func) {
if(elements.size() > 10) {
DEBUG_FUNCTION_LINE("Warning, many tasks running currently\n");
if (elements.size() > 10) {
DEBUG_FUNCTION_LINE("Warning, many tasks running currently");
//std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
DEBUG_FUNCTION_LINE("Add new task\n");
DEBUG_FUNCTION_LINE("Add new task");
mutex.lock();
elements.push_back(std::async(std::launch::async,func));
elements.push_back(std::async(std::launch::async, func));
mutex.unlock();
}

View File

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

View File

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

View File

@ -34,27 +34,36 @@
class StringTools {
public:
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 BOOL EndsWith(const std::string &a, const std::string &b);
static const char * FullpathToFilename(const char *path) {
if(!path)
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) {
if (!path)
return path;
const char * ptr = path;
const char * Filename = ptr;
const char *ptr = path;
const char *Filename = ptr;
while(*ptr != '\0') {
if(ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr+1;
while (*ptr != '\0') {
if (ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr + 1;
++ptr;
}
@ -66,8 +75,8 @@ public:
uint32_t length = str.size();
//! clear path of double slashes
for(uint32_t i = 1; i < length; ++i) {
if(str[i-1] == '/' && str[i] == '/') {
for (uint32_t i = 1; i < length; ++i) {
if (str[i - 1] == '/' && str[i] == '/') {
str.erase(i, 1);
i--;
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
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 */

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_
#define __LOGGER_H_
#pragma once
#include <whb/log.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#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__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#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); \
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -7,34 +7,34 @@
#include <utils/logger.h>
// 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];
size_t i, j;
ascii[16] = '\0';
DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data);
DEBUG_FUNCTION_LINE_WRITE("0x%08X (0x0000): ", data);
for (i = 0; i < size; ++i) {
log_printf("%02X ", ((unsigned char*)data)[i]);
if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') {
ascii[i % 16] = ((unsigned char*)data)[i];
WHBLogWritef("%02X ", ((unsigned char *) data)[i]);
if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') {
ascii[i % 16] = ((unsigned char *) data)[i];
} else {
ascii[i % 16] = '.';
}
if ((i+1) % 8 == 0 || i+1 == size) {
log_printf(" ");
if ((i+1) % 16 == 0) {
log_printf("| %s \n", ascii);
if(i + 1 < size) {
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1,i+1);
if ((i + 1) % 8 == 0 || i + 1 == size) {
WHBLogWritef(" ");
if ((i + 1) % 16 == 0) {
WHBLogWritef("| %s \n", ascii);
if (i + 1 < size) {
WHBLogWritef("0x%08X (0x%04X); ", data + i + 1, i + 1);
}
} else if (i+1 == size) {
ascii[(i+1) % 16] = '\0';
if ((i+1) % 16 <= 8) {
log_printf(" ");
} else if (i + 1 == size) {
ascii[(i + 1) % 16] = '\0';
if ((i + 1) % 16 <= 8) {
WHBLogWritef(" ");
}
for (j = (i+1) % 16; j < 16; ++j) {
log_printf(" ");
for (j = (i + 1) % 16; j < 16; ++j) {
WHBLogWritef(" ");
}
log_printf("| %s \n", ascii);
WHBLogWritef("| %s \n", ascii);
}
}
}

View File

@ -7,12 +7,12 @@
extern "C" {
#endif
#define LIMIT(x, min, max) \
({ \
typeof( x ) _x = x; \
typeof( min ) _min = min; \
typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
#define LIMIT(x, min, max) \
({ \
typeof( x ) _x = x; \
typeof( min ) _min = min; \
typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
})
#define DegToRad(a) ( (a) * 0.01745329252f )
@ -26,7 +26,7 @@ extern "C" {
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
//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
}