(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
authorskidd13
Mon, 19 Nov 2007 18:58:04 +0000
changeset 7923 91982bd3c549
parent 7922 a7e266f966d9
child 7924 7ef93d919eba
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
src/aircraft_cmd.cpp
src/graph_gui.cpp
src/helpers.hpp
src/macros.h
src/roadveh_cmd.cpp
src/tgp.cpp
src/train_cmd.cpp
src/tree_cmd.cpp
src/tunnelbridge_cmd.cpp
src/vehicle.cpp
src/viewport.cpp
--- a/src/aircraft_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/aircraft_cmd.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -1112,7 +1112,7 @@
 	}
 
 	/* Get distance from destination pos to current pos. */
-	uint dist = myabs(x + amd->x - v->x_pos) +  myabs(y + amd->y - v->y_pos);
+	uint dist = abs(x + amd->x - v->x_pos) +  abs(y + amd->y - v->y_pos);
 
 	/* Need exact position? */
 	if (!(amd->flag & AMED_EXACTPOS) && dist <= (amd->flag & AMED_SLOWTURN ? 8U : 4U)) return true;
--- a/src/graph_gui.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/graph_gui.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -139,7 +139,7 @@
 					/* For now, if the graph has negative values the scaling is
 					 * symmetrical about the x axis, so take the absolute value
 					 * of each data point. */
-					highest_value = max(highest_value, myabs(datapoint));
+					highest_value = max(highest_value, abs(datapoint));
 				}
 			}
 		}
--- a/src/helpers.hpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/helpers.hpp	Mon Nov 19 18:58:04 2007 +0000
@@ -39,8 +39,6 @@
 }
 
 
-/** returns the absolute value of (scalar) variable. @note assumes variable to be signed */
-template <typename T> static inline T myabs(T a) { return a < (T)0 ? -a : a; }
 /** returns the (absolute) difference between two (scalar) variables */
 template <typename T> static inline T delta(T a, T b) { return a < b ? b - a : a - b; }
 
