[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] performance issues, etc



> pygame.display.update()
> When I call update() and pass it a list of rects, does update() check
> to see if any of the rects overlap or contain each other, etc? 


hi mike. here's some answers and insight for you...

the update does not check for overlapping areas. so yes, any areas 
listed twice in the update rectangle list will be updated twice.

obviously if you have a lot of overlapping action this could become a 
problem, but from what i don't expect people will ever have a problem 
from too many overlapping sprites.

the one area where this does become a concern is when you have an update 
rectangle for the old and new position of the sprite. usually a sprite 
only moves a couple pixels in any direction. therefore the old and new 
rectangles will overlap a lot. the easiest thing to do in this situation 
is take the union of both rectangles. it may seem a little sloppy if the 
sprite might be moving diagonally, but it's a method tested and approved 
  by the experts :]

obviously you want to be updating the absolute minimum amount of area 
each frame, but for the most part it's not worth fiddling with things to 
shave off an extra edge of pixels.

at one point i had written a Rect optimizer for SDL in C. it cleaned up 
the inputs for the list. it sped up some demos by about 10%. but several 
people pointed out it had the potential to actually slow things down in 
many cases. the best thing you can do some minimal work on the 
rectangles when you add them to the list.

also, be sure to only make one call to update() each frame. running 
under windows it doesn't really matter, but on X displays there is more 
communication needed for this sort of things, so wrapping it all into a 
single call is the best move.

on a plus note. if you use the new sprite module in pygame. it can 
automatically handle the dirty rects for you. it is also smart about 
removing the overlap between the "old" and "new" position for each sprite.

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org