dependency cleanup: split image.* into minimap.*,

so that 'image' does not depend any more on 'team'
This commit is contained in:
Yann Dirson 2005-10-28 22:50:31 +00:00
parent 62abd2f89e
commit d464e829f1
13 changed files with 139 additions and 92 deletions

View file

@ -1,8 +1,10 @@
src/filechooser.cpp
src/font.cpp
src/hotkeys.cpp
src/image.cpp
src/mapgen_dialog.cpp
src/marked-up_text.cpp
src/minimap.cpp
src/preferences.cpp
src/show_dialog.cpp
src/widgets/file_chooser.cpp

View file

@ -40,7 +40,6 @@ src/game_config.cpp
src/gamestatus.cpp
src/gettext.cpp
src/halo.cpp
src/image.cpp
src/key.cpp
src/log.cpp
src/map.cpp

View file

@ -67,6 +67,7 @@ wesnoth_SOURCES = \
mapgen.cpp \
mapgen_dialog.cpp \
marked-up_text.cpp \
minimap.cpp \
mouse.cpp \
multiplayer.cpp \
multiplayer_ui.cpp \
@ -164,6 +165,7 @@ wesnoth_SOURCES = \
mapgen.hpp \
mapgen_dialog.hpp \
marked-up_text.hpp \
minimap.hpp \
mouse.hpp \
multiplayer.hpp \
multiplayer_ui.hpp \
@ -270,6 +272,7 @@ wesnoth_editor_SOURCES = \
mapgen.cpp \
mapgen_dialog.cpp \
marked-up_text.cpp \
minimap.cpp \
mouse.cpp \
network.cpp \
network_worker.cpp \
@ -356,6 +359,7 @@ wesnoth_editor_SOURCES = \
mapgen.hpp \
mapgen_dialog.hpp \
marked-up_text.hpp \
minimap.hpp \
mouse.hpp \
network.hpp \
network_worker.hpp \

View file

@ -24,6 +24,7 @@
#include "log.hpp"
#include "map.hpp"
#include "marked-up_text.hpp"
#include "minimap.hpp"
#include "playturn.hpp"
#include "preferences.hpp"
#include "replay.hpp"

View file

@ -28,6 +28,7 @@
#include "language.hpp"
#include "log.hpp"
#include "marked-up_text.hpp"
#include "minimap.hpp"
#include "preferences.hpp"
#include "sdl_utils.hpp"
#include "sound.hpp"

View file

@ -22,6 +22,7 @@
#include "../image.hpp"
#include "../language.hpp"
#include "../map.hpp"
#include "../minimap.hpp"
#include "../preferences.hpp"
#include "../random.hpp"
#include "../team.hpp"

View file

