Index: dataobj/settings.cc =================================================================== --- dataobj/settings.cc (revision 9173) +++ dataobj/settings.cc (working copy) @@ -724,7 +724,7 @@ random_counter = get_random_seed( ); file->rdwr_long( random_counter ); if( !env_t::networkmode || env_t::server ) { - frames_per_second = clamp(env_t::fps,5,100 ); // update it on the server to the current setting + frames_per_second = clamp(env_t::fps, 5u, 100u); // update it on the server to the current setting frames_per_step = env_t::network_frames_per_step; } file->rdwr_long( frames_per_second ); @@ -924,9 +924,9 @@ env_t::show_names = contents.get_int("show_names", env_t::show_names ); env_t::show_month = contents.get_int("show_month", env_t::show_month ); env_t::max_acceleration = contents.get_int("fast_forward", env_t::max_acceleration ); - env_t::fps = clamp(contents.get_int("frames_per_second", env_t::fps), env_t::min_fps, env_t::max_fps); - env_t::ff_fps = clamp(contents.get_int("fast_forward_frames_per_second", env_t::ff_fps), env_t::min_fps, env_t::max_fps); - env_t::num_threads = clamp( contents.get_int("threads", env_t::num_threads ), 1, MAX_THREADS ); + env_t::fps = clamp((uint32)contents.get_int("frames_per_second", env_t::fps), env_t::min_fps, env_t::max_fps); + env_t::ff_fps = clamp((uint32)contents.get_int("fast_forward_frames_per_second", env_t::ff_fps), env_t::min_fps, env_t::max_fps); + env_t::num_threads = clamp(contents.get_int("threads", env_t::num_threads ), 1, MAX_THREADS); env_t::simple_drawing_default = contents.get_int("simple_drawing_tile_size",env_t::simple_drawing_default ); env_t::simple_drawing_fast_forward = contents.get_int("simple_drawing_fast_forward",env_t::simple_drawing_fast_forward ); env_t::visualize_schedule = contents.get_int("visualize_schedule",env_t::visualize_schedule ) != 0; @@ -1344,10 +1344,10 @@ env_t::pak_height_conversion_factor = contents.get_int("height_conversion_factor", env_t::pak_height_conversion_factor ); // minimum clearance under under bridges: 1 or 2? (HACK: value only zero during loading of pak set config) - int bounds = (way_height_clearance!=0); + uint8 bounds = (way_height_clearance!=0); way_height_clearance = contents.get_int("way_height_clearance", way_height_clearance ); if( way_height_clearance > 2 && way_height_clearance < bounds ) { - sint8 new_whc = clamp( way_height_clearance, bounds, 2 ); + uint8 new_whc = clamp( way_height_clearance, bounds, (uint8)2 ); dbg->warning( "settings_t::parse_simuconf()", "Illegal way_height_clearance of %i set to %i", way_height_clearance, new_whc ); way_height_clearance = new_whc; } Index: dataobj/settings.h =================================================================== --- dataobj/settings.h (revision 9173) +++ dataobj/settings.h (working copy) @@ -256,7 +256,7 @@ bool with_private_paks; /// what is the minimum clearance required under bridges - sint8 way_height_clearance; + uint8 way_height_clearance; // if true, you can buy obsolete stuff bool allow_buying_obsolete_vehicles; Index: display/font.cc =================================================================== --- display/font.cc (revision 9173) +++ display/font.cc (working copy) @@ -171,7 +171,7 @@ dbg->message("font_t::load_from_bdf", "Loading BDF font '%s'", fname); glyphs.clear(); - int f_height = 0; + uint32 f_height = 0; int f_desc = 0; int f_numglyphs = 0; sint32 max_glyph = 0; @@ -193,7 +193,7 @@ f_numglyphs = atoi(str + 5) <= 0x100 ? 0x100 : 0xFFFE; glyphs.resize(max(f_numglyphs, 0)); - glyphs[(uint32)' '].advance = clamp(f_height / 2, 3, GLYPH_BITMAP_HEIGHT); + glyphs[(uint32)' '].advance = clamp(f_height / 2, 3u, GLYPH_BITMAP_HEIGHT); continue; } Index: gui/simwin.cc =================================================================== --- gui/simwin.cc (revision 9173) +++ gui/simwin.cc (working copy) @@ -1215,8 +1215,8 @@ } // CLIP(wert,min,max) - to_pos.x = CLIP( to_pos.x, 8-to_size.x, display_get_width()-16 ); - to_pos.y = CLIP( to_pos.y, env_t::iconsize.h, display_get_height() - D_TITLEBAR_HEIGHT - win_get_statusbar_height() - TICKER_HEIGHT); + to_pos.x = clamp( to_pos.x, 8-to_size.x, display_get_width()-16 ); + to_pos.y = clamp( to_pos.y, env_t::iconsize.h, display_get_height() - D_TITLEBAR_HEIGHT - win_get_statusbar_height() - TICKER_HEIGHT); // delta is actual window movement. const scr_coord delta = to_pos - from_pos; Index: macros.h =================================================================== --- macros.h (revision 9173) +++ macros.h (working copy) @@ -27,15 +27,9 @@ #define MEMZERO(obj) MEMZERON(&(obj), 1) // make sure, a value in within the borders -static inline int clamp(int x, int min, int max) +template static inline T clamp(T v, T l, T u) { - if (x <= min) { - return min; - } - if (x >= max) { - return max; - } - return x; + return v < l ? l : (v > u ? u :v); } Index: player/ai_goods.cc =================================================================== --- player/ai_goods.cc (revision 9173) +++ player/ai_goods.cc (working copy) @@ -977,7 +977,7 @@ if( count_road<255 ) { // for short distance: reduce number of cars // calculated here, since the above number was based on production - count_road = CLIP( (sint32)(dist*15)/best_road_speed, 2, count_road ); + count_road = clamp( (sint32)(dist*15)/best_road_speed, 2, count_road ); int freight_price = (freight->get_value()*road_vehicle->get_capacity()*count_road)/24*((8000+(best_road_speed-80)*freight->get_speed_bonus())/1000); cost_road = road_weg->get_maintenance() + 300/dist + (count_road*road_vehicle->get_running_cost()*best_road_speed)/(2*dist+5); income_road = (freight_price*best_road_speed)/(2*dist+5); Index: script/api_param.cc =================================================================== --- script/api_param.cc (revision 9173) +++ script/api_param.cc (working copy) @@ -18,8 +18,6 @@ #include "api/api_simple.h" // my_ribi_t -template T clamp(T v, T l, T u) { return v < l ? l : (v > u ? u :v); } - namespace script_api { karte_ptr_t welt; Index: simtool.cc =================================================================== --- simtool.cc (revision 9173) +++ simtool.cc (working copy) @@ -6392,7 +6392,7 @@ } if( distance < welt->get_settings().allow_merge_distant_halt ) { - distance = clamp(distance,2,33)-2; + distance = clamp(distance,2u,33u)-2; workcost = welt->scale_with_month_length( (1<get_settings().cst_multiply_merge_halt ); win_set_static_tooltip( tooltip_with_price("Building costs estimates", workcost) ); } @@ -6424,7 +6424,7 @@ } if( distance < welt->get_settings().allow_merge_distant_halt ) { - distance = clamp(distance,2,33)-2; + distance = clamp(distance,2u,33u)-2; workcost = welt->scale_with_month_length( (1<get_settings().cst_multiply_merge_halt ); win_set_static_tooltip( tooltip_with_price("Building costs estimates", workcost) ); if( player != welt->get_public_player() && !player->can_afford(workcost) ) { Index: simtypes.h =================================================================== --- simtypes.h (revision 9173) +++ simtypes.h (working copy) @@ -147,11 +147,6 @@ }; -// makros are not very safe: thus use these macro like functions -// otherwise things may fail or functions are called uneccessarily twice - -#define CLIP(wert,mini,maxi) min(max((wert),(mini)),(maxi)) - // define machine independent types typedef unsigned int uint; typedef signed char sint8; Index: simworld.cc =================================================================== --- simworld.cc (revision 9173) +++ simworld.cc (working copy) @@ -6343,7 +6343,7 @@ } else if(step_mode==FIX_RATIO) { last_frame_idx = 0; - fix_ratio_frame_time = 1000 / clamp(settings.get_frames_per_second(), 5, 100); + fix_ratio_frame_time = 1000 / clamp(settings.get_frames_per_second(), 5u, 100u); next_step_time = last_tick_sync + fix_ratio_frame_time; set_frame_time( fix_ratio_frame_time ); intr_disable();