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