From c42ee44271a0f1b87db9e505d810c4700bb9280d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 25 Aug 2011 15:34:47 +0200 Subject: [PATCH] Don't blit unnecessarily. During the game, a lot of images were blitted outside the visible area. Also, addBuffer() was called even when the destination surface was not the screen, resulting in unnecessary blits in unBuffer(). --- code/classes.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/classes.h b/code/classes.h index 475e985..a415536 100644 --- a/code/classes.h +++ b/code/classes.h @@ -265,20 +265,26 @@ class Graphics { void blit(SDL_Surface *image, int x, int y, SDL_Surface *dest) { + // Exit early if image is not on dest at all + if(x + image->w < 0 || x >= dest->w || y + image->h < 0 || y >= dest->h) + return; + // Set up a rectangle to draw to blitRect.x = x; blitRect.y = y; blitRect.w = image->w; blitRect.h = image->h; - /* Blit onto the screen surface */ + /* Blit onto the destination surface */ if(SDL_BlitSurface(image, NULL, dest, &blitRect) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); showErrorAndExit(2, ""); } - addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h); + // Only ff it is to the screen, mark the region as damaged + if(dest == screen) + addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h); } void blit(SDL_Surface *image, int x, int y)