spritecache.c
changeset 366 9d2630b8b4de
parent 365 5752af05ed75
child 368 32aad6ad36e1
equal deleted inserted replaced
365:5752af05ed75 366:9d2630b8b4de
    17 
    17 
    18 int _skip_sprites = 0;
    18 int _skip_sprites = 0;
    19 int _replace_sprites_count[16];
    19 int _replace_sprites_count[16];
    20 int _replace_sprites_offset[16];
    20 int _replace_sprites_offset[16];
    21 
    21 
    22 static const char *_cur_grffile;
       
    23 static int _skip_specials;
    22 static int _skip_specials;
    24 static SpriteHdr _cur_sprite;
    23 static SpriteHdr _cur_sprite;
    25 
    24 
    26 
    25 
    27 static byte *_sprite_ptr[NUM_SPRITES];
    26 static byte *_sprite_ptr[NUM_SPRITES];
    83 	_slopes_spriteindexes_3,
    82 	_slopes_spriteindexes_3,
    84 };
    83 };
    85 
    84 
    86 static void CompactSpriteCache();
    85 static void CompactSpriteCache();
    87 
    86 
    88 void DecodeSpecialSprite(const char *filename, int num, int load_index);
    87 void InitNewGRFFile(const char *filename, int sprite_offset);
       
    88 void DecodeSpecialSprite(int num, int load_index);
    89 
    89 
    90 static void ReadSpriteHeaderSkipData(int num, int load_index)
    90 static void ReadSpriteHeaderSkipData(int num, int load_index)
    91 {
    91 {
    92 	byte type;
    92 	byte type;
    93 	int8 i;
    93 	int8 i;
   108 		 * processed, they themselves are never referenced and loaded
   108 		 * processed, they themselves are never referenced and loaded
   109 		 * on their own. */
   109 		 * on their own. */
   110 		if (_skip_specials || deaf) {
   110 		if (_skip_specials || deaf) {
   111 			FioSkipBytes(num);
   111 			FioSkipBytes(num);
   112 		} else {
   112 		} else {
   113 			DecodeSpecialSprite(_cur_grffile, num, load_index);
   113 			DecodeSpecialSprite(num, load_index);
   114 		}
   114 		}
   115 		return;
   115 		return;
   116 	}
   116 	}
   117 
   117 
   118 #ifdef WANT_SPRITESIZES
   118 #ifdef WANT_SPRITESIZES
   279 static int LoadGrfFile(const char *filename, int load_index, int file_index)
   279 static int LoadGrfFile(const char *filename, int load_index, int file_index)
   280 {
   280 {
   281 	int load_index_org = load_index;
   281 	int load_index_org = load_index;
   282 
   282 
   283 	FioOpenFile(file_index, filename);
   283 	FioOpenFile(file_index, filename);
   284 	_cur_grffile = filename;
       
   285 
   284 
   286 	/* Thou shalt use LoadNewGrfFile() if thou loadeth a GRF file that
   285 	/* Thou shalt use LoadNewGrfFile() if thou loadeth a GRF file that
   287 	 * might contain some special sprites. */
   286 	 * might contain some special sprites. */
   288 	_skip_specials = 1;
   287 	_skip_specials = 1;
   289 	_skip_sprites = 0;
   288 	_skip_sprites = 0;
   290 
   289 
   291 	DEBUG(spritecache, 2) ("Reading grf-file ``%s''", _cur_grffile);
   290 	DEBUG(spritecache, 2) ("Reading grf-file ``%s''", filename);
   292 
   291 
   293  	if(file_index==0 && !_ignore_wrong_grf)
   292  	if(file_index==0 && !_ignore_wrong_grf)
   294  		if(!CheckGrfFile())
   293  		if(!CheckGrfFile())
   295  			error("Wrong version of grf files!\nThe Windows 95 edition of Transport Tycoon Deluxe is required to play OTTD!\n(you can disable this message by starting with the \"-i\" switch.");
   294  			error("Wrong version of grf files!\nThe Windows 95 edition of Transport Tycoon Deluxe is required to play OTTD!\n(you can disable this message by starting with the \"-i\" switch.");
   296 
   295 
   310 	 * be tolerant and comply with more/less sprites too? --pasky */
   309 	 * be tolerant and comply with more/less sprites too? --pasky */
   311 	int num_sprites = 0;
   310 	int num_sprites = 0;
   312 	int i;
   311 	int i;
   313 	
   312 	
   314 	FioOpenFile(file_index, filename);
   313 	FioOpenFile(file_index, filename);
   315 	_cur_grffile = filename;
       
   316 	_skip_specials = 0;
   314 	_skip_specials = 0;
   317 	_skip_sprites = 0;
   315 	_skip_sprites = 0;
   318 
   316 
   319 	DEBUG(spritecache, 2) ("Reading newgrf-file ``%s'' [offset: %u]",
   317 	DEBUG(spritecache, 2) ("Reading newgrf-file ``%s'' [offset: %u]",
   320 			_cur_grffile, load_index);
   318 			filename, load_index);
   321 
   319 
   322 	{
   320 	{
   323 		int length;
   321 		int length;
   324 		byte type;
   322 		byte type;
   325 
   323 
   358 static void LoadGrfIndexed(const char *filename, const uint16 *index_tbl, int file_index)
   356 static void LoadGrfIndexed(const char *filename, const uint16 *index_tbl, int file_index)
   359 {
   357 {
   360 	int start;
   358 	int start;
   361 
   359 
   362 	FioOpenFile(file_index, filename);
   360 	FioOpenFile(file_index, filename);
   363 	_cur_grffile = filename;
       
   364 	_skip_specials = 1;
   361 	_skip_specials = 1;
   365 	_skip_sprites = 0;
   362 	_skip_sprites = 0;
   366 
   363 
   367 	DEBUG(spritecache, 2) ("Reading indexed grf-file ``%s''", _cur_grffile);
   364 	DEBUG(spritecache, 2) ("Reading indexed grf-file ``%s''", filename);
   368 
   365 
   369 	for(;(start=*index_tbl++) != 0xffff;) {
   366 	for(;(start=*index_tbl++) != 0xffff;) {
   370 		int end = *index_tbl++;
   367 		int end = *index_tbl++;
   371 		if(start==0xfffe) { // skip sprites (amount in second var)
   368 		if(start==0xfffe) { // skip sprites (amount in second var)
   372 			SkipSprites(end);
   369 			SkipSprites(end);
   806 		load_index = SPR_CANALS_BASE;
   803 		load_index = SPR_CANALS_BASE;
   807 		load_index += LoadGrfFile("canalsw.grf", load_index, i++);
   804 		load_index += LoadGrfFile("canalsw.grf", load_index, i++);
   808 
   805 
   809 		load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1;
   806 		load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT + 1;
   810 
   807 
   811 		for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++)
   808 		for(j = 0; j != lengthof(_newgrf_files) && _newgrf_files[j]; j++) {
       
   809 			InitNewGRFFile(_newgrf_files[j], load_index);
   812 			load_index += LoadNewGrfFile(_newgrf_files[j], load_index, i++);
   810 			load_index += LoadNewGrfFile(_newgrf_files[j], load_index, i++);
       
   811 		}
   813 
   812 
   814 		// If needed, save the cache to file
   813 		// If needed, save the cache to file
   815 		HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], false);
   814 		HandleCachedSpriteHeaders(_cached_filenames[_opt.landscape], false);
   816 	} else {
   815 	} else {
   817 		// We have sprites cached. We just loaded the cached files
   816 		// We have sprites cached. We just loaded the cached files
   821 		//  open it can not read. So all files that are in the 'if'-section
   820 		//  open it can not read. So all files that are in the 'if'-section
   822 		//  above should also be in this 'else'-section.
   821 		//  above should also be in this 'else'-section.
   823 		//
   822 		//
   824 		// NOTE: the order of the files must be identical as in the section above!!
   823 		// NOTE: the order of the files must be identical as in the section above!!
   825 
   824 
   826 		for(i=0; _filename_list[i] != NULL; i++)
   825 		for(i = 0; _filename_list[i] != NULL; i++)
   827 			FioOpenFile(i,_filename_list[i]);
   826 			FioOpenFile(i,_filename_list[i]);
   828 
   827 
   829 		FioOpenFile(i++, "openttd.grf");
   828 		FioOpenFile(i++, "openttd.grf");
   830 
   829 
   831 		if (_sprite_page_to_load != 0)
   830 		if (_sprite_page_to_load != 0)