void cMushroom::Create_From_Stream(XMLElement* attributes) { int posx = 0, posy = 0; int mushroom_type = TYPE_MUSHROOM_DEFAULT; for (XMLElement* node = attributes->FirstChildElement(); node; node = node->NextSiblingElement()) { const char* name = node->Attribute("name"); const char* value = node->Attribute("value"); if (!strcmp(name, "posx")) { posx = atoi(value); } else if (!strcmp(name, "posy")) { posy = atoi(value); } else if (!strcmp(name, "mushroom_type")) { mushroom_type = atoi(value); } } Set_Pos(static_cast<float>(posx), static_cast<float>(posy)); Set_Type(static_cast<SpriteType>(mushroom_type)); }
bool UserXml::LoadXml(std::string file) { XMLDocument doc; XMLError e = doc.LoadFile(file.c_str()); if (e != XML_SUCCESS) return false; XMLElement* root = doc.RootElement(); if (!root) return false; // clear trks.clear(); trkmap.clear(); // tracks const char* a; //int i=1; //0 = none XMLElement* eTrk = root->FirstChildElement("track"); while (eTrk) { UserTrkInfo t; a = eTrk->Attribute("n"); if (a) t.name = string(a); a = eTrk->Attribute("date"); if (a) t.last = s2dt(a); a = eTrk->Attribute("rate"); if (a) t.rating = s2i(a); a = eTrk->Attribute("laps"); if (a) t.laps = s2i(a); a = eTrk->Attribute("time"); if (a) t.time = s2r(a); trks.push_back(t); trkmap[t.name] = trks.size(); //i++; eTrk = eTrk->NextSiblingElement("track"); } return true; }
string XMLHandler::LoadLink(string name) { XMLDocument doc; doc.LoadFile("links.xml"); if( doc.Error() ) { cout << "\nERROR:" << doc.ErrorID() << endl; return "ERROR"; } XMLElement* rootNode = doc.FirstChildElement("Links"); if (!rootNode) std::cout << "No Links element" << std::endl; XMLElement* linkNode = rootNode->FirstChildElement("Link"); if(!linkNode) std::cout << "No link elements" << std::endl; // Loop through XML for( ; linkNode != NULL; linkNode = linkNode->NextSiblingElement() ) { if( name == linkNode->Attribute("name") ) { return linkNode->Attribute("url"); } } return "NOTFOUND"; }
Stadium* Scanner::readConfigXML(string file) { string name, type, path; double shot, move; double npcVel, shotNpc, alturaObstaculo, freqTiro; doc.LoadFile(file.data()); if(!doc.ErrorID()) { XMLElement* arena = doc.FirstChildElement("aplicacao")->FirstChildElement("arquivoDaArena"); name = arena->Attribute("nome"); type = arena->Attribute("tipo"); path = arena->Attribute("caminho"); XMLElement* player = doc.FirstChildElement("aplicacao")->FirstChildElement("jogador"); player->QueryDoubleAttribute("velTiro",&shot); player->QueryDoubleAttribute("vel",&move); XMLElement* inimigo = doc.FirstChildElement("aplicacao")->FirstChildElement("inimigo"); inimigo->QueryDoubleAttribute("velTiro",&shotNpc); inimigo->QueryDoubleAttribute("vel",&npcVel); inimigo->QueryDoubleAttribute("freqTiro",&freqTiro); XMLElement* obstacle = doc.FirstChildElement("aplicacao")->FirstChildElement("obstaculo"); obstacle->QueryDoubleAttribute("altura",&alturaObstaculo); return readArenaSVG(path + name +"."+type,shot,move,shotNpc,npcVel,alturaObstaculo,freqTiro); }else { cout << "Erro ao abrir o arquivo XML "<< file << "\n"; exit(1); } }
void Book::parseOPF(BLUnZip& zip) { std::string data = zip.ExtractToString(m_opf); XMLDocument doc; doc.Parse(data.c_str()); XMLElement* package = doc.FirstChildElement("package"); XMLElement* metadata = package->FirstChildElement("metadata"); XMLElement* manifest = package->FirstChildElement("manifest"); XMLElement* item = manifest->FirstChildElement("item"); m_title = metadata->FirstChildElement("dc:title")->GetText(); m_author = metadata->FirstChildElement("dc:creator")->GetText(); for(XMLElement* rfe = item; rfe != nullptr; rfe = rfe->NextSiblingElement("item")) { m_manifest.emplace(rfe->Attribute("id"), rfe->Attribute("href")); } XMLElement* spine = package->FirstChildElement("spine"); XMLElement* itemref = spine->FirstChildElement("itemref"); for (XMLElement* it = itemref; it != nullptr; it = it->NextSiblingElement("itemref")) { m_spine.push_back(it->Attribute("idref")); } }
// Initialize a Geometry class given an XML element, return IQM file name static Geometry getGeom(XMLElement *elGeom){ Geometry G; XMLElement * trEl = check("Transform", elGeom); vec3 T(safeAtoF(*trEl, "Tx"), safeAtoF(*trEl, "Ty"), safeAtoF(*trEl, "Tz")); vec3 S(safeAtoF(*trEl, "Sx"), safeAtoF(*trEl, "Sy"), safeAtoF(*trEl, "Sz")); vec3 R(safeAtoF(*trEl, "Rx"), safeAtoF(*trEl, "Ry"), safeAtoF(*trEl, "Rz")); float rot = safeAtoF(*trEl, ("R")); mat4 M = glm::translate(T) * glm::rotate(rot, R) * glm::scale(S); // Create a Material XMLElement * matEl = check("Material", elGeom); float shininess(safeAtoF(*matEl, "shininess")); float reflectivity(safeAtoF(*matEl, "reflectivity")); vec4 diff(safeAtoF(*matEl, "Dr"), safeAtoF(*matEl, "Dg"), safeAtoF(*matEl, "Db"), safeAtoF(*matEl, "Da")); vec4 spec(safeAtoF(*matEl, "Sr"), safeAtoF(*matEl, "Sg"), safeAtoF(*matEl, "Sb"), safeAtoF(*matEl, "Sa")); Material mat(shininess, reflectivity, diff, spec); if (matEl->Attribute("Texture")) mat.SetTexMapSrc(matEl->Attribute("Texture")); if (matEl->Attribute("Normal")) mat.SetNrmMapSrc(matEl->Attribute("Normal")); // Set values G = Geometry("../Resources/IQM/" + string(elGeom->Attribute("fileName"))); G.leftMultM(M); G.setMaterial(mat); return G; }
void cEato::Create_From_Stream(XMLElement* attributes) { int posx = 0, posy = 0; std::string image_dir = m_img_dir; std::string direction = Get_Direction_Name(m_start_direction); for (XMLElement* node = attributes->FirstChildElement(); node; node = node->NextSiblingElement()) { const char* name = node->Attribute("name"); const char* value = node->Attribute("value"); if (!strcmp(name, "posx")) { posx = atoi(value); } else if (!strcmp(name, "posy")) { posy = atoi(value); } else if (!strcmp(name, "image_dir")) { image_dir = value; } else if (!strcmp(name, "direction")) { direction = value; } } Set_Pos(static_cast<float>(posx), static_cast<float>(posy), 1); Set_Image_Dir(image_dir.c_str()); Set_Direction(Get_Direction_Id(direction.c_str())); }
void CSimulator::_configureStructure ( XMLElement* elem ){ string elemName, attr; /* Create lines */ attr = elem->Attribute("lines"); int nLines = atoi( attr.c_str() ); for ( int i = 0 ; i < nLines ; i++ ){ CLine* tmp_line = new CLine ( &m_sSimCnf ); for( XMLElement* line = elem->FirstChildElement() ; line != NULL ; line = line->NextSiblingElement() ){ elemName = line->Value(); stringstream tmp_name; tmp_name << "line_"; tmp_name << (i+1); if ( elemName == tmp_name.str() ){ /* Create Nodes */ attr = line->Attribute("nodes"); int nNodes = atoi( attr.c_str() ); string sType = line->Attribute("type"); for( XMLElement* node = elem->FirstChildElement() ; node != NULL ; node = node->NextSiblingElement() ){ elemName = node->Value(); if ( elemName == sType ){ for ( int j = 0 ; j < nNodes ; j++ ){ tmp_line->addNode ( _createNode ( node , tmp_line->getPVNrGen() , tmp_line->getPVNrFrc() ) ); } } } } } m_pcGrid->addLine ( tmp_line ); } return; };
void GameObject::Load( XMLElement & e ) { const char * attrib = e.Attribute("id"); if ( !attrib ) throw AttributeMissingException("Attribute id is missing!"); SetId(attrib); attrib = e.Attribute("description"); if ( !attrib ) throw AttributeMissingException("Attribute description is missing!"); SetDescription(attrib); attrib = e.Attribute("name"); if ( !attrib ) throw AttributeMissingException("Attribute name is missing!"); SetName(attrib); attrib = e.Attribute("match"); if ( attrib) { SetNamePattern(attrib); } // Load properties XMLElement *props = e.FirstChildElement("Properties"); if ( props ) LoadProperties( *props); XMLElement *items = e.FirstChildElement("Items"); if ( items ) LoadItems(*items); else g_Log << "There were no items...\n"; }
void CEnvironment::_configureSinusoidal ( void ){ /* Read components from XML file */ XMLDocument conf; conf.LoadFile( m_sSourceFile.c_str() ); XMLElement* root = conf.FirstChildElement(); string elemName, attr; SFreqCmp tmp_FC; for( XMLElement* elem = root->FirstChildElement() ; elem != NULL ; elem = elem->NextSiblingElement() ){ elemName = elem->Value(); if ( elemName == "Cmp" ){ attr = elem->Attribute("period"); tmp_FC.period = atof( attr.c_str() ) / float ( m_nSampling ); attr = elem->Attribute("phase"); tmp_FC.phs = atof( attr.c_str() ); attr = elem->Attribute("amplitude"); tmp_FC.amp = m_fAmplitude * atof( attr.c_str() ); if ( tmp_FC.period > 0.0 ){ m_vInputSignal [ int ( float( m_nFFTsize ) / tmp_FC.period ) ] = tmp_FC; m_vNCAmp [ int ( float( m_nFFTsize ) / tmp_FC.period ) ] = tmp_FC.amp; } else{ m_vInputSignal [ 0 ] = tmp_FC; m_vNCAmp [ 0 ] = tmp_FC.amp; } } } return; };
void MapLoader::load(const std::string &xmlFilename, ResourceHandler &handler) { XMLFile doc(xmlFilename); XMLElement *areaElement = doc.FirstChildElement("maps").FirstChildElement("area").ToElement(); while(areaElement) { u16 area = areaElement->IntAttribute("id"); XMLElement *mapElement = areaElement->FirstChildElement("map"); while(mapElement) { std::string name = mapElement->Attribute("name"); std::string tilesetName = mapElement->Attribute("tileset"); u16 x = mapElement->IntAttribute("x"); u16 y = mapElement->IntAttribute("y"); Tileset &tileset = handler.get<Tileset>(tilesetName); loadMap(name, area, x, y, tileset, handler); mapElement = mapElement->NextSiblingElement("map"); } areaElement = areaElement->NextSiblingElement("area"); } }
void CSimulator::_configureVisu ( void ){ if ( m_sSimCnf.pcPlotter ) delete m_sSimCnf.pcPlotter; m_sSimCnf.pcPlotter = new CPlotter ( ); XMLDocument conf; conf.LoadFile( m_sSimCnf.sParamsFile.c_str() ); XMLElement* root = conf.FirstChildElement(); string elemName , attr; for( XMLElement* elem = root->FirstChildElement() ; elem != NULL ; elem = elem->NextSiblingElement() ){ elemName = elem->Value(); if ( elemName == "Visualization" ){ attr = elem->Attribute("rf_rate"); m_sSimCnf.pcPlotter->setRefreshRate ( atoi( attr.c_str() ) ); int cnt = 0; int type; for( XMLElement* e = elem->FirstChildElement() ; e != NULL ; e = e->NextSiblingElement() ){ attr = e->Attribute("title"); m_sSimCnf.pcPlotter->createDisplay ( NULL , NULL , 1 , attr ); attr = e->Attribute("x_lng"); m_sSimCnf.pcPlotter->setXrange ( cnt , atoi( attr.c_str() ) , "Time [k]" ); int y_ini, y_end; attr = e->Attribute("y_ini"); y_ini = atoi( attr.c_str() ); attr = e->Attribute("y_end"); y_end = atoi( attr.c_str() ); m_sSimCnf.pcPlotter->setYrange ( cnt , y_ini , y_end , "Power (W)" ); cnt++; } } } conf.Clear(); return; };
XMLElement * Utils::w(XMLElement * element, const char * name, const char * attribute, const char * value){ XMLElement * sibilingElement = element->NextSiblingElement(name); while (sibilingElement != NULL && strcmp(sibilingElement->Attribute(attribute), value) != 0) { sibilingElement = sibilingElement->NextSiblingElement(name); } return sibilingElement == NULL || strcmp(sibilingElement->Attribute(attribute), value) != 0 ? NULL : sibilingElement; }
XMLElement * Utils::getFirstChildElementWith(XMLElement * element, const char * name, const char * attribute, const char * value) { XMLElement * childElement = element->FirstChildElement(name); while (childElement != NULL && strcmp(childElement->Attribute(attribute), value) != 0) { childElement = childElement->NextSiblingElement(name); } return childElement == NULL || strcmp(childElement->Attribute(attribute), value) != 0 ? NULL : childElement; }
void parallelSetUp ( void ){ XMLDocument conf; conf.LoadFile( g_sMainFilename.c_str() ); XMLElement* root = conf.FirstChildElement(); string elemName , attr; for( XMLElement* elem = root->FirstChildElement() ; elem != NULL ; elem = elem->NextSiblingElement() ){ elemName = elem->Value(); if ( elemName == "output" ){ attr = elem->Attribute("file"); g_sOutputFile = attr; } else if ( elemName == "exp_conf" ){ attr = elem->Attribute("file"); g_sExpConf = attr; } else if ( elemName == "seed"){ attr = elem->Attribute("number"); g_nSeeds = atoi( attr.c_str() ); } else if ( elemName == "prm"){ SParamConf tmp_param; attr = elem->Attribute("length"); tmp_param.length = atoi( attr.c_str() ); attr = elem->Attribute("offset"); tmp_param.offset = atof( attr.c_str() ); attr = elem->Attribute("step"); tmp_param.step = atof( attr.c_str() ); g_vParams.push_back( tmp_param ); } else if ( elemName == "env"){ SParamConf tmp_envir; attr = elem->Attribute("length"); tmp_envir.length = atoi( attr.c_str() ); attr = elem->Attribute("offset"); tmp_envir.offset = atof( attr.c_str() ); attr = elem->Attribute("step"); tmp_envir.step = atof( attr.c_str() ); g_vEnvirs.push_back( tmp_envir ); } else if ( elemName == "result"){ attr = elem->Attribute("length"); g_nResltN = atoi( attr.c_str() ); } } g_nParamN = g_vParams.size(); g_nEnvirN = g_vEnvirs.size(); for ( int i = 0 ; i < g_nParamN ; i++ ) g_nExpSize *= g_vParams[i].length; for ( int i = 0 ; i < g_nEnvirN ; i++ ) g_nExpSize *= g_vEnvirs[i].length; conf.Clear(); return; };
Helicopter XMLConfig::readHelicopterConfig(const char * path){ XMLDocument doc; doc.LoadFile(path); XMLElement* helicoptero = doc.FirstChildElement("aplicacao")->FirstChildElement("helicoptero"); Helicopter h = Helicopter(atof(helicoptero->Attribute("velTiro")), atof(helicoptero->Attribute("velHelicoptero")), atof(helicoptero->Attribute("tempoDeVoo"))); return h; }
int CSettings::ParseOutputs(XMLElement *Outputs) { // Parse Outputs XMLElement *Output = Outputs->FirstChildElement("output"); int NumberOfOutputs = 0; while(Output) { OutputContainer OutputParse; NumberOfOutputs++; if(!Output->Attribute("name")) { Log.error("Output entry has no name\n"); return false; } // Check if there is a duplicate name OutputParse.name = Output->Attribute("name"); for(list<OutputContainer>::iterator i=OutputsDB.begin(); i != OutputsDB.end(); ++i) { if(OutputParse.name.compare((*i).name) == 0) { Log.error("Duplicate output name [%s]\n", OutputParse.name.c_str()); return false; } } OutputParse.type = Output->Attribute("type"); XMLNode *OutSettings = Output->FirstChild(); while(OutSettings) { if(OutSettings->Value() && OutSettings->ToElement()->GetText()) { OutputParse.settings[OutSettings->Value()] = OutSettings->ToElement()->GetText(); Log.debug("parsed [%s]=[%s]", OutSettings->Value(), OutputParse.settings[OutSettings->Value()].c_str()); } OutSettings = OutSettings->NextSibling(); } OutputsDB.push_back(OutputParse); Output = Output->NextSiblingElement("output"); } Log.log("Parsed %d outputs\n", NumberOfOutputs); return true; }
TestData readXMLDoc() { XMLDocument doc; #ifdef WIN32 XMLCheckResult(doc.LoadFile("../../test/mpw_tests.xml")); #else XMLCheckResult(doc.LoadFile("mpw_tests.xml")); #endif TestData data; XMLNode * pRoot = doc.FirstChild(); if (pRoot == 0) return data; XMLElement * pListElement = pRoot->FirstChildElement("case"); TestData testData; while (pListElement != 0) { //We have a test case. Allocate memory for it. TestCase testCase; //Get the ID of this case std::string id = pListElement->Attribute("id"); std::cout << "ID: " << id << std::endl; //Now check if we have a parent. const char* pParent = pListElement->Attribute("parent"); if (pParent) { testCase = testData.at(pParent); } //Now fill in the data from this node. XMLElement * pNodeListElement = pListElement->FirstChildElement(); while (pNodeListElement != 0) { const char* name = pNodeListElement->Name(); const char* value = pNodeListElement->GetText(); if (value != 0) { testCase[name] = value; std::cout << name << ": " << testCase[name] << std::endl; } else { testCase[name] = ""; std::cout << name << ": " << "null" << std::endl; } pNodeListElement = pNodeListElement->NextSiblingElement(); } testData[id] = testCase; pListElement = pListElement->NextSiblingElement("case"); } return testData; }
Helicopter XMLConfig::readEnemyHelicopter(const char* path, float cx, float cy){ XMLDocument doc; doc.LoadFile(path); XMLElement* helicoptero = doc.FirstChildElement("aplicacao")->FirstChildElement("helicopteroInimigo"); Helicopter h = Helicopter(atof(helicoptero->Attribute("freqTiro")), atof(helicoptero->Attribute("velHelicoptero")), cx, cy); // <helicopteroInimigo freqTiro="0.0001" velHelicoptero="0.1"></helicopteroInimigo> return h; }
void TriggerManager::LoadTriggersConfig(const std::string& moduleDir, std::vector<TriggerParameters>& trigsParams) { trigsParams.clear(); std::string file(moduleDir + "triggersConfig.xml"); XMLDocument doc; if(doc.LoadFile(file.c_str()) != XML_SUCCESS) { throw -1; } XMLElement* root = doc.RootElement(); // Look for first trigger XMLElement* firstTrigger = root->FirstChildElement("Trigger"); // Read all triggers for(XMLElement* trigger = firstTrigger; trigger != nullptr; trigger = trigger->NextSiblingElement()) { TriggerParameters trigParams; // Get trigger id trigParams.sensorId = std::atoi(trigger->Attribute("sensorId")); // Get trigger type trigParams.type = Util::Enums::TriggerTypeFromString(trigger->Attribute("sensorType")); // Read xml elements XMLElement* threshold = trigger->FirstChildElement("Threshold"); XMLElement* scanTime = trigger->FirstChildElement("ScanTime"); XMLElement* maskTime = trigger->FirstChildElement("MaskTime"); XMLElement* response = trigger->FirstChildElement("Response"); trigParams.threshold = (short) std::atoi(threshold->GetText()); trigParams.scanTime = (unsigned int) std::atoi(scanTime->GetText()); trigParams.maskTime = std::atoi(maskTime->GetText()); trigParams.response = Util::Enums::CurveTypeFromString(response->GetText()); //XXX Reading only sensor type LoadSensorsConfig(moduleDir, trigParams.sensorType); //trigParams.sensorType = IO::SensorType::Hdd; trigsParams.push_back(trigParams); } return; }
void TextureLoader::load(const char *xmlFilename, ResourceHandler &handler) { XMLFile doc(xmlFilename); XMLElement *textureElement = doc.FirstChildElement("textures").FirstChildElement("texture").ToElement(); while(textureElement) { std::string folder = textureElement->Attribute("folder"); std::string name = textureElement->Attribute("name"); sf::Texture &texture = handler.add<sf::Texture>(folder + "-" + name); texture.loadFromFile("graphics/" + folder + "/" + name + ".png"); textureElement = textureElement->NextSiblingElement("texture"); } }
bool TiledMap::loadTilesets(XMLDocument *map) { XMLElement* tileset; if((tileset = map->FirstChildElement("map")->FirstChildElement("tileset")) != NULL) { TiledMapTileset* temp = new TiledMapTileset(); temp->setFirstgid(this->stringToInt(tileset->Attribute("firstgid"))); temp->setName(tileset->Attribute("name")); temp->setTilewidth(this->stringToInt(tileset->Attribute("tilewidth"))); temp->setTileheight(this->stringToInt(tileset->Attribute("tileheight"))); temp->setImageSource(tileset->FirstChildElement("image")->Attribute("source")); temp->setImageTrans(tileset->FirstChildElement("image")->Attribute("trans")); temp->setImageWidth(this->stringToInt(tileset->FirstChildElement("image")->Attribute("width"))); temp->setImageHeight(this->stringToInt(tileset->FirstChildElement("image")->Attribute("height"))); this->insertTileset(temp); } while(tileset != NULL && (tileset = tileset->NextSiblingElement("tileset")) != NULL) { TiledMapTileset* temp = new TiledMapTileset(); temp->setFirstgid(this->stringToInt(tileset->Attribute("firstgid"))); temp->setName(tileset->Attribute("name")); temp->setTilewidth(this->stringToInt(tileset->Attribute("tilewidth"))); temp->setTileheight(this->stringToInt(tileset->Attribute("tileheight"))); temp->setImageSource(tileset->FirstChildElement("image")->Attribute("source")); temp->setImageTrans(tileset->FirstChildElement("image")->Attribute("trans")); temp->setImageWidth(this->stringToInt(tileset->FirstChildElement("image")->Attribute("width"))); temp->setImageHeight(this->stringToInt(tileset->FirstChildElement("image")->Attribute("height"))); this->insertTileset(temp); } }
XMLElement* CManagerModel::ParseMesh(XMLElement *XMLMesh,CModel* Model) { // Parse a SINGLE Mesh // Parse XMLSources AND Triangles. CMesh Mesh; XMLElement *XMLSource = XMLMesh->FirstChildElement("source"); XMLElement *Tri = XMLMesh->FirstChildElement("triangles"); XMLElement *Input = Tri->FirstChildElement("input"); //Mesh.mTriangleCount = Tri->IntAttribute("count"); while (Input != NULL) { CSource Source; if (strcmp(Input->Attribute("semantic"),"VERTEX") == 0) { Source.mID = XMLMesh->FirstChildElement("vertices")->FirstChildElement("input")->Attribute("source"); } else { Source.mID = Input->Attribute("source"); } Source.mType = (char*) Input->Attribute("semantic"); Source.mOffset = Input->IntAttribute("offset"); Source.mID = Source.mID.erase(0, 1); // Remove the pound symbol. // This is actually <p>, aka an index list. Mesh.mIndex = gusVector_SplitString((char*)Tri->FirstChildElement("p")->GetText(),' '); ParseSource(SourceByID(XMLMesh,(char*)Source.mID.c_str()),&Mesh,&Source); Input = Input->NextSiblingElement("input"); } // [Matrix setup] // Let's hope we've added everything needed in these loops. Model->AddMesh(Mesh); return XMLMesh->NextSiblingElement("mesh"); }
void readVisualSceneInstanceGeometries(XMLDocument& doc, btHashMap<btHashString,int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances) { btHashMap<btHashString,XMLElement* > allVisualScenes; XMLElement* libVisualScenes = doc.RootElement()->FirstChildElement("library_visual_scenes"); if (libVisualScenes==0) return; { for(XMLElement* scene = libVisualScenes->FirstChildElement("visual_scene"); scene != NULL; scene = scene->NextSiblingElement("visual_scene")) { const char* sceneName = scene->Attribute("id"); allVisualScenes.insert(sceneName,scene); } } XMLElement* scene = 0; { XMLElement* scenes = doc.RootElement()->FirstChildElement("scene"); if (scenes) { XMLElement* instanceSceneReference = scenes->FirstChildElement("instance_visual_scene"); if (instanceSceneReference) { const char* instanceSceneUrl = instanceSceneReference->Attribute("url"); XMLElement** sceneInstancePtr = allVisualScenes[instanceSceneUrl+1];//skip # if (sceneInstancePtr) { scene = *sceneInstancePtr; } } } } if (scene) { for(XMLElement* node = scene->FirstChildElement("node"); node != NULL; node = node->NextSiblingElement("node")) { btMatrix4x4 identity; identity.setIdentity(); btVector3 identScaling(1,1,1); readNodeHierarchy(node,name2Shape,visualShapeInstances, identity); } } }
void VisualComponent::init(XMLElement *componentElement) { XMLElement* textureElement; const char* textureFileLocation; const char* fontFileLocation; std::ostringstream LabelString; ComponentID = componentElement->IntAttribute("ComponentType"); viewType = (ViewType)componentElement->IntAttribute("GameViewId"); XMLElement* colorElement = componentElement->FirstChildElement("Color"); //actorColor = new sf::Color(colorElement->IntAttribute("r"),colorElement->IntAttribute("g"),colorElement->IntAttribute("b"),colorElement->IntAttribute("a")); XMLElement* shapeElement = colorElement->NextSiblingElement("Structure"); shapeID = shapeElement->IntAttribute("ShapeID"); switch(shapeElement->IntAttribute("ShapeID")) { case 1://"Rectangle": actorShape = new ActorShape::Rectangle(); ((ActorShape::Rectangle*)actorShape)->setSize(shapeElement->FloatAttribute("Height"), shapeElement->FloatAttribute("Width")); ((ActorShape::Rectangle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor);//(const sf::Color &)actorColor break; case 2://"Circle": actorShape = new ActorShape::Circle(); ((ActorShape::Circle*)actorShape)->setSize(shapeElement->FloatAttribute("Radious")); ((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor); break; case 3://"GRID MAP": actorShape = new ActorShape::GridMap(); ((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth")); break; case 5://TextArea textureElement = shapeElement->NextSiblingElement("Texture"); textureFileLocation = textureElement->Attribute("TextureFileName"); actorShape = new ActorShape::GridMap(); ((ActorShape::GridMap*)actorShape)->LoadTexture(textureFileLocation); ((ActorShape::GridMap*)actorShape)->setBlockSize(shapeElement->IntAttribute("BlockHeight"),shapeElement->IntAttribute("BlockWidth")); fontFileLocation = textureElement->Attribute("FontFileName"); ((ActorShape::GridMap*)actorShape)->LoadFont(fontFileLocation); //LabelString << textureElement->Attribute("Text");// put float into string buffer //((ActorShape::GridMap*)actorShape)->SetTextInBox(LabelString, 0, 0); break; default: actorShape = new ActorShape::Circle(); ((ActorShape::Circle*)actorShape)->setSize(10); ((ActorShape::Circle*)actorShape)->actorShape.setFillColor((const sf::Color &)actorColor); break; } isVisible = true; }
XMLElement* FindElementWithAttribute(XMLElement *parent, const char* elementname, const char *attribute, const char *value, XMLDocument* createIfNotExists) { _ASSERT(parent); XMLElement *r = parent->FirstChildElement(elementname); if (!r) { if (createIfNotExists) { r = createIfNotExists->NewElement(elementname); r->SetAttribute(attribute, value); parent->LinkEndChild(r); return r; } else { return 0; } } XMLElement *s = r; do { if (r->Attribute(attribute, value)) return r; r = r->NextSiblingElement(elementname); } while (r != 0 && r != s); // cannot found previous element if (createIfNotExists) { r = createIfNotExists->NewElement(elementname); r->SetAttribute(attribute, value); parent->LinkEndChild(r); return r; } return 0; }
void LoadedMap::loadTerrains(XMLElement *element, TileSet *target) { Logger.logMessage(LOG_STATE, LOG_MAP, "LoadedMap::loadTerrains start\n"); assert(element); assert(target); XMLElement *terrain = element->FirstChildElement(XML_TERRAIN.c_str()); Logger.logMessage(LOG_DEBUG, LOG_MAP, "LoadedMap::loadTerrains: Found first terrain\n"); while(terrain) { TerrainType parsed_terrain; parsed_terrain.name = getAttributeString(terrain, XML_TERRAIN_NAME); stringstream tile (terrain->Attribute(XML_TERRAIN_TILE.c_str())); tile >> parsed_terrain.tile; XMLElement *properties = terrain->FirstChildElement(XML_TERRAIN_PROPS.c_str()); if(properties) { loadTerrainProperties(properties, &parsed_terrain); } target->terraintypes.push_back(parsed_terrain); terrain = terrain->NextSiblingElement(); } Logger.logMessage(LOG_STATE, LOG_MAP, "LoadedMap::loadTerrains end\n"); }
void SpriteAnimationManager::init() { XMLFile doc("data/config/spriteAnimations.xml"); XMLElement *animationElement = doc.FirstChildElement("spriteAnimations").FirstChildElement("animation").ToElement(); while(animationElement) { std::string name = animationElement->Attribute("name"); std::vector<SpriteAnimation> animation; XMLElement *framesElement = animationElement->FirstChildElement("frames"); while(framesElement) { std::vector<u16> frames; u16 delay = framesElement->IntAttribute("delay"); XMLElement *frameElement = framesElement->FirstChildElement("frame"); while(frameElement) { frames.push_back(frameElement->IntAttribute("id")); frameElement = frameElement->NextSiblingElement("frame"); } animation.push_back(SpriteAnimation(frames.size(), frames, delay)); framesElement = framesElement->NextSiblingElement("frames"); } spriteAnimations[name] = animation; animationElement = animationElement->NextSiblingElement("animation"); } }
void FileList::read() { XMLDocument doc; const string filepath = dir + "filelist"; doc.LoadFile(filepath.c_str()); XMLElement* filelist = doc.FirstChildElement(); try { validateXML(filelist, filepath); } catch (NoFile) { return; } for (XMLElement* i = filelist->FirstChildElement(); i != NULL; i = (XMLElement*) i->NextSibling()) { const string from = i->Attribute("from"); const string to = i->Attribute("to"); const Args::Action action = static_cast<Args::Action>(i->IntAttribute("action")); records.push_back(Record(from, to, action)); } }
/** * Reads a node from the document and parses into metadata. */ bool FrequencyTranslator::OnRead( Context & ctxt, const XMLElement & elem, AccessorAdaptorBase* pAdaptor ) { //The node as been tested as a Frequency Translator if( pAdaptor != NULL) { pcstr format = elem.Attribute("format"); if( format == NULL) format = "Hz"; Frequency::FrequencyFormat fmt = ToFormat( format); Frequency freq; switch( fmt) { case Frequency::Ratio: { long num, denom; sscanf( elem.GetText(), "%ld,%ld", &num, &denom); freq.Value( num, denom); } break; default: { freq.Value( atof(elem.GetText()), fmt); } break; } //Set the accessor. pAdaptor->set( &freq); return true; } return false; }