By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,879 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,879 IT Pros & Developers. It's quick & easy.

shoving a [pygame] up your [gtk]!

P: n/a
My project:
I'm working on a game, where in the ui, it takes the pygame window, and
shoves it into a gtk2 socket widget. (gtk2 widgets are generated with
glade, with the exception of the socket widget, which is manualy added
into a window)

My problem:
Since adding the gtk half, it is realy slow. I can make one or the
other update realy fast, or I can make it so the pygame window/widget
gets a fluctuation in framerate between realy good, then realy bad,
I've narrowed down my problem a bit to my events loop.

Here's a simplified version of the events loop:

while True:

game_board is a class defining pygame/opengl code that produces the
pygame window, and a simple game engine (its actualy a place holder
untill I can make it run full speed. think of something with the
sophistication of the pygame chimp example, or a opengl hello world).
The same unmodified engine (pure pygame/opengl, no gtk2) works fine.

game_board.frame() performs some game logic tasks, and updates the
pygame display. It also handles some keyboard inputs, but only grabs
the latest one on the pygame stack.
So here's the problem sumary, as far as I can gather:
What I think is happening is that gtk.main_iteration(block=False) works
through every event in the queue untill there aren't any, THEN the
pygame event loop briefly fires, checks one or two events from the
pygame queue, and the loop repeats.
(An intresting varriation to the loop above only allowed
gtk.main_iteration to run when the pygame framerate is above 60... this
resulted in the two taking turns monopolising cpu, heh)

Here's what I think I want to do:
I'm looking for something to the equivalent of processing the one gtk
event (and remove it from it's stack), and then call
game_board.frame(), and have the loop repeate, possibly with some load
balancing to allow multiple gtk events to process if the framerate is
high. However, this is where I've hit a wall.

So here we go.

If I'm correct in my assumptions, how can I break down gtk.main even

If I'm wrong, advice steering me in the right direction, or a shot in
the head--- both would be appreciated :)

Jul 6 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.