Changeset - r10056:7a18efcd8edb
[Not reviewed]
master
0 19 0
rubidium - 16 years ago 2008-09-02 15:20:38
rubidium@openttd.org
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
19 files changed with 61 insertions and 51 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -220,7 +220,7 @@ void DrawAircraftEngine(int x, int y, En
 
 */
 
void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height)
 
{
 
	const Sprite *spr = GetSprite(GetAircraftIcon(engine));
 
	const Sprite *spr = GetSprite(GetAircraftIcon(engine), ST_NORMAL);
 

	
 
	width  = spr->width;
 
	height = spr->height;
src/blitter/8bpp_base.cpp
Show inline comments
 
@@ -8,7 +8,7 @@
 

	
 
void Blitter_8bppBase::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
	const uint8 *ctab = GetNonSprite(pal) + 1;
 
	const uint8 *ctab = GetNonSprite(pal, ST_RECOLOUR) + 1;
 

	
 
	do {
 
		for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
src/depot_gui.cpp
Show inline comments
 
@@ -281,7 +281,7 @@ struct DepotWindow : Window {
 
			case VEH_ROAD:     DrawRoadVehImage( v, x + 24, sprite_y, this->sel, 1); break;
 
			case VEH_SHIP:     DrawShipImage(    v, x + 19, sprite_y - 1, this->sel); break;
 
			case VEH_AIRCRAFT: {
 
				const Sprite *spr = GetSprite(v->GetImage(DIR_W));
 
				const Sprite *spr = GetSprite(v->GetImage(DIR_W), ST_NORMAL);
 
				DrawAircraftImage(v, x + 12,
 
									y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
 
									this->sel);
src/fontcache.cpp
Show inline comments
 
@@ -401,7 +401,7 @@ const Sprite *GetGlyph(FontSize size, WC
 
	if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
 
		SpriteID sprite = GetUnicodeGlyph(size, key);
 
		if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
 
		return GetSprite(sprite);
 
		return GetSprite(sprite, ST_FONT);
 
	}
 

	
 
	/* Check for the glyph in our cache */
 
@@ -470,7 +470,7 @@ uint GetGlyphWidth(FontSize size, WChar 
 
	if (face == NULL || (key >= SCC_SPRITE_START && key <= SCC_SPRITE_END)) {
 
		SpriteID sprite = GetUnicodeGlyph(size, key);
 
		if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
 
		return SpriteExists(sprite) ? GetSprite(sprite)->width + (size != FS_NORMAL) : 0;
 
		return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL) : 0;
 
	}
 

	
 
	glyph = GetGlyphPtr(size, key);
src/fontcache.h
Show inline comments
 
@@ -46,7 +46,7 @@ static inline const Sprite *GetGlyph(Fon
 
{
 
	SpriteID sprite = GetUnicodeGlyph(size, key);
 
	if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
 
	return GetSprite(sprite);
 
	return GetSprite(sprite, ST_FONT);
 
}
 

	
 

	
 
@@ -55,7 +55,7 @@ static inline uint GetGlyphWidth(FontSiz
 
{
 
	SpriteID sprite = GetUnicodeGlyph(size, key);
 
	if (sprite == 0) sprite = GetUnicodeGlyph(size, '?');
 
	return SpriteExists(sprite) ? GetSprite(sprite)->width + (size != FS_NORMAL) : 0;
 
	return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + (size != FS_NORMAL) : 0;
 
}
 

	
 
#endif /* WITH_FREETYPE */
src/gfx.cpp
Show inline comments
 
@@ -888,13 +888,13 @@ int DoDrawStringTruncated(const char *st
 
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub)
 
{
 
	if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
 
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
 
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT, sub);
 
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_TRANSPARENT, sub);
 
	} else if (pal != PAL_NONE) {
 
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
 
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP, sub);
 
		_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_COLOUR_REMAP, sub);
 
	} else {
 
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL, sub);
 
		GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_NORMAL, sub);
 
	}
 
}
 

	
 
