Changeset - r28313:4d0ad08733f5
[Not reviewed]
master
0 25 0
Peter Nelson - 12 months ago 2023-12-20 20:38:21
peter1138@openttd.org
Codechange: Replace pointer to Sprite array with reference to SpriteCollection. (#11580)

Add `SpriteLoader::SpriteCollection` type which is an array of `SpriteLoad::Sprite`.

This removes the ambiguity of what `SpriteLoader::Sprite *` is pointing to,
and cleans up mismatches using both dereference -> and array access [] for the
same object.
25 files changed with 90 insertions and 82 deletions:
0 comments (0 inline, 0 general)
src/blitter/32bpp_anim_sse4.hpp
Show inline comments
 
@@ -39,7 +39,7 @@ public:
 
	template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent, bool animated>
 
	void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override {
 
		return Blitter_32bppSSE_Base::Encode(sprite, allocator);
 
	}
 
	const char *GetName() override { return "32bpp-sse4-anim"; }
src/blitter/32bpp_optimized.cpp
Show inline comments
 
@@ -272,7 +272,7 @@ void Blitter_32bppOptimized::Draw(Blitte
 
	this->Draw<false>(bp, mode, zoom);
 
}
 

	
 
template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	/* streams of pixels (a, r, g, b channels)
 
	 *
 
@@ -293,7 +293,7 @@ template <bool Tpal_to_rgb> Sprite *Blit
 
	ZoomLevel zoom_min;
 
	ZoomLevel zoom_max;
 

	
 
	if (sprite->type == SpriteType::Font) {
 
	if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font) {
 
		zoom_min = ZOOM_LVL_NORMAL;
 
		zoom_max = ZOOM_LVL_NORMAL;
 
	} else {
 
@@ -403,10 +403,10 @@ template <bool Tpal_to_rgb> Sprite *Blit
 

	
 
	Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(SpriteData) + len);
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 
	dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dest_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 

	
 
	SpriteData *dst = (SpriteData *)dest_sprite->data;
 
	memset(dst, 0, sizeof(*dst));
 
@@ -425,10 +425,10 @@ template <bool Tpal_to_rgb> Sprite *Blit
 
	return dest_sprite;
 
}
 

	
 
template Sprite *Blitter_32bppOptimized::EncodeInternal<true>(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
 
template Sprite *Blitter_32bppOptimized::EncodeInternal<false>(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
 
template Sprite *Blitter_32bppOptimized::EncodeInternal<true>(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
 
template Sprite *Blitter_32bppOptimized::EncodeInternal<false>(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
 

	
 
Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	return this->EncodeInternal<true>(sprite, allocator);
 
}
src/blitter/32bpp_optimized.hpp
Show inline comments
 
@@ -22,7 +22,7 @@ public:
 
	};
 

	
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 

	
 
	const char *GetName() override { return "32bpp-optimized"; }
 

	
 
@@ -30,7 +30,7 @@ public:
 

	
 
protected:
 
	template <bool Tpal_to_rgb> void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
	template <bool Tpal_to_rgb> Sprite *EncodeInternal(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
 
	template <bool Tpal_to_rgb> Sprite *EncodeInternal(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
 
};
 

	
 
/** Factory for the optimised 32 bpp blitter (without palette animation). */
src/blitter/32bpp_simple.cpp
Show inline comments
 
@@ -109,20 +109,20 @@ void Blitter_32bppSimple::DrawColourMapp
 
	Debug(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
 
}
 

	
 
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	Blitter_32bppSimple::Pixel *dst;
 
	Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width * sizeof(*dst));
 
	Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite[ZOOM_LVL_NORMAL].height * (size_t)sprite[ZOOM_LVL_NORMAL].width * sizeof(*dst));
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 
	dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dest_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 

	
 
	dst = (Blitter_32bppSimple::Pixel *)dest_sprite->data;
 
	SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite->data;
 
	SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite[ZOOM_LVL_NORMAL].data;
 

	
 
	for (int i = 0; i < sprite->height * sprite->width; i++) {
 
	for (int i = 0; i < sprite[ZOOM_LVL_NORMAL].height * sprite[ZOOM_LVL_NORMAL].width; i++) {
 
		if (src->m == 0) {
 
			dst[i].r = src->r;
 
			dst[i].g = src->g;
src/blitter/32bpp_simple.hpp
Show inline comments
 
@@ -26,7 +26,7 @@ class Blitter_32bppSimple : public Blitt
 
public:
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
 
	void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 

	
 
	const char *GetName() override { return "32bpp-simple"; }
 
};
src/blitter/32bpp_sse2.cpp
Show inline comments
 
@@ -20,7 +20,7 @@
 
/** Instantiation of the SSE2 32bpp blitter factory. */
 
static FBlitter_32bppSSE2 iFBlitter_32bppSSE2;
 

	
 
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	/* First uint32_t of a line = the number of transparent pixels from the left.
 
	 * Second uint32_t of a line = the number of transparent pixels from the right.
 
@@ -28,7 +28,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(co
 
	 */
 
	ZoomLevel zoom_min = ZOOM_LVL_NORMAL;
 
	ZoomLevel zoom_max = ZOOM_LVL_NORMAL;
 
	if (sprite->type != SpriteType::Font) {
 
	if (sprite[ZOOM_LVL_NORMAL].type != SpriteType::Font) {
 
		zoom_min = _settings_client.gui.zoom_min;
 
		zoom_max = _settings_client.gui.zoom_max;
 
		if (zoom_max == zoom_min) zoom_max = ZOOM_LVL_MAX;
 
@@ -52,10 +52,10 @@ Sprite *Blitter_32bppSSE_Base::Encode(co
 
	}
 

	
 
	Sprite *dst_sprite = (Sprite *) allocator(sizeof(Sprite) + sizeof(SpriteData) + all_sprites_size);
 
	dst_sprite->height = sprite->height;
 
	dst_sprite->width  = sprite->width;
 
	dst_sprite->x_offs = sprite->x_offs;
 
	dst_sprite->y_offs = sprite->y_offs;
 
	dst_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dst_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dst_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dst_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 
	memcpy(dst_sprite->data, &sd, sizeof(SpriteData));
 

	
 
	/* Copy colours and determine flags. */
src/blitter/32bpp_sse2.hpp
Show inline comments
 
@@ -76,7 +76,7 @@ public:
 
		byte data[]; ///< Data, all zoomlevels.
 
	};
 

	
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
 
};
 

	
 
DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
 
@@ -88,7 +88,7 @@ public:
 
	template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
 
	void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
 

	
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override {
 
		return Blitter_32bppSSE_Base::Encode(sprite, allocator);
 
	}
 

	
src/blitter/40bpp_anim.cpp
Show inline comments
 
@@ -377,7 +377,7 @@ void Blitter_40bppAnim::DrawColourMappin
 
	}
 
}
 

	
 
Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	return this->EncodeInternal<false>(sprite, allocator);
 
}
src/blitter/40bpp_anim.hpp
Show inline comments
 
