Format code

This commit is contained in:
Maschell 2020-07-05 13:34:13 +02:00
parent 39ce864c70
commit 349de9b582
37 changed files with 887 additions and 939 deletions

View File

@ -33,13 +33,7 @@ bool Application::exitApplication = false;
bool Application::quitRequest = false; bool Application::quitRequest = false;
Application::Application() Application::Application()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000) : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000), bgMusic(NULL), video(NULL), mainWindow(NULL), fontSystem(NULL), exitCode(0) {
, bgMusic(NULL)
, video(NULL)
, mainWindow(NULL)
, fontSystem(NULL)
, exitCode(0)
{
controller[0] = new VPadController(GuiTrigger::CHANNEL_1); controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
controller[1] = new WPadController(GuiTrigger::CHANNEL_2); controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
controller[2] = new WPadController(GuiTrigger::CHANNEL_3); controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
@ -57,8 +51,7 @@ Application::Application()
ProcUIInit(OSSavesDone_ReadyToRelease); ProcUIInit(OSSavesDone_ReadyToRelease);
} }
Application::~Application() Application::~Application() {
{
log_printf("Destroy music\n"); log_printf("Destroy music\n");
delete bgMusic; delete bgMusic;
@ -80,8 +73,7 @@ Application::~Application()
ProcUIShutdown(); ProcUIShutdown();
} }
int Application::exec() int Application::exec() {
{
//! start main GX2 thread //! start main GX2 thread
resumeThread(); resumeThread();
//! now wait for thread to finish //! now wait for thread to finish
@ -90,19 +82,16 @@ int Application::exec()
return exitCode; return exitCode;
} }
void Application::quit(int code) void Application::quit(int code) {
{
exitCode = code; exitCode = code;
exitApplication = true; exitApplication = true;
quitRequest = true; quitRequest = true;
} }
void Application::fadeOut() void Application::fadeOut() {
{
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) {0, 0, 0, 255}); GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) {0, 0, 0, 255});
for(int i = 0; i < 255; i += 10) for (int i = 0; i < 255; i += 10) {
{
if (i > 255) if (i > 255)
i = 255; i = 255;
@ -145,24 +134,19 @@ void Application::fadeOut()
video->drcEnable(false); video->drcEnable(false);
} }
bool Application::procUI(void) bool Application::procUI(void) {
{
bool executeProcess = false; bool executeProcess = false;
switch(ProcUIProcessMessages(true)) switch (ProcUIProcessMessages(true)) {
{ case PROCUI_STATUS_EXITING: {
case PROCUI_STATUS_EXITING:
{
log_printf("PROCUI_STATUS_EXITING\n"); log_printf("PROCUI_STATUS_EXITING\n");
exitCode = EXIT_SUCCESS; exitCode = EXIT_SUCCESS;
exitApplication = true; exitApplication = true;
break; break;
} }
case PROCUI_STATUS_RELEASE_FOREGROUND: case PROCUI_STATUS_RELEASE_FOREGROUND: {
{
log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n"); log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n");
if(video != NULL) if (video != NULL) {
{
// we can turn of the screen but we don't need to and it will display the last image // we can turn of the screen but we don't need to and it will display the last image
video->tvEnable(true); video->tvEnable(true);
video->drcEnable(true); video->drcEnable(true);
@ -178,19 +162,14 @@ bool Application::procUI(void)
log_printf("deinitialze memory\n"); log_printf("deinitialze memory\n");
memoryRelease(); memoryRelease();
ProcUIDrawDoneRelease(); ProcUIDrawDoneRelease();
} } else {
else
{
ProcUIDrawDoneRelease(); ProcUIDrawDoneRelease();
} }
break; break;
} }
case PROCUI_STATUS_IN_FOREGROUND: case PROCUI_STATUS_IN_FOREGROUND: {
{ if (!quitRequest) {
if(!quitRequest) if (video == NULL) {
{
if(video == NULL)
{
log_printf("PROCUI_STATUS_IN_FOREGROUND\n"); log_printf("PROCUI_STATUS_IN_FOREGROUND\n");
log_printf("initialze memory\n"); log_printf("initialze memory\n");
memoryInitialize(); memoryInitialize();
@ -204,8 +183,7 @@ bool Application::procUI(void)
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true); FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem); GuiText::setPresetFont(fontSystem);
if(mainWindow == NULL) if (mainWindow == NULL) {
{
log_printf("Initialize main window\n"); log_printf("Initialize main window\n");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight()); mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
} }
@ -223,19 +201,16 @@ bool Application::procUI(void)
return executeProcess; return executeProcess;
} }
void Application::executeThread(void) void Application::executeThread(void) {
{
log_printf("Entering main loop\n"); log_printf("Entering main loop\n");
//! main GX2 loop (60 Hz cycle with max priority on core 1) //! main GX2 loop (60 Hz cycle with max priority on core 1)
while(!exitApplication) while (!exitApplication) {
{
if (procUI() == false) if (procUI() == false)
continue; continue;
//! Read out inputs //! Read out inputs
for(int i = 0; i < 5; i++) for (int i = 0; i < 5; i++) {
{
if (controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false) if (controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
continue; continue;
@ -273,8 +248,7 @@ void Application::executeThread(void)
} }
//! in case we exit to a homebrew let's smoothly fade out //! in case we exit to a homebrew let's smoothly fade out
if(video) if (video) {
{
fadeOut(); fadeOut();
} }

View File

@ -24,14 +24,14 @@
// forward declaration // forward declaration
class FreeTypeGX; class FreeTypeGX;
class Application : public CThread class Application : public CThread {
{
public: public:
static Application *instance() { static Application *instance() {
if (!applicationInstance) if (!applicationInstance)
applicationInstance = new Application(); applicationInstance = new Application();
return applicationInstance; return applicationInstance;
} }
static void destroyInstance() { static void destroyInstance() {
if (applicationInstance) { if (applicationInstance) {
delete applicationInstance; delete applicationInstance;
@ -42,6 +42,7 @@ public:
CVideo *getVideo(void) const { CVideo *getVideo(void) const {
return video; return video;
} }
MainWindow *getMainWindow(void) const { MainWindow *getMainWindow(void) const {
return mainWindow; return mainWindow;
} }
@ -51,12 +52,14 @@ public:
} }
int exec(void); int exec(void);
void fadeOut(void); void fadeOut(void);
void quit(int code); void quit(int code);
private: private:
Application(); Application();
virtual ~Application(); virtual ~Application();
bool procUI(void); bool procUI(void);

View File

@ -2,8 +2,7 @@
#include <sysapp/launch.h> #include <sysapp/launch.h>
#include "main.h" #include "main.h"
int main(int argc, char **argv) int main(int argc, char **argv) {
{
//! ******************************************************************* //! *******************************************************************
//! * Jump to our application * //! * Jump to our application *
//! ******************************************************************* //! *******************************************************************

View File

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

View File

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

View File

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

View File

@ -23,8 +23,7 @@
* Constructor for the GuiButton class. * Constructor for the GuiButton class.
*/ */
Background::Background(char *picture, float scroll_speed) Background::Background(char *picture, float scroll_speed) {
{
loc_x = 0.0f; loc_x = 0.0f;
bgImg = Resources::GetImageData(picture); bgImg = Resources::GetImageData(picture);
@ -41,8 +40,7 @@ Background::Background(char *picture, float scroll_speed)
/** /**
* Destructor for the GuiButton class. * Destructor for the GuiButton class.
*/ */
Background::~Background() Background::~Background() {
{
speed = 0.0f; speed = 0.0f;
loc_x = 0.0f; loc_x = 0.0f;
delete (bgImg); delete (bgImg);
@ -50,16 +48,14 @@ Background::~Background()
delete (bgs); delete (bgs);
} }
void Background::setScrollSpeed(float scroll_speed) void Background::setScrollSpeed(float scroll_speed) {
{
speed = scroll_speed; speed = scroll_speed;
} }
/** /**
* Draw the button on screen * Draw the button on screen
*/ */
void Background::draw(CVideo *v) void Background::draw(CVideo *v) {
{
if (speed > 0.0f) { if (speed > 0.0f) {
loc_x -= speed; loc_x -= speed;
if (loc_x < 0.0f) loc_x = 1280.0f; if (loc_x < 0.0f) loc_x = 1280.0f;
@ -76,7 +72,6 @@ void Background::draw(CVideo *v)
bgs->draw(v); bgs->draw(v);
} }
void Background::update(GuiController * c) void Background::update(GuiController *c) {
{
} }

View File

@ -25,14 +25,18 @@
#include "gui/GuiTrigger.h" #include "gui/GuiTrigger.h"
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class Background : public GuiElement class Background : public GuiElement {
{
public: public:
Background(char *picture, float scroll_speed); Background(char *picture, float scroll_speed);
virtual ~Background(); virtual ~Background();
void setScrollSpeed(float scroll_speed); void setScrollSpeed(float scroll_speed);
void draw(CVideo *video); void draw(CVideo *video);
void update(GuiController *c); void update(GuiController *c);
protected: protected:
GuiImageData *bgImg; GuiImageData *bgImg;
GuiImage *bg; GuiImage *bg;

View File

@ -24,8 +24,7 @@
* Constructor for the GuiButton class. * Constructor for the GuiButton class.
*/ */
Pipe::Pipe(float x) Pipe::Pipe(float x) {
{
srand(OSGetTime()); srand(OSGetTime());
loc_y = rand() % 250 - 125; loc_y = rand() % 250 - 125;
loc_x = x; loc_x = x;
@ -46,8 +45,7 @@ Pipe::Pipe(float x)
/** /**
* Destructor for the GuiButton class. * Destructor for the GuiButton class.
*/ */
Pipe::~Pipe() Pipe::~Pipe() {
{
loc_x = 0.0f; loc_x = 0.0f;
loc_y = 0.0f; loc_y = 0.0f;
scroll_state = 0; scroll_state = 0;
@ -57,21 +55,19 @@ Pipe::~Pipe()
delete (pipeBottomImg); delete (pipeBottomImg);
} }
void Pipe::setPosX(float x) void Pipe::setPosX(float x) {
{
loc_x = x; loc_x = x;
pipebottom->setPosition((int) loc_x, -410 - loc_y); pipebottom->setPosition((int) loc_x, -410 - loc_y);
pipetop->setPosition((int) loc_x, 410 - loc_y); pipetop->setPosition((int) loc_x, 410 - loc_y);
} }
void Pipe::setScroll(bool state) void Pipe::setScroll(bool state) {
{
scroll_state = state; scroll_state = state;
} }
int Pipe::checkCollision(GuiImage* check) int Pipe::checkCollision(GuiImage *check) {
{ if ((pipetop->getLeft() - pipetop->getWidth() / 4.0f) < (check->getLeft() + check->getWidth() / 2.0f) &&
if((pipetop->getLeft()-pipetop->getWidth()/4.0f)<(check->getLeft()+check->getWidth()/2.0f) && (pipetop->getLeft()+pipetop->getWidth()/2)>(check->getLeft()-check->getWidth()/2.0f)) { //How can that thing work? No, really... (pipetop->getLeft() + pipetop->getWidth() / 2) > (check->getLeft() - check->getWidth() / 2.0f)) { //How can that thing work? No, really...
poss_collision = 1; poss_collision = 1;
if ((check->getTop() + check->getHeight() / 2.0f) > (pipetop->getTop() - 720.0f) || ((check->getTop() - check->getHeight() / 2.0f)) < pipebottom->getTop()) { if ((check->getTop() + check->getHeight() / 2.0f) > (pipetop->getTop() - 720.0f) || ((check->getTop() - check->getHeight() / 2.0f)) < pipebottom->getTop()) {
poss_collision = 0; //we already collided poss_collision = 0; //we already collided
@ -88,8 +84,7 @@ int Pipe::checkCollision(GuiImage* check)
/** /**
* Draw the button on screen * Draw the button on screen
*/ */
void Pipe::draw(CVideo *v) void Pipe::draw(CVideo *v) {
{
if (scroll_state == true) { if (scroll_state == true) {
loc_x -= 1.5f; loc_x -= 1.5f;
if (loc_x < -640.0f) { if (loc_x < -640.0f) {
@ -108,7 +103,6 @@ void Pipe::draw(CVideo *v)
pipetop->draw(v); pipetop->draw(v);
} }
void Pipe::update(GuiController * c) void Pipe::update(GuiController *c) {
{
} }

View File

@ -25,16 +25,22 @@
#include "gui/GuiTrigger.h" #include "gui/GuiTrigger.h"
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class Pipe : public GuiElement class Pipe : public GuiElement {
{
public: public:
Pipe(float x); Pipe(float x);
virtual ~Pipe(); virtual ~Pipe();
void setPosX(float x); void setPosX(float x);
void setScroll(bool state); void setScroll(bool state);
int checkCollision(GuiImage *check); int checkCollision(GuiImage *check);
void draw(CVideo *video); void draw(CVideo *video);
void update(GuiController *c); void update(GuiController *c);
protected: protected:
GuiImageData *pipeBottomImg; GuiImageData *pipeBottomImg;
GuiImageData *pipeTopImg; GuiImageData *pipeTopImg;

View File

@ -23,8 +23,7 @@
* Constructor for the GuiButton class. * Constructor for the GuiButton class.
*/ */
ScoreImage::ScoreImage(int x, int y) ScoreImage::ScoreImage(int x, int y) {
{
digitsImagesData[0] = Resources::GetImageData("font_big_0.png"); digitsImagesData[0] = Resources::GetImageData("font_big_0.png");
digitsImagesData[1] = Resources::GetImageData("font_big_1.png"); digitsImagesData[1] = Resources::GetImageData("font_big_1.png");
digitsImagesData[2] = Resources::GetImageData("font_big_2.png"); digitsImagesData[2] = Resources::GetImageData("font_big_2.png");
@ -49,13 +48,11 @@ ScoreImage::ScoreImage(int x, int y)
/** /**
* Destructor for the GuiButton class. * Destructor for the GuiButton class.
*/ */
ScoreImage::~ScoreImage() ScoreImage::~ScoreImage() {
{
//for (int i=0;i<11;i++) delete(digitsImagesData[i]); //for (int i=0;i<11;i++) delete(digitsImagesData[i]);
} }
void ScoreImage::setScore(int score) void ScoreImage::setScore(int score) {
{
//Yeah, that's hacky and there are unusefull functions :P //Yeah, that's hacky and there are unusefull functions :P
if (score > 999) score = 999; //That's unlikey but... if (score > 999) score = 999; //That's unlikey but...
for (int a = 0; a < 3; a++) digits[a] = 10; //Initialize digits to 10 (=don't draw) for (int a = 0; a < 3; a++) digits[a] = 10; //Initialize digits to 10 (=don't draw)
@ -71,8 +68,7 @@ void ScoreImage::setScore(int score)
/** /**
* Draw the button on screen * Draw the button on screen
*/ */
void ScoreImage::draw(CVideo *v) void ScoreImage::draw(CVideo *v) {
{
if (!this->isVisible()) if (!this->isVisible())
return; return;
@ -82,7 +78,6 @@ void ScoreImage::draw(CVideo *v)
digitsImages[2]->draw(v); digitsImages[2]->draw(v);
} }
void ScoreImage::update(GuiController * c) void ScoreImage::update(GuiController *c) {
{
} }

View File

@ -25,14 +25,18 @@
#include "gui/GuiTrigger.h" #include "gui/GuiTrigger.h"
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class ScoreImage : public GuiElement class ScoreImage : public GuiElement {
{
public: public:
ScoreImage(int x, int y); ScoreImage(int x, int y);
virtual ~ScoreImage(); virtual ~ScoreImage();
void setScore(int score); void setScore(int score);
void draw(CVideo *video); void draw(CVideo *video);
void update(GuiController *c); void update(GuiController *c);
protected: protected:
GuiImageData *digitsImagesData[11]; //Our 10 numers + 1 null digit :P GuiImageData *digitsImagesData[11]; //Our 10 numers + 1 null digit :P
GuiImage *digitsImages[3]; GuiImage *digitsImages[3];

View File

@ -22,8 +22,7 @@
* Constructor for the GuiButton class. * Constructor for the GuiButton class.
*/ */
SplashScreen::SplashScreen(GuiImageData * img) SplashScreen::SplashScreen(GuiImageData *img) {
{
img_real = new GuiImage(img); img_real = new GuiImage(img);
img_real->setAlignment(ALIGN_CENTER | ALIGN_CENTER); img_real->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
img_real->setPosition(0, 0); img_real->setPosition(0, 0);
@ -32,25 +31,22 @@ SplashScreen::SplashScreen(GuiImageData * img)
/** /**
* Destructor for the GuiButton class. * Destructor for the GuiButton class.
*/ */
SplashScreen::~SplashScreen() SplashScreen::~SplashScreen() {
{
state = 0; state = 0;
delete (img_real); delete (img_real);
} }
void SplashScreen::setSplashImageData(GuiImageData * img) void SplashScreen::setSplashImageData(GuiImageData *img) {
{
img_real->setImageData(img); img_real->setImageData(img);
} }
void SplashScreen::FadeExit() void SplashScreen::FadeExit() {
{
trasparency = 1.0f; trasparency = 1.0f;
state = 1; state = 1;
img_real->setAlpha(trasparency); img_real->setAlpha(trasparency);
} }
void SplashScreen::FadeEnter()
{ void SplashScreen::FadeEnter() {
trasparency = 0.0f; trasparency = 0.0f;
state = 2; state = 2;
img_real->setAlpha(trasparency); img_real->setAlpha(trasparency);
@ -60,8 +56,7 @@ void SplashScreen::FadeEnter()
/** /**
* Draw the button on screen * Draw the button on screen
*/ */
void SplashScreen::draw(CVideo *v) void SplashScreen::draw(CVideo *v) {
{
if (state != 0) { if (state != 0) {
switch (state) { switch (state) {
case 1: case 1:
@ -86,7 +81,6 @@ void SplashScreen::draw(CVideo *v)
img_real->draw(v); img_real->draw(v);
} }
void SplashScreen::update(GuiController * c) void SplashScreen::update(GuiController *c) {
{
} }

View File

@ -25,16 +25,22 @@
#include "gui/GuiTrigger.h" #include "gui/GuiTrigger.h"
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
class SplashScreen : public GuiElement class SplashScreen : public GuiElement {
{
public: public:
SplashScreen(GuiImageData *img); SplashScreen(GuiImageData *img);
virtual ~SplashScreen(); virtual ~SplashScreen();
void setSplashImageData(GuiImageData *img); void setSplashImageData(GuiImageData *img);
void FadeExit(); void FadeExit();
void FadeEnter(); void FadeEnter();
void draw(CVideo *video); void draw(CVideo *video);
void update(GuiController *c); void update(GuiController *c);
protected: protected:
GuiImage *img_real; GuiImage *img_real;
int state; int state;

View File

@ -19,10 +19,10 @@
#include <gui/Gui.h> #include <gui/Gui.h>
class GuiMainWindowScreen : public GuiFrame class GuiMainWindowScreen : public GuiFrame {
{
public: public:
GuiMainWindowScreen(int w, int h) : GuiFrame(w, h) {} GuiMainWindowScreen(int w, int h) : GuiFrame(w, h) {}
virtual ~GuiMainWindowScreen() {} virtual ~GuiMainWindowScreen() {}
}; };

View File

@ -6,8 +6,7 @@
#include "utils/utils.h" #include "utils/utils.h"
/* Entry point */ /* Entry point */
extern "C" int Menu_Main(void) extern "C" int Menu_Main(void) {
{
//!******************************************************************* //!*******************************************************************
//! Initialize function pointers * //! Initialize function pointers *
//!******************************************************************* //!*******************************************************************

View File

@ -24,11 +24,8 @@
#include "system/AsyncDeleter.h" #include "system/AsyncDeleter.h"
MainWindow::MainWindow(int w, int h) MainWindow::MainWindow(int w, int h)
: width(w) : width(w), height(h) {
, height(h) for (int i = 0; i < 4; i++) {
{
for(int i = 0; i < 4; i++)
{
std::string filename = StringTools::strfmt("player%i_point.png", i + 1); std::string filename = StringTools::strfmt("player%i_point.png", i + 1);
pointerImgData[i] = Resources::GetImageData(filename.c_str()); pointerImgData[i] = Resources::GetImageData(filename.c_str());
pointerImg[i] = new GuiImage(pointerImgData[i]); pointerImg[i] = new GuiImage(pointerImgData[i]);
@ -39,48 +36,39 @@ MainWindow::MainWindow(int w, int h)
SetupMainView(); SetupMainView();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow() {
{
while(!tvElements.empty()) while (!tvElements.empty()) {
{
delete tvElements[0]; delete tvElements[0];
remove(tvElements[0]); remove(tvElements[0]);
} }
while(!drcElements.empty()) while (!drcElements.empty()) {
{
delete drcElements[0]; delete drcElements[0];
remove(drcElements[0]); remove(drcElements[0]);
} }
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++) {
{
delete pointerImg[i]; delete pointerImg[i];
Resources::RemoveImageData(pointerImgData[i]); Resources::RemoveImageData(pointerImgData[i]);
} }
} }
void MainWindow::updateEffects() void MainWindow::updateEffects() {
{
//! dont read behind the initial elements in case one was added //! dont read behind the initial elements in case one was added
uint32_t tvSize = tvElements.size(); uint32_t tvSize = tvElements.size();
uint32_t drcSize = drcElements.size(); uint32_t drcSize = drcElements.size();
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
{
drcElements[i]->updateEffects(); drcElements[i]->updateEffects();
} }
//! only update TV elements that are not updated yet because they are on DRC //! only update TV elements that are not updated yet because they are on DRC
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
{
uint32_t n; uint32_t n;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
{
if (tvElements[i] == drcElements[n]) if (tvElements[i] == drcElements[n])
break; break;
} }
if(n == drcElements.size()) if (n == drcElements.size()) {
{
tvElements[i]->updateEffects(); tvElements[i]->updateEffects();
} }
} }
@ -91,47 +79,37 @@ void MainWindow::process(){
uint32_t tvSize = tvElements.size(); uint32_t tvSize = tvElements.size();
uint32_t drcSize = drcElements.size(); uint32_t drcSize = drcElements.size();
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
{
drcElements[i]->process(); drcElements[i]->process();
} }
//! only update TV elements that are not updated yet because they are on DRC //! only update TV elements that are not updated yet because they are on DRC
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
{
uint32_t n; uint32_t n;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++) for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
{
if (tvElements[i] == drcElements[n]) if (tvElements[i] == drcElements[n])
break; break;
} }
if(n == drcElements.size()) if (n == drcElements.size()) {
{
tvElements[i]->process(); tvElements[i]->process();
} }
} }
} }
void MainWindow::update(GuiController *controller) void MainWindow::update(GuiController *controller) {
{
//! dont read behind the initial elements in case one was added //! dont read behind the initial elements in case one was added
//uint32_t tvSize = tvElements.size(); //uint32_t tvSize = tvElements.size();
if(controller->chan & GuiTrigger::CHANNEL_1) if (controller->chan & GuiTrigger::CHANNEL_1) {
{
uint32_t drcSize = drcElements.size(); uint32_t drcSize = drcElements.size();
for(uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) for (uint32_t i = 0; (i < drcSize) && (i < drcElements.size()); ++i) {
{
drcElements[i]->update(controller); drcElements[i]->update(controller);
} }
} } else {
else
{
uint32_t tvSize = tvElements.size(); uint32_t tvSize = tvElements.size();
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
{
tvElements[i]->update(controller); tvElements[i]->update(controller);
} }
} }
@ -151,8 +129,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) {
{
int wpadIdx = controller->chanIdx - 1; int wpadIdx = controller->chanIdx - 1;
float posX = controller->data.x; float posX = controller->data.x;
float posY = controller->data.y; float posY = controller->data.y;
@ -162,17 +139,13 @@ void MainWindow::update(GuiController *controller)
} }
} }
void MainWindow::drawDrc(CVideo *video) void MainWindow::drawDrc(CVideo *video) {
{ for (uint32_t i = 0; i < drcElements.size(); ++i) {
for(uint32_t i = 0; i < drcElements.size(); ++i)
{
drcElements[i]->draw(video); drcElements[i]->draw(video);
} }
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++) {
{ if (pointerValid[i]) {
if(pointerValid[i])
{
pointerImg[i]->setAlpha(0.5f); pointerImg[i]->setAlpha(0.5f);
pointerImg[i]->draw(video); pointerImg[i]->draw(video);
pointerImg[i]->setAlpha(1.0f); pointerImg[i]->setAlpha(1.0f);
@ -180,25 +153,20 @@ void MainWindow::drawDrc(CVideo *video)
} }
} }
void MainWindow::drawTv(CVideo *video) void MainWindow::drawTv(CVideo *video) {
{ for (uint32_t i = 0; i < tvElements.size(); ++i) {
for(uint32_t i = 0; i < tvElements.size(); ++i)
{
tvElements[i]->draw(video); tvElements[i]->draw(video);
} }
for(int i = 0; i < 4; i++) for (int i = 0; i < 4; i++) {
{ if (pointerValid[i]) {
if(pointerValid[i])
{
pointerImg[i]->draw(video); pointerImg[i]->draw(video);
pointerValid[i] = false; pointerValid[i] = false;
} }
} }
} }
void MainWindow::SetupMainView() void MainWindow::SetupMainView() {
{
//DrcFrame = new MainWindowDRC(width,height); //DrcFrame = new MainWindowDRC(width,height);
TvFrame = new MainWindowTV(width, height); TvFrame = new MainWindowTV(width, height);
@ -207,15 +175,13 @@ void MainWindow::SetupMainView()
appendDrc(DrcFrame); appendDrc(DrcFrame);
} }
void MainWindow::OnOpenEffectFinish(GuiElement *element) void MainWindow::OnOpenEffectFinish(GuiElement *element) {
{
//! once the menu is open reset its state and allow it to be "clicked/hold" //! once the menu is open reset its state and allow it to be "clicked/hold"
element->effectFinished.disconnect(this); element->effectFinished.disconnect(this);
element->clearState(GuiElement::STATE_DISABLED); element->clearState(GuiElement::STATE_DISABLED);
} }
void MainWindow::OnCloseEffectFinish(GuiElement *element) void MainWindow::OnCloseEffectFinish(GuiElement *element) {
{
//! remove element from draw list and push to delete queue //! remove element from draw list and push to delete queue
remove(element); remove(element);
AsyncDeleter::pushForDelete(element); AsyncDeleter::pushForDelete(element);

View File

@ -26,22 +26,21 @@
class CVideo; class CVideo;
class MainWindow : public sigslot::has_slots<> class MainWindow : public sigslot::has_slots<> {
{
public: public:
MainWindow(int w, int h); MainWindow(int w, int h);
virtual ~MainWindow(); virtual ~MainWindow();
void appendTv(GuiElement *e) void appendTv(GuiElement *e) {
{
if (!e) if (!e)
return; return;
removeTv(e); removeTv(e);
tvElements.push_back(e); tvElements.push_back(e);
} }
void appendDrc(GuiElement *e)
{ void appendDrc(GuiElement *e) {
if (!e) if (!e)
return; return;
@ -49,22 +48,20 @@ public:
drcElements.push_back(e); drcElements.push_back(e);
} }
void append(GuiElement *e) void append(GuiElement *e) {
{
appendTv(e); appendTv(e);
appendDrc(e); appendDrc(e);
} }
void insertTv(uint32_t pos, GuiElement *e) void insertTv(uint32_t pos, GuiElement *e) {
{
if (!e) if (!e)
return; return;
removeTv(e); removeTv(e);
tvElements.insert(tvElements.begin() + pos, e); tvElements.insert(tvElements.begin() + pos, e);
} }
void insertDrc(uint32_t pos, GuiElement *e)
{ void insertDrc(uint32_t pos, GuiElement *e) {
if (!e) if (!e)
return; return;
@ -72,59 +69,54 @@ public:
drcElements.insert(drcElements.begin() + pos, e); drcElements.insert(drcElements.begin() + pos, e);
} }
void insert(uint32_t pos, GuiElement *e) void insert(uint32_t pos, GuiElement *e) {
{
insertTv(pos, e); insertTv(pos, e);
insertDrc(pos, e); insertDrc(pos, e);
} }
void removeTv(GuiElement *e) void removeTv(GuiElement *e) {
{ for (uint32_t i = 0; i < tvElements.size(); ++i) {
for(uint32_t i = 0; i < tvElements.size(); ++i) if (e == tvElements[i]) {
{
if(e == tvElements[i])
{
tvElements.erase(tvElements.begin() + i); tvElements.erase(tvElements.begin() + i);
break; break;
} }
} }
} }
void removeDrc(GuiElement *e)
{ void removeDrc(GuiElement *e) {
for(uint32_t i = 0; i < drcElements.size(); ++i) for (uint32_t i = 0; i < drcElements.size(); ++i) {
{ if (e == drcElements[i]) {
if(e == drcElements[i])
{
drcElements.erase(drcElements.begin() + i); drcElements.erase(drcElements.begin() + i);
break; break;
} }
} }
} }
void remove(GuiElement *e) void remove(GuiElement *e) {
{
removeTv(e); removeTv(e);
removeDrc(e); removeDrc(e);
} }
void removeAll()
{ void removeAll() {
tvElements.clear(); tvElements.clear();
drcElements.clear(); drcElements.clear();
} }
void drawDrc(CVideo *video); void drawDrc(CVideo *video);
void drawTv(CVideo *video); void drawTv(CVideo *video);
void update(GuiController *controller); void update(GuiController *controller);
void updateEffects(); void updateEffects();
void process(); void process();
void lockGUI() void lockGUI() {
{
guiMutex.lock(); guiMutex.lock();
} }
void unlockGUI()
{ void unlockGUI() {
guiMutex.unlock(); guiMutex.unlock();
} }
@ -132,6 +124,7 @@ private:
void SetupMainView(void); void SetupMainView(void);
void OnOpenEffectFinish(GuiElement *element); void OnOpenEffectFinish(GuiElement *element);
void OnCloseEffectFinish(GuiElement *element); void OnCloseEffectFinish(GuiElement *element);
int width, height; int width, height;

View File

@ -20,11 +20,7 @@
#include "resources/Resources.h" #include "resources/Resources.h"
MainWindowTV::MainWindowTV(int w, int h) MainWindowTV::MainWindowTV(int w, int h)
: GuiMainWindowScreen(w, h) : GuiMainWindowScreen(w, h), width(w), height(h), bgImageColor(w, h, (GX2Color) {0, 0, 0, 0}) {
, width(w)
, height(h)
,bgImageColor(w, h, (GX2Color){ 0, 0, 0, 0 })
{
bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 0); bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 0);
bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 1); bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 1);
bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 2); bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 2);
@ -32,8 +28,6 @@ MainWindowTV::MainWindowTV(int w, int h)
append(&bgImageColor); append(&bgImageColor);
wingSound = new GuiSound(Resources::GetFile("sfx_wing.ogg"), Resources::GetFileSize("sfx_wing.ogg")); wingSound = new GuiSound(Resources::GetFile("sfx_wing.ogg"), Resources::GetFileSize("sfx_wing.ogg"));
pointSound = new GuiSound(Resources::GetFile("sfx_point.ogg"), Resources::GetFileSize("sfx_point.ogg")); pointSound = new GuiSound(Resources::GetFile("sfx_point.ogg"), Resources::GetFileSize("sfx_point.ogg"));
swooshSound = new GuiSound(Resources::GetFile("sfx_swooshing.ogg"), Resources::GetFileSize("sfx_swooshing.ogg")); swooshSound = new GuiSound(Resources::GetFile("sfx_swooshing.ogg"), Resources::GetFileSize("sfx_swooshing.ogg"));
@ -84,8 +78,7 @@ MainWindowTV::MainWindowTV(int w, int h)
//append(hello); //append(hello);
} }
MainWindowTV::~MainWindowTV() MainWindowTV::~MainWindowTV() {
{
remove(&bgImageColor); remove(&bgImageColor);
delete (wingSound); delete (wingSound);
delete (swooshSound); delete (swooshSound);

View File

@ -38,7 +38,9 @@ class CVideo;
class MainWindowTV : public GuiMainWindowScreen { class MainWindowTV : public GuiMainWindowScreen {
public: public:
MainWindowTV(int w, int h); MainWindowTV(int w, int h);
virtual ~MainWindowTV(); virtual ~MainWindowTV();
private: private:
int width, height; int width, height;
@ -87,7 +89,9 @@ private:
float flappy_bird_rotation = 0.0f; float flappy_bird_rotation = 0.0f;
void draw(CVideo *v); void draw(CVideo *v);
void update(GuiController *c); void update(GuiController *c);
void process(); void process();
}; };

View File

@ -9,12 +9,9 @@
Resources *Resources::instance = NULL; Resources *Resources::instance = NULL;
void Resources::Clear() void Resources::Clear() {
{ for (int i = 0; RecourceList[i].filename != NULL; ++i) {
for(int i = 0; RecourceList[i].filename != NULL; ++i) if (RecourceList[i].CustomFile) {
{
if(RecourceList[i].CustomFile)
{
free(RecourceList[i].CustomFile); free(RecourceList[i].CustomFile);
RecourceList[i].CustomFile = NULL; RecourceList[i].CustomFile = NULL;
} }
@ -29,16 +26,14 @@ void Resources::Clear()
instance = NULL; instance = NULL;
} }
bool Resources::LoadFiles(const char * path) bool Resources::LoadFiles(const char *path) {
{
if (!path) if (!path)
return false; return false;
bool result = false; bool result = false;
Clear(); Clear();
for(int i = 0; RecourceList[i].filename != NULL; ++i) for (int i = 0; RecourceList[i].filename != NULL; ++i) {
{
std::string fullpath(path); std::string fullpath(path);
fullpath += "/"; fullpath += "/";
fullpath += RecourceList[i].filename; fullpath += RecourceList[i].filename;
@ -56,12 +51,9 @@ bool Resources::LoadFiles(const char * path)
return result; return result;
} }
const uint8_t * Resources::GetFile(const char * filename) const uint8_t *Resources::GetFile(const char *filename) {
{ for (int i = 0; RecourceList[i].filename != NULL; ++i) {
for(int i = 0; RecourceList[i].filename != NULL; ++i) if (strcasecmp(filename, RecourceList[i].filename) == 0) {
{
if(strcasecmp(filename, RecourceList[i].filename) == 0)
{
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile); return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
} }
} }
@ -69,34 +61,27 @@ const uint8_t * Resources::GetFile(const char * filename)
return NULL; return NULL;
} }
uint32_t Resources::GetFileSize(const char * filename) uint32_t Resources::GetFileSize(const char *filename) {
{ for (int i = 0; RecourceList[i].filename != NULL; ++i) {
for(int i = 0; RecourceList[i].filename != NULL; ++i) if (strcasecmp(filename, RecourceList[i].filename) == 0) {
{
if(strcasecmp(filename, RecourceList[i].filename) == 0)
{
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize); return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize);
} }
} }
return 0; return 0;
} }
GuiImageData * Resources::GetImageData(const char * filename) GuiImageData *Resources::GetImageData(const char *filename) {
{
if (!instance) if (!instance)
instance = new Resources; instance = new Resources;
std::map<std::string, std::pair<unsigned int, GuiImageData *> >::iterator itr = instance->imageDataMap.find(std::string(filename)); std::map<std::string, std::pair<unsigned int, GuiImageData *> >::iterator itr = instance->imageDataMap.find(std::string(filename));
if(itr != instance->imageDataMap.end()) if (itr != instance->imageDataMap.end()) {
{
itr->second.first++; itr->second.first++;
return itr->second.second; return itr->second.second;
} }
for(int i = 0; RecourceList[i].filename != NULL; ++i) for (int i = 0; RecourceList[i].filename != NULL; ++i) {
{ if (strcasecmp(filename, RecourceList[i].filename) == 0) {
if(strcasecmp(filename, RecourceList[i].filename) == 0)
{
const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile; const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize; const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
@ -114,18 +99,14 @@ GuiImageData * Resources::GetImageData(const char * filename)
return NULL; return NULL;
} }
void Resources::RemoveImageData(GuiImageData * image) void Resources::RemoveImageData(GuiImageData *image) {
{
std::map<std::string, std::pair<unsigned int, GuiImageData *> >::iterator itr; std::map<std::string, std::pair<unsigned int, GuiImageData *> >::iterator itr;
for(itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) for (itr = instance->imageDataMap.begin(); itr != instance->imageDataMap.end(); itr++) {
{ if (itr->second.second == image) {
if(itr->second.second == image)
{
itr->second.first--; itr->second.first--;
if(itr->second.first == 0) if (itr->second.first == 0) {
{
AsyncDeleter::pushForDelete(itr->second.second); AsyncDeleter::pushForDelete(itr->second.second);
instance->imageDataMap.erase(itr); instance->imageDataMap.erase(itr);
} }
@ -134,22 +115,18 @@ void Resources::RemoveImageData(GuiImageData * image)
} }
} }
GuiSound * Resources::GetSound(const char * filename) GuiSound *Resources::GetSound(const char *filename) {
{
if (!instance) if (!instance)
instance = new Resources; instance = new Resources;
std::map<std::string, std::pair<unsigned int, GuiSound *> >::iterator itr = instance->soundDataMap.find(std::string(filename)); std::map<std::string, std::pair<unsigned int, GuiSound *> >::iterator itr = instance->soundDataMap.find(std::string(filename));
if(itr != instance->soundDataMap.end()) if (itr != instance->soundDataMap.end()) {
{
itr->second.first++; itr->second.first++;
return itr->second.second; return itr->second.second;
} }
for(int i = 0; RecourceList[i].filename != NULL; ++i) for (int i = 0; RecourceList[i].filename != NULL; ++i) {
{ if (strcasecmp(filename, RecourceList[i].filename) == 0) {
if(strcasecmp(filename, RecourceList[i].filename) == 0)
{
const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile; const uint8_t *buff = RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile;
const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize; const uint32_t size = RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize;
@ -167,18 +144,14 @@ GuiSound * Resources::GetSound(const char * filename)
return NULL; return NULL;
} }
void Resources::RemoveSound(GuiSound * sound) void Resources::RemoveSound(GuiSound *sound) {
{
std::map<std::string, std::pair<unsigned int, GuiSound *> >::iterator itr; std::map<std::string, std::pair<unsigned int, GuiSound *> >::iterator itr;
for(itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) for (itr = instance->soundDataMap.begin(); itr != instance->soundDataMap.end(); itr++) {
{ if (itr->second.second == sound) {
if(itr->second.second == sound)
{
itr->second.first--; itr->second.first--;
if(itr->second.first == 0) if (itr->second.first == 0) {
{
AsyncDeleter::pushForDelete(itr->second.second); AsyncDeleter::pushForDelete(itr->second.second);
instance->soundDataMap.erase(itr); instance->soundDataMap.erase(itr);
} }

View File

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

View File

@ -19,8 +19,7 @@
AsyncDeleter *AsyncDeleter::deleterInstance = NULL; AsyncDeleter *AsyncDeleter::deleterInstance = NULL;
AsyncDeleter::AsyncDeleter() AsyncDeleter::AsyncDeleter()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff) : CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff), exitApplication(false) {
, exitApplication(false) {
} }
AsyncDeleter::~AsyncDeleter() { AsyncDeleter::~AsyncDeleter() {

View File

@ -32,6 +32,7 @@ public:
class Element { class Element {
public: public:
Element() {} Element() {}
virtual ~Element() {} virtual ~Element() {}
}; };
@ -46,6 +47,7 @@ public:
private: private:
AsyncDeleter(); AsyncDeleter();
virtual ~AsyncDeleter(); virtual ~AsyncDeleter();
static AsyncDeleter *deleterInstance; static AsyncDeleter *deleterInstance;

View File

@ -20,8 +20,7 @@
#include <malloc.h> #include <malloc.h>
#include <coreinit/mutex.h> #include <coreinit/mutex.h>
class CMutex class CMutex {
{
public: public:
CMutex() { CMutex() {
pMutex = (OSMutex *) malloc(sizeof(OSMutex)); pMutex = (OSMutex *) malloc(sizeof(OSMutex));
@ -30,6 +29,7 @@ public:
OSInitMutex(pMutex); OSInitMutex(pMutex);
} }
virtual ~CMutex() { virtual ~CMutex() {
if (pMutex) if (pMutex)
free(pMutex); free(pMutex);
@ -39,29 +39,33 @@ public:
if (pMutex) if (pMutex)
OSLockMutex(pMutex); OSLockMutex(pMutex);
} }
void unlock(void) { void unlock(void) {
if (pMutex) if (pMutex)
OSUnlockMutex(pMutex); OSUnlockMutex(pMutex);
} }
BOOL tryLock(void) { BOOL tryLock(void) {
if (!pMutex) if (!pMutex)
return false; return false;
return (OSTryLockMutex(pMutex) != 0); return (OSTryLockMutex(pMutex) != 0);
} }
private: private:
OSMutex *pMutex; OSMutex *pMutex;
}; };
class CMutexLock class CMutexLock {
{
public: public:
CMutexLock() { CMutexLock() {
mutex.lock(); mutex.lock();
} }
virtual ~CMutexLock() { virtual ~CMutexLock() {
mutex.unlock(); mutex.unlock();
} }
private: private:
CMutex mutex; CMutex mutex;
}; };

View File

@ -29,10 +29,7 @@ public:
//! constructor //! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL) CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL) : pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
, pThreadStack(NULL)
, pCallback(callback)
, pCallbackArg(callbackArg) {
//! save attribute assignment //! save attribute assignment
iAttributes = iAttr; iAttributes = iAttr;
//! allocate the thread //! allocate the thread
@ -57,39 +54,47 @@ public:
virtual void *getThread() const { virtual void *getThread() const {
return pThread; return pThread;
} }
//! Thread entry function //! Thread entry function
virtual void executeThread(void) { virtual void executeThread(void) {
if (pCallback) if (pCallback)
pCallback(this, pCallbackArg); pCallback(this, pCallbackArg);
} }
//! Suspend thread //! Suspend thread
virtual void suspendThread(void) { virtual void suspendThread(void) {
if (isThreadSuspended()) return; if (isThreadSuspended()) return;
if (pThread) OSSuspendThread(pThread); if (pThread) OSSuspendThread(pThread);
} }
//! Resume thread //! Resume thread
virtual void resumeThread(void) { virtual void resumeThread(void) {
if (!isThreadSuspended()) return; if (!isThreadSuspended()) return;
if (pThread) OSResumeThread(pThread); if (pThread) OSResumeThread(pThread);
} }
//! Set thread priority //! Set thread priority
virtual void setThreadPriority(int prio) { virtual void setThreadPriority(int prio) {
if (pThread) OSSetThreadPriority(pThread, prio); if (pThread) OSSetThreadPriority(pThread, prio);
} }
//! Check if thread is suspended //! Check if thread is suspended
virtual BOOL isThreadSuspended(void) const { virtual BOOL isThreadSuspended(void) const {
if (pThread) return OSIsThreadSuspended(pThread); if (pThread) return OSIsThreadSuspended(pThread);
return false; return false;
} }
//! Check if thread is terminated //! Check if thread is terminated
virtual BOOL isThreadTerminated(void) const { virtual BOOL isThreadTerminated(void) const {
if (pThread) return OSIsThreadTerminated(pThread); if (pThread) return OSIsThreadTerminated(pThread);
return false; return false;
} }
//! Check if thread is running //! Check if thread is running
virtual BOOL isThreadRunning(void) const { virtual BOOL isThreadRunning(void) const {
return !isThreadSuspended() && !isThreadRunning(); return !isThreadSuspended() && !isThreadRunning();
} }
//! Shutdown thread //! Shutdown thread
virtual void shutdownThread(void) { virtual void shutdownThread(void) {
//! wait for thread to finish //! wait for thread to finish
@ -108,6 +113,7 @@ public:
pThread = NULL; pThread = NULL;
pThreadStack = NULL; pThreadStack = NULL;
} }
//! Thread attributes //! Thread attributes
enum eCThreadAttributes { enum eCThreadAttributes {
eAttributeNone = 0x07, eAttributeNone = 0x07,
@ -123,6 +129,7 @@ private:
((CThread *) argv)->executeThread(); ((CThread *) argv)->executeThread();
return 0; return 0;
} }
int iAttributes; int iAttributes;
OSThread *pThread; OSThread *pThread;
uint8_t *pThreadStack; uint8_t *pThreadStack;

View File

@ -38,10 +38,8 @@
static MEMHeapHandle mem1_heap = NULL; static MEMHeapHandle mem1_heap = NULL;
static MEMHeapHandle bucket_heap = NULL; static MEMHeapHandle bucket_heap = NULL;
void memoryInitialize(void) void memoryInitialize(void) {
{ if (!mem1_heap) {
if(!mem1_heap)
{
MEMHeapHandle mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); MEMHeapHandle mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4);
void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4);
@ -49,8 +47,7 @@ void memoryInitialize(void)
mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0);
} }
if(!bucket_heap) if (!bucket_heap) {
{
MEMHeapHandle bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); MEMHeapHandle bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET);
unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4);
void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4);
@ -59,16 +56,13 @@ void memoryInitialize(void)
} }
} }
void memoryRelease(void) void memoryRelease(void) {
{ if (mem1_heap) {
if(mem1_heap)
{
MEMDestroyExpHeap(mem1_heap); MEMDestroyExpHeap(mem1_heap);
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3);
mem1_heap = NULL; mem1_heap = NULL;
} }
if(bucket_heap) if (bucket_heap) {
{
MEMDestroyExpHeap(bucket_heap); MEMDestroyExpHeap(bucket_heap);
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3);
bucket_heap = NULL; bucket_heap = NULL;
@ -162,36 +156,30 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
//!------------------------------------------------------------------------------------------- //!-------------------------------------------------------------------------------------------
//! some wrappers //! some wrappers
//!------------------------------------------------------------------------------------------- //!-------------------------------------------------------------------------------------------
void * MEM2_alloc(unsigned int size, unsigned int align) void *MEM2_alloc(unsigned int size, unsigned int align) {
{
return memalign(align, size); return memalign(align, size);
} }
void MEM2_free(void *ptr) void MEM2_free(void *ptr) {
{
free(ptr); free(ptr);
} }
void * MEM1_alloc(unsigned int size, unsigned int align) void *MEM1_alloc(unsigned int size, unsigned int align) {
{
if (align < 4) if (align < 4)
align = 4; align = 4;
return MEMAllocFromExpHeapEx(mem1_heap, size, align); return MEMAllocFromExpHeapEx(mem1_heap, size, align);
} }
void MEM1_free(void *ptr) void MEM1_free(void *ptr) {
{
MEMFreeToExpHeap(mem1_heap, ptr); MEMFreeToExpHeap(mem1_heap, ptr);
} }
void * MEMBucket_alloc(unsigned int size, unsigned int align) void *MEMBucket_alloc(unsigned int size, unsigned int align) {
{
if (align < 4) if (align < 4)
align = 4; align = 4;
return MEMAllocFromExpHeapEx(bucket_heap, size, align); return MEMAllocFromExpHeapEx(bucket_heap, size, align);
} }
void MEMBucket_free(void *ptr) void MEMBucket_free(void *ptr) {
{
MEMFreeToExpHeap(bucket_heap, ptr); MEMFreeToExpHeap(bucket_heap, ptr);
} }

View File

@ -24,15 +24,19 @@ extern "C" {
#include <malloc.h> #include <malloc.h>
void memoryInitialize(void); void memoryInitialize(void);
void memoryRelease(void); void memoryRelease(void);
void *MEM2_alloc(unsigned int size, unsigned int align); void *MEM2_alloc(unsigned int size, unsigned int align);
void MEM2_free(void *ptr); void MEM2_free(void *ptr);
void *MEM1_alloc(unsigned int size, unsigned int align); void *MEM1_alloc(unsigned int size, unsigned int align);
void MEM1_free(void *ptr); void MEM1_free(void *ptr);
void *MEMBucket_alloc(unsigned int size, unsigned int align); void *MEMBucket_alloc(unsigned int size, unsigned int align);
void MEMBucket_free(void *ptr); void MEMBucket_free(void *ptr);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -33,14 +33,23 @@
class StringTools { class StringTools {
public: public:
static BOOL EndsWith(const std::string &a, const std::string &b); static BOOL EndsWith(const std::string &a, const std::string &b);
static const char *byte_to_binary(int32_t x); static const char *byte_to_binary(int32_t x);
static std::string removeCharFromString(std::string &input, char toBeRemoved); static std::string removeCharFromString(std::string &input, char toBeRemoved);
static const char *fmt(const char *format, ...); static const char *fmt(const char *format, ...);
static const wchar_t *wfmt(const char *format, ...); static const wchar_t *wfmt(const char *format, ...);
static int32_t strprintf(std::string &str, const char *format, ...); static int32_t strprintf(std::string &str, const char *format, ...);
static std::string strfmt(const char *format, ...); static std::string strfmt(const char *format, ...);
static BOOL char2wchar_t(const char *src, wchar_t *dest); static BOOL char2wchar_t(const char *src, wchar_t *dest);
static int32_t strtokcmp(const char *string, const char *compare, const char *separator); static int32_t strtokcmp(const char *string, const char *compare, const char *separator);
static int32_t strextcmp(const char *string, const char *extension, char seperator); static int32_t strextcmp(const char *string, const char *extension, char seperator);
static const char *FullpathToFilename(const char *path) { static const char *FullpathToFilename(const char *path) {
@ -49,8 +58,7 @@ class StringTools{
const char *ptr = path; const char *ptr = path;
const char *Filename = ptr; const char *Filename = ptr;
while(*ptr != '\0') while (*ptr != '\0') {
{
if (ptr[0] == '/' && ptr[1] != '\0') if (ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr + 1; Filename = ptr + 1;
@ -64,10 +72,8 @@ class StringTools{
uint32_t length = str.size(); uint32_t length = str.size();
//! clear path of double slashes //! clear path of double slashes
for(uint32_t i = 1; i < length; ++i) for (uint32_t i = 1; i < length; ++i) {
{ if (str[i - 1] == '/' && str[i] == '/') {
if(str[i-1] == '/' && str[i] == '/')
{
str.erase(i, 1); str.erase(i, 1);
i--; i--;
length--; length--;

View File

@ -8,9 +8,12 @@ extern "C" {
#include <string.h> #include <string.h>
void log_init_(); void log_init_();
//void log_deinit_(void); //void log_deinit_(void);
void log_print_(const char *str); void log_print_(const char *str);
void log_printf_(const char *format, ...); void log_printf_(const char *format, ...);
void OSFatal_printf(const char *format, ...); void OSFatal_printf(const char *format, ...);
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
@ -31,7 +34,6 @@ void OSFatal_printf(const char *format, ...);
} while (0) } while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif