Reducing pygame cpu-load to < 4 %

Bernardo Innocenti bernie at codewiz.org
Sun Dec 9 19:29:27 EST 2007


On 12/09/07 19:08, Noah Kantrowitz wrote:
> Unfortunately this is not possible in most games, as doing them purely
> vector-based is infeasible. A lot of the artwork made for games will be
> standard raster graphics, and will need to be designed for a specific
> screen. If there are changes in the future, they can always be redrawn.

The conversion to the screen format can happen at load
time, rather than each time the bitmap is being redrawn
on screen.

Doing it systematically is very easy:

  Surface *load_image(const char *filename)
  {
      Surface *s = NULL, tmp;

      if ((tmp = IMG_Load(filename))
      {
          s = SDL_DisplayFormat(tmp);
          SDL_FreeSurface(tmp);
      }
      return s;
  }

Some libraries, notably SDL, make blitting graphics between
different pixel formats a little bit too transparent.
As a result, developers don't even notice and huge performance
bugs like this slip through.

-- 
 \___/
 |___|   Bernardo Innocenti - http://www.codewiz.org/
  \___\  One Laptop Per Child - http://www.laptop.org/



More information about the Devel mailing list