Game Development Reference
In-Depth Information
We should destroy a group whenever we no longer need those resources in memory
(for example, a group containing resources for a particular level of a game only
needs to be in memory when playing that level). It isn't strictly necessary to destroy
all groups on shutdown however, as Marmalade will ensure everything that has
been allocated will be freed whenever an application is terminated.
The CIwResource class
We've already seen how the CIwManaged class can be used to allow us to easily
create instances of our own classes by loading them out of a file. This functionality
is improved further by the CIwResource class, which allows us to include our own
classes into a resource group.
In the GROUP file example shown in the previous section, we specified the levels.
itx file that may contain definitions of our own classes. If our custom classes used
CIwResource as their base class (or of course another class that was in turn derived
from CIwResource ) then all of our resources can be added to the resource group,
saving us the bother of keeping track of them ourselves.
GROUP file serialization
It is great that we can load different types of resources so easily, but ultimately we
probably do not want to deploy our application with a collection of easily recognized
or editable files. There are several reasons for this:
• Loading speed: Parsing a text file and converting it into a class is a slower
operation than just loading in a ready parsed serialized version. It is also
possible that we might need to do some sort of conversion on the original
data to make it usable in the game, so if we can avoid doing this we will
improve the loading time of our game.
• To prevent hacking: If we ship a collection of text files and common file
formats such as PNG files, we make it very easy for someone to hack and
modify our game or make unauthorized use of the game's resources.
• Smaller code size: If we are loading resource data that is already in a form
that our game code can use directly, there is no need to include any code for
converting the original data format into our own internal one. This makes
the code size smaller and also helps guard against hackers a little more.
• Deployment size: Text files are often much larger than their serialized
binary equivalents, so shipping a binary version could reduce the size
of our install package.
 
Search WWH ::




Custom Search