shoving a [pygame] up your [gtk]!

L

Lunpa

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,
repeat.
I've narrowed down my problem a bit to my events loop.

Here's a simplified version of the events loop:

while True:
gtk.main_iteration(block=False)
game_board.clock.tick(75)
game_board.frame()

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
further?

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top