@@ -198,7 +196,7 @@
 	 */
 	FORCEINLINE OverflowSafeInt& operator += (const OverflowSafeInt& other)
 	{
-		if ((T_MAX - myabs(other.m_value)) < myabs(this->m_value) &&
+		if ((T_MAX - abs(other.m_value)) < abs(this->m_value) &&
 				(this->m_value < 0) == (other.m_value < 0)) {
 			this->m_value = (this->m_value < 0) ? T_MIN : T_MAX ;
 		} else {
@@ -229,7 +227,7 @@
 	 */
 	FORCEINLINE OverflowSafeInt& operator *= (const int factor)
 	{
-		if (factor != 0 && (T_MAX / myabs(factor)) < myabs(this->m_value)) {
+		if (factor != 0 && (T_MAX / abs(factor)) < abs(this->m_value)) {
 			 this->m_value = ((this->m_value < 0) == (factor < 0)) ? T_MAX : T_MIN ;
 		} else {
 			this->m_value *= factor ;
--- a/src/macros.h	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/macros.h	Mon Nov 19 18:58:04 2007 +0000
@@ -79,6 +79,10 @@
 #undef max
 #endif
 
+#ifdef abs
+#undef abs
+#endif
+
 /**
  * Returns the maximum of two values.
  *
@@ -138,6 +142,18 @@
 }
 
 /**
+ * Returns the absolute value of (scalar) variable.
+ *
+ * @note assumes variable to be signed
+ * @param a The value we want to unsign
+ * @return The unsigned value
+ */
+template <typename T> static inline T abs(T a)
+{
+	return (a < (T)0) ? -a : a;
+}
+
+/**
  * Clamp an integer between an interval.
  *
  * This function returns a value which is between the given interval of
@@ -519,8 +535,6 @@
 	for (_i = 0; _b != 0; _i++, _b >>= 1) \
 		if (_b & 1)
 
-#define abs myabs
-
 
 static inline uint16 ReadLE16Aligned(const void* x)
 {
--- a/src/roadveh_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/roadveh_cmd.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -671,9 +671,9 @@
 
 	return
 		v->type == VEH_TRAIN &&
-		myabs(v->z_pos - u->z_pos) <= 6 &&
-		myabs(v->x_pos - u->x_pos) <= 4 &&
-		myabs(v->y_pos - u->y_pos) <= 4 ?
+		abs(v->z_pos - u->z_pos) <= 6 &&
+		abs(v->x_pos - u->x_pos) <= 4 &&
+		abs(v->y_pos - u->y_pos) <= 4 ?
 			v : NULL;
 }
 
@@ -870,7 +870,7 @@
 	return
 		v->type == VEH_ROAD &&
 		!v->IsInDepot() &&
-		myabs(v->z_pos - rvf->veh->z_pos) < 6 &&
+		abs(v->z_pos - rvf->veh->z_pos) < 6 &&
 		v->direction == rvf->dir &&
 		rvf->veh->First() != v->First() &&
 		(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) &&
--- a/src/tgp.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/tgp.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -540,7 +540,7 @@
 	/* Lower to sea level */
 	for (y = 0; y <= _height_map.size_y; y++) {
 		/* Top right */
-		max_x = myabs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
+		max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
 		max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
 		if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
 		for (x = 0; x < max_x; x++) {
@@ -548,7 +548,7 @@
 		}
 
 		/* Bottom left */
-		max_x = myabs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45,  67) + 0.75) * 8);
+		max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45,  67) + 0.75) * 8);
 		max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x);
 		if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
 		for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) {
@@ -559,7 +559,7 @@
 	/* Lower to sea level */
 	for (x = 0; x <= _height_map.size_x; x++) {
 		/* Top left */
-		max_y = myabs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
+		max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
 		max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
 		if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
 		for (y = 0; y < max_y; y++) {
@@ -568,7 +568,7 @@
 
 
 		/* Bottom right */
-		max_y = myabs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
+		max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
 		max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y);
 		if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
 		for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) {
--- a/src/train_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/train_cmd.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -2726,9 +2726,9 @@
 			v != tcc->v_skip &&
 			v->type == VEH_TRAIN &&
 			v->u.rail.track != TRACK_BIT_DEPOT &&
-			myabs(v->z_pos - tcc->v->z_pos) < 6 &&
-			myabs(v->x_pos - tcc->v->x_pos) < 6 &&
-			myabs(v->y_pos - tcc->v->y_pos) < 6 ) {
+			abs(v->z_pos - tcc->v->z_pos) < 6 &&
+			abs(v->x_pos - tcc->v->x_pos) < 6 &&
+			abs(v->y_pos - tcc->v->y_pos) < 6 ) {
 
 		Vehicle *coll = v->First();
 
--- a/src/tree_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/tree_cmd.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -109,7 +109,7 @@
 		uint32 r = Random();
 		int x = GB(r, 0, 5) - 16;
 		int y = GB(r, 8, 5) - 16;
-		uint dist = myabs(x) + myabs(y);
+		uint dist = abs(x) + abs(y);
 		TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
 
 		if (dist <= 13 &&
@@ -155,7 +155,7 @@
 		TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
 
 		/* Keep in range of the existing tree */
-		if (myabs(x) + myabs(y) > 16) continue;
+		if (abs(x) + abs(y) > 16) continue;
 
 		/* Clear tile, no farm-tiles or rocks */
 		if (!IsTileType(cur_tile, MP_CLEAR) ||
--- a/src/tunnelbridge_cmd.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -1396,7 +1396,7 @@
 {
 	int z = GetSlopeZ(x, y) - v->z_pos;
 
-	if (myabs(z) > 2) return VETSB_CANNOT_ENTER;
+	if (abs(z) > 2) return VETSB_CANNOT_ENTER;
 
 	if (IsTunnel(tile)) {
 		byte fc;
--- a/src/vehicle.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/vehicle.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -1385,8 +1385,8 @@
 				y >= v->top_coord && y <= v->bottom_coord) {
 
 			dist = max(
-				myabs( ((v->left_coord + v->right_coord)>>1) - x ),
-				myabs( ((v->top_coord + v->bottom_coord)>>1) - y )
+				abs( ((v->left_coord + v->right_coord)>>1) - x ),
+				abs( ((v->top_coord + v->bottom_coord)>>1) - y )
 			);
 
 			if (dist < best_dist) {
--- a/src/viewport.cpp	Mon Nov 19 18:38:10 2007 +0000
+++ b/src/viewport.cpp	Mon Nov 19 18:58:04 2007 +0000
@@ -2522,8 +2522,8 @@
 
 	int dx = thd->selstart.x - (thd->selend.x & ~0xF);
 	int dy = thd->selstart.y - (thd->selend.y & ~0xF);
-	w = myabs(dx) + 16;
-	h = myabs(dy) + 16;
+	w = abs(dx) + 16;
+	h = abs(dy) + 16;
 
 	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
 		if (method == VPM_RAILDIRS) {
@@ -2678,7 +2678,7 @@
 
 	switch (method) {
 		case VPM_X_OR_Y: /* drag in X or Y direction */
-			if (myabs(sy - y) < myabs(sx - x)) {
+			if (abs(sy - y) < abs(sx - x)) {
 				y = sy;
 				style = HT_DIR_X;
 			} else {