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

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




--- Scott Russell <scott@activestudios.com> wrote:
> 
> Hi, all.  
> 
> I've got some code that currently keeps a map as an
> array of integers:
> 
> map = [[0] * map_max_y for i in range(map_max_x)]
> 
> The map is larger than the viewport.
> 
> The current screen is constructed with something
> like this pseudocode
> 
> Assume the viewport is guaranteed to be safely
> within the boundaries - 
> it's checked elsewhere.
> 
> for x in range(viewport.x, viewport.x +
> viewport.width):
>   for y in range(viewport.y, viewport.y +
> viewport.height):
>     cell = map[x][y]
>     if cell != 0:
>       if cell == 10:
>         viewport.display.set_at((x,y),(255,255,255))
>       elif cell ==20:
>         viewport.display.set_at((x,y),(0,255,255))
>       else:
>         viewport.display.set_at((x,y),(128,128,128))
> 
> blit_and_flip(Screen)
> 
> Of course this is slow.  Screen redraws are on the
> order of a half a 
> second.  Is there something
> I can do with pynumeric to make this fast enough for
> realtime (atleast 
> 10 fps)?  
> Can I speed up an order of magnitude using map
> somethow?  Do I need to 
> drop to C?
> 
> Any ideas would be appreciated.
> 
>   - Scott

Very first thing you can try is only doing that
set_at/get_at routine when you need it.  Blit to an
extra surface (call it 'map'?) and then just blit that
surface to the screen every cycle.  When the viewport
scrolls enough (x amount of pixels) use that routine
(or an optimized one) to redraw the map.

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org