summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2019-04-21 20:15:55 +0100
committerPeterN <peter@fuzzle.org>2019-04-29 17:40:22 +0100
commit96a47877104d99e117b9fd97e43908f9e9567ec5 (patch)
tree2d7bec001304967a69796fd3975024662ffca330
parentaa220b2375efecf831ead0794e6de7b621e3c7a2 (diff)
downloadopenttd-96a47877104d99e117b9fd97e43908f9e9567ec5.tar.xz
Codechange: Set ZoomLevel's base type to byte instead of using ZoomLevelByte
-rw-r--r--src/gfx.cpp4
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/saveload/misc_sl.cpp2
-rw-r--r--src/saveload/saveload_internal.h2
-rw-r--r--src/settings_type.h4
-rw-r--r--src/viewport.cpp2
-rw-r--r--src/zoom_func.h4
-rw-r--r--src/zoom_type.h14
8 files changed, 14 insertions, 20 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 97ae0f510..5165fe01c 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -58,8 +58,8 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode,
static ReusableBuffer<uint8> _cursor_backup;
-ZoomLevelByte _gui_zoom; ///< GUI Zoom level
-ZoomLevelByte _font_zoom; ///< Font Zoom level
+ZoomLevel _gui_zoom; ///< GUI Zoom level
+ZoomLevel _font_zoom; ///< Font Zoom level
/**
* The rect for repaint.
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 8d9b0ffa6..b5095c521 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -2834,7 +2834,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_165)) {
/* Adjust zoom level to account for new levels */
- _saved_scrollpos_zoom = _saved_scrollpos_zoom + ZOOM_LVL_SHIFT;
+ _saved_scrollpos_zoom = static_cast<ZoomLevel>(_saved_scrollpos_zoom + ZOOM_LVL_SHIFT);
_saved_scrollpos_x *= ZOOM_LVL_BASE;
_saved_scrollpos_y *= ZOOM_LVL_BASE;
}
diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp
index f0b130952..4a9b05a46 100644
--- a/src/saveload/misc_sl.cpp
+++ b/src/saveload/misc_sl.cpp
@@ -30,7 +30,7 @@ extern byte _trees_tick_ctr;
/* Keep track of current game position */
int _saved_scrollpos_x;
int _saved_scrollpos_y;
-ZoomLevelByte _saved_scrollpos_zoom;
+ZoomLevel _saved_scrollpos_zoom;
void SaveViewportBeforeSaveGame()
{
diff --git a/src/saveload/saveload_internal.h b/src/saveload/saveload_internal.h
index 74e5b9936..e7a9e7bf5 100644
--- a/src/saveload/saveload_internal.h
+++ b/src/saveload/saveload_internal.h
@@ -49,7 +49,7 @@ void CopyTempEngineData();
extern int32 _saved_scrollpos_x;
extern int32 _saved_scrollpos_y;
-extern ZoomLevelByte _saved_scrollpos_zoom;
+extern ZoomLevel _saved_scrollpos_zoom;
extern SavegameType _savegame_type;
extern uint32 _ttdp_version;
diff --git a/src/settings_type.h b/src/settings_type.h
index 245905897..d164be431 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -107,8 +107,8 @@ struct GUISettings {
uint8 statusbar_pos; ///< position of statusbar, 0=left, 1=center, 2=right
uint8 window_snap_radius; ///< windows snap at each other if closer than this
uint8 window_soft_limit; ///< soft limit of maximum number of non-stickied non-vital windows (0 = no limit)
- ZoomLevelByte zoom_min; ///< minimum zoom out level
- ZoomLevelByte zoom_max; ///< maximum zoom out level
+ ZoomLevel zoom_min; ///< minimum zoom out level
+ ZoomLevel zoom_max; ///< maximum zoom out level
bool disable_unsuitable_building; ///< disable infrastructure building when no suitable vehicles are available
byte autosave; ///< how often should we do autosaves?
bool threaded_saves; ///< should we do threaded saves?
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 8ec315b16..8a1319072 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1692,7 +1692,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
*/
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom)
{
- if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE) {
+ if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > (int)(180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE)) {
if ((bottom - top) > (right - left)) {
int t = (top + bottom) >> 1;
ViewportDrawChk(vp, left, top, right, t);
diff --git a/src/zoom_func.h b/src/zoom_func.h
index 0e8fa8c9e..dff7322a0 100644
--- a/src/zoom_func.h
+++ b/src/zoom_func.h
@@ -23,7 +23,6 @@
*/
static inline int ScaleByZoom(int value, ZoomLevel zoom)
{
- assert(zoom >= 0);
return value << zoom;
}
@@ -36,7 +35,6 @@ static inline int ScaleByZoom(int value, ZoomLevel zoom)
*/
static inline int UnScaleByZoom(int value, ZoomLevel zoom)
{
- assert(zoom >= 0);
return (value + (1 << zoom) - 1) >> zoom;
}
@@ -48,7 +46,6 @@ static inline int UnScaleByZoom(int value, ZoomLevel zoom)
*/
static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
{
- assert(zoom >= 0);
return value << zoom;
}
@@ -60,7 +57,6 @@ static inline int ScaleByZoomLower(int value, ZoomLevel zoom)
*/
static inline int UnScaleByZoomLower(int value, ZoomLevel zoom)
{
- assert(zoom >= 0);
return value >> zoom;
}
diff --git a/src/zoom_type.h b/src/zoom_type.h
index ea8302761..47a725df2 100644
--- a/src/zoom_type.h
+++ b/src/zoom_type.h
@@ -14,11 +14,11 @@
#include "core/enum_type.hpp"
-static int const ZOOM_LVL_SHIFT = 2;
-static int const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT;
+static uint const ZOOM_LVL_SHIFT = 2;
+static uint const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT;
/** All zoom levels we know. */
-enum ZoomLevel {
+enum ZoomLevel : byte {
/* Our possible zoom-levels */
ZOOM_LVL_BEGIN = 0, ///< Begin for iteration.
ZOOM_LVL_NORMAL = 0, ///< The normal zoom level.
@@ -46,14 +46,12 @@ enum ZoomLevel {
ZOOM_LVL_MIN = ZOOM_LVL_NORMAL, ///< Minimum zoom level.
ZOOM_LVL_MAX = ZOOM_LVL_OUT_32X, ///< Maximum zoom level.
+
};
DECLARE_POSTFIX_INCREMENT(ZoomLevel)
-/** Type for storing the zoom level in a byte. */
-typedef SimpleTinyEnumT<ZoomLevel, byte> ZoomLevelByte;
-
-extern ZoomLevelByte _gui_zoom;
-extern ZoomLevelByte _font_zoom;
+extern ZoomLevel _gui_zoom;
+extern ZoomLevel _font_zoom;
#define ZOOM_LVL_GUI (_gui_zoom)
#define ZOOM_LVL_FONT (_font_zoom)