From 9847537979b8a3ccf4ee5c7f6ca5b66ed9d7b80b Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 1 Apr 2017 00:57:38 +0200 Subject: BGE: new bge.logic.Render() to perform render w/o logic step. This function works only if python has control: 1. add scene custom property, call it __main__ 2. give it string value as the name of a text block 3. code game loop in python in text block. Example: import bge bge.logic.setUseExternalClock(True) t = 0.0; scene = bge.logic.getCurrentScene() cam = scene.cameras["Camera"] cam.setViewport(120,120,370,370) while not bge.logic.NextFrame(): cam.useViewport = True # second render with viewport enable, clock time unchanged bge.logic.Render() # advance animation for next frame t += 0.02 bge.logic.setClockTime(t) cam.useViewport = False --- source/gameengine/Ketsji/KX_PythonInit.cpp | 10 ++++++++++ source/gameengine/Ketsji/KX_PythonInit.h | 3 +++ 2 files changed, 13 insertions(+) (limited to 'source/gameengine/Ketsji') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index a93294e93ee..8b9dd2df9b1 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -905,6 +905,15 @@ static PyObject *gPyNextFrame(PyObject *) } } +static PyObject *gPyRender(PyObject *) +{ + if (pynextframestate.render == NULL) Py_RETURN_NONE; + if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead? + + pynextframestate.render(pynextframestate.state); + Py_RETURN_NONE; +} + static struct PyMethodDef game_methods[] = { {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc}, @@ -953,6 +962,7 @@ static struct PyMethodDef game_methods[] = { {"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)"}, + {"Render", (PyCFunction)gPyRender, METH_NOARGS, (const char *)"Do only render (skip logic), if Python has control"}, {"getProfileInfo", (PyCFunction)gPyGetProfileInfo, METH_NOARGS, gPyGetProfileInfo_doc}, /* library functions */ {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 6550934a916..3b754ea1e25 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -78,12 +78,15 @@ KX_Scene *KX_GetActiveScene(); KX_KetsjiEngine *KX_GetActiveEngine(); typedef int (*PyNextFrameFunc)(void *); +typedef void (*PyRenderFunc)(void *); struct PyNextFrameState { /** can be either a GPG_NextFrameState or a BL_KetsjiNextFrameState */ void *state; /** can be either GPG_PyNextFrame or BL_KetsjiPyNextFrame */ PyNextFrameFunc func; + /** can be either GPG_PyRender or BL_KetsjiPyRender */ + PyRenderFunc render; }; extern struct PyNextFrameState pynextframestate; -- cgit v1.2.3