summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blitter/32bpp_optimized.cpp21
-rw-r--r--src/blitter/8bpp_optimized.cpp17
-rw-r--r--src/fontcache.cpp1
-rw-r--r--src/settings.cpp1
-rw-r--r--src/spritecache.cpp24
-rw-r--r--src/spritecache.h1
-rw-r--r--src/spriteloader/spriteloader.hpp1
7 files changed, 59 insertions, 7 deletions
diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp
index 8449fb154..b7d252721 100644
--- a/src/blitter/32bpp_optimized.cpp
+++ b/src/blitter/32bpp_optimized.cpp
@@ -11,6 +11,7 @@
#include "../stdafx.h"
#include "../zoom_func.h"
+#include "../settings_type.h"
#include "../core/math_func.hpp"
#include "32bpp_optimized.hpp"
@@ -274,7 +275,19 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr
/* lengths of streams */
uint32 lengths[ZOOM_LVL_COUNT][2];
- for (ZoomLevel z = ZOOM_LVL_BEGIN; z < ZOOM_LVL_END; z++) {
+ ZoomLevel zoom_min;
+ ZoomLevel zoom_max;
+
+ if (sprite->type == ST_FONT) {
+ zoom_min = ZOOM_LVL_NORMAL;
+ zoom_max = ZOOM_LVL_NORMAL;
+ } else {
+ zoom_min = _settings_client.gui.zoom_min;
+ zoom_max = _settings_client.gui.zoom_max;
+ if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
+ }
+
+ for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
const SpriteLoader::Sprite *src_orig = ResizeSprite(sprite, z);
uint size = src_orig->height * src_orig->width;
@@ -358,7 +371,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr
}
uint len = 0; // total length of data
- for (ZoomLevel z = ZOOM_LVL_BEGIN; z < ZOOM_LVL_END; z++) {
+ for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
len += lengths[z][0] + lengths[z][1];
}
@@ -371,8 +384,8 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr
SpriteData *dst = (SpriteData *)dest_sprite->data;
- for (ZoomLevel z = ZOOM_LVL_BEGIN; z < ZOOM_LVL_END; z++) {
- dst->offset[z][0] = z == ZOOM_LVL_BEGIN ? 0 : lengths[z - 1][1] + dst->offset[z - 1][1];
+ for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
+ dst->offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->offset[z - 1][1];
dst->offset[z][1] = lengths[z][0] + dst->offset[z][0];
memcpy(dst->data + dst->offset[z][0], dst_px_orig[z], lengths[z][0]);
diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp
index ed3d24a77..24b9252b7 100644
--- a/src/blitter/8bpp_optimized.cpp
+++ b/src/blitter/8bpp_optimized.cpp
@@ -11,6 +11,7 @@
#include "../stdafx.h"
#include "../zoom_func.h"
+#include "../settings_type.h"
#include "../core/math_func.hpp"
#include "8bpp_optimized.hpp"
@@ -116,7 +117,19 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPro
/* Make memory for all zoom-levels */
uint memory = sizeof(SpriteData);
- for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
+ ZoomLevel zoom_min;
+ ZoomLevel zoom_max;
+
+ if (sprite->type == ST_FONT) {
+ zoom_min = ZOOM_LVL_NORMAL;
+ zoom_max = ZOOM_LVL_NORMAL;
+ } else {
+ zoom_min = _settings_client.gui.zoom_min;
+ zoom_max = _settings_client.gui.zoom_max;
+ if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
+ }
+
+ for (ZoomLevel i = zoom_min; i <= zoom_max; i++) {
memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
}
@@ -131,7 +144,7 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPro
byte *dst = temp_dst->data;
/* Make the sprites per zoom-level */
- for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
+ for (ZoomLevel i = zoom_min; i <= zoom_max; i++) {
/* Store the index table */
uint offset = dst - temp_dst->data;
temp_dst->offset[i] = offset;
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index 507ee2940..2e1882147 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -1113,6 +1113,7 @@ const Sprite *GetGlyph(FontSize size, WChar key)
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
sprite.AllocateData(width * height);
+ sprite.type = ST_FONT;
sprite.width = width;
sprite.height = height;
sprite.x_offs = slot->bitmap_left;
diff --git a/src/settings.cpp b/src/settings.cpp
index 28192a4d7..b5b5c0d52 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -898,6 +898,7 @@ static bool ZoomMinMaxChanged(int32 p1)
{
extern void ConstrainAllViewportsZoom();
ConstrainAllViewportsZoom();
+ GfxClearSpriteCache();
return true;
}
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index 7765c340a..dc5a2acd1 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -199,6 +199,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
/* Try loading 32bpp graphics in case we are 32bpp output */
SpriteLoaderPNG sprite_loader;
SpriteLoader::Sprite sprite;
+ sprite.type = sprite_type;
if (sprite_loader.LoadSprite(&sprite, file_slot, sc->id, sprite_type)) {
return BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, allocator);
@@ -290,6 +291,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
SpriteLoaderGrf sprite_loader;
SpriteLoader::Sprite sprite;
+ sprite.type = sprite_type;
if (!sprite_loader.LoadSprite(&sprite, file_slot, file_pos, sprite_type)) {
if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?");
@@ -608,7 +610,7 @@ void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator)
}
-void GfxInitSpriteMem()
+static void GfxInitSpriteCache()
{
/* initialize sprite cache heap */
if (_spritecache_ptr == NULL) _spritecache_ptr = (MemBlock*)MallocT<byte>(_sprite_cache_size * 1024 * 1024);
@@ -617,6 +619,11 @@ void GfxInitSpriteMem()
_spritecache_ptr->size = ((_sprite_cache_size * 1024 * 1024) - sizeof(MemBlock)) | S_FREE_MASK;
/* Sentinel block (identified by size == 0) */
NextBlock(_spritecache_ptr)->size = 0;
+}
+
+void GfxInitSpriteMem()
+{
+ GfxInitSpriteCache();
/* Reset the spritecache 'pool' */
free(_spritecache);
@@ -626,4 +633,19 @@ void GfxInitSpriteMem()
_compact_cache_counter = 0;
}
+/**
+ * Remove all encoded sprites from the sprite cache without
+ * discarding sprite location information.
+ */
+void GfxClearSpriteCache()
+{
+ /* Clear sprite ptr for all cached items */
+ for (uint i = 0; i != _spritecache_items; i++) {
+ SpriteCache *sc = GetSpriteCache(i);
+ sc->ptr = NULL;
+ }
+
+ GfxInitSpriteCache();
+}
+
/* static */ ReusableBuffer<SpriteLoader::CommonPixel> SpriteLoader::Sprite::buffer;
diff --git a/src/spritecache.h b/src/spritecache.h
index f0c124f5a..0b1a08b19 100644
--- a/src/spritecache.h
+++ b/src/spritecache.h
@@ -48,6 +48,7 @@ static inline const byte *GetNonSprite(SpriteID sprite, SpriteType type)
}
void GfxInitSpriteMem();
+void GfxClearSpriteCache();
void IncreaseSpriteLRU();
bool LoadNextSprite(int load_index, byte file_index, uint file_sprite_id);
diff --git a/src/spriteloader/spriteloader.hpp b/src/spriteloader/spriteloader.hpp
index 86a87e7a4..b1d9b5c58 100644
--- a/src/spriteloader/spriteloader.hpp
+++ b/src/spriteloader/spriteloader.hpp
@@ -38,6 +38,7 @@ public:
uint16 width; ///< Width of the sprite
int16 x_offs; ///< The x-offset of where the sprite will be drawn
int16 y_offs; ///< The y-offset of where the sprite will be drawn
+ SpriteType type; ///< The sprite type
SpriteLoader::CommonPixel *data; ///< The sprite itself
/**