Erwan
- Zip file support for card pictures - TODO : linux, update JGFX.cpp for zip support - TODO : make sure there is no leak in the PSP version
This commit is contained in:
@@ -68,8 +68,7 @@ JFileSystem::JFileSystem()
|
||||
|
||||
JFileSystem::~JFileSystem()
|
||||
{
|
||||
if (mZipAvailable && mZipFile != NULL)
|
||||
unzCloseCurrentFile(mZipFile);
|
||||
DetachZipFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +77,9 @@ bool JFileSystem::AttachZipFile(const string &zipfile, char *password /* = NULL
|
||||
if (mZipAvailable && mZipFile != NULL)
|
||||
{
|
||||
if (mZipFileName != zipfile)
|
||||
unzCloseCurrentFile(mZipFile); // close the previous zip file
|
||||
DetachZipFile(); // close the previous zip file
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
mZipFileName = zipfile;
|
||||
@@ -101,6 +102,7 @@ void JFileSystem::DetachZipFile()
|
||||
if (mZipAvailable && mZipFile != NULL)
|
||||
{
|
||||
unzCloseCurrentFile(mZipFile);
|
||||
unzClose(mZipFile);
|
||||
}
|
||||
|
||||
mZipFile = NULL;
|
||||
@@ -115,9 +117,10 @@ bool JFileSystem::OpenFile(const string &filename)
|
||||
|
||||
if (mZipAvailable && mZipFile != NULL)
|
||||
{
|
||||
if (unzLocateFile(mZipFile, path.c_str(), 0) != UNZ_OK)
|
||||
return false;
|
||||
|
||||
if (unzLocateFile(mZipFile, filename.c_str(), 0) != UNZ_OK){
|
||||
DetachZipFile();
|
||||
return OpenFile(filename);
|
||||
}
|
||||
char filenameInzip[256];
|
||||
unz_file_info fileInfo;
|
||||
|
||||
@@ -159,8 +162,10 @@ bool JFileSystem::OpenFile(const string &filename)
|
||||
|
||||
void JFileSystem::CloseFile()
|
||||
{
|
||||
if (mZipAvailable && mZipFile != NULL)
|
||||
if (mZipAvailable && mZipFile != NULL){
|
||||
unzCloseCurrentFile(mZipFile);
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
if (mFile != NULL)
|
||||
|
||||
@@ -1022,7 +1022,7 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
u8 *scanline, *p;
|
||||
u8 *rawdata, *scanline, *p;
|
||||
u16 *rgbadata16, *q16, *bits16;
|
||||
u32 *rgbadata32, *q32, *bits32;
|
||||
int rawsize, i;
|
||||
@@ -1030,6 +1030,7 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
bits16 = NULL;
|
||||
bits32 = NULL;
|
||||
|
||||
/*
|
||||
FILE * fp = fopen(filenamenew, "rb");
|
||||
if (fp==NULL)
|
||||
return;
|
||||
@@ -1039,6 +1040,39 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
jpeg_stdio_src(&cinfo, fp);
|
||||
*/
|
||||
|
||||
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (!fileSystem->OpenFile(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rawsize = fileSystem->GetFileSize();
|
||||
|
||||
rawdata = new u8[rawsize];
|
||||
|
||||
if (!rawdata)
|
||||
{
|
||||
fileSystem->CloseFile();
|
||||
return;
|
||||
}
|
||||
|
||||
fileSystem->ReadFile(rawdata, rawsize);
|
||||
fileSystem->CloseFile();
|
||||
|
||||
/* if (rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
|
||||
{
|
||||
delete [] rawdata;
|
||||
return;
|
||||
} */
|
||||
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
jpeg_mem_src(&cinfo, rawdata, rawsize);
|
||||
|
||||
|
||||
jpeg_read_header(&cinfo, true);
|
||||
@@ -1175,7 +1209,9 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
|
||||
free(scanline);
|
||||
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
try{
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
}catch(...){}
|
||||
|
||||
|
||||
|
||||
@@ -1202,7 +1238,8 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
textureInfo.mVRAM =videoRAMUsed;
|
||||
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(fp);
|
||||
// fclose(fp);
|
||||
delete [] rawdata;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -608,17 +608,45 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
BYTE *rgbadata, *scanline, *p, *q;
|
||||
BYTE *rawdata, *rgbadata, *scanline, *p, *q;
|
||||
int rawsize, i;
|
||||
|
||||
char filenamenew[4096];
|
||||
sprintf(filenamenew, "Res/%s", filename);
|
||||
// char filenamenew[4096];
|
||||
// sprintf(filenamenew, "Res/%s", filename);
|
||||
|
||||
|
||||
// Initialise libJpeg Object
|
||||
|
||||
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (!fileSystem->OpenFile(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rawsize = fileSystem->GetFileSize();
|
||||
|
||||
rawdata = new BYTE[rawsize];
|
||||
|
||||
if (!rawdata)
|
||||
{
|
||||
fileSystem->CloseFile();
|
||||
return;
|
||||
}
|
||||
|
||||
fileSystem->ReadFile(rawdata, rawsize);
|
||||
fileSystem->CloseFile();
|
||||
|
||||
/* if (rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
|
||||
{
|
||||
delete [] rawdata;
|
||||
return;
|
||||
} */
|
||||
|
||||
// Initialise libJpeg Object
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
/*
|
||||
FILE* fp = fopen(filenamenew, "rb");
|
||||
if (fp == NULL)
|
||||
{
|
||||
@@ -627,12 +655,16 @@ FILE* fp = fopen(filenamenew, "rb");
|
||||
}
|
||||
|
||||
jpeg_stdio_src(&cinfo, fp);
|
||||
*/
|
||||
|
||||
jpeg_mem_src(&cinfo, rawdata, rawsize);
|
||||
|
||||
// Process JPEG header
|
||||
jpeg_read_header(&cinfo, true);
|
||||
|
||||
|
||||
|
||||
|
||||
// Start Decompression
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
@@ -703,7 +735,8 @@ FILE* fp = fopen(filenamenew, "rb");
|
||||
|
||||
|
||||
|
||||
fclose(fp);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -715,12 +748,14 @@ fclose(fp);
|
||||
|
||||
|
||||
// Finish Decompression
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
|
||||
try{
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
}catch(...){}
|
||||
// Destroy JPEG object
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
|
||||
//fclose(fp);
|
||||
delete [] rawdata;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../include/GameApp.h"
|
||||
#include "../include/MTGCard.h"
|
||||
|
||||
static const char* GAME_VERSION = "WTH?! 0.6.1 - by WilLoW";
|
||||
static const char* GAME_VERSION = "WTH?! 0.6.2 - by WilLoW";
|
||||
#define ALPHA_WARNING 0
|
||||
|
||||
#define DEFAULT_ANGLE_MULTIPLIER 0.4
|
||||
|
||||
@@ -73,9 +73,9 @@ void GameStateOptions::Render()
|
||||
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
|
||||
|
||||
const char * const CreditsText[] = {
|
||||
"Wagic, The Homebrew ?! by WilLoW",
|
||||
"Wagic, The Homebrew?! by WilLoW",
|
||||
"",
|
||||
"updates, new cards, and more on http://www.wololo.net/wagic",
|
||||
"updates, new cards, and more on http://wololo.net/wagic",
|
||||
"Many thanks to the devs and card creators who help this project",
|
||||
"",
|
||||
"Developped with the JGE++ Library (http://jge.khors.com)",
|
||||
@@ -83,8 +83,8 @@ void GameStateOptions::Render()
|
||||
"Background picture from KDE4 , www.kde.org",
|
||||
"SFX From www.soundsnap.com",
|
||||
"",
|
||||
"Music by Celestial Aeon Project, under Creative Commons License",
|
||||
"Their music can be downloaded at http://www.jamendo.com",
|
||||
"Music by Celestial Aeon Project, http://www.jamendo.com",
|
||||
"",
|
||||
"",
|
||||
"This work is not related to or endorsed by Wizards of the Coast, Inc",
|
||||
"",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../include/config.h"
|
||||
#include "../include/TexturesCache.h"
|
||||
#include "../include/GameOptions.h"
|
||||
#include <JFileSystem.h>
|
||||
|
||||
TexturesCache::TexturesCache(){
|
||||
nb_textures = 0;
|
||||
@@ -95,6 +96,7 @@ int CardTexture::getId(){
|
||||
|
||||
CardTexture::CardTexture(MTGCard * card, int _type): type(_type){
|
||||
LOG("==Creating CardTexture Object");
|
||||
JFileSystem* fs = JFileSystem::GetInstance();
|
||||
char filename[100];
|
||||
quad = NULL;
|
||||
tex = NULL;
|
||||
@@ -105,11 +107,23 @@ CardTexture::CardTexture(MTGCard * card, int _type): type(_type){
|
||||
}else{
|
||||
sprintf(filename, "sets/%s/%s", card->getSetName(), card->getImageName());
|
||||
}
|
||||
#ifdef WIN32
|
||||
OutputDebugString(filename);
|
||||
#endif
|
||||
if (fileExists(filename))
|
||||
|
||||
if (fileExists(filename)){
|
||||
fs->DetachZipFile();
|
||||
tex = JRenderer::GetInstance()->LoadTexture(filename, false,GU_PSM_5551);
|
||||
}else{
|
||||
char zipname[100];
|
||||
sprintf(zipname, "Res/sets/%s/%s.zip", card->getSetName(),card->getSetName());
|
||||
if (fileExists(zipname)){
|
||||
fs->AttachZipFile(zipname);
|
||||
if (type == CACHE_THUMB){
|
||||
sprintf(filename, "thumbnails/%s", card->getImageName());
|
||||
}else{
|
||||
sprintf(filename, "%s", card->getImageName());
|
||||
}
|
||||
tex = JRenderer::GetInstance()->LoadTexture(filename, false,GU_PSM_5551);
|
||||
}
|
||||
}
|
||||
if (tex){
|
||||
quad = NEW JQuad(tex, 0.0f, 0.0f, tex->mWidth, tex->mHeight);
|
||||
nbpixels = tex->mTexHeight * tex->mTexWidth;
|
||||
|
||||
Reference in New Issue
Block a user