|
| MobileDragon based game is supposed have access to
it’s persistent resources like images, sounds, 3d models and user’s custom
data files. MobileDragon way is to store all those files compressed in
single packed file. Such a file can be created using supplied command-line
utility packdir.exe Access to this compressed storage provided through PackDir class interface. Instance of PackDir object is created by the MobileDragon core, it opens the compressed storage file and prepares it for reading, and pointer to that PackDir instance is stored in the system object, all this is done before MDGame::Init() method is called. Name of the packdir file to open is set in MDGamePreferences structure [ see MobileDragon Basic Application Structure] . Working with this packed resource is very simple. API allows you to check if there is specified file in packdir, allows to determine that file size and to load that whole file into memory. Suppose you have mdragon::System * system variable pointing to valid MobileDragon system object therefore you can obtain pointer to PackDir object by calling PackDir * pd = system->GetPackDir(); Let’s for example load the file “data.bin” from the PackDir //
Obtain pointer to the PackDir object //
Determine that file size, allocate memory for it and load. /* ... some data processing stuff here */ //release
memory
/* ... some data processing stuff here */
packdir utility packs directory contents including subdirectories.
To load file “sample.txt” residing in subdirectory “dir” you need supply
it’s full name The Resource class represents a binary resource in memory. Using it simplifies parsing your binary data, it allow simple retrieving of data of all basic numeric types and string. Note that you must use this API only when loading your custom data files, all MobileDragon objects like Sound, Music, Image, Texture, etc. loaders interrogate with PackDir themselves.
Copyright 2005-2006 Herocraft Hitech Co. Ltd. |