Game Development Reference
In-Depth Information
if (fread(rd,4,1,fp)!=1) return FALSE;
cf[0]=rd[3]; cf[1]=rd[2]; cf[2]=rd[1]; cf[3]=rd[0];
return TRUE;
}
Assuming that we have read the file header and the file is of suitable
format, we can start to read the chunk headers. To read a chunk header,
we read the 4-byte identifier and the chunk length. Below is a function that
will do just this. We pass a file pointer, a buffer that must be at least four
characters long, and an integer reference to the function. Again, the
function returns false if there was a file read error. We store the chunk
identifier and length in passed variables. When navigating a chunk we
need to read an additional byte from the file if the length of a chunk is odd,
because all chunks start on an even byte boundary.
BOOL CLWObject::ReadChunkHeader(FILE *fp, char *buf, int &i)
{
//Read header
if (!fread(buf,4,1,fp)) return FALSE;
//Read sub chunk length
if (!ReadInt(fp,i)) return FALSE;
return TRUE;
}
Lightwave also uses sub-chunks; these are read in exactly the same
way as reading a standard chunk, except that the length of the sub-chunk
is stored in a short integer. The function call for reading a sub-chunk
header is as follows:
BOOL CLWObject::ReadSubChunkHeader(FILE *fp, char *buf, USHORT &s)
{
//Read header
if (!fread(buf,4,1,fp)) return FALSE;
//Read sub chunk length
if (!ReadShort(fp,s)) return FALSE;
return TRUE;
}
Now that we have an armoury of function calls for navigating a
Lightwave object file, we will look at the structure of the parser. We want
to create a structure that is easily extendable. All Lightwave files have a
Search Nedrilad ::




Custom Search