Game Development Reference
In-Depth Information
There are times that we will care about reading or writing values to a file; for
example, if we need to allocate a block of memory to read some values into. The
functions IwSerialiseIsReading and IwSerialiseIsWriting allow us to make
the appropriate decisions.
The following code snippet illustrates how the serialization functions are used by
showing what the Serialise method might look like for WidgetClass :
void WidgetClass::Serialise()
{
CIwManaged::Serialise();
IwSerialiseUInt8(mColor[0], 3);
IwSerialiseInt32(mSize);
IwSerialiseBool(mSparkly);
}
Resolving a class
The act of resolving a class instance is to fix up any parts of our class that are not
initialized correctly when parsing the object from an ITX file or having created it
from the serialization process.
When might this happen? The most frequent reason for needing to resolve our
instances is when the instance requires a pointer to another class that may not
exist when it is first created.
This is best illustrated by an example. Let's say our class contains a pointer to another
instance of our class in order to implement a linked list. When we read in our
instances, it is possible we might refer to an instance that has not yet been created
and so we can't create the linked list yet.
To solve this problem we instead store a value in our data that will allow us to look
up the required instance later. This might be a string representing the name of the
instance or perhaps a unique identifier number.
Once all the instances have been read in, we can then call the CIwManaged class'
virtual method Resolve on each instance in turn and obtain the required pointer
to the correct instance using whatever methodology we see fit. For example, we
might maintain a list of all instances of our class that gets added to whenever a
new instance is created. We can then use this list to look up the required instance.
It is not always necessary to create our own implementation of Resolve , but if we
do we must be sure to call the inherited version of the method from our superclass.
 
Search WWH ::




Custom Search