[Bf-blender-cvs] [984d6c8] master: BGE debug API and actuator

HG1 noreply at git.blender.org
Sat Jul 12 01:00:25 CEST 2014


Commit: 984d6c8677a365cf47cc6ad6c89c93b04877a948
Author: HG1
Date:   Fri Jul 11 15:18:43 2014 -0700
https://developer.blender.org/rB984d6c8677a365cf47cc6ad6c89c93b04877a948

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

===================================================================

M	doc/python_api/rst/bge.render.rst
M	doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
M	source/gameengine/GameLogic/SCA_IScene.cpp
M	source/gameengine/GameLogic/SCA_IScene.h
M	source/gameengine/Ketsji/KX_GameObject.cpp
M	source/gameengine/Ketsji/KX_GameObject.h
M	source/gameengine/Ketsji/KX_KetsjiEngine.cpp
M	source/gameengine/Ketsji/KX_KetsjiEngine.h
M	source/gameengine/Ketsji/KX_PythonInit.cpp
M	source/gameengine/Ketsji/KX_Scene.cpp
M	source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
M	source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
M	source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
M	source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
M	source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h

===================================================================

diff --git a/doc/python_api/rst/bge.render.rst b/doc/python_api/rst/bge.render.rst
index 5a80b7f..9dd4057 100644
--- a/doc/python_api/rst/bge.render.rst
+++ b/doc/python_api/rst/bge.render.rst
@@ -301,6 +301,34 @@ Functions
 
    Disable the motion blur effect.
 
+.. function:: showFramerate(enable)
+
+   Show or hide the framerate.
+
+   :type enable: boolean
+
+.. function:: showProfile(enable)
+
+   Show or hide the profile.
+
+   :type enable: boolean
+
+.. function:: showProperties(enable)
+
+   Show or hide the debug properties.
+
+   :type enable: boolean
+
+.. function:: autoDebugList(enable)
+
+   Enable or disable auto adding debug properties to the debug list.
+
+   :type enable: boolean
+
+.. function:: clearDebugList()
+
+   Clears the debug property list.
+
 .. function:: setVsync(value)
 
    Set the vsync value
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst b/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
index 215ff40..a6d03de 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_GameObject.rst
@@ -363,6 +363,18 @@ base class --- :class:`SCA_IObject`
 
       :type: float
 
+   .. attribute:: debug
+
+      If true, the object's debug properties will be displayed on screen.
+
+      :type: boolean
+
+   .. attribute:: debugRecursive
+
+      If true, the object's and children's debug properties will be displayed on screen.
+
+      :type: boolean
+
    .. method:: endObject()
 
       Delete this object, can be used in place of the EndObject Actuator.
@@ -857,3 +869,11 @@ base class --- :class:`SCA_IObject`
       :return: Whether or not the action is playing
       :rtype: boolean
 
+   .. method:: addDebugProperty (name, debug = True)
+
+      Adds a single debug property to the debug list.
+
+      :arg name: name of the property that added to the debug list.
+      :type name: string
+      :arg debug: the debug state.
+      :type debug: boolean
\ No newline at end of file
diff --git a/source/gameengine/GameLogic/SCA_IScene.cpp b/source/gameengine/GameLogic/SCA_IScene.cpp
index c98c866..3ca4b66 100644
--- a/source/gameengine/GameLogic/SCA_IScene.cpp
+++ b/source/gameengine/GameLogic/SCA_IScene.cpp
@@ -70,6 +70,32 @@ std::vector<SCA_DebugProp*>& SCA_IScene::GetDebugProperties()
 }
 
 
+bool SCA_IScene::PropertyInDebugList( class CValue *gameobj, const STR_String &name )
+{
+	for (std::vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
+		!(it==m_debugList.end());++it) {
+		STR_String debugname = (*it)->m_name;
+		CValue *debugobj = (*it)->m_obj;
+
+		if (debugobj == gameobj && debugname == name)
+			return true;
+	}
+	return false;
+}
+
+
+bool SCA_IScene::ObjectInDebugList( class CValue *gameobj )
+{
+	for (std::vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
+		!(it==m_debugList.end());++it) {
+		CValue* debugobj = (*it)->m_obj;
+
+		if (debugobj == gameobj)
+			return true;
+	}
+	return false;
+}
+
 
 void SCA_IScene::AddDebugProperty(class CValue* debugprop,
 								  const STR_String &name)
@@ -84,6 +110,24 @@ void SCA_IScene::AddDebugProperty(class CValue* debugprop,
 }
 
 
+void SCA_IScene::RemoveDebugProperty(class CValue *gameobj,
+								  const STR_String &name)
+{
+	vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
+	while(it != m_debugList.end()) {
+		STR_String debugname = (*it)->m_name;
+		CValue *debugobj = (*it)->m_obj;
+
+		if (debugobj == gameobj && debugname == name) {
+			delete (*it);
+			m_debugList.erase(it);
+			break;
+		}
+		++it;
+	}
+}
+
+
 void SCA_IScene::RemoveObjectDebugProperties(class CValue* gameobj)
 {	
 	vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
diff --git a/source/gameengine/GameLogic/SCA_IScene.h b/source/gameengine/GameLogic/SCA_IScene.h
index e2e1edd..b76b563 100644
--- a/source/gameengine/GameLogic/SCA_IScene.h
+++ b/source/gameengine/GameLogic/SCA_IScene.h
@@ -67,9 +67,11 @@ public:
 	virtual void	ReplaceMesh(class CValue* gameobj,
 								void* meshobj, bool use_gfx, bool use_phys)=0;
 	std::vector<SCA_DebugProp*>& GetDebugProperties();
+	bool			PropertyInDebugList(class CValue *gameobj, const STR_String &name);
+	bool			ObjectInDebugList(class CValue *gameobj);
 	void			RemoveAllDebugProperties();
-	void			AddDebugProperty(class CValue* debugprop,
-									 const STR_String &name);
+	void			AddDebugProperty(class CValue* debugprop, const STR_String &name);
+	void			RemoveDebugProperty(class CValue *gameobj, const STR_String &name);
 	void			RemoveObjectDebugProperties(class CValue* gameobj);
 
 	virtual void	Update2DFilter(std::vector<STR_String>& propNames, void* gameObj, 
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index f61d08e..639cd98 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 */
 
 
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index f7f40ac..d4fa485 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -934,6 +934,11 @@ public:
 		m_pObstacleSimulation = NULL;
 	}
 	
+	/**
+	 * add debug object to the debuglist.
+	 */
+	void SetUseDebugProperties(bool debug, bool recursive);
+
 	KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
 	
 	CListValue* GetChildren();
@@ -993,6 +998,7 @@ public:
 	KX_PYMETHOD_DOC_O(KX_GameObject,g

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list