mirror of
https://github.com/wiiu-env/Flappy-Bird_GX2.git
synced 2024-11-23 16:29:16 +01:00
Format code
This commit is contained in:
parent
39ce864c70
commit
349de9b582
@ -33,13 +33,7 @@ bool Application::exitApplication = false;
|
||||
bool Application::quitRequest = false;
|
||||
|
||||
Application::Application()
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000)
|
||||
, bgMusic(NULL)
|
||||
, video(NULL)
|
||||
, mainWindow(NULL)
|
||||
, fontSystem(NULL)
|
||||
, exitCode(0)
|
||||
{
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff, 0, 0x20000), bgMusic(NULL), video(NULL), mainWindow(NULL), fontSystem(NULL), exitCode(0) {
|
||||
controller[0] = new VPadController(GuiTrigger::CHANNEL_1);
|
||||
controller[1] = new WPadController(GuiTrigger::CHANNEL_2);
|
||||
controller[2] = new WPadController(GuiTrigger::CHANNEL_3);
|
||||
@ -57,8 +51,7 @@ Application::Application()
|
||||
ProcUIInit(OSSavesDone_ReadyToRelease);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
Application::~Application() {
|
||||
log_printf("Destroy music\n");
|
||||
|
||||
delete bgMusic;
|
||||
@ -80,8 +73,7 @@ Application::~Application()
|
||||
ProcUIShutdown();
|
||||
}
|
||||
|
||||
int Application::exec()
|
||||
{
|
||||
int Application::exec() {
|
||||
//! start main GX2 thread
|
||||
resumeThread();
|
||||
//! now wait for thread to finish
|
||||
@ -90,19 +82,16 @@ int Application::exec()
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
void Application::quit(int code)
|
||||
{
|
||||
void Application::quit(int code) {
|
||||
exitCode = code;
|
||||
exitApplication = true;
|
||||
quitRequest = true;
|
||||
}
|
||||
|
||||
void Application::fadeOut()
|
||||
{
|
||||
void Application::fadeOut() {
|
||||
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)
|
||||
i = 255;
|
||||
|
||||
@ -145,24 +134,19 @@ void Application::fadeOut()
|
||||
video->drcEnable(false);
|
||||
}
|
||||
|
||||
bool Application::procUI(void)
|
||||
{
|
||||
bool Application::procUI(void) {
|
||||
bool executeProcess = false;
|
||||
|
||||
switch(ProcUIProcessMessages(true))
|
||||
{
|
||||
case PROCUI_STATUS_EXITING:
|
||||
{
|
||||
switch (ProcUIProcessMessages(true)) {
|
||||
case PROCUI_STATUS_EXITING: {
|
||||
log_printf("PROCUI_STATUS_EXITING\n");
|
||||
exitCode = EXIT_SUCCESS;
|
||||
exitApplication = true;
|
||||
break;
|
||||
}
|
||||
case PROCUI_STATUS_RELEASE_FOREGROUND:
|
||||
{
|
||||
case PROCUI_STATUS_RELEASE_FOREGROUND: {
|
||||
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
|
||||
video->tvEnable(true);
|
||||
video->drcEnable(true);
|
||||
@ -178,19 +162,14 @@ bool Application::procUI(void)
|
||||
log_printf("deinitialze memory\n");
|
||||
memoryRelease();
|
||||
ProcUIDrawDoneRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ProcUIDrawDoneRelease();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PROCUI_STATUS_IN_FOREGROUND:
|
||||
{
|
||||
if(!quitRequest)
|
||||
{
|
||||
if(video == NULL)
|
||||
{
|
||||
case PROCUI_STATUS_IN_FOREGROUND: {
|
||||
if (!quitRequest) {
|
||||
if (video == NULL) {
|
||||
log_printf("PROCUI_STATUS_IN_FOREGROUND\n");
|
||||
log_printf("initialze memory\n");
|
||||
memoryInitialize();
|
||||
@ -204,8 +183,7 @@ bool Application::procUI(void)
|
||||
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
|
||||
GuiText::setPresetFont(fontSystem);
|
||||
|
||||
if(mainWindow == NULL)
|
||||
{
|
||||
if (mainWindow == NULL) {
|
||||
log_printf("Initialize main window\n");
|
||||
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
|
||||
}
|
||||
@ -223,19 +201,16 @@ bool Application::procUI(void)
|
||||
return executeProcess;
|
||||
}
|
||||
|
||||
void Application::executeThread(void)
|
||||
{
|
||||
void Application::executeThread(void) {
|
||||
log_printf("Entering main loop\n");
|
||||
|
||||
//! main GX2 loop (60 Hz cycle with max priority on core 1)
|
||||
while(!exitApplication)
|
||||
{
|
||||
while (!exitApplication) {
|
||||
if (procUI() == false)
|
||||
continue;
|
||||
|
||||
//! 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)
|
||||
continue;
|
||||
|
||||
@ -273,8 +248,7 @@ void Application::executeThread(void)
|
||||
}
|
||||
|
||||
//! in case we exit to a homebrew let's smoothly fade out
|
||||
if(video)
|
||||
{
|
||||
if (video) {
|
||||
fadeOut();
|
||||
}
|
||||
|
||||
|
@ -24,14 +24,14 @@
|
||||
// forward declaration
|
||||
class FreeTypeGX;
|
||||
|
||||
class Application : public CThread
|
||||
{
|
||||
class Application : public CThread {
|
||||
public:
|
||||
static Application *instance() {
|
||||
if (!applicationInstance)
|
||||
applicationInstance = new Application();
|
||||
return applicationInstance;
|
||||
}
|
||||
|
||||
static void destroyInstance() {
|
||||
if (applicationInstance) {
|
||||
delete applicationInstance;
|
||||
@ -42,6 +42,7 @@ public:
|
||||
CVideo *getVideo(void) const {
|
||||
return video;
|
||||
}
|
||||
|
||||
MainWindow *getMainWindow(void) const {
|
||||
return mainWindow;
|
||||
}
|
||||
@ -51,12 +52,14 @@ public:
|
||||
}
|
||||
|
||||
int exec(void);
|
||||
|
||||
void fadeOut(void);
|
||||
|
||||
void quit(int code);
|
||||
|
||||
private:
|
||||
Application();
|
||||
|
||||
virtual ~Application();
|
||||
|
||||
bool procUI(void);
|
||||
|
@ -2,8 +2,7 @@
|
||||
#include <sysapp/launch.h>
|
||||
#include "main.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
//! *******************************************************************
|
||||
//! * Jump to our application *
|
||||
//! *******************************************************************
|
||||
|
@ -18,11 +18,15 @@ public:
|
||||
};
|
||||
|
||||
CFile();
|
||||
|
||||
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);
|
||||
|
||||
BOOL isOpen() const {
|
||||
@ -38,15 +42,21 @@ public:
|
||||
void close();
|
||||
|
||||
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);
|
||||
};
|
||||
|
@ -40,42 +40,54 @@ 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);
|
||||
|
||||
//!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);
|
||||
|
||||
//! Get a filename of the list
|
||||
//!\param list index
|
||||
const char *GetFilename(int32_t index) const;
|
||||
|
||||
//! Get the a filepath of the list
|
||||
//!\param list index
|
||||
const char *GetFilepath(int32_t index) const {
|
||||
if (!valid(index)) return "";
|
||||
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)) 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,
|
||||
@ -85,10 +97,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);
|
||||
|
||||
//! Clear the list
|
||||
void ClearList();
|
||||
|
||||
//! Check if valid pos is requested
|
||||
inline BOOL valid(uint32_t pos) const {
|
||||
return (pos < FileInfo.size());
|
||||
|
@ -9,7 +9,9 @@ public:
|
||||
|
||||
//! todo: C++ class
|
||||
static int32_t CreateSubfolder(const char *fullpath);
|
||||
|
||||
static int32_t CheckFile(const char *filepath);
|
||||
|
||||
static BOOL saveBufferToFile(const char *path, void *buffer, uint32_t size);
|
||||
};
|
||||
|
||||
|
@ -23,8 +23,7 @@
|
||||
* Constructor for the GuiButton class.
|
||||
*/
|
||||
|
||||
Background::Background(char *picture, float scroll_speed)
|
||||
{
|
||||
Background::Background(char *picture, float scroll_speed) {
|
||||
loc_x = 0.0f;
|
||||
|
||||
bgImg = Resources::GetImageData(picture);
|
||||
@ -41,8 +40,7 @@ Background::Background(char *picture, float scroll_speed)
|
||||
/**
|
||||
* Destructor for the GuiButton class.
|
||||
*/
|
||||
Background::~Background()
|
||||
{
|
||||
Background::~Background() {
|
||||
speed = 0.0f;
|
||||
loc_x = 0.0f;
|
||||
delete (bgImg);
|
||||
@ -50,16 +48,14 @@ Background::~Background()
|
||||
delete (bgs);
|
||||
}
|
||||
|
||||
void Background::setScrollSpeed(float scroll_speed)
|
||||
{
|
||||
void Background::setScrollSpeed(float scroll_speed) {
|
||||
speed = scroll_speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void Background::draw(CVideo *v)
|
||||
{
|
||||
void Background::draw(CVideo *v) {
|
||||
if (speed > 0.0f) {
|
||||
loc_x -= speed;
|
||||
if (loc_x < 0.0f) loc_x = 1280.0f;
|
||||
@ -76,7 +72,6 @@ void Background::draw(CVideo *v)
|
||||
bgs->draw(v);
|
||||
}
|
||||
|
||||
void Background::update(GuiController * c)
|
||||
{
|
||||
void Background::update(GuiController *c) {
|
||||
|
||||
}
|
||||
|
@ -25,14 +25,18 @@
|
||||
#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)
|
||||
class Background : public GuiElement
|
||||
{
|
||||
class Background : public GuiElement {
|
||||
public:
|
||||
Background(char *picture, float scroll_speed);
|
||||
|
||||
virtual ~Background();
|
||||
|
||||
void setScrollSpeed(float scroll_speed);
|
||||
|
||||
void draw(CVideo *video);
|
||||
|
||||
void update(GuiController *c);
|
||||
|
||||
protected:
|
||||
GuiImageData *bgImg;
|
||||
GuiImage *bg;
|
||||
|
@ -24,8 +24,7 @@
|
||||
* Constructor for the GuiButton class.
|
||||
*/
|
||||
|
||||
Pipe::Pipe(float x)
|
||||
{
|
||||
Pipe::Pipe(float x) {
|
||||
srand(OSGetTime());
|
||||
loc_y = rand() % 250 - 125;
|
||||
loc_x = x;
|
||||
@ -46,8 +45,7 @@ Pipe::Pipe(float x)
|
||||
/**
|
||||
* Destructor for the GuiButton class.
|
||||
*/
|
||||
Pipe::~Pipe()
|
||||
{
|
||||
Pipe::~Pipe() {
|
||||
loc_x = 0.0f;
|
||||
loc_y = 0.0f;
|
||||
scroll_state = 0;
|
||||
@ -57,21 +55,19 @@ Pipe::~Pipe()
|
||||
delete (pipeBottomImg);
|
||||
}
|
||||
|
||||
void Pipe::setPosX(float x)
|
||||
{
|
||||
void Pipe::setPosX(float x) {
|
||||
loc_x = x;
|
||||
pipebottom->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;
|
||||
}
|
||||
|
||||
int Pipe::checkCollision(GuiImage* check)
|
||||
{
|
||||
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...
|
||||
int Pipe::checkCollision(GuiImage *check) {
|
||||
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...
|
||||
poss_collision = 1;
|
||||
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
|
||||
@ -88,8 +84,7 @@ int Pipe::checkCollision(GuiImage* check)
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void Pipe::draw(CVideo *v)
|
||||
{
|
||||
void Pipe::draw(CVideo *v) {
|
||||
if (scroll_state == true) {
|
||||
loc_x -= 1.5f;
|
||||
if (loc_x < -640.0f) {
|
||||
@ -108,7 +103,6 @@ void Pipe::draw(CVideo *v)
|
||||
pipetop->draw(v);
|
||||
}
|
||||
|
||||
void Pipe::update(GuiController * c)
|
||||
{
|
||||
void Pipe::update(GuiController *c) {
|
||||
|
||||
}
|
||||
|
@ -25,16 +25,22 @@
|
||||
#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)
|
||||
class Pipe : public GuiElement
|
||||
{
|
||||
class Pipe : public GuiElement {
|
||||
public:
|
||||
Pipe(float x);
|
||||
|
||||
virtual ~Pipe();
|
||||
|
||||
void setPosX(float x);
|
||||
|
||||
void setScroll(bool state);
|
||||
|
||||
int checkCollision(GuiImage *check);
|
||||
|
||||
void draw(CVideo *video);
|
||||
|
||||
void update(GuiController *c);
|
||||
|
||||
protected:
|
||||
GuiImageData *pipeBottomImg;
|
||||
GuiImageData *pipeTopImg;
|
||||
|
@ -23,8 +23,7 @@
|
||||
* 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[1] = Resources::GetImageData("font_big_1.png");
|
||||
digitsImagesData[2] = Resources::GetImageData("font_big_2.png");
|
||||
@ -49,13 +48,11 @@ ScoreImage::ScoreImage(int x, int y)
|
||||
/**
|
||||
* Destructor for the GuiButton class.
|
||||
*/
|
||||
ScoreImage::~ScoreImage()
|
||||
{
|
||||
ScoreImage::~ScoreImage() {
|
||||
//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
|
||||
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)
|
||||
@ -71,8 +68,7 @@ void ScoreImage::setScore(int score)
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void ScoreImage::draw(CVideo *v)
|
||||
{
|
||||
void ScoreImage::draw(CVideo *v) {
|
||||
if (!this->isVisible())
|
||||
return;
|
||||
|
||||
@ -82,7 +78,6 @@ void ScoreImage::draw(CVideo *v)
|
||||
digitsImages[2]->draw(v);
|
||||
}
|
||||
|
||||
void ScoreImage::update(GuiController * c)
|
||||
{
|
||||
void ScoreImage::update(GuiController *c) {
|
||||
|
||||
}
|
||||
|
@ -25,14 +25,18 @@
|
||||
#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)
|
||||
class ScoreImage : public GuiElement
|
||||
{
|
||||
class ScoreImage : public GuiElement {
|
||||
public:
|
||||
ScoreImage(int x, int y);
|
||||
|
||||
virtual ~ScoreImage();
|
||||
|
||||
void setScore(int score);
|
||||
|
||||
void draw(CVideo *video);
|
||||
|
||||
void update(GuiController *c);
|
||||
|
||||
protected:
|
||||
GuiImageData *digitsImagesData[11]; //Our 10 numers + 1 null digit :P
|
||||
GuiImage *digitsImages[3];
|
||||
|
@ -22,8 +22,7 @@
|
||||
* Constructor for the GuiButton class.
|
||||
*/
|
||||
|
||||
SplashScreen::SplashScreen(GuiImageData * img)
|
||||
{
|
||||
SplashScreen::SplashScreen(GuiImageData *img) {
|
||||
img_real = new GuiImage(img);
|
||||
img_real->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
|
||||
img_real->setPosition(0, 0);
|
||||
@ -32,25 +31,22 @@ SplashScreen::SplashScreen(GuiImageData * img)
|
||||
/**
|
||||
* Destructor for the GuiButton class.
|
||||
*/
|
||||
SplashScreen::~SplashScreen()
|
||||
{
|
||||
SplashScreen::~SplashScreen() {
|
||||
state = 0;
|
||||
delete (img_real);
|
||||
}
|
||||
|
||||
void SplashScreen::setSplashImageData(GuiImageData * img)
|
||||
{
|
||||
void SplashScreen::setSplashImageData(GuiImageData *img) {
|
||||
img_real->setImageData(img);
|
||||
}
|
||||
|
||||
void SplashScreen::FadeExit()
|
||||
{
|
||||
void SplashScreen::FadeExit() {
|
||||
trasparency = 1.0f;
|
||||
state = 1;
|
||||
img_real->setAlpha(trasparency);
|
||||
}
|
||||
void SplashScreen::FadeEnter()
|
||||
{
|
||||
|
||||
void SplashScreen::FadeEnter() {
|
||||
trasparency = 0.0f;
|
||||
state = 2;
|
||||
img_real->setAlpha(trasparency);
|
||||
@ -60,8 +56,7 @@ void SplashScreen::FadeEnter()
|
||||
/**
|
||||
* Draw the button on screen
|
||||
*/
|
||||
void SplashScreen::draw(CVideo *v)
|
||||
{
|
||||
void SplashScreen::draw(CVideo *v) {
|
||||
if (state != 0) {
|
||||
switch (state) {
|
||||
case 1:
|
||||
@ -86,7 +81,6 @@ void SplashScreen::draw(CVideo *v)
|
||||
img_real->draw(v);
|
||||
}
|
||||
|
||||
void SplashScreen::update(GuiController * c)
|
||||
{
|
||||
void SplashScreen::update(GuiController *c) {
|
||||
|
||||
}
|
||||
|
@ -25,16 +25,22 @@
|
||||
#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)
|
||||
class SplashScreen : public GuiElement
|
||||
{
|
||||
class SplashScreen : public GuiElement {
|
||||
public:
|
||||
SplashScreen(GuiImageData *img);
|
||||
|
||||
virtual ~SplashScreen();
|
||||
|
||||
void setSplashImageData(GuiImageData *img);
|
||||
|
||||
void FadeExit();
|
||||
|
||||
void FadeEnter();
|
||||
|
||||
void draw(CVideo *video);
|
||||
|
||||
void update(GuiController *c);
|
||||
|
||||
protected:
|
||||
GuiImage *img_real;
|
||||
int state;
|
||||
|
@ -19,10 +19,10 @@
|
||||
|
||||
#include <gui/Gui.h>
|
||||
|
||||
class GuiMainWindowScreen : public GuiFrame
|
||||
{
|
||||
class GuiMainWindowScreen : public GuiFrame {
|
||||
public:
|
||||
GuiMainWindowScreen(int w, int h) : GuiFrame(w, h) {}
|
||||
|
||||
virtual ~GuiMainWindowScreen() {}
|
||||
};
|
||||
|
||||
|
@ -6,8 +6,7 @@
|
||||
#include "utils/utils.h"
|
||||
|
||||
/* Entry point */
|
||||
extern "C" int Menu_Main(void)
|
||||
{
|
||||
extern "C" int Menu_Main(void) {
|
||||
//!*******************************************************************
|
||||
//! Initialize function pointers *
|
||||
//!*******************************************************************
|
||||
|
@ -24,11 +24,8 @@
|
||||
#include "system/AsyncDeleter.h"
|
||||
|
||||
MainWindow::MainWindow(int w, int h)
|
||||
: width(w)
|
||||
, height(h)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
: width(w), height(h) {
|
||||
for (int 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]);
|
||||
@ -39,48 +36,39 @@ MainWindow::MainWindow(int w, int h)
|
||||
SetupMainView();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
MainWindow::~MainWindow() {
|
||||
|
||||
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(int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
delete pointerImg[i];
|
||||
Resources::RemoveImageData(pointerImgData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateEffects()
|
||||
{
|
||||
void MainWindow::updateEffects() {
|
||||
//! dont read behind the initial elements in case one was added
|
||||
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++)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -91,47 +79,37 @@ 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++)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::update(GuiController *controller)
|
||||
{
|
||||
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
|
||||
{
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
float posX = controller->data.x;
|
||||
float posY = controller->data.y;
|
||||
@ -162,17 +139,13 @@ void MainWindow::update(GuiController *controller)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::drawDrc(CVideo *video)
|
||||
{
|
||||
for(uint32_t i = 0; i < drcElements.size(); ++i)
|
||||
{
|
||||
void MainWindow::drawDrc(CVideo *video) {
|
||||
for (uint32_t i = 0; i < drcElements.size(); ++i) {
|
||||
drcElements[i]->draw(video);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
if(pointerValid[i])
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (pointerValid[i]) {
|
||||
pointerImg[i]->setAlpha(0.5f);
|
||||
pointerImg[i]->draw(video);
|
||||
pointerImg[i]->setAlpha(1.0f);
|
||||
@ -180,25 +153,20 @@ void MainWindow::drawDrc(CVideo *video)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::drawTv(CVideo *video)
|
||||
{
|
||||
for(uint32_t i = 0; i < tvElements.size(); ++i)
|
||||
{
|
||||
void MainWindow::drawTv(CVideo *video) {
|
||||
for (uint32_t i = 0; i < tvElements.size(); ++i) {
|
||||
tvElements[i]->draw(video);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
if(pointerValid[i])
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (pointerValid[i]) {
|
||||
pointerImg[i]->draw(video);
|
||||
pointerValid[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::SetupMainView()
|
||||
{
|
||||
void MainWindow::SetupMainView() {
|
||||
|
||||
//DrcFrame = new MainWindowDRC(width,height);
|
||||
TvFrame = new MainWindowTV(width, height);
|
||||
@ -207,15 +175,13 @@ void MainWindow::SetupMainView()
|
||||
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"
|
||||
element->effectFinished.disconnect(this);
|
||||
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);
|
||||
AsyncDeleter::pushForDelete(element);
|
||||
|
@ -26,22 +26,21 @@
|
||||
|
||||
class CVideo;
|
||||
|
||||
class MainWindow : public sigslot::has_slots<>
|
||||
{
|
||||
class MainWindow : public sigslot::has_slots<> {
|
||||
public:
|
||||
MainWindow(int w, int h);
|
||||
|
||||
virtual ~MainWindow();
|
||||
|
||||
void appendTv(GuiElement *e)
|
||||
{
|
||||
void appendTv(GuiElement *e) {
|
||||
if (!e)
|
||||
return;
|
||||
|
||||
removeTv(e);
|
||||
tvElements.push_back(e);
|
||||
}
|
||||
void appendDrc(GuiElement *e)
|
||||
{
|
||||
|
||||
void appendDrc(GuiElement *e) {
|
||||
if (!e)
|
||||
return;
|
||||
|
||||
@ -49,22 +48,20 @@ public:
|
||||
drcElements.push_back(e);
|
||||
}
|
||||
|
||||
void append(GuiElement *e)
|
||||
{
|
||||
void append(GuiElement *e) {
|
||||
appendTv(e);
|
||||
appendDrc(e);
|
||||
}
|
||||
|
||||
void insertTv(uint32_t pos, GuiElement *e)
|
||||
{
|
||||
void insertTv(uint32_t pos, GuiElement *e) {
|
||||
if (!e)
|
||||
return;
|
||||
|
||||
removeTv(e);
|
||||
tvElements.insert(tvElements.begin() + pos, e);
|
||||
}
|
||||
void insertDrc(uint32_t pos, GuiElement *e)
|
||||
{
|
||||
|
||||
void insertDrc(uint32_t pos, GuiElement *e) {
|
||||
if (!e)
|
||||
return;
|
||||
|
||||
@ -72,59 +69,54 @@ public:
|
||||
drcElements.insert(drcElements.begin() + pos, e);
|
||||
}
|
||||
|
||||
void insert(uint32_t pos, GuiElement *e)
|
||||
{
|
||||
void insert(uint32_t pos, GuiElement *e) {
|
||||
insertTv(pos, e);
|
||||
insertDrc(pos, e);
|
||||
}
|
||||
|
||||
void removeTv(GuiElement *e)
|
||||
{
|
||||
for(uint32_t i = 0; i < tvElements.size(); ++i)
|
||||
{
|
||||
if(e == tvElements[i])
|
||||
{
|
||||
void removeTv(GuiElement *e) {
|
||||
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])
|
||||
{
|
||||
|
||||
void removeDrc(GuiElement *e) {
|
||||
for (uint32_t i = 0; i < drcElements.size(); ++i) {
|
||||
if (e == drcElements[i]) {
|
||||
drcElements.erase(drcElements.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove(GuiElement *e)
|
||||
{
|
||||
void remove(GuiElement *e) {
|
||||
removeTv(e);
|
||||
removeDrc(e);
|
||||
}
|
||||
void removeAll()
|
||||
{
|
||||
|
||||
void removeAll() {
|
||||
tvElements.clear();
|
||||
drcElements.clear();
|
||||
}
|
||||
|
||||
void drawDrc(CVideo *video);
|
||||
|
||||
void drawTv(CVideo *video);
|
||||
|
||||
void update(GuiController *controller);
|
||||
|
||||
void updateEffects();
|
||||
|
||||
void process();
|
||||
|
||||
void lockGUI()
|
||||
{
|
||||
void lockGUI() {
|
||||
guiMutex.lock();
|
||||
}
|
||||
void unlockGUI()
|
||||
{
|
||||
|
||||
void unlockGUI() {
|
||||
guiMutex.unlock();
|
||||
}
|
||||
|
||||
@ -132,6 +124,7 @@ private:
|
||||
void SetupMainView(void);
|
||||
|
||||
void OnOpenEffectFinish(GuiElement *element);
|
||||
|
||||
void OnCloseEffectFinish(GuiElement *element);
|
||||
|
||||
int width, height;
|
||||
|
@ -20,11 +20,7 @@
|
||||
#include "resources/Resources.h"
|
||||
|
||||
MainWindowTV::MainWindowTV(int w, int h)
|
||||
: GuiMainWindowScreen(w, h)
|
||||
, width(w)
|
||||
, height(h)
|
||||
,bgImageColor(w, h, (GX2Color){ 0, 0, 0, 0 })
|
||||
{
|
||||
: GuiMainWindowScreen(w, h), 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}, 1);
|
||||
bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 2);
|
||||
@ -32,8 +28,6 @@ MainWindowTV::MainWindowTV(int w, int h)
|
||||
append(&bgImageColor);
|
||||
|
||||
|
||||
|
||||
|
||||
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"));
|
||||
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);
|
||||
}
|
||||
|
||||
MainWindowTV::~MainWindowTV()
|
||||
{
|
||||
MainWindowTV::~MainWindowTV() {
|
||||
remove(&bgImageColor);
|
||||
delete (wingSound);
|
||||
delete (swooshSound);
|
||||
|
@ -38,7 +38,9 @@ class CVideo;
|
||||
class MainWindowTV : public GuiMainWindowScreen {
|
||||
public:
|
||||
MainWindowTV(int w, int h);
|
||||
|
||||
virtual ~MainWindowTV();
|
||||
|
||||
private:
|
||||
int width, height;
|
||||
|
||||
@ -87,7 +89,9 @@ private:
|
||||
float flappy_bird_rotation = 0.0f;
|
||||
|
||||
void draw(CVideo *v);
|
||||
|
||||
void update(GuiController *c);
|
||||
|
||||
void process();
|
||||
};
|
||||
|
||||
|
@ -9,12 +9,9 @@
|
||||
|
||||
Resources *Resources::instance = NULL;
|
||||
|
||||
void Resources::Clear()
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(RecourceList[i].CustomFile)
|
||||
{
|
||||
void Resources::Clear() {
|
||||
for (int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if (RecourceList[i].CustomFile) {
|
||||
free(RecourceList[i].CustomFile);
|
||||
RecourceList[i].CustomFile = NULL;
|
||||
}
|
||||
@ -29,16 +26,14 @@ void Resources::Clear()
|
||||
instance = NULL;
|
||||
}
|
||||
|
||||
bool Resources::LoadFiles(const char * path)
|
||||
{
|
||||
bool Resources::LoadFiles(const char *path) {
|
||||
if (!path)
|
||||
return false;
|
||||
|
||||
bool result = false;
|
||||
Clear();
|
||||
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
for (int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
std::string fullpath(path);
|
||||
fullpath += "/";
|
||||
fullpath += RecourceList[i].filename;
|
||||
@ -56,12 +51,9 @@ bool Resources::LoadFiles(const char * path)
|
||||
return result;
|
||||
}
|
||||
|
||||
const uint8_t * Resources::GetFile(const char * filename)
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
const uint8_t *Resources::GetFile(const char *filename) {
|
||||
for (int i = 0; RecourceList[i].filename != NULL; ++i) {
|
||||
if (strcasecmp(filename, RecourceList[i].filename) == 0) {
|
||||
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
|
||||
}
|
||||
}
|
||||
@ -69,34 +61,27 @@ const uint8_t * Resources::GetFile(const char * filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t Resources::GetFileSize(const char * filename)
|
||||
{
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
uint32_t Resources::GetFileSize(const char *filename) {
|
||||
for (int i = 0; RecourceList[i].filename != NULL; ++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)
|
||||
{
|
||||
GuiImageData *Resources::GetImageData(const char *filename) {
|
||||
if (!instance)
|
||||
instance = new Resources;
|
||||
|
||||
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++;
|
||||
return itr->second.second;
|
||||
}
|
||||
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
for (int 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;
|
||||
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;
|
||||
}
|
||||
|
||||
void Resources::RemoveImageData(GuiImageData * image)
|
||||
{
|
||||
void Resources::RemoveImageData(GuiImageData *image) {
|
||||
std::map<std::string, std::pair<unsigned int, 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) {
|
||||
AsyncDeleter::pushForDelete(itr->second.second);
|
||||
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)
|
||||
instance = new Resources;
|
||||
|
||||
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++;
|
||||
return itr->second.second;
|
||||
}
|
||||
|
||||
for(int i = 0; RecourceList[i].filename != NULL; ++i)
|
||||
{
|
||||
if(strcasecmp(filename, RecourceList[i].filename) == 0)
|
||||
{
|
||||
for (int 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;
|
||||
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;
|
||||
}
|
||||
|
||||
void Resources::RemoveSound(GuiSound * sound)
|
||||
{
|
||||
void Resources::RemoveSound(GuiSound *sound) {
|
||||
std::map<std::string, std::pair<unsigned int, 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) {
|
||||
AsyncDeleter::pushForDelete(itr->second.second);
|
||||
instance->soundDataMap.erase(itr);
|
||||
}
|
||||
|
@ -5,25 +5,32 @@
|
||||
|
||||
//! forward declaration
|
||||
class GuiImageData;
|
||||
|
||||
class GuiSound;
|
||||
|
||||
class Resources
|
||||
{
|
||||
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 GuiSound *GetSound(const char *filename);
|
||||
|
||||
static void RemoveSound(GuiSound *sound);
|
||||
|
||||
private:
|
||||
static Resources *instance;
|
||||
|
||||
Resources() {}
|
||||
|
||||
~Resources() {}
|
||||
|
||||
std::map<std::string, std::pair<unsigned int, GuiImageData *> > imageDataMap;
|
||||
|
@ -19,8 +19,7 @@
|
||||
AsyncDeleter *AsyncDeleter::deleterInstance = NULL;
|
||||
|
||||
AsyncDeleter::AsyncDeleter()
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff)
|
||||
, exitApplication(false) {
|
||||
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff), exitApplication(false) {
|
||||
}
|
||||
|
||||
AsyncDeleter::~AsyncDeleter() {
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
class Element {
|
||||
public:
|
||||
Element() {}
|
||||
|
||||
virtual ~Element() {}
|
||||
};
|
||||
|
||||
@ -46,6 +47,7 @@ public:
|
||||
|
||||
private:
|
||||
AsyncDeleter();
|
||||
|
||||
virtual ~AsyncDeleter();
|
||||
|
||||
static AsyncDeleter *deleterInstance;
|
||||
|
@ -20,8 +20,7 @@
|
||||
#include <malloc.h>
|
||||
#include <coreinit/mutex.h>
|
||||
|
||||
class CMutex
|
||||
{
|
||||
class CMutex {
|
||||
public:
|
||||
CMutex() {
|
||||
pMutex = (OSMutex *) malloc(sizeof(OSMutex));
|
||||
@ -30,6 +29,7 @@ public:
|
||||
|
||||
OSInitMutex(pMutex);
|
||||
}
|
||||
|
||||
virtual ~CMutex() {
|
||||
if (pMutex)
|
||||
free(pMutex);
|
||||
@ -39,29 +39,33 @@ public:
|
||||
if (pMutex)
|
||||
OSLockMutex(pMutex);
|
||||
}
|
||||
|
||||
void unlock(void) {
|
||||
if (pMutex)
|
||||
OSUnlockMutex(pMutex);
|
||||
}
|
||||
|
||||
BOOL tryLock(void) {
|
||||
if (!pMutex)
|
||||
return false;
|
||||
|
||||
return (OSTryLockMutex(pMutex) != 0);
|
||||
}
|
||||
|
||||
private:
|
||||
OSMutex *pMutex;
|
||||
};
|
||||
|
||||
class CMutexLock
|
||||
{
|
||||
class CMutexLock {
|
||||
public:
|
||||
CMutexLock() {
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
virtual ~CMutexLock() {
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
CMutex mutex;
|
||||
};
|
||||
|
@ -29,10 +29,7 @@ public:
|
||||
|
||||
//! constructor
|
||||
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||
: pThread(NULL)
|
||||
, pThreadStack(NULL)
|
||||
, pCallback(callback)
|
||||
, pCallbackArg(callbackArg) {
|
||||
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
|
||||
//! save attribute assignment
|
||||
iAttributes = iAttr;
|
||||
//! allocate the thread
|
||||
@ -57,39 +54,47 @@ public:
|
||||
virtual void *getThread() const {
|
||||
return pThread;
|
||||
}
|
||||
|
||||
//! Thread entry function
|
||||
virtual void executeThread(void) {
|
||||
if (pCallback)
|
||||
pCallback(this, pCallbackArg);
|
||||
}
|
||||
|
||||
//! Suspend thread
|
||||
virtual void suspendThread(void) {
|
||||
if (isThreadSuspended()) return;
|
||||
if (pThread) OSSuspendThread(pThread);
|
||||
}
|
||||
|
||||
//! Resume thread
|
||||
virtual void resumeThread(void) {
|
||||
if (!isThreadSuspended()) return;
|
||||
if (pThread) OSResumeThread(pThread);
|
||||
}
|
||||
|
||||
//! Set thread priority
|
||||
virtual void setThreadPriority(int prio) {
|
||||
if (pThread) OSSetThreadPriority(pThread, prio);
|
||||
}
|
||||
|
||||
//! Check if thread is suspended
|
||||
virtual BOOL isThreadSuspended(void) const {
|
||||
if (pThread) return OSIsThreadSuspended(pThread);
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Check if thread is terminated
|
||||
virtual BOOL isThreadTerminated(void) const {
|
||||
if (pThread) return OSIsThreadTerminated(pThread);
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Check if thread is running
|
||||
virtual BOOL isThreadRunning(void) const {
|
||||
return !isThreadSuspended() && !isThreadRunning();
|
||||
}
|
||||
|
||||
//! Shutdown thread
|
||||
virtual void shutdownThread(void) {
|
||||
//! wait for thread to finish
|
||||
@ -108,6 +113,7 @@ public:
|
||||
pThread = NULL;
|
||||
pThreadStack = NULL;
|
||||
}
|
||||
|
||||
//! Thread attributes
|
||||
enum eCThreadAttributes {
|
||||
eAttributeNone = 0x07,
|
||||
@ -123,6 +129,7 @@ private:
|
||||
((CThread *) argv)->executeThread();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iAttributes;
|
||||
OSThread *pThread;
|
||||
uint8_t *pThreadStack;
|
||||
|
@ -38,10 +38,8 @@
|
||||
static MEMHeapHandle mem1_heap = NULL;
|
||||
static MEMHeapHandle bucket_heap = NULL;
|
||||
|
||||
void memoryInitialize(void)
|
||||
{
|
||||
if(!mem1_heap)
|
||||
{
|
||||
void memoryInitialize(void) {
|
||||
if (!mem1_heap) {
|
||||
MEMHeapHandle mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1);
|
||||
unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 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);
|
||||
}
|
||||
|
||||
if(!bucket_heap)
|
||||
{
|
||||
if (!bucket_heap) {
|
||||
MEMHeapHandle bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET);
|
||||
unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4);
|
||||
void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4);
|
||||
@ -59,16 +56,13 @@ void memoryInitialize(void)
|
||||
}
|
||||
}
|
||||
|
||||
void memoryRelease(void)
|
||||
{
|
||||
if(mem1_heap)
|
||||
{
|
||||
void memoryRelease(void) {
|
||||
if (mem1_heap) {
|
||||
MEMDestroyExpHeap(mem1_heap);
|
||||
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3);
|
||||
mem1_heap = NULL;
|
||||
}
|
||||
if(bucket_heap)
|
||||
{
|
||||
if (bucket_heap) {
|
||||
MEMDestroyExpHeap(bucket_heap);
|
||||
MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3);
|
||||
bucket_heap = NULL;
|
||||
@ -162,36 +156,30 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
//! some wrappers
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
void * MEM2_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
void *MEM2_alloc(unsigned int size, unsigned int align) {
|
||||
return memalign(align, size);
|
||||
}
|
||||
|
||||
void MEM2_free(void *ptr)
|
||||
{
|
||||
void MEM2_free(void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void * MEM1_alloc(unsigned int size, unsigned int align)
|
||||
{
|
||||
void *MEM1_alloc(unsigned int size, unsigned int align) {
|
||||
if (align < 4)
|
||||
align = 4;
|
||||
return MEMAllocFromExpHeapEx(mem1_heap, size, align);
|
||||
}
|
||||
|
||||
void MEM1_free(void *ptr)
|
||||
{
|
||||
void MEM1_free(void *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)
|
||||
align = 4;
|
||||
return MEMAllocFromExpHeapEx(bucket_heap, size, align);
|
||||
}
|
||||
|
||||
void MEMBucket_free(void *ptr)
|
||||
{
|
||||
void MEMBucket_free(void *ptr) {
|
||||
MEMFreeToExpHeap(bucket_heap, ptr);
|
||||
}
|
||||
|
@ -24,15 +24,19 @@ extern "C" {
|
||||
#include <malloc.h>
|
||||
|
||||
void memoryInitialize(void);
|
||||
|
||||
void memoryRelease(void);
|
||||
|
||||
void *MEM2_alloc(unsigned int size, unsigned int align);
|
||||
|
||||
void MEM2_free(void *ptr);
|
||||
|
||||
void *MEM1_alloc(unsigned int size, unsigned int align);
|
||||
|
||||
void MEM1_free(void *ptr);
|
||||
|
||||
void *MEMBucket_alloc(unsigned int size, unsigned int align);
|
||||
|
||||
void MEMBucket_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -33,14 +33,23 @@
|
||||
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 const char *FullpathToFilename(const char *path) {
|
||||
@ -49,8 +58,7 @@ class StringTools{
|
||||
const char *ptr = path;
|
||||
const char *Filename = ptr;
|
||||
|
||||
while(*ptr != '\0')
|
||||
{
|
||||
while (*ptr != '\0') {
|
||||
if (ptr[0] == '/' && ptr[1] != '\0')
|
||||
Filename = ptr + 1;
|
||||
|
||||
@ -64,10 +72,8 @@ class StringTools{
|
||||
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--;
|
||||
|
@ -8,9 +8,12 @@ extern "C" {
|
||||
#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__)
|
||||
@ -31,7 +34,6 @@ void OSFatal_printf(const char *format, ...);
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user