Re: [pygame] Sound still glitchy in 1.8.1rc1 on Ubuntu
I'am not an expert in pygame audio but: 1. It makes any diference if you reduce the sleep time? Say, 1/30 sec by example. 2. It makes some diference if you initialize the mixer with diferent buffer sizes ? That was pointed to me by Patrick Mullen time ago, and the advice periodically resurfaces. Sometimes, especially with old hardware, increasing the buffer size alleviates the problem ( at the cost of more latency, If i remember well). ex: # last param is buffer size pygame.mixer.init(44100, -16, True, 1024) 3. Your real code really dont pump the event queue? Maybe .get_busy() updates all necesary inner state, but a lot of pygame functionallity depends on the event queue being pumped. HTH --- claxo
Re: [pygame] New on the mailing list with a strange FPS behavior
Look at the module gc in the global module index of Python docs, but in a pinch: import gc ... gc.collect( ) Don't put into a tight loop, this waste cpu time. claxo On 12 Nov 2007 at 8:30, Ghislain Leveque wrote: 2007/11/12, claxo [EMAIL PROTECTED]: On 11 Nov 2007 at 22:41, Ghislain Leveque wrote: Today I've come into a strange behavior with my rendering loop. 3. Memory garbage collection kicks in. you can try to do a explicit garbage collection after each M frames to see if max time is reduced. How do I do an explicite garbage collection ? Thanks -- Ghislain Lévêque
Re: [pygame] New on the mailing list with a strange FPS behavior
I seems to remember time.time() is prefered to calculate delta times? Anybody ? On 12 Nov 2007 at 8:29, Ghislain Leveque wrote: First I will explain how I did measure and what make me think it's the draw that stucks : ... def post(self,event): for listener in self.listeners: now = pygame.time.get_ticks() listener.notify(event) self.stats[listener].append((pygame.time.get_ticks() - now,event)) Ghislain Lévêque
Re: [pygame] I'm getting BSOD while using PyGame.
Try to shortcut all the fps - cpu caping in your code, see if it crash or freezes. Its seems to me that that all the restrictions are fighting. If doenst crash, we know the problem is in the caping. claxo On 12 Nov 2007 at 14:02, Jake b wrote: The source is at: http://www.newmech.com/pics/ZombieHunt_v0.2-BSOD.zip If you want more feedback, post more code ( from the non numeric version, to keep it easy) Cheers claxo
Re: [pygame] New on the mailing list with a strange FPS behavior
On 11 Nov 2007 at 22:41, Ghislain Leveque wrote: Hi there, I subscribed to the mailing list today because I've used pygame for a while now and I begin to be comfortable with it. Wellcome! Today I've come into a strange behavior with my rendering loop. I use dirty rectangles to update the screen so my render function looks like this : def draw(self): self.spritegroup1.clear(self.window,self.background) self.spritegroup2.clear(self.window,self.background) # ... dirty = self.spritegroup1.draw(self.window) + self.spritegroup2.draw(self.window) # ... pygame.display.update(dirty) self.clock.tick (TARGET_FPS) I've measured the time to each call to this draw function and the normal time is 15ms (quite fast) but from time to time, the function takes 500ms to execute !! And of course I see my game freezing... Can anyone tell me where I should look at ? -- Ghislain Lévêque 1. I don't known if clock.tick() can be to blame, maybe you can try to bypass clock.tick to see if times are irregular. 2. If the size or quantity of sprites have great variations, so can the time. And if the workload is too variable, probably clock.tick can magnify the diference. 3. Memory garbage collection kicks in. you can try to do a explicit garbage collection after each M frames to see if max time is reduced. 4. At each frame you can try to print some stats to see if there something unexpected, by example: print len(dirty), other info that you think is relevant, maybe the total dirty area claxo
Re: [pygame] I\'m getting BSOD while using PyGame.
Hello, I\'m new to the list. ( Can I use HTML formatting to make it easier to read my code, or if this is text only, what\'s the best way to paste it? ) It is prefered plain text, not HTML. If the code is long, usually is beter as an attachement, with the little parts you want to comment also into the body of mail. ( yours it not too long). If the code is very long, and or needs media file, put a compresed archive somewhere and post the link. I\'ve started on a very basic game, right now all it does is blit tiles to the screen. I used a NumPy tutorial to create a 2D array to store tileID\'s for rendering. But running it, caused my computer to get a Blue Screen Of Death. The code was \x = ones( ( 3, 4 ) )\ Not enought context to tell wat was going . What is \'ones\' ? I was surprised because I was running my game in windowed mode, if I called blit() witih an invalid value, or accessed an array out of bounds, I thought it would at worst crash to desktop. I have also tried the game Snowballz, ( it uses PyGame ) So my first guess was that it was NumPy that did it. I removed NumPy, creating my own basic 2D array class that seems to be working correctly stand-alone. I started to place it into my tile code, and I got the BSOD again. Now I know it\'s not NumPy. The wierd thing is even when it crashes, it seems to render the tileset at least once. Sometimes it had been running for a few seconds ( at 60 renders per second ), but once it was the very first render that crashed. What can I do to figure out what is causing the crash? I took a look at my computer - event viewer and there were no errors or warnings. This is the code used to render the tileset. The rest of the code in the program I\'ve used in other tests I\'ve done, and they haven\'t crashed. The member .data() is an instance of my Array2D() class. Do you need any more information? ( I wasn\'t sure if I should attach the source code, or use one of those websites, or HTML formatting or what. ) computer: win32 winXP, AMD Athlon 64 X2 Dual core 4600+ Thanks, -- jake [ code starts here ] # file: Map.py : snippet: class Map(), method .render() def render(self): \\\render the map to screen\\\ for y in range( 0, self.tiles_y ): for x in range( 0, self.tiles_x): you can spare the 0, when range has only one param it asumes begin at 0 tile_id = self.data.get( x, y ) # will equal rand value 0..3 dest_rect = pygame.Rect( x*self.tile_w, y*self.tile_h, self.tile_w, self.tile_h ) src_rect = pygame.Rect( tile_id*self.tile_w, 0, self.tile_w, self.tile_h ) # blit it self.screen.blit( self.tileset, dest_rect, src_rec ) seems ok, if self.tileset is initialized to a pygame surface anywhere # file: Array2D.py # code seems to work, but there could be a bug. Also wasn\'t sure if # return \'None\' is the correct thing to do on a failed .get() class Array2D: \\\Simple 2D array without math operations.\\\ def __init__(self, cols, rows): \\\Initialize array size [cols][rows]\\\ self.resize(cols, rows) def resize(self, cols, rows): \\\resize array, works same way as constructor arguments\\\ # populate: None\'s self.__rows = rows self.__cols = cols self.__data = [ [None for row in range(rows)] for col in range(cols) ] Why the names begins with \'__\' ? Usually its only used to hide members. To the readers convey the sense \'We play tricks with this members, dont touch\' def get(self, x, y): \\\get the value at the offset for now, if invalid bounds, then return None\\\ if self.validIndex( x, y ): return self.__data[x][y] return None # maybe throw exception? Haven\'t learned about them yet. def set(self, x, y, value): \\\set the value at the offset for now, if invalid bounds, then return None\\\ if self.validIndex( x, y ): self.__data[x][y] = value # todo: else throw exception / error but doesn\'t need to halt program. Returns None any time def validIndex( self, x, y ): \\\Check if the index [x][y] is valid or not\\\ if x 0: return False if y 0: return False if x = self.cols(): return False if y = self.rows(): return False return True Its ok, but you could use def validIndex(self,x,y): return (0=xself.__cols) and (0=yself.__rows) def cols(self): \\\return number of cols\\\ return self.__cols def rows(self): \\\return number of rows\\\ return self.__rows def Print(self): \\\output data to console for testing\\\ print \\\nArray2D = {\ for y in range( 0, self.rows() ): for x in range( 0,
Re: [pygame] I'm getting BSOD while using PyGame.
On 10 Nov 2007 at 15:30, Jake b wrote: I've started on a very basic game, right now all it does is blit tiles to the screen. I used a NumPy tutorial to create a 2D array to store tileID's for rendering. But running it, caused my computer to get a Blue Screen Of Death. The code was x = ones( ( 3, 4 ) ) I was surprised because I was running my game in windowed mode, if I called blit() witih an invalid value, or accessed an array out of bounds, I thought it would at worst crash to desktop. I have also tried the game Snowballz, ( it uses PyGame ) So my first guess was that it was NumPy that did it. I removed NumPy, creating my own basic 2D array class that seems to be working correctly stand-alone. I started to place it into my tile code, and I got the BSOD again. Now I know it's not NumPy. The wierd thing is even when it crashes, it seems to render the tileset at least once. Sometimes it had been running for a few seconds ( at 60 renders per second ), but once it was the very first render that crashed. A BSOD is strange. Checking basics: Are you sure your alternative code has loaded ? I mean, if you run from the cmd prompt, by example c:\python24\python.exe myprog.py all modules are reloaded, but if you are runing from inside an IDE maybe you need to restart the IDE. Make sure the dir and files have standart attribs, ie no ReadOnly , no Hide, etc. I remember a time when editing in IDE and running from command line ,when IDLE writes the sources but the interpreter keeps loading the prev compiled module. Really weird. No warning messages. Just in case try deleting the .pyc before run the alternate (non Numpy) code. If you want more feedback, post more code ( from the non numeric version, to keep it easy) Cheers claxo