Made the editor use the default image for the terrains...

...while drawing them so that updates are visible immediately, but
things do not have to be rebuilt. (Fixes some CVS-only issues)

Changed rebuild_terrain() to set the image for that location to the
default image of the terrain. It would still be nice to be able to
rebuild locations on the fly, but if it really is too complicated,
this solution is not that bad.
This commit is contained in:
Kristoffer Erlandsson 2004-06-06 12:49:27 +00:00
parent 74530fadcd
commit 33681e609a
5 changed files with 41 additions and 22 deletions

View file

@ -77,11 +77,19 @@ const std::vector<image::locator> *terrain_builder::get_terrain_at(const gamemap
void terrain_builder::rebuild_terrain(const gamemap::location &loc)
{
if (tile_map_.on_map(loc)) {
tile& btile = tile_map_[loc];
btile.clear();
const std::string filename =
map_.get_terrain_info(map_.get_terrain(loc)).default_image();
image::locator img_loc(filename);
btile.images_foreground.push_back(img_loc);
}
}
void terrain_builder::rebuild_all() {
tile_map_.reset();
terrain_by_type_.clear();
// For now, rebuild the whole map on each rebuilt_terrain. This is highly slow and
// inefficient, but this is simple
build_terrains();
}

View file

@ -36,8 +36,12 @@ public:
ADJACENT_TERRAIN_TYPE terrain_type) const;
// regenerate the generated content at the given location.
// regenerate the generated content at the given
// location. Currently: set the image at that location to the
// default image for the terrain.
void rebuild_terrain(const gamemap::location &loc);
void rebuild_all();
typedef std::multimap<int, std::string> imagelist;

View file

@ -2339,6 +2339,10 @@ void display::rebuild_terrain(const gamemap::location &loc) {
builder_.rebuild_terrain(loc);
}
void display::rebuild_all() {
builder_.rebuild_all();
}
void display::add_highlighted_loc(const gamemap::location &hex) {
// Only invalidate and insert if this is a new addition, for
// efficiency.

View file

@ -320,6 +320,8 @@ public:
//rebuild the dynamic terrain at the given location.
void rebuild_terrain(const gamemap::location &location);
//rebuild all dynamic terrain.
void rebuild_all();
//Add a location to highlight. Note that this has nothing to do with
//selecting hexes, it is pure highlighting. These hexes will be

View file

@ -840,21 +840,24 @@ void map_editor::draw_on_mouseover_hexes(const gamemap::TERRAIN terrain) {
draw_terrain(terrain, hex);
}
}
std::vector<gamemap::location> locs =
get_tiles(map_, hex, brush_.selected_brush_size());
map_undo_action action;
std::vector<gamemap::location> to_invalidate;
for(std::vector<gamemap::location>::const_iterator it = locs.begin();
it != locs.end(); ++it) {
if(terrain != map_[it->x][it->y]) {
to_invalidate.push_back(*it);
action.add_terrain(map_.get_terrain(*it), terrain, *it);
map_.set_terrain(*it, terrain);
else {
std::vector<gamemap::location> locs =
get_tiles(map_, hex, brush_.selected_brush_size());
map_undo_action action;
std::vector<gamemap::location> to_invalidate;
for(std::vector<gamemap::location>::const_iterator it = locs.begin();
it != locs.end(); ++it) {
if(terrain != map_[it->x][it->y]) {
to_invalidate.push_back(*it);
action.add_terrain(map_.get_terrain(*it), terrain, *it);
map_.set_terrain(*it, terrain);
gui_.rebuild_terrain(*it);
}
}
if (!to_invalidate.empty()) {
terrain_changed(to_invalidate, action);
save_undo_action(action);
}
}
if (!to_invalidate.empty()) {
terrain_changed(to_invalidate, action);
save_undo_action(action);
}
}
}
@ -901,11 +904,10 @@ void map_editor::perform_selection_move() {
void map_editor::draw_terrain(const gamemap::TERRAIN terrain,
const gamemap::location hex) {
const gamemap::TERRAIN current_terrain = map_.get_terrain(hex);
//const int xpos = gui_.get_location_x(hex);
//const int ypos = gui_.get_location_x(hex);
map_undo_action undo_action;
undo_action.add_terrain(current_terrain, terrain, hex);
map_.set_terrain(hex, terrain);
gui_.rebuild_terrain(hex);
terrain_changed(hex, undo_action);
save_undo_action(undo_action);
}
@ -1266,8 +1268,7 @@ void map_editor::main_loop() {
if (map_dirty_) {
if (!l_button_down && !r_button_down) {
map_dirty_ = false;
// XXX Currently this rebuilds all terrain, so we only want to do it once.
gui_.rebuild_terrain(gamemap::location(1,1));
gui_.rebuild_all();
gui_.invalidate_all();
recalculate_starting_pos_labels();
gui_.recalculate_minimap();