2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/render/texsave.cpp,v 1.4 1998/10/05 17:28:29 mahk Exp $
7 // editorlevel file format and save/load code
9 // Tag: Families (FAMILY)
10 // contains a header and then a list of the current families
11 // Tag: Textures (TXLIST)
12 // resname memory block for the textures in memory
30 // Must be last header
34 static BOOL texsave_enabled
= TRUE
;
36 /////////////////////////
37 // generic block header stuff for lists of same size records
39 // put at the top of each string block
46 static BOOL
_saveGenericBlocked(ITagFile
*file
, blockHeader
*hdr
, void *mem
, TagFileTag
*tag
, TagVersion
*ver
)
51 if (file
->OpenBlock(tag
,ver
)!=S_OK
) return FALSE
;
52 write_sz
=hdr
->elem_cnt
*hdr
->size_per
;
53 if (file
->Write((char*)hdr
,sizeof(blockHeader
))==sizeof(blockHeader
))
54 if (file
->Write((char*)mem
,write_sz
)==write_sz
)
61 static void *_loadGenericBlocked(ITagFile
*file
, TagFileTag
*tag
, TagVersion
*ver
, TagVersion
*newver
, blockHeader
*hdr
)
65 if (file
->OpenBlock(tag
,newver
)!=S_OK
) return NULL
;
66 if (file
->Read((char*)hdr
,sizeof(blockHeader
))==sizeof(blockHeader
))
68 int read_sz
=hdr
->elem_cnt
*hdr
->size_per
;
69 mem
=(char*)Malloc(read_sz
);
71 if (file
->Read(mem
,read_sz
)!=read_sz
)
73 Free(mem
); // we are gonna return failure
74 mem
=NULL
; // but lets free our memory block first
81 /////////////////////////
83 static TagVersion FamilyVer
={1,0};
84 static TagFileTag FamilyTag
={"FAMILY"};
87 static BOOL
_saveAllFamilies(ITagFile
*file
)
90 void *mem
=family_name_block_build(&theHdr
.elem_cnt
,&theHdr
.size_per
);
93 BOOL rv
=_saveGenericBlocked(file
,&theHdr
,mem
,&FamilyTag
,&FamilyVer
);
94 Free(mem
); // allocated by block build
101 static BOOL
_loadAllFamilies(ITagFile
*file
)
103 TagVersion LocalVer
=FamilyVer
;
107 mem
=_loadGenericBlocked(file
,&FamilyTag
,&FamilyVer
,&LocalVer
,&theHdr
);
110 BOOL rv
=family_name_block_parse(theHdr
.elem_cnt
,theHdr
.size_per
,mem
);
117 /////////////////////////
119 static TagVersion TextureVer
={1,0};
120 static TagFileTag TextureTag
={"TXLIST"};
123 static BOOL
_saveAllTextures(ITagFile
*file
)
125 void *mem
=familyDiskTexBlockBuild();
129 int size
=ResBlockSize(mem
);
130 if (file
->OpenBlock(&TextureTag
,&TextureVer
)!=S_OK
) return FALSE
;
131 rv
=(file
->Write((char*)mem
,size
)==size
);
140 static BOOL
_loadAllTextures(ITagFile
*file
)
142 TagVersion LocalVer
=TextureVer
;
147 if (file
->OpenBlock(&TextureTag
,&LocalVer
)!=S_OK
) return FALSE
;
148 size
=file
->BlockSize(file
->CurrentBlock());
149 mem
=(void *)Malloc(size
);
150 rv
=(file
->Read((char *)mem
,size
)==size
);
151 Assrt(size
==ResBlockSize(mem
));
153 if (rv
) // successfully read the data, now lets try to load
154 rv
=familyDiskTexBlockLoad(mem
); // the resnameblock in for real...
155 Free(mem
); // since we malloced it and dont need it any more
161 ////////////////////////
163 // these are the actual calls made by the outside world
165 BOOL
texture_Save(ITagFile
*file
)
167 if (!texsave_enabled
)
171 rv
|= _saveAllFamilies(file
);
172 rv
|= _saveAllTextures(file
);
174 Warning(("Some texture component of the file saved incorrectly"));
178 BOOL
texture_Load(ITagFile
*file
)
180 if (!texsave_enabled
)
185 rv
|= _loadAllFamilies(file
);
186 rv
|= _loadAllTextures(file
);
188 // The theory is that we don't need this any more...
191 if (texmemSpaceOverrun())
193 mprintf("HEY! YOU! Out of Texture Slots!\n");
194 texmemSpaceOverrun()=0; // well, reset it, at least
195 } // hateful syntax, i know, sorry, will fix someday - dc
198 Warning(("Some texture component of the file loaded incorrectly"));
204 BOOL
texture_EnableSaveLoad(BOOL enabled
)
206 BOOL old
= texsave_enabled
;
207 texsave_enabled
= enabled
;