From f563dfe194769bca14e615d8c2a623aacfd8fd0e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 24 Feb 2020 22:55:07 +0000 Subject: [PATCH] Viewport: Trim parent sprites to redraw area before sorting --- src/viewport.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/viewport.cpp b/src/viewport.cpp index 0f632575d7..55d6ef9dce 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2996,8 +2996,18 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom if (_vd.tile_sprites_to_draw.size() != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw); - for (auto &psd : _vd.parent_sprites_to_draw) { - _vd.parent_sprites_to_sort.push_back(&psd); + { + const int vd_left = _vd.dpi.left; + const int vd_top = _vd.dpi.top; + const int vd_right = _vd.dpi.left + _vd.dpi.width; + const int vd_bottom = _vd.dpi.top + _vd.dpi.height; + for (auto &psd : _vd.parent_sprites_to_draw) { + if (psd.left >= vd_right) continue; + if (psd.top >= vd_bottom) continue; + if (psd.left + psd.width <= vd_left) continue; + if (psd.top + psd.height <= vd_top) continue; + _vd.parent_sprites_to_sort.push_back(&psd); + } } ViewportProcessParentSprites();