Movement of loading code, and addition of OpenFromZip, removal of PhysFS
in light of new zlib based code.
This commit is contained in:
parent
f7c8398239
commit
1000addea2
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZEngine utility functions.
|
\brief Source file for ZEngine utility functions.
|
||||||
|
|
||||||
Source file containing open utilities for use inside and alongside ZEngine.
|
Source file containing open utilities for use inside and alongside ZEngine.
|
||||||
<br>$Id: ZE_Utility.cpp,v 1.10 2003/07/12 01:25:42 cozman Exp $<br>
|
<br>$Id: ZE_Utility.cpp,v 1.11 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -33,6 +33,48 @@ std::string FormatStr(const char *fmtstr, ...)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_RWops* RWFromZip(std::string zipname, std::string filename)
|
||||||
|
{
|
||||||
|
unzFile zip = unzOpen(zipname.c_str());
|
||||||
|
unz_file_info info;
|
||||||
|
void *buffer;
|
||||||
|
|
||||||
|
if(!zip) //failed to open zip
|
||||||
|
{
|
||||||
|
//log error
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//locate the file and open it (last param means case sensitive comparison)
|
||||||
|
unzLocateFile(zip,filename.c_str(),0);
|
||||||
|
if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//find current file info (we are looking for uncompressed file size)
|
||||||
|
unzGetCurrentFileInfo(zip,&info,NULL,0,NULL,0,NULL,0);
|
||||||
|
|
||||||
|
//create a buffer big enough to hold uncompressed file in memory
|
||||||
|
buffer = (void*)new char[info.uncompressed_size];
|
||||||
|
if(!buffer)
|
||||||
|
{
|
||||||
|
unzCloseCurrentFile(zip);
|
||||||
|
unzClose(zip);
|
||||||
|
//log error (failed to allocate memory?!)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//load into memory
|
||||||
|
unzReadCurrentFile(zip, buffer, info.uncompressed_size);
|
||||||
|
|
||||||
|
//close archive
|
||||||
|
unzCloseCurrentFile(zip);
|
||||||
|
unzClose(zip);
|
||||||
|
|
||||||
|
return SDL_RWFromMem(buffer, info.uncompressed_size); //return buffer in RW form
|
||||||
|
}
|
||||||
|
|
||||||
//Each of the Free*s safely frees & NULLs the pointer
|
//Each of the Free*s safely frees & NULLs the pointer
|
||||||
void FreeImage(SDL_Surface *&image)
|
void FreeImage(SDL_Surface *&image)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Central source file for ZEngine.
|
\brief Central source file for ZEngine.
|
||||||
|
|
||||||
Actual implementation of ZEngine singleton class, the core of ZEngine.
|
Actual implementation of ZEngine singleton class, the core of ZEngine.
|
||||||
<br>$Id: ZE_ZEngine.cpp,v 1.58 2003/09/21 03:28:53 cozman Exp $<br>
|
<br>$Id: ZE_ZEngine.cpp,v 1.59 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -184,7 +184,12 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_WM_SetCaption(title.c_str(),title.c_str());
|
SDL_WM_SetCaption(title.c_str(),title.c_str());
|
||||||
iconImg = LoadImage(icon);
|
|
||||||
|
#ifdef USE_SDL_IMAGE
|
||||||
|
iconImg = IMG_Load(icon.c_str());
|
||||||
|
#else
|
||||||
|
iconImg = SDL_LoadBMP(icon.c_str());
|
||||||
|
#endif
|
||||||
SDL_WM_SetIcon(iconImg,NULL);
|
SDL_WM_SetIcon(iconImg,NULL);
|
||||||
FreeImage(iconImg);
|
FreeImage(iconImg);
|
||||||
}
|
}
|
||||||
@ -677,120 +682,6 @@ double ZEngine::RandDouble()
|
|||||||
return mRandGen.RandDouble();
|
return mRandGen.RandDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface* ZEngine::LoadImage(std::string filename)
|
|
||||||
{
|
|
||||||
SDL_Surface *image;
|
|
||||||
//using physfs//
|
|
||||||
#ifdef USE_PHYSFS
|
|
||||||
SDL_RWops *rw;
|
|
||||||
rw = PHYSFSRWOPS_openRead(filename.c_str());
|
|
||||||
if(!rw)
|
|
||||||
{
|
|
||||||
ReportError(ZERR_LOAD_IMAGE,FormatStr("%s [PhysFS RWops failed: %s]",filename.c_str(),SDL_GetError()));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#ifdef USE_SDL_IMAGE
|
|
||||||
image = IMG_Load_RW(rw,0);
|
|
||||||
#else
|
|
||||||
image = SDL_LoadBMP_RW(rw,0);
|
|
||||||
#endif //USE_SDL_IMAGE
|
|
||||||
SDL_FreeRW(rw);
|
|
||||||
//end using physfs//
|
|
||||||
|
|
||||||
//Just SDL//
|
|
||||||
#else
|
|
||||||
#ifdef USE_SDL_IMAGE
|
|
||||||
image = IMG_Load(filename.c_str());
|
|
||||||
#else
|
|
||||||
image = SDL_LoadBMP(filename.c_str());
|
|
||||||
#endif //USE_SDL_IMAGE
|
|
||||||
#endif //USE_PHYSFS
|
|
||||||
|
|
||||||
if(!image)
|
|
||||||
{
|
|
||||||
ReportError(ZERR_LOAD_IMAGE,filename);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef USE_SDL_MIXER
|
|
||||||
|
|
||||||
Mix_Chunk* ZEngine::LoadSound(std::string filename)
|
|
||||||
{
|
|
||||||
Mix_Chunk *sound;
|
|
||||||
|
|
||||||
#ifdef USE_PHYSFS
|
|
||||||
SDL_RWops *rw;
|
|
||||||
rw = PHYSFSRWOPS_openRead(filename.c_str());
|
|
||||||
sound = Mix_LoadWAV_RW(rw,0);
|
|
||||||
SDL_FreeRW(rw);
|
|
||||||
#else
|
|
||||||
sound = Mix_LoadWAV(filename.c_str());
|
|
||||||
#endif //USE_PHYSFS
|
|
||||||
|
|
||||||
if(!sound)
|
|
||||||
{
|
|
||||||
ReportError(ZERR_LOAD_SOUND,filename);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mix_Music* ZEngine::LoadMusic(std::string filename)
|
|
||||||
{
|
|
||||||
Mix_Music *music;
|
|
||||||
|
|
||||||
//Currently SDL_Mixer doesn't support Music from a RW
|
|
||||||
//#ifdef USE_PHYSFS
|
|
||||||
// SDL_RWops *rw;
|
|
||||||
// rw = PHYSFSRWOPS_openRead(filename.c_str());
|
|
||||||
// mus.music = Mix_LoadMUS_RW(filename.c_str(),0);
|
|
||||||
// SDL_FreeRW(rw);
|
|
||||||
//#else
|
|
||||||
music = Mix_LoadMUS(filename.c_str());
|
|
||||||
//#endif //USE_PHYSFS
|
|
||||||
|
|
||||||
if(!music)
|
|
||||||
{
|
|
||||||
ReportError(ZERR_LOAD_MUSIC,filename);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return music;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_SDL_TTF
|
|
||||||
|
|
||||||
TTF_Font* ZEngine::LoadFont(std::string filename, int size)
|
|
||||||
{
|
|
||||||
TTF_Font *font;
|
|
||||||
|
|
||||||
#ifdef USE_PHYSFS
|
|
||||||
SDL_RWops *rw;
|
|
||||||
rw = PHYSFSRWOPS_openRead(filename.c_str());
|
|
||||||
font = TTF_OpenFontRW(rw,0,size);
|
|
||||||
SDL_FreeRW(rw);
|
|
||||||
#else
|
|
||||||
font = TTF_OpenFont(filename.c_str(),size);
|
|
||||||
#endif //USE_PHYSFS
|
|
||||||
|
|
||||||
if(!font)
|
|
||||||
{
|
|
||||||
ReportError(ZERR_LOAD_FONT,filename);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int ZEngine::DisplayWidth()
|
int ZEngine::DisplayWidth()
|
||||||
{
|
{
|
||||||
return mWidth;
|
return mWidth;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZFont.
|
\brief Source file for ZFont.
|
||||||
|
|
||||||
Implementation of ZFont, the basic Font class for ZEngine.
|
Implementation of ZFont, the basic Font class for ZEngine.
|
||||||
<br>$Id: ZE_ZFont.cpp,v 1.12 2003/06/11 05:51:16 cozman Exp $<br>
|
<br>$Id: ZE_ZFont.cpp,v 1.13 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -50,7 +50,32 @@ void ZFont::Open(std::string filename, int size)
|
|||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
rFilename = filename;
|
rFilename = filename;
|
||||||
rFont = rEngine->LoadFont(filename,size);
|
|
||||||
|
rFont = TTF_OpenFont(filename.c_str(),size);
|
||||||
|
|
||||||
|
if(!rFont)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_FONT,filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZFont::OpenFromZip(std::string zipname, std::string filename, int size)
|
||||||
|
{
|
||||||
|
SDL_RWops *rw;
|
||||||
|
|
||||||
|
Release();
|
||||||
|
rZipname = zipname;
|
||||||
|
rFilename = filename;
|
||||||
|
|
||||||
|
rw = RWFromZip(zipname,filename);
|
||||||
|
|
||||||
|
if(rw)
|
||||||
|
{
|
||||||
|
rFont = TTF_OpenFontRW(rw,0,size);
|
||||||
|
//delete []rw->hidden.mem.base; //must free buffer
|
||||||
|
//SDL_FreeRW(rw);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rFont)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_FONT,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZFont::Release()
|
void ZFont::Release()
|
||||||
@ -106,7 +131,10 @@ void ZFont::SetStyle(bool bold, bool italic, bool underline)
|
|||||||
|
|
||||||
void ZFont::Resize(int size)
|
void ZFont::Resize(int size)
|
||||||
{
|
{
|
||||||
Open(rFilename,size);
|
if(rZipname.length())
|
||||||
|
OpenFromZip(rZipname,rFilename,size);
|
||||||
|
else
|
||||||
|
Open(rFilename,size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZFont::IsLoaded() const
|
bool ZFont::IsLoaded() const
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZImage.
|
\brief Source file for ZImage.
|
||||||
|
|
||||||
Implementation of ZImage, the Image class for ZEngine.
|
Implementation of ZImage, the Image class for ZEngine.
|
||||||
<br>$Id: ZE_ZImage.cpp,v 1.46 2003/09/07 20:59:20 cozman Exp $<br>
|
<br>$Id: ZE_ZImage.cpp,v 1.47 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -79,8 +79,40 @@ void ZImage::Open(std::string filename)
|
|||||||
{
|
{
|
||||||
SDL_Surface *image;
|
SDL_Surface *image;
|
||||||
|
|
||||||
image = rEngine->LoadImage(filename.c_str());
|
#ifdef USE_SDL_IMAGE
|
||||||
Attach(image);
|
image = IMG_Load(filename.c_str());
|
||||||
|
#else
|
||||||
|
image = SDL_LoadBMP(filename.c_str());
|
||||||
|
#endif //USE_SDL_IMAGE
|
||||||
|
|
||||||
|
if(!image)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_IMAGE,filename);
|
||||||
|
else
|
||||||
|
Attach(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZImage::OpenFromZip(std::string zipname, std::string filename)
|
||||||
|
{
|
||||||
|
SDL_Surface *image=NULL;
|
||||||
|
SDL_RWops *rw;
|
||||||
|
|
||||||
|
rw = RWFromZip(zipname,filename);
|
||||||
|
|
||||||
|
if(rw)
|
||||||
|
{
|
||||||
|
#ifdef USE_SDL_IMAGE
|
||||||
|
image = IMG_Load_RW(rw,0);
|
||||||
|
#else
|
||||||
|
image = SDL_LoadBMP_RW(rw,0);
|
||||||
|
#endif //USE_SDL_IMAGE
|
||||||
|
delete []rw->hidden.mem.base; //must free buffer
|
||||||
|
SDL_FreeRW(rw);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!image)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_IMAGE,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
|
||||||
|
else
|
||||||
|
Attach(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
|
void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZMusic.
|
\brief Source file for ZMusic.
|
||||||
|
|
||||||
Implementation of ZMusic, the basic Music class for ZEngine.
|
Implementation of ZMusic, the basic Music class for ZEngine.
|
||||||
<br>$Id: ZE_ZMusic.cpp,v 1.10 2003/06/11 05:51:16 cozman Exp $<br>
|
<br>$Id: ZE_ZMusic.cpp,v 1.11 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -48,7 +48,11 @@ ZMusic::~ZMusic()
|
|||||||
void ZMusic::Open(std::string filename)
|
void ZMusic::Open(std::string filename)
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
rMusic = rEngine->LoadMusic(filename);
|
|
||||||
|
rMusic = Mix_LoadMUS(filename.c_str());
|
||||||
|
|
||||||
|
if(!rMusic)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_MUSIC,filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZMusic::Release()
|
void ZMusic::Release()
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZSound.
|
\brief Source file for ZSound.
|
||||||
|
|
||||||
Implementation of ZSound, the basic Sound class for ZEngine.
|
Implementation of ZSound, the basic Sound class for ZEngine.
|
||||||
<br>$Id: ZE_ZSound.cpp,v 1.10 2003/06/11 05:51:16 cozman Exp $<br>
|
<br>$Id: ZE_ZSound.cpp,v 1.11 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -51,7 +51,28 @@ ZSound::~ZSound()
|
|||||||
void ZSound::Open(std::string filename)
|
void ZSound::Open(std::string filename)
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
rSound = rEngine->LoadSound(filename);
|
|
||||||
|
rSound = Mix_LoadWAV(filename.c_str());
|
||||||
|
|
||||||
|
if(!rSound)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_SOUND,filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZSound::OpenFromZip(std::string zipname, std::string filename)
|
||||||
|
{
|
||||||
|
SDL_RWops *rw;
|
||||||
|
|
||||||
|
rw = RWFromZip(zipname,filename);
|
||||||
|
|
||||||
|
if(rw)
|
||||||
|
{
|
||||||
|
rSound = Mix_LoadWAV_RW(rw,0);
|
||||||
|
delete []rw->hidden.mem.base; //must free buffer
|
||||||
|
SDL_FreeRW(rw);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rSound)
|
||||||
|
rEngine->ReportError(ZERR_LOAD_SOUND,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZSound::Release()
|
void ZSound::Release()
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
The entry point 'main' defined in this file simply does the initial creation and freeing of ZEngine.
|
The entry point 'main' defined in this file simply does the initial creation and freeing of ZEngine.
|
||||||
An application that defines main overrides this main, so backwards compatibility is not broken, however as of 0.8.5 ZE_main is the
|
An application that defines main overrides this main, so backwards compatibility is not broken, however as of 0.8.5 ZE_main is the
|
||||||
expected entry point of ZEngine applications.
|
expected entry point of ZEngine applications.
|
||||||
<br>$Id: ZE_main.cpp,v 1.2 2003/09/22 23:49:22 cozman Exp $<br>
|
<br>$Id: ZE_main.cpp,v 1.3 2003/09/24 02:03:18 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
#ifdef USE_PHYSFS
|
||||||
|
|
||||||
#include "ZEngine.h"
|
#include "ZEngine.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -51,3 +53,4 @@ int main(int argc, char *argv[])
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //USE_PHYSFS
|
Loading…
Reference in New Issue
Block a user