mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-19 20:49:11 +00:00
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.
This commit is contained in:
@@ -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"; }
|
||||
|
@@ -272,7 +272,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
|
||||
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 *Blitter_32bppOptimized::EncodeInternal(const
|
||||
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 *Blitter_32bppOptimized::EncodeInternal(const
|
||||
|
||||
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 *Blitter_32bppOptimized::EncodeInternal(const
|
||||
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);
|
||||
}
|
||||
|
@@ -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). */
|
||||
|
@@ -109,20 +109,20 @@ void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height
|
||||
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;
|
||||
|
@@ -26,7 +26,7 @@ class Blitter_32bppSimple : public Blitter_32bppBase {
|
||||
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"; }
|
||||
};
|
||||
|
@@ -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(const SpriteLoader::Sprite *sprite, Alloca
|
||||
*/
|
||||
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(const SpriteLoader::Sprite *sprite, Alloca
|
||||
}
|
||||
|
||||
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. */
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -377,7 +377,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -119,7 +119,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
|
||||
}
|
||||
}
|
||||
|
||||
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(const SpriteLoader::Sprite *sprite, Alloca
|
||||
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(const SpriteLoader::Sprite *sprite, Alloca
|
||||
/* 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;
|
||||
|
@@ -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"; }
|
||||
};
|
||||
|
@@ -60,19 +60,19 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@@ -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"; }
|
||||
};
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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 {};
|
||||
|
Reference in New Issue
Block a user