Example #1
0
void Settings::clearAllFields()
{
    // Fetch Dynamic-Field Dictionary.
    SimFieldDictionary* pFieldDictionary = getFieldDictionary();

    // Any Field Dictionary?
    if ( pFieldDictionary == NULL )
    {
        // No, so we're done.
        return;
    }

    // Iterate fields.
    for ( SimFieldDictionaryIterator itr(pFieldDictionary); *itr; ++itr )
    {
        // Fetch Field Entry.
        SimFieldDictionary::Entry* fieldEntry = *itr;

        // don't remove default field values
        if (dStrEndsWith(fieldEntry->slotName, "_default"))
           continue;

        // remove it.
        pFieldDictionary->setFieldValue( fieldEntry->slotName, "" );
    }
}
Example #2
0
//-----------------------------------------------------------------------------
// Destroy any fields.
//-----------------------------------------------------------------------------
void FieldBrushObject::destroyFields()
{
    // Fetch Dynamic-Field Dictionary.
    SimFieldDictionary* pFieldDictionary = getFieldDictionary();

    // Any Field Dictionary?
    if ( pFieldDictionary == NULL )
    {
        // No, so we're done.
        return;
    }

    // Iterate fields.
    for ( SimFieldDictionaryIterator itr(pFieldDictionary); *itr; ++itr )
    {
        // Fetch Field Entry.
        SimFieldDictionary::Entry* fieldEntry = *itr;

        // Internal Field?
        if ( dStrstr( fieldEntry->slotName, INTERNAL_FIELD_PREFIX ) == fieldEntry->slotName )
        {
            // Yes, so remove it.
            pFieldDictionary->setFieldValue( fieldEntry->slotName, "" );
        }
    }
}
Example #3
0
void Settings::remove(const UTF8 *settingName, bool includeDefaults)
{
    // Fetch Dynamic-Field Dictionary.
    SimFieldDictionary* pFieldDictionary = getFieldDictionary();

    // Any Field Dictionary?
    if ( pFieldDictionary == NULL )
    {
        // No, so we're done.
        return;
    }

	 String name;
    buildGroupString(name, settingName);
    StringTableEntry nameEntry = StringTable->insert(name.c_str());
	 StringTableEntry nameEntryDefault = StringTable->insert( String::ToString("%s%s",name.c_str(), "_default") );

    // Iterate fields.
    for ( SimFieldDictionaryIterator itr(pFieldDictionary); *itr; ++itr )
    {
        // Fetch Field Entry.
        SimFieldDictionary::Entry* fieldEntry = *itr;

        // is this a field of our current group
        if ( (dStrcmp(nameEntry, "") == 0) || 
					dStrcmp( nameEntry, fieldEntry->slotName ) == 0 ||
					(includeDefaults && dStrcmp( nameEntryDefault, fieldEntry->slotName ) == 0) )
        {
            // Yes, so remove it.
            pFieldDictionary->setFieldValue( fieldEntry->slotName, "" );
        }
    }
}
Example #4
0
/*
S32 Settings::buildSearchList( const char* pattern, bool deepSearch, bool includeDefaults )
{
	mSearchResults.clear();

	SimFieldDictionary* fieldDictionary = getFieldDictionary();
	// Get the dynamic field count
	if ( !fieldDictionary )
		return -1;

   for (SimFieldDictionaryIterator itr(fieldDictionary); *itr; ++itr)
	{
		// Fetch Field Entry.
      SimFieldDictionary::Entry* fieldEntry = *itr;
		
		// Compare strings, store proper results in vector
		String extendedPath = String::ToString(fieldEntry->slotName);
		String::SizeType start(0);
		String::SizeType slashPos = extendedPath.find('/', 0, String::Right);
		String shortPath = extendedPath.substr( start, slashPos );

		if( deepSearch )
		{
			if( shortPath.find( pattern ) != -1 )
			{
				if( !includeDefaults && extendedPath.find("_default") != -1 )
					continue;

				String listMember = String::ToString(fieldEntry->value);
				listMember.insert(start, " " );
				listMember.insert(start, String::ToString(fieldEntry->slotName) );

				mSearchResults.push_back( listMember );
			}
		}
		else
		{
			if( shortPath.compare( pattern ) == 0 )
			{
				if( !includeDefaults && extendedPath.find("_default") != -1 )
					continue;

				String listMember = String::ToString(fieldEntry->value);
				listMember.insert(start, " " );
				listMember.insert(start, String::ToString(fieldEntry->slotName) );

				mSearchResults.push_back( listMember );
			}
		}
	}

	return mSearchResults.size();
}
*/
const char* Settings::findFirstValue( const char* pattern, bool deepSearch, bool includeDefaults )
{
	mSearchResults.clear();

	SimFieldDictionary* fieldDictionary = getFieldDictionary();
	// Get the dynamic field count
	if ( !fieldDictionary )
		return "";

   for (SimFieldDictionaryIterator itr(fieldDictionary); *itr; ++itr)
	{
		// Fetch Field Entry.
      SimFieldDictionary::Entry* fieldEntry = *itr;
		
		// Compare strings, store proper results in vector
		String extendedPath = String::ToString(fieldEntry->slotName);
		String::SizeType start(0);
		String::SizeType slashPos = extendedPath.find('/', 0, String::Right);
		String shortPath = extendedPath.substr( start, slashPos );

		if( deepSearch )
		{
			if( shortPath.find( pattern ) != -1 )
			{
				if( !includeDefaults && extendedPath.find("_default") != -1 )
					continue;

				String listMember = String::ToString(fieldEntry->slotName);
				//listMember.insert(start, " " );
				//listMember.insert(start, String::ToString(fieldEntry->slotName) );

				mSearchResults.push_back( listMember );
			}
		}
		else
		{
			if( shortPath.compare( pattern ) == 0 )
			{
				if( !includeDefaults && extendedPath.find("_default") != -1 )
					continue;

				String listMember = String::ToString(fieldEntry->slotName);
				//listMember.insert(start, " " );
				//listMember.insert(start, String::ToString(fieldEntry->slotName) );

				mSearchResults.push_back( listMember );
			}
		}
	}
	
	if( mSearchResults.size() < 1 )
   {
		Con::errorf("findFirstValue() : Pattern not found");
      return "";
   }

	mSearchPos = 0;
	return mSearchResults[mSearchPos];
}
//--------------------------------------------------------------------------
// On add - verify data settings
//--------------------------------------------------------------------------
bool CustomMaterial::onAdd()
{
   if (Parent::onAdd() == false)
      return false;

   mShaderData = dynamic_cast<ShaderData*>(Sim::findObject( mShaderDataName ) );
   if(mShaderDataName.isNotEmpty() && mShaderData == NULL)
   {
      logError("Failed to find ShaderData %s", mShaderDataName.c_str());
      return false;
   }
   
   const char* samplerDecl = "sampler";
   S32 i = 0;
   for (SimFieldDictionaryIterator itr(getFieldDictionary()); *itr; ++itr)
   {
   	SimFieldDictionary::Entry* entry = *itr;
      if (dStrStartsWith(entry->slotName, samplerDecl))
      {
      	if (i >= MAX_TEX_PER_PASS)
         {
            logError("Too many sampler declarations, you may only have %i", MAX_TEX_PER_PASS);
            return false;
         }
         
         if (dStrlen(entry->slotName) == dStrlen(samplerDecl))
         {
         	logError("sampler declarations must have a sampler name, e.g. sampler[\"diffuseMap\"]");
            return false;
         }
         
         // Assert sampler names are defined on ShaderData
         S32 pos = -1;
         String samplerName = entry->slotName + dStrlen(samplerDecl);
         samplerName.insert(0, '$');
         mShaderData->hasSamplerDef(samplerName, pos);
         
         if(pos == -1)
         {
            const char *error = (avar("CustomMaterial(%s) bind sampler[%s] and is not present on ShaderData(%s)", 
               getName(), samplerName.c_str(), mShaderDataName.c_str() ));
            Con::errorf(error);
            GFXAssertFatal(0, error);
            continue;
         }
         mSamplerNames[pos] = samplerName;
         mTexFilename[pos] = entry->value;
         ++i;
      }
   }

   return true;
}
Example #6
0
bool TSStatic::onAdd()
{
   PROFILE_SCOPE(TSStatic_onAdd);

   if ( isServerObject() )
   {
      // Handle the old "usePolysoup" field
      SimFieldDictionary* fieldDict = getFieldDictionary();

      if ( fieldDict )
      {
         StringTableEntry slotName = StringTable->insert( "usePolysoup" );

         SimFieldDictionary::Entry * entry = fieldDict->findDynamicField( slotName );

         if ( entry )
         {
            // Was "usePolysoup" set?
            bool usePolysoup = dAtob( entry->value );

            // "usePolysoup" maps to the new VisibleMesh type
            if ( usePolysoup )
               mCollisionType = VisibleMesh;

            // Remove the field in favor on the new "collisionType" field
            fieldDict->setFieldValue( slotName, "" );
         }
      }
   }

   if ( !Parent::onAdd() )
      return false;

   // Setup the shape.
   if ( !_createShape() )
   {
      Con::errorf( "TSStatic::onAdd() - Shape creation failed!" );
      return false;
   }

   setRenderTransform(mObjToWorld);

   // Register for the resource change signal.
   ResourceManager::get().getChangedSignal().notify( this, &TSStatic::_onResourceChanged );

   addToScene();

   _updateShouldTick();

   return true;
}
bool SimObject::writeObject(Stream *stream)
{
   stream->writeString(getName() ? getName() : "");

   // Static fields
   AbstractClassRep *rep = getClassRep();
   AbstractClassRep::FieldList &fieldList = rep->mFieldList;
   AbstractClassRep::FieldList::iterator itr;
   
   U32 savePos = stream->getPosition();
   U32 numFields = fieldList.size();
   stream->write(numFields);

   for(itr = fieldList.begin();itr != fieldList.end();itr++)
   {
      if( itr->type >= AbstractClassRep::ARCFirstCustomField )
      {
         numFields--;
         continue;
      }

      const char *field = getDataField(itr->pFieldname, NULL);
      if(field == NULL)
         field = "";

      stream->writeString(itr->pFieldname);
      stream->writeString(field);
   }

   // Dynamic Fields
   if(mCanSaveFieldDictionary)
   {
      SimFieldDictionary * fieldDictionary = getFieldDictionary();
      for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
      {
         SimFieldDictionary::Entry * entry = (*ditr);

         stream->writeString(entry->slotName);
         stream->writeString(entry->value);
         numFields++;
      }
   }

   // Overwrite the number of fields with the correct value
   U32 savePos2 = stream->getPosition();
   stream->setPosition(savePos);
   stream->write(numFields);
   stream->setPosition(savePos2);

   return true;
}
//--------------------------------------------------------------------------
// On add - verify data settings
//--------------------------------------------------------------------------
bool CustomMaterial::onAdd()
{
   if (Parent::onAdd() == false)
      return false;

   mShaderData = dynamic_cast<ShaderData*>(Sim::findObject( mShaderDataName ) );
   if(mShaderDataName.isNotEmpty() && mShaderData == NULL)
   {
      logError("Failed to find ShaderData %s", mShaderDataName.c_str());
      return false;
   }
   
   const char* samplerDecl = "sampler";
   S32 i = 0;
   for (SimFieldDictionaryIterator itr(getFieldDictionary()); *itr; ++itr)
   {
   	SimFieldDictionary::Entry* entry = *itr;
      if (dStrStartsWith(entry->slotName, samplerDecl))
      {
      	if (i >= MAX_TEX_PER_PASS)
         {
            logError("Too many sampler declarations, you may only have %i", MAX_TEX_PER_PASS);
            return false;
         }
         
         if (dStrlen(entry->slotName) == dStrlen(samplerDecl))
         {
         	logError("sampler declarations must have a sampler name, e.g. sampler[\"diffuseMap\"]");
            return false;
         }
         
      	mSamplerNames[i] = entry->slotName + dStrlen(samplerDecl);
         mSamplerNames[i].insert(0, '$');
         mTexFilename[i] = entry->value;
         ++i;
      }
   }

   return true;
}
Example #9
0
bool Settings::write()
{
   // Fetch Dynamic-Field Dictionary.
   SimFieldDictionary* pFieldDictionary = getFieldDictionary();

   // Any Field Dictionary?
   if ( pFieldDictionary == NULL )
   {
      // No, so we're done.
      return false;
   }

/*
   // Iterate fields.
   for ( SimFieldDictionaryIterator itr(pFieldDictionary); *itr; ++itr )
   {
      // Fetch Field Entry.
      SimFieldDictionary::Entry* fieldEntry = *itr;

	  String check(fieldEntry->slotName);
	  String::SizeType pos = check.find("_default");
	  if(pos != String::NPos)
		 continue;

      // let's build our XML doc
      document->pushNewElement("dynamicField");
	  document->setAttribute("name", fieldEntry->slotName);
	  document->addText(fieldEntry->value);
      document->popElement();
   }
*/
   SimXMLDocument *document = new SimXMLDocument();
   document->registerObject();
   document->addHeader();

   document->pushNewElement(getName());

   SettingSaveNode *node = new SettingSaveNode();
   // Iterate fields.
   for ( SimFieldDictionaryIterator itr(pFieldDictionary); *itr; ++itr )
   {
      // Fetch Field Entry.
      SimFieldDictionary::Entry* fieldEntry = *itr;

      String check(fieldEntry->slotName);
	  if(check.find("_default") != String::NPos || check.find("_type") != String::NPos)
		 continue;

	  node->addValue(fieldEntry->slotName, fieldEntry->value);
   }

   node->buildDocument(document, true);
   node->clear();
   delete node;

   bool saved = document->saveFile(mFile.c_str());
   document->deleteObject();

   if(saved)
      return true;
   else
	   return false;   
}