The Battle for Wesnoth  1.15.0-dev
display.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Routines to set up the display, scroll and zoom the map.
18  */
19 
20 #include "display.hpp"
21 
22 #include "arrow.hpp"
23 #include "color.hpp"
24 #include "cursor.hpp"
25 #include "fake_unit_manager.hpp"
26 #include "floating_label.hpp"
27 #include "font/marked-up_text.hpp"
28 #include "font/text.hpp"
29 #include "gettext.hpp"
31 #include "halo.hpp"
33 #include "log.hpp"
34 #include "map/label.hpp"
35 #include "map/map.hpp"
36 #include "overlay.hpp"
37 #include "preferences/game.hpp"
38 #include "resources.hpp"
39 #include "sdl/render_utils.hpp"
40 #include "synced_context.hpp"
41 #include "team.hpp"
42 #include "terrain/builder.hpp"
43 #include "time_of_day.hpp"
44 #include "tooltips.hpp"
46 #include "units/drawer.hpp"
47 #include "units/unit.hpp"
48 #include "whiteboard/manager.hpp"
49 
50 #include <array>
51 #include <cmath>
52 #include <iomanip>
53 #include <utility>
54 
55 static lg::log_domain log_display("display");
56 #define ERR_DP LOG_STREAM(err, log_display)
57 #define LOG_DP LOG_STREAM(info, log_display)
58 #define DBG_DP LOG_STREAM(debug, log_display)
59 
60 // These are macros instead of proper constants so that they auto-update if the game config is reloaded.
61 #define zoom_levels (game_config::zoom_levels)
62 #define final_zoom_index (static_cast<int>(zoom_levels.size()) - 1)
63 #define DefaultZoom (game_config::tile_size)
64 #define SmallZoom (DefaultZoom / 2)
65 #define MinZoom (zoom_levels.front())
66 #define MaxZoom (zoom_levels.back())
67 
68 namespace
69 {
70 bool benchmark = false;
71 bool debug_foreground = false;
72 
73 int prevLabel = 0;
74 
75 // frametime is in milliseconds
76 static unsigned calculate_fps(unsigned frametime)
77 {
78  return frametime != 0u ? 1000u / frametime : 999u;
79 }
80 
81 } // end anon namespace
82 
83 unsigned int display::zoom_ = DefaultZoom;
84 unsigned int display::last_zoom_ = SmallZoom;
85 
87  std::weak_ptr<wb::manager> wb,
88  const config& theme_cfg,
89  const config& level,
90  bool auto_join)
91  : events::sdl_handler(auto_join)
92  , dc_(dc)
93  , halo_man_(new halo::manager())
94  , wb_(wb)
95  , exclusive_unit_draw_requests_()
96  , video_(CVideo::get_singleton())
97  , currentTeam_(0)
98  , dont_show_all_(false)
99  , xpos_(0)
100  , ypos_(0)
101  , view_locked_(false)
102  , theme_(theme_cfg, video().screen_area())
103  , zoom_index_(0)
104  , fake_unit_man_(new fake_unit_manager(*this))
105  , builder_(new terrain_builder(level, (dc_ ? &get_map() : nullptr), theme_.border().tile_image, theme_.border().show_border))
106  , minimap_location_(sdl::empty_rect)
107  , grid_(false)
108  , diagnostic_label_(0)
109  , turbo_speed_(2)
110  , turbo_(false)
111  , map_labels_(new map_labels(nullptr))
112  , scroll_event_("scrolled")
113  , fps_counter_()
114  , fps_start_()
115  , fps_actual_()
116  , mouseover_hex_overlay_(nullptr)
117  , tod_hex_mask1(nullptr)
118  , tod_hex_mask2(nullptr)
119  , fog_images_()
120  , shroud_images_()
121  , selectedHex_()
122  , mouseoverHex_()
123  , keys_()
124  , animate_map_(true)
125  , animate_water_(true)
126  , flags_()
127  , activeTeam_(0)
128  , map_screenshot_(false)
129  , reach_map_()
130  , fps_handle_(0)
131  , drawn_hexes_(0)
132  , idle_anim_(preferences::idle_anim())
133  , idle_anim_rate_(1.0)
134  , draw_coordinates_(false)
135  , draw_terrain_codes_(false)
136  , draw_num_of_bitmaps_(false)
137  , arrows_map_()
138  , color_adjust_()
139 {
140  assert(singleton_ == nullptr);
141  singleton_ = this;
142 
144 
145  blindfold_ctr_ = 0;
146 
147  read(level.child_or_empty("display"));
148 
149  if(video_.non_interactive() && video_.faked()) {
150  video_.lock_updates(true);
151  }
152 
155 
157 
158  zoom_index_ = std::distance(zoom_levels.begin(), std::find(zoom_levels.begin(), zoom_levels.end(), zoom_));
159 
161 
162  init_flags();
163 }
164 
166 {
167  singleton_ = nullptr;
168  resources::fake_units = nullptr;
169 }
170 
171 void display::set_theme(config theme_cfg)
172 {
173  theme_ = theme(theme_cfg, video_.screen_area());
174 }
175 
177 {
178  flags_.clear();
179 
180  if(!dc_) {
181  return;
182  }
183 
184  flags_.resize(get_teams().size());
185 
186  for(std::size_t i = 0; i < get_teams().size(); ++i) {
187  init_flags(i);
188  }
189 }
190 
191 void display::init_flags(std::size_t side_index)
192 {
193  if(!dc_ || side_index >= dc_->teams().size()) {
194  ERR_DP << "Cannot build flag for nonexistent or unconfigured side " << (side_index + 1) << '\n';
195  return;
196  }
197 
198  const team& t = get_teams()[side_index];
199 
200  std::string flag = t.flag();
201  std::string old_rgb = game_config::flag_rgb;
202  std::string new_rgb = t.color();
203 
204  if(flag.empty()) {
206  }
207 
208  LOG_DP << "Adding flag for team " << t.side() << " from animation " << flag << "\n";
209 
210  // Must recolor flag image
211  animated<image::locator> temp_anim;
212 
213  std::vector<std::string> items = utils::square_parenthetical_split(flag);
214 
215  for(const std::string& item : items) {
216  const std::vector<std::string>& sub_items = utils::split(item, ':');
217  std::string str = item;
218  int time = 100;
219 
220  if(sub_items.size() > 1) {
221  str = sub_items.front();
222 
223  try {
224  time = std::max<int>(1, std::stoi(sub_items.back()));
225  } catch(const std::invalid_argument&) {
226  ERR_DP << "Invalid time value found when constructing flag for side " << t.side() << ": " << sub_items.back() << "\n";
227  }
228  }
229 
230  std::stringstream temp;
231  temp << str << "~RC(" << old_rgb << ">" << new_rgb << ")";
232  image::locator flag_image(temp.str());
233 
234  temp_anim.add_frame(time, flag_image);
235  }
236 
237  animated<image::locator>& f = flags_[side_index];
238  f = temp_anim;
239 
240  auto time = f.get_end_time();
241  if(time > 0) {
242  f.start_animation(randomness::rng::default_instance().get_random_int(0, time - 1), true);
243  } else {
244  // this can happen if both flag and game_config::images::flag are empty.
245  ERR_DP << "Missing flag for team" << t.side() << "\n";
246  }
247 }
248 
249 void display::set_team(std::size_t teamindex, bool show_everything)
250 {
251  assert(teamindex < get_teams().size());
252  currentTeam_ = teamindex;
253 
254  if(!show_everything) {
255  labels().set_team(&get_teams()[teamindex]);
256  dont_show_all_ = true;
257  } else {
258  labels().set_team(nullptr);
259  dont_show_all_ = false;
260  }
261 
263 
264  if(std::shared_ptr<wb::manager> w = wb_.lock()) {
265  w->on_viewer_change(teamindex);
266  }
267 }
268 
269 void display::set_playing_team(std::size_t teamindex)
270 {
271  assert(teamindex < get_teams().size());
272  activeTeam_ = teamindex;
273 }
274 
276  const std::string& img,
277  const std::string& halo,
278  const std::string& team_name,
279  const std::string& item_id,
280  bool visible_under_fog)
281 {
282  if(halo_man_) {
283  const halo::handle halo_handle = halo_man_->add(
284  get_location_x(loc) + hex_size() / 2,
285  get_location_y(loc) + hex_size() / 2, halo, loc
286  );
287 
288  get_overlays().emplace(loc, overlay(img, halo, halo_handle, team_name, item_id, visible_under_fog));
289  }
290 }
291 
293 {
294  get_overlays().erase(loc);
295 }
296 
297 void display::remove_single_overlay(const map_location& loc, const std::string& toDelete)
298 {
299  // Iterate through the values with key of loc
300  auto itors = get_overlays().equal_range(loc);
301 
302  while(itors.first != itors.second) {
303  const overlay& o = itors.first->second;
304 
305  if(o.image == toDelete || o.halo == toDelete || o.id == toDelete) {
306  get_overlays().erase(itors.first++);
307  } else {
308  ++itors.first;
309  }
310  }
311 }
312 
314 {
315  if(loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end()) {
316  exclusive_unit_draw_requests_[loc] = unit.id();
317  return true;
318  } else {
319  return false;
320  }
321 }
322 
324 {
325  std::string id = "";
326  if(loc.valid()) {
328  // id will be set to the default "" string by the [] operator if the map doesn't have anything for that loc.
330  }
331 
332  return id;
333 }
334 
336 {
337  static time_of_day tod;
338  return tod;
339 }
340 
341 void display::update_tod(const time_of_day* tod_override)
342 {
343  const time_of_day* tod = tod_override;
344  if(tod == nullptr) {
345  tod = &get_time_of_day();
346  }
347 
348  const tod_color col = color_adjust_ + tod->color;
349  image::set_color_adjustment(col.r, col.g, col.b);
350 }
351 
352 void display::adjust_color_overlay(int r, int g, int b)
353 {
354  color_adjust_ = tod_color(r, g, b);
355  update_tod();
356 }
357 
358 void display::fill_images_list(const std::string& prefix, std::vector<std::string>& images)
359 {
360  if(prefix == "") {
361  return;
362  }
363 
364  // search prefix.png, prefix1.png, prefix2.png ...
365  for(int i = 0;; ++i) {
366  std::ostringstream s;
367  s << prefix;
368 
369  if(i != 0) {
370  s << i;
371  }
372 
373  s << ".png";
374 
375  if(image::exists(s.str())) {
376  images.push_back(s.str());
377  } else if(i > 0) {
378  break;
379  }
380  }
381 
382  if(images.empty()) {
383  images.emplace_back();
384  }
385 }
386 
387 const std::string& display::get_variant(const std::vector<std::string>& variants, const map_location& loc) const
388 {
389  // TODO use better noise function
390  return variants[std::abs(loc.x + loc.y) % variants.size()];
391 }
392 
394 {
395  builder_->rebuild_all();
396 }
397 
399 {
400  builder_->reload_map();
401 }
402 
404 {
405  dc_ = dc;
406  builder_->change_map(&get_map()); // TODO: Should display_context own and initialize the builder object?
407 }
408 
410 {
411  halo_man_.reset(new halo::manager());
412 }
413 
415 {
416  halo_man_.reset(&halo_man);
417 }
418 
419 void display::blindfold(bool value)
420 {
421  if(value == true) {
422  ++blindfold_ctr_;
423  } else {
424  --blindfold_ctr_;
425  }
426 }
427 
429 {
430  return blindfold_ctr_ > 0;
431 }
432 
433 const SDL_Rect& display::max_map_area() const
434 {
435  static SDL_Rect max_area {0, 0, 0, 0};
436 
437  // hex_size() is always a multiple of 4 and hex_width() a multiple of 3,
438  // so there shouldn't be off-by-one-errors due to rounding.
439  // To display a hex fully on screen, a little bit extra space is needed.
440  // Also added the border two times.
441  max_area.w = static_cast<int>((get_map().w() + 2 * theme_.border().size + 1.0 / 3.0) * hex_width());
442  max_area.h = static_cast<int>((get_map().h() + 2 * theme_.border().size + 0.5) * hex_size());
443 
444  return max_area;
445 }
446 
447 const SDL_Rect& display::map_area() const
448 {
449  static SDL_Rect max_area;
450  max_area = max_map_area();
451 
452  // if it's for map_screenshot, maximize and don't recenter
453  if(map_screenshot_) {
454  return max_area;
455  }
456 
457  static SDL_Rect res;
458  res = map_outside_area();
459 
460  // map is smaller, center
461  if(max_area.w < res.w) {
462  res.x += (res.w - max_area.w) / 2;
463  res.w = max_area.w;
464  }
465 
466  // map is smaller, center
467  if(max_area.h < res.h) {
468  res.y += (res.h - max_area.h) / 2;
469  res.h = max_area.h;
470  }
471 
472  return res;
473 }
474 
475 const SDL_Rect display::map_outside_area() const
476 {
478 }
479 
480 bool display::outside_area(const SDL_Rect& area, const int x, const int y)
481 {
482  const int x_thresh = hex_size();
483  const int y_thresh = hex_size();
484  return (x < area.x || x > area.x + area.w - x_thresh || y < area.y || y > area.y + area.h - y_thresh);
485 }
486 
487 // This function uses the screen as reference
488 const map_location display::hex_clicked_on(int xclick, int yclick) const
489 {
490  const SDL_Rect& rect = map_area();
491  if(sdl::point_in_rect(xclick, yclick, rect) == false) {
492  return map_location();
493  }
494 
495  xclick -= rect.x;
496  yclick -= rect.y;
497 
498  return pixel_position_to_hex(xpos_ + xclick, ypos_ + yclick);
499 }
500 
501 // This function uses the rect of map_area as reference
503 {
504  // adjust for the border
505  x -= static_cast<int>(theme_.border().size * hex_width());
506  y -= static_cast<int>(theme_.border().size * hex_size());
507 
508  // The editor can modify the border and this will result in a negative y
509  // value. Instead of adding extra cases we just shift the hex. Since the
510  // editor doesn't use the direction this is no problem.
511  const int offset = y < 0 ? 1 : 0;
512  if(offset) {
513  x += hex_width();
514  y += hex_size();
515  }
516 
517  const int s = hex_size();
518  const int tesselation_x_size = hex_width() * 2;
519  const int tesselation_y_size = s;
520  const int x_base = x / tesselation_x_size * 2;
521  const int x_mod = x % tesselation_x_size;
522  const int y_base = y / tesselation_y_size;
523  const int y_mod = y % tesselation_y_size;
524 
525  int x_modifier = 0;
526  int y_modifier = 0;
527 
528  if(y_mod < tesselation_y_size / 2) {
529  if((x_mod * 2 + y_mod) < (s / 2)) {
530  x_modifier = -1;
531  y_modifier = -1;
532  } else if((x_mod * 2 - y_mod) < (s * 3 / 2)) {
533  x_modifier = 0;
534  y_modifier = 0;
535  } else {
536  x_modifier = 1;
537  y_modifier = -1;
538  }
539  } else {
540  if((x_mod * 2 - (y_mod - s / 2)) < 0) {
541  x_modifier = -1;
542  y_modifier = 0;
543  } else if((x_mod * 2 + (y_mod - s / 2)) < s * 2) {
544  x_modifier = 0;
545  y_modifier = 0;
546  } else {
547  x_modifier = 1;
548  y_modifier = 0;
549  }
550  }
551 
552  return map_location(x_base + x_modifier - offset, y_base + y_modifier - offset);
553 }
554 
555 const rect_of_hexes display::hexes_under_rect(const SDL_Rect& r) const
556 {
557  rect_of_hexes res;
558 
559  if(r.w <= 0 || r.h <= 0) {
560  return res;
561  }
562 
563  SDL_Rect map_rect = map_area();
564 
565  // translate rect coordinates from screen-based to map_area-based
566  int x = xpos_ - map_rect.x + r.x;
567  int y = ypos_ - map_rect.y + r.y;
568 
569  // we use the "double" type to avoid important rounding error (size of an hex!)
570  // we will also need to use std::floor to avoid bad rounding at border (negative values)
571  double tile_width = hex_width();
572  double tile_size = hex_size();
573  double border = theme_.border().size;
574 
575  // we minus "0.(3)", for horizontal imbrication.
576  // reason is: two adjacent hexes each overlap 1/4 of their width, so for
577  // grid calculation 3/4 of tile width is used, which by default gives
578  // 18/54=0.(3). Note that, while tile_width is zoom dependent, 0.(3) is not.
579  res.left = static_cast<int>(std::floor(-border + x / tile_width - 0.3333333));
580 
581  // we remove 1 pixel of the rectangle dimensions
582  // (the rounded division take one pixel more than needed)
583  res.right = static_cast<int>(std::floor(-border + (x + r.w - 1) / tile_width));
584 
585  // for odd x, we must shift up one half-hex. Since x will vary along the edge,
586  // we store here the y values for even and odd x, respectively
587  res.top[0] = static_cast<int>(std::floor(-border + y / tile_size));
588  res.top[1] = static_cast<int>(std::floor(-border + y / tile_size - 0.5));
589  res.bottom[0] = static_cast<int>(std::floor(-border + (y + r.h - 1) / tile_size));
590  res.bottom[1] = static_cast<int>(std::floor(-border + (y + r.h - 1) / tile_size - 0.5));
591 
592  // TODO: in some rare cases (1/16), a corner of the big rect is on a tile
593  // (the 72x72 rectangle containing the hex) but not on the hex itself
594  // Can maybe be optimized by using pixel_position_to_hex
595 
596  return res;
597 }
598 
600 {
601  return hexes_under_rect(map_area());
602 }
603 
605 {
606  return currentTeam_ < get_teams().size();
607 }
608 
609 bool display::shrouded(const map_location& loc) const
610 {
611  return is_blindfolded() || (dont_show_all_ && get_teams()[currentTeam_].shrouded(loc));
612 }
613 
614 bool display::fogged(const map_location& loc) const
615 {
616  return is_blindfolded() || (dont_show_all_ && get_teams()[currentTeam_].fogged(loc));
617 }
618 
620 {
621  return static_cast<int>(map_area().x + (loc.x + theme_.border().size) * hex_width() - xpos_);
622 }
623 
625 {
626  return static_cast<int>(map_area().y + (loc.y + theme_.border().size) * zoom_ - ypos_ + (is_odd(loc.x) ? zoom_/2 : 0));
627 }
628 
630 {
631  return {
632  get_location_x(loc),
633  get_location_y(loc)
634  };
635 }
636 
638 {
639  // TODO: don't return location for this,
640  // instead directly scroll to the clicked pixel position
641 
642  if(!sdl::point_in_rect(x, y, minimap_area())) {
643  return map_location();
644  }
645 
646  // we transform the coordinates from minimap to the full map image
647  // probably more adjustments to do (border, minimap shift...)
648  // but the mouse and human capacity to evaluate the rectangle center
649  // is not pixel precise.
650  int px = (x - minimap_location_.x) * get_map().w() * hex_width() / std::max(minimap_location_.w, 1);
651  int py = (y - minimap_location_.y) * get_map().h() * hex_size() / std::max(minimap_location_.h, 1);
652 
653  map_location loc = pixel_position_to_hex(px, py);
654  loc.x = utils::clamp(loc.x, 0, get_map().w() - 1);
655  loc.y = utils::clamp(loc.x, 0, get_map().h() - 1);
656 
657  return loc;
658 }
659 
660 surface display::screenshot(bool map_screenshot)
661 {
662  if(!map_screenshot) {
663  // Use make_neutral_surface() to copy surface content
664  // TODO: convert to texture handling
665  //return make_neutral_surface(video_.getSurface());
666  return surface(nullptr);
667  }
668 
669  if(get_map().empty()) {
670  ERR_DP << "No map loaded, cannot create a map screenshot.\n";
671  return nullptr;
672  }
673 
674  const SDL_Rect area = max_map_area();
675  surface res = create_neutral_surface(area.w, area.h);
676 
677  // Memory problem?
678  if(res == nullptr) {
679  ERR_DP << "Could not create screenshot surface, try zooming out.\n";
680  return nullptr;
681  }
682 
683  // Back up the current map viewport position and move to top-left.
684  const int old_xpos = xpos_;
685  const int old_ypos = ypos_;
686  xpos_ = 0;
687  ypos_ = 0;
688 
689  // Reroute render output to a separate texture .
690  texture output_texture(area.w, area.h, SDL_TEXTUREACCESS_TARGET);
691  const render_target_setter target_setter(output_texture);
692 
693  map_screenshot_ = true;
694 
695  DBG_DP << "draw() call for map screenshot\n";
696  draw();
697 
698  map_screenshot_ = false;
699 
700  // Restore map viewport position
701  xpos_ = old_xpos;
702  ypos_ = old_ypos;
703 
704  // Copy the texture data to the output surface.
705  SDL_RenderReadPixels(video_.get_renderer(), &area, SDL_PIXELFORMAT_ARGB8888, res->pixels, res->pitch);
706  return res;
707 }
708 
709 static const std::string& get_direction(std::size_t n)
710 {
711  static const std::array<std::string, 6> dirs {{"-n", "-ne", "-se", "-s", "-sw", "-nw"}};
712  return dirs[n >= dirs.size() ? 0 : n];
713 }
714 
716 {
717  std::vector<std::string> names;
718 
719  adjacent_loc_array_t adjacent;
720  get_adjacent_tiles(loc, adjacent.data());
721 
722  enum VISIBILITY { FOG = 0, SHROUD = 1, CLEAR = 2 };
723  std::array<VISIBILITY, 6> tiles;
724 
725  const std::array<const std::string*, 2> image_prefix {{&game_config::fog_prefix, &game_config::shroud_prefix}};
726 
727  for(unsigned i = 0; i < tiles.size(); ++i) {
728  if(shrouded(adjacent[i])) {
729  tiles[i] = SHROUD;
730  } else if(!fogged(loc) && fogged(adjacent[i])) {
731  tiles[i] = FOG;
732  } else {
733  tiles[i] = CLEAR;
734  }
735  }
736 
737  for(int v = FOG; v != CLEAR; ++v) {
738  // Find somewhere that doesn't have overlap to use as a starting point
739  int start;
740  for(start = 0; start != 6; ++start) {
741  if(tiles[start] != v) {
742  break;
743  }
744  }
745 
746  if(start == 6) {
747  // Completely surrounded by fog or shroud. This might have a special graphic.
748  const std::string name = *image_prefix[v] + "-all.png";
749  if(image::exists(name)) {
750  names.push_back(name);
751  // Proceed to the next visibility (fog -> shroud -> clear).
752  continue;
753  }
754 
755  // No special graphic found. We'll just combine some other images
756  // and hope it works out.
757  start = 0;
758  }
759 
760  // Find all the directions overlap occurs from
761  for(int i = (start + 1) % 6, cap1 = 0; i != start && cap1 != 6; ++cap1) {
762  if(tiles[i] == v) {
763  std::ostringstream stream;
764  stream << *image_prefix[v];
765 
766  std::string name;
767  for(int cap2 = 0; v == tiles[i] && cap2 != 6; i = (i + 1) % 6, ++cap2) {
768  stream << get_direction(i);
769 
770  if(!image::exists(stream.str() + ".png")) {
771  // If we don't have any surface at all,
772  // then move onto the next overlapped area
773  if(name.empty()) {
774  i = (i + 1) % 6;
775  }
776  break;
777  } else {
778  name = stream.str();
779  }
780  }
781 
782  if(!name.empty()) {
783  names.push_back(name + ".png");
784  }
785  } else {
786  i = (i + 1) % 6;
787  }
788  }
789  }
790 
791  // Now render the images
792  for(const std::string& name : names) {
793  render_scaled_to_zoom(image::get_texture(name), loc); // TODO: image_type
794  }
795 }
796 
798 {
799  benchmark = !benchmark;
800 }
801 
803 {
804  debug_foreground = !debug_foreground;
805 }
806 
808 {
809  if(video_.update_locked()) {
810  return;
811  }
812 
813  if(preferences::show_fps() || benchmark) {
814  static int frames = 0;
815  ++frames;
816 
817  const int sample_freq = 10;
818  if(frames == sample_freq) {
819  const auto minmax_it = std::minmax_element(frametimes_.begin(), frametimes_.end());
820  const unsigned render_avg = std::accumulate(frametimes_.begin(), frametimes_.end(), 0) / frametimes_.size();
821  const int avg_fps = calculate_fps(render_avg);
822  const int max_fps = calculate_fps(*minmax_it.first);
823  const int min_fps = calculate_fps(*minmax_it.second);
824  frames = 0;
825 
826  if(fps_handle_ != 0) {
828  fps_handle_ = 0;
829  }
830 
831  std::ostringstream stream;
832  stream << "<tt> min/avg/max/act</tt>\n";
833  stream << "<tt>FPS: " << std::setfill(' ') << std::setw(3) << min_fps << '/'<< std::setw(3) << avg_fps << '/' << std::setw(3) << max_fps << '/' << std::setw(3) << fps_actual_ << "</tt>\n";
834  stream << "<tt>Time: " << std::setfill(' ') << std::setw(3) << *minmax_it.first << '/' << std::setw(3) << render_avg << '/' << std::setw(3) << *minmax_it.second << " ms</tt>\n";
835  if(game_config::debug) {
836  stream << "\nhex: " << drawn_hexes_ * 1.0 / sample_freq;
837  }
838 
839  drawn_hexes_ = 0;
840 
841  font::floating_label flabel(stream.str());
842  flabel.set_font_size(12);
843  flabel.set_color(benchmark ? font::BAD_COLOR : font::NORMAL_COLOR);
844  flabel.set_position(10, 100);
845  flabel.set_alignment(font::LEFT_ALIGN);
846 
848  }
849  } else if(fps_handle_ != 0) {
851  fps_handle_ = 0;
852  drawn_hexes_ = 0;
853  }
854 }
855 
857 {
858  const std::string& image = theme_.border().background_image;
859  SDL_Rect area = map_outside_area();
860 
861  // No background image, just fill in black.
862  if(image.empty()) {
863  sdl::fill_rectangle(area, color_t(0, 0, 0));
864  return;
865  }
866 
867  const texture background(image::get_texture(image));
868  if(background.null()) {
869  return;
870  }
871 
872  // TODO: should probably tile this as before.
873  video_.render_copy(background, nullptr, &area);
874 }
875 
877  const std::string& text,
878  std::size_t font_size,
879  color_t color,
880  int fl_label_id,
881  double x_in_hex,
882  double y_in_hex)
883 {
884  if(text.empty()) {
885  return fl_label_id;
886  }
887 
888  const std::size_t font_sz = static_cast<std::size_t>(font_size * get_zoom_factor());
889 
890  const int x = get_location_x(loc) /*- text_surf->w / 2*/ + static_cast<int>(x_in_hex * hex_size());
891  const int y = get_location_y(loc) /*- text_surf->h / 2*/ + static_cast<int>(y_in_hex * hex_size());
892 
893  // We were given a label id, remove it.
894  if(fl_label_id != 0) {
895  font::remove_floating_label(fl_label_id);
896  }
897 
898  font::floating_label flabel(text);
899  flabel.set_font_size(font_sz);
900  flabel.set_color(color);
901  flabel.set_position(x, y);
904 
905  return font::add_floating_label(flabel);
906 }
907 
909 {
910  selectedHex_ = hex;
911 }
912 
914 {
915  mouseoverHex_ = hex;
916 }
917 
918 void display::set_diagnostic(const std::string& msg)
919 {
920  if(diagnostic_label_ != 0) {
922  diagnostic_label_ = 0;
923  }
924 
925  if(!msg.empty()) {
926  font::floating_label flabel(msg);
929  flabel.set_position(300, 50);
931 
933  }
934 }
935 
936 void display::announce(const std::string& message, const color_t& color, const announce_options& options)
937 {
938  if(options.discard_previous) {
939  font::remove_floating_label(prevLabel);
940  }
941 
942  font::floating_label flabel(message);
944  flabel.set_color(color);
945  flabel.set_position(map_outside_area().w / 2, map_outside_area().h / 3);
946  flabel.set_lifetime(options.lifetime);
948 
949  prevLabel = font::add_floating_label(flabel);
950 }
951 
952 bool display::scroll(int xmove, int ymove, bool force)
953 {
954  if(view_locked_ && !force) {
955  return false;
956  }
957 
958  // No move offset, do nothing.
959  if(xmove == 0 && ymove == 0) {
960  return false;
961  }
962 
963  int new_x = xpos_ + xmove;
964  int new_y = ypos_ + ymove;
965 
966  bounds_check_position(new_x, new_y);
967 
968  // Camera position doesn't change, exit.
969  if(xpos_ == new_x && ypos_ == new_y) {
970  return false;
971  }
972 
973  const int diff_x = xpos_ - new_x;
974  const int diff_y = ypos_ - new_y;
975 
976  xpos_ = new_x;
977  ypos_ = new_y;
978 
979  /* Adjust floating label positions. This only affects labels whose position is anchored
980  * to the map instead of the screen. In order to do that, we want to adjust their drawing
981  * coordinates in the opposite direction of the screen scroll.
982  *
983  * The check a few lines up prevents any scrolling from happening if the camera position
984  * doesn't change. Without that, the label still scroll even when the map edge is reached.
985  * If that's removed, the following formula should work instead:
986  *
987  * const int label_[x,y]_adjust = [x,y]pos_ - new_[x,y];
988  */
989  font::scroll_floating_labels(diff_x, diff_y);
990 
992 
994 
995  return true;
996 }
997 
999 {
1000  return zoom_ == MaxZoom;
1001 }
1002 
1004 {
1005  return zoom_ == MinZoom;
1006 }
1007 
1008 bool display::set_zoom(bool increase)
1009 {
1010  // Ensure we don't try to access nonexistent vector indices.
1011  zoom_index_ = utils::clamp(increase ? zoom_index_ + 1 : zoom_index_ - 1, 0, final_zoom_index);
1012 
1013  // No validation check is needed in the next step since we've already set the index here and
1014  // know the new zoom value is indeed valid.
1015  return set_zoom(zoom_levels[zoom_index_], false);
1016 }
1017 
1018 bool display::set_zoom(unsigned int amount, const bool validate_value_and_set_index)
1019 {
1020  unsigned int new_zoom = utils::clamp(amount, MinZoom, MaxZoom);
1021 
1022  LOG_DP << "new_zoom = " << new_zoom << std::endl;
1023 
1024  if(new_zoom == zoom_) {
1025  return false;
1026  }
1027 
1028  // Confirm this is indeed a valid zoom level.
1029  if(validate_value_and_set_index) {
1030  auto iter = std::lower_bound(zoom_levels.begin(), zoom_levels.end(), new_zoom);
1031 
1032  if(iter == zoom_levels.end()) {
1033  // This should never happen, since the value was already clamped earlier
1034  return false;
1035  } else if(iter != zoom_levels.begin()) {
1036  float diff = *iter - *(iter - 1);
1037  float lower = (new_zoom - *(iter - 1)) / diff;
1038  float upper = (*iter - new_zoom) / diff;
1039  if(lower < upper) {
1040  // It's actually closer to the previous element.
1041  iter--;
1042  }
1043  }
1044 
1045  new_zoom = *iter;
1046  zoom_index_ = std::distance(zoom_levels.begin(), iter);
1047  }
1048 
1049  const SDL_Rect& area = map_area();
1050 
1051  // Turn the zoom factor to a double in order to avoid rounding errors.
1052  double zoom_factor = static_cast<double>(new_zoom) / static_cast<double>(zoom_);
1053 
1054  xpos_ = std::round(((xpos_ + area.w / 2) * zoom_factor) - (area.w / 2));
1055  ypos_ = std::round(((ypos_ + area.h / 2) * zoom_factor) - (area.h / 2));
1056 
1057  zoom_ = new_zoom;
1059  if(zoom_ != DefaultZoom) {
1060  last_zoom_ = zoom_;
1061  }
1062 
1064 
1066 
1067  // Forces a redraw after zooming.
1068  // This prevents some graphic glitches from occurring.
1069  // draw();
1070 
1071  return true;
1072 }
1073 
1075 {
1076  if(zoom_ != DefaultZoom) {
1077  last_zoom_ = zoom_;
1079  } else {
1080  // When we are already at the default zoom,
1081  // switch to the last zoom used
1083  }
1084 }
1085 
1087 {
1088  int x = get_location_x(loc);
1089  int y = get_location_y(loc);
1090  return !outside_area(map_area(), x, y);
1091 }
1092 
1094 {
1095  int x = get_location_x(loc);
1096  int y = get_location_y(loc);
1097  const SDL_Rect& area = map_area();
1098  int hw = hex_width(), hs = hex_size();
1099  return x + hs >= area.x - hw && x < area.x + area.w + hw && y + hs >= area.y - hs && y < area.y + area.h + hs;
1100 }
1101 
1102 void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force)
1103 {
1104  if(!force && (view_locked_ || !preferences::scroll_to_action())) {
1105  return;
1106  }
1107 
1108  if(video_.update_locked()) {
1109  return;
1110  }
1111 
1112  const SDL_Rect area = map_area();
1113  const int xmove_expected = screenxpos - (area.x + area.w / 2);
1114  const int ymove_expected = screenypos - (area.y + area.h / 2);
1115 
1116  int xpos = xpos_ + xmove_expected;
1117  int ypos = ypos_ + ymove_expected;
1118  bounds_check_position(xpos, ypos);
1119  int xmove = xpos - xpos_;
1120  int ymove = ypos - ypos_;
1121 
1122  if(scroll_type == WARP || scroll_type == ONSCREEN_WARP || turbo_speed() > 2.0 || preferences::scroll_speed() > 99) {
1123  scroll(xmove, ymove, true);
1124  // draw();
1125  return;
1126  }
1127 
1128  // Doing an animated scroll, with acceleration etc.
1129 
1130  int x_old = 0;
1131  int y_old = 0;
1132 
1133  const double dist_total = std::hypot(xmove, ymove);
1134  double dist_moved = 0.0;
1135 
1136  int t_prev = SDL_GetTicks();
1137 
1138  double velocity = 0.0;
1139  while(dist_moved < dist_total) {
1141 
1142  int t = SDL_GetTicks();
1143  double dt = (t - t_prev) / 1000.0;
1144  if(dt > 0.200) {
1145  // Do not skip too many frames on slow PCs
1146  dt = 0.200;
1147  }
1148  t_prev = t;
1149 
1150  const double accel_time = 0.3 / turbo_speed(); // seconds until full speed is reached
1151  const double decel_time = 0.4 / turbo_speed(); // seconds from full speed to stop
1152 
1153  double velocity_max = preferences::scroll_speed() * 60.0;
1154  velocity_max *= turbo_speed();
1155  double accel = velocity_max / accel_time;
1156  double decel = velocity_max / decel_time;
1157 
1158  // If we started to decelerate now, where would we stop?
1159  double stop_time = velocity / decel;
1160  double dist_stop = dist_moved + velocity * stop_time - 0.5 * decel * stop_time * stop_time;
1161 
1162  if(dist_stop > dist_total || velocity > velocity_max) {
1163  velocity -= decel * dt;
1164  if(velocity < 1.0) {
1165  velocity = 1.0;
1166  }
1167  } else {
1168  velocity += accel * dt;
1169  if(velocity > velocity_max) {
1170  velocity = velocity_max;
1171  }
1172  }
1173 
1174  dist_moved += velocity * dt;
1175  if(dist_moved > dist_total) {
1176  dist_moved = dist_total;
1177  }
1178 
1179  int x_new = std::round(xmove * dist_moved / dist_total);
1180  int y_new = std::round(ymove * dist_moved / dist_total);
1181 
1182  int dx = x_new - x_old;
1183  int dy = y_new - y_old;
1184 
1185  scroll(dx, dy, true);
1186  x_old += dx;
1187  y_old += dy;
1188  // draw();
1189  }
1190 }
1191 
1192 void display::scroll_to_tile(const map_location& loc, SCROLL_TYPE scroll_type, bool check_fogged, bool force)
1193 {
1194  if(get_map().on_board(loc) == false) {
1195  ERR_DP << "Tile at " << loc << " isn't on the map, can't scroll to the tile." << std::endl;
1196  return;
1197  }
1198 
1199  std::vector<map_location> locs;
1200  locs.push_back(loc);
1201 
1202  scroll_to_tiles(locs, scroll_type, check_fogged, false, 0.0, force);
1203 }
1204 
1206  map_location loc2,
1207  SCROLL_TYPE scroll_type,
1208  bool check_fogged,
1209  double add_spacing,
1210  bool force)
1211 {
1212  std::vector<map_location> locs;
1213  locs.push_back(loc1);
1214  locs.push_back(loc2);
1215  scroll_to_tiles(locs, scroll_type, check_fogged, false, add_spacing, force);
1216 }
1217 
1218 void display::scroll_to_tiles(const std::vector<map_location>::const_iterator& begin,
1219  const std::vector<map_location>::const_iterator& end,
1220  SCROLL_TYPE scroll_type,
1221  bool check_fogged,
1222  bool only_if_possible,
1223  double add_spacing,
1224  bool force)
1225 {
1226  // basically we calculate the min/max coordinates we want to have on-screen
1227  int minx = 0;
1228  int maxx = 0;
1229  int miny = 0;
1230  int maxy = 0;
1231  bool valid = false;
1232 
1233  for(std::vector<map_location>::const_iterator itor = begin; itor != end; ++itor) {
1234  if(get_map().on_board(*itor) == false)
1235  continue;
1236  if(check_fogged && fogged(*itor))
1237  continue;
1238 
1239  int x = get_location_x(*itor);
1240  int y = get_location_y(*itor);
1241 
1242  if(!valid) {
1243  minx = x;
1244  maxx = x;
1245  miny = y;
1246  maxy = y;
1247 
1248  valid = true;
1249  } else {
1250  int minx_new = std::min<int>(minx, x);
1251  int miny_new = std::min<int>(miny, y);
1252  int maxx_new = std::max<int>(maxx, x);
1253  int maxy_new = std::max<int>(maxy, y);
1254 
1255  SDL_Rect r = map_area();
1256  r.x = minx_new;
1257  r.y = miny_new;
1258 
1259  if(outside_area(r, maxx_new, maxy_new)) {
1260  // we cannot fit all locations to the screen
1261  if(only_if_possible) {
1262  return;
1263  }
1264 
1265  break;
1266  }
1267 
1268  minx = minx_new;
1269  miny = miny_new;
1270  maxx = maxx_new;
1271  maxy = maxy_new;
1272  }
1273  }
1274 
1275  // if everything is fogged or the location list is empty
1276  if(!valid) {
1277  return;
1278  }
1279 
1280  if(scroll_type == ONSCREEN || scroll_type == ONSCREEN_WARP) {
1281  SDL_Rect r = map_area();
1282  int spacing = std::round(add_spacing * hex_size());
1283  r.x += spacing;
1284  r.y += spacing;
1285  r.w -= 2 * spacing;
1286  r.h -= 2 * spacing;
1287 
1288  if(!outside_area(r, minx, miny) && !outside_area(r, maxx, maxy)) {
1289  return;
1290  }
1291  }
1292 
1293  // let's do "normal" rectangle math from now on
1294  SDL_Rect locs_bbox {
1295  minx,
1296  miny,
1297  maxx - minx + hex_size(),
1298  maxy - miny + hex_size()
1299  };
1300 
1301  // target the center
1302  int target_x = locs_bbox.x + locs_bbox.w / 2;
1303  int target_y = locs_bbox.y + locs_bbox.h / 2;
1304 
1305  if(scroll_type == ONSCREEN || scroll_type == ONSCREEN_WARP) {
1306  // when doing an ONSCREEN scroll we do not center the target unless needed
1307  SDL_Rect r = map_area();
1308  int map_center_x = r.x + r.w / 2;
1309  int map_center_y = r.y + r.h / 2;
1310 
1311  int h = r.h;
1312  int w = r.w;
1313 
1314  // we do not want to be only inside the screen rect, but center a bit more
1315  double inside_frac = 0.5; // 0.0 = always center the target, 1.0 = scroll the minimum distance
1316  w = static_cast<int>(w * inside_frac);
1317  h = static_cast<int>(h * inside_frac);
1318 
1319  // shrink the rectangle by the size of the locations rectangle we found
1320  // such that the new task to fit a point into a rectangle instead of rectangle into rectangle
1321  w -= locs_bbox.w;
1322  h -= locs_bbox.h;
1323 
1324  if (w < 1) w = 1;
1325  if (h < 1) h = 1;
1326 
1327  r.x = target_x - w / 2;
1328  r.y = target_y - h / 2;
1329  r.w = w;
1330  r.h = h;
1331 
1332  // now any point within r is a possible target to scroll to
1333  // we take the one with the minimum distance to map_center
1334  // which will always be at the border of r
1335 
1336  if(map_center_x < r.x) {
1337  target_x = r.x;
1338  target_y = utils::clamp(map_center_y, r.y, r.y + r.h - 1);
1339  } else if(map_center_x > r.x + r.w - 1) {
1340  target_x = r.x + r.w - 1;
1341  target_y = utils::clamp(map_center_y, r.y, r.y + r.h - 1);
1342  } else if(map_center_y < r.y) {
1343  target_y = r.y;
1344  target_x = utils::clamp(map_center_x, r.x, r.x + r.w - 1);
1345  } else if(map_center_y > r.y + r.h - 1) {
1346  target_y = r.y + r.h - 1;
1347  target_x = utils::clamp(map_center_x, r.x, r.x + r.w - 1);
1348  } else {
1349  ERR_DP << "Bug in the scrolling code? Looks like we would not need to scroll after all..." << std::endl;
1350  // keep the target at the center
1351  }
1352  }
1353 
1354  scroll_to_xy(target_x, target_y, scroll_type, force);
1355 }
1356 
1358 {
1359  const unsigned int orig_zoom = zoom_;
1360 
1362 
1364 
1365  if(zoom_ != orig_zoom) {
1367  }
1368 }
1369 
1370 void display::bounds_check_position(int& xpos, int& ypos) const
1371 {
1372  const int tile_width = hex_width();
1373 
1374  // Adjust for the border 2 times
1375  const int xend = static_cast<int>(tile_width * (get_map().w() + 2 * theme_.border().size) + tile_width / 3);
1376  const int yend = static_cast<int>(zoom_ * (get_map().h() + 2 * theme_.border().size) + zoom_ / 2);
1377 
1378  xpos = utils::clamp(xpos, 0, xend - map_area().w);
1379  ypos = utils::clamp(ypos, 0, yend - map_area().h);
1380 }
1381 
1382 double display::turbo_speed() const
1383 {
1384  bool res = turbo_;
1385  if(keys_[SDLK_LSHIFT] || keys_[SDLK_RSHIFT]) {
1386  res = !res;
1387  }
1388 
1389  res |= video_.faked();
1390  if(res) {
1391  return turbo_speed_;
1392  }
1393 
1394  return 1.0;
1395 }
1396 
1398 {
1399  idle_anim_rate_ = std::pow(2.0, -rate / 10.0);
1400 }
1401 
1403 {
1404  return *map_labels_;
1405 }
1406 
1408 {
1409  return *map_labels_;
1410 }
1411 
1412 const SDL_Rect display::get_clip_rect()
1413 {
1414  return map_area();
1415 }
1416 
1418 {
1419  return image::TOD_COLORED;
1420 }
1421 
1423 {
1425 
1427  if(animate_map_) {
1428  for(const map_location& loc : get_visible_hexes()) {
1429  if(shrouded(loc)) {
1430  continue;
1431  }
1432 
1433  builder_->update_animation(loc);
1434  }
1435  }
1436 
1437  for(const unit& u : get_units()) {
1438  u.anim_comp().refresh();
1439  }
1440 
1441  for(const unit* u : *fake_unit_man_) {
1442  u->anim_comp().refresh();
1443  }
1444 }
1445 
1447 {
1448  for(const unit& u : get_units()) {
1449  u.anim_comp().set_standing();
1450  }
1451 }
1452 
1454 {
1455  for(const map_location& loc : arrow.get_path()) {
1456  arrows_map_[loc].push_back(&arrow);
1457  }
1458 }
1459 
1461 {
1462  for(const map_location& loc : arrow.get_path()) {
1463  arrows_map_[loc].remove(&arrow);
1464  }
1465 }
1466 
1468 {
1469  for(const map_location& loc : arrow.get_previous_path()) {
1470  arrows_map_[loc].remove(&arrow);
1471  }
1472 
1473  for(const map_location& loc : arrow.get_path()) {
1474  arrows_map_[loc].push_back(&arrow);
1475  }
1476 }
1477 
1479 {
1480  const SDL_Rect& rect = map_area();
1481  return pixel_position_to_hex(xpos_ + rect.x + rect.w / 2, ypos_ + rect.y + rect.h / 2);
1482 }
1483 
1484 void display::write(config& cfg) const
1485 {
1486  cfg["view_locked"] = view_locked_;
1487  cfg["color_adjust_red"] = color_adjust_.r;
1488  cfg["color_adjust_green"] = color_adjust_.g;
1489  cfg["color_adjust_blue"] = color_adjust_.b;
1490 
1491  get_middle_location().write(cfg.add_child("location"));
1492 }
1493 
1494 void display::read(const config& cfg)
1495 {
1496  view_locked_ = cfg["view_locked"].to_bool(false);
1497  color_adjust_.r = cfg["color_adjust_red"].to_int(0);
1498  color_adjust_.g = cfg["color_adjust_green"].to_int(0);
1499  color_adjust_.b = cfg["color_adjust_blue"].to_int(0);
1500 }
1501 
1502 //
1503 // NEW RENDERING CODE =========================================================================
1504 //
1505 
1507 {
1508  // DO NOTHING
1509 }
1510 
1511 void display::draw_visible_hexes(const rect_of_hexes& visible_hexes, TERRAIN_TYPE layer)
1512 {
1513  assert(builder_);
1514 
1515  drawn_hexes_ = 0;
1516 
1517  terrain_builder::TERRAIN_TYPE builder_terrain_type = layer == FOREGROUND
1520 
1521  for(const map_location& loc : visible_hexes) {
1522  if(shrouded(loc)) {
1523  continue;
1524  }
1525 
1526  //image::TYPE image_type = get_image_type(loc);
1527  const time_of_day& tod = get_time_of_day(loc);
1528 
1529  // Get the image list for this location.
1530  const terrain_builder::imagelist* const terrains = builder_->get_terrain_at(loc, tod.id, builder_terrain_type);
1531  if(!terrains) {
1532  continue;
1533  }
1534 
1535 #if 0
1537 
1538  const time_of_day& tod = get_time_of_day(loc);
1539 
1540  //get all the light transitions
1541  map_location adjs[6];
1542  get_adjacent_tiles(loc,adjs);
1543 
1544  for(int d=0; d<6; ++d){
1545  /* concave
1546  _____
1547  / \
1548  / atod1 \_____
1549  \ !tod / \
1550  \_____/ atod2 \
1551  / \__\ !tod /
1552  / \_____/
1553  \ tod /
1554  \_____/*/
1555 
1556  const time_of_day& atod1 = get_time_of_day(adjs[d]);
1557  const time_of_day& atod2 = get_time_of_day(adjs[(d + 1) % 6]);
1558 
1559  if(atod1.color == tod.color || atod2.color == tod.color || atod1.color != atod2.color)
1560  continue;
1561 
1562  if(lt.empty()) {
1563  //color the full hex before adding transitions
1564  tod_color col = tod.color + color_adjust_;
1565  lt = image::get_light_string(0, col.r, col.g, col.b);
1566  }
1567 
1568  // add the directional transitions
1569  tod_color acol = atod1.color + color_adjust_;
1570  lt += image::get_light_string(d + 1, acol.r, acol.g, acol.b);
1571  }
1572  for(int d=0; d<6; ++d){
1573  /* convex 1
1574  _____
1575  / \
1576  / atod1 \_____
1577  \ !tod / \
1578  \_____/ atod2 \
1579  / \__\ tod /
1580  / \_____/
1581  \ tod /
1582  \_____/*/
1583 
1584  const time_of_day& atod1 = get_time_of_day(adjs[d]);
1585  const time_of_day& atod2 = get_time_of_day(adjs[(d + 1) % 6]);
1586 
1587  if(atod1.color == tod.color || atod1.color == atod2.color)
1588  continue;
1589 
1590  if(lt.empty()) {
1591  //color the full hex before adding transitions
1592  tod_color col = tod.color + color_adjust_;
1593  lt = image::get_light_string(0, col.r, col.g, col.b);
1594  }
1595 
1596  // add the directional transitions
1597  tod_color acol = atod1.color + color_adjust_;
1598  lt += image::get_light_string(d + 7, acol.r, acol.g, acol.b);
1599  }
1600  for(int d=0; d<6; ++d){
1601  /* convex 2
1602  _____
1603  / \
1604  / atod1 \_____
1605  \ tod / \
1606  \_____/ atod2 \
1607  / \__\ !tod /
1608  / \_____/
1609  \ tod /
1610  \_____/*/
1611 
1612  const time_of_day& atod1 = get_time_of_day(adjs[d]);
1613  const time_of_day& atod2 = get_time_of_day(adjs[(d + 1) % 6]);
1614 
1615  if(atod2.color == tod.color || atod1.color == atod2.color)
1616  continue;
1617 
1618  if(lt.empty()) {
1619  //color the full hex before adding transitions
1620  tod_color col = tod.color + color_adjust_;
1621  lt = image::get_light_string(0, col.r, col.g, col.b);
1622  }
1623 
1624  // add the directional transitions
1625  tod_color acol = atod2.color + color_adjust_;
1626  lt += image::get_light_string(d + 13, acol.r, acol.g, acol.b);
1627  }
1628 
1629  if(lt.empty()){
1630  tod_color col = tod.color + color_adjust_;
1631  if(!col.is_zero()){
1632  // no real lightmap needed but still color the hex
1633  lt = image::get_light_string(-1, col.r, col.g, col.b);
1634  }
1635  }
1636 #endif
1637 
1638  // Cache the offmap name.
1639  // Since it is themeable it can change, so don't make it static.
1640  //const std::string off_map_name = "terrain/" + theme_.border().tile_image;
1641 
1642  for(const auto& terrain : *terrains) {
1643  const image::locator& image = animate_map_
1644  ? terrain.get_current_frame()
1645  : terrain.get_first_frame();
1646 
1647  // We prevent ToD coloring and brightening of off-map tiles,
1648  // We need to test for the tile to be rendered and
1649  // not the location, since the transitions are rendered
1650  // over the offmap-terrain and these need a ToD coloring.
1651  texture tex = image::get_texture(image, image::HEXED); // TODO: scaled to hex?
1652 
1653  //const bool off_map = (image.get_filename() == off_map_name || image.get_modifications().find("NO_TOD_SHIFT()") != std::string::npos);
1654 #if 0
1655  if(off_map) {
1656  surf = image::get_image(image, off_map ? image::SCALED_TO_HEX : image_type);
1657  } else if(lt.empty()) {
1658  surf = image::get_image(image, image::SCALED_TO_HEX);
1659  } else {
1660  surf = image::get_lighted_image(image, lt, image::SCALED_TO_HEX);
1661  }
1662 #endif
1663  if(!tex.null()) {
1664  render_scaled_to_zoom(tex, loc);
1665  }
1666  }
1667 
1668  ++drawn_hexes_;
1669  }
1670 }
1671 
1672 void display::draw_gamemap()
1673 {
1674  // Currenty visible hexes.
1675  const rect_of_hexes& visible_hexes = get_visible_hexes();
1676 
1677  //
1678  // Background terrains
1679  //
1680  draw_visible_hexes(visible_hexes, BACKGROUND);
1681 
1682  //
1683  // On-map overlays, such as [item]s.
1684  //
1685  for(const auto& overlay_record : get_overlays()) {
1686  const map_location& o_loc = overlay_record.first;
1687 
1688  if(shrouded(o_loc)) {
1689  continue;
1690  }
1691 
1692  const overlay& item = overlay_record.second;
1693  const std::string& current_team_name = get_teams()[viewing_team()].team_name();
1694 
1695  if((item.team_name.empty() || item.team_name.find(current_team_name) != std::string::npos) &&
1696  (!fogged(o_loc) || item.visible_in_fog))
1697  {
1698  const texture tex = item.image.find("~NO_TOD_SHIFT()") == std::string::npos
1699  ? image::get_texture(item.image) // TODO
1700  : image::get_texture(item.image);
1701 
1702  // was: SCALED_TO_HEX
1703  render_scaled_to_zoom(tex, o_loc);
1704  }
1705  }
1706 
1707  //
1708  // Village flags
1709  //
1710  for(const team& t : get_teams()) {
1711  auto& flag = flags_[t.side() - 1];
1712  flag.update_last_draw_time();
1713 
1714  for(const map_location& v_loc : t.villages()) {
1715  if(!fogged(v_loc) || !dc_->get_team(viewing_side()).is_enemy(t.side())) {
1716 
1717  // TODO: move this if-animated check to a helper function.
1718  const image::locator& flag_image = animate_map_
1719  ? flag.get_current_frame()
1720  : flag.get_first_frame();
1721 
1722  render_scaled_to_zoom(image::get_texture(flag_image), v_loc);
1723  }
1724  }
1725  }
1726 
1727  //
1728  // The grid overlay, if that's been enabled
1729  //
1730  if(grid_) {
1731  for(const map_location& loc : visible_hexes) {
1732  if(shrouded(loc)) {
1733  continue;
1734  }
1735 
1736  // TODO: split into drawing layers? If not, combine into one image or texture.
1737  static const texture grid_top = image::get_texture(game_config::images::grid_top);
1738  render_scaled_to_zoom(grid_top, loc);
1739 
1740  static const texture grid_bottom = image::get_texture(game_config::images::grid_bottom);
1741  render_scaled_to_zoom(grid_bottom, loc);
1742  }
1743  }
1744 
1745  //
1746  // Real (standing) units
1747  //
1748  if(!get_teams().empty()) {
1749  unit_drawer drawer = unit_drawer(*this);
1750 
1751  for(const unit& real_unit : get_units()) {
1752  drawer.redraw_unit(real_unit);
1753  }
1754 
1755  // TODO: re-add exclusionary checks for exclusive_unit_draw_requests_ later on, if necessary.
1756 #if 0
1757  auto request = exclusive_unit_draw_requests_.find(loc);
1758  if(request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()) {};
1759 #endif
1760  }
1761 
1762  //
1763  // Foreground terrains. FIXME! sometimes cut off units...
1764  //
1765  draw_visible_hexes(visible_hexes, FOREGROUND);
1766 
1767  //
1768  // Fake (moving) units
1769  //
1770  if(!get_teams().empty()) {
1771  unit_drawer drawer = unit_drawer(*this); // TODO: don't create this twice per cycle.
1772 
1773  for(const unit* temp_unit : *fake_unit_man_) {
1774  drawer.redraw_unit(*temp_unit);
1775  }
1776  }
1777 
1778  //
1779  // Draws various overlays, such as reach maps, etc.
1780  //
1781  draw_hex_overlays();
1782 
1783  //
1784  // Hex cursor (TODO: split into layers?)
1785  //
1786  draw_hex_cursor(mouseoverHex_);
1787 
1788  //
1789  // Shroud and fog
1790  //
1791  for(const map_location& loc : visible_hexes) {
1792  image::TYPE image_type = get_image_type(loc);
1793 
1794  const bool is_shrouded = shrouded(loc);
1795  const bool is_fogged = fogged(loc);
1796 
1797  // Main images.
1798  if(is_shrouded || is_fogged) {
1799 
1800  // If is_shrouded is false, is_fogged is true
1801  const std::string& weather_image = is_shrouded
1802  ? get_variant(shroud_images_, loc)
1803  : get_variant(fog_images_, loc);
1804 
1805  // TODO: image type
1806  render_scaled_to_zoom(image::get_texture(weather_image), loc);
1807  }
1808 
1809  // Transitions to main hexes.
1810  if(!is_shrouded) {
1811  draw_fog_shroud_transition_images(loc, image_type);
1812  }
1813  }
1814 
1815  // ================================================================================
1816  // TODO: RE-ADD ALL THIS!
1817  // ================================================================================
1818 
1819 #if 0
1820 
1821  //
1822  // Mouseover overlays (TODO: delegate to editor)
1823  //
1824  if(loc == mouseoverHex_ && (on_map || (in_editor() && get_map().on_board_with_border(loc)))
1825  && mouseover_hex_overlay_ != nullptr)
1826  {
1827  render_scaled_to_zoom(mouseover_hex_overlay_, xpos, ypos);
1828  }
1829 
1830  //
1831  // Arrows (whiteboard?) TODO:
1832  //
1833  auto arrows_in_hex = arrows_map_.find(loc);
1834  if(arrows_in_hex != arrows_map_.end()) {
1835  for(arrow* const a : arrows_in_hex->second) {
1836  a->draw_hex(loc);
1837  }
1838  }
1839 
1840  //
1841  // ToD Mask
1842  //
1843  // Draw the time-of-day mask on top of the terrain in the hex.
1844  // tod may differ from tod if hex is illuminated.
1845  const std::string& tod_hex_mask = tod.image_mask;
1846  if(tod_hex_mask1 != nullptr || tod_hex_mask2 != nullptr) {
1847  drawing_queue_add(drawing_queue::LAYER_TERRAIN_FG, loc, xpos, ypos, tod_hex_mask1);
1848  drawing_queue_add(drawing_queue::LAYER_TERRAIN_FG, loc, xpos, ypos, tod_hex_mask2);
1849  } else if(!tod_hex_mask.empty()) {
1850  drawing_queue_add(drawing_queue::LAYER_TERRAIN_FG, loc, xpos, ypos,
1851  image::get_image(tod_hex_mask,image::SCALED_TO_HEX));
1852  }
1853 
1854  //
1855  // Debugging output - coordinates, etc.
1856  //
1857  if(on_map) {
1858  if(draw_coordinates_) {
1859  int off_x = xpos + hex_size()/2;
1860  int off_y = ypos + hex_size()/2;
1861  surface text = font::get_rendered_text(lexical_cast<std::string>(loc), font::SIZE_SMALL, font::NORMAL_COLOR);
1862  surface bg = create_neutral_surface(text->w, text->h);
1863  SDL_Rect bg_rect {0, 0, text->w, text->h};
1864  sdl::fill_surface_rect(bg, &bg_rect, 0xaa000000);
1865  off_x -= text->w / 2;
1866  off_y -= text->h / 2;
1867  if (draw_terrain_codes_) {
1868  off_y -= text->h / 2;
1869  }
1870  if (draw_num_of_bitmaps_) {
1871  off_y -= text->h / 2;
1872  }
1873  drawing_queue_add(drawing_queue::LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
1874  drawing_queue_add(drawing_queue::LAYER_FOG_SHROUD, loc, off_x, off_y, text);
1875  }
1876 
1877  if(draw_terrain_codes_ && (game_config::debug || !shrouded(loc))) {
1878  int off_x = xpos + hex_size()/2;
1879  int off_y = ypos + hex_size()/2;
1880  surface text = font::get_rendered_text(lexical_cast<std::string>(get_map().get_terrain(loc)), font::SIZE_SMALL, font::NORMAL_COLOR);
1881  surface bg = create_neutral_surface(text->w, text->h);
1882  SDL_Rect bg_rect {0, 0, text->w, text->h};
1883  sdl::fill_surface_rect(bg, &bg_rect, 0xaa000000);
1884  off_x -= text->w / 2;
1885  off_y -= text->h / 2;
1886  if (draw_coordinates_ && !draw_num_of_bitmaps_) {
1887  off_y += text->h / 2;
1888  } else if (draw_num_of_bitmaps_ && !draw_coordinates_) {
1889  off_y -= text->h / 2;
1890  }
1891  drawing_queue_add(drawing_queue::LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
1892  drawing_queue_add(drawing_queue::LAYER_FOG_SHROUD, loc, off_x, off_y, text);
1893  }
1894 
1895  if(draw_num_of_bitmaps_) {
1896  int off_x = xpos + hex_size()/2;
1897  int off_y = ypos + hex_size()/2;
1898  surface text = font::get_rendered_text(lexical_cast<std::string>(num_images_bg + num_images_fg), font::SIZE_SMALL, font::NORMAL_COLOR);
1899  surface bg = create_neutral_surface(text->w, text->h);
1900  SDL_Rect bg_rect {0, 0, text->w, text->h};
1901  sdl::fill_surface_rect(bg, &bg_rect, 0xaa000000);
1902  off_x -= text->w / 2;
1903  off_y -= text->h / 2;
1904  if (draw_coordinates_) {
1905  off_y += text->h / 2;
1906  }
1907  if (draw_terrain_codes_) {
1908  off_y += text->h / 2;
1909  }
1910  drawing_queue_add(drawing_queue::LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
1911  drawing_queue_add(drawing_queue::LAYER_FOG_SHROUD, loc, off_x, off_y, text);
1912  }
1913  }
1914 
1915  if(debug_foreground) {
1916  drawing_queue_add(drawing_queue::LAYER_UNIT_DEFAULT, loc, xpos, ypos,
1917  image::get_image("terrain/foreground.png", image_type));
1918  }
1919 #endif
1920 }
1921 
1922 void display::draw()
1923 {
1924  // Execute any pre-draw actions from derived classes.
1925  pre_draw();
1926 
1927  // Draw theme background.
1928  draw_background();
1929 
1930  // Progress animations.
1931  invalidate_animations();
1932 
1933  // Draw the gamemap and its contents (units, etc)
1934  {
1935  SDL_Rect map_area_rect = map_area();
1936  render_clip_rect_setter setter(&map_area_rect);
1937 
1938  draw_gamemap();
1939  }
1940 
1941  // Draw debugging aids such as the FPS counter.
1942  draw_debugging_aids();
1943 
1944  // Draw floating labels (includes map labels).
1945  font::draw_floating_labels();
1946 
1947  // Execute any post-draw actions from derived classes.
1948  post_draw();
1949 }
1950 
1951 void display::handle_window_event(const SDL_Event& event)
1952 {
1953  if(event.type == SDL_WINDOWEVENT) {
1954  switch(event.window.event) {
1955  case SDL_WINDOWEVENT_RESIZED:
1956  case SDL_WINDOWEVENT_RESTORED:
1957  case SDL_WINDOWEVENT_EXPOSED:
1958  // TODO: add additional handling here if needed.
1959  break;
1960  }
1961  }
1962 }
1963 
1964 void display::handle_event(const SDL_Event& /*event*/)
1965 {
1967  return;
1968  }
1969 }
1970 
1971 display* display::singleton_ = nullptr;
constexpr const T & clamp(const T &value, const T &min, const T &max)
Definition: general.hpp:31
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: picture.hpp:181
int zoom_index_
Definition: display.hpp:842
void recalculate_shroud()
Definition: label.cpp:277
bool discard_previous
An announcement according these options should replace the previous announce (typical of fast announc...
Definition: display.hpp:624
bool is_odd(T num)
Definition: math.hpp:34
virtual void select_hex(map_location hex)
Definition: display.cpp:908
Arrows destined to be drawn on the map.
int h() const
Effective map height.
Definition: map.hpp:116
bool update_locked() const
Whether the screen has been &#39;locked&#39; or not.
Definition: video.cpp:295
void write(config &cfg) const
Definition: display.cpp:1484
virtual void draw_hex_overlays()
Draws various map overlays such as game reachmap.
Definition: display.cpp:1506
bool show_fps()
Definition: general.cpp:827
Small struct to store and manipulate ToD color adjusts.
Definition: time_of_day.hpp:28
void adjust_color_overlay(int r, int g, int b)
Add r,g,b to the colors for all images displayed on the map.
Definition: display.cpp:352
const arrow_path_t & get_path() const
Definition: arrow.cpp:116
#define DefaultZoom
Definition: display.cpp:63
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
Definition: location.cpp:517
void invalidate_animations()
Function to invalidate animated terrains and units which may have changed.
Definition: display.cpp:1422
#define ERR_DP
Definition: display.cpp:56
static int hex_size()
Function which returns the size of a hex in pixels (from top tip to bottom tip or left edge to right ...
Definition: display.hpp:321
This class represents a single unit of a specific type.
Definition: unit.hpp:99
virtual void notify_observers()
tod_color color
The color modifications that should be made to the game board to reflect the time of day...
const std::string & get_variant(const std::vector< std::string > &variants, const map_location &loc) const
Definition: display.cpp:387
static void toggle_benchmark()
Toggle to continuously redraw the screen.
Definition: display.cpp:797
CKey keys_
Definition: display.hpp:872
void set_clip_rect(const SDL_Rect &r)
bool set_zoom(bool increase)
Zooms the display in (true) or out (false).
Definition: display.cpp:1008
void change_display_context(const display_context *dc)
Definition: display.cpp:403
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
Definition: display.cpp:488
boost::circular_buffer< unsigned > frametimes_
Definition: display.hpp:856
static help_manager manager
The help manager.
Definition: help.cpp:34
int ypos_
Definition: display.hpp:837
void draw_background()
Draws the background behind the gamemap.
Definition: display.cpp:856
void set_playing_team(std::size_t team)
set_playing_team sets the team whose turn it currently is
Definition: display.cpp:269
void set_default_zoom()
Sets the zoom amount to the default.
Definition: display.cpp:1074
void set_idle_anim_rate(int rate)
Definition: display.cpp:1397
const map_location pixel_position_to_hex(int x, int y) const
given x,y co-ordinates of a pixel on the map, will return the location of the hex that this pixel cor...
Definition: display.cpp:502
void scroll_floating_labels(double xmove, double ymove)
Moves all floating labels that have &#39;scroll_mode&#39; set to ANCHOR_LABEL_MAP.
const std::string & flag() const
Definition: team.hpp:300
Definition: video.hpp:36
map_location mouseoverHex_
Definition: display.hpp:871
void init_flags()
Initialize the flag list for all sides.
Definition: display.cpp:176
Manages a list of fake units for the display object.
std::string id
Definition: time_of_day.hpp:91
void lock_updates(bool value)
Stop the screen being redrawn.
Definition: video.cpp:286
const SDL_Rect & map_area() const
Returns the area used for the map.
Definition: display.cpp:447
int scroll_speed()
Definition: general.cpp:723
void remove_floating_label(int handle)
Removes the floating label given by &#39;handle&#39; from the screen.
static lg::log_domain log_display("display")
int fps_handle_
Handle for the label which displays frames per second.
Definition: display.hpp:910
bool show_everything() const
Definition: display.hpp:104
The class terrain_builder is constructed from a config object, and a gamemap object.
Definition: builder.hpp:45
map_location minimap_location_on(int x, int y)
given x,y co-ordinates of the mouse, will return the location of the hex in the minimap that the mous...
Definition: display.cpp:637
bool idle_anim()
Definition: general.cpp:457
void reset_halo_manager()
Definition: display.cpp:409
const SDL_Rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
Definition: display.cpp:475
const unit_map & get_units() const
Definition: display.hpp:157
bool non_interactive() const
Definition: video.cpp:90
#define h
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:108
#define MaxZoom
Definition: display.cpp:66
map_location selectedHex_
Definition: display.hpp:870
void set_font_size(int font_size)
const std::vector< std::string > items
static display * singleton_
Definition: display.hpp:934
#define d
const int SIZE_PLUS
Definition: constants.cpp:26
-file sdl_utils.hpp
static unsigned int zoom_
Definition: display.hpp:841
surface create_neutral_surface(int w, int h)
Definition: utils.cpp:85
const SDL_Rect & minimap_area() const
mapx is the width of the portion of the display which shows the game area.
Definition: display.hpp:276
std::vector< std::string > split(const std::string &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
void reset_standing_animations()
Definition: display.cpp:1446
void remove_arrow(arrow &)
Definition: display.cpp:1460
void add_frame(int duration, const T &value, bool force_change=false)
Adds a frame to an animation.
#define DBG_DP
Definition: display.cpp:58
Wrapper class to encapsulate creation and management of an SDL_Texture.
Definition: texture.hpp:26
const rect_of_hexes get_visible_hexes() const
Returns the rectangular area of visible hexes.
Definition: display.cpp:599
void draw_debugging_aids()
Definition: display.cpp:807
std::string id
Definition: overlay.hpp:40
bool team_valid() const
Definition: display.cpp:604
#define b
const int SIZE_XLARGE
Definition: constants.cpp:29
std::vector< std::string > shroud_images_
Definition: display.hpp:868
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57
bool exists(const image::locator &i_locator)
returns true if the given image actually exists, without loading it.
Definition: picture.cpp:1142
void blindfold(bool flag)
Definition: display.cpp:419
virtual const SDL_Rect get_clip_rect()
Get the clipping rectangle for drawing.
Definition: display.cpp:1412
const config & options()
Definition: game.cpp:566
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
virtual void draw() override final
Main drawing function.
Definition: display.cpp:1922
CVideo & video_
Definition: display.hpp:833
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
void set_alignment(ALIGN align)
const std::string & id() const
Gets this unit&#39;s id.
Definition: unit.hpp:305
const arrow_path_t & get_previous_path() const
Definition: arrow.cpp:121
double turbo_speed() const
Definition: display.cpp:1382
static bool zoom_at_max()
Definition: display.cpp:998
bool null() const
Definition: texture.hpp:79
const t_string id
void new_animation_frame()
Definition: animated.cpp:30
static bool outside_area(const SDL_Rect &area, const int x, const int y)
Check if the bbox of the hex at x,y has pixels outside the area rectangle.
Definition: display.cpp:480
bool tile_fully_on_screen(const map_location &loc) const
Check if a tile is fully visible on screen.
Definition: display.cpp:1086
const t_string name
Arrows destined to be drawn on the map.
Definition: arrow.hpp:29
surface screenshot(bool map_screenshot=false)
Capture a (map-)screenshot into a surface.
Definition: display.cpp:660
std::array< int, 2 > bottom
Definition: hex_rect.hpp:48
std::string theme()
Definition: game.cpp:816
void set_lifetime(int lifetime)
Set the number of frames to display the text for, or -1 to display until removed. ...
Sets the renderer output target to the specified texture.
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force=true)
Definition: display.cpp:1102
bool valid() const
Definition: location.hpp:93
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
Definition: display.hpp:889
arrows_map_t arrows_map_
Maps the list of arrows for each location.
Definition: display.hpp:929
virtual image::TYPE get_image_type(const map_location &loc)
Definition: display.cpp:1417
const std::unique_ptr< map_labels > map_labels_
Definition: display.hpp:851
int xpos_
Definition: display.hpp:837
void update_tod(const time_of_day *tod_override=nullptr)
Applies r,g,b coloring to the map.
Definition: display.cpp:341
std::string background_image
Definition: theme.hpp:86
SDL_Rect minimap_location_
Definition: display.hpp:846
double size
Definition: theme.hpp:84
void set_zoom(unsigned int amount)
sets the amount scaled images should be scaled.
Definition: picture.cpp:836
TERRAIN_TYPE
Used as a parameter for the get_terrain_at function.
Definition: builder.hpp:49
tod_color color_adjust_
Definition: display.hpp:931
fake_unit_manager * fake_units
Definition: resources.cpp:30
Rectangular area of hexes.
Definition: hex_rect.hpp:33
void bounds_check_position()
Definition: display.cpp:1357
Modify, read and display user preferences.
#define MinZoom
Definition: display.cpp:65
void set_position(double xpos, double ypos)
Set the location on the screen to display the text.
void update_arrow(arrow &a)
Called by arrow objects when they change.
Definition: display.cpp:1467
map_display and display: classes which take care of displaying the map and game-data on the screen...
unsigned int fps_actual_
Definition: display.hpp:859
bool animate_map()
Definition: general.cpp:757
std::string shroud_prefix
Definition: game_config.cpp:70
std::array< map_location, 6 > adjacent_loc_array_t
Definition: location.hpp:170
const color_t YELLOW_COLOR
static const std::string & get_direction(std::size_t n)
Definition: display.cpp:709
const color_t NORMAL_COLOR
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
Definition: display.cpp:614
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
Definition: rect.cpp:22
static int hex_width()
Function which returns the width of a hex in pixels, up to where the next hex starts.
Definition: display.hpp:312
std::string flag_rgb
static unsigned int last_zoom_
Definition: display.hpp:843
void set_color_adjustment(int r, int g, int b)
will make all scaled images have these rgb values added to all their pixels.
Definition: picture.cpp:822
std::unique_ptr< halo::manager > halo_man_
Definition: display.hpp:671
SDL_Rect rect
The coordinates of this image on the spritesheet.
int idle_anim_rate()
Definition: general.cpp:467
Encapsulates the map of the game.
Definition: location.hpp:42
void set_color(const color_t &color)
void set_team(const team *)
Definition: label.cpp:138
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
Definition: display.cpp:609
void set_scroll_mode(LABEL_SCROLL_MODE scroll)
bool faked() const
Definition: video.hpp:65
const border_t & border() const
Definition: theme.hpp:275
void recalculate_labels()
Definition: label.cpp:244
int w() const
Effective map width.
Definition: map.hpp:113
virtual overlay_map & get_overlays()=0
std::size_t i
Definition: function.cpp:933
virtual const std::vector< team > & teams() const =0
bool is_blindfolded() const
Definition: display.cpp:428
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
Definition: display.cpp:1192
void announce(const std::string &msg, const color_t &color=font::GOOD_COLOR, const announce_options &options=announce_options())
Announce a message prominently.
Definition: display.cpp:936
virtual void highlight_hex(map_location hex)
Definition: display.cpp:913
Holds options for calls to function &#39;announce&#39; (announce).
Definition: display.hpp:614
std::size_t activeTeam_
Definition: display.hpp:886
void set_diagnostic(const std::string &msg)
Definition: display.cpp:918
void scroll_to_tiles(map_location loc1, map_location loc2, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, double add_spacing=0.0, bool force=true)
Scroll such that location loc1 is on-screen.
Definition: display.cpp:1205
map_location get_middle_location() const
Definition: display.cpp:1478
static map_location::DIRECTION s
void render_scaled_to_zoom(const texture &tex, const int x_pos, const int y_pos, T &&... extra_args) const
Renders a texture directly to the screen (or current rendering target) scaled to the current zoom fac...
Definition: display.hpp:743
std::vector< std::string > names
Definition: build_info.cpp:53
virtual ~display()
Definition: display.cpp:165
double g
Definition: astarsearch.cpp:63
void read(const config &cfg)
Definition: display.cpp:1494
bool dont_show_all_
Definition: display.hpp:836
int get_location_y(const map_location &loc) const
Definition: display.cpp:624
std::basic_string< signed char > light_string
light_string store colors info of central and adjacent hexes.
Definition: picture.hpp:146
void start_animation(int start_time, bool cycles=false)
Starts an animation cycle.
int add_floating_label(const floating_label &flabel)
Add a label floating on the screen above everything else.
bool tile_nearly_on_screen(const map_location &loc) const
Checks if location loc or one of the adjacent tiles is visible on screen.
Definition: display.cpp:1093
bool add_exclusive_draw(const map_location &loc, unit &unit)
Allows a unit to request to be the only one drawn in its hex.
Definition: display.cpp:313
Represents terrains which are to be drawn in front of them.
Definition: builder.hpp:54
static bool zoom_at_min()
Definition: display.cpp:1003
int w
double get_zoom_factor() const
Returns the current zoom factor.
Definition: display.hpp:327
theme theme_
Definition: display.hpp:840
const bool & debug
bool view_locked_
Definition: display.hpp:839
Definitions for the terrain builder.
Represents terrains which are to be drawn behind unit sprites.
Definition: builder.hpp:50
config & add_child(config_key_type key)
Definition: config.cpp:479
display(const display_context *dc, std::weak_ptr< wb::manager > wb, const config &theme_cfg, const config &level, bool auto_join=true)
Definition: display.cpp:86
std::vector< std::string > fog_images_
Definition: display.hpp:867
std::vector< animated< image::locator > > imagelist
A shorthand typedef for a list of animated image locators, the base data type returned by the get_ter...
Definition: builder.hpp:72
Handling of system events.
Definition: manager.hpp:41
void set_team(std::size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
Definition: display.cpp:249
std::string halo
Definition: overlay.hpp:37
std::array< int, 2 > top
Definition: hex_rect.hpp:47
void add_overlay(const map_location &loc, const std::string &image, const std::string &halo="", const std::string &team_name="", const std::string &item_id="", bool visible_under_fog=true)
Functions to add and remove overlays from locations.
Definition: display.cpp:275
Definition: display.hpp:44
const std::vector< team > & get_teams() const
Definition: display.hpp:114
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
Definition: display.cpp:619
const gamemap & get_map() const
Definition: display.hpp:109
const std::string & color() const
Definition: team.hpp:256
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_
map of hexes where only one unit should be drawn, the one identified by the associated id string ...
Definition: display.hpp:831
events::generic_event scroll_event_
Event raised when the map is being scrolled.
Definition: display.hpp:854
#define f
int lifetime
Lifetime measured in frames.
Definition: display.hpp:617
double t
Definition: astarsearch.cpp:63
void reload_map()
Updates internals that cache map size.
Definition: display.cpp:398
constexpr const SDL_Rect empty_rect
Definition: rect.hpp:31
unsigned int tile_size
Definition: game_config.cpp:67
const display_context * dc_
Definition: display.hpp:669
this module manages the cache of images.
double idle_anim_rate_
Definition: display.hpp:915
void fill_rectangle(const SDL_Rect &rect, const color_t &color)
Draws a filled rectangle.
Definition: rect.cpp:65
int drawn_hexes_
Count work done for the debug info displayed under fps.
Definition: display.hpp:912
Standard logging facilities (interface).
double turbo_speed_
Definition: display.hpp:849
int diagnostic_label_
Definition: display.hpp:848
void run_event_loop()
Definition: events.cpp:436
EXIT_STATUS start(const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Definition: editor_main.cpp:28
bool scroll_to_action()
Definition: general.cpp:365
map_labels & labels()
Definition: display.cpp:1402
static void fill_images_list(const std::string &prefix, std::vector< std::string > &images)
Definition: display.cpp:358
const std::unique_ptr< fake_unit_manager > fake_unit_man_
Definition: display.hpp:844
#define SmallZoom
Definition: display.cpp:64
#define final_zoom_index
Definition: display.cpp:62
std::vector< animated< image::locator > > flags_
Animated flags for each team.
Definition: display.hpp:882
void draw_visible_hexes(const rect_of_hexes &visible_hexes, TERRAIN_TYPE layer)
Draws the visible map hex terrains.
Definition: display.cpp:1511
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
Definition: config.cpp:456
#define zoom_levels
Definition: display.cpp:61
int get_end_time() const
int side() const
Definition: team.hpp:188
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const
Definition: display.cpp:335
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
SDL_Point get_loc_drawing_origin(const map_location &loc) const
Wrapper to return the drawing origin for the specified location in screen coordinates.
Definition: display.cpp:629
void remove_single_overlay(const map_location &loc, const std::string &toDelete)
remove_single_overlay will remove a single overlay from a tile
Definition: display.cpp:297
SDL_Rect screen_area(bool as_pixels=true) const
Returns the current window renderer area, either in pixels or screen coordinates. ...
Definition: video.cpp:197
static map_location::DIRECTION n
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
SDL_Renderer * get_renderer()
Returns a pointer to the underlying window&#39;s renderer.
Definition: video.cpp:326
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
Definition: display.cpp:952
bool turbo_
Definition: display.hpp:850
void add_arrow(arrow &)
Definition: display.cpp:1453
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
Definition: display.cpp:292
bool animate_map_
Local cache for preferences::animate_map, since it is constantly queried.
Definition: display.hpp:875
const SDL_Rect & max_map_area() const
Returns the maximum area used for the map regardless to resolution and view size. ...
Definition: display.cpp:433
static rng & default_instance()
Definition: random.cpp:73
#define LOG_DP
Definition: display.cpp:57
static void toggle_debug_foreground()
Toggle to debug foreground terrain.
Definition: display.cpp:802
const std::unique_ptr< terrain_builder > builder_
Definition: display.hpp:845
std::string fog_prefix
Definition: game_config.cpp:70
std::weak_ptr< wb::manager > wb_
Definition: display.hpp:673
Definition: display.hpp:49
void set_theme(config theme_cfg)
Definition: display.cpp:171
int blindfold_ctr_
Definition: display.hpp:665
TERRAIN_TYPE
Definition: display.hpp:709
texture get_texture(const image::locator &i_locator, TYPE type)
Definition: picture.cpp:1424
void render_copy(const texture &txt, SDL_Rect *src_rect=nullptr, SDL_Rect *dst_rect=nullptr, const bool flip_h=false, const bool flip_v=false)
Definition: video.cpp:253
std::vector< std::string > square_parenthetical_split(const std::string &val, const char separator, const std::string &left, const std::string &right, const int flags)
Similar to parenthetical_split, but also expands embedded square brackets.
std::string remove_exclusive_draw(const map_location &loc)
Cancels an exclusive draw request.
Definition: display.cpp:323
const color_t BAD_COLOR
int draw_text_in_hex(const map_location &loc, const std::string &text, std::size_t font_size, color_t color, int fl_label_id=0, double x_in_hex=0.5, double y_in_hex=0.5)
Adds a floating label with the specified text at the given location.
Definition: display.cpp:876
std::size_t currentTeam_
Definition: display.hpp:835
void rebuild_all()
Rebuild all dynamic terrain.
Definition: display.cpp:393
void write(config &cfg) const
Definition: location.cpp:210
void draw_fog_shroud_transition_images(const map_location &loc, image::TYPE image_type)
Draw the appropriate fog or shroud transition images for a specific hex.
Definition: display.cpp:715
const rect_of_hexes hexes_under_rect(const SDL_Rect &r) const
Return the rectangular area of hexes overlapped by r (r is in screen coordinates) ...
Definition: display.cpp:555
std::string image
Definition: overlay.hpp:36