Game Development Reference
In-Depth Information
See also
F Decompressing iles from the .zip archives
Enumerating iles in the .zip archives
To incorporate the contents of a .zip ile seamlessly into our ilesystem, we need to read
the archive contents and be able to access each ile individually. Since we are developing our
own ile I/O library, we use the iIStream interface to access .zip iles. The NDK provides
a way to read the .apk assets from your C++ application (see usr/include/android/
asset_manager.h in your NDK folder). However, it is only available on Android 2.3, and will
make debugging of ile access in your game more complex on a desktop computer without
an emulator. To make our native code portable to previous Android versions and other mobile
operating systems, we will craft our own assets reader.
Android applications are distributed as .apk packages, which are basically
just renamed .zip archives, containing a special folder structure and
metadata inside them.
Getting ready
We use the zlib library and the MiniZIP project to access the content of a .zip archive.
The most recent versions can be downloaded from http://www.winimage.com/
zLibDll/minizip.html .
How to do it...
1.
The zlib library is designed to be extensible. It does not assume every developer
uses only the fopen() calls or the std::ifstream interface. To read the data from
our own containers with the iIStream interface, we cast the iIStream instances
to the void* pointers and write a set of routines that are passed to zlib . These
routines resemble the standard fopen() -like interface and essentially only redirect
the zlib to our iIStream classes:
static voidpf ZCALLBACK zip_fopen( voidpf opaque,
const void* filename, int mode )
{
( ( iIStream* )opaque )->Seek( 0 );
return opaque;
}
 
Search WWH ::




Custom Search