diff options
author | skidd13 <skidd13@openttd.org> | 2007-11-19 18:58:04 +0000 |
---|---|---|
committer | skidd13 <skidd13@openttd.org> | 2007-11-19 18:58:04 +0000 |
commit | f4a5c80d7193821bdfe9b3669e245b43c6feee3d (patch) | |
tree | 18ac24e0b26fa3cf7cb17962dde493f142f39a03 | |
parent | 98f66552beadfa14cf28cd126fc462a5abe3087b (diff) | |
download | openttd-f4a5c80d7193821bdfe9b3669e245b43c6feee3d.tar.xz |
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
-rw-r--r-- | src/aircraft_cmd.cpp | 2 | ||||
-rw-r--r-- | src/graph_gui.cpp | 2 | ||||
-rw-r--r-- | src/helpers.hpp | 6 | ||||
-rw-r--r-- | src/macros.h | 18 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 8 | ||||
-rw-r--r-- | src/tgp.cpp | 8 | ||||
-rw-r--r-- | src/train_cmd.cpp | 6 | ||||
-rw-r--r-- | src/tree_cmd.cpp | 4 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 2 | ||||
-rw-r--r-- | src/vehicle.cpp | 4 | ||||
-rw-r--r-- | src/viewport.cpp | 6 |
11 files changed, 39 insertions, 27 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 65d90fa47..72d13e0f4 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1112,7 +1112,7 @@ static bool AircraftController(Vehicle *v) } /* 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; diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index cfed85561..1e273a251 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -139,7 +139,7 @@ static void DrawGraph(const GraphDrawer *gw) /* 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)); } } } diff --git a/src/helpers.hpp b/src/helpers.hpp index 4163be4ac..b69f17ae9 100644 --- a/src/helpers.hpp +++ b/src/helpers.hpp @@ -39,8 +39,6 @@ template<typename T> void Swap(T& a, T& b) } -/** 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 @@ public: */ 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 @@ public: */ 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 ; diff --git a/src/macros.h b/src/macros.h index f42870f3c..e5f64c68f 100644 --- a/src/macros.h +++ b/src/macros.h @@ -79,6 +79,10 @@ template<typename T, typename U> static inline T AB(T& x, const uint8 s, const u #undef max #endif +#ifdef abs +#undef abs +#endif + /** * Returns the maximum of two values. * @@ -138,6 +142,18 @@ static inline uint minu(const uint a, const uint b) } /** + * 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 @@ static inline bool CHANCE16I(const uint a, const uint b, const uint32 r) for (_i = 0; _b != 0; _i++, _b >>= 1) \ if (_b & 1) -#define abs myabs - static inline uint16 ReadLE16Aligned(const void* x) { diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index d00c12e92..ce3ae239a 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -671,9 +671,9 @@ static void* EnumCheckRoadVehCrashTrain(Vehicle* v, void* data) 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 @@ static void* EnumCheckRoadVehClose(Vehicle *v, void* data) 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)) && diff --git a/src/tgp.cpp b/src/tgp.cpp index 9b66b3f3d..f856a51c6 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -540,7 +540,7 @@ static void HeightMapCoastLines() /* 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 @@ static void HeightMapCoastLines() } /* 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 @@ static void HeightMapCoastLines() /* 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 @@ static void HeightMapCoastLines() /* 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--) { diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 0e6400c7a..4489a0bea 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2726,9 +2726,9 @@ static void *FindTrainCollideEnum(Vehicle *v, void *data) 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(); diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index ae83a76ca..eba4403bd 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -109,7 +109,7 @@ static void DoPlaceMoreTrees(TileIndex tile) 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 @@ void PlaceTreeAtSameHeight(TileIndex tile, uint height) 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) || diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 1bd4322f5..ee995dbb1 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1396,7 +1396,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y { 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; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e486dd2ff..b91b232a9 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1385,8 +1385,8 @@ Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) 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) { diff --git a/src/viewport.cpp b/src/viewport.cpp index 68af110a8..775d44f32 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2522,8 +2522,8 @@ static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int meth 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 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method) 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 { |