Santiago Romero schrieb:
>>> - Speed Performance: Do you think that changing from list to Array()
>>> would improve speed? I'm going to do lots of tilemap[y][x] checks (I
>>> mean, player jumping around the screen, checking if it's falling over
>>> a non-zero tile, and so).
>
>> First of all: if y
Santiago Romero wrote:
> My problem is that, in my game, each screen is 30x20, and I have
> about 100 screens, so my tilemap contains 32*20*100 = 6 python
> objects (integers).
>
> If each integer-python-object takes 16 bytes, this makes 6 * 16 =
> almost 1MB of memory just for the tile
Santiago Romero:
> If each integer-python-object takes 16 bytes, this makes 6 * 16 =
> almost 1MB of memory just for the tilemaps...
> Using array of type H (16 bits per item = 2 bytes), my maps take just
> 6*2 = 120KB of memory.
> Do you think I should still go with lists instead of an
> > - Speed Performance: Do you think that changing from list to Array()
> > would improve speed? I'm going to do lots of tilemap[y][x] checks (I
> > mean, player jumping around the screen, checking if it's falling over
> > a non-zero tile, and so).
> First of all: if you have enough memory to use
> C:\> \python25\python -m -s
:-)
Thanks a lot :-)
--
http://mail.python.org/mailman/listinfo/python-list
Santiago Romero wrote:
>...
[I wrote]
>>def __init__( self, bw, bh, tiles ):
>> self.width, self.height = bw, bh
>> self.tilemap = array.array('b', [0]) * bw * bh
>> Gives a pure linearization (you do the math for lines).
> Do you mean : tilemap[(width*y)+x] ?
Yup, exac
Santiago Romero:
> - Speed Performance: Do you think that changing from list to Array()
> would improve speed? I'm going to do lots of tilemap[y][x] checks (I
> mean, player jumping around the screen, checking if it's falling over
> a non-zero tile, and so).
First of all: if you have enough memory
> > This is how I create the tilemap (and the clipboard, a copy of my
> > tilemap):
>
> > def __init__( self, bw, bh, tiles ):
> > self.tilemap = []
> > (...)
> > for i in range(bh):
> > self.tilemap.append([0] * bw)
>def __init__( self, bw, bh, tiles ):
>
Santiago Romero wrote:
> I'm trying to change my current working source code so that it works
> with an array instead of using a list, but I'm not managing to do it.
> ...
>
> This is how I create the tilemap (and the clipboard, a copy of my
> tilemap):
>
> def __init__( self, bw, bh, tiles