diff options
author | smatz <smatz@openttd.org> | 2007-12-17 22:04:07 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2007-12-17 22:04:07 +0000 |
commit | bda9d4a23633c4ebb6ad18c29218deaf1a92d55d (patch) | |
tree | e1686070db2bce48c4953e4bbef6a196640ae495 | |
parent | 61dcdbf0e0bbbe231b7adbd0a82da8d9e16dbb88 (diff) | |
download | openttd-bda9d4a23633c4ebb6ad18c29218deaf1a92d55d.tar.xz |
(svn r11656) -Codechange: add ZOOM_LVL_BEGIN and postfix operators so ZoomLevel can be used in some iterations
-rw-r--r-- | src/blitter/8bpp_optimized.cpp | 18 | ||||
-rw-r--r-- | src/main_gui.cpp | 4 | ||||
-rw-r--r-- | src/openttd.cpp | 2 | ||||
-rw-r--r-- | src/sound.cpp | 4 | ||||
-rw-r--r-- | src/zoom.hpp | 13 |
5 files changed, 23 insertions, 18 deletions
diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp index 8287035e8..f6013fac2 100644 --- a/src/blitter/8bpp_optimized.cpp +++ b/src/blitter/8bpp_optimized.cpp @@ -17,7 +17,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z uint offset = 0; /* Find the offset of this zoom-level */ - offset = ((const uint8 *)bp->sprite)[(int)zoom * 2] | ((const byte *)bp->sprite)[(int)zoom * 2 + 1] << 8; + offset = ((const uint8 *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2] | ((const byte *)bp->sprite)[(int)(zoom - ZOOM_LVL_BEGIN) * 2 + 1] << 8; /* Find where to start reading in the source sprite */ src = (const uint8 *)bp->sprite + offset; @@ -110,9 +110,9 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All uint index = 0; /* Make memory for all zoom-levels */ - memory += (int)ZOOM_LVL_END * sizeof(uint16); - for (int i = 0; i < (int)ZOOM_LVL_END; i++) { - memory += UnScaleByZoom(sprite->height, (ZoomLevel)i) * UnScaleByZoom(sprite->width, (ZoomLevel)i); + memory += (int)(ZOOM_LVL_END - ZOOM_LVL_BEGIN) * sizeof(uint16); + for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) { + memory += UnScaleByZoom(sprite->height, i) * UnScaleByZoom(sprite->width, i); index += 2; } @@ -121,7 +121,7 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All temp_dst = MallocT<byte>(memory); /* Make the sprites per zoom-level */ - for (int i = 0; i < (int)ZOOM_LVL_END; i++) { + for (ZoomLevel i = ZOOM_LVL_BEGIN; i < ZOOM_LVL_END; i++) { /* Store the scaled image */ const SpriteLoader::CommonPixel *src; @@ -131,19 +131,19 @@ Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::All byte *dst = &temp_dst[index]; - for (int y = 0; y < UnScaleByZoom(sprite->height, (ZoomLevel)i); y++) { + for (int y = 0; y < UnScaleByZoom(sprite->height, i); y++) { uint trans = 0; uint pixels = 0; uint last_color = 0; uint count_index = 0; uint rx = 0; - src = &sprite->data[ScaleByZoom(y, (ZoomLevel)i) * sprite->width]; + src = &sprite->data[ScaleByZoom(y, i) * sprite->width]; - for (int x = 0; x < UnScaleByZoom(sprite->width, (ZoomLevel)i); x++) { + for (int x = 0; x < UnScaleByZoom(sprite->width, i); x++) { uint color = 0; /* Get the color keeping in mind the zoom-level */ - for (int j = 0; j < ScaleByZoom(1, (ZoomLevel)i); j++) { + for (int j = 0; j < ScaleByZoom(1, i); j++) { if (src->m != 0) color = src->m; src++; rx++; diff --git a/src/main_gui.cpp b/src/main_gui.cpp index d85ec6369..66d854060 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -872,7 +872,7 @@ bool DoZoomInOutWindow(int how, Window *w) switch (how) { case ZOOM_IN: if (vp->zoom == ZOOM_LVL_MIN) return false; - vp->zoom = (ZoomLevel)((byte)vp->zoom - 1); + vp->zoom = (ZoomLevel)((int)vp->zoom - 1); vp->virtual_width >>= 1; vp->virtual_height >>= 1; @@ -883,7 +883,7 @@ bool DoZoomInOutWindow(int how, Window *w) break; case ZOOM_OUT: if (vp->zoom == ZOOM_LVL_MAX) return false; - vp->zoom = (ZoomLevel)((byte)vp->zoom + 1); + vp->zoom = (ZoomLevel)((int)vp->zoom + 1); WP(w, vp_d).scrollpos_x -= vp->virtual_width >> 1; WP(w, vp_d).scrollpos_y -= vp->virtual_height >> 1; diff --git a/src/openttd.cpp b/src/openttd.cpp index 2c0f1a0ec..af80a9dd1 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1291,7 +1291,7 @@ static bool InitializeWindowsAndCaches() WP(w, vp_d).dest_scrollpos_y = _saved_scrollpos_y; ViewPort *vp = w->viewport; - vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); + vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX); vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); diff --git a/src/sound.cpp b/src/sound.cpp index 5a3cb7638..312484c42 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -157,7 +157,7 @@ static void StartSound(uint sound, int panning, uint volume) static const byte _vol_factor_by_zoom[] = {255, 190, 134, 87}; -assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_END); +assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_END - ZOOM_LVL_BEGIN); static const byte _sound_base_vol[] = { 128, 90, 128, 128, 128, 128, 128, 128, @@ -216,7 +216,7 @@ static void SndPlayScreenCoordFx(SoundFx sound, int x, int y) StartSound( sound, left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, - (GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15 + (GetSound(sound)->volume * msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) >> 15 ); return; } diff --git a/src/zoom.hpp b/src/zoom.hpp index f924b362f..dea064196 100644 --- a/src/zoom.hpp +++ b/src/zoom.hpp @@ -5,8 +5,11 @@ #ifndef ZOOM_HPP #define ZOOM_HPP +#include "helpers.hpp" + enum ZoomLevel { /* Our possible zoom-levels */ + ZOOM_LVL_BEGIN = 0, ZOOM_LVL_NORMAL = 0, ZOOM_LVL_OUT_2X, ZOOM_LVL_OUT_4X, @@ -32,6 +35,8 @@ enum ZoomLevel { extern ZoomLevel _saved_scrollpos_zoom; +DECLARE_POSTFIX_INCREMENT(ZoomLevel) + /** * Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) * When shifting right, value is rounded up @@ -42,7 +47,7 @@ extern ZoomLevel _saved_scrollpos_zoom; static inline int ScaleByZoom(int value, ZoomLevel zoom) { if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; + int izoom = zoom - ZOOM_LVL_NORMAL; return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : (value + (1 << -izoom) - 1) >> -izoom; } @@ -56,7 +61,7 @@ static inline int ScaleByZoom(int value, ZoomLevel zoom) static inline int UnScaleByZoom(int value, ZoomLevel zoom) { if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; + int izoom = zoom - ZOOM_LVL_NORMAL; return (zoom > ZOOM_LVL_NORMAL) ? (value + (1 << izoom) - 1) >> izoom : value << -izoom; } @@ -69,7 +74,7 @@ static inline int UnScaleByZoom(int value, ZoomLevel zoom) static inline int ScaleByZoomLower(int value, ZoomLevel zoom) { if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; + int izoom = zoom - ZOOM_LVL_NORMAL; return (zoom > ZOOM_LVL_NORMAL) ? value << izoom : value >> -izoom; } @@ -82,7 +87,7 @@ static inline int ScaleByZoomLower(int value, ZoomLevel zoom) static inline int UnScaleByZoomLower(int value, ZoomLevel zoom) { if (zoom == ZOOM_LVL_NORMAL) return value; - int izoom = (int)zoom - (int)ZOOM_LVL_NORMAL; + int izoom = zoom - ZOOM_LVL_NORMAL; return (zoom > ZOOM_LVL_NORMAL) ? value >> izoom : value << -izoom; } |