/** * Lee el tag XML static y agrega al escenario la entidad correspondiente * @param pStaticElement * @param scenario */ logic::CEntity* CScenariosXmlDao::readStaticEntity(TiXmlElement* pStaticElement) { TiXmlHandle hStatic(pStaticElement); TiXmlElement* pPositionElement = hStatic.FirstChild("position").Element(); TiXmlElement* pOrientationElement = hStatic.FirstChild("orientation").Element(); string id = pStaticElement->Attribute("id"); bool reflect = false; logic::tRGBAColor color; if(pStaticElement->Attribute("reflect")){ TiXmlElement* pColorElement = hStatic.FirstChild("color").Element(); pColorElement->QueryFloatAttribute("r",&color.r); pColorElement->QueryFloatAttribute("g",&color.g); pColorElement->QueryFloatAttribute("b",&color.b); pColorElement->QueryFloatAttribute("a",&color.a); //cout<<"[ScenariosXmlDao::readScenario] Elemento: "<<id<<" REFLEJA!!\n"; reflect = true; } float x=0,y=0,z=0; pPositionElement->QueryFloatAttribute("x",&x); pPositionElement->QueryFloatAttribute("y",&y); pPositionElement->QueryFloatAttribute("z",&z); float orientation = 0; pOrientationElement->QueryFloatAttribute("value",&orientation); //cout<<"[ScenariosXmlDao::readScenario]Entidad "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n"; logic::CEntity* entity = new logic::CEntity(id, x, y, z, orientation, true); entity->setReflection(reflect); entity->setColor(color); return entity; }
logic::CScreen* CScenariosXmlDao::readScreen(TiXmlElement* pScreenElement) { TiXmlHandle hScreen(pScreenElement); TiXmlElement* pPositionElement = hScreen.FirstChild("position").Element(); TiXmlElement* pOrientationElement = hScreen.FirstChild("orientation").Element(); TiXmlElement* pSkinsElement = hScreen.FirstChild("skins").Element(); string id = pScreenElement->Attribute("id"); float interval = 0; pSkinsElement->QueryFloatAttribute("interval", &interval); float x=0,y=0,z=0; pPositionElement->QueryFloatAttribute("x",&x); pPositionElement->QueryFloatAttribute("y",&y); pPositionElement->QueryFloatAttribute("z",&z); float orientation = 0; pOrientationElement->QueryFloatAttribute("value",&orientation); vector<string> skinList = readSkins(pSkinsElement); //cout<<"[ScenariosXmlDao::readScreen]Entidad "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n"; logic::CScreen* screen = new logic::CScreen(id, x, y, z, orientation, true); screen->setSkinList(skinList); screen->setInterval(interval); return screen; }
logic::CQuizShowHost* CScenariosXmlDao::readHost(TiXmlElement* pHostElement) { //cout<<"Etiqueta: "<<pHostElement->Value()<<"\n"; string id = pHostElement->Attribute("id"); string type = ""; if(pHostElement->Attribute("type")) type = pHostElement->Attribute("type"); TiXmlHandle hHost(pHostElement); TiXmlElement* pPositionElement = hHost.FirstChild("position").Element(); TiXmlElement* pOrientationElement = hHost.FirstChild("orientation").Element(); float x=0,y=0,z=0; pPositionElement->QueryFloatAttribute("x",&x); pPositionElement->QueryFloatAttribute("y",&y); pPositionElement->QueryFloatAttribute("z",&z); float orientation = 0; pOrientationElement->QueryFloatAttribute("value",&orientation); //cout<<"[ScenariosXmlDao::readScenario] Animado "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n"; logic::CQuizShowHost* host= new logic::CQuizShowHost(id, id, x, y, z, orientation, true, 9); return host; }
logic::CAvatar* CScenariosXmlDao::readAudience(TiXmlElement* pPublicElement) { //cout<<"Etiqueta: "<<pPublicElement->Value()<<"\n"; string id = pPublicElement->Attribute("id"); string type = ""; if(pPublicElement->Attribute("type")) type = pPublicElement->Attribute("type"); TiXmlHandle hPublic(pPublicElement); TiXmlElement* pPositionElement = hPublic.FirstChild("position").Element(); TiXmlElement* pOrientationElement = hPublic.FirstChild("orientation").Element(); float x=0,y=0,z=0; pPositionElement->QueryFloatAttribute("x",&x); pPositionElement->QueryFloatAttribute("y",&y); pPositionElement->QueryFloatAttribute("z",&z); float orientation = 0; pOrientationElement->QueryFloatAttribute("value",&orientation); //cout<<"[ScenariosXmlDao::readScenario] Animado "<<id<<", ["<<x<<", "<<y<<", "<<z<<"], "<<orientation<<"\n"; logic::CAvatar* audience= new logic::CAvatar("player", id, x, y, z, orientation, true, 10); return audience; }
bool ETHSceneProperties::ReadFromXMLFile(TiXmlElement *pRoot) { TiXmlNode *pNode; pNode = pRoot->FirstChild(GS_L("SceneProperties")); if (pNode) { TiXmlElement *pElement = pNode->ToElement(); pElement->QueryFloatAttribute(GS_L("lightIntensity"), &lightIntensity); pElement->QueryFloatAttribute(GS_L("parallaxIntensity"), ¶llaxIntensity); TiXmlElement *pIter; pNode = pElement->FirstChild(GS_L("Ambient")); if (pNode) { pIter = pNode->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("r"), &ambient.x); pIter->QueryFloatAttribute(GS_L("g"), &ambient.y); pIter->QueryFloatAttribute(GS_L("b"), &ambient.z); } } pNode = pElement->FirstChild(GS_L("ZAxisDirection")); if (pNode) { pIter = pNode->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("x"), &zAxisDirection.x); pIter->QueryFloatAttribute(GS_L("y"), &zAxisDirection.y); } } } return true; }
void File::Init(TiXmlNode *node) { TiXmlElement *element = node->ToElement(); if (element) { int intValue; float floatValue; if (element->QueryIntAttribute("id", &intValue) == TIXML_SUCCESS) id = intValue; else id = 0; name = element->Attribute("name"); if (element->QueryFloatAttribute("width", &floatValue) == TIXML_SUCCESS) width = floatValue; else width = 0; if (element->QueryFloatAttribute("height", &floatValue) == TIXML_SUCCESS) height = floatValue; else height = 0; if (name.size()>0) { sprite = CCSprite::createWithSpriteFrameName(name.c_str()); // sprite = CCSprite::create(name.c_str()); sprite->retain(); } } }
void YafFile::processLights(TiXmlElement* lights) { float location[4], ambient[4], diffuse[4], specular[4]; float angle = 0, exponent = 0, direction[3]; bool enabled; string type; char* id; Light* light; TiXmlElement* element = lights->FirstChildElement(); while(element!=NULL) { element->QueryBoolAttribute("enabled",&enabled); id = (char*)element->Attribute("id"); read3Float("location", element, location[0], location[1], location[2]); read4Float("ambient", element, ambient[0], ambient[1], ambient[2], ambient[3]); read4Float("diffuse", element, diffuse[0], diffuse[1], diffuse[2], diffuse[3]); read4Float("specular", element, specular[0], specular[1], specular[2], specular[3]); if(element->Attribute("angle")!=NULL) { type="spot"; element->QueryFloatAttribute("angle", &angle); element->QueryFloatAttribute("exponent", &exponent); read3Float("direction", element, direction[0], direction[1], direction[2]); } light = new Light(id,enabled,type,location,ambient,diffuse,specular,angle,exponent,direction); this->sceneLights.push_back(light); element=element->NextSiblingElement(); } }
// A font is specified by two files: a TGA file with the rendered // chars for the font, and a XML file which contains global info // about the font and the texture coordinates and width of each char // The parameter fontName is the filename without extension. // It is assumed that the files are "fontName.xml" and "fontName.tga" bool VSFontLib::load(std::string fontName) { // Test if image file exists FILE *fp; std::string s; s = fontName + ".tga"; fp = fopen(s.c_str(),"r"); if (fp == NULL) { VSResourceLib::sLogError.addMessage("Unable to find font texture: %s", s.c_str()); return false; } mFontTex = loadRGBATexture(s); s = fontName + ".xml"; TiXmlDocument doc(s.c_str()); bool loadOK = doc.LoadFile(); if (!loadOK) { VSResourceLib::sLogError.addMessage("Problem reading the XML font definition file: %s", s.c_str()); return false; } TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement *pElem; pElem = hDoc.FirstChildElement().Element(); if (0 == pElem) return false; hRoot = TiXmlHandle(pElem); pElem->QueryIntAttribute("numchars",&mNumChars); if (mNumChars == 0) return false; hRoot = hRoot.FirstChild("characters"); pElem = hRoot.FirstChild("chardata").Element(); if (pElem) pElem->QueryIntAttribute("hgt",&mHeight); VSFLChar aChar; int charCode, numChars = 0; for(; 0 != pElem; pElem = pElem->NextSiblingElement(), ++numChars) { pElem->QueryIntAttribute("char",&charCode); pElem->QueryIntAttribute("wid",&(aChar.width)); pElem->QueryFloatAttribute("X1", &(aChar.x1)); pElem->QueryFloatAttribute("X2", &(aChar.x2)); pElem->QueryFloatAttribute("Y1", &(aChar.y1)); pElem->QueryFloatAttribute("Y2", &(aChar.y2)); pElem->QueryIntAttribute("A", &(aChar.A)); pElem->QueryIntAttribute("C", &(aChar.C)); mChars[(unsigned char)charCode] = aChar; } VSResourceLib::sLogInfo.addMessage("Font has %d chars", numChars); return true; }
/** * Extract a light elements containing position (x, y, z) and colour (r, g, b) attributes */ void MapLoader::extractLights() { Vector3f lightPos; Vector3f lightColor; float distance; float energy; TiXmlElement* lightElement = rootHandle.FirstChild("light").ToElement(); do { XmlHelper::pushAttributeVertexToVector(lightElement, lightPos); lightElement->QueryFloatAttribute("r", &lightColor.x); lightElement->QueryFloatAttribute("g", &lightColor.y); lightElement->QueryFloatAttribute("b", &lightColor.z); lightElement->QueryFloatAttribute("distance", &distance); lightElement->QueryFloatAttribute("energy", &energy); scene->lights.emplace_back(); Light &light = scene->lights.back(); light.position.set(lightPos.x, lightPos.y, lightPos.z); light.color.set(lightColor.x, lightColor.y, lightColor.z); light.distance = distance; light.energy = energy; } while ((lightElement = lightElement->NextSiblingElement("light")) != nullptr); }
void MapLoader::extractButtons() { TiXmlElement *textureElement = rootHandle.FirstChild("texture").ToElement(); string texturePath("none"); string surfaceType("none"); Vector2f position; Vector2f size; if (textureElement) { do { textureElement->QueryStringAttribute("source", &texturePath); textureElement->QueryStringAttribute("type", &surfaceType); TiXmlElement *buttonElement = textureElement->FirstChildElement("GUIbutton"); if (buttonElement) { do { scene->buttons.emplace_back(); GUIButton &button = scene->buttons.back(); buttonElement->QueryFloatAttribute("x", &position.x); buttonElement->QueryFloatAttribute("y", &position.y); buttonElement->QueryFloatAttribute("w", &size.x); buttonElement->QueryFloatAttribute("h", &size.y); button.texture = TextureLoader::getTexture(texturePath); button.texture.xTiling = 0.5f; button.texture.yTiling = 0.5f; } while ((buttonElement = buttonElement->NextSiblingElement("GUIbutton")) != nullptr); } texturePath = "none"; } while ((textureElement = textureElement->NextSiblingElement("texture")) != nullptr); } }
bool ETHLight::ReadFromXMLFile(TiXmlElement *pElement) { int nActive; pElement->QueryIntAttribute(GS_L("active"), &nActive); active = static_cast<ETH_BOOL>(nActive); int nStatic; pElement->QueryIntAttribute(GS_L("static"), &nStatic); staticLight = static_cast<ETH_BOOL>(nStatic); int nCastShadows; pElement->QueryIntAttribute(GS_L("castShadows"), &nCastShadows); castShadows = static_cast<ETH_BOOL>(nCastShadows); pElement->QueryFloatAttribute(GS_L("range"), &range); pElement->QueryFloatAttribute(GS_L("haloBrightness"), &haloBrightness); pElement->QueryFloatAttribute(GS_L("haloSize"), &haloSize); TiXmlNode *pNode; TiXmlElement *pIter; pNode = pElement->FirstChild(GS_L("Position")); if (pNode) { pIter = pNode->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("x"), &pos.x); pIter->QueryFloatAttribute(GS_L("y"), &pos.y); pIter->QueryFloatAttribute(GS_L("z"), &pos.z); } } pNode = pElement->FirstChild(GS_L("Color")); if (pNode) { pIter = pNode->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("r"), &color.x); pIter->QueryFloatAttribute(GS_L("g"), &color.y); pIter->QueryFloatAttribute(GS_L("b"), &color.z); } } pNode = pElement->FirstChild(GS_L("HaloBitmap")); if (pNode) { TiXmlElement *pStringElement = pNode->ToElement(); if (pStringElement) { haloBitmap = pStringElement->GetText(); } } return true; }
void ControlSuper::loadXML(TiXmlElement &root) { root.QueryBoolAttribute("enabled",&enabled); root.QueryBoolAttribute("hidden",&hidden); root.QueryFloatAttribute("left", &controlPos.left); root.QueryFloatAttribute("right", &controlPos.right); root.QueryFloatAttribute("top", &controlPos.top); root.QueryFloatAttribute("bottom",&controlPos.bottom); }
void Object::Init(TiXmlNode *node, CCSpriterX *animator) { sprite = NULL; TiXmlElement *element = node->ToElement(); if (element) { int intValue; float floatValue; if (element->QueryIntAttribute("folder", &intValue) == TIXML_SUCCESS) folder = intValue; else folder = 0; if (element->QueryIntAttribute("file", &intValue) == TIXML_SUCCESS) file = intValue; else file = 0; if (element->QueryFloatAttribute("x", &floatValue) == TIXML_SUCCESS) x = floatValue; else x = 0; if (element->QueryFloatAttribute("y", &floatValue) == TIXML_SUCCESS) y = floatValue; else y = 0; if (element->QueryFloatAttribute("angle", &floatValue) == TIXML_SUCCESS) angle = floatValue; else angle = 0; if (element->QueryFloatAttribute("pivot_x", &floatValue) == TIXML_SUCCESS) pivot_x = floatValue; else pivot_x = 0; if (element->QueryFloatAttribute("pivot_y", &floatValue) == TIXML_SUCCESS) pivot_y = floatValue; else pivot_y = 1; if (element->QueryIntAttribute("z_index", &intValue) == TIXML_SUCCESS) z_index = intValue; else z_index = 0; sprite = animator->getSprite(folder, file); } }
bool CTextureAtlas::Load() { BEATS_ASSERT(!IsLoaded()); TString fileext = CFilePathTool::GetInstance()->Extension(GetFilePath().c_str()); if(fileext == _T(".xml")) { TiXmlDocument doc; CSerializer serializer; CFilePathTool::GetInstance()->LoadFile(&serializer, GetFilePath().c_str(), _T("rb")); if (serializer.GetWritePos() != serializer.GetReadPos()) { doc.Parse((char*)serializer.GetReadPtr()); } TiXmlElement *root = doc.RootElement(); BEATS_ASSERT(root && strcmp(root->Value(), "Imageset") == 0, _T("TextureAtlas file %s not found or incorrect!"), GetFilePath().c_str()); const char *textureFile = root->Attribute("Imagefile"); BEATS_ASSERT(textureFile); TCHAR szNameBuffer[MAX_PATH]; CStringHelper::GetInstance()->ConvertToTCHAR(textureFile, szNameBuffer, MAX_PATH); m_texture = CResourceManager::GetInstance()->GetResource<CTexture>(szNameBuffer); kmVec2 size; kmVec2 point; TString strName; for(TiXmlElement *elemImage = root->FirstChildElement("Image"); elemImage != nullptr; elemImage = elemImage->NextSiblingElement("Image")) { const char *name = elemImage->Attribute("Name"); BEATS_ASSERT(name); kmVec2Fill(&point, 0.f, 0.f); kmVec2Fill(&size, 0.f, 0.f); elemImage->QueryFloatAttribute("XPos", &point.x); elemImage->QueryFloatAttribute("YPos", &point.y); elemImage->QueryFloatAttribute("Width", &size.x); elemImage->QueryFloatAttribute("Height", &size.y); CStringHelper::GetInstance()->ConvertToTCHAR(name, szNameBuffer, MAX_PATH); strName.assign(szNameBuffer); CreateTextureFrag(strName, point, size); } } else { m_texture = CResourceManager::GetInstance()->GetResource<CTexture>(GetFilePath()); } m_name = CFilePathTool::GetInstance()->FileName(GetFilePath().c_str()); super::Load(); return true; }
/** * @method PigManager::loadLevel() * @desc parse the current level xml and instantiate the pigs in it */ void PigManager::loadLevel(TiXmlElement* levelPigElement) { if (numPigs > 0) { shutdown(); } numPigs = 0; TiXmlElement* levelPig = levelPigElement->FirstChildElement(); while (levelPig != NULL) { numPigs++; levelPig = levelPig->NextSiblingElement(); } pigList = new EnemyPig*[numPigs]; int i = 0; int x, y; float wid, ht; levelPig = levelPigElement->FirstChildElement(); ObjectData currentPigData; while (levelPig != NULL) { const char* currentBlockType = levelPig->Attribute("type"); int j; for (j = 0; j < totalPossiblePigs; j++) { if (strcmp(currentBlockType, allPigsData[j].objectType) == 0) { currentPigData = allPigsData[j]; break; } } assert(j < totalPossiblePigs); levelPig->QueryIntAttribute("x", &x); levelPig->QueryIntAttribute("y", &y); levelPig->QueryFloatAttribute("wid", &wid); levelPig->QueryFloatAttribute("ht", &ht); pigList[i] = new EnemyPig(); pigList[i]->init(x, y, wid, currentPigData); levelPig = levelPig->NextSiblingElement(); i++; } CGame::GetInstance()->setPigCount(numPigs); }
void FontXMLLoader::loadFont (Font *aFont, std::string &aFilename) { File::FixSlashes(aFilename); std::string s = aFilename; int numChars,height; TiXmlDocument doc(s.c_str()); bool loadOK = doc.LoadFile(); if (!loadOK) { NAU_THROW("Parsing Error -%s- Line(%d) Column(%d) in file: %s", doc.ErrorDesc(), doc.ErrorRow(), doc.ErrorCol(),aFilename.c_str()); } TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement *pElem; pElem = hDoc.FirstChildElement().Element(); if (0 == pElem) NAU_THROW("Not a XML file: %s", aFilename.c_str()); hRoot = TiXmlHandle(pElem); pElem->QueryIntAttribute("numchars",&numChars); if (numChars == 0) NAU_THROW("Zero chars in file: %s", aFilename.c_str()); hRoot = hRoot.FirstChild("characters"); pElem = hRoot.FirstChild("chardata").Element(); if (pElem) { pElem->QueryIntAttribute("hgt",&height); if (pElem) aFont->setFontHeight(height); } int code,width,A,C; float x1,x2,y1,y2; for(; 0 != pElem; pElem = pElem->NextSiblingElement()) { pElem->QueryIntAttribute("char",&code); pElem->QueryIntAttribute("wid",&(width)); pElem->QueryFloatAttribute("X1", &(x1)); pElem->QueryFloatAttribute("X2", &(x2)); pElem->QueryFloatAttribute("Y1", &(y1)); pElem->QueryFloatAttribute("Y2", &(y2)); pElem->QueryIntAttribute("A", &(A)); pElem->QueryIntAttribute("C", &(C)); aFont->addChar(code,width,x1,x2,y1,y2,A,C); } }
std::vector<osg::Vec3f> loadXMLFile(const char * name){ TiXmlDocument * document = new TiXmlDocument(name); int element_counter = 1; ///< counter used to report xml reading errors if(!document->LoadFile()){ std::cerr << "[ReadXML] Loading Error : " << document->ErrorDesc() << std::endl; } std::vector<osg::Vec3f> result; float x,y,z; int reading_result; TiXmlElement * xmlPoint = document->FirstChildElement(); while (xmlPoint){ reading_result = xmlPoint->QueryFloatAttribute("x",&x); if(reading_result == TIXML_WRONG_TYPE){ std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute x is not a float" << std::endl; } else if(reading_result == TIXML_NO_ATTRIBUTE ){ std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute x doesn't exist" << std::endl; } reading_result = xmlPoint->QueryFloatAttribute("y",&y); if(reading_result == TIXML_WRONG_TYPE){ std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute y is not a float" << std::endl; } else if(reading_result == TIXML_NO_ATTRIBUTE ){ std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute y doesn't exist" << std::endl; } reading_result = xmlPoint->QueryFloatAttribute("z",&z); if(reading_result == TIXML_WRONG_TYPE){ std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute z is not a float" << std::endl; } else if(reading_result == TIXML_NO_ATTRIBUTE ){ std::cerr << "[ReadXML] Reading error at element n°"<< element_counter <<": attribute z doesn't exist" << std::endl; } osg::Vec3f vec3Point(x,y,z);// = new std::vector<float>(); /*vec3Point.push_back(x); vec3Point.push_back(y); vec3Point.push_back(z);*/ result.push_back(vec3Point); xmlPoint = xmlPoint->NextSiblingElement(); element_counter++; } return result; }
void StatTracker::Load ( const char* path ) { TiXmlDocument doc; if ( doc.LoadFile ( path ) == false ) { Reset(); return; } TiXmlElement* pRoot = doc.RootElement (); if ( pRoot == nullptr ) return; TiXmlElement* pTime = pRoot->FirstChildElement ( "Time" ); pTime->QueryFloatAttribute ( "Total" , &m_fTimePlayed); pTime->QueryFloatAttribute ( "Build" , &m_fBuildPhaseTime); pTime->QueryFloatAttribute ( "Survival" , &m_fSurvivalTime); TiXmlElement* pDistance = pRoot->FirstChildElement ( "General" ); pDistance->QueryFloatAttribute ( "Walking" , &m_fDistanceWalked); pDistance->Attribute ( "Rounds" , (int *)&m_uRoundsSurvived); pDistance->Attribute ( "RoundSpree" , (int *)&m_uConsecutiveRoundsSurvived); TiXmlElement* pViolence = pRoot->FirstChildElement ( "Violence" ); pViolence->Attribute ( "Kills" , (int *)&m_uTotalKills); pViolence->QueryFloatAttribute ( "Blood" , &m_fBloodSpilled); pViolence->Attribute ( "Grenades" , (int *)&m_uGrenadesThrown); pViolence->Attribute ( "TotalShots" , (int *)&m_uTotalShotsFired); pViolence->Attribute ( "MachineGun" , (int *)&m_uMachineGunBullets); pViolence->Attribute ( "Shotgun" , (int *)&m_uShotgunShells); pViolence->Attribute ( "RPG" , (int *)&m_uRPGRounds); pViolence->Attribute ( "HatTrick" , (int *)&m_uHatTrickShots); TiXmlElement* pExchange = pRoot->FirstChildElement ( "Exchange" ); pExchange->Attribute ( "WallsPlaced" , (int *)&m_uWallsPlaced); pExchange->Attribute ( "WallsPickedUp" , (int *)&m_uWallsPickedUp); pExchange->Attribute ( "WindowsPlaced" , (int *)&m_uWindowsPlaced); pExchange->Attribute ( "WindowsPickedUp" , (int *)&m_uWindowsPickedUp); pExchange->Attribute ( "TowersBought" , (int *)&m_uTowersBought); pExchange->Attribute ( "TowersSold" , (int *)&m_uTowersSold); pExchange->Attribute ( "TrapsBought" , (int *)&m_uTrapsBought); pExchange->Attribute ( "TrapsSold" , (int *)&m_uTrapsSold); pExchange->Attribute ( "Money" , (int *)&m_uMoneySpent); }
bool UIObject::loadFromXML(TiXmlElement *xmlUIObjNode) { TiXmlHandle hXmlNode(xmlUIObjNode); xmlUIObjNode->QueryStringAttribute("name",&m_name); TiXmlElement * basicNode = hXmlNode.FirstChild("basic").Element(); if(basicNode==0) { DBG("engineDbg_UI","Fail to load UIObject, missing basic node!"); return false; } basicNode->QueryFloatAttribute("x", &m_pos.X); // If this fails, original value is left as-is basicNode->QueryFloatAttribute("y", &m_pos.Y); f32 rl, rt, rw, rh; basicNode->QueryFloatAttribute("rl", &rl); basicNode->QueryFloatAttribute("rt", &rt); basicNode->QueryFloatAttribute("rw", &rw); basicNode->QueryFloatAttribute("rh", &rh); m_localRect.set(rl, rt, rw, rh); basicNode->QueryFloatAttribute("scaleX", &m_scaleX); basicNode->QueryFloatAttribute("scaleY", &m_scaleY); basicNode->QueryFloatAttribute("rotation", &m_rotation); basicNode->QueryFloatAttribute("alpha", &m_alpha); basicNode->QueryFloatAttribute("r", &m_r); basicNode->QueryFloatAttribute("g", &m_g); basicNode->QueryFloatAttribute("b", &m_b); return true; }
void YafFile::processCameras(TiXmlElement* camerasElement) { char* rootId = (char*)camerasElement->Attribute("initial"); char* id; string testRoot=rootId; TiXmlElement* orthoElement = camerasElement->FirstChildElement("ortho"); TiXmlElement* perspectiveElement = camerasElement->FirstChildElement("perspective"); CGFcamera* cam; float near, far, left, right, top, bottom; unsigned int i = 0; while(orthoElement != NULL) { orthoElement->QueryFloatAttribute("near", &near); orthoElement->QueryFloatAttribute("far", &far); orthoElement->QueryFloatAttribute("left", &left); orthoElement->QueryFloatAttribute("right", &right); orthoElement->QueryFloatAttribute("top", &top); orthoElement->QueryFloatAttribute("bottom", &bottom); id=(char*)orthoElement->Attribute("id"); cam = new OrthoCamera(near, far, left, right, top, bottom,id==rootId); sceneCameras.push_back(make_pair(id,cam)); orthoElement = orthoElement->NextSiblingElement("ortho"); string test = id; if(test==testRoot) { camera=i; } else i++; } while(perspectiveElement != NULL) { float position[3],target[3],angle; perspectiveElement->QueryFloatAttribute("near", &near); perspectiveElement->QueryFloatAttribute("far", &far); perspectiveElement->QueryFloatAttribute("angle", &angle); read3Float("pos", perspectiveElement, position[0], position[1], position[2]); read3Float("target", perspectiveElement, target[0], target[1], target[2]); id=(char*)perspectiveElement->Attribute("id"); cam = new PerspectiveCamera(id==rootId,near, far, angle, position[0], position[1], position[2], target[0], target[1], target[2]); sceneCameras.push_back(make_pair(id,cam)); string test = id; if(test==testRoot) { camera=i; } else i++; perspectiveElement = perspectiveElement->NextSiblingElement("perspective"); } }
void Poof::init(TiXmlElement* poofElement) { int totalPoofFrames = 0; TiXmlElement* poofSprite = poofElement->FirstChildElement()->FirstChildElement(); while (poofSprite != NULL) { poofSprite = poofSprite->NextSiblingElement(); totalPoofFrames++; } poofData.numSprites = totalPoofFrames; poofData.spriteData = (SpriteStateData *)malloc(poofData.numSprites * sizeof(SpriteStateData)); int j = 0; poofSprite = poofElement->FirstChildElement()->FirstChildElement(); while (poofSprite != NULL) { poofData.spriteData[j].spriteState = poofSprite->Attribute("state"); poofSprite->QueryFloatAttribute("xPosLeft", &poofData.spriteData[j].uLeft); poofSprite->QueryFloatAttribute("xPosRight", &poofData.spriteData[j].uRight); poofSprite->QueryFloatAttribute("yPosTop", &poofData.spriteData[j].vTop); poofSprite->QueryFloatAttribute("yPosBottom", &poofData.spriteData[j].vBottom); poofSprite = poofSprite->NextSiblingElement(); j++; } float imageWidth, imageHeight; poofElement->QueryFloatAttribute("imageWidth", &imageWidth); poofElement->QueryFloatAttribute("imageHeight", &imageHeight); poofRenderer = new Renderer(); poofRenderer->init(poofElement->Attribute("src"), totalPoofFrames, imageWidth, imageHeight); int k = 0; for (j = 0; j < poofData.numSprites; j++) { poofRenderer->setUTextureLeft(k, poofData.spriteData[j].uLeft); poofRenderer->setUTextureRight(k, poofData.spriteData[j].uRight); poofRenderer->setVTextureTop(k, poofData.spriteData[j].vTop); poofRenderer->setVTextureBottom(k, poofData.spriteData[j].vBottom); poofData.spriteData[j].rendererIndex = k; k++; } }
void EntityLoader::loadChildDefinition(EntityDefinitionProto& entity, const TiXmlElement& xmlchild) { std::unique_ptr<ChildDefinitionProto> pchild(new ChildDefinitionProto()); const char* pid = xmlchild.Attribute("id"); pchild->mID = String::fromUtf8(pid); const char* pref = xmlchild.Attribute("ref"); if ( pref != NULL ) { pchild->mRefType = ChildDefinitionProto::eLocalReference; pchild->mRef = String::fromUtf8(pref); } else { const char* pfile = xmlchild.Attribute("file"); if ( pfile == NULL ) { throw std::runtime_error("Should have a file reference!"); } pchild->mRefType = ChildDefinitionProto::eFileReference; pchild->mRef = String::fromUtf8(pfile); } float offsetx, offsety; xmlchild.QueryFloatAttribute("offsetx", &offsetx); xmlchild.QueryFloatAttribute("offsety", &offsety); pchild->mOffset = Vector(offsetx, offsety); entity.mChildren.push_back(pchild.release()); }
void CTexturePreviewDialog::LoadInfoFromFile(wxString& fileName) { wxString path, simpleName, ext; wxFileName::SplitPath(fileName, &path, &simpleName, &ext); TiXmlDocument doc; doc.LoadFile(fileName); TiXmlElement *root = doc.RootElement(); BEATS_ASSERT(root && strcmp(root->Value(), "Imageset") == 0); const char *textureFileName = root->Attribute("Imagefile"); BEATS_ASSERT(textureFileName != NULL); path += _T("\\"); wxBitmap texture; { //suppress the warning from loading png wxLogNull logNo; texture.LoadFile(path + textureFileName, wxBITMAP_TYPE_PNG); } for(TiXmlElement *elemImage = root->FirstChildElement("Image"); elemImage != nullptr; elemImage = elemImage->NextSiblingElement("Image")) { const char *textureName = elemImage->Attribute("Name"); BEATS_ASSERT(textureName); kmVec2 point; kmVec2Fill(&point, 0.f, 0.f); kmVec2 size; kmVec2Fill(&size, 0.f, 0.f); elemImage->QueryFloatAttribute("XPos", &point.x); elemImage->QueryFloatAttribute("YPos", &point.y); elemImage->QueryFloatAttribute("Width", &size.x); elemImage->QueryFloatAttribute("Height", &size.y); wxRect rect(point.x, point.y, size.x, size.y); wxIcon icon; icon.CopyFromBitmap(texture.GetSubBitmap(rect)); m_pTexturePreviewIconList->Add(icon); TexturePreviewInfo info; info.fileName = simpleName + _T(".") + ext; info.textureName = textureName; info.with.Printf(_T("%d"), rect.GetWidth()); info.height.Printf(_T("%d"), rect.GetHeight()); m_texturePreviewInfoList.push_back(info); } BEATS_ASSERT(m_pTexturePreviewIconList->GetImageCount() == (int)m_texturePreviewInfoList.size()); }
void ETHEntityProperties::ReadColorPropertyFromXmlElement( TiXmlElement *pElement, const str_type::string& name, Vector3& value) { TiXmlNode *pNode = pElement->FirstChild(name); if (pNode) { TiXmlElement *pIter = pNode->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("r"), &value.x); pIter->QueryFloatAttribute(GS_L("g"), &value.y); pIter->QueryFloatAttribute(GS_L("b"), &value.z); } } }
void readVector3Keys(TiXmlElement * node, MKey * keys) { TiXmlElement * kNode = node->FirstChildElement("k"); for(kNode; kNode; kNode=kNode->NextSiblingElement("k")) { int t = 0; MVector3 * vector3 = keys->createVector3Data(); kNode->QueryIntAttribute("t", &t); kNode->QueryFloatAttribute("x", &vector3->x); kNode->QueryFloatAttribute("y", &vector3->y); kNode->QueryFloatAttribute("z", &vector3->z); keys->setT(t); keys++; } }
float ParticleComponentLoader::loadValue(const TiXmlElement& xmlElement, const char* pname) { float result = 0.0f; if ( xmlElement.QueryFloatAttribute(pname, &result) == TIXML_WRONG_TYPE ) { throw new std::runtime_error("Invalid type!"); } return result; }
void LevelManager::load(const std::string& name) { while(!myEntityModels.empty()) myEntityModels.pop(); TiXmlDocument document(name.c_str()); if(!document.LoadFile()) throw std::invalid_argument(name + ": couldn't load XML world: " + document.ErrorDesc()); // Get background element TiXmlHandle handle(&document); TiXmlElement* bgElement = handle.FirstChildElement().FirstChildElement("background").ToElement(); float speed; bgElement->QueryFloatAttribute("speed", &speed); myBackground = std::shared_ptr<Background>(new Background(*imageManager().get(bgElement->Attribute("image")), speed)); // Get enemy element (planet or asteroid) TiXmlElement* element = handle.FirstChildElement().FirstChildElement("enemies").FirstChild().ToElement(); // Get all elements in the file and add it to the priority queue while(element) { float coordinate = 0, speed = 0, angle = 0, rotation = 0, time = 0; element->QueryFloatAttribute("xCoordinate", &coordinate); element->QueryFloatAttribute("speed", &speed); element->QueryFloatAttribute("angle", &angle); element->QueryFloatAttribute("time", &time); if(element->Attribute("rotationSpeed")) element->QueryFloatAttribute("rotationSpeed", &rotation); // Load the image in memory if it is still not loaded imageManager().get(element->Attribute("image")); // Add the entity to the priority queue myEntityModels.push(EntityModel(element->Value(), element->Attribute("image"), coordinate, speed, angle, rotation, time)); element = element->NextSiblingElement(); } }
bool ETH_COLLISION_BOX::ReadFromXMLFile(TiXmlElement *pElement) { TiXmlElement *pIter; pIter = pElement->FirstChild(GS_L("Position"))->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("x"), &pos.x); pIter->QueryFloatAttribute(GS_L("y"), &pos.y); pIter->QueryFloatAttribute(GS_L("z"), &pos.z); } pIter = pElement->FirstChild(GS_L("Size"))->ToElement(); if (pIter) { pIter->QueryFloatAttribute(GS_L("x"), &size.x); pIter->QueryFloatAttribute(GS_L("y"), &size.y); pIter->QueryFloatAttribute(GS_L("z"), &size.z); } return true; }
void XMLScene::processAnimations(TiXmlElement* animationElement){ TiXmlElement* element = animationElement->FirstChildElement("animation"); while(element!=NULL) { string id = element->Attribute("id"),type=element->Attribute("type"); float span; element->QueryFloatAttribute("span",&span); vector<Point> points; if(type == "linear"){ Point p; TiXmlElement* child = element->FirstChildElement("controlpoint"); while(child!=NULL) { child->QueryFloatAttribute("xx", &p.x); child->QueryFloatAttribute("yy",&p.y); child->QueryFloatAttribute("zz",&p.z); points.push_back(p); child=child->NextSiblingElement(); } Animation* animation = new Animation(span,type,points); Animations[id]=animation; element=element->NextSiblingElement(); } else{ float center[3], radius, startang, rotang; read3Float("center", element, center[0], center[1], center[2]); element->QueryFloatAttribute("radius",&radius); element->QueryFloatAttribute("startang",&startang); element->QueryFloatAttribute("rotang",&rotang); Animation* animation = new Animation(span,type,center[0],center[1],center[2],radius,startang,rotang); Animations[id]=animation; element=element->NextSiblingElement(); } } }
float getMeshUnitRescale(const std::string& resource_path) { static std::map<std::string, float> rescale_cache; // Try to read unit to meter conversion ratio from mesh. Only valid in Collada XML formats. TiXmlDocument xmlDoc; float unit_scale(1.0); resource_retriever::Retriever retriever; resource_retriever::MemoryResource res; try { res = retriever.get(resource_path); } catch (resource_retriever::Exception& e) { ROS_ERROR("%s", e.what()); return unit_scale; } if (res.size == 0) { return unit_scale; } // Use the resource retriever to get the data. const char * data = reinterpret_cast<const char * > (res.data.get()); xmlDoc.Parse(data); // Find the appropriate element if it exists if(!xmlDoc.Error()) { TiXmlElement * colladaXml = xmlDoc.FirstChildElement("COLLADA"); if(colladaXml) { TiXmlElement *assetXml = colladaXml->FirstChildElement("asset"); if(assetXml) { TiXmlElement *unitXml = assetXml->FirstChildElement("unit"); if (unitXml && unitXml->Attribute("meter")) { // Failing to convert leaves unit_scale as the default. if(unitXml->QueryFloatAttribute("meter", &unit_scale) != 0) ROS_WARN_STREAM("getMeshUnitRescale::Failed to convert unit element meter attribute to determine scaling. unit element: " << *unitXml); } } } } return unit_scale; }