(svn r185) -Fix: [1016954] Cached_sprites does now work again

This commit is contained in:
truelight 2004-09-08 18:05:49 +00:00
parent 1a0a7ed763
commit 0a04fe95c9
1 changed files with 61 additions and 42 deletions

View File

@ -680,8 +680,17 @@ static void LoadSpriteTables()
{
int i,j;
/* load initial sprites */
/*
* Note for developers:
* Keep in mind that when you add a LoadGrfIndexed in the 'if'-section below
* that you should also add the corresponding FioOpenFile to the 'else'-section
* below.
*/
// Try to load the sprites from cache
if (!HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], true)) {
// We do not have the sprites in cache yet, or cache is disabled
// So just load all files from disk..
int load_index = 0;
for(i=0; _filename_list[i] != NULL; i++) {
@ -690,38 +699,48 @@ static void LoadSpriteTables()
LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++);
{
int l;
if ((l=_sprite_page_to_load) != 0)
LoadGrfIndexed(_landscape_filenames[l-1], _landscape_spriteindexes[l-1], i++);
}
if (_sprite_page_to_load != 0)
LoadGrfIndexed(_landscape_filenames[_sprite_page_to_load-1], _landscape_spriteindexes[_sprite_page_to_load-1], i++);
LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++);
load_index = SPR_CANALS_BASE;
load_index += LoadGrfFile("canalsw.grf", load_index, i++);
/* XXX: Only for debugging. Will be more generic. */
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT+1;
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1;
for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++)
load_index += LoadGrfFile(_newgrf_files[j], load_index, i++);
// load_index += LoadGrfFile("arcticseto.grf", load_index, i++);
// load_index += LoadGrfFile("tempsetpo.grf", load_index, i++);
// load_index += LoadGrfFile("newshipso.grf", load_index, i++);
//load_index += LoadGrfFile("brseto.grf", load_index, i++);
// If needed, save the cache to file
HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], false);
} else {
// We have sprites cached. We just loaded the cached files
// now we only have to open a file-pointer to all the original grf-files
// This is very important. Not all sprites are in the cache. So sometimes
// the game needs to load the sprite from disk. When the file is not
// open it can not read. So all files that are in the 'if'-section
// above should also be in this 'else'-section.
//
// NOTE: the order of the files must be identical as in the section above!!
for(i=0; _filename_list[i] != NULL; i++)
FioOpenFile(i,_filename_list[i]);
FioOpenFile(i, "openttd.grf");
FioOpenFile(i+1, "canalsw.grf");
FioOpenFile(i++, "openttd.grf");
if (_sprite_page_to_load != 0)
FioOpenFile(i+2, _landscape_filenames[_sprite_page_to_load-1]);
FioOpenFile(i++, _landscape_filenames[_sprite_page_to_load-1]);
FioOpenFile(i++, "trkfoundw.grf");
FioOpenFile(i++, "canalsw.grf");
// FIXME: if a user changes his newgrf's, the cached-sprites gets
// invalid. We should have some kind of check for this.
// The best solution for this is to delete the cached-sprites.. but how
// do we detect it?
for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++)
FioOpenFile(i++, _newgrf_files[j]);
}
_compact_cache_counter = 0;