mirror of https://github.com/OpenTTD/OpenTTD
(svn r13551) -Codechange: store offsets to different zoom levels in a distinguished struct instead in the data stream for 8bpp-optimized
parent
6d4590ec7c
commit
dedb0033b3
|
@ -14,10 +14,11 @@ static FBlitter_8bppOptimized iFBlitter_8bppOptimized;
|
||||||
void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
||||||
{
|
{
|
||||||
/* Find the offset of this zoom-level */
|
/* Find the offset of this zoom-level */
|
||||||
uint offset = ((const uint8 *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2] | ((const byte *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2 + 1] << 8;
|
const SpriteData *sprite_src = (const SpriteData *)bp->sprite;
|
||||||
|
uint offset = sprite_src->offset[zoom];
|
||||||
|
|
||||||
/* Find where to start reading in the source sprite */
|
/* Find where to start reading in the source sprite */
|
||||||
const uint8 *src = (const uint8 *)bp->sprite + offset;
|
const uint8 *src = sprite_src->data + offset;
|
||||||
uint8 *dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
|
uint8 *dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
|
||||||
|
|
||||||
/* Skip over the top lines in the source image */
|
/* Skip over the top lines in the source image */
|
||||||
|
@ -101,7 +102,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
|
||||||
Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
|
Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
|
||||||
{
|
{
|
||||||
/* Make memory for all zoom-levels */
|
/* Make memory for all zoom-levels */
|
||||||
uint memory = (int)(ZOOM_LVL_END - ZOOM_LVL_BEGIN) * sizeof(uint16);
|
uint memory = sizeof(SpriteData);
|
||||||
|
|
||||||
for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
|
for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
|
||||||
memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
|
memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i);
|
||||||
|
@ -109,15 +110,14 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All
|
||||||
|
|
||||||
/* We have no idea how much memory we really need, so just guess something */
|
/* We have no idea how much memory we really need, so just guess something */
|
||||||
memory *= 5;
|
memory *= 5;
|
||||||
byte *temp_dst = MallocT<byte>(memory);
|
SpriteData *temp_dst = (SpriteData *)MallocT<byte>(memory);
|
||||||
byte *dst = &temp_dst[(ZOOM_LVL_END - ZOOM_LVL_BEGIN) * 2];
|
byte *dst = temp_dst->data;
|
||||||
|
|
||||||
/* Make the sprites per zoom-level */
|
/* Make the sprites per zoom-level */
|
||||||
for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
|
for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) {
|
||||||
/* Store the index table */
|
/* Store the index table */
|
||||||
uint index = dst - temp_dst;
|
uint offset = dst - temp_dst->data;
|
||||||
temp_dst[i * 2] = index & 0xFF;
|
temp_dst->offset[i] = offset;
|
||||||
temp_dst[i * 2 + 1] = (index >> 8) & 0xFF;
|
|
||||||
|
|
||||||
/* cache values, because compiler can't cache it */
|
/* cache values, because compiler can't cache it */
|
||||||
int scaled_height = UnScaleByZoom(sprite->height, i);
|
int scaled_height = UnScaleByZoom(sprite->height, i);
|
||||||
|
@ -179,7 +179,7 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint size = dst - temp_dst;
|
uint size = dst - (byte *)temp_dst;
|
||||||
|
|
||||||
/* Safety check, to make sure we guessed the size correctly */
|
/* Safety check, to make sure we guessed the size correctly */
|
||||||
assert(size < memory);
|
assert(size < memory);
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
|
|
||||||
class Blitter_8bppOptimized : public Blitter_8bppBase {
|
class Blitter_8bppOptimized : public Blitter_8bppBase {
|
||||||
public:
|
public:
|
||||||
|
struct SpriteData {
|
||||||
|
uint32 offset[ZOOM_LVL_COUNT]; ///< offsets (from .data) to streams for different zoom levels
|
||||||
|
byte data[VARARRAY_SIZE]; ///< data, all zoomlevels
|
||||||
|
};
|
||||||
|
|
||||||
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
|
||||||
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
|
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ static void StartSound(uint sound, int panning, uint volume)
|
||||||
|
|
||||||
|
|
||||||
static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87};
|
static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87};
|
||||||
assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_END - ZOOM_LVL_BEGIN);
|
assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_COUNT);
|
||||||
|
|
||||||
static const byte _sound_base_vol[] = {
|
static const byte _sound_base_vol[] = {
|
||||||
128, 90, 128, 128, 128, 128, 128, 128,
|
128, 90, 128, 128, 128, 128, 128, 128,
|
||||||
|
|
|
@ -16,6 +16,9 @@ enum ZoomLevel {
|
||||||
ZOOM_LVL_OUT_8X,
|
ZOOM_LVL_OUT_8X,
|
||||||
ZOOM_LVL_END,
|
ZOOM_LVL_END,
|
||||||
|
|
||||||
|
/* Number of zoom levels */
|
||||||
|
ZOOM_LVL_COUNT = ZOOM_LVL_END - ZOOM_LVL_BEGIN,
|
||||||
|
|
||||||
/* Here we define in which zoom viewports are */
|
/* Here we define in which zoom viewports are */
|
||||||
ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL,
|
ZOOM_LVL_VIEWPORT = ZOOM_LVL_NORMAL,
|
||||||
ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL,
|
ZOOM_LVL_NEWS = ZOOM_LVL_NORMAL,
|
||||||
|
|
Loading…
Reference in New Issue