How many of those Convex objects are you instantiating, and how many points
are in each object? In general it'll be more efficient to larger amounts of
geometry at the same time, rather than small amounts of geometry lots of
times. By the looks of your video, it's the latter case, i.e. lots of
objects with a small number of points each.

The bottleneck in this sort of thing is often the openGL calls -
communicating with the graphics card. On every update, it's changing the
contents of the vertex buffer once for every object. If you're using a lot
of objects, that's a lot of openGL calls. It's much better to structure it
so you can update the transformations of all your polygons at once, then
send it all to the graphics card in one call. As a quick fix in your code,
you could try appending all your Convex object's vertex tuples to another
'global' list at update time, then add it to a single vertex list once per
update.

cheers

Matt



On Wed, May 15, 2013 at 9:50 AM, elliot <[email protected]> wrote:

> Hello,
>
> I wrote the first part of a tutorial on integrating pyglet, pymunk, Numpy
> and OpenCV.  Any feedback would be appreciated.
>
> The tutorial is here:
> http://pyratesarecool.appspot.com/Integrating_Pyglet_and_Pymunk
>
> -videos-
> part 1: http://vimeo.com/65989831 <https://vimeo.com/65989831>
> part 2: http://vimeo.com/64970859 <https://vimeo.com/64970859>
> part 3: http://vimeo.com/65915091 <https://vimeo.com/65915091>
>
>
> In case you don't end up reading it but have some insight, the bottleneck
> in my code right now is translating the dynamic vertices and updating
> batches.  I have 300+ polygons that are updated every frame, having
> their vertices rotated and translated.  This runs at 60 fps on my not so
> great laptop.  Am I doing the best I can?
>
> The update function is only this:
>
>     def translate(self):
>         px,py = self.body.position
>         theta = self.body.angle
>         initiald = self.initial_data
>         cost, sint = cos(theta), sin(theta)
>         #Just a bunch of multiplication and addition, optimized
>         pts = 
> [(px+x+r*(xhelper*(cost-1)-sint*yhelper),py+y+r*(yhelper*(cost-1)+sint*xhelper))
>  for x,y,r,xhelper,yhelper in initiald]
>         #flatten and assign as tuple to batch vertices
>         self.vertlist.vertices = tuple(map(int,[val for subl in pts for val 
> in subl]))
>
>
>
>  ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>         1    0.019    0.019   49.193   49.193 poly_demo.py:1(<module>)
>       ...
>      1911    0.035    0.000   44.047    0.023 poly_demo.py:122(on_draw)
>      1911    3.940    0.002   42.308    0.022 entities.py:12(step)
>    620979    2.838    0.000   37.946    0.000 entities.py:268(update)
>
>
> So this function takes up 86% of my run time.  The second to last line
> takes up 2/3 of that, and the last line 1/3.
>
>
> Thanks everyone,
> Elliot
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to