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; }
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); } } } } }
CDrawQuadRendererCommand::CDrawQuadRendererCommand(CXMLTreeNode &atts) : CStagedTexturedRendererCommand(atts) { int l_count_textures = atts.GetNumChildren(); for (int i=0; i<l_count_textures; ++i) { int l_StageId = atts(i).GetIntProperty("stage_id", 0); std::string l_File = atts(i).GetPszProperty("file",""); CTexture* l_Texture = CORE->GetTextureManager()->GetTexture(l_File); if (l_Texture != NULL) { CStagedTexturedRendererCommand::AddStageTexture(l_StageId, l_Texture); } } bool l_TextureWidhtAsFrameBuffer = atts.GetBoolProperty("texture_width_as_frame_buffer", true); uint32 w,h; if (l_TextureWidhtAsFrameBuffer) { CORE->GetRenderManager()->GetWidthAndHeight(w, h); } else { w = atts.GetIntProperty("width", 0); h = atts.GetIntProperty("height", 0); } m_Rect.top=m_Rect.left=(long)0.0; m_Rect.right=w-1; m_Rect.bottom=h-1; }
CBillboardAnimation::CBillboardAnimation ( CXMLTreeNode &_Node ) : m_fTimePerImage ( 0.f ) , m_fCurrentTime ( 0.f ) , m_uiImage ( 0 ) , m_vColor ( Vect4f(0.f,0.f,0.f,0.f) ) , m_fSize ( 0.f ) , m_uiNumTextures ( 0 ) , m_bLoop ( false ) { m_Name = _Node.GetPszProperty ( "name", "" ); m_vColor = _Node.GetVect4fProperty( "color", Vect4f(0.f,0.f,0.f,0.f) ); m_fSize = _Node.GetFloatProperty("size", 1.f); m_fTimePerImage = _Node.GetFloatProperty("timePerImage", 1.f); m_bLoop = _Node.GetBoolProperty("loop", false); uint16 l_TotalAnimationNodes = _Node.GetNumChildren (); for ( uint16 i = 0; i < l_TotalAnimationNodes; ++i ) { std::string l_Node = _Node(i).GetName(); if ( l_Node == "Texture" ) { std::string l_TextureName = _Node(i).GetPszProperty("file", ""); CTexture *l_Tex = CORE->GetTextureManager()->GetTexture( l_TextureName ); m_vTextures.push_back( l_Tex ); } } m_uiNumTextures = m_vTextures.size(); }
/// <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)); } }
CLightProbe::CLightProbe( const CXMLTreeNode& aXMLNode ) { for ( int i = 0, l_NumChilds = aXMLNode.GetNumChildren(); i < l_NumChilds; ++i ) { CXMLTreeNode& l_CurrentNode = aXMLNode( i ); std::string lTagName( l_CurrentNode.GetName() ); if (lTagName == "center") mPosition = l_CurrentNode.GetAttribute<Math::Vect3f>( "pos", Math::Vect3f(0.0f) ); if (lTagName == "vertexs") { for ( int j = 0, l_NumVertexs = l_CurrentNode.GetNumChildren(); j < l_NumVertexs; ++j ) { CXMLTreeNode l_VertexNode = l_CurrentNode( j ); std::string lVertexTag( l_VertexNode.GetName() ); if (lVertexTag == "vertex") { Math::Vect3f lPos( l_VertexNode.GetAttribute<Math::Vect3f>( "pos", Math::Vect3f(0.0f) )); Math::Vect2f lUV( l_VertexNode.GetAttribute<Math::Vect2f>( "uv", Math::Vect2f(0.0f) )); Math::Vect3f lDir( lPos - mPosition ); lDir.Normalize(); CLightProbeVertex* v = new CLightProbeVertex(lPos, lUV); std::string lKey( "" ); if (lDir.x > 0.9f) lKey = "x"; if (lDir.x < -0.9f) lKey = "-x"; if (lDir.y > 0.9f) lKey = "y"; if (lDir.y < -0.9f) lKey = "-y"; if (lDir.z > 0.9f) lKey = "z"; if (lDir.z < -0.9f) lKey = "-z"; ASSERT(lKey != "", "LightProbe incorrect.") mVertexs[lKey] = v; } } } } }
CMaterial::CMaterial(CXMLTreeNode &TreeNode) : CNamed(TreeNode) { std::string l_EffectTechnique = TreeNode.GetPszProperty("effect_technique"); m_EffectTechnique = CEngine::GetSingletonPtr()->GetEffectManager()->GetResource(l_EffectTechnique); if (l_EffectTechnique == "diffuse_technique") { for (int i = 0; i < TreeNode.GetNumChildren(); ++i) { CXMLTreeNode l_Texture = TreeNode(i); CTexture * Texture = new CTexture(); Texture->Load(l_Texture.GetPszProperty("filename")); m_Textures.push_back(Texture); } } }
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; }
CSetRenderTargetSceneRendererCommand::CSetRenderTargetSceneRendererCommand(CXMLTreeNode &TreeNode) :CStagedTexturedSceneRendererCommand(TreeNode) { setName(TreeNode.GetPszProperty("name")); for (int i = 0; i < TreeNode.GetNumChildren(); i++){ CXMLTreeNode text = TreeNode(i); if (text.GetName()==std::string("dynamic_texture")) { //XML SceneRenderCommands: //<dynamic_texture name="DiffuseMapTexture" texture_width_as_frame_buffer="true" format_type="A8R8G8B8" create_depth_stencil_buffer="false"/> CDynamicTexture * dynText = new CDynamicTexture(text); m_DynamicTextures.push_back(dynText); CEngine::GetSingleton().getTextureManager()->add(dynText->getName(), dynText); } } CreateRenderTargetViewVector(); }
CDialogBox::CDialogBox( const CXMLTreeNode& aNode, const Math::Vect2i& screenResolution ) : CGuiElement( aNode, screenResolution ) , m_bDialogClicked(false) , m_ButtonClose( aNode, screenResolution) //, m_ButtonMove( aNode, screenResolution ) , m_pBackGroundTexture(aNode.GetAttribute<CTexture>( "quad" )) , m_BackGroundColor(Math::colWHITE) , m_bStart_to_Move(false) , m_PreviousPosMouse(Math::v2iZERO) , m_fButtonHeight( 0.0f ) , m_fButtonWidth( 0.0f ) { m_ButtonClose.SetParent(this); m_ButtonClose.SetName("buttonClose"); m_ButtonClose.SetLiteral( "" ); m_ButtonClose.SetTextures ( aNode.GetAttribute<CTexture>( "buttonClose_normal" ), aNode.GetAttribute<CTexture>( "buttonClose_over" ), aNode.GetAttribute<CTexture>( "buttonClose_clicked" ), aNode.GetAttribute<CTexture>( "buttonClose_deactivated" ) ); m_ButtonClose.SetPositionPercent(m_PositionPercent + aNode.GetAttribute<Math::Vect2f>("pos_button", Math::Vect2f(0,0))); m_ButtonClose.SetWidthPercent(aNode.GetAttribute<float>("width_button",0.0f)); m_ButtonClose.SetHeightPercent(aNode.GetAttribute<float>("height_button", 0.0f)); for ( int i = 0, count = aNode.GetNumChildren(); i < count; ++i ) { CXMLTreeNode SubTreeNode = aNode( i ); const std::string& TagName = SubTreeNode.GetName(); if( TagName == "Dialog" ) { CStaticText* lTexto1 = new CStaticText(SubTreeNode(0), screenResolution ); CStaticText* lTexto2 = new CStaticText(SubTreeNode(1), screenResolution ); CStaticText* lTexto3 = new CStaticText(SubTreeNode(2), screenResolution ); lTexto1->SetPositionPercent(m_PositionPercent + lTexto1->GetPositionPercent()); lTexto2->SetPositionPercent(m_PositionPercent + lTexto2->GetPositionPercent()); lTexto3->SetPositionPercent(m_PositionPercent + lTexto3->GetPositionPercent()); CDialog* lDialog = new CDialog(lTexto1, lTexto2, lTexto3); m_Dialogo.push_back(lDialog); } } m_CurrentDialog = m_Dialogo.begin(); }
//---Constructor CMap::CMap( const CXMLTreeNode& aNode, const Math::Vect2i& screenResolution ) : CGuiElement( aNode, screenResolution ) , m_Width_Map( aNode.GetAttribute<float>( "width_map", 0.02f ) ) , m_Height_Map( aNode.GetAttribute<float>( "height_map", 0.02f ) ) , m_Mapa( aNode.GetAttribute<CTexture>( "texture_map" ) ) // , m_Marco( aNode.GetAttribute<CTexture>( "texture_marco" ) ) , m_Cone( aNode.GetAttribute<CTexture>( "Data/textures/GUI/Textures_Test/conotrans.png" ) ) // TODO Ruly, poner esto en el xml tambien , m_Player( 0 ) { /*AddEnemys ( aNode.GetAttribute<std::string>( "texture_enemy", "" ), aNode.GetAttribute<int32>( "width_enemy", 50 ), aNode.GetAttribute<int32>( "height_enemy", 50 ), aNode.GetAttribute<std::string>( "get_position_script", "" ), aNode.GetAttribute<std::string>( "orientation", "" ) );*/ m_MinMaxMap[0] = aNode.GetAttribute<Math::Vect2f>( "pos_0_0_3d_map", Math::Vect2f( 0.f, 0.f ) ); m_MinMaxMap[1] = aNode.GetAttribute<Math::Vect2f>( "pos_1_1_3d_map", Math::Vect2f( 0.f, 0.f ) ); for ( int i = 0, count = aNode.GetNumChildren(); i < count; ++i ) { const CXMLTreeNode& pSubNewNode = aNode( i ); const std::string& NameItem = pSubNewNode.GetAttribute<std::string>( "name", "defaultItemElement" ); const std::string& TextureItem = pSubNewNode.GetAttribute<std::string>( "texture", "no_texture" ); const std::string& position_script = pSubNewNode.GetAttribute<std::string>( "get_position_script", "no_script" ); const std::string& orientation_script = pSubNewNode.GetAttribute<std::string>( "orientation", "no_script" ); uint32 WidthItem = pSubNewNode.GetAttribute<uint32>( "width", 50 ); uint32 HeightItem = pSubNewNode.GetAttribute<uint32>( "height", 50 ); float Yaw = pSubNewNode.GetAttribute<float>( "yaw", 0.f ); const std::string& tagName = pSubNewNode.GetName(); const Math::Vect3f& pos = pSubNewNode.GetAttribute<Math::Vect3f>( "pos_in_map", Math::Vect3f() ); if ( tagName == "item" ) AddItem( NameItem, TextureItem, pos, WidthItem, HeightItem, Yaw, position_script, orientation_script ); else if ( tagName == "mark_player" ) AddPlayer( NameItem, TextureItem, pos, WidthItem, HeightItem, Yaw, position_script, orientation_script ); } }
//---------------------------------------------------------------------------- // 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 CParticleSettingsManager::Reload() { CXMLTreeNode newFile; if (!newFile.LoadFile(m_Filename.c_str())) { std::string msg_error = "CParticleSettingsManager::Load->Error al intentar leer el archivo xml: " + m_Filename; LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); return false; } CXMLTreeNode l_xml = newFile["particle_settings"]; if( l_xml.Exists() ) { uint16 l_Count = l_xml.GetNumChildren(); for(uint16 i=0; i<l_Count; ++i) { std::string l_Type = l_xml(i).GetName(); if( l_Type == "settings" ) { CXMLTreeNode child = l_xml(i); TParticleSystemSettings* settings = new TParticleSystemSettings(); settings->m_Name = child.GetPszProperty("name", "", true); uint16 l_CountChild = child.GetNumChildren(); for(uint16 j = 0; j < l_CountChild; ++j) { std::string l_TypeChild = child(j).GetName(); if(l_TypeChild == "TextureName") { settings->m_TextureName = child(j).GetPszProperty("value", "", true); } else if(l_TypeChild == "MaxParticles") { uint32 maxPart = (uint32)child(j).GetIntProperty("value", 0, true) / CORE->GetConfig().particle_level; maxPart = maxPart == 0 ? 1 : maxPart; settings->m_MaxParticles = maxPart; } else if(l_TypeChild == "Duration") { settings->m_Duration = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "DurationRandomness") { settings->m_DurationRandomness = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "EmitterVelocitySensitivity") { settings->m_EmitterVelocitySensitivity = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MinHorizontalVelocity") { settings->m_MinHorizontalVelocity = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MaxHorizontalVelocity") { settings->m_MaxHorizontalVelocity = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MinVerticalVelocity") { settings->m_MinVerticalVelocity = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MaxVerticalVelocity") { settings->m_MaxVerticalVelocity = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "Gravity") { settings->m_Gravity = child(j).GetVect3fProperty("value", Vect3f(0, 0, 0), true); } else if(l_TypeChild == "EndVelocity") { settings->m_EndVelocity = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MinColor") { Vect4f temp = child(j).GetVect4fProperty("value", Vect4f(0, 0, 0, 0), true) / 255.0f; settings->m_MinColor = CColor(temp); } else if(l_TypeChild == "MaxColor") { Vect4f temp = child(j).GetVect4fProperty("value", Vect4f(0, 0, 0, 0), true) / 255.0f; settings->m_MaxColor = CColor(temp); } else if(l_TypeChild == "MinRotateSpeed") { settings->m_MinRotateSpeed = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MaxRotateSpeed") { settings->m_MaxRotateSpeed = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MinStartSize") { settings->m_MinStartSize = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MaxStartSize") { settings->m_MaxStartSize = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MinEndSize") { settings->m_MinEndSize = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "MaxEndSize") { settings->m_MaxEndSize = child(j).GetFloatProperty("value", 0, true); } else if(l_TypeChild == "BlendState") { std::string type = child(j).GetPszProperty("value", 0, true); settings->m_BlendName = type; if(type.compare("NonPremultiplied") == 0) { settings->m_BlendState = TGraphicBlendStates::NonPremultiplied; } else if (type.compare("Additive") == 0) { settings->m_BlendState = TGraphicBlendStates::Additive; } else if (type.compare("DefaultState") == 0) { settings->m_BlendState = TGraphicBlendStates::DefaultState; } } } bool isOk = this->AddResource(settings->m_Name, settings); assert(isOk); } } } else { return false; } return true; }
CEffectTechnique::CEffectTechnique( const CXMLTreeNode& aTechniqueNode ) : CName( aTechniqueNode.GetAttribute<std::string>("name", "null") ) , m_DebugColor( Math::colWHITE ) , m_VertexType( aTechniqueNode.GetAttribute<uint32>("vertex_type", 0 ) ) , m_Filename( aTechniqueNode.GetAttribute<std::string>("file", "null_file") ) , mUseWorld ( false ) , mUseInverseWorld ( false ) , mUseView ( false ) , mUseInverseView ( false ) , mUseProjection ( false ) , mUseInverseProjection ( false ) , mUseViewProjection ( false ) , mUseWorldView ( false ) , mUseWorldViewProjection ( false ) , mUseViewToLightProjection ( false ) , mUseFog ( false ) , mUseLights ( false ) , mUseDebugColor ( false ) , mUseFBSize ( false ) , mUseAmbientLight ( false ) , mUseCamera ( false ) , mUseTime ( false ) , m_NumOfLights ( 0 ) { ASSERT( m_Filename != "null_file", "Check the file of the technique %s", GetName().c_str() ); //Use the compiled effect m_Filename = "../CommonData/fx/" + GetName() + ".o"; LOG_INFO_APPLICATION( "Loading effect tecnhique %s", m_Filename.c_str() ); for ( uint32 j = 0, lCount = aTechniqueNode.GetNumChildren(); j < lCount; ++j ) { const CXMLTreeNode& lCurrentNode = aTechniqueNode( j ); const std::string& l_TagName = lCurrentNode.GetName(); if ( l_TagName == "handles" ) { ReadFlags( lCurrentNode ); } #ifdef _DEBUG if( l_TagName == "define" ) { SDefines lDefine = { lCurrentNode.GetAttribute<std::string>("name", "null_name"), lCurrentNode.GetAttribute<std::string>("description", "") }; m_Defines.push_back(lDefine); } #endif } #ifdef _DEBUG // By default insert the definition of the technique name SDefines lDefine = { "TECHNIQUE_NAME", GetName() }; m_Defines.push_back(lDefine); #endif m_Effect = new CEffect(GetName() + "_Effect" ); bool lLoaded = m_Effect->Load( m_Filename, m_Defines ); ASSERT(lLoaded, "The effect %s could not be loaded" ); if( lLoaded ) { m_D3DTechnique = ( m_Effect ) ? m_Effect->GetTechniqueByName( GetName() ) : 0; } else { CHECKED_DELETE( m_Effect ); } }
/// <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 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; }
void CGUIWindow::LoadRadioBox(CRadioBox** radioBox_aux, CXMLTreeNode& pNewNode, const Vect2i& screenResolution, CTextureManager* tm) { //<RadioBox name="pepito" posx="0" posy="2" height="10" width="10" default_checkButton="bla" visible="true" active="true" texture_back="" // columns="3" rows="3" OnCheckOn="blabla" OnCheckOff="blabla" OnOverButton="blabla" // OnSaveValue="blabl" OnLoadValue="" Literal="blabla" widthOffset="" heightOffset=""/> // <texture name="q3dm1" on="gui_q3dm1_on.jpg" off="gui_q3dm1_off.jpg" deactivated="gui_q3dm1_on.jpg" /> // <texture name="q3dm2" on="gui_q3dm2_on.jpg" off="gui_q3dm2_off.jpg" deactivated="gui_q3dm2_on.jpg" /> // ... //</RadioBox> CRadioBox* radioBox; 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 default_checkButton = pNewNode.GetPszProperty("default_checkButton", ""); std::string texture_back = pNewNode.GetPszProperty("texture_back", ""); uint32 columns = pNewNode.GetIntProperty("columns", 0); uint32 rows = pNewNode.GetIntProperty("rows", 0); std::string OnCheckOn = pNewNode.GetPszProperty("OnCheckOn", ""); std::string OnCheckOff = pNewNode.GetPszProperty("OnCheckOff", ""); std::string OnOverButton = pNewNode.GetPszProperty("OnOverButton", ""); std::string OnSaveValue = pNewNode.GetPszProperty("OnSaveValue", ""); std::string OnLoadValue = pNewNode.GetPszProperty("OnLoadValue", ""); std::string l_literal = pNewNode.GetPszProperty("Literal", ""); float widthOffsetPercent = pNewNode.GetFloatProperty("widthOffset", 0.f); float heightOffsetPercent = pNewNode.GetFloatProperty("heightOffset", 0.f); uint32 widthOffset = (uint32) (screenResolution.x * 0.01f * widthOffsetPercent ); uint32 heightOffset = (uint32) (screenResolution.y * 0.01f * heightOffsetPercent ); radioBox = new CRadioBox( screenResolution.y,screenResolution.x,h, w, Vect2f(posx,posy), columns, rows, default_checkButton, l_literal, heightOffset, widthOffset, visible, activated); if (texture_back!="") { CTexture* quad = tm->GetTexture(texture_back); radioBox->SetTextureBack(quad); } radioBox->SetName(name); radioBox->SetOnLoadValueAction(OnLoadValue); radioBox->SetOnSaveValueAction(OnSaveValue); //radioBox->SetCheckButtonActions(OnCheckOn, OnCheckOff, OnOverButton); int count = pNewNode.GetNumChildren(); for (int j = 0; j < count; ++j) { CXMLTreeNode pTexture = pNewNode(j); std::string tagName = pTexture.GetName(); if (tagName.compare("texture")==0) { std::string name = pTexture.GetPszProperty("name"); std::string on = pTexture.GetPszProperty("on"); std::string off = pTexture.GetPszProperty("off"); std::string deactivated = pTexture.GetPszProperty("deactivated"); CTexture* texture_on = tm->GetTexture(on); CTexture* texture_off = tm->GetTexture(off); CTexture* texture_deactivated = tm->GetTexture(deactivated); radioBox->SetCheckButton(name, texture_on, texture_off, texture_deactivated); } } radioBox->SetCheckButtonActions(OnCheckOn, OnCheckOff, OnOverButton); *radioBox_aux = radioBox; }
void CGUIWindow::LoadAnimatedImage(CAnimatedImage** image_aux, CXMLTreeNode& pNewNode, const Vect2i& screenResolution, CTextureManager* tm) { //<AnimatedImage name="imageRoomSelected_gameserver2" posx="35" posy="20" height="40" width="30" visible="true" active="true" //default="q3dm1" isAnimated="true", time="0" loop="true" OnSaveValue="blabla" OnLoadValue="blabla" Literal="blabla" //widthOffset="" heightOffset="" flip="" Literal="blabla" widthOffset="" heightOffset=""/> // <texture name="q3dm1" texture="gui_q3dm1_off.jpg"/> // <texture name="q3dm2" texture="gui_q3dm2_off.jpg"/> // ... //</Image> CAnimatedImage* image; 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); uint16 initFrame = pNewNode.GetIntProperty("initFrame", true); bool playOnLoad = pNewNode.GetBoolProperty("playOnLoad", true); std::string OnSaveValue = pNewNode.GetPszProperty("OnSaveValue", ""); std::string OnLoadValue = pNewNode.GetPszProperty("OnLoadValue", ""); std::string flip = pNewNode.GetPszProperty("flip", ""); bool backGround = pNewNode.GetBoolProperty("backGround", false); std::string l_literal = pNewNode.GetPszProperty("Literal", ""); float widthOffsetPercent = pNewNode.GetFloatProperty("widthOffset", 0.f); float heightOffsetPercent = pNewNode.GetFloatProperty("heightOffset", 0.f); uint32 widthOffset = (uint32) (screenResolution.x * 0.01f * widthOffsetPercent ); uint32 heightOffset = (uint32) (screenResolution.y * 0.01f * heightOffsetPercent ); image = new CAnimatedImage( screenResolution.y,screenResolution.x, h, w, Vect2f(posx,posy), l_literal, heightOffset, widthOffset, visible, activated); image->SetName(name); image->SetOnLoadValueAction(OnLoadValue); image->SetOnSaveValueAction(OnSaveValue); image->SetBackGround(backGround); if( flip.compare("FLIP_X") == 0) { image->SetFlip(FLIP_X); } else if (flip.compare("FLIP_Y") == 0) { image->SetFlip(FLIP_Y); } else { image->SetFlip(NONE_FLIP); } int count = pNewNode.GetNumChildren(); for (int j = 0; j < count; ++j) { CXMLTreeNode pTexture = pNewNode(j); std::string tagName = pTexture.GetName(); if (tagName.compare("texture")==0) { std::string texture = pNewNode(j).GetPszProperty("name_texture"); CTexture* texture_image = tm->GetTexture(texture); image->AddFrame(texture_image); } } image->GoToFrame(initFrame); if (playOnLoad) { //image->PlayAnimation(); } *image_aux = image; }
CMaterial::CMaterial(CXMLTreeNode &TreeNode) : CNamed(TreeNode) { /*m_RenderableObjectTechnique = new CRenderableObjectTechnique(TreeNode.GetPszProperty("effect_technique"), CEngine::GetSingletonPtr()->getEffectsManager()->get(TreeNode.GetPszProperty("effect_technique")));*/ std::string name; const char * rot = TreeNode.GetPszProperty("renderable_object_technique", 0, false); if (rot) { name = rot; } else { name = TreeNode.GetPszProperty("vertex_type", "", true); DEBUG_ASSERT( name != std::string("") ); } m_RenderableObjectTechnique = CEngine::GetSingleton().getRenderableObjectTechniqueManager()->get(name); void *nextDir = &CEffectManager::m_MaterialEffectParameters.m_RawData[0]; int l_NextStage = 0; for (int i = 0; i < TreeNode.GetNumChildren(); ++i) { CXMLTreeNode l_paramMat = TreeNode(i); if (l_paramMat.GetName() == std::string("texture")) { CXMLTreeNode l_Texture = l_paramMat; CTexture * Texture = CEngine::GetSingleton().getTextureManager()->GetTexture(l_Texture.GetPszProperty("filename")); int stage = GetTextureStage(l_Texture.GetPszProperty("type", "", false)); if (stage < 0) { stage = l_paramMat.GetIntProperty("stage", -1, false); } if (stage < 0) { stage = l_NextStage; } m_textures.push_back(std::make_pair(stage,Texture)); l_NextStage++; } else if (l_paramMat.GetName() == std::string("parameter")) { CMaterialParameter::TMaterialType type; if (l_paramMat.GetPszProperty("type") == std::string("float")) { type = CMaterialParameter::TMaterialType::FLOAT; CTemplatedMaterialParameter<float> *param = new CTemplatedMaterialParameter<float>( l_paramMat, nextDir, l_paramMat.GetFloatProperty("value"), type); m_Parameters.push_back(param); } else if (l_paramMat.GetPszProperty("type") == std::string("Vect2f")) { type = CMaterialParameter::TMaterialType::VECT2F; CTemplatedMaterialParameter<Vect2f> *param = new CTemplatedMaterialParameter<Vect2f>( l_paramMat, nextDir, l_paramMat.GetVect2fProperty("value", Vect2f(0, 0)), type); m_Parameters.push_back(param); } else if (l_paramMat.GetPszProperty("type") == std::string("Vect3f")) { type = CMaterialParameter::TMaterialType::VECT3F; CTemplatedMaterialParameter<Vect3f> *param = new CTemplatedMaterialParameter<Vect3f>( l_paramMat, nextDir, l_paramMat.GetVect3fProperty("value", Vect3f(0, 0, 0)), type); m_Parameters.push_back(param); } else if (l_paramMat.GetPszProperty("type") == std::string("Vect4f")) { type = CMaterialParameter::TMaterialType::VECT4F; CTemplatedMaterialParameter<Vect4f> *param = new CTemplatedMaterialParameter<Vect4f>( l_paramMat, nextDir, l_paramMat.GetVect4fProperty("value", Vect4f(0, 0, 0, 0)), type); m_Parameters.push_back(param); } nextDir = reinterpret_cast<unsigned char*>(nextDir)+sizeof(Vect4f); } } }
CFont::CFont(CXMLTreeNode& fontNode, CGUI* gui) : CNamed(fontNode) , m_glyphs( MAX_GLYPHS_BATCH ) , m_gui(gui) , m_textAlign(Rectf::Alignment::TOP_LEFT) { auto mm = CEngine::GetSingleton().getMaterialManager(); auto tm = CEngine::GetSingleton().getTextureManager(); std::string fontFile = fontNode.GetPszProperty("path", "", false); std::string fontName = fontNode.GetPszProperty("name", "", false); DEBUG_ASSERT(fontFile.size() != 0 && fontName.size() != 0); if (fontFile.size() == 0 || fontName.size() == 0) { return; } for (int i = 0; i < fontNode.GetNumChildren(); ++i) { auto matNode = fontNode(i); if (matNode.GetName() == std::string("material")) { std::string matName = "font-material-" + fontName; CMaterial *mat = new CMaterial(matNode); mat->setName(matName); mm->add(matName, mat); m_material = mat; break; } } std::string fontPath; size_t pathEnd = fontFile.find_last_of('\\'); if (pathEnd == fontFile.npos) { pathEnd = fontFile.find_last_of('/'); } if (pathEnd != fontFile.npos) { fontPath = fontFile.substr(0, pathEnd+1); } CXMLTreeNode ff; if (!ff.LoadFile(fontFile.c_str())) { DEBUG_ASSERT(false); return; } CXMLTreeNode font = ff["font"]; CXMLTreeNode common = font["common"]; CXMLTreeNode info = font["info"]; Vect2f pageSize(common.GetFloatProperty("scaleW", 0, false), common.GetFloatProperty("scaleH", 0, false)); m_fontSize = info.GetFloatProperty( "size", 0, false ); DEBUG_ASSERT( m_fontSize != 0); m_lineHeight = common.GetFloatProperty( "lineHeight", m_fontSize, false ); m_base = common.GetFloatProperty( "base", m_fontSize, false ); CXMLTreeNode pages = font["pages"]; for (int i = 0; i < pages.GetNumChildren(); ++i) { auto page = pages(i); if (page.GetName() == std::string("page")) { std::string texFile = page.GetPszProperty("file", "", false); DEBUG_ASSERT(texFile.size() > 0); texFile = fontPath + texFile; CTexture *tex = new CTexture(); tex->load(texFile, false); tm->add(tex->getName(), tex); m_pages.push_back(tex); } } auto chars = font["chars"]; for (int i = 0; i < chars.GetNumChildren(); ++i) { auto ch = chars(i); if (ch.GetName() != std::string("char")) { continue; } uchar chId = ch.GetIntProperty("id"); CharDesc_t cdesc; cdesc.offset = Vect2f(ch.GetFloatProperty("xoffset", 0, false), ch.GetFloatProperty("yoffset", 0, false)); cdesc.page = ch.GetIntProperty("page"); cdesc.size = Vect2f(ch.GetFloatProperty("width", 0, false), ch.GetFloatProperty("height", 0, false)); cdesc.xAdvance = ch.GetFloatProperty("xadvance", 0, false); cdesc.uvRect.position = Vect2f(ch.GetFloatProperty("x", 0, false), ch.GetFloatProperty("y", 0, false)); cdesc.uvRect.position = Vect2f(cdesc.uvRect.position.x / pageSize.x, cdesc.uvRect.position.y / pageSize.y); cdesc.uvRect.size = Vect2f(cdesc.size.x / pageSize.x, cdesc.size.y / pageSize.y); m_chars[chId] = cdesc; } auto kerns = font["kernings"]; if (kerns.Exists()) { for (int i = 0; i < kerns.GetNumChildren(); ++i) { auto k = kerns(i); uchar f = k.GetIntProperty("first", 0, false); uchar s = k.GetIntProperty("second", 0, false); uchar a = k.GetIntProperty("amount", 0, false); m_kernings[std::make_pair(f, s)] = a; } } m_glyphsVtxs = new CPointsListRenderableVertexs<GUI_TEXT_VERTEX>(m_glyphs.data(), MAX_GLYPHS_BATCH, MAX_GLYPHS_BATCH, true); }
bool CEnemyManager::Init(const char* _pcFile) { CXMLTreeNode FileXML; FileXML.LoadFile(_pcFile); //CXMLTreeNode Enemies = fileXML(0); { CXMLTreeNode Templates = FileXML["templates"]; int iNumChildren = Templates.GetNumChildren(); for(int i = 0; i < iNumChildren; i++) { CXMLTreeNode EnemyTemplate = Templates(i); const char* pcId = EnemyTemplate.GetPszProperty("id"); const char* pcMesh = EnemyTemplate.GetPszProperty("mesh"); CEnemyResource* pResource = new CEnemyResource(); std::string szId = pcId; //TODO comprovar errors pResource->Init(pcId,pcMesh); m_Resources[szId] = pResource; } } { Vect3f Default(0,0,0); CXMLTreeNode Instances = FileXML["instances"]; int iNumChildren = Instances.GetNumChildren(); for(int i = 0; i < iNumChildren; i++) { CXMLTreeNode EnemyInstance = Instances(i); const char* pcType = EnemyInstance.GetPszProperty("type"); const Vect3f vPos = EnemyInstance.GetVect3fProperty("pos",Default); const Vect3f vRot = EnemyInstance.GetVect3fProperty("rot",Default); const float fMoveSpeed = EnemyInstance.GetFloatProperty("move_speed"); const float fRotateSpeed = EnemyInstance.GetFloatProperty("rotate_speed"); const float fHealth = EnemyInstance.GetFloatProperty("health"); if(strcmp(pcType,"PATROLLER") == 0) { const char* pcPaths = EnemyInstance.GetPszProperty("paths"); CPatroller* pPatroller = new CPatroller(); pPatroller->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,pcPaths); m_Instances.push_back(pPatroller); } else if(strcmp(pcType,"SNIPER") == 0) { float fAimDistance = EnemyInstance.GetFloatProperty("aim_distance"); CSniper* pSniper = new CSniper(); pSniper->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,fAimDistance); m_Instances.push_back(pSniper); } else if(strcmp(pcType,"TURRET") == 0) { Vect3f vMaxAngle = EnemyInstance.GetVect3fProperty("max_angle",Default); Vect3f vMinAngle = EnemyInstance.GetVect3fProperty("min_angle",Default); CTurret* pTurret = new CTurret(); pTurret->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,vMaxAngle,vMinAngle); m_Instances.push_back(pTurret); } else if(strcmp(pcType,"CAMERA") == 0) { Vect3f vMaxAngle = EnemyInstance.GetVect3fProperty("max_angle",Default); Vect3f vMinAngle = EnemyInstance.GetVect3fProperty("min_angle",Default); CCamera* pCamera = new CCamera(); pCamera->Init(vPos,vRot,fMoveSpeed,fRotateSpeed,fHealth,vMaxAngle,vMinAngle); m_Instances.push_back(pCamera); } else { //TODO errors } } } return true; }
bool CWayPointManager::Reload() { CXMLTreeNode newFile; if (!newFile.LoadFile(m_Filename.c_str())) { std::string msg_error = "WayPointManager::Load->Error al intentar leer el archivo xml: " + m_Filename; LOGGER->AddNewLog(ELL_ERROR, msg_error.c_str()); return false; } CXMLTreeNode l_wps = newFile["waypoints"]; if( l_wps.Exists() ) { uint16 l_Count = l_wps.GetNumChildren(); for(uint16 i=0; i<l_Count; ++i) { std::string l_Type = l_wps(i).GetName(); if( l_Type == "group" ) { CXMLTreeNode groupChild = l_wps(i); std::string groupName = groupChild.GetPszProperty("name", "", true); if(m_WPGroups.find(groupName) == m_WPGroups.end()) { m_WPGroups[groupName] = WayPointList(); } uint16 l_CountGroup = groupChild.GetNumChildren(); for(uint16 j = 0; j < l_CountGroup; ++j) { std::string l_TypeChild = groupChild(j).GetName(); if(l_TypeChild == "waypoint") { std::string wpName = groupChild(j).GetPszProperty("name", "", true); Vect3f wpPos = groupChild(j).GetVect3fProperty("position", Vect3f(0.0f, 0.0f, 0.0f), true); CWayPoint* wp = new CWayPoint(wpName, wpPos); m_WPGroups[groupName].push_back(wp); } if(l_TypeChild == "Brothers") { CXMLTreeNode broChild = groupChild(j); uint16 broChildCount = broChild.GetNumChildren(); std::string wpName = broChild.GetPszProperty("wave_point_name", "", true); CWayPoint* wp = GetWayPoint(groupName, wpName); assert(wp); for (uint16 x = 0; x < broChildCount; ++x) { std::string l_TypeBroChild = broChild(x).GetName(); if(l_TypeBroChild == "Brother") { std::string broName = broChild(x).GetPszProperty("name", "", true); CWayPoint* wpBro = GetWayPoint(groupName, broName); assert(wpBro); wp->AddBrother(wpBro); } } } } } } } else { return false; } return true; }
CMaterial::CMaterial(CXMLTreeNode &TreeNode) :m_Textures(NULL) ,m_RenderableObjectTechnique(NULL) ,CNamed(TreeNode.GetPszProperty("name", "")) ,m_CurrentParameterData(0) ,m_Offset(0) ,m_StaticFriction(0.0f) ,m_DynamicFriction(0.0f) ,m_Restitution(0.0f) { std::string l_RenderableObjectTechniqueName=TreeNode.GetPszProperty("renderable_object_technique", ""); if(l_RenderableObjectTechniqueName!="") m_RenderableObjectTechnique=CEngine::GetSingleton().GetRenderableObjectTechniqueManager()->GetResource(l_RenderableObjectTechniqueName); for (int i = 0; i < TreeNode.GetNumChildren(); ++i) { CXMLTreeNode l_Element = TreeNode(i); if (l_Element.GetName() == std::string("texture")) { std::string l_Filename = l_Element.GetPszProperty("filename", ""); bool l_GuiTexture = l_Element.GetBoolProperty("gui_texture", false); CTexture *l_Texture = CEngine::GetSingleton().GetTextureManager()->GetTexture(l_Filename, l_GuiTexture); if (l_Texture!=nullptr) m_Textures.push_back(l_Texture); } else if (l_Element.GetName() == std::string("parameter")) { std::string l_Type = l_Element.GetPszProperty("type"); std::string l_Name = l_Element.GetPszProperty("name"); if (l_Name == "static_friction") { m_StaticFriction = l_Element.GetFloatProperty("value", 0.0f); } else if (l_Name == "dynamic_friction") { m_DynamicFriction = l_Element.GetFloatProperty("value", 0.0f); } else if (l_Name == "restitution") { m_Restitution = l_Element.GetFloatProperty("value", 0.0f); } else { CMaterialParameter* l_MaterialParameter; CMaterialParameter::TMaterialType l_MaterialType; if (l_Type == "float") { l_MaterialType = CMaterialParameter::FLOAT; l_MaterialParameter = new CTemplatedMaterialParameter<float>(this, l_Element, l_Element.GetFloatProperty("value", 0.0f), l_MaterialType); } else if (l_Type == "vect2f") { l_MaterialType = CMaterialParameter::VECT2F; l_MaterialParameter = new CTemplatedMaterialParameter<Vect2f>(this, l_Element, l_Element.GetVect2fProperty("value", v2fZERO), l_MaterialType); } else if (l_Type == "vect3f") { l_MaterialType = CMaterialParameter::VECT3F; l_MaterialParameter = new CTemplatedMaterialParameter<Vect3f>(this, l_Element, l_Element.GetVect3fProperty("value", v3fZERO), l_MaterialType); } else if (l_Type == "vect4f") { l_MaterialType = CMaterialParameter::VECT4F; l_MaterialParameter = new CTemplatedMaterialParameter<Vect4f>(this, l_Element, l_Element.GetVect4fProperty("value", v4fZERO), l_MaterialType); } m_Parameters.push_back(l_MaterialParameter); } } } }