Changeset - r7923:a6f3bc7003dc
[Not reviewed]
master
0 11 0
skidd13 - 17 years ago 2007-11-19 18:58:04
skidd13@openttd.org
(svn r11476) -Codechange: rename the function myabs to abs to get rid of an unneeded define
11 files changed with 39 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1112,7 +1112,7 @@ static bool AircraftController(Vehicle *
 
	}
 

	
 
	/* 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;
src/graph_gui.cpp
Show inline comments
 
@@ -139,7 +139,7 @@ static void DrawGraph(const GraphDrawer 
 
					/* 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));
 
				}
 
			}
 
		}
src/helpers.hpp
Show inline comments
 
@@ -39,8 +39,6 @@ template<typename T> void Swap(T& a, T& 
 
}
 

	
 

	
 
/** 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 ;
src/macros.h
Show inline comments
 
@@ -79,6 +79,10 @@ template<typename T, typename U> static 
 
#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, co
 
}
 

	
 
/**
 
 * 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 
 
	for (_i = 0; _b != 0; _i++, _b >>= 1) \
 
		if (_b & 1)
 

	
 
#define abs myabs
 

	
 

	
 
static inline uint16 ReadLE16Aligned(const void* x)
 
{
src/roadveh_cmd.cpp
Show inline comments
 
@@ -671,9 +671,9 @@ static void* EnumCheckRoadVehCrashTrain(
 

	
 
	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(Vehic
 
	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)) &&
src/tgp.cpp
Show inline comments
 
@@ -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--) {
src/train_cmd.cpp
Show inline comments
 
@@ -2726,9 +2726,9 @@ static void *FindTrainCollideEnum(Vehicl
 
			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();
 

	
src/tree_cmd.cpp
Show inline comments
 
@@ -109,7 +109,7 @@ static void DoPlaceMoreTrees(TileIndex t
 
		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 til
 
		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) ||
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1396,7 +1396,7 @@ static uint32 VehicleEnter_TunnelBridge(
 
{
 
	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;
src/vehicle.cpp
Show inline comments
 
@@ -1385,8 +1385,8 @@ Vehicle *CheckClickOnVehicle(const ViewP
 
				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) {
src/viewport.cpp
Show inline comments
 
@@ -2522,8 +2522,8 @@ static void CalcRaildirsDrawstyle(TileHi
 

	
 
	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 
 

	
 
	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 {
0 comments (0 inline, 0 general)