Dynamically generated terrain now displays correctly in the editor.

This commit is contained in:
Kristoffer Erlandsson 2004-04-26 21:35:22 +00:00
parent ed55b59702
commit ce362b34b7
6 changed files with 55 additions and 1 deletions

View file

@ -32,6 +32,24 @@ const std::vector<std::string>* terrain_builder::get_terrain_at(const gamemap::l
}
}
void terrain_builder::rebuild_terrain(const gamemap::location &loc) {
const std::vector<std::string> &vback = build_terrain_at(loc, ADJACENT_BACKGROUND);
if (vback.empty()) {
buildings_background.erase(loc);
}
else {
buildings_background[loc] = vback;
}
const std::vector<std::string> &vfore = build_terrain_at(loc, ADJACENT_FOREGROUND);
if (vfore.empty()) {
buildings_foreground.erase(loc);
}
else {
buildings_foreground[loc] = vfore;
}
}
void terrain_builder::build_terrains()
{
for(int x = -1; x <= map_.x(); ++x) {

View file

@ -34,7 +34,9 @@ public:
//Returns NULL if there is no built content for this tile.
const std::vector<std::string> *terrain_builder::get_terrain_at(const gamemap::location &loc,
ADJACENT_TERRAIN_TYPE terrain_type) const;
// regenerate the generated content at the given location.
void rebuild_terrain(const gamemap::location &loc);
private:
//pre-calculates the list of generated content for all tiles (will slow the game
//too much otherwise)

View file

@ -2158,3 +2158,11 @@ void display::prune_chat_messages(bool remove_all)
prune_chat_messages(remove_all);
}
}
void display::rebuild_terrains(const std::vector<gamemap::location> &locations) {
for (std::vector<gamemap::location>::const_iterator it = locations.begin();
it != locations.end(); it++) {
builder_.rebuild_terrain(*it);
}
}

View file

@ -306,6 +306,9 @@ public:
bool upside_down=false,double alpha=1.0, Uint32 blendto=0, double submerged=0.0,
SDL_Surface* ellipse_back=NULL, SDL_Surface* ellipse_front=NULL);
//rebuild the dynamic terrain at the given locations.
void rebuild_terrains(const std::vector<gamemap::location> &locations);
private:
display(const display&);
void operator=(const display&);

View file

@ -394,6 +394,7 @@ void map_editor::undo() {
--num_operations_since_save_;
map_undo_action action = undo_stack_.back();
map_.set_terrain(action.location,action.old_terrain);
dirty_positions_.push_back(action.location);
undo_stack_.pop_back();
redo_stack_.push_back(action);
if(redo_stack_.size() > undo_limit)
@ -407,6 +408,7 @@ void map_editor::redo() {
++num_operations_since_save_;
map_undo_action action = redo_stack_.back();
map_.set_terrain(action.location,action.new_terrain);
dirty_positions_.push_back(action.location);
redo_stack_.pop_back();
undo_stack_.push_back(action);
if(undo_stack_.size() > undo_limit)
@ -417,6 +419,7 @@ void map_editor::redo() {
void map_editor::set_starting_position(const int player, const gamemap::location loc) {
if(map_.on_board(loc)) {
dirty_positions_.push_back(loc);
map_.set_terrain(loc, gamemap::CASTLE);
// This operation is currently not undoable, so we need to make sure
// that save is always asked for after it is performed.
@ -470,6 +473,7 @@ void map_editor::draw_terrain(const gamemap::TERRAIN terrain,
if(undo_stack_.size() > undo_limit)
undo_stack_.pop_front();
map_.set_terrain(hex, terrain);
dirty_positions_.push_back(hex);
invalidate_adjacent(hex);
}
@ -598,6 +602,21 @@ void map_editor::execute_command(const hotkey::HOTKEY_COMMAND command) {
}
}
void map_editor::rebuild_dirty_terrains() {
std::vector<gamemap::location> including_adjacent;
for (std::vector<gamemap::location>::const_iterator it = dirty_positions_.begin();
it != dirty_positions_.end(); it++) {
gamemap::location locs[7];
locs[0] = *it;
get_adjacent_tiles(*it,locs+1);
for(int i = 0; i != 7; ++i) {
including_adjacent.push_back(locs[i]);
}
gui_.rebuild_terrains(including_adjacent);
}
dirty_positions_.clear();
}
void map_editor::main_loop() {
const double scroll_speed = preferences::scroll_speed();
unsigned int counter = 0;
@ -644,6 +663,7 @@ void map_editor::main_loop() {
middle_button_down(mousex, mousey);
}
rebuild_dirty_terrains();
gui_.draw(false);
palette_.draw();
//if(drawterrainpalette(gui_, tstart_, selected_terrain_, map_, size_specs_) == false)

View file

@ -165,6 +165,8 @@ public:
};
private:
void map_editor::rebuild_dirty_terrains();
/// Called in every iteration when the left mouse button is held
/// down. Note that this differs from a click.
void left_button_down(const int mousex, const int mousey);
@ -234,6 +236,7 @@ private:
// scheduled.
bool minimap_dirty_;
terrain_palette palette_;
std::vector<gamemap::location> dirty_positions_;
};