@@ -27,7 +27,7 @@ public:
 
	void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
 
	void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 
	size_t BufferSize(uint width, uint height) override;
 
	Blitter::PaletteAnimation UsePaletteAnimation() override;
 
	bool NeedsAnimationBuffer() override;
src/blitter/8bpp_optimized.cpp
Show inline comments
 
@@ -119,7 +119,7 @@ void Blitter_8bppOptimized::Draw(Blitter
 
	}
 
}
 

	
 
Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	/* Make memory for all zoom-levels */
 
	uint memory = sizeof(SpriteData);
 
@@ -127,7 +127,7 @@ Sprite *Blitter_8bppOptimized::Encode(co
 
	ZoomLevel zoom_min;
 
	ZoomLevel zoom_max;
 

	
 
	if (sprite->type == SpriteType::Font) {
 
	if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font) {
 
		zoom_min = ZOOM_LVL_NORMAL;
 
		zoom_max = ZOOM_LVL_NORMAL;
 
	} else {
 
@@ -220,10 +220,10 @@ Sprite *Blitter_8bppOptimized::Encode(co
 
	/* Allocate the exact amount of memory we need */
 
	Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + size);
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 
	dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dest_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 
	memcpy(dest_sprite->data, temp_dst, size);
 

	
 
	return dest_sprite;
src/blitter/8bpp_optimized.hpp
Show inline comments
 
@@ -23,7 +23,7 @@ public:
 
	};
 

	
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 

	
 
	const char *GetName() override { return "8bpp-optimized"; }
 
};
src/blitter/8bpp_simple.cpp
Show inline comments
 
