Mercurial > hg > openttd
changeset 5601:ca6b459bf488 draft
(svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
author | celestar <celestar@openttd.org> |
---|---|
date | Thu, 11 Jan 2007 11:05:01 +0000 |
parents | 37c5d98c3fa6 |
children | 0727c102447e |
files | src/aircraft_cmd.cpp src/depot_gui.cpp src/disaster_cmd.cpp src/economy.cpp src/graph_gui.cpp src/industry_gui.cpp src/macros.h src/main_gui.cpp src/newgrf_engine.cpp src/newgrf_spritegroup.cpp src/settings.cpp src/settings_gui.cpp src/station.h src/station_cmd.cpp src/tgp.cpp src/train_cmd.cpp src/train_gui.cpp src/unmovable_cmd.cpp src/viewport.cpp |
diffstat | 19 files changed, 40 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1066,7 +1066,7 @@ if (curz > z) { z++; } else { - int t = max(1, dist - 4); + int t = max(1U, dist - 4); z -= ((z - curz) + t - 1) / t; if (z < curz) z = curz;
--- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -194,7 +194,8 @@ { Vehicle **vl = WP(w, depot_d).vehicle_list; TileIndex tile = w->window_number; - int x, y, i, hnum, max; + int x, y, i, maxval; + uint16 hnum; uint16 num = WP(w, depot_d).engine_count; /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */ @@ -218,7 +219,7 @@ hnum = 8; for (num = 0; num < WP(w, depot_d).engine_count; num++) { const Vehicle *v = vl[num]; - hnum = maxu(hnum, v->u.rail.cached_total_length); + hnum = max(hnum, v->u.rail.cached_total_length); } /* Always have 1 empty row, so people can change the setting of the train */ SetVScrollCount(w, WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count + 1); @@ -240,22 +241,22 @@ DrawWindowWidgets(w); num = w->vscroll.pos * boxes_in_each_row; - max = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row)); + maxval = min(WP(w, depot_d).engine_count, num + (rows_in_display * boxes_in_each_row)); - for (x = 2, y = 15; num < max; y += w->resize.step_height, x = 2) { // Draw the rows + for (x = 2, y = 15; num < maxval; y += w->resize.step_height, x = 2) { // Draw the rows byte i; - for (i = 0; i < boxes_in_each_row && num < max; i++, num++, x += w->resize.step_width) { + for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += w->resize.step_width) { /* Draw all vehicles in the current row */ const Vehicle *v = vl[num]; DrawVehicleInDepot(w, v, x, y); } } - max = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); + maxval = min(WP(w, depot_d).engine_count + WP(w, depot_d).wagon_count, (w->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); /* draw the train wagons, that do not have an engine in front */ - for (; num < max; num++, y += 14) { + for (; num < maxval; num++, y += 14) { const Vehicle *v = WP(w, depot_d).wagon_list[num - WP(w, depot_d).engine_count]; const Vehicle *u;
--- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -134,7 +134,7 @@ BeginVehicleMove(u); u->x_pos = x; - u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0) >> 3); + u->y_pos = y - 1 - (max(z - GetSlopeZ(safe_x, safe_y), 0U) >> 3); safe_y = clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE); u->z_pos = GetSlopeZ(safe_x, safe_y); u->direction = v->direction;
--- a/src/economy.cpp +++ b/src/economy.cpp @@ -85,7 +85,7 @@ value += p->money64 - p->current_loan; // add real money value - return max64(value, 1); + return max(value, 1LL); } // if update is set to true, the economy is updated with this score
--- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -119,7 +119,7 @@ col_ptr = row_ptr; do { if (*col_ptr != INVALID_VALUE) { - mx = max64(mx, *col_ptr); + mx = max((uint64)mx, *col_ptr); } } while (col_ptr++, --num_x); } @@ -306,7 +306,7 @@ { const Player* p; uint excludebits = _legend_excludebits; - int nums; + byte nums; int mo,yr; // Exclude the players which aren't valid
--- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -366,7 +366,7 @@ /* Clicked buttons, decrease or increase production */ if (x < 15) { if (isProductionMinimum(i, line)) return; - i->production_rate[line] = maxu(i->production_rate[line] / 2, 1); + i->production_rate[line] = max(i->production_rate[line] / 2, 1); } else { if (isProductionMaximum(i, line)) return; i->production_rate[line] = minu(i->production_rate[line] * 2, 255);
--- a/src/macros.h +++ b/src/macros.h @@ -20,13 +20,11 @@ #undef max #endif -static inline int max(int a, int b) { if (a >= b) return a; return b; } -static inline double dmax(double a, double b) { if (a >= b) return a; return b; } -static inline uint64 max64(uint64 a, uint64 b) { if (a >= b) return a; return b; } +template <typename T> T max(T a, T b) { return a >= b ? a : b; } + static inline int min(int a, int b) { if (a <= b) return a; return b; } static inline uint minu(uint a, uint b) { if (a <= b) return a; return b; } -static inline uint maxu(uint a, uint b) { if (a >= b) return a; return b; } static inline int clamp(int a, int min, int max)
--- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -1054,7 +1054,7 @@ static void CommonRaiseLowerBigLand(TileIndex tile, int mode) { int sizex, sizey; - byte h; + uint h; _generating_world = true; // used to create green terraformed land
--- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -832,7 +832,7 @@ } else if (v->cargo_count == 0 || totalsets == 2) { set = 0; } else { - set = v->cargo_count * (totalsets - 2) / max(1, v->cargo_cap) + 1; + set = v->cargo_count * (totalsets - 2) / max((uint16)1, v->cargo_cap) + 1; } return in_motion ? group->g.real.loaded[set] : group->g.real.loading[set];
--- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -114,8 +114,8 @@ switch (adjust->operation) { case DSGA_OP_ADD: return last_value + value; case DSGA_OP_SUB: return last_value - value; - case DSGA_OP_SMIN: return min(last_value, value); - case DSGA_OP_SMAX: return max(last_value, value); + case DSGA_OP_SMIN: return min((S)last_value, (S)value); + case DSGA_OP_SMAX: return max((S)last_value, (S)value); case DSGA_OP_UMIN: return min((U)last_value, (U)value); case DSGA_OP_UMAX: return max((U)last_value, (U)value); case DSGA_OP_SDIV: return last_value / value;
--- a/src/settings.cpp +++ b/src/settings.cpp @@ -234,7 +234,7 @@ uint pos; // add to comment if (ns > a) { - a = max(a, 128); + a = max(a, 128U); do a*=2; while (a < ns); ReallocT(&comment, comment_alloc = a); }
--- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -437,7 +437,7 @@ const GameSettingData *info; int x, y; uint btn, dis; - int val; + int16 val; // Don't allow clients to make any changes if (_networking && !_network_server) @@ -473,7 +473,8 @@ SETBIT(_difficulty_click_b, btn); } else { // Decrease button clicked - val = max(val - info->step, info->min); + val -= info->step; + val = max(val, info->min); SETBIT(_difficulty_click_a, btn); }
--- a/src/station.h +++ b/src/station.h @@ -119,7 +119,8 @@ HVOT_BUOY = 1 << 6 }; -enum { +typedef enum CatchmentAeras { + CA_NONE = 0, CA_BUS = 3, CA_TRUCK = 3, CA_AIR_OILPAD = 3, @@ -134,7 +135,7 @@ CA_AIR_HELIDEPOT = 4, CA_AIR_INTERCON = 10, CA_AIR_HELISTATION = 4, -}; +} CatchmentAera; void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -200,7 +200,7 @@ * radius that is available within the station */ static uint FindCatchmentRadius(const Station* st) { - uint ret = 0; + CatchmentAera ret = CA_NONE; if (st->bus_stops != NULL) ret = max(ret, CA_BUS); if (st->truck_stops != NULL) ret = max(ret, CA_TRUCK); @@ -2525,7 +2525,7 @@ if (rating <= 127 && waiting != 0) { uint32 r = Random(); if ( (uint)rating <= (r & 0x7F) ) { - waiting = max(waiting - ((r >> 8)&3) - 1, 0); + waiting = max(waiting - ((r >> 8)&3) - 1, 0U); waiting_changed = true; } }
--- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -536,7 +536,7 @@ 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 = dmax((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x); + 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++) { HeightMapXY(x, y) = 0; @@ -544,7 +544,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 = dmax((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x); + 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--) { HeightMapXY(x, y) = 0; @@ -555,7 +555,7 @@ 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 = dmax((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y); + 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++) { HeightMapXY(x, y) = 0; @@ -564,7 +564,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 = dmax((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y); + 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--) { HeightMapXY(x, y) = 0;
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -365,7 +365,7 @@ if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) { if (TrainShouldStop(v, v->tile)) { - uint station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction)); + int station_length = GetPlatformLength(v->tile, DirToDiagDir(v->direction)); int delta_v; max_speed = 120;
--- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -166,8 +166,8 @@ * Because of this, the return value have to be reversed as well and we return b - a instead of a - b. * Another thing is that both power and running costs should be doubled for multiheaded engines. * Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */ - int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1, rvi_a->power); - int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1, rvi_b->power); + int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power); + int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power); int r = vb - va; return _internal_sort_order ? -r : r;
--- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -234,13 +234,13 @@ // Top town building generates 10, so to make HQ interesting, the top // type makes 20. - ac[CT_PASSENGERS] = max(1, level); + ac[CT_PASSENGERS] = max(1U, level); // Top town building generates 4, HQ can make up to 8. The // proportion passengers:mail is different because such a huge // commercial building generates unusually high amount of mail // correspondence per physical visitor. - ac[CT_MAIL] = max(1, level / 2); + ac[CT_MAIL] = max(1U, level / 2); }
--- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2091,7 +2091,7 @@ assert(style_t < lengthof(heightdiff_line_by_dir) - 13); h0 = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t]))); ht = TileHeight(TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_line_by_dir[style_t + 1]))); - h0 = maxu(h0, ht); + h0 = max(h0, ht); /* Use lookup table for end-tile based on HighLightStyle direction * flip around side (lower/upper, left/right) based on distance */ @@ -2099,7 +2099,7 @@ assert(style_t < lengthof(heightdiff_line_by_dir) - 13); h1 = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t]))); ht = TileHeight(TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_line_by_dir[12 + style_t + 1]))); - h1 = maxu(h1, ht); + h1 = max(h1, ht); } break; }