예제 #1
0
/**
 * Write the current object 
 */
void FrequencyTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Frequency* pfreq = dynamic_cast< const Frequency*>(pObject);
	if( pfreq == NULL) 
		throw TranslationException("FrequencyTranslator cannot cast frequency object");

	XMLElement* pelemf = elem.GetDocument()->NewElement( pszName);
	pelemf->SetAttribute("format", _szfmts[ pfreq->Format()]);
	char buff[64];
	const Frequency::ValueType& val = pfreq->Value();
	
	switch( pfreq->Format() )
	{
	case Frequency::Ratio:
		{
			sprintf(buff, "%ld,%ld", val.ratioVal.numerator,
				val.ratioVal.denominator);
		}
		break;
	default:
		{
			sprintf(buff, "%0.16le", val.doubleVal);
		}
		break;
	}
	pelemf->SetText( buff);
	elem.InsertEndChild( pelemf);

}
예제 #2
0
/**
 * Write the current object 
 */
void SystemTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const System* psystem = dynamic_cast< const System*>(pObject);
	if( psystem == NULL) 
		throw TranslationException("SystemTranslator cannot cast System object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *psystem, ctxt, *pelemc);

	if( !psystem->IsReference())
	{
		//Write Frequency Base.
		WriteElement( &psystem->BaseFrequency(), "freqbase", ctxt, *pelemc);
	
		//Write Equipment [0..1]
		WriteElement("equipment", psystem->Equipment().c_str(),  pelemc, false, "");

		//Write Type Attribute [0..1]
		WriteElement( "types", _szTypes[psystem->Type()], pelemc, false, "");

		//Write source elements [1..*]
		WriteList<Source>( psystem->Sources(), "source", ctxt,*pelemc);

		//Write cluster elements [0..*]
		WriteList<Cluster>( psystem->Clusters(), "cluster", ctxt,*pelemc);
	}
	
	elem.InsertEndChild( pelemc);
}
예제 #3
0
/**
 * Write the current object 
 */
void ChannelTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Channel* pchannel = dynamic_cast< const Channel*>(pObject);
	if( pchannel == NULL) 
		throw TranslationException("ChannelTranslator cannot cast Channel object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	if( !pchannel->IsReference())
	{
		XMLElement* pelem;

		//Write CenterFrequency
		WriteElement( &pchannel->CenterFrequency(), "centerfreq", ctxt, *pelemc);
	
		//Write Translated Frequency
		WriteElement( &pchannel->TranslatedFrequency(), "translatedfreq", ctxt, *pelemc);

		//Inverted Element
		pelem = elem.GetDocument()->NewElement( "inverted");
		pelem->SetText( (pchannel->Inverted())? "true":"false");
		pelemc->InsertEndChild( pelem);

		//delaybias
		WriteElement( &pchannel->DelayBias(), "delaybias", ctxt, *pelemc);

		//System
		WriteElement( &pchannel->System(), "system", ctxt, *pelemc);
	}
	
	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *pchannel, ctxt, *pelemc);
	elem.InsertEndChild( pelemc);
}
예제 #4
0
// Virtual IComponent methods
bool CCmpRenderable::Init(CObjectIdHash oid, tinyxml2::XMLNode &node)
{
  // Get XML info
  try
  {
    tinyxml2::XMLElement * element = NULL;
    if(!node.FirstChildElement("float"))
    {
      CLog::Get()->Write(LOG_ERROR, "No child element to this node");
      return false;
    }
    for(element = node.FirstChildElement(); element != NULL; element = element->NextSiblingElement())
    {
      std::string name = element->Name();
      if(name == "path")
      {
        std::string nameAttrib = element->Attribute("name");
        if(nameAttrib == "model")
          this->createModel(element->FirstChild()->ToText()->Value());
      }//end if - name == path
    }//end for loop through nodes
  }//end try block
  catch(std::exception e)
  {
    CLog::Get()->Write( LOG_ERROR, "Unable to parse XML for CCmpRenderable Init! %s", e.what());
    return false;
  }
  return true;
}
예제 #5
0
/**
 * Write the current object 
 */
void RfConfigTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const RfConfiguration* pconfig = dynamic_cast< const RfConfiguration*>(pObject);
	if( pconfig == NULL) 
		throw TranslationException("RfConfigTranslator cannot cast to RfConfiguration object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *pconfig, ctxt, *pelemc);
	elem.InsertEndChild( pelemc);
}
예제 #6
0
/**
 * Write the current object 
 */
void StreamTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Stream* pstream = dynamic_cast< const Stream*>(pObject);
	if( pstream == NULL) 
		throw TranslationException("StreamTranslator cannot cast Stream object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *pstream, ctxt, *pelemc);

	if( !pstream->IsReference())
	{
		XMLElement* pelem;
		char buff[64];

		//Write ratefactor
		pelem = elem.GetDocument()->NewElement( "ratefactor");
		sprintf( buff, "%ld", pstream->RateFactor() );
		pelem->SetText( buff );
		pelemc->InsertEndChild( pelem);

		//Write quantization
		pelem = elem.GetDocument()->NewElement( "quantization");
		sprintf( buff, "%ld", pstream->Quantization() );
		pelem->SetText( buff );
		pelemc->InsertEndChild( pelem);

		//Write packedbits
		pelem = elem.GetDocument()->NewElement( "packedbits");
		sprintf( buff, "%ld", pstream->Packedbits() );
		pelem->SetText( buff );
		pelemc->InsertEndChild( pelem);

		//Write alignment
		pelem = elem.GetDocument()->NewElement( "alignment");
		pelem->SetText( _szAlignFmts[ pstream->Alignment()] );
		pelemc->InsertEndChild( pelem);

		//Write format
		pelem = elem.GetDocument()->NewElement( "format");
		pelem->SetText( _szSampleFmts[pstream->Format()] );
		pelemc->InsertEndChild( pelem);

		//Write encoding
		pelem = elem.GetDocument()->NewElement( "encoding");
		pelem->SetText( pstream->Encoding().c_str() );
		pelemc->InsertEndChild( pelem);

		//Write band
		WriteList<Band>( pstream->Bands(), "band", ctxt,*pelemc);

	}
	
	elem.InsertEndChild( pelemc);
}
예제 #7
0
inline void CameraSet<T>::appendTextElement( tinyxml2::XMLDocument& doc,
                                             tinyxml2::XMLNode& node,
                                             std::string name,
                                             std::string val )
{
    tinyxml2::XMLNode* tmp = node.InsertEndChild( doc.NewElement( name.c_str() ) );
    tmp->InsertEndChild( doc.NewText( val.c_str() ));
}
/**
 * Write the current object 
 */
void SessionTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Session* psession = dynamic_cast< const Session*>(pObject);
	if( psession == NULL) 
		throw TranslationException("SessionTranslator cannot cast Session object");
	else if( psession->Id().length() == 0)
		return;
	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *psession, ctxt, *pelemc);

	if( !psession->IsReference())
	{
		XMLElement* pelem;
		
		//Write toa
		pelem = elem.GetDocument()->NewElement( "toa");
		pelem->SetText( psession->Toa().toString().c_str());
		pelemc->InsertEndChild( pelem);

		//Write Position
		WriteElement( &psession->Position(), "position", ctxt, *pelemc);

		//TODO Write Attitude 

		//Write poc
		WriteElement("poc",psession->Poc().c_str(), pelemc, false, "");

		//Write conact
		WriteElement("contact",psession->Contact().c_str(), pelemc, false, "");

		//Write campaign
		WriteElement("campaign",psession->Campaign().c_str(), pelemc, false, "");

		//Write scenario
		WriteElement("scenario",psession->Scenario().c_str(), pelemc, false, "");

		//Write system
		WriteList<System>( psession->Systems(), "system", ctxt,*pelemc);		//Write location
	}
	

	elem.InsertEndChild( pelemc);
}
예제 #9
0
bool 
  CCmpUserInput::Init(CObjectIdHash oid, tinyxml2::XMLNode &node)
{
  //register keys->broadcast messages, based on XML file
  //Globals::GetInputManager()->playerInputHandler->registerCallback(
  //Globals::GetObjectManager()->BroadcastMessage
  CLog::Get()->Write(LOG_GENERAL,"TODO! Write a configurable keyboard thing in CCmpUserInput");

    // Get XML info
  try
  {
    tinyxml2::XMLElement * element = NULL;
    for(element = node.FirstChildElement(); element; element = element->NextSiblingElement()) 
    {
      std::string name = element->Name();
      if(name == "key")
      {
        //map the characters we'll load up from our XML to in-game constants
        IInputHandler * inputHandler = Globals::GetInputManager()->mInputHandlers[INPUT_PLAYER_KEY];

        SInput_t * key = new SKeyboardKey_t(element->Attribute("name"));
        int state = 0;
        if(element->Attribute("state") != NULL)
          state = atoi(element->Attribute("state"));
        
        CLog::Get()->Write(LOG_GENERAL,"working on input for %s", key->getIdentifier());
        
        CLog::Get()->Write(LOG_ERROR,"TODO! Writing the init for certain common actions");

        //TODO: write more generalized code to allow for customization.
        // currently, you define key mappings here in objects - ideally
        // you'd define them in one config to a generalized "Intent" (i.e. "hero action 1")
        // which is then mapped to the object, but I just want to get this working for now






        //THIS is where we register some script handle with our input handling
        //TODO:
        //create a scriptComponent
        //  -> scriptManager will get script filename from XML, return a handle/register a message/give a callback

      } //end if - name == key

    } //end for
  } // end try block
  catch(std::exception e)
  {
    CLog::Get()->Write( LOG_ERROR, "Unable to parse XML for CCmpEntity Init! %s", e.what());
    return false;
  }//end catch
  return true;
}
예제 #10
0
/**
 * Write the current object 
 */
void SourceTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Source* psource = dynamic_cast< const Source*>(pObject);
	if( psource == NULL) 
		throw TranslationException("SourceTranslator cannot cast Source object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	//Source object must have ID defined in order to support association
	//with bandsrc.
	WriteAttributedObject( *psource, ctxt, *pelemc, true);

	if( !psource->IsReference())
	{
		XMLElement* pelem;

		//Write type [0..1]
		pelem = elem.GetDocument()->NewElement( "type");
		pelem->SetText( _szSourceType[ psource->Type()] );
		pelemc->InsertEndChild( pelem);

		//Write polarization [0..1]
		pelem = elem.GetDocument()->NewElement( "polarization");
		pelem->SetText( _szSourcePolarization[ psource->Polarization()] );
		pelemc->InsertEndChild( pelem);

		//Write origin [0..1]
		WriteElement( &psource->Origin(), "origin", ctxt, *pelemc);

		//TODO Write rotation 

		//Write idcluster [0..1]
		WriteElement("idcluster",psource->IdCluster().c_str(), pelemc, false, "");
	}
	
	elem.InsertEndChild( pelemc);
}
/**
 * Write the current object 
 */
void LumpTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Lump* plump = dynamic_cast< const Lump*>(pObject);
	if( plump == NULL) 
		throw TranslationException("LumpTranslator cannot cast Lump object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *plump, ctxt, *pelemc);

	if( !plump->IsReference())
	{

      //Write band
		WriteList<IonStream>( plump->Streams(), "stream", ctxt,*pelemc);

	}
	

	elem.InsertEndChild( pelemc);
}
/**
 * Write the current object 
 */
void LaneTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Lane* plane = dynamic_cast< const Lane*>(pObject);
	if( plane == NULL) 
		throw TranslationException("LaneTranslator cannot cast Lane object");

	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *plane, ctxt, *pelemc);

	if( !plane->IsReference())
	{
		//Write bandsrc [1..*]
		Lane::BandSourceList::const_iterator iter = plane->BandSources().begin();
        for(; iter != plane->BandSources().end(); iter++)
		{
			XMLElement* pelem = elem.GetDocument()->NewElement("bandsrc");
			pelem->SetAttribute("idband", iter->idBand.c_str());
			pelem->SetAttribute("idsrc", iter->idSource.c_str());
			pelemc->InsertEndChild(pelem);
		}

		//Write session [0..*]
		WriteList<Session>( plane->Sessions(), "session", ctxt,*pelemc);

		//Write system [1..*]
		WriteList<System>( plane->Systems(), "system", ctxt,*pelemc);

		//Write block [1..*]
		WriteList<Block>( plane->Blocks(), "block", ctxt,*pelemc);
	}
	
	elem.InsertEndChild( pelemc);
}
예제 #13
0
/**
 * Write the current object 
 */
