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;
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);
@ -52,87 +46,82 @@ Application::Application()
bgMusic->Play();
bgMusic->SetVolume(50);
exitApplication = false;
exitApplication = false;
ProcUIInit(OSSavesDone_ReadyToRelease);
}
Application::~Application()
{
Application::~Application() {
log_printf("Destroy music\n");
delete bgMusic;
log_printf("Destroy controller\n");
for(int i = 0; i < 5; i++)
for (int i = 0; i < 5; i++)
delete controller[i];
log_printf("Destroy async deleter\n");
AsyncDeleter::destroyInstance();
AsyncDeleter::destroyInstance();
log_printf("Clear resources\n");
Resources::Clear();
log_printf("Stop sound handler\n");
SoundHandler::DestroyInstance();
SoundHandler::DestroyInstance();
ProcUIShutdown();
}
int Application::exec()
{
int Application::exec() {
//! start main GX2 thread
resumeThread();
//! now wait for thread to finish
shutdownThread();
shutdownThread();
return exitCode;
return exitCode;
}
void Application::quit(int code)
{
void Application::quit(int code) {
exitCode = code;
exitApplication = true;
quitRequest = true;
}
void Application::fadeOut()
{
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color){ 0, 0, 0, 255 });
void Application::fadeOut() {
GuiImage fadeOut(video->getTvWidth(), video->getTvHeight(), (GX2Color) {0, 0, 0, 255});
for(int i = 0; i < 255; i += 10)
{
if(i > 255)
for (int i = 0; i < 255; i += 10) {
if (i > 255)
i = 255;
fadeOut.setAlpha(i / 255.0f);
//! start rendering DRC
video->prepareDrcRendering();
mainWindow->drawDrc(video);
video->prepareDrcRendering();
mainWindow->drawDrc(video);
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS);
fadeOut.draw(video);
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
video->drcDrawDone();
video->drcDrawDone();
//! start rendering TV
video->prepareTvRendering();
video->prepareTvRendering();
mainWindow->drawTv(video);
mainWindow->drawTv(video);
GX2SetDepthOnlyControl(GX2_DISABLE, GX2_DISABLE, GX2_COMPARE_FUNC_ALWAYS);
fadeOut.draw(video);
GX2SetDepthOnlyControl(GX2_ENABLE, GX2_ENABLE, GX2_COMPARE_FUNC_LEQUAL);
video->tvDrawDone();
video->tvDrawDone();
//! as last point update the effects as it can drop elements
mainWindow->updateEffects();
//! as last point update the effects as it can drop elements
mainWindow->updateEffects();
video->waitForVSync();
video->waitForVSync();
}
//! one last cleared black screen
@ -145,98 +134,84 @@ void Application::fadeOut()
video->drcEnable(false);
}
bool Application::procUI(void)
{
bool Application::procUI(void) {
bool executeProcess = false;
switch(ProcUIProcessMessages(true))
{
case PROCUI_STATUS_EXITING:
{
log_printf("PROCUI_STATUS_EXITING\n");
exitCode = EXIT_SUCCESS;
exitApplication = true;
break;
}
case PROCUI_STATUS_RELEASE_FOREGROUND:
{
log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n");
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);
log_printf("delete fontSystem\n");
delete fontSystem;
fontSystem = NULL;
log_printf("delete video\n");
delete video;
video = NULL;
log_printf("deinitialze memory\n");
memoryRelease();
ProcUIDrawDoneRelease();
switch (ProcUIProcessMessages(true)) {
case PROCUI_STATUS_EXITING: {
log_printf("PROCUI_STATUS_EXITING\n");
exitCode = EXIT_SUCCESS;
exitApplication = true;
break;
}
else
{
ProcUIDrawDoneRelease();
}
break;
}
case PROCUI_STATUS_IN_FOREGROUND:
{
if(!quitRequest)
{
if(video == NULL)
{
log_printf("PROCUI_STATUS_IN_FOREGROUND\n");
log_printf("initialze memory\n");
memoryInitialize();
case PROCUI_STATUS_RELEASE_FOREGROUND: {
log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n");
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);
log_printf("Initialize video\n");
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE);
log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight());
log_printf("delete fontSystem\n");
delete fontSystem;
fontSystem = NULL;
//! setup default Font
log_printf("Initialize main font system\n");
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem);
if(mainWindow == NULL)
{
log_printf("Initialize main window\n");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
}
log_printf("delete video\n");
delete video;
video = NULL;
log_printf("deinitialze memory\n");
memoryRelease();
ProcUIDrawDoneRelease();
} else {
ProcUIDrawDoneRelease();
}
executeProcess = true;
break;
}
break;
}
case PROCUI_STATUS_IN_BACKGROUND:
default:
break;
case PROCUI_STATUS_IN_FOREGROUND: {
if (!quitRequest) {
if (video == NULL) {
log_printf("PROCUI_STATUS_IN_FOREGROUND\n");
log_printf("initialze memory\n");
memoryInitialize();
log_printf("Initialize video\n");
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE);
log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight());
//! setup default Font
log_printf("Initialize main font system\n");
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem);
if (mainWindow == NULL) {
log_printf("Initialize main window\n");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
}
}
executeProcess = true;
}
break;
}
case PROCUI_STATUS_IN_BACKGROUND:
default:
break;
}
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)
{
if(procUI() == false)
continue;
while (!exitApplication) {
if (procUI() == false)
continue;
//! Read out inputs
for(int i = 0; i < 5; i++)
{
if(controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
//! Read out inputs
for (int i = 0; i < 5; i++) {
if (controller[i]->update(video->getTvWidth(), video->getTvHeight()) == false)
continue;
//! update controller states
@ -246,35 +221,34 @@ void Application::executeThread(void)
mainWindow->process();
//! start rendering DRC
video->prepareDrcRendering();
mainWindow->drawDrc(video);
video->drcDrawDone();
video->prepareDrcRendering();
mainWindow->drawDrc(video);
video->drcDrawDone();
//! start rendering TV
video->prepareTvRendering();
mainWindow->drawTv(video);
video->tvDrawDone();
video->prepareTvRendering();
mainWindow->drawTv(video);
video->tvDrawDone();
//! enable screen after first frame render
if(video->getFrameCount() == 0) {
if (video->getFrameCount() == 0) {
video->tvEnable(true);
video->drcEnable(true);
}
}
//! as last point update the effects as it can drop elements
mainWindow->updateEffects();
//! as last point update the effects as it can drop elements
mainWindow->updateEffects();
video->waitForVSync();
video->waitForVSync();
//! transfer elements to real delete list here after all processes are finished
//! the elements are transfered to another list to delete the elements in a separate thread
//! and avoid blocking the GUI thread
AsyncDeleter::triggerDeleteProcess();
}
}
//! in case we exit to a homebrew let's smoothly fade out
if(video)
{
if (video) {
fadeOut();
}

View File

@ -24,16 +24,16 @@
// forward declaration
class FreeTypeGX;
class Application : public CThread
{
class Application : public CThread {
public:
static Application * instance() {
if(!applicationInstance)
static Application *instance() {
if (!applicationInstance)
applicationInstance = new Application();
return applicationInstance;
}
static void destroyInstance() {
if(applicationInstance) {
if (applicationInstance) {
delete applicationInstance;
applicationInstance = NULL;
}
@ -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);

View File

@ -2,10 +2,9 @@
#include <sysapp/launch.h>
#include "main.h"
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
//! *******************************************************************
//! * Jump to our application *
//! *******************************************************************
return Menu_Main();
return Menu_Main();
}

View File

@ -11,12 +11,12 @@ CFile::CFile() {
pos = 0;
}
CFile::CFile(const std::string & filepath, eOpenTypes mode) {
CFile::CFile(const std::string &filepath, eOpenTypes mode) {
iFd = -1;
this->open(filepath, mode);
}
CFile::CFile(const uint8_t * mem, int32_t size) {
CFile::CFile(const uint8_t *mem, int32_t size) {
iFd = -1;
this->open(mem, size);
}
@ -25,25 +25,25 @@ CFile::~CFile() {
this->close();
}
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
this->close();
int32_t openMode = 0;
switch(mode) {
default:
case ReadOnly:
openMode = O_RDONLY;
break;
case WriteOnly:
openMode = O_WRONLY;
break;
case ReadWrite:
openMode = O_RDWR;
break;
case Append:
openMode = O_APPEND | O_WRONLY;
break;
switch (mode) {
default:
case ReadOnly:
openMode = O_RDONLY;
break;
case WriteOnly:
openMode = O_WRONLY;
break;
case ReadWrite:
openMode = O_RDWR;
break;
case Append:
openMode = O_APPEND | O_WRONLY;
break;
}
//! Using fopen works only on the first launch as expected
@ -51,7 +51,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
//! the .data sections which is needed for a normal application to re-init
//! this will be added with launching as RPX
iFd = ::open(filepath.c_str(), openMode);
if(iFd < 0)
if (iFd < 0)
return iFd;
@ -61,7 +61,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
return 0;
}
int32_t CFile::open(const uint8_t * mem, int32_t size) {
int32_t CFile::open(const uint8_t *mem, int32_t size) {
this->close();
mem_file = mem;
@ -71,7 +71,7 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) {
}
void CFile::close() {
if(iFd >= 0)
if (iFd >= 0)
::close(iFd);
iFd = -1;
@ -80,24 +80,24 @@ void CFile::close() {
pos = 0;
}
int32_t CFile::read(uint8_t * ptr, size_t size) {
if(iFd >= 0) {
int32_t ret = ::read(iFd, ptr,size);
if(ret > 0)
int32_t CFile::read(uint8_t *ptr, size_t size) {
if (iFd >= 0) {
int32_t ret = ::read(iFd, ptr, size);
if (ret > 0)
pos += ret;
return ret;
}
int32_t readsize = size;
if(readsize > (int64_t) (filesize-pos))
readsize = filesize-pos;
if (readsize > (int64_t) (filesize - pos))
readsize = filesize - pos;
if(readsize <= 0)
if (readsize <= 0)
return readsize;
if(mem_file != NULL) {
memcpy(ptr, mem_file+pos, readsize);
if (mem_file != NULL) {
memcpy(ptr, mem_file + pos, readsize);
pos += readsize;
return readsize;
}
@ -105,12 +105,12 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
return -1;
}
int32_t CFile::write(const uint8_t * ptr, size_t size) {
if(iFd >= 0) {
int32_t CFile::write(const uint8_t *ptr, size_t size) {
if (iFd >= 0) {
size_t done = 0;
while(done < size) {
while (done < size) {
int32_t ret = ::write(iFd, ptr, size - done);
if(ret <= 0)
if (ret <= 0)
return ret;
ptr += ret;
@ -127,25 +127,25 @@ int32_t CFile::seek(long int offset, int32_t origin) {
int32_t ret = 0;
int64_t newPos = pos;
if(origin == SEEK_SET) {
if (origin == SEEK_SET) {
newPos = offset;
} else if(origin == SEEK_CUR) {
} else if (origin == SEEK_CUR) {
newPos += offset;
} else if(origin == SEEK_END) {
newPos = filesize+offset;
} else if (origin == SEEK_END) {
newPos = filesize + offset;
}
if(newPos < 0) {
if (newPos < 0) {
pos = 0;
} else {
pos = newPos;
}
if(iFd >= 0)
if (iFd >= 0)
ret = ::lseek(iFd, pos, SEEK_SET);
if(mem_file != NULL) {
if(pos > filesize) {
if (mem_file != NULL) {
if (pos > filesize) {
pos = filesize;
}
}
@ -160,8 +160,8 @@ int32_t CFile::fwrite(const char *format, ...) {
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
result = this->write((uint8_t *)tmp, strlen(tmp));
if ((vsprintf(tmp, format, va) >= 0)) {
result = this->write((uint8_t *) tmp, strlen(tmp));
}
va_end(va);

View File

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

View File

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

View File

@ -32,7 +32,7 @@
#include <wut_types.h>
typedef struct {
char * FilePath;
char *FilePath;
BOOL isDir;
} DirEntry;
@ -40,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);
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);
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;
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;
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);
void AddEntrie(const std::string &filepath, const char *filename, BOOL isDir);
//! Clear the list
void ClearList();
//! Check if valid pos is requested
inline BOOL valid(uint32_t pos) const {
return (pos < FileInfo.size());

View File

@ -10,7 +10,7 @@
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input
*inbuffer = NULL;
if(size)
if (size)
*size = 0;
int32_t iFd = open(filepath, O_RDONLY);
@ -30,12 +30,12 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
uint32_t done = 0;
int32_t readBytes = 0;
while(done < filesize) {
if(done + blocksize > filesize) {
while (done < filesize) {
if (done + blocksize > filesize) {
blocksize = filesize - done;
}
readBytes = read(iFd, buffer + done, blocksize);
if(readBytes <= 0)
if (readBytes <= 0)
break;
done += readBytes;
}
@ -51,27 +51,27 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
*inbuffer = buffer;
//! sign is optional input
if(size) {
if (size) {
*size = filesize;
}
return filesize;
}
int32_t FSUtils::CheckFile(const char * filepath) {
if(!filepath)
int32_t FSUtils::CheckFile(const char *filepath) {
if (!filepath)
return 0;
struct stat filestat;
char dirnoslash[strlen(filepath)+2];
char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
while(dirnoslash[strlen(dirnoslash)-1] == '/')
dirnoslash[strlen(dirnoslash)-1] = '\0';
while (dirnoslash[strlen(dirnoslash) - 1] == '/')
dirnoslash[strlen(dirnoslash) - 1] = '\0';
char * notRoot = strrchr(dirnoslash, '/');
if(!notRoot) {
char *notRoot = strrchr(dirnoslash, '/');
if (!notRoot) {
strcat(dirnoslash, "/");
}
@ -81,29 +81,29 @@ int32_t FSUtils::CheckFile(const char * filepath) {
return 0;
}
int32_t FSUtils::CreateSubfolder(const char * fullpath) {
if(!fullpath)
int32_t FSUtils::CreateSubfolder(const char *fullpath) {
if (!fullpath)
return 0;
int32_t result = 0;
char dirnoslash[strlen(fullpath)+1];
char dirnoslash[strlen(fullpath) + 1];
strcpy(dirnoslash, fullpath);
int32_t pos = strlen(dirnoslash)-1;
while(dirnoslash[pos] == '/') {
int32_t pos = strlen(dirnoslash) - 1;
while (dirnoslash[pos] == '/') {
dirnoslash[pos] = '\0';
pos--;
}
if(CheckFile(dirnoslash)) {
if (CheckFile(dirnoslash)) {
return 1;
} else {
char parentpath[strlen(dirnoslash)+2];
char parentpath[strlen(dirnoslash) + 2];
strcpy(parentpath, dirnoslash);
char * ptr = strrchr(parentpath, '/');
char *ptr = strrchr(parentpath, '/');
if(!ptr) {
if (!ptr) {
//!Device root directory (must be with '/')
strcat(parentpath, "/");
struct stat filestat;
@ -119,7 +119,7 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
result = CreateSubfolder(parentpath);
}
if(!result)
if (!result)
return 0;
if (mkdir(dirnoslash, 0777) == -1) {
@ -129,15 +129,15 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
return 1;
}
BOOL FSUtils::saveBufferToFile(const char * path, void * buffer, uint32_t size) {
BOOL FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) {
int32_t res = open(path, O_CREAT | O_TRUNC | O_WRONLY);
close(res);
CFile file(path, CFile::WriteOnly);
if (!file.isOpen()) {
DEBUG_FUNCTION_LINE("Failed to open %s\n",path);
DEBUG_FUNCTION_LINE("Failed to open %s\n", path);
return false;
}
file.write((const uint8_t*) buffer,size);
file.write((const uint8_t *) buffer, size);
file.close();
return true;
}

View File

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

View File

@ -23,60 +23,55 @@
* Constructor for the GuiButton class.
*/
Background::Background(char *picture, float scroll_speed)
{
loc_x=0.0f;
Background::Background(char *picture, float scroll_speed) {
loc_x = 0.0f;
bgImg = Resources::GetImageData(picture);
bg = new GuiImage(bgImg);
bgs = new GuiImage(bgImg);
bg->setPosition(0, 0);
bgs->setPosition(-1280, 0);
speed=scroll_speed;
speed = scroll_speed;
}
/**
* Destructor for the GuiButton class.
*/
Background::~Background()
{
speed=0.0f;
loc_x=0.0f;
delete(bgImg);
delete(bg);
delete(bgs);
Background::~Background() {
speed = 0.0f;
loc_x = 0.0f;
delete (bgImg);
delete (bg);
delete (bgs);
}
void Background::setScrollSpeed(float scroll_speed)
{
speed=scroll_speed;
void Background::setScrollSpeed(float scroll_speed) {
speed = scroll_speed;
}
/**
* Draw the button on screen
*/
void Background::draw(CVideo *v)
{
if(speed>0.0f) {
loc_x-=speed;
if(loc_x<0.0f) loc_x=1280.0f;
void Background::draw(CVideo *v) {
if (speed > 0.0f) {
loc_x -= speed;
if (loc_x < 0.0f) loc_x = 1280.0f;
bg->setPosition((int)loc_x, 0);
bgs->setPosition((int)loc_x-1280, 0);
}
bg->setPosition((int) loc_x, 0);
bgs->setPosition((int) loc_x - 1280, 0);
}
if(!this->isVisible())
return;
if (!this->isVisible())
return;
// draw images
bg->draw(v);
bgs->draw(v);
// draw images
bg->draw(v);
bgs->draw(v);
}
void Background::update(GuiController * c)
{
void Background::update(GuiController *c) {
}

View File

@ -25,20 +25,24 @@
#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
{
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;
GuiImage * bgs;
float speed;
float loc_x;
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;
GuiImage *bgs;
float speed;
float loc_x;
};
#endif

View File

@ -24,10 +24,9 @@
* Constructor for the GuiButton class.
*/
Pipe::Pipe(float x)
{
Pipe::Pipe(float x) {
srand(OSGetTime());
loc_y=rand() % 250 - 125;
loc_y = rand() % 250 - 125;
loc_x = x;
pipeBottomImg = Resources::GetImageData("pipe_down.png");
pipeTopImg = Resources::GetImageData("pipe_up.png");
@ -37,48 +36,45 @@ Pipe::Pipe(float x)
pipebottom->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
pipetop->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
pipebottom->setPosition((int)loc_x,-410-loc_y);
pipetop->setPosition((int)loc_x,410-loc_y);
pipebottom->setPosition((int) loc_x, -410 - loc_y);
pipetop->setPosition((int) loc_x, 410 - loc_y);
scroll_state=false;
scroll_state = false;
}
/**
* Destructor for the GuiButton class.
*/
Pipe::~Pipe()
{
loc_x=0.0f;
loc_y=0.0f;
scroll_state=0;
delete(pipetop);
delete(pipebottom);
delete(pipeTopImg);
delete(pipeBottomImg);
Pipe::~Pipe() {
loc_x = 0.0f;
loc_y = 0.0f;
scroll_state = 0;
delete (pipetop);
delete (pipebottom);
delete (pipeTopImg);
delete (pipeBottomImg);
}
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::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)
{
scroll_state=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...
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
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
return 1;
}
} else if (poss_collision==1) { //We just surpassed the problem
poss_collision=0;
} else if (poss_collision == 1) { //We just surpassed the problem
poss_collision = 0;
return -1; //Add point
}
return 0;
@ -88,27 +84,25 @@ int Pipe::checkCollision(GuiImage* check)
/**
* Draw the button on screen
*/
void Pipe::draw(CVideo *v)
{
if(scroll_state==true) {
loc_x-=1.5f;
if (loc_x<-640.0f) {
loc_x=700.0f;
loc_y=rand() % 250 - 125;
}
pipebottom->setPosition((int)loc_x,-410-loc_y);
pipetop->setPosition((int)loc_x,410-loc_y);
void Pipe::draw(CVideo *v) {
if (scroll_state == true) {
loc_x -= 1.5f;
if (loc_x < -640.0f) {
loc_x = 700.0f;
loc_y = rand() % 250 - 125;
}
pipebottom->setPosition((int) loc_x, -410 - loc_y);
pipetop->setPosition((int) loc_x, 410 - loc_y);
}
if(!this->isVisible())
return;
if (!this->isVisible())
return;
// draw images
pipebottom->draw(v);
pipetop->draw(v);
// draw images
pipebottom->draw(v);
pipetop->draw(v);
}
void Pipe::update(GuiController * c)
{
void Pipe::update(GuiController *c) {
}

View File

@ -25,25 +25,31 @@
#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
{
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;
GuiImage * pipebottom;
GuiImage * pipetop;
float loc_x;
int loc_y;
int poss_collision=0;
bool scroll_state;
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;
GuiImage *pipebottom;
GuiImage *pipetop;
float loc_x;
int loc_y;
int poss_collision = 0;
bool scroll_state;
};
#endif

View File

@ -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");
@ -36,11 +35,11 @@ ScoreImage::ScoreImage(int x, int y)
digitsImagesData[8] = Resources::GetImageData("font_big_8.png");
digitsImagesData[9] = Resources::GetImageData("font_big_9.png");
digitsImagesData[10] = Resources::GetImageData("font_big_null.png");
for (int i=0;i<3;i++) {
digitsImages[i] = new GuiImage(digitsImagesData[10]);
digitsImages[i]->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
digitsImages[i]->setPosition(x+(i*36),y);
for (int i = 0; i < 3; i++) {
digitsImages[i] = new GuiImage(digitsImagesData[10]);
digitsImages[i]->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
digitsImages[i]->setPosition(x + (i * 36), y);
}
digitsImages[2]->setImageData(digitsImagesData[0]);
@ -49,40 +48,36 @@ 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)
digits[0]=(int)(score/pow(10, 0))%10;
if (score>9) digits[1]=(int)(score/pow(10, 1))%10;
if (score>99) digits[2]=(int)(score/pow(10, 2))%10;
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++) digitsImages[a]->setImageData(digitsImagesData[digits[2-a]]);
digits[0] = (int) (score / pow(10, 0)) % 10;
if (score > 9) digits[1] = (int) (score / pow(10, 1)) % 10;
if (score > 99) digits[2] = (int) (score / pow(10, 2)) % 10;
for (int a = 0; a < 3; a++) digitsImages[a]->setImageData(digitsImagesData[digits[2 - a]]);
}
/**
* Draw the button on screen
*/
void ScoreImage::draw(CVideo *v)
{
if(!this->isVisible())
return;
void ScoreImage::draw(CVideo *v) {
if (!this->isVisible())
return;
// draw images
digitsImages[0]->draw(v);
digitsImages[1]->draw(v);
digitsImages[2]->draw(v);
// draw images
digitsImages[0]->draw(v);
digitsImages[1]->draw(v);
digitsImages[2]->draw(v);
}
void ScoreImage::update(GuiController * c)
{
void ScoreImage::update(GuiController *c) {
}

View File

@ -25,18 +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 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];
int digits[3];
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];
int digits[3];
};
#endif

View File

@ -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,61 +31,56 @@ SplashScreen::SplashScreen(GuiImageData * img)
/**
* Destructor for the GuiButton class.
*/
SplashScreen::~SplashScreen()
{
state=0;
delete(img_real);
SplashScreen::~SplashScreen() {
state = 0;
delete (img_real);
}
void SplashScreen::setSplashImageData(GuiImageData * img)
{
void SplashScreen::setSplashImageData(GuiImageData *img) {
img_real->setImageData(img);
}
void SplashScreen::FadeExit()
{
trasparency=1.0f;
state=1;
img_real->setAlpha(trasparency);
void SplashScreen::FadeExit() {
trasparency = 1.0f;
state = 1;
img_real->setAlpha(trasparency);
}
void SplashScreen::FadeEnter()
{
trasparency=0.0f;
state=2;
img_real->setAlpha(trasparency);
void SplashScreen::FadeEnter() {
trasparency = 0.0f;
state = 2;
img_real->setAlpha(trasparency);
}
/**
* Draw the button on screen
*/
void SplashScreen::draw(CVideo *v)
{
if(state!=0) {
switch(state) {
case 1:
if (trasparency>0.0f) {
trasparency=trasparency-0.05f;
img_real->setAlpha(trasparency);
} else state=0;
break;
case 2:
if (trasparency<1.0f) {
trasparency=trasparency+0.05f;
img_real->setAlpha(trasparency);
} else state=0;
break;
}
void SplashScreen::draw(CVideo *v) {
if (state != 0) {
switch (state) {
case 1:
if (trasparency > 0.0f) {
trasparency = trasparency - 0.05f;
img_real->setAlpha(trasparency);
} else state = 0;
break;
case 2:
if (trasparency < 1.0f) {
trasparency = trasparency + 0.05f;
img_real->setAlpha(trasparency);
} else state = 0;
break;
}
}
if(!this->isVisible())
return;
if (!this->isVisible())
return;
// draw images
img_real->draw(v);
// draw images
img_real->draw(v);
}
void SplashScreen::update(GuiController * c)
{
void SplashScreen::update(GuiController *c) {
}

View File

@ -25,21 +25,27 @@
#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
{
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;
float trasparency=1.0f;
int tmp_xpos;
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;
float trasparency = 1.0f;
int tmp_xpos;
};
#endif

View File

@ -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() {}
};

View File

@ -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 *
//!*******************************************************************
@ -25,7 +24,7 @@ extern "C" int Menu_Main(void)
log_printf("Start main application\n");
Application::instance()->exec();
Application::destroyInstance();
Application::destroyInstance();
return 0;
}

View File

@ -24,12 +24,9 @@
#include "system/AsyncDeleter.h"
MainWindow::MainWindow(int w, int h)
: width(w)
, height(h)
{
for(int i = 0; i < 4; i++)
{
std::string filename = StringTools::strfmt("player%i_point.png", i+1);
: 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]);
pointerImg[i]->setScale(1.5f);
@ -39,99 +36,80 @@ 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++)
{
if(tvElements[i] == drcElements[n])
for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if (tvElements[i] == drcElements[n])
break;
}
if(n == drcElements.size())
{
if (n == drcElements.size()) {
tvElements[i]->updateEffects();
}
}
}
void MainWindow::process(){
void MainWindow::process() {
//! 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]->process();
}
//! only update TV elements that are not updated yet because they are on DRC
for(uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i)
{
for (uint32_t i = 0; (i < tvSize) && (i < tvElements.size()); ++i) {
uint32_t n;
for(n = 0; (n < drcSize) && (n < drcElements.size()); n++)
{
if(tvElements[i] == drcElements[n])
for (n = 0; (n < drcSize) && (n < drcElements.size()); n++) {
if (tvElements[i] == drcElements[n])
break;
}
if(n == drcElements.size())
{
if (n == drcElements.size()) {
tvElements[i]->process();
}
}
}
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,42 +153,35 @@ 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);
DrcFrame = TvFrame;
TvFrame = new MainWindowTV(width, height);
DrcFrame = TvFrame;
appendTv(TvFrame);
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);

View File

@ -26,105 +26,97 @@
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)
{
if(!e)
void appendTv(GuiElement *e) {
if (!e)
return;
removeTv(e);
tvElements.push_back(e);
}
void appendDrc(GuiElement *e)
{
if(!e)
void appendDrc(GuiElement *e) {
if (!e)
return;
removeDrc(e);
drcElements.push_back(e);
}
void append(GuiElement *e)
{
void append(GuiElement *e) {
appendTv(e);
appendDrc(e);
}
void insertTv(uint32_t pos, GuiElement *e)
{
if(!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)
{
if(!e)
void insertDrc(uint32_t pos, GuiElement *e) {
if (!e)
return;
removeDrc(e);
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;
@ -140,8 +133,8 @@ private:
GuiSound *ClickSound;
GuiMainWindowScreen * TvFrame;
GuiMainWindowScreen * DrcFrame;
GuiMainWindowScreen *TvFrame;
GuiMainWindowScreen *DrcFrame;
GuiImageData *pointerImgData[4];
GuiImage *pointerImg[4];

View File

@ -20,18 +20,12 @@
#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 })
{
bgImageColor.setImageColor((GX2Color){ 248, 248, 249, 255 }, 0);
bgImageColor.setImageColor((GX2Color){ 248, 248, 249, 255 }, 1);
bgImageColor.setImageColor((GX2Color){ 248, 248, 249, 255 }, 2);
bgImageColor.setImageColor((GX2Color){ 248, 248, 249, 255 }, 3);
: 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);
bgImageColor.setImageColor((GX2Color) {248, 248, 249, 255}, 3);
append(&bgImageColor);
wingSound = new GuiSound(Resources::GetFile("sfx_wing.ogg"), Resources::GetFileSize("sfx_wing.ogg"));
@ -53,10 +47,10 @@ MainWindowTV::MainWindowTV(int w, int h)
//splash = new GuiImage(splashImgData);
flappy_bird = new GuiImage(flappy_bird_frm[0]);
for (int i=0;i<4;i++) pipes[i] = new Pipe(150.0f+((float)i*320.0f));
for (int i = 0; i < 4; i++) pipes[i] = new Pipe(150.0f + ((float) i * 320.0f));
bg = new Background("bg_back.png",0);
fg = new Background("bg_front.png",0);
bg = new Background("bg_back.png", 0);
fg = new Background("bg_front.png", 0);
score_img = new ScoreImage(-54, 200);
@ -70,7 +64,7 @@ MainWindowTV::MainWindowTV(int w, int h)
append(bg);
append(flappy_bird);
for (int i=0;i<4;i++) append(pipes[i]);
for (int i = 0; i < 4; i++) append(pipes[i]);
append(fg);
append(splash);
@ -84,152 +78,151 @@ MainWindowTV::MainWindowTV(int w, int h)
//append(hello);
}
MainWindowTV::~MainWindowTV()
{
MainWindowTV::~MainWindowTV() {
remove(&bgImageColor);
delete(wingSound);
delete(swooshSound);
delete(dieSound);
delete (wingSound);
delete (swooshSound);
delete (dieSound);
//delete(bg);
//for (int i=0;i<4;i++) delete pipes[i];
//pipes = NULL;
//delete(fg);
delete(splash);
delete(flappy_bird);
delete (splash);
delete (flappy_bird);
}
void MainWindowTV::draw(CVideo *v){
GuiMainWindowScreen::draw(v);
//gets called on every frame for drawing
void MainWindowTV::draw(CVideo *v) {
GuiMainWindowScreen::draw(v);
//gets called on every frame for drawing
}
void MainWindowTV::update(GuiController * c){
void MainWindowTV::update(GuiController *c) {
GuiMainWindowScreen::update(c);
//CONTROLLER UPDATE!!!
switch(game_state) {
switch (game_state) {
case state_splash: //Start screen
if(c->data.buttons_d & VPAD_BUTTON_A || c->data.buttons_d & VPAD_BUTTON_B) {
if (c->data.buttons_d & VPAD_BUTTON_A || c->data.buttons_d & VPAD_BUTTON_B) {
splash->FadeExit();
append(score_img);
for(int i=0;i<4;i++) pipes[i]->setScroll(true);
for (int i = 0; i < 4; i++) pipes[i]->setScroll(true);
bg->setScrollSpeed(0.5f);
fg->setScrollSpeed(1.5f);
flappy_bird_velocity = jump; //Jump after start
wingSound->Stop();
wingSound->Play();
game_state=state_ingame;
game_state = state_ingame;
}
break;
case state_ingame:
if(c->data.buttons_d & VPAD_BUTTON_A || c->data.buttons_d & VPAD_BUTTON_B) {
if (c->data.buttons_d & VPAD_BUTTON_A || c->data.buttons_d & VPAD_BUTTON_B) {
flappy_bird_velocity = jump;
wingSound->Stop();
wingSound->Play();
}
break;
case state_gameover:
if(dieSound->IsPlaying() == false && (c->data.buttons_d & VPAD_BUTTON_A || c->data.buttons_d & VPAD_BUTTON_B)) {
flappy_bird_position=-5;
if (dieSound->IsPlaying() == false && (c->data.buttons_d & VPAD_BUTTON_A || c->data.buttons_d & VPAD_BUTTON_B)) {
flappy_bird_position = -5;
flappy_bird_rotation = 0.0f;
flappy_bird_velocity = 0.0f;
flappy_bird->setPosition(-150, -5);
flappy_bird->setAngle(0.0f);
score=0;
score = 0;
score_img->setScore(score);
for (int i=0;i<4;i++) pipes[i]->setPosX(150.0f+((float)i*320.0f));
for (int i = 0; i < 4; i++) pipes[i]->setPosX(150.0f + ((float) i * 320.0f));
splash->setSplashImageData(splashImgData);
splash->FadeEnter();
swooshSound->Stop();
swooshSound->Play();
game_state=state_splash;
game_state = state_splash;
}
break;
default:
break;
}
}
void MainWindowTV::process(){
void MainWindowTV::process() {
GuiMainWindowScreen::process();
if (game_state!=2) { //If not game over
if (++flappy_bird_change_skip==6) { //Animate picture
flappy_bird_change_skip=0;
if (++flappy_bird_curr_frame==4) flappy_bird_curr_frame=0;
if (game_state != 2) { //If not game over
if (++flappy_bird_change_skip == 6) { //Animate picture
flappy_bird_change_skip = 0;
if (++flappy_bird_curr_frame == 4) flappy_bird_curr_frame = 0;
flappy_bird->setImageData(flappy_bird_frm[flappy_bird_curr_frame]);
}
}
switch(game_state) {
switch (game_state) {
case state_ingame:
flappy_bird_velocity += gravity;
flappy_bird_position -= flappy_bird_velocity;
if(flappy_bird_position<-224) flappy_bird_position=-224;
if(flappy_bird_position>320) flappy_bird_position=320;
if (flappy_bird_position < -224) flappy_bird_position = -224;
if (flappy_bird_position > 320) flappy_bird_position = 320;
flappy_bird->setPosition(-150, (int)flappy_bird_position);
if ((((float)flappy_bird_velocity / 10.0f) * 90.0f)<90.0f) flappy_bird_rotation = (((float)flappy_bird_velocity / 10.0f) * 90.0f);
flappy_bird->setPosition(-150, (int) flappy_bird_position);
if ((((float) flappy_bird_velocity / 10.0f) * 90.0f) < 90.0f) flappy_bird_rotation = (((float) flappy_bird_velocity / 10.0f) * 90.0f);
else flappy_bird_rotation = 90.0f;
flappy_bird->setAngle(flappy_bird_rotation);
for (int i=0;i<4;i++) {
collision_state[i]=pipes[i]->checkCollision(flappy_bird);
if(collision_state[i]!=0) {
if(collision_state[i]==-1) {
for (int i = 0; i < 4; i++) {
collision_state[i] = pipes[i]->checkCollision(flappy_bird);
if (collision_state[i] != 0) {
if (collision_state[i] == -1) {
//Add point
score_img->setScore(++score);
pointSound->Stop();
pointSound->Play();
}
if(collision_state[i]==1) {
if (collision_state[i] == 1) {
bg->setScrollSpeed(0.0f);
fg->setScrollSpeed(0.0f);
for(int i=0;i<4;i++) pipes[i]->setScroll(false);
fg->setScrollSpeed(0.0f);
for (int i = 0; i < 4; i++) pipes[i]->setScroll(false);
dieSound->Stop();
dieSound->Play();
game_state=state_collided;
game_state = state_collided;
}
}
}
if (flappy_bird_position<-220) game_state=state_die;
if (flappy_bird_position < -220) game_state = state_die;
break;
case state_collided: //is dying from a pipe: go down by gravity
flappy_bird_velocity += gravity;
flappy_bird_position -= flappy_bird_velocity;
if(flappy_bird_position<-224) flappy_bird_position=-224;
if(flappy_bird_position>320) flappy_bird_position=320;
if (flappy_bird_position < -224) flappy_bird_position = -224;
if (flappy_bird_position > 320) flappy_bird_position = 320;
flappy_bird->setPosition(-150, (int)flappy_bird_position);
if ((((float)flappy_bird_velocity / 10.0f) * 90.0f)<90.0f) flappy_bird_rotation = (((float)flappy_bird_velocity / 10.0f) * 90.0f);
flappy_bird->setPosition(-150, (int) flappy_bird_position);
if ((((float) flappy_bird_velocity / 10.0f) * 90.0f) < 90.0f) flappy_bird_rotation = (((float) flappy_bird_velocity / 10.0f) * 90.0f);
else flappy_bird_rotation = 90.0f;
flappy_bird->setAngle(flappy_bird_rotation);
if (flappy_bird_position<-220) game_state=state_show_gameover;
if (flappy_bird_position < -220) game_state = state_show_gameover;
break;
case state_show_gameover: //IsDying
if(dieSound->IsPlaying() == false) {
if (dieSound->IsPlaying() == false) {
swooshSound->Stop();
swooshSound->Play();
splash->setSplashImageData(looseImgData);
splash->FadeEnter();
remove(score_img);
game_state=state_gameover;
game_state = state_gameover;
}
break;
case state_die: //Die
bg->setScrollSpeed(0.0f);
fg->setScrollSpeed(0.0f);
for(int i=0;i<4;i++) pipes[i]->setScroll(false);
fg->setScrollSpeed(0.0f);
for (int i = 0; i < 4; i++) pipes[i]->setScroll(false);
dieSound->Stop();
dieSound->Play();
game_state=state_show_gameover;
game_state = state_show_gameover;
break;
default:
break;

View File

@ -35,10 +35,12 @@
class CVideo;
class MainWindowTV : public GuiMainWindowScreen{
class MainWindowTV : public GuiMainWindowScreen {
public:
MainWindowTV(int w, int h);
virtual ~MainWindowTV();
private:
int width, height;
@ -49,45 +51,47 @@ private:
GuiSound *swooshSound;
GuiSound *dieSound;
GuiImageData* bgImgData;
GuiImageData* fgImgData;
GuiImageData* splashImgData;
GuiImageData* looseImgData;
GuiImageData *bgImgData;
GuiImageData *fgImgData;
GuiImageData *splashImgData;
GuiImageData *looseImgData;
Background* bg;
Background* fg;
Background *bg;
Background *fg;
//GuiImage* splash; //Splash screen
SplashScreen* splash;
SplashScreen *splash;
ScoreImage *score_img;
int score=0;
int score = 0;
Pipe* pipes[4];
Pipe *pipes[4];
int collision_state[4];
int bg_offset=0;
int fg_offset=0;
int bg_offset = 0;
int fg_offset = 0;
GuiImageData *flappy_bird_frm[4];
GuiImage* flappy_bird;
GuiImage *flappy_bird;
int flappy_bird_change_skip=0;
int flappy_bird_curr_frame=0;
int flappy_bird_change_skip = 0;
int flappy_bird_curr_frame = 0;
int game_state=0; //0=start, 1=in-game, 2=game over
int set_gameover=0;
int game_state = 0; //0=start, 1=in-game, 2=game over
int set_gameover = 0;
#define gravity 0.25f
#define jump -4.6f
#define gravity 0.25f
#define jump -4.6f
float flappy_bird_position=-5.0f;
float flappy_bird_position = -5.0f;
float flappy_bird_velocity = 0.0f;
float flappy_bird_rotation = 0.0f;
void draw(CVideo *v);
void update(GuiController * c);
void update(GuiController *c);
void process();
};

View File

@ -7,43 +7,38 @@
#include "gui/GuiImageAsync.h"
#include "gui/GuiSound.h"
Resources * Resources::instance = NULL;
Resources *Resources::instance = NULL;
void Resources::Clear()
{
for(int i = 0; RecourceList[i].filename != NULL; ++i)
{
if(RecourceList[i].CustomFile)
{
free(RecourceList[i].CustomFile);
RecourceList[i].CustomFile = NULL;
}
void Resources::Clear() {
for (int i = 0; RecourceList[i].filename != NULL; ++i) {
if (RecourceList[i].CustomFile) {
free(RecourceList[i].CustomFile);
RecourceList[i].CustomFile = NULL;
}
if(RecourceList[i].CustomFileSize != 0)
RecourceList[i].CustomFileSize = 0;
}
if (RecourceList[i].CustomFileSize != 0)
RecourceList[i].CustomFileSize = 0;
}
if(instance)
if (instance)
delete instance;
instance = NULL;
}
bool Resources::LoadFiles(const char * path)
{
if(!path)
return false;
bool Resources::LoadFiles(const char *path) {
if (!path)
return false;
bool result = false;
Clear();
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;
uint8_t * buffer = NULL;
uint8_t *buffer = NULL;
uint32_t filesize = 0;
FSUtils::LoadFileToMem(fullpath.c_str(), &buffer, &filesize);
@ -51,82 +46,68 @@ bool Resources::LoadFiles(const char * path)
RecourceList[i].CustomFile = buffer;
RecourceList[i].CustomFileSize = (uint32_t) filesize;
result |= (buffer != 0);
}
}
return result;
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)
{
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFile : RecourceList[i].DefaultFile);
}
}
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);
}
}
return NULL;
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)
{
return (RecourceList[i].CustomFile ? RecourceList[i].CustomFileSize : RecourceList[i].DefaultFileSize);
}
}
return 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)
{
if(!instance)
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)
{
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;
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;
if(buff == NULL)
if (buff == NULL)
return NULL;
GuiImageData * image = new GuiImageData(buff, size);
GuiImageData *image = new GuiImageData(buff, size);
instance->imageDataMap[std::string(filename)].first = 1;
instance->imageDataMap[std::string(filename)].second = image;
return image;
}
}
}
}
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;
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)
{
AsyncDeleter::pushForDelete( itr->second.second );
if (itr->second.first == 0) {
AsyncDeleter::pushForDelete(itr->second.second);
instance->imageDataMap.erase(itr);
}
break;
@ -134,52 +115,44 @@ void Resources::RemoveImageData(GuiImageData * image)
}
}
GuiSound * Resources::GetSound(const char * filename)
{
if(!instance)
GuiSound *Resources::GetSound(const char *filename) {
if (!instance)
instance = new Resources;
std::map<std::string, std::pair<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)
{
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;
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;
if(buff == NULL)
if (buff == NULL)
return NULL;
GuiSound * sound = new GuiSound(buff, size);
GuiSound *sound = new GuiSound(buff, size);
instance->soundDataMap[std::string(filename)].first = 1;
instance->soundDataMap[std::string(filename)].second = sound;
return sound;
}
}
}
}
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;
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)
{
AsyncDeleter::pushForDelete( itr->second.second );
if (itr->second.first == 0) {
AsyncDeleter::pushForDelete(itr->second.second);
instance->soundDataMap.erase(itr);
}
break;

View File

@ -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 bool LoadFiles(const char *path);
static const uint8_t *GetFile(const char *filename);
static uint32_t GetFileSize(const char *filename);
static GuiImageData *GetImageData(const char *filename);
static void RemoveImageData(GuiImageData *image);
static GuiSound *GetSound(const char *filename);
static void RemoveSound(GuiSound *sound);
static GuiSound * GetSound(const char * filename);
static void RemoveSound(GuiSound * sound);
private:
static Resources *instance;
Resources() {}
~Resources() {}
std::map<std::string, std::pair<unsigned int, GuiImageData *> > imageDataMap;

View File

@ -16,11 +16,10 @@
****************************************************************************/
#include "AsyncDeleter.h"
AsyncDeleter * AsyncDeleter::deleterInstance = NULL;
AsyncDeleter *AsyncDeleter::deleterInstance = NULL;
AsyncDeleter::AsyncDeleter()
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff)
, exitApplication(false) {
: CThread(CThread::eAttributeAffCore1 | CThread::eAttributePinnedAff), exitApplication(false) {
}
AsyncDeleter::~AsyncDeleter() {
@ -28,14 +27,14 @@ AsyncDeleter::~AsyncDeleter() {
}
void AsyncDeleter::triggerDeleteProcess(void) {
if(!deleterInstance)
if (!deleterInstance)
deleterInstance = new AsyncDeleter;
//! to trigger the event after GUI process is finished execution
//! this function is used to swap elements from one to next array
if(!deleterInstance->deleteElements.empty()) {
if (!deleterInstance->deleteElements.empty()) {
deleterInstance->deleteMutex.lock();
while(!deleterInstance->deleteElements.empty()) {
while (!deleterInstance->deleteElements.empty()) {
deleterInstance->realDeleteElements.push(deleterInstance->deleteElements.front());
deleterInstance->deleteElements.pop();
}
@ -45,12 +44,12 @@ void AsyncDeleter::triggerDeleteProcess(void) {
}
void AsyncDeleter::executeThread(void) {
while(!exitApplication) {
while (!exitApplication) {
suspendThread();
//! delete elements that require post process deleting
//! because otherwise they would block or do invalid access on GUI thread
while(!realDeleteElements.empty()) {
while (!realDeleteElements.empty()) {
deleteMutex.lock();
GuiElement *element = realDeleteElements.front();
realDeleteElements.pop();

View File

@ -32,11 +32,12 @@ public:
class Element {
public:
Element() {}
virtual ~Element() {}
};
static void pushForDelete(GuiElement *e) {
if(!deleterInstance)
if (!deleterInstance)
deleterInstance = new AsyncDeleter;
deleterInstance->deleteElements.push(e);
@ -46,6 +47,7 @@ public:
private:
AsyncDeleter();
virtual ~AsyncDeleter();
static AsyncDeleter *deleterInstance;

View File

@ -20,48 +20,52 @@
#include <malloc.h>
#include <coreinit/mutex.h>
class CMutex
{
class CMutex {
public:
CMutex() {
pMutex = (OSMutex*) malloc(sizeof(OSMutex));
if(!pMutex)
pMutex = (OSMutex *) malloc(sizeof(OSMutex));
if (!pMutex)
return;
OSInitMutex(pMutex);
}
virtual ~CMutex() {
if(pMutex)
if (pMutex)
free(pMutex);
}
void lock(void) {
if(pMutex)
if (pMutex)
OSLockMutex(pMutex);
}
void unlock(void) {
if(pMutex)
if (pMutex)
OSUnlockMutex(pMutex);
}
BOOL tryLock(void) {
if(!pMutex)
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;
};

View File

@ -25,23 +25,20 @@
class CThread {
public:
typedef void (* Callback)(CThread *thread, void *arg);
typedef void (*Callback)(CThread *thread, void *arg);
//! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL)
, pThreadStack(NULL)
, pCallback(callback)
, pCallbackArg(callbackArg) {
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
//! save attribute assignment
iAttributes = iAttr;
//! allocate the thread
pThread = (OSThread*)memalign(8, sizeof(OSThread));
pThread = (OSThread *) memalign(8, sizeof(OSThread));
//! allocate the stack
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
//! create the thread
if(pThread && pThreadStack)
OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
if (pThread && pThreadStack)
OSCreateThread(pThread, &CThread::threadCallback, 1, (char *) this, pThreadStack + iStackSize, iStackSize, iPriority, iAttributes);
}
//! destructor
@ -50,72 +47,81 @@ public:
}
static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
return (new CThread(iAttr, iPriority, iStackSize, callback, callbackArg));
}
//! Get thread ID
virtual void* getThread() const {
virtual void *getThread() const {
return pThread;
}
//! Thread entry function
virtual void executeThread(void) {
if(pCallback)
if (pCallback)
pCallback(this, pCallbackArg);
}
//! Suspend thread
virtual void suspendThread(void) {
if(isThreadSuspended()) return;
if(pThread) OSSuspendThread(pThread);
if (isThreadSuspended()) return;
if (pThread) OSSuspendThread(pThread);
}
//! Resume thread
virtual void resumeThread(void) {
if(!isThreadSuspended()) return;
if(pThread) OSResumeThread(pThread);
if (!isThreadSuspended()) return;
if (pThread) OSResumeThread(pThread);
}
//! Set thread priority
virtual void setThreadPriority(int prio) {
if(pThread) OSSetThreadPriority(pThread, prio);
if (pThread) OSSetThreadPriority(pThread, prio);
}
//! Check if thread is suspended
virtual BOOL isThreadSuspended(void) const {
if(pThread) return OSIsThreadSuspended(pThread);
if (pThread) return OSIsThreadSuspended(pThread);
return false;
}
//! Check if thread is terminated
virtual BOOL isThreadTerminated(void) const {
if(pThread) return OSIsThreadTerminated(pThread);
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
if(pThread && !(iAttributes & eAttributeDetach)) {
if(isThreadSuspended())
if (pThread && !(iAttributes & eAttributeDetach)) {
if (isThreadSuspended())
resumeThread();
OSJoinThread(pThread, NULL);
}
//! free the thread stack buffer
if(pThreadStack)
if (pThreadStack)
free(pThreadStack);
if(pThread)
if (pThread)
free(pThread);
pThread = NULL;
pThreadStack = NULL;
}
//! Thread attributes
enum eCThreadAttributes {
eAttributeNone = 0x07,
eAttributeAffCore0 = 0x01,
eAttributeAffCore1 = 0x02,
eAttributeAffCore2 = 0x04,
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
eAttributeNone = 0x07,
eAttributeAffCore0 = 0x01,
eAttributeAffCore1 = 0x02,
eAttributeAffCore2 = 0x04,
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
};
private:
static int threadCallback(int argc, const char **argv) {
@ -123,6 +129,7 @@ private:
((CThread *) argv)->executeThread();
return 0;
}
int iAttributes;
OSThread *pThread;
uint8_t *pThreadStack;

View File

@ -38,37 +38,31 @@
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);
if(mem1_memory)
if (mem1_memory)
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);
if(bucket_memory)
if (bucket_memory)
bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0);
}
}
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);
}

View File

@ -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_alloc(unsigned int size, unsigned int align);
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 * MEMBucket_alloc(unsigned int size, unsigned int align);
void *MEMBucket_alloc(unsigned int size, unsigned int align);
void MEMBucket_free(void *ptr);
#ifdef __cplusplus

View File

@ -36,12 +36,12 @@
#include <utils/StringTools.h>
BOOL StringTools::EndsWith(const std::string& a, const std::string& b) {
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
if (b.size() > a.size()) return false;
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
}
const char * StringTools::byte_to_binary(int32_t x) {
const char *StringTools::byte_to_binary(int32_t x) {
static char b[9];
b[0] = '\0';
@ -53,25 +53,25 @@ const char * StringTools::byte_to_binary(int32_t x) {
return b;
}
std::string StringTools::removeCharFromString(std::string& input,char toBeRemoved) {
std::string StringTools::removeCharFromString(std::string &input, char toBeRemoved) {
std::string output = input;
size_t position;
while(1) {
while (1) {
position = output.find(toBeRemoved);
if(position == std::string::npos)
if (position == std::string::npos)
break;
output.erase(position, 1);
}
return output;
}
const char * StringTools::fmt(const char * format, ...) {
const char *StringTools::fmt(const char *format, ...) {
static char strChar[512];
strChar[0] = 0;
va_list va;
va_start(va, format);
if((vsprintf(strChar, format, va) >= 0)) {
if ((vsprintf(strChar, format, va) >= 0)) {
va_end(va);
return (const char *) strChar;
}
@ -80,26 +80,26 @@ const char * StringTools::fmt(const char * format, ...) {
return NULL;
}
const wchar_t * StringTools::wfmt(const char * format, ...) {
const wchar_t *StringTools::wfmt(const char *format, ...) {
static char tmp[512];
static wchar_t strWChar[512];
strWChar[0] = 0;
tmp[0] = 0;
if(!format)
if (!format)
return (const wchar_t *) strWChar;
if(strcmp(format, "") == 0)
if (strcmp(format, "") == 0)
return (const wchar_t *) strWChar;
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
int bt;
if ((vsprintf(tmp, format, va) >= 0)) {
int bt;
int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 );
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
if(bt > 0) {
if (bt > 0) {
strWChar[bt] = 0;
return (const wchar_t *) strWChar;
}
@ -109,14 +109,14 @@ const wchar_t * StringTools::wfmt(const char * format, ...) {
return NULL;
}
int32_t StringTools::strprintf(std::string &str, const char * format, ...) {
int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
static char tmp[512];
tmp[0] = 0;
int32_t result = 0;
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp;
result = str.size();
}
@ -125,14 +125,14 @@ int32_t StringTools::strprintf(std::string &str, const char * format, ...) {
return result;
}
std::string StringTools::strfmt(const char * format, ...) {
std::string StringTools::strfmt(const char *format, ...) {
std::string str;
static char tmp[512];
tmp[0] = 0;
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp;
}
va_end(va);
@ -140,11 +140,11 @@ std::string StringTools::strfmt(const char * format, ...) {
return str;
}
BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
if(!strChar || !dest)
BOOL StringTools::char2wchar_t(const char *strChar, wchar_t *dest) {
if (!strChar || !dest)
return false;
int bt;
int bt;
bt = mbstowcs(dest, strChar, strlen(strChar));
if (bt > 0) {
dest[bt] = 0;
@ -154,39 +154,39 @@ BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
return false;
}
int32_t StringTools::strtokcmp(const char * string, const char * compare, const char * separator) {
if(!string || !compare)
int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) {
if (!string || !compare)
return -1;
char TokCopy[512];
strncpy(TokCopy, compare, sizeof(TokCopy));
TokCopy[511] = '\0';
char * strTok = strtok(TokCopy, separator);
char *strTok = strtok(TokCopy, separator);
while (strTok != NULL) {
if (strcasecmp(string, strTok) == 0) {
return 0;
}
strTok = strtok(NULL,separator);
strTok = strtok(NULL, separator);
}
return -1;
}
int32_t StringTools::strextcmp(const char * string, const char * extension, char seperator) {
if(!string || !extension)
int32_t StringTools::strextcmp(const char *string, const char *extension, char seperator) {
if (!string || !extension)
return -1;
char *ptr = strrchr(string, seperator);
if(!ptr)
if (!ptr)
return -1;
return strcasecmp(ptr + 1, extension);
}
std::vector<std::string> StringTools::stringSplit(const std::string & inValue, const std::string & splitter) {
std::vector<std::string> StringTools::stringSplit(const std::string &inValue, const std::string &splitter) {
std::string value = inValue;
std::vector<std::string> result;
while (true) {
@ -201,7 +201,7 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
result.push_back("");
break;
}
if(index + splitter.size() > value.length()) {
if (index + splitter.size() > value.length()) {
break;
}
value = value.substr(index + splitter.size(), value.length());

View File

@ -30,52 +30,58 @@
#include <string>
#include <wut_types.h>
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);
class StringTools {
public:
static BOOL EndsWith(const std::string &a, const std::string &b);
static const char * FullpathToFilename(const char *path){
if(!path) return path;
static const char *byte_to_binary(int32_t x);
const char * ptr = path;
const char * Filename = ptr;
static std::string removeCharFromString(std::string &input, char toBeRemoved);
while(*ptr != '\0')
{
if(ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr+1;
static const char *fmt(const char *format, ...);
++ptr;
}
static const wchar_t *wfmt(const char *format, ...);
return Filename;
static int32_t strprintf(std::string &str, const char *format, ...);
static std::string strfmt(const char *format, ...);
static BOOL char2wchar_t(const char *src, wchar_t *dest);
static int32_t strtokcmp(const char *string, const char *compare, const char *separator);
static int32_t strextcmp(const char *string, const char *extension, char seperator);
static const char *FullpathToFilename(const char *path) {
if (!path) return path;
const char *ptr = path;
const char *Filename = ptr;
while (*ptr != '\0') {
if (ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr + 1;
++ptr;
}
static void RemoveDoubleSlashs(std::string &str){
uint32_t length = str.size();
return Filename;
}
//! clear path of double slashes
for(uint32_t i = 1; i < length; ++i)
{
if(str[i-1] == '/' && str[i] == '/')
{
str.erase(i, 1);
i--;
length--;
}
static void RemoveDoubleSlashs(std::string &str) {
uint32_t length = str.size();
//! clear path of double slashes
for (uint32_t i = 1; i < length; ++i) {
if (str[i - 1] == '/' && str[i] == '/') {
str.erase(i, 1);
i--;
length--;
}
}
}
static std::vector<std::string> stringSplit(const std::string & value, const std::string & splitter);
static std::vector<std::string> stringSplit(const std::string &value, const std::string &splitter);
};
#endif /* __STRING_TOOLS_H */

View File

@ -10,7 +10,7 @@
#include <coreinit/systeminfo.h>
#include <coreinit/thread.h>
static int log_socket __attribute__((section(".data")))= -1;
static int log_socket __attribute__((section(".data"))) = -1;
static struct sockaddr_in connect_addr __attribute__((section(".data")));
static volatile int log_lock __attribute__((section(".data"))) = 0;
@ -30,20 +30,20 @@ void log_init_() {
void log_print_(const char *str) {
// socket is always 0 initially as it is in the BSS
if(log_socket < 0) {
if (log_socket < 0) {
return;
}
while(log_lock)
OSSleepTicks(OSMicrosecondsToTicks(1000));
while (log_lock)
OSSleepTicks(OSMicrosecondsToTicks(1000));
log_lock = 1;
int len = strlen(str);
int ret;
while (len > 0) {
int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
ret = sendto(log_socket, str, block, 0, (struct sockaddr *)&connect_addr, sizeof(struct sockaddr_in));
if(ret < 0)
ret = sendto(log_socket, str, block, 0, (struct sockaddr *) &connect_addr, sizeof(struct sockaddr_in));
if (ret < 0)
break;
len -= ret;
@ -54,18 +54,18 @@ void log_print_(const char *str) {
}
void OSFatal_printf(const char *format, ...) {
char tmp[512];
char tmp[512];
tmp[0] = 0;
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
if ((vsprintf(tmp, format, va) >= 0)) {
OSFatal(tmp);
}
va_end(va);
}
void log_printf_(const char *format, ...) {
if(log_socket < 0) {
if (log_socket < 0) {
return;
}
@ -74,7 +74,7 @@ void log_printf_(const char *format, ...) {
va_list va;
va_start(va, format);
if((vsprintf(tmp, format, va) >= 0)) {
if ((vsprintf(tmp, format, va) >= 0)) {
log_print_(tmp);
}
va_end(va);

View File

@ -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

View File

@ -7,31 +7,31 @@
#include <utils/logger.h>
// https://gist.github.com/ccbrown/9722406
void dumpHex(const void* data, size_t size) {
void dumpHex(const void *data, size_t size) {
char ascii[17];
size_t i, j;
ascii[16] = '\0';
DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data);
for (i = 0; i < size; ++i) {
log_printf("%02X ", ((unsigned char*)data)[i]);
if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') {
ascii[i % 16] = ((unsigned char*)data)[i];
log_printf("%02X ", ((unsigned char *) data)[i]);
if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') {
ascii[i % 16] = ((unsigned char *) data)[i];
} else {
ascii[i % 16] = '.';
}
if ((i+1) % 8 == 0 || i+1 == size) {
if ((i + 1) % 8 == 0 || i + 1 == size) {
log_printf(" ");
if ((i+1) % 16 == 0) {
if ((i + 1) % 16 == 0) {
log_printf("| %s \n", ascii);
if(i + 1 < size) {
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1,i+1);
if (i + 1 < size) {
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1);
}
} else if (i+1 == size) {
ascii[(i+1) % 16] = '\0';
if ((i+1) % 16 <= 8) {
} else if (i + 1 == size) {
ascii[(i + 1) % 16] = '\0';
if ((i + 1) % 16 <= 8) {
log_printf(" ");
}
for (j = (i+1) % 16; j < 16; ++j) {
for (j = (i + 1) % 16; j < 16; ++j) {
log_printf(" ");
}
log_printf("| %s \n", ascii);

View File

@ -7,12 +7,12 @@
extern "C" {
#endif
#define LIMIT(x, min, max) \
({ \
typeof( x ) _x = x; \
typeof( min ) _min = min; \
typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
#define LIMIT(x, min, max) \
({ \
typeof( x ) _x = x; \
typeof( min ) _min = min; \
typeof( max ) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \
})
#define DegToRad(a) ( (a) * 0.01745329252f )
@ -26,7 +26,7 @@ extern "C" {
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32)))
//Needs to have log_init() called beforehand.
void dumpHex(const void* data, size_t size);
void dumpHex(const void *data, size_t size);
#ifdef __cplusplus
}