BGE patch: add Debug button next to object state. The object state mask will be print...
authorBenoit Bolsee <benoit.bolsee@online.be>
Thu, 25 Sep 2008 16:19:07 +0000 (16:19 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Thu, 25 Sep 2008 16:19:07 +0000 (16:19 +0000)
source/blender/makesdna/DNA_object_types.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/KX_ConvertProperties.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.cpp

index 041e0eaebde44e25299f413077c54649291ccfb6..2fed5e6170be1caba577ad3d398fbf4df722c986 100644 (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
index 667f822bed56294ff6e752f835535edfd81af554..dd374af8675aaf72a24a81739e09419c3b7051e0 100644 (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;
index aae8752671f05a3e4934bdeea59c994fcf571f4f..dfbc6f0c48d1d14a014116dc284574380f482422 100644 (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__"));
+       }
 }
index c7b0d7b3ea34c7177c56493d8391076a6bf23450..b1ab8e3e7def86b45319bf697404dc7394b2ba5e 100644 (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;
+                                       }
+                               }
                        }
                }
        }