//--------------------------------------------------------------------------------- // Name: init() // Desc: Loads metadata. //--------------------------------------------------------------------------------- void ResourceManager::init() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file( RESOURCES_MAP ); if (!result) _FATAL("Failed loading XML document : " + TO_STD_STRING(RESOURCES_MAP) + " XML error : " + result.description()); pugi::xml_node resource_tree = doc.child(RESOURCES); if ( !resource_tree ) _FATAL("XML document : " + TO_STD_STRING(RESOURCES_MAP) + " is not valid"); for ( pugi::xml_node child = resource_tree.first_child() ; child; child = child.next_sibling() ) { Resource * resource = NULL; std::string type = child.name(); assert( !type.empty() ); if ( pd->m_loaders.find(type) != pd->m_loaders.end() ) resource = pd->m_loaders[type]( &child ); assert(resource); incResCount( type ); for ( pugi::xml_attribute element_attrb = child.first_attribute(); element_attrb; element_attrb = element_attrb.next_attribute() ) { std::string attrb_name = element_attrb.name(); if ( attrb_name == FILENAME ) resource->setFilePath(element_attrb.as_string()); if ( attrb_name == RES_NAME ) resource->setName(element_attrb.as_string()); if ( attrb_name == GLOBAL ) resource->setGlobal( element_attrb.as_bool() ); } std::string file_path = resource->getFilePath(); if ( file_path == UNDEFINED || file_path.empty() ) { SAFE_DELETE(resource); continue; } std::string file_name = resource->getName(); if ( file_name == UNDEFINED || file_name.empty() ) resource->cutOutNameFromPath(); resource->setResourceType( type ); resource->setID( getNextResourceID() ); pd->m_resources.push_back( resource ); } }