[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58126] branches/ge_dev/source/gameengine: BGE: Committing patch #32422 "Debug properties for added objects" by HG1.

Mitchell Stokes mogurijin at gmail.com
Tue Jul 9 22:06:37 CEST 2013


Revision: 58126
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58126
Author:   moguri
Date:     2013-07-09 20:06:36 +0000 (Tue, 09 Jul 2013)
Log Message:
-----------
BGE: Committing patch #32422 "Debug properties for added objects" by HG1.

This patch allows debug properties from objects added to the scene at runtime to be displayed under the Debug Properties in the overhead display.

Modified Paths:
--------------
    branches/ge_dev/source/gameengine/Converter/KX_ConvertProperties.cpp
    branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.cpp
    branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.h
    branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.h
    branches/ge_dev/source/gameengine/Ketsji/KX_Scene.cpp
    branches/ge_dev/source/gameengine/Ketsji/KX_Scene.h

Modified: branches/ge_dev/source/gameengine/Converter/KX_ConvertProperties.cpp
===================================================================
--- branches/ge_dev/source/gameengine/Converter/KX_ConvertProperties.cpp	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/Converter/KX_ConvertProperties.cpp	2013-07-09 20:06:36 UTC (rev 58126)
@@ -131,7 +131,7 @@
 		
 		if (propval)
 		{
-			if (show_debug_info)
+			if (show_debug_info && isInActiveLayer)
 			{
 				scene->AddDebugProperty(gameobj,STR_String(prop->name));
 			}
@@ -159,7 +159,7 @@
 		prop = prop->next;
 	}
 	// check if state needs to be debugged
