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

Willian Padovani Germano wgermano at ig.com.br
Wed Sep 10 03:13:41 CEST 2003


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.

BTW, I've played two games recently, recommended and developed by d0oGs:
Armadillos and Smash Blaster.  The last time I tried some Blender games was
probably more than two years ago, not sure.  So again I was surprised by the
power of the engine and talent in the community.  Very nice games have been
made, with specially good gfx, compared to most amateur games out there.

--
Willian, wgermano at ig.com.br





More information about the Bf-python mailing list