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.
This commit is contained in:
Mitchell Stokes 2013-07-09 20:06:36 +00:00
parent f6502a67f2
commit 83e9f32382
7 changed files with 65 additions and 36 deletions

@ -131,7 +131,7 @@ void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventMan
if (propval)
{
if (show_debug_info)
if (show_debug_info && isInActiveLayer)
{
scene->AddDebugProperty(gameobj,STR_String(prop->name));
}
@ -159,7 +159,7 @@ void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventMan
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__"));

@ -74,9 +74,28 @@ std::vector<SCA_DebugProp*>& SCA_IScene::GetDebugProperties()
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;
}
}

@ -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 @@ public:
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) {}

@ -129,8 +129,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
m_keyboarddevice(NULL),
m_mousedevice(NULL),
m_propertiesPresent(false),
m_bInitialized(false),
m_activecam(0),
m_bFixedTime(false),
@ -515,7 +513,7 @@ void KX_KetsjiEngine::EndFrame()
// 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 @@ void KX_KetsjiEngine::AddScene(KX_Scene* scene)
{
m_scenes.push_back(scene);
PostProcessScene(scene);
SceneListsChanged();
}
@ -1533,7 +1530,7 @@ void KX_KetsjiEngine::RenderDebugProperties()
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 @@ void KX_KetsjiEngine::RenderDebugProperties()
// 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,24 +1944,6 @@ void KX_KetsjiEngine::ProcessScheduledScenes(void)
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++;
}
}

@ -437,7 +437,6 @@ protected:
/**
* This method is invoked when the scene lists have changed.
*/
void SceneListsChanged(void);
void RemoveScheduledScenes(void);
void AddScheduledScenes(void);

@ -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 @@ void KX_Scene::EnableZBufferClearing(bool isclearingZbuffer)
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 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal
// 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 KX_Scene::NewRemoveObject(class CValue* gameobj)
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 @@ bool KX_Scene::MergeScene(KX_Scene *other)
{
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 */
}

@ -324,6 +324,7 @@ public:
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);