@@ -1476,7 +1476,7 @@ static void SetCursorSprite(SpriteID cur
 

	
 
	if (cv->sprite == cursor) return;
 

	
 
	p = GetSprite(GB(cursor, 0, SPRITE_WIDTH));
 
	p = GetSprite(GB(cursor, 0, SPRITE_WIDTH), ST_NORMAL);
 
	cv->sprite = cursor;
 
	cv->pal    = pal;
 
	cv->size.y = p->height;
src/gfx_type.h
Show inline comments
 
@@ -243,4 +243,12 @@ enum PaletteType {
 
	MAX_PAL = 2,    ///< The number of palettes.
 
};
 

	
 
/** Types of sprites that might be loaded */
 
enum SpriteType {
 
	ST_NORMAL   = 0,      ///< The most basic (normal) sprite
 
	ST_MAPGEN   = 1,      ///< Special sprite for the map generator
 
	ST_FONT     = 2,      ///< A sprite used for fonts
 
	ST_RECOLOUR = 3,      ///< Recolour sprite
 
};
 

	
 
#endif /* GFX_TYPE_H */
src/landscape.cpp
Show inline comments
 
@@ -675,7 +675,7 @@ static void GenerateTerrain(int type, ui
 
{
 
	uint32 r = Random();
 

	
 
	const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
 
	const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845, ST_MAPGEN);
 

	
 
	uint x = r & MapMaxX();
 
	uint y = (r >> MapLogX()) & MapMaxY();
src/main_gui.cpp
Show inline comments
 
@@ -386,7 +386,7 @@ void ShowSelectGameWindow();
 
void SetupColorsAndInitialWindow()
 
{
 
	for (uint i = 0; i != 16; i++) {
 
		const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i);
 
		const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i, ST_RECOLOUR);
 

	
 
		assert(b);
 
		memcpy(_colour_gradient[i], b + 0xC6, sizeof(_colour_gradient[i]));
src/ship_cmd.cpp
Show inline comments
 
@@ -84,7 +84,7 @@ void DrawShipEngine(int x, int y, Engine
 
 */
 
void GetShipSpriteSize(EngineID engine, uint &width, uint &height)
 
{
 
	const Sprite *spr = GetSprite(GetShipIcon(engine));
 
	const Sprite *spr = GetSprite(GetShipIcon(engine), ST_NORMAL);
 

	
 
	width  = spr->width;
 
	height = spr->height;
src/spritecache.cpp
Show inline comments
 
@@ -28,7 +28,7 @@ struct SpriteCache {
 
	uint32 id;
 
	uint16 file_slot;
 
	int16 lru;
 
	bool real_sprite; ///< In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as non-real sprite. If the non-real sprite gets into the cache it might be drawn as real sprite which causes enormous trouble.
 
	SpriteType type; ///< In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as recolour sprite. If the recolour sprite gets into the cache it might be drawn as real sprite which causes enormous trouble.
 
};
 

	
 

	
 
@@ -133,7 +133,7 @@ bool SpriteExists(SpriteID id)
 

	
 
void* AllocSprite(size_t);
 

	
 
static void* ReadSprite(SpriteCache *sc, SpriteID id, bool real_sprite)
 
static void* ReadSprite(SpriteCache *sc, SpriteID id, SpriteType sprite_type)
 
{
 
	uint8 file_slot = sc->file_slot;
 
	size_t file_pos = sc->file_pos;
 
@@ -149,17 +149,17 @@ static void* ReadSprite(SpriteCache *sc,
 
		file_pos  = GetSpriteCache(SPR_IMG_QUERY)->file_pos;
 
	}
 

	
 
	if (real_sprite && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) {
 
	if (sprite_type == ST_NORMAL && 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)) {
 
		if (sprite_loader.LoadSprite(&sprite, file_slot, sc->id, sprite_type)) {
 
			sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
 
			free(sprite.data);
 

	
 
			sc->real_sprite = real_sprite;
 
			sc->type = sprite_type;
 

	
 
			return sc->ptr;
 
		}
 
@@ -180,18 +180,18 @@ static void* ReadSprite(SpriteCache *sc,
 
	byte type = FioReadByte();
 
	/* Type 0xFF indicates either a colormap or some other non-sprite info */
 
	if (type == 0xFF) {
 
		if (real_sprite) {
 
		if (sprite_type != ST_RECOLOUR) {
 
			static byte warning_level = 0;
 
			DEBUG(sprite, warning_level, "Tried to load non sprite #%d as a real sprite. Probable cause: NewGRF interference", id);
 
			DEBUG(sprite, warning_level, "Tried to load recolour 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*)GetRawSprite(SPR_IMG_QUERY, true);
 
			if (id == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a recolour-sprite?");
 
			return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL);
 
		}
 

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

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

	
 
		return sc->ptr;
 
@@ -205,8 +205,8 @@ static void* ReadSprite(SpriteCache *sc,
 
	 * 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);
 
	assert((id >= 4845 && id <= 4881) == (sprite_type == ST_MAPGEN));
 
	if (sprite_type == ST_MAPGEN) {
 
		uint height = FioReadByte();
 
		uint width  = FioReadWord();
 
		Sprite *sprite;
 
@@ -234,24 +234,24 @@ static void* ReadSprite(SpriteCache *sc,
 
			}
 
		}
 

	
 
		sc->real_sprite = real_sprite;
 
		sc->type = sprite_type;
 

	
 
		return sc->ptr;
 
	}
 

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

	
 
	SpriteLoaderGrf sprite_loader;
 
	SpriteLoader::Sprite sprite;
 

	
 
	sc->real_sprite = real_sprite;
 
	sc->type = sprite_type;
 

	
 
	if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos)) return NULL;
 
	if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos, sprite_type)) return NULL;
 
	sc->ptr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, &AllocSprite);
 
	free(sprite.data);
 

	
 
@@ -276,7 +276,7 @@ bool LoadNextSprite(int load_index, byte
 
	sc->ptr = NULL;
 
	sc->lru = 0;
 
	sc->id = file_sprite_id;
 
	sc->real_sprite = false;
 
	sc->type = ST_NORMAL;
 

	
 
	return true;
 
}
 
@@ -291,7 +291,7 @@ void DupSprite(SpriteID old_spr, SpriteI
 
	scnew->file_pos = scold->file_pos;
 
	scnew->ptr = NULL;
 
	scnew->id = scold->id;
 
	scnew->real_sprite = scold->real_sprite;
 
	scnew->type = scold->type;
 
}
 

	
 

	
 
@@ -461,7 +461,7 @@ void* AllocSprite(size_t mem_req)
 
}
 

	
 

	
 
const void *GetRawSprite(SpriteID sprite, bool real_sprite)
 
const void *GetRawSprite(SpriteID sprite, SpriteType type)
 
{
 
	SpriteCache *sc;
 
	void* p;
 
@@ -476,7 +476,7 @@ const void *GetRawSprite(SpriteID sprite
 
	p = sc->ptr;
 

	
 
	/* Load the sprite, if it is not loaded, yet */
 
	if (p == NULL || sc->real_sprite != real_sprite) p = ReadSprite(sc, sprite, real_sprite);
 
	if (p == NULL || sc->type != type) p = ReadSprite(sc, sprite, type);
 

	
 
	return p;
 
}
src/spritecache.h
Show inline comments
 
@@ -17,17 +17,19 @@ struct Sprite {
 

	
 
extern uint _sprite_cache_size;
 

	
 
const void *GetRawSprite(SpriteID sprite, bool real_sprite);
 
const void *GetRawSprite(SpriteID sprite, SpriteType type);
 
bool SpriteExists(SpriteID sprite);
 

	
 
static inline const Sprite *GetSprite(SpriteID sprite)
 
static inline const Sprite *GetSprite(SpriteID sprite, SpriteType type)
 
{
 
	return (Sprite*)GetRawSprite(sprite, true);
 
	assert(type != ST_RECOLOUR);
 
	return (Sprite*)GetRawSprite(sprite, type);
 
}
 

	
 
static inline const byte *GetNonSprite(SpriteID sprite)
 
static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
 
{
 
	return (byte*)GetRawSprite(sprite, false);
 
	assert(type == ST_RECOLOUR);
 
	return (byte*)GetRawSprite(sprite, type);
 
}
 

	
 
void GfxInitSpriteMem();
src/spriteloader/grf.cpp
Show inline comments
 
@@ -9,7 +9,7 @@
 
#include "../core/alloc_func.hpp"
 
#include "grf.hpp"
 

	
 
bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos)
 
bool SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type)
 
{
 
	/* Open the right file and go to the correct position */
 
	FioSeekToFile(file_slot, file_pos);
src/spriteloader/grf.hpp
Show inline comments
 
@@ -12,7 +12,7 @@ public:
 
	/**
 
	 * Load a sprite from the disk and return a sprite struct which is the same for all loaders.
 
	 */
 
	bool LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos);
 
	bool LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type);
 
};
 

	
 
#endif /* SPRITELOADER_GRF_HPP */
src/spriteloader/png.cpp
Show inline comments
 
@@ -170,7 +170,7 @@ static bool LoadPNG(SpriteLoader::Sprite
 
	return true;
 
}
 

	
 
bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos)
 
