Bool CMaterialResource::Init() { CXMLDocument document; document.Load( m_FilePath.c_str() ); CXMLNode rootNode = document.GetRootNode(); //Read out textures CXMLNode childNode = rootNode.GetChildNode( "Texture2D" ); while ( childNode.IsEmpty() == false ) { CXMLAttribute attribute = childNode.GetAttribute( "Hash" ); const Uint hash = (Uint)strtoul( attribute.GetValue(), NULL, 0 ); AddDependentHash( hash ); childNode = childNode.GetNextSibling(); } if ( m_DependenciesLeft == 0 ) { return true; } return false; }
/** * expand from view data. * * expand dom from old instanceview.xml data * * @param - * @return - * @exception - * @see - */ void CInstanceTree::ExpandFromViewData() { CXMLDocument tOldDoc; CString strFileName; strFileName = m_pProjectManager->GetProjectPath() + _T("\\") + CE_PROJECT_VIEW_PATH + _T("\\") + m_strFileName; if (!FC_Exist(strFileName)) { return; } if (!tOldDoc.Load(strFileName)) { return; } CXMLNode tNodeRootNew; CXMLNode tNodeRootOld; if(!m_domDocument.GetRootNode(tNodeRootNew) || !tOldDoc.GetRootNode(tNodeRootOld)) { return; } ExpandParallel(tNodeRootNew, tNodeRootOld); }
void CXMLDlg::OnLoad() { CWaitCursor Wait; UpdateData(); HRESULT hr = S_OK; HTREEITEM hFirstItem = m_treeOutput.GetChildItem(TVI_ROOT); if (hFirstItem) m_treeOutput.Expand(hFirstItem, TVE_COLLAPSE); m_treeOutput.DeleteAllItems(); CoInitialize(NULL); // Create an empty XML document CXMLDocument* pXMLDoc = new CXMLDocument; hr = pXMLDoc->RegisterCallback(&MyXMLCallback, (LPARAM)this); if (m_strFileName.IsEmpty()) { hr = pXMLDoc->Build(); // load a document from in-memory string. } else { if (m_bStream) hr = pXMLDoc->LoadStream(m_strFileName); else hr = pXMLDoc->Load(m_strFileName, !!m_bAsync); } // Now walk the loaded XML document dumping the name-value pairs pXMLDoc->WalkTree(CString("")); //j // Test persistence of encoded XML doc in memory //j PBYTE pData = NULL; //j ULONG ulLen; //j hr = pXMLDoc->PersistToMemory(&pData, &ulLen); //j hr = pXMLDoc->LoadFromMemory(pData, ulLen); //j delete pData; delete pXMLDoc; CoUninitialize(); }
void CMaterialResource::Load() { m_IsLoaded = true; CXMLDocument document; document.Load( m_FilePath.c_str() ); CXMLNode rootNode = document.GetRootNode(); //Read out shaders CXMLNode childNode = rootNode.GetChildNode( "Shader" ); CXMLAttribute attribute = childNode.GetAttribute( "File" ); std::string shaderPath; shaderPath += "../Content/"; shaderPath += attribute.GetValue(); //Read out defines childNode = rootNode.GetChildNode( "ShaderDefine" ); while ( childNode.IsEmpty() == false ) { attribute = childNode.GetAttribute( "Name" ); const Char* name = attribute.GetValue( "" ); if ( strcmp( name, "" ) != 0 ) { m_ShaderDefines.push_back( name ); } childNode = childNode.GetNextSibling(); } //Build hash Uint hash = HashString( shaderPath.c_str() ); hash += m_ShaderDefines.size(); for ( Uint i = 0; i < m_ShaderDefines.size(); ++i ) { hash += HashString( m_ShaderDefines[i].c_str() ); } CResource* shaderResource; if ( ( shaderResource = CResourceManager::GetInstance()->GetResourceByHash( hash ) ) == NULL ) { shaderResource = CResourceManager::GetInstance()->AddShaderResource( shaderPath.c_str(), hash, m_ShaderDefines ); } m_ShaderResource = (CShaderResource*)shaderResource; m_Shader = m_ShaderResource->GetShader(); //Read terms childNode = rootNode.GetChildNode( "Terms" ); //Emmisive CXMLNode termNode = childNode.GetChildNode( "Emissive" ); attribute = termNode.GetAttribute( "R" ); m_EmissiveTerm.X = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "G" ); m_EmissiveTerm.Y = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "B" ); m_EmissiveTerm.Z = (Float)atof( attribute.GetValue() ); //Diffuse termNode = childNode.GetChildNode( "Diffuse" ); attribute = termNode.GetAttribute( "R" ); m_DiffuseTerm.X = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "G" ); m_DiffuseTerm.Y = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "B" ); m_DiffuseTerm.Z = (Float)atof( attribute.GetValue() ); //Specular termNode = childNode.GetChildNode( "Specular" ); attribute = termNode.GetAttribute( "R" ); m_SpecularTerm.X = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "G" ); m_SpecularTerm.Y = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "B" ); m_SpecularTerm.Z = (Float)atof( attribute.GetValue() ); //Ambient termNode = childNode.GetChildNode( "Ambient" ); attribute = termNode.GetAttribute( "R" ); m_AmbientTerm.X = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "G" ); m_AmbientTerm.Y = (Float)atof( attribute.GetValue() ); attribute = termNode.GetAttribute( "B" ); m_AmbientTerm.Z = (Float)atof( attribute.GetValue() ); //Specular power termNode = childNode.GetChildNode( "SpecularPower" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_SpecularPower = (Float)atof( attribute.GetValue( "1.0f" ) ); } termNode = childNode.GetChildNode( "Reflection" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_Reflection = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "Refraction" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_Refraction = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "Transmittance" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_Transmittance = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "FresnelPower" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_FresnelValues.X = (Float)atof( attribute.GetValue( "1.0f" ) ); } termNode = childNode.GetChildNode( "FresnelScale" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_FresnelValues.Y = (Float)atof( attribute.GetValue( "1.0f" ) ); } termNode = childNode.GetChildNode( "FresnelBias" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_FresnelValues.Z = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "TextureWeight" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_TextureWeight = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "ParallaxScale" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_ParallaxScale = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "ParallaxBias" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "Value" ); m_ParallaxBias = (Float)atof( attribute.GetValue( "0.0f" ) ); } termNode = childNode.GetChildNode( "RefractiveIndices" ); if ( termNode.IsEmpty() == false ) { attribute = termNode.GetAttribute( "R" ); m_RefractiveIndices.X = (Float)atof( attribute.GetValue( "1.0f" ) ); attribute = termNode.GetAttribute( "G" ); m_RefractiveIndices.Y = (Float)atof( attribute.GetValue( "1.0f" ) ); attribute = termNode.GetAttribute( "B" ); m_RefractiveIndices.Z = (Float)atof( attribute.GetValue( "1.0f" ) ); } //Read out textures childNode = rootNode.GetChildNode( "Texture2D" ); while ( childNode.IsEmpty() == false ) { attribute = childNode.GetAttribute( "Name" ); const Char* name = attribute.GetValue(); attribute = childNode.GetAttribute( "Hash" ); const Uint hash = (Uint)strtoul( attribute.GetValue(), NULL, 0 ); //Check if the resource already exists and is loaded CResource* resource = m_DependentResources.find( hash )->second; Uint textureID = 0; if ( resource != NULL ) { CTextureResource* textureResource = (CTextureResource*)resource; if ( textureResource->IsLoaded() ) { textureID = textureResource->GetTextureID(); } } attribute = childNode.GetAttribute( "Type" ); const Char* type = attribute.GetValue(); attribute = childNode.GetAttribute( "UVChannel" ); const Uint uvChannel = atoi( attribute.GetValue() ); attribute = childNode.GetAttribute( "Mapping" ); const Char* mapping = attribute.GetValue(); CXMLNode mapNode = childNode.GetChildNode( "MapMode" ); attribute = mapNode.GetAttribute( "X" ); const Char* mapModeX = attribute.GetValue(); attribute = mapNode.GetAttribute( "Y" ); const Char* mapModeY = attribute.GetValue(); TextureMapMode mapModes[2]; mapModes[0] = (TextureMapMode)ConvertMapMode( mapModeX ); mapModes[1] = (TextureMapMode)ConvertMapMode( mapModeY ); CTexture2D* texture = new CTexture2D( name, hash, (TextureMapping)ConvertMapping( mapping ), mapModes, (TextureMapType)ConvertTextureType( type ), uvChannel, textureID ); m_2DTextures.push_back( texture ); childNode = childNode.GetNextSibling(); } childNode = rootNode.GetChildNode( "TextureCube" ); while ( childNode.IsEmpty() == false ) { attribute = childNode.GetAttribute( "FileBase" ); const Char* fileBase = attribute.GetValue(); attribute = childNode.GetAttribute( "UniformName" ); const Char* uniformName = attribute.GetValue(); attribute = childNode.GetAttribute( "Extension" ); const Char* extension = attribute.GetValue(); CTextureCube* texture = new CTextureCube( fileBase, uniformName, extension ); m_3DTextures.push_back( texture ); childNode = childNode.GetNextSibling(); } }
void CFYSPrintDoc::UnpackFiles() { CString strTemp; CString strSep("\\"); CString strFileName = m_strFYSTempPath + FORYOURSOUL_TXT; FILE* input = NULL; errno_t err = fopen_s(&input, strFileName, "rb"); if (!input || err != 0) { SetError(String("Failed to open %s", strFileName)); return; } HGLOBAL hMemory; BYTE* pMemory; // unpack the mini header hMemory = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(BYTE)); pMemory = (BYTE*)::GlobalLock(hMemory); char xz = ']'; do { fread(pMemory, sizeof(BYTE), 1, input); strTemp += (char)*pMemory; }while((*(char*)pMemory) != xz); ::GlobalUnlock(hMemory); ::GlobalFree(hMemory); // unpack streamheader strTemp = strTemp.Mid(1, strTemp.Find(',', 0)-1); DWORD dwSize = atoi(strTemp); hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize); pMemory = (BYTE*)::GlobalLock(hMemory); fread(pMemory, sizeof(BYTE), dwSize, input); CString strPath = m_strFYSTempPath + XML_PATH + strSep; strTemp.Format("%sXP_%s", strPath, STREAMHDR_XML); FILE* output = NULL; err = fopen_s(&output, strTemp, "wb"); if (!output || err != 0) { SetError(String("Failed to open %s", strTemp)); } else { fwrite(pMemory, sizeof(BYTE), dwSize, output); fclose(output); output = NULL; } ::GlobalUnlock(hMemory); ::GlobalFree(hMemory); // time to read the stream header into a xml class CXMLDocument* pXMLDoc = new CXMLDocument; pXMLDoc->Load(strTemp, false); CString strCount = pXMLDoc->GetStringValue("//FYS_DataStreamHeader//Files", "Count"); int nFileCount = atoi(strCount); for (int i=0, offset=0; i<nFileCount; i++) { CString strSrch = String("//FYS_DataStreamHeader//Files//File[@StartOffset = '%ld']", offset); CString strType = pXMLDoc->GetStringValue(strSrch, "Type"); CString strName = pXMLDoc->GetStringValue(strSrch, "Name"); CString strSize = pXMLDoc->GetStringValue(strSrch, "Size"); DWORD dwSize = atoi(strSize); hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize); pMemory = (BYTE*)::GlobalLock(hMemory); fread(pMemory, sizeof(BYTE), dwSize, input); if (strType == "DataEnvelope") strPath = m_strFYSTempPath + XML_PATH + strSep; if (strType == "Image") strPath = m_strFYSTempPath + IMAGES_PATH + strSep; if (strType == "Font") strPath = m_strFYSTempPath + FONTS_PATH + strSep; strTemp.Format("%sXP_%s", strPath, strName); err = fopen_s(&output, strTemp, "wb"); if (!output || err != 0) { SetError(String("Failed to open %s", strTemp)); } else { fwrite(pMemory, sizeof(BYTE), dwSize, output); fclose(output); output = NULL; } ::GlobalUnlock(hMemory); ::GlobalFree(hMemory); offset += dwSize; } fclose(input); delete pXMLDoc; }