Only update tiles on SDL2 renderer when required.
@@ -38,6 +38,21 @@ struct SDL_Texture* SDL2Renderer::render(const TCOD_Console* console)
const int ch = console->ch_array[i];
const TCOD_color_t fg = console->fg_array[i];
const TCOD_color_t bg = console->bg_array[i];
+ int& cache_ch = std::get<0>(cache_.at(x, y));
+ ColorRGBA& cache_fg = std::get<1>(cache_.at(x, y));
+ ColorRGBA& cache_bg = std::get<2>(cache_.at(x, y));
+ if (cache_ch == ch &&
+ cache_fg.r == fg.r && cache_fg.g == fg.g && cache_fg.b == fg.b &&
+ cache_bg.r == bg.r && cache_bg.g == bg.g && cache_bg.b == bg.b) {
+ continue; // This tile was already rendered on a previous frame.
+ }
+ cache_ch = ch;
+ cache_fg.r = fg.r;
+ cache_fg.b = fg.b;
+ cache_fg.g = fg.g;
+ cache_bg.r = bg.r;
+ cache_bg.b = bg.b;
+ cache_bg.g = bg.g;
const SDL_Rect dest_rect{
x * tileset_->get_tile_width(),
y * tileset_->get_tile_height(),