bool SpriteLoaderPNG::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type)
 
{
 
	const char *filename = FioGetFilename(file_slot);
 
	if (!LoadPNG(sprite, filename, (uint32)file_pos, false)) return false;
src/spriteloader/png.hpp
Show inline comments
 
@@ -12,7 +12,7 @@ public:
 
	/**
 
	 * Load a sprite from the disk and return a sprite struct which is the same for all loaders.
 
	 */
 
	bool LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos);
 
	bool LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type);
 
};
 

	
 
#endif /* SPRITELOADER_PNG_HPP */
src/spriteloader/spriteloader.hpp
Show inline comments
 
@@ -26,7 +26,7 @@ public:
 
	/**
 
	 * Load a sprite from the disk and return a sprite struct which is the same for all loaders.
 
	 */
 
	virtual bool LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos) = 0;
 
	virtual bool LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type) = 0;
 

	
 
	virtual ~SpriteLoader() { }
 
};
src/vehicle.cpp
Show inline comments
 
@@ -234,7 +234,7 @@ void VehiclePositionChanged(Vehicle *v)
 
{
 
	int img = v->cur_image;
 
	Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos);
 
	const Sprite *spr = GetSprite(img);
 
	const Sprite *spr = GetSprite(img, ST_NORMAL);
 

	
 
	pt.x += spr->x_offs;
 
	pt.y += spr->y_offs;
