[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re: Fullscreen Performance



Gerrit Holl wrote:

but when I run the game normally I get 10-50 fps at this
resolution non-scrolling, dependant on the number of
sprites in the neighbourhood
when i'm benchmarking, i find it helpful to set a constant "seed" for the random numbers. this way you get the same results every time the game runs. just add a "random.seed(1)" somewhere early in your code.



My game, Brian, is not tile oriented, so this discussion won't
help me much. I don't know exactly what psyco is, but I will
have a look at it.
psyco is a sort of just-in-time compiler for python code. it is very easy to make use of in your application (just pick which functions you want the extra compiling for). it usually makes a noticeable difference on games, but your mileage will definitely vary.

i just took a very quick walk through the rendering code for brian. a couple of quick things i noticed that needed some work.

first, when rendering the background, you always clear it with the background color (currently black). even when the area is covered by a platform. it is well worth your time to not fill these areas, as the "overdraw" costs much more than the time needed to compute things a bit smarter.

second, your platforms are currently all drawn with "tiled" images. every time the platform is drawn, it does a lot of fancy wok in tiled_blit(). at minimum, compute this data once per platform (the offset and boundary used for each blit in the tile). better, but more memory intensive would be to render the platform out in its entirety to an offscreen Surface.

i believe these two changes will provide a bit of performance.

other things would be to remove as much 'conditional logic' from the rendering mainloop. instead of code like

it platform.type == "tiled":
blit_tile(platform)

have the platform predetermine which functions will be called to render, and just call that

platform.render()

then be sure in your tightest of tightest loops, to not call any python globals or builtins. make a local variable copy of them in the function, and they will be accessed much quicker.