summaryrefslogtreecommitdiff
path: root/src/map_func.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-04-18 14:56:05 +0000
committerfrosch <frosch@openttd.org>2010-04-18 14:56:05 +0000
commit2e90f7f8b975d380c3d544995ef6db9d6c8a86d8 (patch)
tree90fb0852bd31229b016ca998a8e6c0ce44d699dd /src/map_func.h
parent2330851d1dc0650335bc73ec4cfd010f08c55742 (diff)
downloadopenttd-2e90f7f8b975d380c3d544995ef6db9d6c8a86d8.tar.xz
(svn r19670) -Codechange: Add CeilDiv() and RoundDiv() to simplify integer divisions with rounding.
Diffstat (limited to 'src/map_func.h')
-rw-r--r--src/map_func.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/map_func.h b/src/map_func.h
index 5acabc11d..6711677c1 100644
--- a/src/map_func.h
+++ b/src/map_func.h
@@ -12,6 +12,7 @@
#ifndef MAP_FUNC_H
#define MAP_FUNC_H
+#include "core/math_func.hpp"
#include "tile_type.h"
#include "map_type.h"
#include "direction_func.h"
@@ -126,9 +127,8 @@ static inline uint MapMaxY()
static inline uint ScaleByMapSize(uint n)
{
/* Subtract 12 from shift in order to prevent integer overflow
- * for large values of n. It's safe since the min mapsize is 64x64.
- * Add (1<<4)-1 to round upwards. */
- return ((n << (MapLogX() + MapLogY() - 12)) + (1 << 4) - 1) >> 4;
+ * for large values of n. It's safe since the min mapsize is 64x64. */
+ return CeilDiv(n << (MapLogX() + MapLogY() - 12), 1 << 4);
}
@@ -142,9 +142,8 @@ static inline uint ScaleByMapSize1D(uint n)
{
/* Normal circumference for the X+Y is 256+256 = 1<<9
* Note, not actually taking the full circumference into account,
- * just half of it.
- * (1<<9) - 1 is there to scale upwards. */
- return ((n << MapLogX()) + (n << MapLogY()) + (1 << 9) - 1) >> 9;
+ * just half of it. */
+ return CeilDiv((n << MapLogX()) + (n << MapLogY()), 1 << 9);
}
/**