diff options
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 24 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 10 |
3 files changed, 35 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 23419f11cd5..90913041521 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -184,7 +184,10 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) for (int i = tc_first; i < tc_numCategories; i++) m_logger->AddCategory((KX_TimeCategory)i); - + +#ifdef WITH_PYTHON + m_pyprofiledict = PyDict_New(); +#endif } @@ -197,6 +200,10 @@ KX_KetsjiEngine::~KX_KetsjiEngine() delete m_logger; if (m_usedome) delete m_dome; + +#ifdef WITH_PYTHON + Py_CLEAR(m_pyprofiledict); +#endif } @@ -256,6 +263,12 @@ void KX_KetsjiEngine::SetPyNamespace(PyObject *pythondictionary) MT_assert(pythondictionary); m_pythondictionary = pythondictionary; } + +PyObject* KX_KetsjiEngine::GetPyProfileDict() +{ + Py_INCREF(m_pyprofiledict); + return m_pyprofiledict; +} #endif @@ -1513,6 +1526,15 @@ void KX_KetsjiEngine::RenderDebugProperties() m_rendertools->RenderBox2D(xcoord + (int)(2.2 * profile_indent), ycoord, m_canvas->GetWidth(), m_canvas->GetHeight(), time/tottime); ycoord += const_ysize; + +#ifdef WITH_PYTHON + PyObject *val = PyTuple_New(2); + PyTuple_SetItem(val, 0, PyFloat_FromDouble(time*1000.f)); + PyTuple_SetItem(val, 1, PyFloat_FromDouble(time/tottime * 100.f)); + + PyDict_SetItemString(m_pyprofiledict, m_profileLabels[j], val); + Py_DECREF(val); +#endif } } // Add the ymargin for titles below the other section of debug info diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 92ffaf47aa4..fdfe0551d18 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -81,6 +81,7 @@ private: #ifdef WITH_PYTHON /* borrowed from sys.modules["__main__"], don't manage ref's */ PyObject* m_pythondictionary; + PyObject* m_pyprofiledict; #endif class SCA_IInputDevice* m_keyboarddevice; class SCA_IInputDevice* m_mousedevice; @@ -222,6 +223,7 @@ public: #ifdef WITH_PYTHON void SetPyNamespace(PyObject *pythondictionary); PyObject* GetPyNamespace() { return m_pythondictionary; } + PyObject* GetPyProfileDict(); #endif void SetSceneConverter(KX_ISceneConverter* sceneconverter); void SetAnimRecordMode(bool animation_record, int startFrame); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 66333a061c5..06abc755a9a 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -371,6 +371,15 @@ static PyObject *gPyLoadGlobalDict(PyObject *) Py_RETURN_NONE; } +static char gPyGetProfileInfo_doc[] = +"getProfileInfo()\n" +"returns a dictionary with profiling information"; + +static PyObject *gPyGetProfileInfo(PyObject *) +{ + return gp_KetsjiEngine->GetPyProfileDict(); +} + static char gPySendMessage_doc[] = "sendMessage(subject, [body, to, from])\n\ sends a message in same manner as a message actuator\ @@ -858,6 +867,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)"}, + {"getProfileInfo", (PyCFunction)gPyGetProfileInfo, METH_NOARGS, gPyGetProfileInfo_doc}, /* library functions */ {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""}, {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""}, |