Hey Alex,

Thanks heaps for the response.

I've tried that out, and am now using the exact canonical 'hello
world' example, cut and paste from the programming guide, and it does
help, but I'm still very confused.

My 'update' function now gets called every 33 to 37ms, no matter what
happens. This is not quite the 30fps I asked for, but is much
improved, and is unaffected by mouse events.

However, on_draw() gets called at 45 to 55 fps, and this rises to
120fps when I move the mouse. So many of my calls to on_draw() are
redundant (drawing the same thing as last frame)

It no longer adds the extra-slow frames after I stop moving the mouse
- now it drops directly back to ~50fps.

I am still seeing tearing.

I'm looking for on_draw() and update() to be called in lockstep, one
directly after the other, with the built-in display buffer flips being
vsynched to monitor refreshes.  Am I being dumb?

Thanks for any suggestions anyone has. I'll keep playing with it and
report any findings, but am beginning to be tempted to write my own
explicit event loop. The programming guide recommends against it
though.

My code now looks like:

----------------------------------
import pyglet

window = pyglet.window.Window()
clockDisplay = pyglet.clock.ClockDisplay()
label = pyglet.text.Label('Hello, world',
                          font_name='Times New Roman',
                          font_size=36,
                          x=window.width//2, y=window.height//2,
                          anchor_x='center', anchor_y='center')
ticks = []

def update(dt):
    ticks.append(dt)

@window.event
def on_draw():
    window.clear()
    label.draw()
    clockDisplay.draw()

pyglet.clock.schedule_interval(update, 1.0/30)
pyglet.app.run()
print "ticks:", " ".join("%.1f" % (t*1000) for t in ticks)





On Jun 20, 6:39 pm, "Alex Holkner" <[EMAIL PROTECTED]> wrote:
> On 6/21/08, Tartley <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> >  Hey there,
>
> >  Moving the mouse causes the framerate of my Pyglet application to
> >  increase massively (from the requested 30fps to about 80fps.) When I
> >  stop moving the mouse, the framerate becomes very slow and jerky
> >  (alternating between frames of ~2ms and ~250ms). This jerkiness lasts
> >  for about as long as the duration of the former mouse movement.
> >  Presumably the event loop is trying to slow down to compensate for the
> >  very fast frames earlier.
>
> >  Even when I don't touch the mouse, while the framerate hovers around
> >  30fps, every so often (a few times per second) I get a really fast
> >  frame (~2ms), followed by one or two really slow ones (~90ms.)
>
> >  Presumably events are short-cutting the sleep that happens between
> >  each frame. Mouse events come in a prolific stream, causing every
> >  frame to be shortened. Other events come occasionally, causing the
> >  sporadic deviations from 30fps.
>
> >  Also, possibly related, I am still seeing tearing when I add some
> >  rapidly moving polygons into the draw event, even though printing
> >  window.vsync reports True. Changing vsync to False does not change the
> >  framerate issue.
>
> >  I've reduced my code to what I *believe* is a fairly canonical event
> >  loop (below)
>
> >  This is on 1.1beta, Ubuntu 8.04, on a dual core thinkpad T60. I'll try
> >  it out on v1.0, see how that goes, post results here. In the meantime,
> >  Any ideas or suggestions much appreciated.
>
> >  ---------------------------
> >  from pyglet import app, clock, window
>
> >  win = window.Window(vsync=True)
> >  clockDisplay = clock.ClockDisplay()
> >  ticks = []
>
> >  def update(dt):
> >     ticks.append(dt)
>
> > [EMAIL PROTECTED]
> >  def on_draw():
> >     win.clear()
> >     clockDisplay.draw()
>
> >  clock.set_fps_limit(30)
> >  clock.schedule(update)
>
> set_fps_limit can't really do its job in the pyglet 1.1-style loop.
> An equivalent and better performing solution is to delete the call to
> set_fps_limit, and instead schedule your update function at the
> desired rate:
>
> clock.schedule_interval(update, 1/30.0)
>
> I imagine this will solve your framerate issue under pyglet 1.1.  I'll
> have a look and see if there's an easy fix for set_fps_limit,
> otherwise I'll probably mark it deprecated in the future.
>
> Alex.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to