[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Re: Fullscreen Performance
Pete Shinners wrote:
> 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.
Ah, yes. This is indeed a good solution, thanks!
> >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 will have a look at it this afternoon.
> 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.
Yes, of course! Why didn't I realise that myself... Thanks
for noticing!
> 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.
The same is true here... in the beginning, I had one big
background image, which was very slow, but platform images
are of course much smaller.
> i believe these two changes will provide a bit of performance.
Yes, it sounds very logical!
> 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.
Thanks for your advices! I will look at my code and see where I
can optimize it according to your advice. I will let the list know
about my results when I'm done.
Gerrit.
--
266. If the animal be killed in the stable by God (an accident), or if
a lion kill it, the herdsman shall declare his innocence before God, and
the owner bears the accident in the stable.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/