mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-22 03:09:15 +01:00
*Fix for image resource manager
This commit is contained in:
parent
1c4f46e8e5
commit
c5c5708e12
@ -2,8 +2,8 @@
|
||||
<app version="1">
|
||||
<name> USB Loader GX</name>
|
||||
<coder>USB Loader GX Team</coder>
|
||||
<version>1.0 r978</version>
|
||||
<release_date>201009260928</release_date>
|
||||
<version>1.0 r979</version>
|
||||
<release_date>201009260941</release_date>
|
||||
<short_description>Loads games from USB-devices</short_description>
|
||||
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
|
||||
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.
|
||||
|
File diff suppressed because one or more lines are too long
@ -60,19 +60,7 @@ GuiImageData::GuiImageData(const u8 * img, int imgSize)
|
||||
height = 0;
|
||||
format = GX_TF_RGBA8;
|
||||
|
||||
if(ResourceManager::Exists(img, imgSize) == true)
|
||||
{
|
||||
GuiImageData * Image = ResourceManager::GetImageData(img, imgSize);
|
||||
|
||||
data = Image->GetImage();
|
||||
width = Image->GetWidth();
|
||||
height = Image->GetHeight();
|
||||
format = Image->GetTextureFormat();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadImage(img, imgSize);
|
||||
}
|
||||
LoadImage(img, imgSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,13 +77,17 @@ void GuiImageData::LoadImage(const u8 * img, int imgSize)
|
||||
if(!img)
|
||||
return;
|
||||
|
||||
if(data)
|
||||
ImageData * Image = ResourceManager::GetImageData(img);
|
||||
if(Image != NULL && Image->data != NULL)
|
||||
{
|
||||
free(data);
|
||||
data = NULL;
|
||||
data = Image->data;
|
||||
width = Image->width;
|
||||
height = Image->height;
|
||||
format = Image->format;
|
||||
return;
|
||||
}
|
||||
|
||||
if (imgSize < 8)
|
||||
else if (imgSize < 8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -124,6 +116,13 @@ void GuiImageData::LoadImage(const u8 * img, int imgSize)
|
||||
// IMAGE_TPL
|
||||
LoadTPL(img, imgSize);
|
||||
}
|
||||
|
||||
ImageData NewImage;
|
||||
NewImage.data = data;
|
||||
NewImage.width = width;
|
||||
NewImage.height = height;
|
||||
NewImage.format = format;
|
||||
ResourceManager::AddImageData(img, NewImage);
|
||||
}
|
||||
|
||||
void GuiImageData::LoadPNG(const u8 *img, int imgSize)
|
||||
|
@ -51,9 +51,8 @@ class GuiImageData
|
||||
int GetHeight() { return height; };
|
||||
//!Gets the texture format
|
||||
u8 GetTextureFormat() { return format; };
|
||||
//!Load a new image into this GuiImageData
|
||||
void LoadImage(const u8 * img, int imgSize);
|
||||
protected:
|
||||
void LoadImage(const u8 * img, int imgSize);
|
||||
void LoadPNG(const u8 *img, int imgSize);
|
||||
void LoadBMP(const u8 *img, int imgSize);
|
||||
void LoadJpeg(const u8 *img, int imgSize);
|
||||
|
@ -165,8 +165,7 @@ static void * UpdateGUI(void *arg)
|
||||
for (i = 5; i < 255; i += 10)
|
||||
{
|
||||
if (strcmp(headlessID, "") == 0) mainWindow->Draw();
|
||||
Menu_DrawRectangle(0, 0, screenwidth, screenheight, ( GXColor )
|
||||
{ 0, 0, 0, i}, 1);
|
||||
Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, i}, 1);
|
||||
Menu_Render();
|
||||
}
|
||||
mainWindow->RemoveAll();
|
||||
@ -236,7 +235,7 @@ GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D, bool noCove
|
||||
{
|
||||
flag = !flag;
|
||||
delete Cover;
|
||||
Cover = new (std::nothrow) GuiImageData(Resources::GetFile(Prefere3D ? "nocover.png" : "nocoverFlat.png"), Resources::GetFileSize(Prefere3D ? "nocover.png" : "nocoverFlat.png"));
|
||||
Cover = Resources::GetImageData(Prefere3D ? "nocover.png" : "nocoverFlat.png");
|
||||
if (Cover && Cover->GetImage()) break;
|
||||
}
|
||||
}
|
||||
@ -253,22 +252,16 @@ GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D, bool noCove
|
||||
***************************************************************************/
|
||||
int MainMenu(int menu)
|
||||
{
|
||||
|
||||
currentMenu = menu;
|
||||
|
||||
//if (strcmp(headlessID,"")!=0)HaltGui();
|
||||
//WindowPrompt("Can you see me now",0,"ok");
|
||||
|
||||
pointer[0] = new GuiImageData(Resources::GetFile("player1_point.png"), Resources::GetFileSize("player1_point.png"));
|
||||
pointer[1] = new GuiImageData(Resources::GetFile("player2_point.png"), Resources::GetFileSize("player2_point.png"));
|
||||
pointer[2] = new GuiImageData(Resources::GetFile("player3_point.png"), Resources::GetFileSize("player3_point.png"));
|
||||
pointer[3] = new GuiImageData(Resources::GetFile("player4_point.png"), Resources::GetFileSize("player4_point.png"));
|
||||
pointer[0] = Resources::GetImageData("player1_point.png");
|
||||
pointer[1] = Resources::GetImageData("player2_point.png");
|
||||
pointer[2] = Resources::GetImageData("player3_point.png");
|
||||
pointer[3] = Resources::GetImageData("player4_point.png");
|
||||
|
||||
mainWindow = new GuiWindow(screenwidth, screenheight);
|
||||
|
||||
const char * image = Settings.widescreen ? "wbackground.png" : "background.png";
|
||||
|
||||
background = new GuiImageData(Resources::GetFile(image), Resources::GetFileSize(image));
|
||||
background = Resources::GetImageData(Settings.widescreen ? "wbackground.png" : "background.png");
|
||||
|
||||
bgImg = new GuiImage(background);
|
||||
mainWindow->Append(bgImg);
|
||||
|
@ -46,59 +46,50 @@ void ResourceManager::DestroyInstance()
|
||||
ResourceManager::~ResourceManager()
|
||||
{
|
||||
// Delete all images...
|
||||
std::map<const u8 *, GuiImageData *>::iterator imgitr;
|
||||
std::map<const u8 *, ImageData>::iterator imgitr;
|
||||
for (imgitr = images.begin(); imgitr != images.end(); imgitr++)
|
||||
{
|
||||
delete imgitr->second;
|
||||
if(imgitr->second.data)
|
||||
free(imgitr->second.data);
|
||||
}
|
||||
images.clear();
|
||||
imageCount.clear();
|
||||
}
|
||||
|
||||
bool ResourceManager::Exists(const u8 *img, u32 imgSize)
|
||||
void ResourceManager::AddImageData(const u8 *img, ImageData & Data)
|
||||
{
|
||||
return ResourceManager::Instance()->InternalExists(img, imgSize);
|
||||
ResourceManager::Instance()->InternalAddImageData(img, Data);
|
||||
}
|
||||
|
||||
bool ResourceManager::InternalExists(const u8 *img, u32 imgSize)
|
||||
ImageData * ResourceManager::GetImageData(const u8 *img)
|
||||
{
|
||||
std::map<const u8 *, GuiImageData *>::iterator itr = images.find(img);
|
||||
|
||||
return (itr != images.end());
|
||||
return ResourceManager::Instance()->InternalGetImageData(img);
|
||||
}
|
||||
|
||||
GuiImageData * ResourceManager::GetImageData(const u8 *img, u32 imgSize)
|
||||
{
|
||||
return ResourceManager::Instance()->InternalGetImageData(img, imgSize);
|
||||
}
|
||||
|
||||
void ResourceManager::Remove(GuiImageData *img)
|
||||
{
|
||||
if(!img)
|
||||
return;
|
||||
|
||||
ResourceManager::Instance()->InternalRemoveImageData(img->GetImage());
|
||||
}
|
||||
|
||||
void ResourceManager::Remove(u8 *img)
|
||||
void ResourceManager::Remove(u8 * img)
|
||||
{
|
||||
ResourceManager::Instance()->InternalRemoveImageData(img);
|
||||
}
|
||||
|
||||
GuiImageData * ResourceManager::InternalGetImageData(const u8 *img, u32 imgSize)
|
||||
void ResourceManager::InternalAddImageData(const u8 * img, ImageData & Data)
|
||||
{
|
||||
std::map<const u8 *, GuiImageData *>::iterator itr = images.find(img);
|
||||
if (itr == images.end())
|
||||
{
|
||||
// Not found, create a new one
|
||||
GuiImageData *d = new GuiImageData(img, imgSize);
|
||||
images[img] = d;
|
||||
imageCount[d->GetImage()] = 1;
|
||||
return d;
|
||||
std::map<const u8 *, ImageData>::iterator itr = images.find(img);
|
||||
if (itr != images.end())
|
||||
return;
|
||||
|
||||
}
|
||||
imageCount[itr->second->GetImage()]++;
|
||||
return itr->second;
|
||||
images[img] = Data;
|
||||
imageCount[Data.data] = 1;
|
||||
}
|
||||
|
||||
ImageData * ResourceManager::InternalGetImageData(const u8 *img)
|
||||
{
|
||||
std::map<const u8 *, ImageData>::iterator itr = images.find(img);
|
||||
if (itr == images.end())
|
||||
return NULL;
|
||||
|
||||
imageCount[itr->second.data]++;
|
||||
|
||||
return &itr->second;
|
||||
}
|
||||
|
||||
void ResourceManager::InternalRemoveImageData(u8 * img)
|
||||
@ -112,12 +103,13 @@ void ResourceManager::InternalRemoveImageData(u8 * img)
|
||||
{
|
||||
imageCount.erase(itr);
|
||||
|
||||
std::map<const u8 *, GuiImageData *>::iterator iitr;
|
||||
std::map<const u8 *, ImageData>::iterator iitr;
|
||||
for (iitr = images.begin(); iitr != images.end(); iitr++)
|
||||
{
|
||||
if (iitr->second->GetImage() == img)
|
||||
if (iitr->second.data == img)
|
||||
{
|
||||
delete iitr->second;
|
||||
if(iitr->second.data)
|
||||
free(iitr->second.data);
|
||||
images.erase(iitr);
|
||||
break;
|
||||
}
|
||||
@ -126,32 +118,7 @@ void ResourceManager::InternalRemoveImageData(u8 * img)
|
||||
}
|
||||
else if(img)
|
||||
{
|
||||
//! This case should actually never accur
|
||||
free(img);
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::InternalRemoveImageData(GuiImageData * img)
|
||||
{
|
||||
std::map<u8 *, int>::iterator itr = imageCount.find(img->GetImage());
|
||||
if (itr != imageCount.end())
|
||||
{
|
||||
itr->second--;
|
||||
|
||||
if (itr->second == 0) // Remove the resource
|
||||
{
|
||||
imageCount.erase(itr);
|
||||
|
||||
std::map<const u8 *, GuiImageData *>::iterator iitr;
|
||||
for (iitr = images.begin(); iitr != images.end(); iitr++)
|
||||
{
|
||||
if (iitr->second == img)
|
||||
{
|
||||
delete iitr->second;
|
||||
images.erase(iitr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,27 +31,33 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
typedef struct _ImageData
|
||||
{
|
||||
u8 * data;
|
||||
int width;
|
||||
int height;
|
||||
u8 format;
|
||||
} ImageData;
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
static ResourceManager *Instance();
|
||||
static void DestroyInstance();
|
||||
|
||||
static GuiImageData * GetImageData(const u8 *img, u32 imgSize);
|
||||
static bool Exists(const u8 *img, u32 imgSize);
|
||||
static void Remove(GuiImageData * img);
|
||||
static void AddImageData(const u8 *img, ImageData & data);
|
||||
static ImageData * GetImageData(const u8 *img);
|
||||
static void Remove(u8 * img);
|
||||
private:
|
||||
bool InternalExists(const u8 *img, u32 imgSize);
|
||||
GuiImageData *InternalGetImageData(const u8 *img, u32 imgSize);
|
||||
void InternalRemoveImageData(GuiImageData *img);
|
||||
void InternalRemoveImageData(u8 *img);
|
||||
void InternalAddImageData(const u8 * img, ImageData & Data);
|
||||
ImageData *InternalGetImageData(const u8 *img);
|
||||
void InternalRemoveImageData(u8 * img);
|
||||
|
||||
~ResourceManager();
|
||||
|
||||
static ResourceManager *instance;
|
||||
|
||||
std::map<const u8 *, GuiImageData *> images;
|
||||
std::map<const u8 *, ImageData> images;
|
||||
std::map<u8 *, int> imageCount;
|
||||
};
|
||||
|
||||
|
@ -30,6 +30,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//! fmt and wfmt can only be used once at a session and the strings needs
|
||||
//! to be copied afterwards. A second use overwrites the first string.
|
||||
const char * fmt(const char * format, ...);
|
||||
const wchar_t * wfmt(const char * format, ...);
|
||||
bool char2wchar_t(const char * src, wchar_t * dest);
|
||||
|
Loading…
Reference in New Issue
Block a user