diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2012-09-02 01:23:05 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2012-09-02 01:23:05 +0400 |
commit | 53f343edd785f346dccdf39dedfe7626260b63a5 (patch) | |
tree | a9c3ac907eae3dd1247168e4cd9dff2760669b27 /source/gameengine/Ketsji | |
parent | 779ecb06dd3f3b5c47391675622fb96d041b23ae (diff) |
..\commmit_hive.txt
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 19 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.h | 10 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonMain.cpp | 78 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonMain.h | 41 |
5 files changed, 149 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 4b3426e0784..269311b7e00 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -107,6 +107,7 @@ set(SRC KX_PyMath.cpp KX_PythonInit.cpp KX_PythonInitTypes.cpp + KX_PythonMain.cpp KX_PythonSeq.cpp KX_RadarSensor.cpp KX_RayCast.cpp @@ -189,6 +190,7 @@ set(SRC KX_PyMath.h KX_PythonInit.h KX_PythonInitTypes.h + KX_PythonMain.h KX_PythonSeq.h KX_RadarSensor.h KX_RayCast.h diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 581b3712f97..86928803502 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -811,6 +811,23 @@ static PyObject *gLibList(PyObject*, PyObject* args) return list; } +struct PyNextFrameState pynextframestate; +static PyObject *gPyNextFrame(PyObject *) +{ + if (pynextframestate.func == NULL) Py_RETURN_NONE; + if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead? + + if (pynextframestate.func(pynextframestate.state)) //nonzero = stop + { + Py_RETURN_TRUE; + } + else // 0 = go on + { + Py_RETURN_FALSE; + } +} + + static struct PyMethodDef game_methods[] = { {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc}, {"startGame", (PyCFunction)gPyStartGame, METH_VARARGS, (const char *)gPyStartGame_doc}, @@ -840,7 +857,7 @@ static struct PyMethodDef game_methods[] = { {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"}, {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"}, {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"}, - + {"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"}, /* library functions */ {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""}, diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 866681b9da7..1500dd97ae1 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -70,6 +70,16 @@ class KX_Scene; void KX_SetActiveScene(class KX_Scene* scene); class KX_Scene* KX_GetActiveScene(); class KX_KetsjiEngine* KX_GetActiveEngine(); + +typedef int (*PyNextFrameFunc)(void *); +struct PyNextFrameState { + //state: can be either a GPG_NextFrameState or a BL_KetsjiNextFrameState + void *state; + //func: can be either GPG_PyNextFrame or BL_KetsjiPyNextFrame + PyNextFrameFunc func; +}; +extern struct PyNextFrameState pynextframestate; + #include "MT_Vector3.h" void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color); diff --git a/source/gameengine/Ketsji/KX_PythonMain.cpp b/source/gameengine/Ketsji/KX_PythonMain.cpp new file mode 100644 index 00000000000..969ecbea5a9 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.cpp @@ -0,0 +1,78 @@ +/* + * $Id: KX_PythonMain.cpp 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +/** \file gameengine/Ketsji/KX_KetsjiPythonMain.cpp + * \ingroup ketsji + */ + +#include "KX_PythonMain.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "RNA_access.h" +#include "MEM_guardedalloc.h" +#include "BKE_text.h" +#include "BKE_main.h" + +#ifdef __cplusplus +} +#endif + +extern "C" char *KX_GetPythonMain(struct Scene* scene) +{ + //examine custom scene properties + + PointerRNA sceneptr; + RNA_id_pointer_create(&scene->id, &sceneptr); + + PropertyRNA *pymain = RNA_struct_find_property(&sceneptr, "[\"__main__\"]"); + if (pymain == NULL) return NULL; + char *python_main; + int len; + python_main = RNA_property_string_get_alloc(&sceneptr, pymain, NULL, 0, &len); + return python_main; +} + +extern "C" char *KX_GetPythonCode(Main *main, char *python_main) +{ + PointerRNA mainptr, txtptr; + PropertyRNA *texts; + + RNA_main_pointer_create(main, &mainptr); + texts = RNA_struct_find_property(&mainptr, "texts"); + char *python_code = NULL; + int ok = RNA_property_collection_lookup_string(&mainptr, texts, python_main, &txtptr); + if (ok) { + Text *text = (Text *) txtptr.data; + python_code = txt_to_buf(text); + } + return python_code; +} + diff --git a/source/gameengine/Ketsji/KX_PythonMain.h b/source/gameengine/Ketsji/KX_PythonMain.h new file mode 100644 index 00000000000..1460ea2ca96 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonMain.h @@ -0,0 +1,41 @@ +/* + * $Id: KX_PythonMain.h 37750 2011-06-27 09:27:56Z sjoerd $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file KX_PythonMain.h + * \ingroup ketsji + */ + +#ifndef __KX_PYTHON_MAIN +#define __KX_PYTHON_MAIN + +#include "BKE_main.h" +#include "DNA_scene_types.h" +extern "C" char *KX_GetPythonMain(struct Scene* scene); +extern "C" char *KX_GetPythonCode(struct Main *main, char *python_main); +#endif |