@@ -60,19 +60,19 @@ void Blitter_8bppSimple::Draw(Blitter::B
 
	}
 
}
 

	
 
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	Sprite *dest_sprite;
 
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
 
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite[ZOOM_LVL_NORMAL].height * (size_t)sprite[ZOOM_LVL_NORMAL].width);
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 
	dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dest_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 

	
 
	/* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
 
	for (int i = 0; i < sprite->height * sprite->width; i++) {
 
		dest_sprite->data[i] = sprite->data[i].m;
 
	for (int i = 0; i < sprite[ZOOM_LVL_NORMAL].height * sprite[ZOOM_LVL_NORMAL].width; i++) {
 
		dest_sprite->data[i] = sprite[ZOOM_LVL_NORMAL].data[i].m;
 
	}
 

	
 
	return dest_sprite;
src/blitter/8bpp_simple.hpp
Show inline comments
 
@@ -17,7 +17,7 @@
 
class Blitter_8bppSimple FINAL : public Blitter_8bppBase {
 
public:
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 

	
 
	const char *GetName() override { return "8bpp-simple"; }
 
};
src/blitter/null.cpp
Show inline comments
 
@@ -15,15 +15,15 @@
 
/** Instantiation of the null blitter factory. */
 
static FBlitter_Null iFBlitter_Null;
 

	
 
Sprite *Blitter_Null::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
Sprite *Blitter_Null::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	Sprite *dest_sprite;
 
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite));
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 
	dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dest_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 

	
 
	return dest_sprite;
 
}
src/blitter/null.hpp
Show inline comments
 
@@ -18,7 +18,7 @@ public:
 
	uint8_t GetScreenDepth() override { return 0; }
 
	void Draw(Blitter::BlitterParams *, BlitterMode, ZoomLevel) override {};
 
	void DrawColourMappingRect(void *, int, int, PaletteID) override {};
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 
	void *MoveTo(void *, int, int) override { return nullptr; };
 
	void SetPixel(void *, int, int, uint8_t) override {};
 
	void DrawRect(void *, int, int, uint8_t) override {};
src/fontcache/freetypefontcache.cpp
Show inline comments
 
@@ -235,7 +235,8 @@ const Sprite *FreeTypeFontCache::Interna
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
 

	
 
	/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
 
	SpriteLoader::Sprite sprite;
 
	SpriteLoader::SpriteCollection spritecollection;
 
	SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, static_cast<size_t>(width) * height);
 
	sprite.type = SpriteType::Font;
 
	sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
 
@@ -266,7 +267,7 @@ const Sprite *FreeTypeFontCache::Interna
 
	}
 

	
 
	GlyphEntry new_glyph;
 
	new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
 
	new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
 
	new_glyph.width  = slot->advance.x >> 6;
 

	
 
	this->SetGlyphPtr(key, &new_glyph);
src/fontcache/truetypefontcache.cpp
Show inline comments
 
@@ -136,7 +136,7 @@ const Sprite *TrueTypeFontCache::GetGlyp
 
			};
 
#undef CPSET
 
#undef CP___
 
			static const SpriteLoader::Sprite builtin_questionmark = {
 
			static const SpriteLoader::SpriteCollection builtin_questionmark = {{ {
 
				10, // height
 
				8,  // width
 
				0,  // x_offs
 
@@ -144,9 +144,9 @@ const Sprite *TrueTypeFontCache::GetGlyp
 
				SpriteType::Font,
 
				SCC_PAL,
 
				builtin_questionmark_data
 
			};
 
			} }};
 

	
 
			Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, SimpleSpriteAlloc);
 
			Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(builtin_questionmark, SimpleSpriteAlloc);
 
			assert(spr != nullptr);
 
			GlyphEntry new_glyph;
 
			new_glyph.sprite = spr;
src/os/macosx/font_osx.cpp
Show inline comments
 
@@ -240,7 +240,8 @@ const Sprite *CoreTextFontCache::Interna
 
	/* Limit glyph size to prevent overflows later on. */
 
	if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) UserError("Font glyph is too large");
 

	
 
	SpriteLoader::Sprite sprite;
 
	SpriteLoader::SpriteCollection spritecollection;
 
	SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
 
	sprite.type = SpriteType::Font;
 
	sprite.colours = (use_aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
 
@@ -290,7 +291,7 @@ const Sprite *CoreTextFontCache::Interna
 
	}
 

	
 
	GlyphEntry new_glyph;
 
	new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
 
	new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
 
	new_glyph.width = (byte)std::round(CTFontGetAdvancesForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1));
 
	this->SetGlyphPtr(key, &new_glyph);
 

	
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -230,7 +230,8 @@ void Win32FontCache::ClearFontCache()
 
	GetGlyphOutline(this->dc, key, GGO_GLYPH_INDEX | (aa ? GGO_GRAY8_BITMAP : GGO_BITMAP), &gm, size, bmp, &mat);
 

	
 
	/* GDI has rendered the glyph, now we allocate a sprite and copy the image into it. */
 
	SpriteLoader::Sprite sprite;
 
	SpriteLoader::SpriteCollection spritecollection;
 
	SpriteLoader::Sprite &sprite = spritecollection[ZOOM_LVL_NORMAL];
 
	sprite.AllocateData(ZOOM_LVL_NORMAL, width * height);
 
	sprite.type = SpriteType::Font;
 
	sprite.colours = (aa ? SCC_PAL | SCC_ALPHA : SCC_PAL);
 
