//---------------------------------------------------------------------------- // Checks if a key is on the tree //---------------------------------------------------------------------------- bool CXMLTreeNode::ExistsKey (const char* _pszKey) { assert(_pszKey); CXMLTreeNode TreeFound = GetSubTree(_pszKey); return TreeFound.Exists(); }
void CAnimatedMeshManager::Load(const std::string &Filename) { CXMLTreeNode l_XML; if (l_XML.LoadFile(Filename.c_str())) { CXMLTreeNode animatedModels = l_XML["animated_models"]; if (animatedModels.Exists()) { for (int i = 0; i < animatedModels.GetNumChildren(); ++i) { CXMLTreeNode animated_model = animatedModels(i); if (animated_model.GetName() == std::string("animated_model")) { CXMLTreeNode &animModel = animated_model; auto inst = new CAnimatedMesh(animModel); add(inst->getName(), inst); } } } } }
bool CTriggerManager::LoadXML( const std::string& FileName ) { mConfigPath = FileName; CXMLTreeNode newFile; if ( !newFile.LoadFile( FileName.c_str() ) ) { LOG_ERROR_APPLICATION( "CTriggerManager::LoadXML=> ERROR loading the file %s.\n", FileName.c_str() ); return false; } CXMLTreeNode m = newFile["triggers"]; if ( m.Exists() ) { int count = m.GetNumChildren(); for ( int i = 0; i < count; ++i ) { const std::string l_TagName = m( i ).GetName(); if ( l_TagName == "trigger" ) { CTrigger* l_Trigger = new CTrigger( m( i ) ); if(!AddResource(l_Trigger->GetName(), l_Trigger)) { CHECKED_DELETE(l_Trigger); } } } } return true; }
/// <summary> /// Carga el .xml de triggers. /// </summary> ///<param name="FileName">Ubicación del archivo xml.</param> bool CTriggerManager::Load(const std::string &FileName) { m_bIsOk = true; m_FileName = FileName; CXMLTreeNode filexml; if (!filexml.LoadFile(FileName.c_str())) { //Guardar el mensaje de error en el LOGGER LOGGER->AddNewLog(ELL_ERROR, "CTriggerManager::Load ---Error al cargar el XML---"); m_bIsOk = false; } else { CXMLTreeNode triggers = filexml["triggers"]; int numNodes = triggers.GetNumChildren(); if (triggers.Exists()) { //<triggers> //<trigger name="Trigger_EntradaPuerta" entity="character" position="13.4664 0.0 -3.93624" max="-0.600954 4.70389 -1.79946" //min="0.600954 0.0 1.79946" active="true" onEnter="testEnter" onLeave="testLeave" rotation="" size="1.0"/> //</triggers> CTrigger* l_Trigger; for (int i = 0; i < numNodes; ++i) { if (!triggers(i).IsComment()) { //crea trigger info l_Trigger = new CTrigger(); l_Trigger->Init(); l_Trigger->SetName(triggers(i).GetPszProperty("name", "")); l_Trigger->SetEntity(triggers(i).GetPszProperty("entity", "")); l_Trigger->SetPosition(triggers(i).GetVect3fProperty("position", Vect3f(0.0f,0.0f,0.0f))); l_Trigger->SetMax(triggers(i).GetVect3fProperty("max", Vect3f(0.0f,0.0f,0.0f))); l_Trigger->SetMin(triggers(i).GetVect3fProperty("min", Vect3f(0.0f,0.0f,0.0f))); l_Trigger->SetActive(triggers(i).GetBoolProperty("active", false)); l_Trigger->SetTriggerActive(triggers(i).GetBoolProperty("active", false)); l_Trigger->SetOnEnterCode(triggers(i).GetPszProperty("onEnter", "")); l_Trigger->SetOnLeaveCode(triggers(i).GetPszProperty("onLeave", "")); l_Trigger->SetRotationX(triggers(i).GetFloatProperty("rotationX")); l_Trigger->SetRotationY(triggers(i).GetFloatProperty("rotationY")); l_Trigger->SetRotationZ(triggers(i).GetFloatProperty("rotationZ")); l_Trigger->SetSize(triggers(i).GetVect3fProperty("size", Vect3f(0.0f,0.0f,0.0f))); l_Trigger->SetDimensions(triggers(i).GetVect3fProperty("size", Vect3f(0.0f,0.0f,0.0f))); GeneraTrigger(l_Trigger->GetName(), l_Trigger, false); m_vTriggers.push_back(l_Trigger); } } } else { m_bIsOk = false; } } return m_bIsOk; }
void CLanguageManager::LoadXML (const std::string& pathFile) { CXMLTreeNode parser; if (!parser.LoadFile(pathFile.c_str())) { std::string msg_error = "LanguageManager::LoadXML->Error al intentar leer el archivo de lenguaje: " + pathFile; LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); throw CException(__FILE__, __LINE__, msg_error); } /*<Language id="english"> <literal id="xfiles" font="X-Files" color="0.5 0.5 0.5 0.5" value="Hi World"/> <literal id="xfiles" font="X-Files" color="0.1 0.1 0.1 0.8" value="Exit"/> </Language>*/ LOGGER->AddNewLog(ELL_INFORMATION, "LanguageManager::LoadXML-> Parseando fichero de lenguaje: %s", pathFile.c_str()); CXMLTreeNode m = parser["Language"]; std::string id_language = m.GetPszProperty("id"); TLanguage language; if (m.Exists()) { int count = m.GetNumChildren(); for (int i = 0; i < count; ++i) { //for each literal: SLiteral l_literal; std::string id = m(i).GetPszProperty("id"); l_literal.m_sFontId = m(i).GetPszProperty("font"); Vect4f vecColor = m(i).GetVect4fProperty("color", Vect4f(0.f,0.f,0.f,0.f)); l_literal.m_value = m(i).GetPszISOProperty("value", "nothing"); l_literal.m_cColor = CColor(vecColor.x, vecColor.y, vecColor.z, vecColor.w); language.insert(std::pair<std::string,SLiteral>(id, l_literal)); LOGGER->AddNewLog(ELL_INFORMATION, "LanguageManager::LoadXML-> Añadido literal(%s,%s,[%f,%f,%f,%f],%s)", id.c_str(), l_literal.m_sFontId.c_str(),vecColor.x,vecColor.y,vecColor.z,vecColor.w, l_literal.m_value.c_str()); } } if (m_Languages.find(id_language) != m_Languages.end()) { //Ya está registrado el identificador id_language LOGGER->AddNewLog(ELL_WARNING, "LanguageManager::LoadXML-> EYa se ha registrado un language con identificador %s", id_language.c_str()); } else { m_Languages.insert(std::pair<std::string, TLanguage>(id_language, language)); } }
bool CSceneRendererStep::InitMaterialEffects(CXMLTreeNode& _treeMaterialEffects) { if(!_treeMaterialEffects.Exists()) return false; m_szParticleEffect = _treeMaterialEffects.GetPszISOProperty("particle_effect","",false); if(_treeMaterialEffects.ExistsProperty("static_mesh_effect") && _treeMaterialEffects.ExistsProperty("animated_model_effect")) { m_szStaticMeshEffect = _treeMaterialEffects.GetPszISOProperty("static_mesh_effect","",false); m_szAnimatedModelEffect = _treeMaterialEffects.GetPszISOProperty("animated_model_effect","",false); m_bUseMap = false; }else{ m_bUseMap = true; int l_iNumRenderTargets = _treeMaterialEffects.GetNumChildren(); for(int l_iIndex = 0; l_iIndex < l_iNumRenderTargets;l_iIndex++) { CXMLTreeNode l_pMaterialEffect = _treeMaterialEffects(l_iIndex); if(string(l_pMaterialEffect.GetName()) == "material_effect") { int l_iMaterialType = l_pMaterialEffect.GetIntProperty("material_type",0,false); string l_szEffectName = l_pMaterialEffect.GetPszISOProperty("effect","",false); if(l_szEffectName != "") { m_mapMaterialEffects[l_iMaterialType] = l_szEffectName; }else{ LOGGER->AddNewLog(ELL_WARNING,"CSceneRendererStep::InitMaterialEffects material type %d amb effecte null",l_iMaterialType); } }else if(!l_pMaterialEffect.IsComment()) { LOGGER->AddNewLog(ELL_WARNING,"CSceneRendererStep::InitMaterialEffects element no reconegut %s",l_pMaterialEffect.GetName()); } } } return true; }
//---------------------------------------------------------------------------- // Constructor //---------------------------------------------------------------------------- CSceneEffect::CSceneEffect(CXMLTreeNode &atts):CActive(),CNamed() { CNamed::Init();//inicia CNamed SetName(atts.GetPszProperty("name")); SetActive(atts.GetBoolProperty("active")); CXMLTreeNode texture = atts["texture"]; if (texture.Exists()) { if (!texture.IsComment()) { int32 numNodes = atts.GetNumChildren(); for(int i=0; i < numNodes; i++) { int l_iStageId = atts(i).GetIntProperty("stage_id"); std::string l_sFile = atts(i).GetPszProperty("file"); bool l_bLoadFile = atts(i).GetBoolProperty("load_file"); CTexture * l_Texture = NULL; if(l_bLoadFile) { l_Texture=CORE->GetTextureManager()->GetTexture(l_sFile); if (l_Texture==NULL) { //Guardar el mensaje de warning en el LOGGER std::string msg_warning = "SceneEffect::Constructor->Error al intentar leer el archivo de efectos: " + l_sFile; LOGGER->AddNewLog(ELL_WARNING, msg_warning.c_str()); } } else { //la creas dinámicamente la textura l_Texture=CORE->GetTextureManager()->GetResource(l_sFile); } if(l_Texture!=NULL) AddStageTexture(l_iStageId, l_Texture); }//end for } } }
bool CGUIWindow::LoadXML( const std::string &xmlGuiFile, const Vect2i& screenResolution) { //Read the xml gui file LOGGER->AddNewLog(ELL_INFORMATION, "CGUIWindow:: Iniciando el parseo del fichero %s", xmlGuiFile.c_str()); bool isOK = false; CXMLTreeNode newFile; if (!newFile.LoadFile(xmlGuiFile.c_str())) { LOGGER->AddNewLog(ELL_ERROR, "CGUIWindow:: No se ha podido leer correctamente el fichero ->%s", xmlGuiFile.c_str()); isOK = false; } else { CTextureManager* textureM = CORE->GetTextureManager(); CXMLTreeNode windows = newFile["Windows"]; m_sLuaCode_OnLoadWindows = windows.GetPszProperty("OnLoadWindows"); m_sLuaCode_OnSaveWindows = windows.GetPszProperty("OnSaveWindows"); m_sLuaCode_OnUpdateWindows = windows.GetPszProperty("OnUpdateWindows"); if (windows.Exists()) { int count = windows.GetNumChildren(); for (int i = 0; i < count; ++i) { CXMLTreeNode pNewNode = windows(i); //Para cada guielement leemos su informacion comun--> std::string name = pNewNode.GetPszProperty("name", "defaultGuiElement"); float posx = pNewNode.GetFloatProperty("posx", 0.f); float posy = pNewNode.GetFloatProperty("posy", 0.f); float w = pNewNode.GetFloatProperty("width", 50.f); float h = pNewNode.GetFloatProperty("height", 50.f); bool visible = pNewNode.GetBoolProperty("visible", true); bool activated = pNewNode.GetBoolProperty("active", true); std::string tagName = pNewNode.GetName(); if (tagName.compare("Button")==0) { CButton* newButton = NULL; LoadButton(&newButton,pNewNode,screenResolution, textureM); AddGuiElement(newButton); } else if (tagName.compare("CheckButton")==0) { CCheckButton* new_checkButton = NULL; LoadCheckButton(&new_checkButton,pNewNode,screenResolution, textureM); AddGuiElement(new_checkButton); } else if (tagName.compare("Slider")==0) { CSlider* new_slider = NULL; LoadSlider(&new_slider,pNewNode,screenResolution, textureM); AddGuiElement(new_slider); } else if (tagName.compare("DialogBox")==0) { CDialogBox* new_dialogBox = NULL; LoadDialogBox(&new_dialogBox,pNewNode,screenResolution, textureM); AddGuiElement(new_dialogBox); } else if (tagName.compare("EditableTextBox")==0) { CEditableTextBox* new_editableTextBox = NULL; LoadEditableTextBox(&new_editableTextBox,pNewNode,screenResolution, textureM); AddGuiElement(new_editableTextBox); } else if (tagName.compare("RadioBox")==0) { CRadioBox* new_radioBox = NULL; LoadRadioBox(&new_radioBox,pNewNode,screenResolution, textureM); AddGuiElement(new_radioBox); } else if (tagName.compare("Image")==0) { CImage* new_image = NULL; _LoadImage(&new_image,pNewNode,screenResolution, textureM); AddGuiElement(new_image); } else if (tagName.compare("AnimatedImage")==0) { CAnimatedImage* new_image = NULL; LoadAnimatedImage(&new_image,pNewNode,screenResolution, textureM); AddGuiElement(new_image); } else if (tagName.compare("ProgressBar")==0) { CProgressBar* new_progressBar = NULL; LoadProgressBar(&new_progressBar,pNewNode,screenResolution, textureM); AddGuiElement(new_progressBar); } else if (tagName.compare("StaticText")==0) { CStaticText* new_staticText = NULL; LoadStaticText(&new_staticText,pNewNode,screenResolution, textureM); AddGuiElement(new_staticText); } else if (tagName.compare("KeyBoard_Back")==0) { //<KeyBoard_Back input="DIK_A" OnKeyDown="blablaLua"/> m_sLuaCode_OnKeyDown = pNewNode.GetPszProperty("OnKeyDown", ""); m_uInputKeyDown = pNewNode.GetIntProperty("input", 0); } else { //Warning LOGGER->AddNewLog(ELL_WARNING, "GUIWindow:: No se reconoce el tag %s del fichero %s", tagName.c_str(), xmlGuiFile.c_str()); } } isOK = true; } else { LOGGER->AddNewLog(ELL_ERROR, "GUIWindow:: No se ha podido leer el tag Windows del fichero ->%s", xmlGuiFile.c_str()); isOK = false; } }//END else de if (!newFile.LoadFile(xmlGuiFile.c_str())) if (!isOK) { LOGGER->AddNewLog(ELL_ERROR, "GUIWindow:: No se ha podido leer correctamente el fichero -->%s", xmlGuiFile.c_str()); isOK = false; } else { LOGGER->AddNewLog(ELL_INFORMATION, "GUIWindow:: Finalizado correctamente el parseo el fichero %s", xmlGuiFile.c_str()); } return isOK; }
/// <summary> /// Carga el .xml de sonido. /// </summary> ///<param name="&FileName">Ubicación del archivo xml.</param> bool CSoundManager::Load(const std::string &FileName) { SSoundData soundData; bool l_bIsOk = true; m_FileName = FileName; CXMLTreeNode filexml; if (!filexml.LoadFile(m_FileName.c_str())) { // Guarda mensaje de error en el log std::string msg_error = "CSoundManager::Load->Error al intentar abrir el archivo: "; msg_error.append(m_FileName.c_str()); LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); throw CException(__FILE__, __LINE__, msg_error); l_bIsOk = false; } else { CXMLTreeNode cores = filexml["sounds"]; if (cores.Exists()) { m_iMaxChannels = cores.GetIntProperty("maxChannels"); // Asignando número de canales de acuerdo al parametro extraído del .xml m_Channels.resize(m_iMaxChannels); if (!cores.IsComment()) { int32 numNodes = cores.GetNumChildren(); for(int i=0; i < numNodes; i++) { if (!cores(i).IsComment()) { // Recibe parametros de los sonidos std::string l_sCoreName = cores(i).GetPszProperty("name"); std::string l_sCoreType = cores(i).GetPszProperty("type"); std::string l_sCorePath = cores(i).GetPszProperty("path"); bool l_bCoreLoop = cores(i).GetBoolProperty("loop"); bool l_bCore3D = cores(i).GetBoolProperty("threeDimensional"); std::string l_sCorePriority = cores(i).GetPszProperty("priority"); std::string l_sCoreEffect = cores(i).GetPszProperty("effect"); float l_fCoreVolume = cores(i).GetFloatProperty("volume"); int iMask = 0; int PathLastCharacters = l_sCorePath.length() - 3; std::string substring = l_sCorePath.substr(PathLastCharacters,3); if (substring != "wav") { // Convert the sample (MP3/MP2/MP1 only) to mono, if it's not already. iMask = BASS_SAMPLE_MONO; } // Asigna propiedad de loop if (l_bCoreLoop) { iMask |= BASS_SAMPLE_LOOP; soundData.m_Loop = true; } else { soundData.m_Loop = false; } // Asigna propiedad 3D y posición 3D if (l_bCore3D) { iMask |= BASS_SAMPLE_3D; soundData.m_ThreeDimensional = true; soundData.m_Position = cores(i).GetVect3fProperty("position", Vect3f(0.0, 0.0, 0.0)); } else { soundData.m_ThreeDimensional = false; } if (l_sCoreType == "sample") { // Genera identificador para sonido soundData.m_type = SAMPLER; soundData.m_Id = BASS_SampleLoad(false, l_sCorePath.c_str(), 0, 0, m_iMaxChannels, iMask); } else { // Genera identificador para música soundData.m_Id = BASS_StreamCreateFile(false, l_sCorePath.c_str(), 0, 0, iMask); soundData.m_type = BGM; } // Añadiendo volumen soundData.m_Volume = l_fCoreVolume; // Añade sonido al mapa m_Resources[l_sCoreName] = soundData; } } } } else { l_bIsOk = false; } } return l_bIsOk; }
bool CSpirit::LoadXML(std::string fileName) { m_pFileName = fileName; CXMLTreeNode header; if(!header.LoadFile(fileName.c_str())) { //Guardar el mensaje de error en el LOGGER std::string msg_error = " CSpirit::Load->Error al intentar abrir el archivo: "; msg_error.append(fileName.c_str()); LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); //throw CException(__FILE__, __LINE__, msg_error); return false; } else { //<spirit> //<parameters posini="3 2 -3" apertura="0.2" speedup="3.3" speeddown="0.5" heightflymax="3.0" heightflymin="1.9" //speedslow="1.0" speedfast="1.5" distnear="4.0" distfar="6.0" //timeidle="5.0" timechase="5.0" //numlaps="2" speedcontento="4.0" ///> //</spirit> //solo un spirit**** CXMLTreeNode tag = header["spirit"]; if(tag.Exists()) { if (!tag.IsComment()) { CXMLTreeNode params = tag(0)["parameters"]; if (params.Exists()) { m_V3PosIni = params.GetVect3fProperty("posini", Vect3f(3.0f, 1.5f, -3.8f)); // m_V3Pos = params.GetVect3fProperty("posini", Vect3f(3.0f, 1.5f, -3.8f)); //quitado para dejar estatico el espiritu m_fSpeed_YUp = params.GetFloatProperty("speedup",3.3f); m_fSpeed_YDown = params.GetFloatProperty("speeddown",0.5f); m_fPosYMax = params.GetFloatProperty("heightflymax",3.f); m_fPosYMin = params.GetFloatProperty("heightflymin",1.9f); m_fAperturaEmisor = params.GetFloatProperty("apertura",0.2f); m_fSpeedMax = params.GetFloatProperty("speedfast",1.5f); m_fSpeedMin = params.GetFloatProperty("speedslow",1.f); m_fDistFar = params.GetFloatProperty("distfar",6.f); m_fDistNear = params.GetFloatProperty("distnear",10.f); m_fDelayTimeIdle = params.GetFloatProperty("timeidle",5.f); m_fDelayTimeChase = params.GetFloatProperty("timechase",5.f); m_uiNumeroVueltasContento = params.GetIntProperty("numlaps",1); m_fSpeedRotationContento = params.GetFloatProperty("speedcontento",3.f); m_pLight = CORE->GetLigthManager()->GetResource(params.GetPszProperty("light", "")); } } } else { //Guardar el mensaje de error en el LOGGER std::string msg_error = " CSpirit::Load->Parametros mal configurados "; msg_error.append(fileName.c_str()); LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); //throw CException(__FILE__, __LINE__, msg_error); return false; } } return true; }