S32 script_simobject_find(const char* classname, const char* name)
   {
      SimObject *object;
      if( Sim::findObject( name, object ) )
      {
         // if we specified a classname do type checking
         if (classname && dStrlen(classname))
         {
            AbstractClassRep* ocr = object->getClassRep();
            while (ocr)
            {
               if (!dStricmp(ocr->getClassName(), classname))
                  return object->getId();
               ocr = ocr->getParentClass();
            }

         }

         // invalid type
         return 0;
      }

      // didn't find object
      return 0;
   }
Example #2
0
AbstractClassRep *AbstractClassRep::getCommonParent( const AbstractClassRep *otherClass ) const
{
   // CodeReview: This may be a noob way of doing it. There may be some kind of
   // super-spiffy algorithm to do what the code below does, but this appeared
   // to make sense to me, and it is pretty easy to see what it is doing [6/23/2007 Pat]

   static VectorPtr<AbstractClassRep *> thisClassHeirarchy;
   thisClassHeirarchy.clear();

   AbstractClassRep *walk = const_cast<AbstractClassRep *>( this );

   while( walk != NULL )
   {
      thisClassHeirarchy.push_front( walk );
      walk = walk->getParentClass();
   }

   static VectorPtr<AbstractClassRep *> compClassHeirarchy;
   compClassHeirarchy.clear();
   walk = const_cast<AbstractClassRep *>( otherClass );
   while( walk != NULL )
   {
      compClassHeirarchy.push_front( walk );
      walk = walk->getParentClass();
   }

   // Make sure we only iterate over the list the number of times we can
   S32 maxIterations = getMin( compClassHeirarchy.size(), thisClassHeirarchy.size() );

   U32 i = 0;
   for( ; i < maxIterations; i++ )
   {
      if( compClassHeirarchy[i] != thisClassHeirarchy[i] )
         break;
   }

   return compClassHeirarchy[i];
}
Example #3
0
AbstractClassRep* GuiInspectorGroup::findCommonAncestorClass()
{
   AbstractClassRep* classRep = getInspector()->getInspectObject( 0 )->getClassRep();
   const U32 numInspectObjects = getInspector()->getNumInspectObjects();
   
   for( U32 i = 1; i < numInspectObjects; ++ i )
   {
      SimObject* object = getInspector()->getInspectObject( i );
      while( !object->getClassRep()->isClass( classRep ) )
      {
         classRep = classRep->getParentClass();
         AssertFatal( classRep, "GuiInspectorGroup::findcommonAncestorClass - Walked above ConsoleObject!" );
      }
   }
      
   return classRep;
}
   void XMLExport::exportNamespaces()
   {

      // keep track of which enumTables are in use
      Vector < const EnumTable*> enumTables;

      mXML->pushNewElement("Namespaces");

      for (Namespace *walk = Namespace::mNamespaceList; walk; walk = walk->mNext)
      {

         if ( walk->mName && !walk->isClass() )
            continue;

         const char *name = walk->mName ? walk->mName : "";

         mXML->pushNewElement("Namespace");
         mXML->setAttribute("name", name);

         Namespace *p = walk->mParent;

         mXML->pushNewElement("Parents");

         while (p)
         {
            if (p->mName == walk->mName)
            {
               p = p->mParent;
               continue;
            }

            const char* pname = p->mName ? p->mName : "";

            mXML->pushNewElement("Parent");
            mXML->setAttribute("name", pname);
            mXML->popElement(); // Parent

            p = p->mParent;
         }

         mXML->popElement(); // Parents

         // Entries (Engine/Script Methods/Functions)

         mXML->pushNewElement("Entries");

         Namespace::Entry *entry;
         VectorPtr<Namespace::Entry *> vec;

         walk->getEntryList(&vec);

         for( NamespaceEntryListIterator compItr = vec.begin(); compItr != vec.end(); compItr++ )
         {

            entry = *compItr;

            if (entry->mNamespace != walk)
               continue;

            if (entry->mNamespace->mName != walk->mName)
               continue;

            mXML->pushNewElement("Entry");

            //consistently name functions
            char functionName[512];
            dSprintf(functionName, 512, entry->mFunctionName);
            functionName[0] = dTolower(functionName[0]);

            S32 minArgs = entry->mMinArgs;
            S32 maxArgs = entry->mMaxArgs;

            if (maxArgs < minArgs)
               maxArgs = minArgs;

            mXML->setAttribute("name", functionName);
            mXML->setAttribute("minArgs", avar("%i", minArgs));
            mXML->setAttribute("maxArgs", avar("%i", maxArgs));

            const char* usage = "";
            if (entry->mUsage && entry->mUsage[0])
               usage = entry->mUsage;
            mXML->setAttribute("usage", usage);
            mXML->setAttribute("package", entry->mPackage ? entry->mPackage : "");
            mXML->setAttribute("entryType", avar("%i", entry->mType));

            mXML->popElement(); // Entry

         }

         mXML->popElement(); // Entries

         // Fields

         mXML->pushNewElement("Fields");

         AbstractClassRep *rep = walk->mClassRep;
         Vector<U32> classFields;

         if (rep)
         {
            AbstractClassRep *parentRep = rep->getParentClass();

            const AbstractClassRep::FieldList& flist = rep->mFieldList;

            for(U32 i = 0; i < flist.size(); i++)
            {
               if (parentRep)
               {
                  if (parentRep->findField(flist[i].pFieldname))
                     continue;

               }
               classFields.push_back(i);
            }

            for(U32 i = 0; i < classFields.size(); i++)
            {
               U32 index = classFields[i];

               char fieldName[256];

               dSprintf(fieldName, 256, flist[index].pFieldname);

               //consistently name fields
               fieldName[0] = dToupper(fieldName[0]);

               mXML->pushNewElement("Field");

               mXML->setAttribute("name", fieldName);
               mXML->setAttribute("type", avar("%i", flist[index].type));

// RD: temporarily deactivated; TypeEnum is no more; need to sync this up
//               if (flist[index].type == TypeEnum  && flist[index].table && dStrlen(flist[index].table->name))
//               {
//                  if (!enumTables.contains(flist[index].table))
//                     enumTables.push_back(flist[index].table);
//
//                  mXML->setAttribute("enumTable", flist[index].table->name);
//
//               }

               const char* pFieldDocs = "";
               if (flist[index].pFieldDocs && flist[index].pFieldDocs[0])
                  pFieldDocs = flist[index].pFieldDocs;

               mXML->setAttribute("docs", pFieldDocs);
               mXML->setAttribute("elementCount", avar("%i", flist[index].elementCount));

               mXML->popElement(); // Field
            }
         }

         mXML->popElement(); // Fields
         mXML->popElement(); // Namespace
      }

      mXML->popElement(); // Namespaces

      mXML->pushNewElement("EnumTables");

      // write out the used EnumTables
      for (S32 i = 0; i < enumTables.size(); i++)
      {
         mXML->pushNewElement("EnumTable");

         const EnumTable* table = enumTables[i];

         mXML->setAttribute("name", table->name);
         mXML->setAttribute("firstFlag", avar("%i", table->firstFlag));
         mXML->setAttribute("mask", avar("%i", table->mask));

         mXML->pushNewElement("Enums");

         for (S32 j = 0; j < table->size; j++)
         {
            mXML->pushNewElement("Enum");

            mXML->setAttribute("name", table->table[j].label);
            mXML->setAttribute("index", avar("%i", table->table[j].index));

            mXML->popElement(); // Enum

         }

         mXML->popElement(); //Enums

         mXML->popElement(); // EnumTable
      }

      mXML->popElement(); // EnumTables
      
   }