@@ -270,7 +271,7 @@ void Win32FontCache::ClearFontCache()
 
	}
 

	
 
	GlyphEntry new_glyph;
 
	new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc);
 
	new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(spritecollection, SimpleSpriteAlloc);
 
	new_glyph.width = gm.gmCellIncX;
 

	
 
	this->SetGlyphPtr(key, &new_glyph);
src/spritecache.cpp
Show inline comments
 
@@ -213,7 +213,7 @@ uint GetMaxSpriteID()
 
	return _spritecache_items;
 
}
 

	
 
static bool ResizeSpriteIn(SpriteLoader::Sprite *sprite, ZoomLevel src, ZoomLevel tgt)
 
static bool ResizeSpriteIn(SpriteLoader::SpriteCollection &sprite, ZoomLevel src, ZoomLevel tgt)
 
{
 
	uint8_t scaled_1 = ScaleByZoom(1, (ZoomLevel)(src - tgt));
 

	
 
@@ -240,7 +240,7 @@ static bool ResizeSpriteIn(SpriteLoader:
 
	return true;
 
}
 

	
 
static void ResizeSpriteOut(SpriteLoader::Sprite *sprite, ZoomLevel zoom)
 
static void ResizeSpriteOut(SpriteLoader::SpriteCollection &sprite, ZoomLevel zoom)
 
{
 
	/* Algorithm based on 32bpp_Optimized::ResizeSprite() */
 
	sprite[zoom].width  = UnScaleByZoom(sprite[ZOOM_LVL_NORMAL].width,  zoom);
 
@@ -323,7 +323,7 @@ static bool PadSingleSprite(SpriteLoader
 
	return true;
 
}
 

	
 
static bool PadSprites(SpriteLoader::Sprite *sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
 
static bool PadSprites(SpriteLoader::SpriteCollection &sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
 
{
 
	/* Get minimum top left corner coordinates. */
 
	int min_xoffs = INT32_MAX;
 
@@ -371,7 +371,7 @@ static bool PadSprites(SpriteLoader::Spr
 
	return true;
 
}
 

	
 
static bool ResizeSprites(SpriteLoader::Sprite *sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
 
static bool ResizeSprites(SpriteLoader::SpriteCollection &sprite, uint8_t sprite_avail, SpriteEncoder *encoder)
 
{
 
	/* Create a fully zoomed image if it does not exist */
 
	ZoomLevel first_avail = static_cast<ZoomLevel>(FIND_FIRST_BIT(sprite_avail));
 
@@ -457,7 +457,7 @@ static void *ReadSprite(const SpriteCach
 

	
 
	Debug(sprite, 9, "Load sprite {}", id);
 

	
 
	SpriteLoader::Sprite sprite[ZOOM_LVL_END];
 
	SpriteLoader::SpriteCollection sprite;
 
	uint8_t sprite_avail = 0;
 
	sprite[ZOOM_LVL_NORMAL].type = sprite_type;
 

	
 
@@ -509,7 +509,7 @@ static void *ReadSprite(const SpriteCach
 
		return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
 
	}
 

	
 
	if (sprite->type == SpriteType::Font && _font_zoom != ZOOM_LVL_NORMAL) {
 
	if (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font && _font_zoom != ZOOM_LVL_NORMAL) {
 
		/* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */
 
		sprite[ZOOM_LVL_NORMAL].width  = sprite[_font_zoom].width;
 
		sprite[ZOOM_LVL_NORMAL].height = sprite[_font_zoom].height;
src/spriteloader/grf.cpp
Show inline comments
 
@@ -215,7 +215,7 @@ bool DecodeSingleSprite(SpriteLoader::Sp
 
	return true;
 
}
 

	
 
uint8_t LoadSpriteV1(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp)
 
uint8_t LoadSpriteV1(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp)
 
{
 
	/* Check the requested colour depth. */
 
	if (load_32bpp) return 0;
 
@@ -252,7 +252,7 @@ uint8_t LoadSpriteV1(SpriteLoader::Sprit
 
	return 0;
 
}
 

	
 
uint8_t LoadSpriteV2(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
 
uint8_t LoadSpriteV2(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
 
{
 
	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};
 

	
 
@@ -350,7 +350,7 @@ uint8_t LoadSpriteV2(SpriteLoader::Sprit
 
	return loaded_sprites;
 
}
 

	
 
uint8_t SpriteLoaderGrf::LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
 
uint8_t SpriteLoaderGrf::LoadSprite(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags)
 
{
 
	if (this->container_ver >= 2) {
 
		return LoadSpriteV2(sprite, file, file_pos, sprite_type, load_32bpp, control_flags);
src/spriteloader/grf.hpp
Show inline comments
 
@@ -17,7 +17,7 @@ class SpriteLoaderGrf : public SpriteLoa
 
	byte container_ver;
 
public:
 
	SpriteLoaderGrf(byte container_ver) : container_ver(container_ver) {}
 
	uint8_t LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) override;
 
	uint8_t LoadSprite(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) override;
 
};
 

	
 
#endif /* SPRITELOADER_GRF_HPP */
src/spriteloader/spriteloader.hpp
Show inline comments
 
@@ -66,6 +66,11 @@ public:
 
	};
 

	
 
	/**
 
	 * Type defining a collection of sprites, one for each zoom level.
 
	 */
 
	using SpriteCollection = std::array<Sprite, ZOOM_LVL_END>;
 

	
 
	/**
 
	 * Load a sprite from the disk and return a sprite struct which is the same for all loaders.
 
	 * @param[out] sprite The sprites to fill with data.
 
	 * @param file_slot   The file "descriptor" of the file we read from.
 
@@ -75,7 +80,7 @@ public:
 
	 * @param control_flags Control flags, see SpriteCacheCtrlFlags.
 
	 * @return Bit mask of the zoom levels successfully loaded or 0 if no sprite could be loaded.
 
	 */
 
	virtual uint8_t LoadSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) = 0;
 
	virtual uint8_t LoadSprite(SpriteLoader::SpriteCollection &sprite, SpriteFile &file, size_t file_pos, SpriteType sprite_type, bool load_32bpp, byte control_flags) = 0;
 

	
 
	virtual ~SpriteLoader() = default;
 
};
 
@@ -94,7 +99,7 @@ public:
 
	/**
 
	 * Convert a sprite from the loader to our own format.
 
	 */
 
	virtual Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) = 0;
 
	virtual Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) = 0;
 

	
 
	/**
 
	 * Get the value which the height and width on a sprite have to be aligned by.
src/video/opengl.cpp
Show inline comments
 
@@ -1264,23 +1264,23 @@ void OpenGLBackend::ReleaseAnimBuffer(co
 
	}
 
}
 

	
 
/* virtual */ Sprite *OpenGLBackend::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
 
/* virtual */ Sprite *OpenGLBackend::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
 
{
 
	/* Allocate and construct sprite data. */
 
	Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(OpenGLSprite));
 

	
 
	OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
 
	new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_END, sprite->colours);
 
	new (gl_sprite) OpenGLSprite(sprite[ZOOM_LVL_NORMAL].width, sprite[ZOOM_LVL_NORMAL].height, sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font ? 1 : ZOOM_LVL_END, sprite[ZOOM_LVL_NORMAL].colours);
 

	
 
	/* Upload texture data. */
 
	for (int i = 0; i < (sprite->type == SpriteType::Font ? 1 : ZOOM_LVL_END); i++) {
 
	for (int i = 0; i < (sprite[ZOOM_LVL_NORMAL].type == SpriteType::Font ? 1 : ZOOM_LVL_END); i++) {
 
		gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
 
	}
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 
	dest_sprite->height = sprite[ZOOM_LVL_NORMAL].height;
 
	dest_sprite->width  = sprite[ZOOM_LVL_NORMAL].width;
 
	dest_sprite->x_offs = sprite[ZOOM_LVL_NORMAL].x_offs;
 
	dest_sprite->y_offs = sprite[ZOOM_LVL_NORMAL].y_offs;
 

	
 
	return dest_sprite;
 
}
src/video/opengl.h
Show inline comments
 
@@ -109,7 +109,7 @@ public:
 

	
 
	bool Is32BppSupported() override { return true; }
 
	uint GetSpriteAlignment() override { return 1u << (ZOOM_LVL_END - 1); }
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
 
};
 

	
 

	
0 comments (0 inline, 0 general)