[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Some particle system insights



> I found that set_at was more efficient than blitting 1x1 rects by a
> factor of about 8x, _even on non-accelerated surfaces_. This implies
> that for very small sprites (2x3 or smaller), going with direct pixel
> access is faster than blitting, even on non-hardware platforms like
> XWindow. When I tried it under windows, I found that the factor was
> around 12x.

the other thing you might try is using the fill function to fill
a 1x1 rectangle. i'm curious how it compares in speed with the
other two. also, what depth of surface is this? i'm curious if
it is 8bit? also, are the bullet colors constant or varied?



> The difference was eating up the improved performance. The lesson is:
> pygame's collision routines are better at detecting collisions between
> rects than between points and rects.

yeah, i noticed when writing aliens that i could get a big speedup
by letting pygame loop over my rectangles instead of python. hence
the two Rect functions, Rect.collidelist() and Rect.collidelistall().
I've heard it mentioned before (and i mostly agree) that these are
some ugly function names. collidelist() is good for finding if
any rectangles overlap, collidelistall() is good for finding 'all'
the rectangles that overlap.

unfortunately this doesn't do anything for points. early on i did have
a point type, but it got canned early on. after writing it up it was
identical to a 2 element Numeric array. the numeric array was still
superior and it would have been a bit of work to match all its features.

it was a tricky thing. when dealing with the points and rectangles,
it turned out having a "size" type might be needed to clear out some
ambiguity. in the end it just seemed like using any 2-element sequence
was the easiest way to go. (and users could then use Numeric arrays
if they wanted a lot of functionality)

perhaps the easiest road here would be to add some collide functions
for lists of points in the Rect. two questions then...

what would be the best name for these functions if we don't change
the rectangle list functions?
and/or... if we change the names of the current rectangle list 
functions, what is the best naming method for all list collisions?


> So - would a point class be a good idea?

or perhaps we could bring back the point type. but i'm not too sure
that is the best solution.


i never closed the door on this issue when writing pygame. it
definitely is in the category of 'tackle it when we get there'.
i suppose that now we are "there". :]


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org