Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHG1 <HG1_public@gmx.net>2014-07-12 02:18:43 +0400
committerMitchell Stokes <mogurijin@gmail.com>2014-07-12 03:00:14 +0400
commit984d6c8677a365cf47cc6ad6c89c93b04877a948 (patch)
tree0433fe2f7f5646d4afddca0c769c42c6cbfca56b /source/gameengine/Ketsji/KX_GameObject.cpp
parent93278165937273fd0c14eb54deb1c4c25ebb1296 (diff)
BGE debug API and actuator
This patch adds some new debug methods to the KX_GameObject for manually adding the debug list and bge.render for controlling the debug visualization. It also adds a new debug actuator, which allows to control the same functions. This patch is a updated version of T33701. Thread on Blenderartists: http://blenderartists.org/forum/showthread.php?264745-Debug-proerties-for-added-objects-patch&p=2256018&viewfull=1#post2256018 Reviewers: moguri Reviewed By: moguri Differential Revision: https://developer.blender.org/D635
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index f61d08e7f71..639cd98bb47 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -68,6 +68,7 @@ typedef unsigned long uint_ptr;
#include "SCA_IController.h"
#include "NG_NetworkScene.h" //Needed for sendMessage()
#include "KX_ObstacleSimulation.h"
+#include "KX_Scene.h"
#include "BKE_object.h"
@@ -979,6 +980,44 @@ KX_GameObject::SetOccluder(
}
}
+static void setDebug_recursive(SG_Node *node, bool debug)
+{
+ NodeList& children = node->GetSGChildren();
+ KX_Scene *scene = KX_GetActiveScene();
+
+ for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) {
+ SG_Node *childnode = (*childit);
+ KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
+ if (clientgameobj != NULL) {
+ if (debug) {
+ if (!scene->ObjectInDebugList(clientgameobj))
+ scene->AddObjectDebugProperties(clientgameobj);
+ }
+ else
+ scene->RemoveObjectDebugProperties(clientgameobj);
+ }
+
+ /* if the childobj is NULL then this may be an inverse parent link
+ * so a non recursive search should still look down this node. */
+ setDebug_recursive(childnode, debug);
+ }
+}
+
+void KX_GameObject::SetUseDebugProperties( bool debug, bool recursive )
+{
+ KX_Scene *scene = KX_GetActiveScene();
+
+ if (debug) {
+ if (!scene->ObjectInDebugList(this))
+ scene->AddObjectDebugProperties(this);
+ }
+ else
+ scene->RemoveObjectDebugProperties(this);
+
+ if (recursive)
+ setDebug_recursive(GetSGNode(), debug);
+}
+
void
KX_GameObject::SetLayer(
int l
@@ -1828,6 +1867,7 @@ PyMethodDef KX_GameObject::Methods[] = {
KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo),
KX_PYMETHODTABLE_O(KX_GameObject, getVectTo),
KX_PYMETHODTABLE(KX_GameObject, sendMessage),
+ KX_PYMETHODTABLE(KX_GameObject, addDebugProperty),
KX_PYMETHODTABLE_KEYWORDS(KX_GameObject, playAction),
KX_PYMETHODTABLE(KX_GameObject, stopAction),
@@ -1880,6 +1920,8 @@ PyAttributeDef KX_GameObject::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("childrenRecursive", KX_GameObject, pyattr_get_children_recursive),
KX_PYATTRIBUTE_RO_FUNCTION("attrDict", KX_GameObject, pyattr_get_attrDict),
KX_PYATTRIBUTE_RW_FUNCTION("color", KX_GameObject, pyattr_get_obcolor, pyattr_set_obcolor),
+ KX_PYATTRIBUTE_RW_FUNCTION("debug", KX_GameObject, pyattr_get_debug, pyattr_set_debug),
+ KX_PYATTRIBUTE_RW_FUNCTION("debugRecursive", KX_GameObject, pyattr_get_debugRecursive, pyattr_set_debugRecursive),
/* experimental, don't rely on these yet */
KX_PYATTRIBUTE_RO_FUNCTION("sensors", KX_GameObject, pyattr_get_sensors),
@@ -2796,6 +2838,52 @@ PyObject *KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_
return self->m_attr_dict;
}
+PyObject *KX_GameObject::pyattr_get_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_Scene *scene = KX_GetActiveScene();
+ KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
+
+ return PyBool_FromLong(scene->ObjectInDebugList(self));
+}
+
+int KX_GameObject::pyattr_set_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
+ int param = PyObject_IsTrue(value);
+
+ if (param == -1) {
+ PyErr_SetString(PyExc_AttributeError, "gameOb.debug = bool: KX_GameObject, expected True or False");
+ return PY_SET_ATTR_FAIL;
+ }
+
+ self->SetUseDebugProperties(param, false);
+
+ return PY_SET_ATTR_SUCCESS;
+}
+
+PyObject *KX_GameObject::pyattr_get_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_Scene *scene = KX_GetActiveScene();
+ KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
+
+ return PyBool_FromLong(scene->ObjectInDebugList(self));
+}
+
+int KX_GameObject::pyattr_set_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
+ int param = PyObject_IsTrue(value);
+
+ if (param == -1) {
+ PyErr_SetString(PyExc_AttributeError, "gameOb.debugRecursive = bool: KX_GameObject, expected True or False");
+ return PY_SET_ATTR_FAIL;
+ }
+
+ self->SetUseDebugProperties(param, true);
+
+ return PY_SET_ATTR_SUCCESS;
+}
+
PyObject *KX_GameObject::PyApplyForce(PyObject *args)
{
int local = 0;
@@ -3617,6 +3705,29 @@ KX_PYMETHODDEF_DOC(KX_GameObject, isPlayingAction,
}
+KX_PYMETHODDEF_DOC(KX_GameObject, addDebugProperty,
+"addDebugProperty(name, visible=1)\n"
+"Added or remove a debug property to the debug list.\n")
+{
+ KX_Scene *scene = KX_GetActiveScene();
+ char *name;
+ int visible = 1;
+
+ if (!PyArg_ParseTuple(args,"s|i:debugProperty", &name , &visible))
+ return NULL;
+
+ if (visible) {
+ if (!scene->PropertyInDebugList(this, name))
+ scene->AddDebugProperty(this, name);
+ }
+ else {
+ scene->RemoveDebugProperty(this, name);
+ }
+
+ Py_RETURN_NONE;
+}
+
+
/* dict style access */