Index: Converter/KX_ConvertProperties.cpp =================================================================== --- Converter/KX_ConvertProperties.cpp (revision 50280) +++ Converter/KX_ConvertProperties.cpp (working copy) @@ -65,7 +65,6 @@ void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer) { - bProperty* prop = (bProperty*)object->prop.first; CValue* propval; bool show_debug_info; @@ -132,7 +131,7 @@ if (propval) { - if (show_debug_info) + if (show_debug_info && isInActiveLayer) { scene->AddDebugProperty(gameobj,STR_String(prop->name)); } @@ -160,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__")); @@ -237,7 +236,7 @@ } } - if (propval) { + if (propval){ propval->Release(); } } Index: GameLogic/CMakeLists.txt =================================================================== --- GameLogic/CMakeLists.txt (revision 50280) +++ GameLogic/CMakeLists.txt (working copy) @@ -28,7 +28,9 @@ ../Expressions ../Rasterizer ../SceneGraph + ../Ketsji ../../blender/blenlib + ../../blender/makesdna ../../../intern/container ../../../intern/moto/include ../../../intern/string Index: GameLogic/SCA_IScene.cpp =================================================================== --- GameLogic/SCA_IScene.cpp (revision 50280) +++ GameLogic/SCA_IScene.cpp (working copy) @@ -29,9 +29,13 @@ * \ingroup gamelogic */ +#include "DNA_property_types.h" +/* end of blender include block */ #include "SCA_IScene.h" #include "Value.h" +//#include +#include "KX_GameObject.h" SCA_DebugProp::SCA_DebugProp(): m_obj(NULL) { @@ -45,6 +49,7 @@ SCA_IScene::SCA_IScene() { + m_ListLenghtMax = 100; } void SCA_IScene::RemoveAllDebugProperties() @@ -70,13 +75,108 @@ } +bool SCA_IScene::PropertyInList(class CValue* gameobj, + const STR_String &name) +{ + for (std::vector::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::ObjectInList(class CValue* gameobj) +{ + for (std::vector::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) { - SCA_DebugProp* dprop = new SCA_DebugProp(); - dprop->m_obj = debugprop; - debugprop->AddRef(); - dprop->m_name = name; - m_debugList.push_back(dprop); + if (m_debugList.capacity() < m_ListLenghtMax) + { + SCA_DebugProp* dprop = new SCA_DebugProp(); + dprop->m_obj = debugprop; + debugprop->AddRef(); + dprop->m_name = name; + m_debugList.push_back(dprop); + } } + + +void SCA_IScene::AddObjectDebugProperties(class KX_GameObject* gameobj) +{ + Object* blenderobject = gameobj->GetBlenderObject(); + bProperty* prop = (bProperty*)blenderobject->prop.first; + + while(prop) + { + if (bool (prop->flag & PROP_DEBUG)) + { + AddDebugProperty(gameobj,STR_String(prop->name)); + } + prop = prop->next; + } + + if (blenderobject->scaflag & OB_DEBUGSTATE) + { + AddDebugProperty(gameobj,STR_String("__state__")); + } +} + + +void SCA_IScene::RemoveDebugProperty(class CValue* gameobj, + const STR_String &name) +{ + vector::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::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; + } +} Index: GameLogic/SCA_IScene.h =================================================================== --- GameLogic/SCA_IScene.h (revision 50280) +++ GameLogic/SCA_IScene.h (working copy) @@ -52,6 +52,7 @@ class SCA_IScene { std::vector m_debugList; + int m_ListLenghtMax; public: SCA_IScene(); virtual ~SCA_IScene(); @@ -65,9 +66,17 @@ virtual void ReplaceMesh(class CValue* gameobj, void* meshobj, bool use_gfx, bool use_phys)=0; std::vector& GetDebugProperties(); + void RemoveAllDebugProperties(); + bool PropertyInList(class CValue* gameobj, + const STR_String &name); + bool ObjectInList(class CValue* gameobj); void AddDebugProperty(class CValue* debugprop, const STR_String &name); - void RemoveAllDebugProperties(); + void AddObjectDebugProperties(class KX_GameObject* gameobj); + void RemoveDebugProperty(class CValue* gameobj, + const STR_String &name); + void RemoveObjectDebugProperties(class CValue* gameobj); + virtual void Update2DFilter(std::vector& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text) {} Index: GameLogic/SConscript =================================================================== --- GameLogic/SConscript (revision 50280) +++ GameLogic/SConscript (working copy) @@ -7,6 +7,8 @@ incs += ' #/source/gameengine/Expressions #/intern/moto/include' incs += ' #/source/gameengine/Rasterizer #/source/gameengine/SceneGraph' incs += ' #/source/blender/blenlib' +incs += ' #/source/gameengine/Ketsji' +incs += ' #/source/blender/makesdna' defs = [] Index: Ketsji/KX_KetsjiEngine.cpp =================================================================== --- Ketsji/KX_KetsjiEngine.cpp (revision 50280) +++ Ketsji/KX_KetsjiEngine.cpp (working copy) @@ -132,8 +132,6 @@ m_keyboarddevice(NULL), m_mousedevice(NULL), - m_propertiesPresent(false), - m_bInitialized(false), m_activecam(0), m_bFixedTime(false), @@ -507,7 +505,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(); } @@ -1382,7 +1380,6 @@ { m_scenes.push_back(scene); PostProcessScene(scene); - SceneListsChanged(); } @@ -1490,7 +1487,7 @@ } /* Property display*/ - if (m_show_debug_properties && m_propertiesPresent) + if (m_show_debug_properties) { KX_SceneList::iterator sceneit; for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++) @@ -1498,7 +1495,7 @@ KX_Scene* scene = *sceneit; /* the 'normal' debug props */ vector& debugproplist = scene->GetDebugProperties(); - + for (vector::iterator it = debugproplist.begin(); !(it==debugproplist.end());it++) { @@ -1895,28 +1892,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& debugproplist = scene->GetDebugProperties(); - m_propertiesPresent = !debugproplist.empty(); - sceneit++; - } -} - - void KX_KetsjiEngine::SetHideCursor(bool hideCursor) { m_hideCursor = hideCursor; Index: Ketsji/KX_KetsjiEngine.h =================================================================== --- Ketsji/KX_KetsjiEngine.h (revision 50280) +++ Ketsji/KX_KetsjiEngine.h (working copy) @@ -430,7 +430,6 @@ /** * This method is invoked when the scene lists have changed. */ - void SceneListsChanged(void); void RemoveScheduledScenes(void); void AddScheduledScenes(void); Index: Ketsji/KX_Scene.cpp =================================================================== --- Ketsji/KX_Scene.cpp (revision 50280) +++ Ketsji/KX_Scene.cpp (working copy) @@ -97,7 +97,9 @@ #include "KX_Light.h" #include +#include "SCA_IScene.h" + void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene) { KX_GameObject* replica = ((KX_Scene*)scene)->AddNodeReplicaObject(node,(KX_GameObject*)gameobj); @@ -926,6 +928,13 @@ { DupliGroupRecurse(*git, 0); } + + // add property to debug list + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + AddObjectDebugProperties(*git); + } + // don't release replica here because we are returning it, not done with it... return replica; } @@ -966,6 +975,9 @@ int ret; KX_GameObject* newobj = (KX_GameObject*) gameobj; + // remove property to debug list + RemoveObjectDebugProperties(gameobj); + /* 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, * @@ -1017,7 +1029,7 @@ m_timemgr->RemoveTimeProperty(propval); } } - + newobj->RemoveMeshes(); ret = 1; if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT && m_lightlist->RemoveValue(newobj)) @@ -1053,9 +1065,8 @@ if (m_sceneConverter) m_sceneConverter->UnregisterGameObject(newobj); #endif - + // return value will be 0 if the object is actually deleted (all reference gone) - return ret; } @@ -1866,6 +1877,7 @@ { KX_GameObject* gameobj = (KX_GameObject*)other->GetObjectList()->GetValue(i); MergeScene_GameObject(gameobj, this, other); + AddObjectDebugProperties(gameobj); gameobj->UpdateBuckets(false); /* only for active objects */ } @@ -2005,6 +2017,8 @@ KX_PYMETHODTABLE(KX_Scene, suspend), KX_PYMETHODTABLE(KX_Scene, resume), KX_PYMETHODTABLE(KX_Scene, drawObstacleSimulation), + KX_PYMETHODTABLE(KX_Scene, debugObject), + KX_PYMETHODTABLE(KX_Scene, debugProperty), /* dict style access */ @@ -2289,10 +2303,9 @@ KX_PYMETHODDEF_DOC(KX_Scene, end, "end()\n" "Removes this scene from the game.\n") -{ - +{ KX_GetActiveEngine()->RemoveScene(m_sceneName); - + Py_RETURN_NONE; } @@ -2366,4 +2379,74 @@ return def; } +KX_PYMETHODDEF_DOC(KX_Scene, debugObject, +"debugObject(object, visible=1, recursive=1)\n" +"Added or remove the enabled debug properties from the given object to the debug list.\n") +{ + PyObject *pyob; + KX_GameObject *ob; + int visible = 1; + int recursive = 1; + + if (!PyArg_ParseTuple(args,"O|ii:debugObject", &pyob, &visible, &recursive)) + return NULL; + + if (!ConvertPythonToGameObject(pyob, &ob, false, "scene.debugObject(object): KX_Scene (first argument)")) + return NULL; + + if (visible) + { + if (!ObjectInList(ob)) + AddObjectDebugProperties(ob); + } + else + RemoveObjectDebugProperties(ob); + + if (recursive) + { + CListValue* childs = ob->GetChildrenRecursive(); + + for (int i=0; iGetCount(); i++) + { + KX_GameObject* obj = (KX_GameObject*)childs->GetValue(i); + + if (visible) + { + if (!ObjectInList(obj)) + AddObjectDebugProperties(obj); + } + else + RemoveObjectDebugProperties(obj); + } + childs->Release(); + } + Py_RETURN_NONE; +} + +KX_PYMETHODDEF_DOC(KX_Scene, debugProperty, +"debugProperty(object, name, visible=1)\n" +"Added or remove a debug property to the debug list.\n") +{ + PyObject *pyob; + KX_GameObject *ob; + char* name; + int visible = 1; + + if (!PyArg_ParseTuple(args,"Os|i:debugProperty", &pyob, &name , &visible)) + return NULL; + + if (!ConvertPythonToGameObject(pyob, &ob, false, "scene.debugProperty(object): KX_Scene (first argument)")) + return NULL; + + if (visible) + { + if (!PropertyInList(ob, name)) + AddDebugProperty(ob, name); + } + else + RemoveDebugProperty(ob, name); + + Py_RETURN_NONE; +} + #endif // WITH_PYTHON Index: Ketsji/KX_Scene.h =================================================================== --- Ketsji/KX_Scene.h (revision 50280) +++ Ketsji/KX_Scene.h (working copy) @@ -602,6 +602,8 @@ KX_PYMETHOD_DOC(KX_Scene, resume); KX_PYMETHOD_DOC(KX_Scene, get); KX_PYMETHOD_DOC(KX_Scene, drawObstacleSimulation); + KX_PYMETHOD_DOC(KX_Scene, debugObject); + KX_PYMETHOD_DOC(KX_Scene, debugProperty); /* attributes */