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

Re: [pygame] Fastest way to plot a map.



Scott Russell wrote:

> Unfortunatley, this map changes every frame.  I could track which
> individual elements change...

This is a good idea if you need to boost performance.  I did this in a
fast-moving C action game where most of the space is "empty" and got a
dramatic speedup (several hundred percent).  Even if your map is usually
full and changing a lot it can still help.  Blits are expensive so
anytime you can avoid one you probably should.  One problem is that it
can make scrolling times erratic but this is usually a much less severe
problem to have.

Unless your map is really big you can keep a second "screen" map array. 
Once this second array is filled when your game starts, it should only
be changed one tile at a time - don't copy the entire map array each
frame.  So you'd have something like this in your screen update loop:

if gamemap[i][j] != screenmap[i][j]:
    screenmap[i][j] = gamemap[i][j]
    blittile(gamemap[i][j])

(Of course i and j would be restricted to the range of the current
viewport.)

BTW I call this "differentiation" but there's probably a more common
name for it.

> I think the answer is what Pete was hinting at at the beginning of his
> response - go tile based, and dramatically decrease the size of the
> viewport.

Yeah, this is probably the way to go.  There are other ways but they are
a lot more complicated and can be slower too.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@home.com                      http://members.home.net/paulsid/
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org