void SessionTranslator::OnWrite( const Object * pObject, pcstr pszName, Context & ctxt, tinyxml2::XMLNode & elem )
{
	const Session* psession = dynamic_cast< const Session*>(pObject);
	if( psession == NULL) 
		throw TranslationException("SessionTranslator cannot cast Session object");
	else if( psession->Id().length() == 0)
		return;
	XMLElement* pelemc = elem.GetDocument()->NewElement( pszName);

	if( !psession->IsReference())
	{
		XMLElement* pelem;

		//Write scenario
		pelem = elem.GetDocument()->NewElement( "scenario");
		pelem->SetText( psession->Scenario().c_str());
		pelemc->InsertEndChild(pelem);
		
		//Write campaign
		pelem = elem.GetDocument()->NewElement( "campaign");
		pelem->SetText( psession->Campaign().c_str());
		pelemc->InsertEndChild(pelem);

		//Write location
		pelem = elem.GetDocument()->NewElement( "location");
		char buff[128];
		const Location& llh = psession->Location();
		sprintf(buff,"%0.8lf", llh.Latitude());
		pelem->SetAttribute("lat", buff);
		sprintf(buff,"%0.8lf", llh.Longitude());
		pelem->SetAttribute("lon", buff);
		sprintf(buff,"%0.3lf", llh.Height());
		pelem->SetAttribute("height", buff);
		pelemc->InsertEndChild(pelem);

		//Write conact
		pelem = elem.GetDocument()->NewElement( "contact");
		pelem->SetText( psession->Contact().c_str());
		pelemc->InsertEndChild(pelem);

		//Write poc
		pelem = elem.GetDocument()->NewElement( "poc");
		pelem->SetText( psession->Poc().c_str());
		pelemc->InsertEndChild(pelem);
	}
	
	//Fill out id, artifacts, and comments last in accordance
	//with schema.
	WriteAttributedObject( *psession, ctxt, *pelemc);
	elem.InsertEndChild( pelemc);
}
예제 #14
0
	/**
	*	@brief This function calls WriteSaveSlot using each of the three save slots loaded 
	*	from earlier and saves the saveData.xml file.
	*/
	void save()	{
		xmlDoc.SaveFile("Backup_SavedData.xml");
		xmlDoc.Clear();
		initFile();

		WriteSaveSlot(*saved_data[0]);
		WriteSaveSlot(*saved_data[1]);
		WriteSaveSlot(*saved_data[2]);

		pRoot->InsertEndChild(saveGame);

		tinyxml2::XMLError eResult = xmlDoc.SaveFile("Assets/save_data.xml");
		if (eResult != NULL)
			perror("Error saving file a backup will be loaded on restart");
		if (remove("Backup_SavedData.xml") != 0)
			perror("Error deleting backup file");
	}
