BGE patch: add Debug button next to object state. The object state mask will be printed at runtime with the debug info as a comma separated list of state numbers (1..30) for each active state bit. The reserved property name __state__ is used for that purpose (users should not create a property with that name).

This commit is contained in:
2008-09-25 16:19:07 +00:00
parent 04fa0fd869
commit c9c9b2e833
4 changed files with 52 additions and 16 deletions

View File

@@ -469,6 +469,7 @@ extern Object workob;
#define OB_SHOWCONT 2048
#define OB_SETSTBIT 4096
#define OB_INITSTBIT 8192
#define OB_DEBUGSTATE 16384
/* ob->restrictflag */
#define OB_RESTRICT_VIEW 1

View File

@@ -3366,24 +3366,25 @@ void logic_buts(void)
/* first show the state */
uiBlockSetEmboss(block, UI_EMBOSSP);
uiDefBlockBut(block, object_state_mask_menu, ob, "State", (short)(xco-10), (short)(yco-10), 40, 19, "Object state menu: store and retrieve initial state");
uiDefBlockBut(block, object_state_mask_menu, ob, "State", (short)(xco-10), (short)(yco-10), 36, 19, "Object state menu: store and retrieve initial state");
uiBlockSetEmboss(block, UI_EMBOSS);
if (!ob->state)
ob->state = 1;
for (offset=0; offset<15; offset+=5) {
uiBlockBeginAlign(block);
for (stbit=0; stbit<5; stbit++) {
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset), stbit+offset, "", (short)(xco+35+12*stbit+13*offset), yco, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset)));
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset), stbit+offset, "", (short)(xco+31+12*stbit+13*offset), yco, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset)));
uiButSetFunc(but, check_state_mask, but, &(ob->state));
}
for (stbit=0; stbit<5; stbit++) {
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset+15)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset+15), stbit+offset+15, "", (short)(xco+35+12*stbit+13*offset), yco-12, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset+15)));
but = uiDefButBitI(block, controller_state_mask&(1<<(stbit+offset+15)) ? BUT_TOGDUAL:TOG, 1<<(stbit+offset+15), stbit+offset+15, "", (short)(xco+31+12*stbit+13*offset), yco-12, 12, 12, (int *)&(ob->state), 0, 0, 0, 0, get_state_name(ob, (short)(stbit+offset+15)));
uiButSetFunc(but, check_state_mask, but, &(ob->state));
}
}
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, OB_SETSTBIT, B_SET_STATE_BIT, "All",(short)(xco+235), yco-10, 25, 19, &ob->scaflag, 0, 0, 0, 0, "Set all state bits");
uiDefButBitS(block, TOG, OB_INITSTBIT, B_INIT_STATE_BIT, "Ini",(short)(xco+260), yco-10, 25, 19, &ob->scaflag, 0, 0, 0, 0, "Set the initial state");
uiDefButBitS(block, TOG, OB_SETSTBIT, B_SET_STATE_BIT, "All",(short)(xco+226), yco-10, 22, 19, &ob->scaflag, 0, 0, 0, 0, "Set all state bits");
uiDefButBitS(block, TOG, OB_INITSTBIT, B_INIT_STATE_BIT, "Ini",(short)(xco+248), yco-10, 22, 19, &ob->scaflag, 0, 0, 0, 0, "Set the initial state");
uiDefButBitS(block, TOG, OB_DEBUGSTATE, 0, "D",(short)(xco+270), yco-10, 15, 19, &ob->scaflag, 0, 0, 0, 0, "Print state debug info");
uiBlockEndAlign(block);
yco-=35;

View File

@@ -132,6 +132,10 @@ 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)
{
// reserve name for object state
scene->AddDebugProperty(gameobj,STR_String("__state__"));
}
}

View File

@@ -1243,19 +1243,49 @@ void KX_KetsjiEngine::RenderDebugProperties()
CValue* propobj = (*it)->m_obj;
STR_String objname = propobj->GetName();
STR_String propname = (*it)->m_name;
CValue* propval = propobj->GetProperty(propname);
if (propval)
if (propname == "__state__")
{
STR_String text = propval->GetText();
debugtxt = objname + "." + propname + " = " + text;
// reserve name for object state
KX_GameObject* gameobj = static_cast<KX_GameObject*>(propobj);
unsigned int state = gameobj->GetState();
debugtxt = objname + "." + propname + " = ";
bool first = true;
for (int statenum=1;state;state >>= 1, statenum++)
{
if (state & 1)
{
if (!first)
{
debugtxt += ",";
}
debugtxt += STR_String(statenum);
first = false;
}
}
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
debugtxt.Ptr(),
xcoord,
ycoord,
m_canvas->GetWidth(),
m_canvas->GetHeight());
debugtxt.Ptr(),
xcoord,
ycoord,
m_canvas->GetWidth(),
m_canvas->GetHeight());
ycoord += 14;
}
else
{
CValue* propval = propobj->GetProperty(propname);
if (propval)
{
STR_String text = propval->GetText();
debugtxt = objname + "." + propname + " = " + text;
m_rendertools->RenderText2D(RAS_IRenderTools::RAS_TEXT_PADDED,
debugtxt.Ptr(),
xcoord,
ycoord,
m_canvas->GetWidth(),
m_canvas->GetHeight());
ycoord += 14;
}
}
}
}
}