[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55400] trunk/blender/source/gameengine/ Ketsji: BGE: Adding a getProfileInfo() function to bge.logic.
Mitchell Stokes
mogurijin at gmail.com
Tue Mar 19 05:51:38 CET 2013
Revision: 55400
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55400
Author: moguri
Date: 2013-03-19 04:51:37 +0000 (Tue, 19 Mar 2013)
Log Message:
-----------
BGE: Adding a getProfileInfo() function to bge.logic. This function returns a Python dictionary with the same information as the on screen profiler.
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h
trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
Modified: trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 2013-03-19 04:29:48 UTC (rev 55399)
+++ trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 2013-03-19 04:51:37 UTC (rev 55400)
@@ -184,7 +184,10 @@
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 @@
delete m_logger;
if (m_usedome)
delete m_dome;
+
+#ifdef WITH_PYTHON
+ Py_CLEAR(m_pyprofiledict);
+#endif
}
@@ -256,6 +263,12 @@
MT_assert(pythondictionary);
m_pythondictionary = pythondictionary;
}
+
+PyObject* KX_KetsjiEngine::GetPyProfileDict()
+{
+ Py_INCREF(m_pyprofiledict);
+ return m_pyprofiledict;
+}
#endif
@@ -1513,6 +1526,15 @@
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
Modified: trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h 2013-03-19 04:29:48 UTC (rev 55399)
+++ trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h 2013-03-19 04:51:37 UTC (rev 55400)
@@ -81,6 +81,7 @@
#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 @@
#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);
Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp 2013-03-19 04:29:48 UTC (rev 55399)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp 2013-03-19 04:51:37 UTC (rev 55400)
@@ -371,6 +371,15 @@
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 @@
{"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 *)""},
More information about the Bf-blender-cvs
mailing list