Changeset - r17036:17fe560ce56e
[Not reviewed]
master
0 1 0
frosch - 13 years ago 2011-01-14 16:09:51
frosch@openttd.org
(svn r21783) -Cleanup (r14997): Remove redundant assignment.
1 file changed with 0 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/spritecache.cpp
Show inline comments
 
@@ -236,98 +236,96 @@ static void *ReadSprite(SpriteCache *sc,
 
			/* The data of index 0 is never used; "literal 00" according to the (New)GRF specs. */
 
			for (int i = 1; i < RECOLOUR_SPRITE_SIZE; i++) {
 
				dest[i] = _palette_remap[dest_tmp[_palette_reverse_remap[i - 1] + 1]];
 
			}
 
		} else {
 
			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
 
	 *  the memory, and they are only read directly by the code, never
 
	 *  send to the blitter. So do not send it to the blitter (which will
 
	 *  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 (sprite_type == ST_MAPGEN) {
 
		uint height = FioReadByte();
 
		uint width  = FioReadWord();
 
		Sprite *sprite;
 
		byte *dest;
 

	
 
		num = width * height;
 
		sprite = (Sprite *)AllocSprite(sizeof(*sprite) + num);
 
		sc->ptr = sprite;
 
		sprite->height = height;
 
		sprite->width  = width;
 
		sprite->x_offs = FioReadWord();
 
		sprite->y_offs = FioReadWord();
 

	
 
		dest = sprite->data;
 
		while (num > 0) {
 
			int8 i = FioReadByte();
 
			if (i >= 0) {
 
				num -= i;
 
				for (; i > 0; --i) *dest++ = FioReadByte();
 
			} else {
 
				const byte *rel = dest - (((i & 7) << 8) | FioReadByte());
 
				i = -(i >> 3);
 
				num -= i;
 
				for (; i > 0; --i) *dest++ = *rel++;
 
			}
 
		}
 

	
 
		sc->type = sprite_type;
 

	
 
		return sc->ptr;
 
	}
 

	
 
	assert(sprite_type == ST_NORMAL || sprite_type == ST_FONT);
 

	
 
	SpriteLoaderGrf sprite_loader;
 
	SpriteLoader::Sprite sprite;
 

	
 
	if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos, sprite_type)) {
 
		if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?");
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL);
 
	}
 
	sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
 

	
 
	return sc->ptr;
 
}
 

	
 

	
 
bool LoadNextSprite(int load_index, byte file_slot, uint file_sprite_id)
 
{
 
	size_t file_pos = FioGetPos();
 

	
 
	SpriteType type = ReadSpriteHeaderSkipData();
 

	
 
	if (type == ST_INVALID) return false;
 

	
 
	if (load_index >= MAX_SPRITES) {
 
		usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
 
	}
 

	
 
	bool is_mapgen = IsMapgenSpriteID(load_index);
 

	
 
	if (is_mapgen) {
 
		if (type != ST_NORMAL) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?");
 
		type = ST_MAPGEN;
 
	}
 

	
 
	SpriteCache *sc = AllocateSpriteCache(load_index);
 
	sc->file_slot = file_slot;
 
	sc->file_pos = file_pos;
 
	sc->ptr = NULL;
 
	sc->lru = 0;
 
	sc->id = file_sprite_id;
 
	sc->type = type;
 
	sc->warned = false;
 

	
 
	return true;
 
}
0 comments (0 inline, 0 general)