Changeset - r9737:b37043004b37
[Not reviewed]
master
0 1 0
rubidium - 16 years ago 2008-07-29 21:45:30
rubidium@openttd.org
(svn r13869) -Fix [FS#2153] (r13674): in some cases the sprite cache could be filled with unremovable items.
1 file changed with 9 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/spritecache.cpp
Show inline comments
 
@@ -134,23 +134,23 @@ static void* ReadSprite(SpriteCache *sc,
 
		/* SPR_IMG_QUERY is a BIG FAT RED ? */
 
		id = SPR_IMG_QUERY;
 
		file_slot = GetSpriteCache(SPR_IMG_QUERY)->file_slot;
 
		file_pos  = GetSpriteCache(SPR_IMG_QUERY)->file_pos;
 
	}
 

	
 
	if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) {
 
	if (real_sprite && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) {
 
#ifdef WITH_PNG
 
		/* Try loading 32bpp graphics in case we are 32bpp output */
 
		SpriteLoaderPNG sprite_loader;
 
		SpriteLoader::Sprite sprite;
 

	
 
		if (sprite_loader.LoadSprite(&sprite, file_slot, sc->id)) {
 
			sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
 
			free(sprite.data);
 

	
 
			sc->real_sprite = true;
 
			sc->real_sprite = real_sprite;
 

	
 
			return sc->ptr;
 
		}
 
		/* If the PNG couldn't be loaded, fall back to 8bpp grfs */
 
#else
 
		static bool show_once = true;
 
@@ -170,19 +170,19 @@ static void* ReadSprite(SpriteCache *sc,
 
	if (type == 0xFF) {
 
		if (real_sprite) {
 
			static byte warning_level = 0;
 
			DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id);
 
			warning_level = 6;
 
			if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non- sprite?");
 
			return (void*)GetSprite(SPR_IMG_QUERY);
 
			return (void*)GetRawSprite(SPR_IMG_QUERY, true);
 
		}
 

	
 
		byte *dest = (byte *)AllocSprite(num);
 

	
 
		sc->ptr = dest;
 
		sc->real_sprite = false;
 
		sc->real_sprite = real_sprite;
 
		FioReadBlock(dest, num);
 

	
 
		return sc->ptr;
 
	}
 
	/* Ugly hack to work around the problem that the old landscape
 
	 *  generator assumes that those sprites are stored uncompressed in
 
@@ -191,12 +191,13 @@ static void* ReadSprite(SpriteCache *sc,
 
	 *  result in a data array in the format the blitter likes most), but
 
	 *  read the data directly from disk and store that as sprite.
 
	 * Ugly: yes. Other solution: no. Blame the original author or
 
	 *  something ;) The image should really have been a data-stream
 
	 *  (so type = 0xFF basicly). */
 
	if (id >= 4845 && id <= 4881) {
 
		assert(real_sprite);
 
		uint height = FioReadByte();
 
		uint width  = FioReadWord();
 
		Sprite *sprite;
 
		byte *dest;
 

	
 
		num = width * height;
 
@@ -218,28 +219,29 @@ static void* ReadSprite(SpriteCache *sc,
 
				i = -(i >> 3);
 
				num -= i;
 
				for (; i > 0; --i) *dest++ = *rel++;
 
			}
 
		}
 

	
 
		sc->real_sprite = false;
 
		sc->real_sprite = real_sprite;
 

	
 
		return sc->ptr;
 
	}
 

	
 
	sc->real_sprite = true;
 

	
 
	if (!real_sprite) {
 
		static byte warning_level = 0;
 
		DEBUG(sprite, warning_level, "Tried to load real sprite #%d as a non sprite. Probable cause: NewGRF interference", id);
 
		warning_level = 6;
 
		return (void*)GetRawSprite(id, true);
 
	}
 

	
 
	SpriteLoaderGrf sprite_loader;
 
	SpriteLoader::Sprite sprite;
 

	
 
	sc->real_sprite = real_sprite;
 

	
 
	if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos)) return NULL;
 
	if (id == 142) sprite.height = 10; // Compensate for a TTD bug
 
	sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
 
	free(sprite.data);
 

	
 
	return sc->ptr;
0 comments (0 inline, 0 general)