Define a simplified draw() mrthod for the editor. Not yet tested.

This commit is contained in:
Eric S. Raymond 2007-06-27 12:52:05 +00:00
parent dd0ec08dad
commit 7c4782a86a
2 changed files with 84 additions and 13 deletions

View file

@ -464,7 +464,7 @@ std::vector<std::string> map_display::get_fog_shroud_graphics(const gamemap::loc
}
std::vector<surface> map_display::get_terrain_images(const gamemap::location &loc,
const time_of_day& tod,
const std::string timeid,
image::TYPE image_type,
ADJACENT_TERRAIN_TYPE terrain_type)
{
@ -493,7 +493,7 @@ std::vector<surface> map_display::get_terrain_images(const gamemap::location &lo
(terrain_type == ADJACENT_FOREGROUND ?
terrain_builder::ADJACENT_FOREGROUND : terrain_builder::ADJACENT_BACKGROUND);
const terrain_builder::imagelist* const terrains = builder_.get_terrain_at(loc,
tod.id, builder_terrain_type);
timeid, builder_terrain_type);
if(terrains != NULL) {
for(std::vector<animated<image::locator> >::const_iterator it = terrains->begin(); it != terrains->end(); ++it) {
@ -526,12 +526,12 @@ void map_display::tile_stack_append(const surface surf)
};
void map_display::tile_stack_terrains(const gamemap::location& loc,
const time_of_day& tod,
const std::string timeid,
image::TYPE image_type,
ADJACENT_TERRAIN_TYPE type)
// find all terrain images matching our specs, drop them on the terrain stack
{
const std::vector<surface>& images = get_terrain_images(loc,tod,image_type,type);
const std::vector<surface>& images = get_terrain_images(loc,timeid,image_type,type);
std::vector<surface>::const_iterator itor;
for(itor = images.begin(); itor != images.end(); ++itor)
@ -1544,6 +1544,68 @@ void display::redraw_everything()
draw(true,true);
}
void editor_display::draw(bool update,bool force)
{
bool changed = map_display::draw_init();
//int simulate_delay = 0;
if(!map_.empty() && !invalidated_.empty()) {
changed = true;
SDL_Rect clip_rect = map_area();
surface const dst(screen_.getSurface());
clip_rect_setter set_clip_rect(dst, clip_rect);
std::set<gamemap::location>::const_iterator it;
for(it = invalidated_.begin(); it != invalidated_.end(); ++it) {
image::TYPE image_type = image::SCALED_TO_HEX;
if(*it == mouseoverHex_ && map_.on_board(mouseoverHex_)) {
image_type = image::BRIGHTENED;
}
else if (highlighted_locations_.find(*it) != highlighted_locations_.end()) {
image_type = image::SEMI_BRIGHTENED;
}
if(screen_.update_locked()) {
continue;
}
int xpos = int(get_location_x(*it));
int ypos = int(get_location_y(*it));
if(xpos >= clip_rect.x + clip_rect.w || ypos >= clip_rect.y + clip_rect.h ||
xpos + zoom_ < clip_rect.x || ypos + zoom_ < clip_rect.y) {
continue;
}
tile_stack_clear();
tile_stack_terrains(*it,"morning",image_type,ADJACENT_BACKGROUND);
tile_stack_terrains(*it,"morning",image_type,ADJACENT_FOREGROUND);
// draw the grid, if that's been enabled
if(grid_) {
tile_stack_append(image::get_image(game_config::grid_image));
}
// paint selection and mouseover overlays
if(*it == selectedHex_ && map_.on_board(selectedHex_) && selected_hex_overlay_ != NULL)
tile_stack_append(selected_hex_overlay_);
if(*it == mouseoverHex_ && map_.on_board(mouseoverHex_) && mouseover_hex_overlay_ != NULL)
tile_stack_append(mouseover_hex_overlay_);
tile_stack_render(xpos, ypos);
}
invalidated_.clear();
} else if (!map_.empty()) {
wassert(invalidated_.empty());
}
map_display::draw_wrap(update, force, changed);
}
void display::draw(bool update,bool force)
{
//log_scope("Drawing");
@ -1624,7 +1686,7 @@ void display::draw(bool update,bool force)
if(!is_shrouded /*|| !on_map*/) {
// unshrouded terrain (the normal case)
tile_stack_terrains(*it,tod, image_type, ADJACENT_BACKGROUND);
tile_stack_terrains(*it,tod.id, image_type, ADJACENT_BACKGROUND);
// village-control flags.
tile_stack_append(get_flag(terrain,*it));
@ -1648,7 +1710,7 @@ void display::draw(bool update,bool force)
tile_stack_append(footstep_image(*it));
if(!is_shrouded /*|| !on_map*/) {
tile_stack_terrains(*it,tod,image_type,ADJACENT_FOREGROUND);
tile_stack_terrains(*it,tod.id,image_type,ADJACENT_FOREGROUND);
}
// apply fogging
@ -1657,7 +1719,7 @@ void display::draw(bool update,bool force)
}
if(!is_shrouded && on_map) {
tile_stack_terrains(*it,tod,image_type,ADJACENT_FOGSHROUD);
tile_stack_terrains(*it,tod.id,image_type,ADJACENT_FOGSHROUD);
}
//draw the time-of-day mask on top of the

View file

@ -240,6 +240,11 @@ public:
void remove_highlighted_loc(const gamemap::location &hex);
//draws invalidated items. If update is true, will also copy the
//display to the frame buffer. If force is true, will not skip frames,
//even if running behind.
virtual void draw(bool update=true,bool force=false) = 0;
// Announce a message prominently
void announce(const std::string msg,
const SDL_Color& colour = font::GOOD_COLOUR);
@ -250,13 +255,12 @@ protected:
enum ADJACENT_TERRAIN_TYPE { ADJACENT_BACKGROUND, ADJACENT_FOREGROUND, ADJACENT_FOGSHROUD };
std::vector<surface> get_terrain_images(const gamemap::location &loc,
const time_of_day& tod,
const std::string timeid,
image::TYPE type,
ADJACENT_TERRAIN_TYPE terrain_type);
std::vector<std::string> get_fog_shroud_graphics(const gamemap::location& loc);
protected:
CVideo& screen_;
const gamemap& map_;
@ -289,7 +293,7 @@ protected:
//composes and draws the terrains on a tile
void tile_stack_terrains(const gamemap::location& loc,
const time_of_day& tod,
const std::string timeid,
image::TYPE image_type,
ADJACENT_TERRAIN_TYPE type);
void tile_stack_append(surface surf);
@ -314,6 +318,13 @@ private:
int fps_handle_;
};
class editor_display : public map_display
{
public:
// draw for the editor display only to know about terrain
void draw(bool update=true,bool force=false);
};
class display : public map_display
{
public:
@ -365,9 +376,7 @@ public:
//invalidates entire screen, including all tiles and sidebar.
void redraw_everything();
//draws invalidated items. If update is true, will also copy the
//display to the frame buffer. If force is true, will not skip frames,
//even if running behind.
// draw for the game display has to know about units
void draw(bool update=true,bool force=false);
//function to display a location as selected. If a unit is in