mirror of https://github.com/OpenTTD/OpenTTD
(svn r23890) -Add: [NewGRF] Support for RealSprites with multiple zoom levels.
parent
e85d5b5d31
commit
5c1cc27b03
|
@ -18,6 +18,7 @@
|
||||||
#include "../error.h"
|
#include "../error.h"
|
||||||
#include "../core/math_func.hpp"
|
#include "../core/math_func.hpp"
|
||||||
#include "../core/alloc_type.hpp"
|
#include "../core/alloc_type.hpp"
|
||||||
|
#include "../core/bitmath_func.hpp"
|
||||||
#include "grf.hpp"
|
#include "grf.hpp"
|
||||||
|
|
||||||
extern const byte _palmap_w2d[];
|
extern const byte _palmap_w2d[];
|
||||||
|
@ -200,6 +201,8 @@ uint8 LoadSpriteV1(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
|
||||||
|
|
||||||
uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type)
|
uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type)
|
||||||
{
|
{
|
||||||
|
static const ZoomLevel zoom_lvl_map[6] = {ZOOM_LVL_OUT_4X, ZOOM_LVL_NORMAL, ZOOM_LVL_OUT_2X, ZOOM_LVL_OUT_8X, ZOOM_LVL_OUT_16X, ZOOM_LVL_OUT_32X};
|
||||||
|
|
||||||
/* Is the sprite not present/stripped in the GRF? */
|
/* Is the sprite not present/stripped in the GRF? */
|
||||||
if (file_pos == SIZE_MAX) return 0;
|
if (file_pos == SIZE_MAX) return 0;
|
||||||
|
|
||||||
|
@ -208,6 +211,7 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
|
||||||
|
|
||||||
uint32 id = FioReadDword();
|
uint32 id = FioReadDword();
|
||||||
|
|
||||||
|
uint8 loaded_sprites = 0;
|
||||||
do {
|
do {
|
||||||
int64 num = FioReadDword();
|
int64 num = FioReadDword();
|
||||||
size_t start_pos = FioGetPos();
|
size_t start_pos = FioGetPos();
|
||||||
|
@ -219,8 +223,15 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
|
||||||
byte colour = type & SCC_MASK;
|
byte colour = type & SCC_MASK;
|
||||||
byte zoom = FioReadByte();
|
byte zoom = FioReadByte();
|
||||||
|
|
||||||
if (colour == SCC_PAL && zoom == 0) {
|
if (colour == SCC_PAL && (sprite_type == ST_NORMAL ? zoom < lengthof(zoom_lvl_map) : zoom == 0)) {
|
||||||
ZoomLevel zoom_lvl = (sprite_type == ST_NORMAL) ? ZOOM_LVL_OUT_4X : ZOOM_LVL_NORMAL;
|
ZoomLevel zoom_lvl = (sprite_type == ST_NORMAL) ? zoom_lvl_map[zoom] : ZOOM_LVL_NORMAL;
|
||||||
|
|
||||||
|
if (HasBit(loaded_sprites, zoom_lvl)) {
|
||||||
|
/* We already have this zoom level, skip sprite. */
|
||||||
|
DEBUG(sprite, 1, "Ignoring duplicate zoom level sprite %u from %s", id, FioGetFilename(file_slot));
|
||||||
|
FioSkipBytes(num - 2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
sprite[zoom_lvl].height = FioReadWord();
|
sprite[zoom_lvl].height = FioReadWord();
|
||||||
sprite[zoom_lvl].width = FioReadWord();
|
sprite[zoom_lvl].width = FioReadWord();
|
||||||
|
@ -240,7 +251,7 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1 << zoom_lvl;
|
if (valid) SetBit(loaded_sprites, zoom_lvl);
|
||||||
} else {
|
} else {
|
||||||
/* Not the wanted zoom level or colour depth, continue searching. */
|
/* Not the wanted zoom level or colour depth, continue searching. */
|
||||||
FioSkipBytes(num - 2);
|
FioSkipBytes(num - 2);
|
||||||
|
@ -248,7 +259,7 @@ uint8 LoadSpriteV2(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_po
|
||||||
|
|
||||||
} while (FioReadDword() == id);
|
} while (FioReadDword() == id);
|
||||||
|
|
||||||
return 0;
|
return loaded_sprites;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type)
|
uint8 SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, uint8 file_slot, size_t file_pos, SpriteType sprite_type)
|
||||||
|
|
Loading…
Reference in New Issue