diff options
author | rubidium <rubidium@openttd.org> | 2008-09-02 15:20:38 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-09-02 15:20:38 +0000 |
commit | c8e8911ef676f503ac5789d3fefac1278cdef971 (patch) | |
tree | e7050537d14303dbc6bc9a461ff38931861cc4aa | |
parent | cbe397388f0ef537b61095b05ee4edfe9dd92202 (diff) | |
download | openttd-c8e8911ef676f503ac5789d3fefac1278cdef971.tar.xz |
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
-rw-r--r-- | src/aircraft_cmd.cpp | 2 | ||||
-rw-r--r-- | src/blitter/8bpp_base.cpp | 2 | ||||
-rw-r--r-- | src/depot_gui.cpp | 2 | ||||
-rw-r--r-- | src/fontcache.cpp | 4 | ||||
-rw-r--r-- | src/fontcache.h | 4 | ||||
-rw-r--r-- | src/gfx.cpp | 12 | ||||
-rw-r--r-- | src/gfx_type.h | 8 | ||||
-rw-r--r-- | src/landscape.cpp | 2 | ||||
-rw-r--r-- | src/main_gui.cpp | 2 | ||||
-rw-r--r-- | src/ship_cmd.cpp | 2 | ||||
-rw-r--r-- | src/spritecache.cpp | 44 | ||||
-rw-r--r-- | src/spritecache.h | 12 | ||||
-rw-r--r-- | src/spriteloader/grf.cpp | 2 | ||||
-rw-r--r-- | src/spriteloader/grf.hpp | 2 | ||||
-rw-r--r-- | src/spriteloader/png.cpp | 2 | ||||
-rw-r--r-- | src/spriteloader/png.hpp | 2 | ||||
-rw-r--r-- | src/spriteloader/spriteloader.hpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 2 | ||||
-rw-r--r-- | src/viewport.cpp | 4 |
19 files changed, 61 insertions, 51 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 2d000ff3b..7a6d45c19 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -220,7 +220,7 @@ void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal) */ 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; diff --git a/src/blitter/8bpp_base.cpp b/src/blitter/8bpp_base.cpp index 78bb90f5e..4bdbfe2df 100644 --- a/src/blitter/8bpp_base.cpp +++ b/src/blitter/8bpp_base.cpp @@ -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]]; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 54e9519a3..f09386a3a 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -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); diff --git a/src/fontcache.cpp b/src/fontcache.cpp index ab7c9c5d1..28924885d 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -401,7 +401,7 @@ const Sprite *GetGlyph(FontSize size, WChar key) 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 key) 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); diff --git a/src/fontcache.h b/src/fontcache.h index 14181a400..bf32c2927 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -46,7 +46,7 @@ static inline const Sprite *GetGlyph(FontSize size, uint32 key) { 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(FontSize size, uint32 key) { 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 */ diff --git a/src/gfx.cpp b/src/gfx.cpp index 4bcdab241..9f896be32 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -888,13 +888,13 @@ int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw 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 cursor, SpriteID pal) 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; diff --git a/src/gfx_type.h b/src/gfx_type.h index 97e987488..7006fa967 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -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 */ diff --git a/src/landscape.cpp b/src/landscape.cpp index 982f02ab8..30a01e5dd 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -675,7 +675,7 @@ static void GenerateTerrain(int type, uint flag) { 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(); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 5417166ed..bdd4a3daf 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -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])); diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 1b1eda4a4..8d28a406c 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -84,7 +84,7 @@ void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal) */ 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; diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 629e519f0..f7ab69b72 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -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, SpriteID id, bool real_sprite) 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, SpriteID id, bool real_sprite) 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, SpriteID id, bool real_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); + 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, SpriteID id, bool real_sprite) } } - 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 file_slot, uint file_sprite_id) 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, SpriteID new_spr) 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, bool real_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; } diff --git a/src/spritecache.h b/src/spritecache.h index 65cc3b95e..76f1073cb 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -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(); diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index 871a9fa0a..17510027e 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -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); diff --git a/src/spriteloader/grf.hpp b/src/spriteloader/grf.hpp index aff4c57cb..fc1e7ddb6 100644 --- a/src/spriteloader/grf.hpp +++ b/src/spriteloader/grf.hpp @@ -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 */ diff --git a/src/spriteloader/png.cpp b/src/spriteloader/png.cpp index 4ccc502aa..43a188fbf 100644 --- a/src/spriteloader/png.cpp +++ b/src/spriteloader/png.cpp @@ -170,7 +170,7 @@ static bool LoadPNG(SpriteLoader::Sprite *sprite, const char *filename, uint32 i 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; diff --git a/src/spriteloader/png.hpp b/src/spriteloader/png.hpp index 62c30db75..bb96ec3aa 100644 --- a/src/spriteloader/png.hpp +++ b/src/spriteloader/png.hpp @@ -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 */ diff --git a/src/spriteloader/spriteloader.hpp b/src/spriteloader/spriteloader.hpp index 69b51c2f0..34e668e22 100644 --- a/src/spriteloader/spriteloader.hpp +++ b/src/spriteloader/spriteloader.hpp @@ -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() { } }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 870c13573..435f2b122 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -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; diff --git a/src/viewport.cpp b/src/viewport.cpp index dce5424d2..ba4d44f82 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -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 image, SpriteID pal, int x, int y, int w, 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); |