-	if (object->scaflag & OB_DEBUGSTATE)
+	if (object->scaflag & OB_DEBUGSTATE && isInActiveLayer)
 	{
 		//  reserve name for object state
 		scene->AddDebugProperty(gameobj,STR_String("__state__"));

Modified: branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.cpp
===================================================================
--- branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.cpp	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.cpp	2013-07-09 20:06:36 UTC (rev 58126)
@@ -74,9 +74,28 @@
 void SCA_IScene::AddDebugProperty(class CValue* debugprop,
 								  const STR_String &name)
 {
-	SCA_DebugProp* dprop = new SCA_DebugProp();
-	dprop->m_obj = debugprop;
-	debugprop->AddRef();
-	dprop->m_name = name;
-	m_debugList.push_back(dprop);
+	if (m_debugList.size() < DEBUG_MAX_DISPLAY) {
+		SCA_DebugProp* dprop = new SCA_DebugProp();
+		dprop->m_obj = debugprop;
+		debugprop->AddRef();
+		dprop->m_name = name;
+		m_debugList.push_back(dprop);
+	}
 }
+
+
+void SCA_IScene::RemoveObjectDebugProperties(class CValue* gameobj)
+{	
+	vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
+	while(it != m_debugList.end()) {
+		CValue* debugobj = (*it)->m_obj;
+
+		if (debugobj == gameobj) {
+			delete (*it);
+			m_debugList.erase(it);
+			continue;
+		}
+		++it;
+	}
+}
+

Modified: branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.h
===================================================================
--- branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.h	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/GameLogic/SCA_IScene.h	2013-07-09 20:06:36 UTC (rev 58126)
@@ -41,6 +41,8 @@
 #include "MEM_guardedalloc.h"
 #endif
 
+#define DEBUG_MAX_DISPLAY 100
+
 struct SCA_DebugProp
 {
 	class CValue*	m_obj;
@@ -65,9 +67,11 @@
 	virtual void	ReplaceMesh(class CValue* gameobj,
 								void* meshobj, bool use_gfx, bool use_phys)=0;
 	std::vector<SCA_DebugProp*>& GetDebugProperties();
+	void			RemoveAllDebugProperties();
 	void			AddDebugProperty(class CValue* debugprop,
 									 const STR_String &name);
-	void			RemoveAllDebugProperties();
+	void			RemoveObjectDebugProperties(class CValue* gameobj);
+
 	virtual void	Update2DFilter(std::vector<STR_String>& propNames, void* gameObj, 
 									RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, 
 									int pass, STR_String& text) {}

Modified: branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2013-07-09 20:06:36 UTC (rev 58126)
@@ -129,8 +129,6 @@
 	m_keyboarddevice(NULL),
 	m_mousedevice(NULL),
 
-	m_propertiesPresent(false),
-
 	m_bInitialized(false),
 	m_activecam(0),
 	m_bFixedTime(false),
@@ -515,7 +513,7 @@
 
 	// Show profiling info
 	m_logger->StartLog(tc_overhead, m_kxsystem->GetTimeInSeconds(), true);
-	if (m_show_framerate || m_show_profile || (m_show_debug_properties && m_propertiesPresent))
+	if (m_show_framerate || m_show_profile || (m_show_debug_properties))
 	{
 		RenderDebugProperties();
 	}
@@ -1389,7 +1387,6 @@
 { 
 	m_scenes.push_back(scene);
 	PostProcessScene(scene);
-	SceneListsChanged();
 }
 
 
@@ -1533,7 +1530,7 @@
 	ycoord += title_y_top_margin;
 
 	/* Property display*/
-	if (m_show_debug_properties && m_propertiesPresent) {
+	if (m_show_debug_properties) {
 
 		/* Title for debugging("Debug properties") */
 		m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
@@ -1548,18 +1545,22 @@
 		// Add the title indent afterwards
 		ycoord += title_y_bottom_margin;
 
+		/* Calculate amount of properties that can displayed. */
+		unsigned propsAct = 0;
+		unsigned propsMax = (m_canvas->GetHeight() - ycoord) / const_ysize;
+
 		KX_SceneList::iterator sceneit;
 		for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++) {
 			KX_Scene* scene = *sceneit;
 			/* the 'normal' debug props */
 			vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();
 			
-			for (vector<SCA_DebugProp*>::iterator it = debugproplist.begin();
-			     !(it==debugproplist.end());it++)
+			for (unsigned i=0; i < debugproplist.size() && propsAct < propsMax; i++)
 			{
-				CValue *propobj = (*it)->m_obj;
+				CValue *propobj = debugproplist[i]->m_obj;
 				STR_String objname = propobj->GetName();
-				STR_String propname = (*it)->m_name;
+				STR_String propname = debugproplist[i]->m_name;
+				propsAct++;
 				if (propname == "__state__") {
 					// reserve name for object state
 					KX_GameObject* gameobj = static_cast<KX_GameObject*>(propobj);
@@ -1943,28 +1944,10 @@
 		ReplaceScheduledScenes();
 		RemoveScheduledScenes();
 		AddScheduledScenes();
-
-		// Notify
-		SceneListsChanged();
 	}
 }
 
 
-
-void KX_KetsjiEngine::SceneListsChanged(void)
-{
-	m_propertiesPresent = false;
-	KX_SceneList::iterator sceneit = m_scenes.begin();
-	while ((sceneit != m_scenes.end()) && (!m_propertiesPresent))
-	{
-		KX_Scene* scene = *sceneit;
-		vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();
-		m_propertiesPresent = !debugproplist.empty();
-		sceneit++;
-	}
-}
-
-
 void KX_KetsjiEngine::SetHideCursor(bool hideCursor)
 {
 	m_hideCursor = hideCursor;

Modified: branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.h	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/Ketsji/KX_KetsjiEngine.h	2013-07-09 20:06:36 UTC (rev 58126)
@@ -437,7 +437,6 @@
 	/**
 	 * This method is invoked when the scene lists have changed.
 	 */
-	void			SceneListsChanged(void);
 
 	void			RemoveScheduledScenes(void);
 	void			AddScheduledScenes(void);

Modified: branches/ge_dev/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- branches/ge_dev/source/gameengine/Ketsji/KX_Scene.cpp	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/Ketsji/KX_Scene.cpp	2013-07-09 20:06:36 UTC (rev 58126)
@@ -59,6 +59,7 @@
 #include "SCA_JoystickManager.h"
 #include "KX_PyMath.h"
 #include "RAS_MeshObject.h"
+#include "SCA_IScene.h"
 
 #include "RAS_IRasterizer.h"
 #include "RAS_BucketManager.h"
@@ -73,6 +74,7 @@
 #include "SG_Tree.h"
 #include "DNA_group_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_property_types.h"
 
 #include "KX_SG_NodeRelationships.h"
 
@@ -438,6 +440,21 @@
 	m_isclearingZbuffer = isclearingZbuffer;
 }
 
+void KX_Scene::AddObjectDebugProperties(class KX_GameObject* gameobj)
+{
+	Object* blenderobject = gameobj->GetBlenderObject();
+	bProperty* prop = (bProperty*)blenderobject->prop.first;
+
+	while(prop) {
+		if (prop->flag & PROP_DEBUG)
+			AddDebugProperty(gameobj,STR_String(prop->name));
+		prop = prop->next;
+	}	
+
+	if (blenderobject->scaflag & OB_DEBUGSTATE)
+		AddDebugProperty(gameobj,STR_String("__state__"));
+}
+
 void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gameobj)
 {
 	KX_GameObject* orgobj = (KX_GameObject*)gameobj;
@@ -561,6 +578,8 @@
 // SCA_IObject::ReParentLogic(), make sure it preserves the order of the bricks.
 void KX_Scene::ReplicateLogic(KX_GameObject* newobj)
 {
+	/* add properties to debug list, for added objects and DupliGroups */
+	AddObjectDebugProperties(newobj);
 	// also relink the controller to sensors/actuators
 	SCA_ControllerList& controllers = newobj->GetControllers();
 	//SCA_SensorList&     sensors     = newobj->GetSensors();
@@ -972,6 +991,9 @@
 	int ret;
 	KX_GameObject* newobj = (KX_GameObject*) gameobj;
 
+	/* remove property to debug list */
+	RemoveObjectDebugProperties(newobj);
+
 	/* Invalidate the python reference, since the object may exist in script lists
 	 * its possible that it wont be automatically invalidated, so do it manually here,
 	 * 
@@ -1911,6 +1933,7 @@
 	{
 		KX_GameObject* gameobj = (KX_GameObject*)other->GetObjectList()->GetValue(i);
 		MergeScene_GameObject(gameobj, this, other);
+		AddObjectDebugProperties(gameobj); // add properties to debug list for LibLoad objects
 
 		gameobj->UpdateBuckets(false); /* only for active objects */
 	}

Modified: branches/ge_dev/source/gameengine/Ketsji/KX_Scene.h
===================================================================
--- branches/ge_dev/source/gameengine/Ketsji/KX_Scene.h	2013-07-09 19:22:26 UTC (rev 58125)
+++ branches/ge_dev/source/gameengine/Ketsji/KX_Scene.h	2013-07-09 20:06:36 UTC (rev 58126)
@@ -324,6 +324,7 @@
 		return (m_groupGameObjects.empty() || 
 				m_groupGameObjects.find(gameobj) != m_groupGameObjects.end());
 	}
+	void AddObjectDebugProperties(class KX_GameObject* gameobj);
 	SCA_IObject* AddReplicaObject(CValue* gameobj,
 	                              CValue* locationobj,
 	                              int lifespan=0);




More information about the Bf-blender-cvs mailing list