Re: Converting a bidimensional list in a bidimensional array

2008-01-11 Thread Diez B. Roggisch
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

Re: Converting a bidimensional list in a bidimensional array

2008-01-11 Thread Fredrik Lundh
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

Re: Converting a bidimensional list in a bidimensional array

2008-01-11 Thread bearophileHUGS
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

Re: Converting a bidimensional list in a bidimensional array

2008-01-11 Thread 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 to use

Re: Converting a bidimensional list in a bidimensional array

2008-01-10 Thread Santiago Romero
> C:\> \python25\python -m -s :-) Thanks a lot :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a bidimensional list in a bidimensional array

2008-01-09 Thread Scott David Daniels
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

Re: Converting a bidimensional list in a bidimensional array

2008-01-09 Thread bearophileHUGS
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

Re: Converting a bidimensional list in a bidimensional array

2008-01-09 Thread Santiago Romero
> > 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 ): >

Re: Converting a bidimensional list in a bidimensional array

2008-01-09 Thread Scott David Daniels
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