Sprite: Don't allocate sprite encode space for map-mode zoom levels
This commit is contained in:
@@ -286,7 +286,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
|
|||||||
/* streams of pixels (a, r, g, b channels)
|
/* streams of pixels (a, r, g, b channels)
|
||||||
*
|
*
|
||||||
* stored in separated stream so data are always aligned on 4B boundary */
|
* stored in separated stream so data are always aligned on 4B boundary */
|
||||||
Colour *dst_px_orig[ZOOM_LVL_COUNT];
|
Colour *dst_px_orig[ZOOM_LVL_SPR_COUNT];
|
||||||
|
|
||||||
/* interleaved stream of 'm' channel and 'n' channel
|
/* interleaved stream of 'm' channel and 'n' channel
|
||||||
* 'n' is number of following pixels with the same alpha channel class
|
* 'n' is number of following pixels with the same alpha channel class
|
||||||
@@ -294,10 +294,10 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
|
|||||||
*
|
*
|
||||||
* it has to be stored in one stream so fewer registers are used -
|
* it has to be stored in one stream so fewer registers are used -
|
||||||
* x86 has problems with register allocation even with this solution */
|
* x86 has problems with register allocation even with this solution */
|
||||||
uint16 *dst_n_orig[ZOOM_LVL_COUNT];
|
uint16 *dst_n_orig[ZOOM_LVL_SPR_COUNT];
|
||||||
|
|
||||||
/* lengths of streams */
|
/* lengths of streams */
|
||||||
uint32 lengths[ZOOM_LVL_COUNT][2];
|
uint32 lengths[ZOOM_LVL_SPR_COUNT][2];
|
||||||
|
|
||||||
ZoomLevel zoom_min;
|
ZoomLevel zoom_min;
|
||||||
ZoomLevel zoom_max;
|
ZoomLevel zoom_max;
|
||||||
|
@@ -18,7 +18,7 @@ public:
|
|||||||
/** Data stored about a (single) sprite. */
|
/** Data stored about a (single) sprite. */
|
||||||
struct SpriteData {
|
struct SpriteData {
|
||||||
BlitterSpriteFlags flags;
|
BlitterSpriteFlags flags;
|
||||||
uint32 offset[ZOOM_LVL_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
|
uint32 offset[ZOOM_LVL_SPR_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
|
||||||
byte data[]; ///< Data, all zoomlevels.
|
byte data[]; ///< Data, all zoomlevels.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -30,8 +30,8 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, Alloca
|
|||||||
ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
|
ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
|
||||||
if (sprite->type != SpriteType::Font) {
|
if (sprite->type != SpriteType::Font) {
|
||||||
zoom_min = _settings_client.gui.zoom_min;
|
zoom_min = _settings_client.gui.zoom_min;
|
||||||
zoom_max = _settings_client.gui.zoom_max;
|
zoom_max = (ZoomLevel) std::min(_settings_client.gui.zoom_max, ZOOM_LVL_DRAW_SPR);
|
||||||
if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
|
if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_DRAW_SPR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate sizes and allocate. */
|
/* Calculate sizes and allocate. */
|
||||||
|
@@ -60,7 +60,7 @@ public:
|
|||||||
};
|
};
|
||||||
struct SpriteData {
|
struct SpriteData {
|
||||||
BlitterSpriteFlags flags;
|
BlitterSpriteFlags flags;
|
||||||
SpriteInfo infos[ZOOM_LVL_COUNT];
|
SpriteInfo infos[ZOOM_LVL_SPR_COUNT];
|
||||||
byte data[]; ///< Data, all zoomlevels.
|
byte data[]; ///< Data, all zoomlevels.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -18,7 +18,7 @@ class Blitter_8bppOptimized FINAL : public Blitter_8bppBase {
|
|||||||
public:
|
public:
|
||||||
/** Data stored about a (single) sprite. */
|
/** Data stored about a (single) sprite. */
|
||||||
struct SpriteData {
|
struct SpriteData {
|
||||||
uint32 offset[ZOOM_LVL_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
|
uint32 offset[ZOOM_LVL_SPR_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
|
||||||
byte data[]; ///< Data, all zoomlevels.
|
byte data[]; ///< Data, all zoomlevels.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -386,7 +386,7 @@ static bool PadSprites(SpriteLoader::Sprite *sprite, unsigned int sprite_avail,
|
|||||||
/* Get minimum top left corner coordinates. */
|
/* Get minimum top left corner coordinates. */
|
||||||
int min_xoffs = INT32_MAX;
|
int min_xoffs = INT32_MAX;
|
||||||
int min_yoffs = INT32_MAX;
|
int min_yoffs = INT32_MAX;
|
||||||
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) {
|
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_SPR_END; zoom++) {
|
||||||
if (HasBit(sprite_avail, zoom)) {
|
if (HasBit(sprite_avail, zoom)) {
|
||||||
min_xoffs = std::min(min_xoffs, ScaleByZoom(sprite[zoom].x_offs, zoom));
|
min_xoffs = std::min(min_xoffs, ScaleByZoom(sprite[zoom].x_offs, zoom));
|
||||||
min_yoffs = std::min(min_yoffs, ScaleByZoom(sprite[zoom].y_offs, zoom));
|
min_yoffs = std::min(min_yoffs, ScaleByZoom(sprite[zoom].y_offs, zoom));
|
||||||
@@ -396,7 +396,7 @@ static bool PadSprites(SpriteLoader::Sprite *sprite, unsigned int sprite_avail,
|
|||||||
/* Get maximum dimensions taking necessary padding at the top left into account. */
|
/* Get maximum dimensions taking necessary padding at the top left into account. */
|
||||||
int max_width = INT32_MIN;
|
int max_width = INT32_MIN;
|
||||||
int max_height = INT32_MIN;
|
int max_height = INT32_MIN;
|
||||||
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) {
|
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_SPR_END; zoom++) {
|
||||||
if (HasBit(sprite_avail, zoom)) {
|
if (HasBit(sprite_avail, zoom)) {
|
||||||
max_width = std::max(max_width, ScaleByZoom(sprite[zoom].width + sprite[zoom].x_offs - UnScaleByZoom(min_xoffs, zoom), zoom));
|
max_width = std::max(max_width, ScaleByZoom(sprite[zoom].width + sprite[zoom].x_offs - UnScaleByZoom(min_xoffs, zoom), zoom));
|
||||||
max_height = std::max(max_height, ScaleByZoom(sprite[zoom].height + sprite[zoom].y_offs - UnScaleByZoom(min_yoffs, zoom), zoom));
|
max_height = std::max(max_height, ScaleByZoom(sprite[zoom].height + sprite[zoom].y_offs - UnScaleByZoom(min_yoffs, zoom), zoom));
|
||||||
@@ -411,7 +411,7 @@ static bool PadSprites(SpriteLoader::Sprite *sprite, unsigned int sprite_avail,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Pad sprites where needed. */
|
/* Pad sprites where needed. */
|
||||||
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) {
|
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_SPR_END; zoom++) {
|
||||||
if (HasBit(sprite_avail, zoom)) {
|
if (HasBit(sprite_avail, zoom)) {
|
||||||
/* Scaling the sprite dimensions in the blitter is done with rounding up,
|
/* Scaling the sprite dimensions in the blitter is done with rounding up,
|
||||||
* so a negative padding here is not an error. */
|
* so a negative padding here is not an error. */
|
||||||
@@ -442,7 +442,7 @@ static bool ResizeSprites(SpriteLoader::Sprite *sprite, unsigned int sprite_avai
|
|||||||
if (!PadSprites(sprite, sprite_avail, encoder)) return false;
|
if (!PadSprites(sprite, sprite_avail, encoder)) return false;
|
||||||
|
|
||||||
/* Create other missing zoom levels */
|
/* Create other missing zoom levels */
|
||||||
for (ZoomLevel zoom = ZOOM_LVL_OUT_2X; zoom != ZOOM_LVL_END; zoom++) {
|
for (ZoomLevel zoom = ZOOM_LVL_OUT_2X; zoom != ZOOM_LVL_SPR_END; zoom++) {
|
||||||
if (HasBit(sprite_avail, zoom)) {
|
if (HasBit(sprite_avail, zoom)) {
|
||||||
/* Check that size and offsets match the fully zoomed image. */
|
/* Check that size and offsets match the fully zoomed image. */
|
||||||
assert(sprite[zoom].width == UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].width, zoom));
|
assert(sprite[zoom].width == UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].width, zoom));
|
||||||
@@ -528,7 +528,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
|
|||||||
|
|
||||||
DEBUG(sprite, 9, "Load sprite %d", id);
|
DEBUG(sprite, 9, "Load sprite %d", id);
|
||||||
|
|
||||||
SpriteLoader::Sprite sprite[ZOOM_LVL_COUNT];
|
SpriteLoader::Sprite sprite[ZOOM_LVL_SPR_COUNT];
|
||||||
uint8 sprite_avail = 0;
|
uint8 sprite_avail = 0;
|
||||||
sprite[ZOOM_LVL_NORMAL].type = sprite_type;
|
sprite[ZOOM_LVL_NORMAL].type = sprite_type;
|
||||||
|
|
||||||
@@ -993,7 +993,7 @@ uint32 GetSpriteMainColour(SpriteID sprite_id, PaletteID palette_id)
|
|||||||
SpriteFile &file = *sc->file;
|
SpriteFile &file = *sc->file;
|
||||||
size_t file_pos = sc->file_pos;
|
size_t file_pos = sc->file_pos;
|
||||||
|
|
||||||
SpriteLoader::Sprite sprites[ZOOM_LVL_COUNT];
|
SpriteLoader::Sprite sprites[ZOOM_LVL_SPR_COUNT];
|
||||||
sprites[ZOOM_LVL_NORMAL].type = SpriteType::Normal;
|
sprites[ZOOM_LVL_NORMAL].type = SpriteType::Normal;
|
||||||
SpriteLoaderGrf sprite_loader(file.GetContainerVersion());
|
SpriteLoaderGrf sprite_loader(file.GetContainerVersion());
|
||||||
uint8 sprite_avail;
|
uint8 sprite_avail;
|
||||||
@@ -1109,4 +1109,4 @@ void GfxClearFontSpriteCache()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ ReusableBuffer<SpriteLoader::CommonPixel> SpriteLoader::Sprite::buffer[ZOOM_LVL_COUNT];
|
/* static */ ReusableBuffer<SpriteLoader::CommonPixel> SpriteLoader::Sprite::buffer[ZOOM_LVL_SPR_COUNT];
|
||||||
|
@@ -62,7 +62,7 @@ public:
|
|||||||
void AllocateData(ZoomLevel zoom, size_t size) { this->data = Sprite::buffer[zoom].ZeroAllocate(size); }
|
void AllocateData(ZoomLevel zoom, size_t size) { this->data = Sprite::buffer[zoom].ZeroAllocate(size); }
|
||||||
private:
|
private:
|
||||||
/** Allocated memory to pass sprite data around */
|
/** Allocated memory to pass sprite data around */
|
||||||
static ReusableBuffer<SpriteLoader::CommonPixel> buffer[ZOOM_LVL_COUNT];
|
static ReusableBuffer<SpriteLoader::CommonPixel> buffer[ZOOM_LVL_SPR_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1272,10 +1272,10 @@ void OpenGLBackend::ReleaseAnimBuffer(const Rect &update_rect)
|
|||||||
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
|
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
|
||||||
|
|
||||||
OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
|
OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
|
||||||
new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_COUNT, sprite->colours);
|
new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_SPR_COUNT, sprite->colours);
|
||||||
|
|
||||||
/* Upload texture data. */
|
/* Upload texture data. */
|
||||||
for (int i = 0; i < (sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_COUNT); i++) {
|
for (int i = 0; i < (sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_SPR_COUNT); i++) {
|
||||||
gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
|
gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -108,7 +108,7 @@ public:
|
|||||||
/* SpriteEncoder */
|
/* SpriteEncoder */
|
||||||
|
|
||||||
bool Is32BppSupported() override { return true; }
|
bool Is32BppSupported() override { return true; }
|
||||||
uint GetSpriteAlignment() override { return 1u << (ZOOM_LVL_COUNT - 1); }
|
uint GetSpriteAlignment() override { return 1u << (ZOOM_LVL_SPR_COUNT - 1); }
|
||||||
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -50,6 +50,9 @@ enum ZoomLevel : byte {
|
|||||||
ZOOM_LVL_MAX = ZOOM_LVL_OUT_512X, ///< Maximum zoom level.
|
ZOOM_LVL_MAX = ZOOM_LVL_OUT_512X, ///< Maximum zoom level.
|
||||||
ZOOM_LVL_DRAW_MAP = ZOOM_LVL_OUT_64X, ///< All zoomlevels above or equal to this are rendered with map style
|
ZOOM_LVL_DRAW_MAP = ZOOM_LVL_OUT_64X, ///< All zoomlevels above or equal to this are rendered with map style
|
||||||
ZOOM_LVL_DRAW_SPR = ZOOM_LVL_DRAW_MAP - 1, ///< All zoomlevels below or equal to this are rendered with sprites
|
ZOOM_LVL_DRAW_SPR = ZOOM_LVL_DRAW_MAP - 1, ///< All zoomlevels below or equal to this are rendered with sprites
|
||||||
|
|
||||||
|
ZOOM_LVL_SPR_END = ZOOM_LVL_DRAW_MAP, ///< End for iteration of zoom levels to draw with sprites.
|
||||||
|
ZOOM_LVL_SPR_COUNT = ZOOM_LVL_SPR_END - ZOOM_LVL_BEGIN, ///< Number of zoom levels to draw with sprites.
|
||||||
};
|
};
|
||||||
DECLARE_POSTFIX_INCREMENT(ZoomLevel)
|
DECLARE_POSTFIX_INCREMENT(ZoomLevel)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user