added better looking minimap code from jzaun
This commit is contained in:
parent
6dfafe2ad4
commit
e776e3ab93
1 changed files with 41 additions and 20 deletions
|
@ -114,10 +114,10 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
|
||||||
std::fill(pixels,pixels+length,0);
|
std::fill(pixels,pixels+length,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_surfaces(std::map<std::string,SDL_Surface*>& surfaces)
|
template<typename Map>
|
||||||
|
void clear_surfaces(Map& surfaces)
|
||||||
{
|
{
|
||||||
for(std::map<std::string,SDL_Surface*>::iterator i = surfaces.begin();
|
for(typename Map::iterator i = surfaces.begin(); i != surfaces.end(); ++i) {
|
||||||
i != surfaces.end(); ++i) {
|
|
||||||
SDL_FreeSurface(i->second);
|
SDL_FreeSurface(i->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,6 +826,13 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
||||||
double highlight_ratio, Pixel blend_with)
|
double highlight_ratio, Pixel blend_with)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
if(map_.on_board(gamemap::location(x,y))) {
|
||||||
|
SDL_Surface* const tile = getTerrain(map_[x][y],UNSCALED,x,y);
|
||||||
|
SDL_Surface* minitile = scale_surface(tile,4,4);
|
||||||
|
|
||||||
|
SDL_FreeSurface(minitile);
|
||||||
|
}
|
||||||
|
|
||||||
if(updatesLocked_)
|
if(updatesLocked_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1611,33 +1618,47 @@ SDL_Surface* display::getImageTinted(const std::string& filename, TINT tint)
|
||||||
SDL_Surface* display::getMinimap(int w, int h)
|
SDL_Surface* display::getMinimap(int w, int h)
|
||||||
{
|
{
|
||||||
if(minimap_ == NULL) {
|
if(minimap_ == NULL) {
|
||||||
|
const int scale = 4;
|
||||||
SDL_Surface* const surface = screen_.getSurface();
|
SDL_Surface* const surface = screen_.getSurface();
|
||||||
minimap_ = SDL_CreateRGBSurface(SDL_SWSURFACE,map_.x(),map_.y(),
|
|
||||||
surface->format->BitsPerPixel,
|
minimap_ = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||||
surface->format->Rmask,
|
map_.x()*scale,map_.y()*scale,
|
||||||
surface->format->Gmask,
|
surface->format->BitsPerPixel,
|
||||||
surface->format->Bmask,
|
surface->format->Rmask,
|
||||||
surface->format->Amask);
|
surface->format->Gmask,
|
||||||
|
surface->format->Bmask,
|
||||||
|
surface->format->Amask);
|
||||||
if(minimap_ == NULL)
|
if(minimap_ == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
const int xpad = is_odd(minimap_->w);
|
typedef std::map<gamemap::TERRAIN,SDL_Surface*> cache_map;
|
||||||
|
cache_map cache;
|
||||||
|
|
||||||
surface_lock lock(minimap_);
|
SDL_Rect minirect = {0,0,scale,scale};
|
||||||
short* data = lock.pixels();
|
|
||||||
for(int y = 0; y != map_.y(); ++y) {
|
for(int y = 0; y != map_.y(); ++y) {
|
||||||
for(int x = 0; x != map_.x(); ++x) {
|
for(int x = 0; x != map_.x(); ++x) {
|
||||||
|
if(map_.on_board(gamemap::location(x,y))) {
|
||||||
|
const gamemap::TERRAIN terrain = map_[x][y];
|
||||||
|
cache_map::iterator i = cache.find(terrain);
|
||||||
|
|
||||||
if(shrouded(x,y))
|
if(i == cache.end()) {
|
||||||
*data = 0;
|
SDL_Surface* const tile = getTerrain(map_[x][y],
|
||||||
else
|
UNSCALED,x,y);
|
||||||
*data = map_.get_terrain_info(map_[x][y]).get_rgb().
|
SDL_Surface* const minitile = scale_surface(tile,scale,
|
||||||
format(surface->format);
|
scale);
|
||||||
++data;
|
i = cache.insert(
|
||||||
|
cache_map::value_type(terrain,minitile)).first;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(i != cache.end());
|
||||||
|
|
||||||
|
SDL_Rect maprect = {x*scale,y*scale,0,0};
|
||||||
|
SDL_BlitSurface(i->second, &minirect, minimap_, &maprect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data += xpad;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear_surfaces(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(minimap_->w != w || minimap_->h != h) {
|
if(minimap_->w != w || minimap_->h != h) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue