diff options
author | michi_cc <michi_cc@openttd.org> | 2012-02-04 13:28:56 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2012-02-04 13:28:56 +0000 |
commit | 02d07e68d8c6fc760021ec1c36086877f714152c (patch) | |
tree | a526ec88ccb316a64b1fc054f3de450138204784 /src | |
parent | 76cfbb257cc3b834e466dfd861852005253028ed (diff) | |
download | openttd-02d07e68d8c6fc760021ec1c36086877f714152c.tar.xz |
(svn r23885) -Codechange: Use the GRF sprite loader for then mapgen sprites as well.
Diffstat (limited to 'src')
-rw-r--r-- | src/landscape.cpp | 1 | ||||
-rw-r--r-- | src/spritecache.cpp | 81 |
2 files changed, 31 insertions, 51 deletions
diff --git a/src/landscape.cpp b/src/landscape.cpp index 7f4b1ed44..caa75ef27 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -769,6 +769,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, ST_MAPGEN); + if (templ == NULL) usererror("Map generator sprites could not be loaded"); uint x = r & MapMaxX(); uint y = (r >> MapLogX()) & MapMaxY(); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 7e70f2fa7..609d92acb 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -227,65 +227,44 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty #endif /* WITH_PNG */ } - FioSeekToFile(file_slot, file_pos); - - /* Read the size and type */ - int num = FioReadWord(); - byte type = FioReadByte(); - - /* Type 0xFF indicates either a colourmap or some other non-sprite info - * which we should have already handled during GRF loading. */ - assert(type != 0xFF); - - /* 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 *)allocator(sizeof(*sprite) + num); - 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++; - } - } - - return sprite; - } - - assert(sprite_type == ST_NORMAL || sprite_type == ST_FONT); - SpriteLoaderGrf sprite_loader; SpriteLoader::Sprite sprite; sprite.type = sprite_type; if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos, sprite_type)) { + if (sprite_type == ST_MAPGEN) return NULL; 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, allocator); } + + if (sprite_type == ST_MAPGEN) { + /* 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 + * extract the data directly 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). */ + uint num = sprite.width * sprite.height; + + Sprite *s = (Sprite *)allocator(sizeof(*s) + num); + s->width = sprite.width; + s->height = sprite.height; + s->x_offs = sprite.x_offs; + s->y_offs = sprite.y_offs; + + SpriteLoader::CommonPixel *src = sprite.data; + byte *dest = s->data; + while (num-- > 0) { + *dest++ = src->m; + src++; + } + + return s; + } + return BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, allocator); } |