Skip to content

Commit

Permalink
optimize minimap.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed May 27, 2014
1 parent d4cead0 commit 8d54407
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/minimap.cpp
Expand Up @@ -45,13 +45,25 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
const int scale = 8;

DBG_DP << "creating minimap " << int(map.w()*scale*0.75) << "," << map.h()*scale << "\n";

const bool preferences_minimap_draw_terrain = preferences::minimap_draw_terrain();
const bool preferences_minimap_terrain_coding = preferences::minimap_terrain_coding();
const bool preferences_minimap_draw_villages = preferences::minimap_draw_villages();

const size_t map_width = map.w()*scale*3/4;
const size_t map_height = map.h()*scale;
if(map_width == 0 || map_height == 0) {
return surface(NULL);
}

if(!preferences_minimap_draw_villages && !preferences_minimap_draw_terrain)
{
//return if there is nothing to draw.
//(optimisation)
double ratio = std::min<double>( w*1.0 / map_width, h*1.0 / map_height);
return create_neutral_surface(map_width * ratio, map_height * ratio);
}

surface minimap(create_neutral_surface(map_width, map_height));
if(minimap == NULL)
return surface(NULL);
Expand Down Expand Up @@ -90,9 +102,9 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
, 0
, 0);

if (preferences::minimap_draw_terrain()) {
if (preferences_minimap_draw_terrain) {

if (!preferences::minimap_terrain_coding()) {
if (!preferences_minimap_terrain_coding) {

surface surf(NULL);

Expand Down Expand Up @@ -218,7 +230,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
}
}

if (terrain_info.is_village() && preferences::minimap_draw_villages()) {
if (terrain_info.is_village() && preferences_minimap_draw_villages) {

int side = village_owner(loc);

Expand Down

0 comments on commit 8d54407

Please sign in to comment.