Game Development Community

dev|Pro Game Development Curriculum

SimSet::DumpTree()

by Orion Elenzil · 12/17/2008 (7:03 am) · 2 comments

this is a simple utility to dump the contents of a SimSet (ergo SimGroups, ergo GuiControls).
very, very similar to the stock tree() command, but just dumps the stuff to the console instead of opening an interactive GUI.

this is a TGE 1.3-based codebase, but should work fine for TGE1.x, TGEA, and TGB.

SimBase.h
in the SimSet class, add the following declaration. for example, right above "DECLARE_CONOBJECT(SimSet);"
S32 dumpTree(U32 depth = 0, bool recurse = true);


SimBase.cc
add the following at the bottom, or someplace you see fit:
this is a simpe utility to dump the contents of a SimSet (ergo SimGroups, ergo GuiControls).
very, very similar to the stock tree() command, but just dumps the stuff to the console instead of opening an interactive GUI.

this is a TGE 1.3-based codebase, but should work fine for TGE1.x, TGEA, and TGB.

SimBase.h
in the SimSet class, add the following declaration. for example, right above "DECLARE_CONOBJECT(SimSet);"
S32 dumpTree(U32 depth = 0, bool recurse = true);


SimBase.cc
add the following at the bottom, or someplace you see fit:
//-----------------------------------------------------------------------------

S32 SimSet::dumpTree(U32 depth, bool recurse)
{
   Con::logf(ConsoleLogEntry::Normal, ConsoleLogEntry::General, "%-*s%d %-20s %s", depth + 1, "", getId(), getClassName(), getName());
   S32 count = 1;
   SimSet::iterator itr;
   for(itr = begin(); itr != end(); itr++)
   {
      SimObject* obj      = *itr;
      SimSet*    objAsSet = dynamic_cast<SimSet*>(obj);
      if (recurse && objAsSet != NULL)
      {
         count += objAsSet->dumpTree(depth + 1, recurse);
      }
      else
      {
         Con::logf(ConsoleLogEntry::Normal, ConsoleLogEntry::General, "%-*s%d %-20s %s", depth + 1, "", obj->getId(), obj->getClassName(), obj->getName());
         count += 1;
      }
   }

   return count;
}

ConsoleMethod( SimSet, dumpTree, S32, 2, 3, "bool recurse = true")
{
   bool recurse = true;

   if (argc > 2)
      recurse = dAtob(argv[2]);

   return object->dumpTree(0, recurse);
}


example use/output:
==>logingui.dumpTree();
 8718 GuiBitmapCtrl        LoginGui
  8719 GuiMLTextCtrl        LoginHelpLinks
  8720 GuiControl           LoginAIMBlurb
   8721 GuiBitmapCtrl        (null)
   8722 GuiTextCtrl          (null)
  8723 GuiControl           LoginLoginPanel
   8724 GuiMLTextCtrl        LoginRegistrationLinks
   8725 GuiTextCtrl          (null)
   8726 GuiVariableWidthButtonCtrl (null)
   8727 GuiTextEditCtrl      LoginUserNameField
   8728 GuiTextCtrl          (null)
   8729 GuiVariableWidthButtonCtrl (null)
   8730 GuiTextEditCtrl      LoginPasswordField
   8731 GuiCheckBoxCtrl      LoginRememberMeCheckbox
   8732 GuiControl           LoginStartHereCtrls
    8733 GuiTextCtrl          LoginStartHereLabel
    8734 GuiBitmapCtrl        LoginStartHereSeparator
    8735 GuiPopUp2MenuCtrl    LoginStartHerePopup
   8736 GuiVariableWidthButtonCtrl LoginLoginButton
   8737 GuiVariableWidthButtonCtrl LoginQuitButton
   8738 GuiControl           LoginProgressBarCtrls
    8739 GuiVariableWidthButtonCtrl LoginProgressBrackets
    8740 GuiControl           LoginProgressHolder
     9015 GuiBitmapCtrl        (null)
     9016 GuiBitmapCtrl        (null)
   8741 GuiBitmapCtrl        (null)
   8742 GuiVariableWidthButtonCtrl LoginSystemStatusButton
   8743 GuiWindowCtrl        LoginSystemStatusWindow
    8744 GuiMLTextCtrl        LoginSystemStatusText
  8745 GuiBitmapCtrl        LoginPartnerLogo
  9279 GuiWindowCtrl        loginDebugPanel
   9280 GuiControl           (null)
    9281 GuiControl           (null)
     9282 GuiDragNZoomCtrl     (null)
      9283 GuiBitmapCtrl        (null)
   9284 GuiTextCtrl          (null)
   9285 GuiArray2Ctrl        DragAndDropExampleList

#1
12/17/2008 (7:37 am)
cool, very handy!
thanks!
#2
12/17/2008 (9:08 am)
thanks, bank!
actually, i realized a small problem with the posted code which is now corrected.
i had used "isClassSimSet()", which is not stock torque, but is a resource here.