Game Engine Architecture

(Ben Green) #1

298 6. Resources and the File System


U8* ConvertOffsetToPointer(U32 objectOffset,
U8* pAddressOfFileImage)
{
U8* pObject = pAddressOfFileImage + objectOffset;
return pObject;
}
The problem we encounter when trying to convert pointers into off sets,
and vice-versa, is how to fi nd all of the pointers that require conversion. This
problem is usually solved at the time the binary fi le is writt en. The code that
writes out the images of the data objects has knowledge of the data types and
classes being writt en, so it has knowledge of the locations of all the pointers

Addresses:
Offsets:

RAM Binary File

Object 1

Object 2

Object 3

Object 4

0x0

0x240

0x4A0

0x7F0

Object 1

Object 4

Object 2

Object 3

0x2A080

0x2D750

0x2F110

0x32EE0

0x32EE0

0x2F110

0x2A080

0x4A0

0x240

0x0

Pointers converted
to offsets; locations
of pointers stored in
fix-up table.

Fix-Up Table
0x2000x340
0x810

Pointers to various
objects are present.

3 pointers

Figure 6.9. A pointer fi x-up table.

Offsets: Addresses:

Binary File RAM

Object 1

Object 2

Object 3

Object 4

0x0

0x240

0x4A0

0x7F0

Object 1

Object 4

Object 2

Object 3

0x30100

0x30340

0x305A0

0x308 F0

Figure 6.8. Contiguous resource fi le image, after it has been loaded into RAM.
Free download pdf