From: Tom <rtp...@us...> - 2010-11-26 12:49:24
|
gemrb: Infinity Engine emulator The branch master has been updated via bf074daba4f97b293a5a37e4d44d45b5668231c4 (commit) Summary of changes: gemrb/core/Interface.cpp | 6 ++++++ gemrb/core/Interface.h | 5 +++++ gemrb/plugins/GUIScript/GUIScript.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 0 deletions(-) from d803d800c81ff730548cc688be2a8750da8d9b4a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://gemrb.git.sourceforge.net/git/gitweb.cgi?p=gemrb/gemrb;a=commitdiff;h=bf074daba4f97b293a5a37e4d44d45b5668231c4 commit bf074daba4f97b293a5a37e4d44d45b5668231c4 Author: Tom Prince <tom...@ua...> Date: Fri Nov 26 06:27:55 2010 -0500 GUIScript: Add SetTimerHook, to allow python to hook in to main loop. This is for doing crazy stuff like twisted web browsers. Signed-off-by: Tom Prince <tom...@ua...> diff --git a/gemrb/core/Interface.cpp b/gemrb/core/Interface.cpp index 43063ce..620df6e 100644 --- a/gemrb/core/Interface.cpp +++ b/gemrb/core/Interface.cpp @@ -1044,6 +1044,7 @@ void Interface::Main() ( unsigned char * ) fpsstring, palette, IE_FONT_ALIGN_LEFT | IE_FONT_ALIGN_MIDDLE, true ); } + TickHook->call(); } while (video->SwapBuffers() == GEM_OK); gamedata->FreePalette( palette ); } @@ -5361,6 +5362,11 @@ void Interface::StripLine(char * string, size_t size) { } } +void Interface::SetTickHook(EventHandler hook) +{ + TickHook = hook; +} + void Interface::SetNextScript(const char *script) { strncpy( NextScript, script, sizeof(NextScript) ); diff --git a/gemrb/core/Interface.h b/gemrb/core/Interface.h index af152df..c470d74 100644 --- a/gemrb/core/Interface.h +++ b/gemrb/core/Interface.h @@ -33,6 +33,7 @@ #include "exports.h" #include "Cache.h" +#include "Callback.h" #include "GlobalTimer.h" #include "Holder.h" @@ -328,6 +329,8 @@ private: bool update_scripts; /** Next Script Name */ char NextScript[64]; + /** Function to call every main loop iteration */ + EventHandler TickHook; public: Holder<StringMgr> strings; GlobalTimer * timer; @@ -769,6 +772,8 @@ public: Audio* GetAudioDrv(void) const; + void SetTickHook(EventHandler); + #ifdef _DEBUG int FileStreamPtrCount; int CachedFileStreamPtrCount; diff --git a/gemrb/plugins/GUIScript/GUIScript.cpp b/gemrb/plugins/GUIScript/GUIScript.cpp index 3041a40..3cc2a49 100644 --- a/gemrb/plugins/GUIScript/GUIScript.cpp +++ b/gemrb/plugins/GUIScript/GUIScript.cpp @@ -9696,6 +9696,36 @@ static PyObject* GemRB_GetSpellCastOn(PyObject* /*self*/, PyObject* args) return PyString_FromString(splname); } +PyDoc_STRVAR( GemRB_SetTickHook__doc, +"Set callback to be called every main loop iteration.\n\n" +"This is useful for things like running a twisted reactor."); + +static PyObject* GemRB_SetTickHook(PyObject* /*self*/, PyObject* args) +{ + PyObject* function; + + if (!PyArg_ParseTuple(args, "O", &function)) { + return AttributeError( GemRB_SetTickHook__doc ); + } + + EventHandler handler; + if (function == Py_None) { + handler = new Callback(); + } else if (PyCallable_Check(function)) { + handler = new PythonCallback(function); + } else { + char buf[256]; + // TODO: Print function name. (func.__name__) + snprintf(buf, sizeof(buf), "Can't set timed event handler!"); + return RuntimeError(buf); + } + + core->SetTickHook(handler); + + Py_INCREF(Py_None); + return Py_None; +} + static PyMethodDef GemRBMethods[] = { METHOD(ActOnPC, METH_VARARGS), METHOD(AddNewArea, METH_VARARGS), @@ -9860,6 +9890,7 @@ static PyMethodDef GemRBMethods[] = { METHOD(SetPlayerSound, METH_VARARGS), METHOD(SetPurchasedAmount, METH_VARARGS), METHOD(SetRepeatClickFlags, METH_VARARGS), + METHOD(SetTickHook, METH_VARARGS), METHOD(SetTimedEvent, METH_VARARGS), METHOD(SetToken, METH_VARARGS), METHOD(SetTooltipDelay, METH_VARARGS), ----------------------------------------------------------------------- This is an automated email from the git hooks/post-receive script. -- gemrb: Infinity Engine emulator |