예제 #15
0
	/**
	*	@brief This is the default constructor for the XMLLoader. This sets up the root
	*	node and initalises the tinyxml2::XMLElement to start on the first save slot 
	*/
	XMLLoader(){
		string path = "Assets/save_data";
		string ext = ".sav";
		ext = ".xml";
		string result = path + ext;

		//xmlDoc.LoadFile(result.c_str());

		//Why does this load the old save_data all the time
		if(xmlDoc.LoadFile(result.c_str()) == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
			GenerateSaveFile();
		
		tinyxml2::XMLNode *pRoot = xmlDoc.FirstChild();
		//cout << string_to_int(s) << endl;
		
		saveGame = pRoot->FirstChildElement("SaveGame");
		if (saveGame == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		
		loadSaveSlots();
		/*
		tinyxml2::XMLElement * slot = saveGame->FirstChildElement("SaveSlot1");
		if (slot == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		tinyxml2::XMLElement * level = slot->FirstChildElement("Levels");
		if (level == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;

		tinyxml2::XMLElement * level_bool = level->FirstChildElement("LVL3");
		if (level_bool == nullptr) throw tinyxml2::XML_ERROR_FILE_READ_ERROR;
		string l_data = level_bool->GetText();
		cout << string_to_int(l_data) << endl;
		*/
		/*
		loadSaveSlots();
		*/
		/*
		const string image_ext = texture->Attribute("EXT");
		const string file_name = image_name + '.' + image_ext;*/
	}
예제 #16
0
/** sample ParaEngine mesh xml file
<mesh version=1 type=0>
	<boundingbox minx=0 miny=0 minz=0 maxx=1 maxy=1 maxz=1/>
	<shader index=3/>
	<submesh loddist=10 filename="LOD_10.x"/>
	<submesh loddist=50 filename="LOD_50.x"/>
</mesh>
*/
bool ParaEngine::CParaMeshXMLFile::LoadFromBuffer(const char* pData, int nSize)
{
#ifdef PARAENGINE_MOBILE
    namespace TXML = tinyxml2;
    try
    {
        TXML::XMLDocument doc(true, TXML::COLLAPSE_WHITESPACE);
        doc.Parse(pData, nSize);
        TXML::XMLElement* pRoot = doc.RootElement();
        if (pRoot)
        {
            pRoot->QueryIntAttribute("version", &m_nVersion);
            if (m_nVersion < SUPPORTED_MESH_FILE_VERSION)
            {
                OUTPUT_LOG("can not load para mesh xml file. because of a lower file version.\n");
            }
            int nType = 0;
            pRoot->QueryIntAttribute("type", &nType);
            m_nType = (ParaMeshXMLType)nType;

            for (TXML::XMLNode* pChild = pRoot->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
            {
                TXML::XMLElement* pElement = pChild->ToElement();
                if (pElement)
                {
                    std::string tagName = pElement->Name();
                    if (tagName == "boundingbox")
                    {
                        pElement->QueryFloatAttribute("minx", &m_vMinPos.x);
                        pElement->QueryFloatAttribute("miny", &m_vMinPos.y);
                        pElement->QueryFloatAttribute("minz", &m_vMinPos.z);
                        pElement->QueryFloatAttribute("maxx", &m_vMaxPos.x);
                        pElement->QueryFloatAttribute("maxy", &m_vMaxPos.y);
                        pElement->QueryFloatAttribute("maxz", &m_vMaxPos.z);
                    }
                    else if (tagName == "shader")
                    {
                        pElement->QueryIntAttribute("index", &m_nPrimaryShader);
                        // TODO: for shader parameters
                        for (TXML::XMLNode* pSubChild = pElement->FirstChild(); pSubChild != 0; pSubChild = pSubChild->NextSibling())
                        {
                            TXML::XMLElement* pParamElement = pSubChild->ToElement();
                            if (pParamElement)
                            {
                                std::string tagName = pParamElement->Name();
                                if (tagName == "params")
                                {
                                    CParameter p;
                                    // param name
                                    p.SetName(pParamElement->Attribute("name", ""));
                                    p.SetTypeByString(pParamElement->Attribute("type", ""));
                                    p.SetValueByString(pParamElement->GetText());
                                    m_paramBlock.AddParameter(p);
                                }
                            }
                        }
                    }
                    else if (tagName == "submesh")
                    {
                        CSubMesh meshInfo;
                        pElement->QueryFloatAttribute("loddist", &meshInfo.m_fToCameraDist);
                        std::string filepath = pElement->Attribute("filename");
                        // check if it is relative path or absolute path
                        if (filepath.find('/') != string::npos || filepath.find('\\') != string::npos)
                            meshInfo.m_sFileName = filepath;
                        else
                            meshInfo.m_sFileName = m_sParentDirectory + filepath;
                        m_SubMeshes.push_back(meshInfo);
                    }
                }
            }
        }
    }
    catch (...)
    {
        OUTPUT_LOG("error parsing xml file %s**.xml \n", m_sParentDirectory.c_str());
        return false;
    }
    return m_SubMeshes.size() > 0;
#else
    TiXmlDocument doc;
    try
    {
        doc.Parse(pData, 0, TIXML_DEFAULT_ENCODING);
        TiXmlElement* pRoot =  doc.RootElement();
        {
            // get mesh file version
            TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/@version");
            TinyXPath::expression_result res = xpathProc.er_compute_xpath();
            TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
            if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
            {
                const TiXmlAttribute* att = pNodeSet->XAp_get_attribute_in_set(0);
                m_nVersion = att->IntValue();
            }
        }
        if(m_nVersion < SUPPORTED_MESH_FILE_VERSION)
        {
            OUTPUT_LOG("can not load para mesh xml file. because of a lower file version.\n");
        }

        {
            // get mesh type
            TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/@type");
            TinyXPath::expression_result res = xpathProc.er_compute_xpath();
            TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
            if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
            {
                const TiXmlAttribute* att = pNodeSet->XAp_get_attribute_in_set(0);
                m_nType = (ParaMeshXMLType)att->IntValue();
            }
        }

        {
            // get mesh bounding box
            TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/boundingbox");
            TinyXPath::expression_result res = xpathProc.er_compute_xpath();
            TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
            if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
            {
                const TiXmlElement* pElem = pNodeSet->XNp_get_node_in_set(0)->ToElement();
                // parse attributes
                const TiXmlAttribute* pAttr = pElem->FirstAttribute();
                if (pAttr) {
                    m_bHasBoundingBox = true;
                    for (; pAttr; pAttr = pAttr->Next())
                    {
                        string sName = pAttr->Name();
                        if(sName == "minx")
                        {
                            m_vMinPos.x = (float)(pAttr->DoubleValue());
                        }
                        else if(sName == "miny")
                        {
                            m_vMinPos.y = (float)(pAttr->DoubleValue());
                        }
                        else if(sName == "minz")
                        {
                            m_vMinPos.z = (float)(pAttr->DoubleValue());
                        }
                        else if(sName == "maxx")
                        {
                            m_vMaxPos.x = (float)(pAttr->DoubleValue());
                        }
                        else if(sName == "maxy")
                        {
                            m_vMaxPos.y = (float)(pAttr->DoubleValue());
                        }
                        else if(sName == "maxz")
                        {
                            m_vMaxPos.z = (float)(pAttr->DoubleValue());
                        }
                    }
                }
            }
        }

        {
            // get shader index.
            TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/shader/@index");
            TinyXPath::expression_result res = xpathProc.er_compute_xpath();
            TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
            if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
            {
                const TiXmlAttribute* att = pNodeSet->XAp_get_attribute_in_set(0);
                m_nPrimaryShader = att->IntValue();
            }
        }
        {
            // get shader parameters.
            TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/shader/param");
            TinyXPath::expression_result res = xpathProc.er_compute_xpath();
            TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
            if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
            {
                int nCount = pNodeSet->u_get_nb_node_in_set();

                for(int i=0; i<nCount; ++i)
                {
                    // for each parameter
                    const TiXmlNode* node = pNodeSet->XNp_get_node_in_set(i);

                    CParameter p;
                    {
                        // param name
                        TinyXPath::xpath_processor xpathProc1(node->ToElement(), "@name");
                        TinyXPath::expression_result res1 = xpathProc1.er_compute_xpath();
                        TinyXPath::node_set* pNodeSet1 = res1.nsp_get_node_set();
                        if(pNodeSet1!=0 && pNodeSet1->u_get_nb_node_in_set()>0)
                        {
                            const TiXmlAttribute* att = pNodeSet1->XAp_get_attribute_in_set(0);
                            p.SetName(att->Value());
                        }
                    }

                    {
                        // get type
                        TinyXPath::xpath_processor xpathProc1(node->ToElement(), "@type");
                        TinyXPath::expression_result res1 = xpathProc1.er_compute_xpath();
                        TinyXPath::node_set* pNodeSet1 = res1.nsp_get_node_set();
                        if(pNodeSet1!=0 && pNodeSet1->u_get_nb_node_in_set()>0)
                        {
                            const TiXmlAttribute* att = pNodeSet1->XAp_get_attribute_in_set(0);
                            p.SetTypeByString(att->Value());
                        }
                    }
                    const TiXmlElement * pParamElement =  node->ToElement();
                    if(pParamElement)
                    {
                        // get text value
                        p.SetValueByString(pParamElement->GetText());
                        m_paramBlock.AddParameter(p);
                    }
                }
            }
        }
        {
            // get mesh info.
            TinyXPath::xpath_processor xpathProc(pRoot, "/mesh/submesh");
            TinyXPath::expression_result res = xpathProc.er_compute_xpath();
            TinyXPath::node_set* pNodeSet = res.nsp_get_node_set();
            if(pNodeSet!=0 && pNodeSet->u_get_nb_node_in_set()>0)
            {
                int nCount = pNodeSet->u_get_nb_node_in_set();
                m_SubMeshes.resize(nCount);

                for(int i=0; i<nCount; ++i)
                {
                    // for each sub meshes
                    const TiXmlNode* node = pNodeSet->XNp_get_node_in_set(i);

                    CSubMesh& meshInfo = m_SubMeshes[i];

                    {
                        // LOD to camera distance
                        TinyXPath::xpath_processor xpathProc1(node->ToElement(), "@loddist");
                        TinyXPath::expression_result res1 = xpathProc1.er_compute_xpath();
                        TinyXPath::node_set* pNodeSet1 = res1.nsp_get_node_set();
                        if(pNodeSet1!=0 && pNodeSet1->u_get_nb_node_in_set()>0)
                        {
                            const TiXmlAttribute* att = pNodeSet1->XAp_get_attribute_in_set(0);
                            meshInfo.m_fToCameraDist = (float)(att->DoubleValue());
                        }
                    }

                    {
                        // file name of the mesh
                        TinyXPath::xpath_processor xpathProc1(node->ToElement(), "@filename");
                        TinyXPath::expression_result res1 = xpathProc1.er_compute_xpath();
                        TinyXPath::node_set* pNodeSet1 = res1.nsp_get_node_set();
                        if(pNodeSet1!=0 && pNodeSet1->u_get_nb_node_in_set()>0)
                        {
                            const TiXmlAttribute* att = pNodeSet1->XAp_get_attribute_in_set(0);
                            string filepath = att->Value();
                            // check if it is relative path or absolute path
                            if(filepath.find('/')!=string::npos || filepath.find('\\')!=string::npos)
                                meshInfo.m_sFileName = filepath;
                            else
                                meshInfo.m_sFileName = m_sParentDirectory + filepath;
                        }
                    }
                }
            }
        }
    }
    catch (...)
    {
        OUTPUT_LOG("error parsing xml file %s**.xml \n", m_sParentDirectory.c_str());
        return false;
    }
    return true;
#endif
}
예제 #17
0
	/**
	*	@brief This generates a new saveData.xml for the game insertting all the approprate
	*	formatting for reading later.
	*	@see SaveSlot
	*/
	void GenerateSaveFile(){
		cLog::inst()->print(3, "XML Loader", "Generating new save_data.xml");

		//create and insert the root node of the .xml document
		tinyxml2::XMLNode *pRoot = xmlDoc.NewElement("Root");
		xmlDoc.InsertFirstChild(pRoot);

		tinyxml2::XMLElement *saveGame = xmlDoc.NewElement("SaveGame");
		for (int i = 0; i < 3; i++)
		{
			string d = "SaveSlot" + std::to_string(i + 1);
			const char * c = d.c_str();
			tinyxml2::XMLElement * saveSlot = xmlDoc.NewElement(c);

			//Inserts IntValue to the .xml file
			tinyxml2::XMLElement * pElement = xmlDoc.NewElement("TimePlayed");
			pElement->SetText(0);
			saveSlot->InsertEndChild(pElement);

			pElement = xmlDoc.NewElement("CurrentGold");
			pElement->SetText(0);
			saveSlot->InsertEndChild(pElement);

			pElement = xmlDoc.NewElement("Levels");
			for (int i = 0; i < 7; i++)
			{
				string d = "LVL" + std::to_string(i + 1);
				const char * c = d.c_str();
				tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
				pListElement->SetText(1);

				pElement->InsertEndChild(pListElement);
			}

			saveSlot->InsertEndChild(pElement);

			//Insert Achievement Tracking into the saveData.sav
			pElement = xmlDoc.NewElement("Achievements");
			for (int i = 0; i < 21; i++)
			{
				string d = "ACH" + std::to_string(i + 1);
				const char * c = d.c_str();
				tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
				pListElement->SetText(0);

				pElement->InsertEndChild(pListElement);
			}

			saveSlot->InsertEndChild(pElement);

			//Insert Stat Tracking into the saveData.sav
			pElement = xmlDoc.NewElement("Statistics");
			for (int i = 0; i < 10; i++)
			{
				string d = "STAT" + std::to_string(i + 1);
				const char * c = d.c_str();
				tinyxml2::XMLElement * pListElement = xmlDoc.NewElement(c);
				pListElement->SetText(0);

				pElement->InsertEndChild(pListElement);
			}

			saveSlot->InsertEndChild(pElement);

			saveGame->InsertEndChild(saveSlot);
		}
		pRoot->InsertEndChild(saveGame);

		tinyxml2::XMLError eResult = xmlDoc.SaveFile("Assets/save_data.xml");

	}