[Bf-python] game engine callbacks for Blender.Draw gui's

tdyar at mit.edu tdyar at mit.edu
Fri Sep 12 16:56:17 CEST 2003


Thanks Willian!

I'm checking out events, too. Looks like screenmain() in editscreen.c controls 
when a window gets events. Redraws can be forced or queued, but events can only 
be queued -- at least that's all I can see.

This could be changed by writing some function like scrarea_do_windraw(ScrArea 
*area), such as scrarea_do_pump_events(ScrArea *area). Then all queued events 
would be pumped through the event handler. This is possible without too much 
trouble, but I think it should be done in the context of the script ui 
integration.

I just put in a notify_game(short val) in my local copy that queues a game 
event on all textspace screens. They only handle the event when the mouse gives 
the window focus, though.

Tom


> Hi Thomas,
> 
> Let me warn you that we're in the process of adding a new space exclusive
> for guis from scripts, plus also changing the handling of global
> dictionaries and start/stop of the Python Interpreter, besides also general
> pop-up windows support from scripts, so things are 'volatile' there right
> now.
> 
> From: "Thomas Dyar" <tdyar at MIT.EDU>
> (...)
> > It would be cool if the game engine start and stop could trigger an event
> > that could be picked up by the registered Draw event callback. Can someone
> > give me a rough sketch of the callback process re. the python?
> 
> Looking at the code should give you a good idea of how they implemented it
> in bpython.  The Register method in exppython's Draw.c links valid callbacks
> for drawing, events and gui button events in three pointers in the SpaceText
> struct, as you probably already saw.  exec_callback uses the Python/C
> PyObject_CallObject function to execute the registered python function.  The
> 'kernel' of it all is in Draw.c, below the comment:
> 
> /* GUI interface routines */
> 
> up to Method_Register.  The functions prepended with 'BPY_' are called from
> drawtext.c, first thing in the drawtextspace function, if there are
> registered callbacks.  These draw* space functions are called every redraw
> loop, so it's a good place to check if there's a gui / event / button
> handler and pass control to it.
> 
> One thing that should change is that the three pointers to the callbacks
> won't be in the SpaceText struct anymore, but rather in a new script struct,
> so that if there's more than one script with gui running, each SpaceScript
> will execute the one currently selected from a dropdown menu list (like in
> the SpaceText's header, known as the Text window header).
> 
> Both ideas you presented are possible, after the changes are made so that
> the game engine doesn't stop/restart the Interpreter anymore.  Adding an
> event to inform start/stopping of the game engine is a nicer solution if you
> want a script to be able to "know" when the game stopped.
> 
> Right now I'm having to study events, etc. in Blender to add support for
> pop-up windows, so in a week or so I may have a good idea of how it is done,
> though finishing the other pre-requisites needed to integrate bpython and
> the game engine should take more time than that.
> 
> One thing that may require care is that the registered py callbacks are only
> called if their window is visible.





More information about the Bf-python mailing list