Changeset - r24464:163cbf3f9ad8
[Not reviewed]
master
0 1 0
dP - 5 years ago 2020-02-14 22:10:04
dp@dpointer.org
Feature #7962: Improve rendering of large viewports
1 file changed with 6 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/viewport.cpp
Show inline comments
 
@@ -1773,65 +1773,44 @@ void ViewportDoDraw(const Viewport *vp, 
 
		ViewportDrawStrings(zoom, &_vd.string_sprites_to_draw);
 
	}
 

	
 
	_cur_dpi = old_dpi;
 

	
 
	_vd.string_sprites_to_draw.clear();
 
	_vd.tile_sprites_to_draw.clear();
 
	_vd.parent_sprites_to_draw.clear();
 
	_vd.parent_sprites_to_sort.clear();
 
	_vd.child_screen_sprites_to_draw.clear();
 
}
 

	
 
/**
 
 * Make sure we don't draw a too big area at a time.
 
 * If we do, the sprite memory will overflow.
 
 */
 
static void ViewportDrawChk(const Viewport *vp, int left, int top, int right, int bottom)
 
{
 
	if ((int64)ScaleByZoom(bottom - top, vp->zoom) * (int64)ScaleByZoom(right - left, vp->zoom) > (int64)(180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE)) {
 
		if ((bottom - top) > (right - left)) {
 
			int t = (top + bottom) >> 1;
 
			ViewportDrawChk(vp, left, top, right, t);
 
			ViewportDrawChk(vp, left, t, right, bottom);
 
		} else {
 
			int t = (left + right) >> 1;
 
			ViewportDrawChk(vp, left, top, t, bottom);
 
			ViewportDrawChk(vp, t, top, right, bottom);
 
		}
 
	} else {
 
		ViewportDoDraw(vp,
 
			ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
 
			ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top,
 
			ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left,
 
			ScaleByZoom(bottom - vp->top, vp->zoom) + vp->virtual_top
 
		);
 
	}
 
}
 

	
 
static inline void ViewportDraw(const Viewport *vp, int left, int top, int right, int bottom)
 
{
 
	if (right <= vp->left || bottom <= vp->top) return;
 

	
 
	if (left >= vp->left + vp->width) return;
 

	
 
	if (left < vp->left) left = vp->left;
 
	if (right > vp->left + vp->width) right = vp->left + vp->width;
 

	
 
	if (top >= vp->top + vp->height) return;
 

	
 
	if (top < vp->top) top = vp->top;
 
	if (bottom > vp->top + vp->height) bottom = vp->top + vp->height;
 

	
 
	ViewportDrawChk(vp, left, top, right, bottom);
 
	ViewportDoDraw(vp,
 
		ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
 
		ScaleByZoom(top - vp->top, vp->zoom) + vp->virtual_top,
 
		ScaleByZoom(right - vp->left, vp->zoom) + vp->virtual_left,
 
		ScaleByZoom(bottom - vp->top, vp->zoom) + vp->virtual_top
 
	);
 
}
 

	
 
/**
 
 * Draw the viewport of this window.
 
 */
 
void Window::DrawViewport() const
 
{
 
	PerformanceAccumulator framerate(PFE_DRAWWORLD);
 

	
 
	DrawPixelInfo *dpi = _cur_dpi;
 

	
 
	dpi->left += this->left;
0 comments (0 inline, 0 general)