src/viewport.cpp
Show inline comments
 
@@ -567,7 +567,7 @@ void OffsetGroundSprite(int x, int y)
 
static void AddCombinedSprite(SpriteID image, SpriteID pal, int x, int y, byte z, const SubSprite *sub)
 
{
 
	Point pt = RemapCoords(x, y, z);
 
	const Sprite* spr = GetSprite(image & SPRITE_MASK);
 
	const Sprite* spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
 

	
 
	if (pt.x + spr->x_offs >= _vd.dpi.left + _vd.dpi.width ||
 
			pt.x + spr->x_offs + spr->width <= _vd.dpi.left ||
 
@@ -632,7 +632,7 @@ void AddSortableSpriteToDraw(SpriteID im
 
		top  = tmp_top  = RemapCoords(x + bb_offset_x, y + bb_offset_y, z + dz         ).y;
 
		bottom          = RemapCoords(x + w          , y + h          , z + bb_offset_z).y + 1;
 
	} else {
 
		const Sprite *spr = GetSprite(image & SPRITE_MASK);
 
		const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
 
		left = tmp_left = (pt.x += spr->x_offs);
 
		right           = (pt.x +  spr->width );
 
		top  = tmp_top  = (pt.y += spr->y_offs);
0 comments (0 inline, 0 general)