@ -19,7 +19,6 @@
#include "image.hpp"
#include "log.hpp"
#include "sdl_utils.hpp"
#include "team.hpp"
#include "util.hpp"
#include "wassert.hpp"
#include "wesconfig.h"
@ -30,14 +29,10 @@
#include <map>
#include <string>
#define LOG_DP LOG_STREAM(info, display)
#define ERR_DP LOG_STREAM(err, display)
namespace {
typedef std::map<gamemap::TERRAIN, surface> mini_terrain_cache_map;
mini_terrain_cache_map mini_terrain_cache;
typedef std::map<image::locator::value, int> locator_finder_t;
typedef std::pair<image::locator::value, int> locator_finder_pair;
locator_finder_t locator_finder;
@ -58,8 +53,6 @@ int red_adjust = 0, green_adjust = 0, blue_adjust = 0;
std::string image_mask;
SDL_PixelFormat* pixel_format = NULL;
#ifdef USE_TINY_GUI
const int tile_size = 36;
#else
@ -86,6 +79,8 @@ void reset_cache(std::vector<image::cache_item<T> >& cache)
namespace image {
mini_terrain_cache_map mini_terrain_cache;
void flush_cache()
{
reset_cache(images_);
@ -359,6 +354,8 @@ void set_wm_icon()
#endif
}
SDL_PixelFormat* pixel_format = NULL;
void set_pixel_format(SDL_PixelFormat* format)
{
pixel_format = format;
@ -647,83 +644,5 @@ bool exists(const image::locator& i_locator)
return cache;
}
surface getMinimap(int w, int h, const gamemap& map, const team* tm)
{
const int scale = 8;
LOG_DP << "creating minimap " << int(map.x()*scale*0.75) << "," << int(map.y()*scale) << "\n";
const size_t map_width = map.x()*scale*3/4;
const size_t map_height = map.y()*scale;
if(map_width == 0 || map_height == 0) {
return surface(NULL);
}
surface minimap(SDL_CreateRGBSurface(SDL_SWSURFACE,
map_width,map_height,
pixel_format->BitsPerPixel,
pixel_format->Rmask,
pixel_format->Gmask,
pixel_format->Bmask,
pixel_format->Amask));
if(minimap == NULL)
return surface(NULL);
typedef mini_terrain_cache_map cache_map;
cache_map& cache = mini_terrain_cache;
for(int y = 0; y != map.y(); ++y) {
for(int x = 0; x != map.x(); ++x) {
surface surf(NULL);
const gamemap::location loc(x,y);
if(map.on_board(loc)) {
const bool shrouded = tm != NULL && tm->shrouded(x,y);
const bool fogged = tm != NULL && tm->fogged(x,y) && !shrouded;
const gamemap::TERRAIN terrain = shrouded ? gamemap::VOID_TERRAIN : map[x][y];
cache_map::iterator i = cache.find(terrain);
if(i == cache.end()) {
surface tile(get_image("terrain/" + map.get_terrain_info(terrain).symbol_image() + ".png",image::UNSCALED));
if(tile == NULL) {
ERR_DP << "could not get image for terrrain '"
<< terrain << "'\n";
continue;
}
surf = surface(scale_surface_blended(tile,scale,scale));
if(surf == NULL) {
continue;
}
i = cache.insert(cache_map::value_type(terrain,surf)).first;
} else {
surf = surface(i->second);
}
if(fogged) {
surf = surface(adjust_surface_colour(surf,-50,-50,-50));
}
wassert(surf != NULL);
SDL_Rect maprect = {x*scale*3/4,y*scale + (is_odd(x) ? scale/2 : 0),0,0};
SDL_BlitSurface(surf, NULL, minimap, &maprect);
}
}
}
if((minimap->w != w || minimap->h != h) && w != 0) {
const surface surf(minimap);
minimap = surface(scale_surface(surf,w,h));
}
LOG_DP << "done generating minimap\n";
return minimap;
}
}

View file

@ -21,8 +21,6 @@
#include <string>
#include <vector>
class team;
///this module manages the cache of images. With an image name, you can get
///the surface corresponding to that image.
//
@ -126,6 +124,8 @@ namespace image {
typedef std::vector<cache_item<surface> > image_cache;
typedef std::vector<cache_item<locator> > locator_cache;
typedef std::map<gamemap::TERRAIN, surface> mini_terrain_cache_map;
extern mini_terrain_cache_map mini_terrain_cache;
void flush_cache();
@ -155,6 +155,8 @@ namespace image {
///the 'mask' is blitted onto all scaled images.
void set_image_mask(const std::string& image_name);
extern SDL_PixelFormat* pixel_format;
///sets the pixel format used by the images. Is called every time the
///video mode changes. Invalidates all images.
void set_pixel_format(SDL_PixelFormat* format);
@ -195,10 +197,6 @@ namespace image {
//returns true if the given image actually exists, without loading it.
bool exists(const locator& i_locator);
///function to create the minimap for a given map
///the surface returned must be freed by the user
surface getMinimap(int w, int h, const gamemap& map_, const team* tm=NULL);
}
#endif

103
src/minimap.cpp Normal file
View file

@ -0,0 +1,103 @@
/* $Id$ */
/*
Copyright (C) 2003-5 by David White <davidnwhite@verizon.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "image.hpp"
#include "log.hpp"
#include "minimap.hpp"
#include "team.hpp"
#include "wassert.hpp"
#define LOG_DP LOG_STREAM(info, display)
#define ERR_DP LOG_STREAM(err, display)
namespace image {
surface getMinimap(int w, int h, const gamemap& map, const team* tm)
{
const int scale = 8;
LOG_DP << "creating minimap " << int(map.x()*scale*0.75) << "," << int(map.y()*scale) << "\n";
const size_t map_width = map.x()*scale*3/4;
const size_t map_height = map.y()*scale;
if(map_width == 0 || map_height == 0) {
return surface(NULL);
}
surface minimap(SDL_CreateRGBSurface(SDL_SWSURFACE,
map_width,map_height,
pixel_format->BitsPerPixel,
pixel_format->Rmask,
pixel_format->Gmask,
pixel_format->Bmask,
pixel_format->Amask));
if(minimap == NULL)
return surface(NULL);
typedef mini_terrain_cache_map cache_map;
cache_map& cache = mini_terrain_cache;
for(int y = 0; y != map.y(); ++y) {
for(int x = 0; x != map.x(); ++x) {
surface surf(NULL);
const gamemap::location loc(x,y);
if(map.on_board(loc)) {
const bool shrouded = tm != NULL && tm->shrouded(x,y);
const bool fogged = tm != NULL && tm->fogged(x,y) && !shrouded;
const gamemap::TERRAIN terrain = shrouded ? gamemap::VOID_TERRAIN : map[x][y];
cache_map::iterator i = cache.find(terrain);
if(i == cache.end()) {
surface tile(get_image("terrain/" + map.get_terrain_info(terrain).symbol_image() + ".png",image::UNSCALED));
if(tile == NULL) {
ERR_DP << "could not get image for terrrain '"
<< terrain << "'\n";
continue;
}
surf = surface(scale_surface_blended(tile,scale,scale));
if(surf == NULL) {
continue;
}
i = cache.insert(cache_map::value_type(terrain,surf)).first;
} else {
surf = surface(i->second);
}
if(fogged) {
surf = surface(adjust_surface_colour(surf,-50,-50,-50));
}
wassert(surf != NULL);
SDL_Rect maprect = {x*scale*3/4,y*scale + (is_odd(x) ? scale/2 : 0),0,0};
SDL_BlitSurface(surf, NULL, minimap, &maprect);
}
}
}
if((minimap->w != w || minimap->h != h) && w != 0) {
const surface surf(minimap);
minimap = surface(scale_surface(surf,w,h));
}
LOG_DP << "done generating minimap\n";
return minimap;
}
}

16
src/minimap.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef MINIMAP_HPP_INCLUDED
#define MINIMAP_HPP_INCLUDED
#include "map.hpp"
#include "sdl_utils.hpp"
class team;
namespace image {
///function to create the minimap for a given map
///the surface returned must be freed by the user
surface getMinimap(int w, int h, const gamemap& map_, const team* tm=NULL);
}
#endif

View file

@ -20,6 +20,7 @@
#include "image.hpp"
#include "show_dialog.hpp"
#include "map_create.hpp"
#include "minimap.hpp"
#include "multiplayer_create.hpp"
#include "filesystem.hpp"
#include "log.hpp"

View file

@ -14,6 +14,7 @@
#include "global.hpp"
#include "filesystem.hpp"
#include "marked-up_text.hpp"
#include "minimap.hpp"
#include "multiplayer_lobby.hpp"
#include "wassert.hpp"
#include "wml_separators.hpp"

View file

@ -24,6 +24,7 @@
#include "image.hpp"
#include "log.hpp"
#include "map_label.hpp"
#include "minimap.hpp"
#include "marked-up_text.hpp"
#include "mouse.hpp"
#include "network.hpp"