Game Development Reference
In-Depth Information
typedef struct stSURFACE{
BYTE red, green, blue;
char name[40];
}SURFACE;
A surface chunk contains many sub-chunks. We will read just the
COLR chunk that defines the base colour. After reading the name for the
surface and skipping the name of the parent of this surface, we go into a
loop reading through the sub-chunks until the length of the surface chunk
is reached.
BOOL CLWObject::LoadSurface(FILE* fp, int length)
{
char buf[4], name[80];
int i, length, count;
float f;
unsigned short sublength, e;
SURFACE *srf;
while(1){
srf = new SURFACE[numsurfaces+1];
if (srfs){
memcpy(srf, srfs, numsurfaces * sizeof(SURFACE));
delete [] srfs;
}
srfs = srf;
srf = &srfs[numsurfaces];
numsurfaces++;
//Read name
if (!ReadString(fp, srf->name, count, 39)) return FALSE;
//Read parent name
ReadString(fp, name, count, 79);
//Read sub-chunks
while (count<length){
if (!ReadSubChunk(buf, sublength, fp)) return FALSE;
count += 6; //Sizeof a subchunk header
if (strncmp(buf, ”COLR”, 4)==0){
//Found colour
if (!ReadFloat(fp, f)) return FALSE;
srf->red = (BYTE)(f * 255.0f);
Search Nedrilad ::




Custom Search