(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define

This commit is contained in:
skidd13 2007-11-19 18:58:04 +00:00
parent 8be526e499
commit 50bfe1a19d
11 changed files with 39 additions and 27 deletions

View File

@ -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;

View File

@ -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));
}
}
}

View File

@ -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 ;

View File

@ -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.
*
@ -137,6 +141,18 @@ static inline uint minu(const uint a, const uint b)
return a < b ? a : 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.
*
@ -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)
{

View File

@ -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)) &&

View File

@ -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--) {

View File

@ -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();

View File

@ -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) ||

View File

@ -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;

View File

@ -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) {

View File

@ -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 {