Ejemplo n.º 1
0
Ref<Material> Material::read(RenderContext& context, const std::string& name)
{
  initializeMaps();

  if (Material* cached = context.cache().find<Material>(name))
    return cached;

  const Path path = context.cache().findFile(name);
  if (path.isEmpty())
  {
    logError("Failed to find material %s", name.c_str());
    return nullptr;
  }

  pugi::xml_document document;

  const pugi::xml_parse_result result = document.load_file(path.name().c_str());
  if (!result)
  {
    logError("Failed to load material %s: %s",
             name.c_str(),
             result.description());
    return nullptr;
  }

  pugi::xml_node root = document.child("material");
  if (!root || root.attribute("version").as_uint() != MATERIAL_XML_VERSION)
  {
    logError("Material file format mismatch in %s", name.c_str());
    return nullptr;
  }

  Ref<Material> material = Material::create(ResourceInfo(context.cache(), name, path), context);

  for (auto pn : root.children("pass"))
  {
    const std::string phaseName(pn.attribute("phase").value());
    if (!phaseMap.hasKey(phaseName))
    {
      logError("Invalid render phase %s in material %s",
               phaseName.c_str(),
               name.c_str());
      return nullptr;
    }

    if (!parsePass(context, material->pass(phaseMap[phaseName]), pn))
    {
      logError("Failed to parse pass for material %s", name.c_str());
      return nullptr;
    }
  }

  return material;
}
Ejemplo n.º 2
0
Ref<Font> Font::read(RenderContext& context, const std::string& name)
{
  if (Font* cached = context.cache().find<Font>(name))
    return cached;

  const Path path = context.cache().findFile(name);
  if (path.isEmpty())
  {
    logError("Failed to find font %s", name.c_str());
    return nullptr;
  }

  pugi::xml_document document;

  const pugi::xml_parse_result result = document.load_file(path.name().c_str());
  if (!result)
  {
    logError("Failed to load font %s: %s",
             name.c_str(),
             result.description());
    return nullptr;
  }

  pugi::xml_node root = document.child("font");
  if (!root || root.attribute("version").as_uint() != FONT_XML_VERSION)
  {
    logError("Font file format mismatch in %s", name.c_str());
    return nullptr;
  }

  const std::string faceName(root.attribute("face").value());
  if (faceName.empty())
  {
    logError("No typeface specified for font %s", faceName.c_str());
    return nullptr;
  }

  const uint height = root.attribute("height").as_uint();

  Ref<Face> face = Face::read(context.cache(), faceName);
  if (!face)
    return nullptr;

  return create(ResourceInfo(context.cache(), name, path),
                context, *face, height);
}
Ejemplo n.º 3
0
Ref<Font> FontReader::read(const String& name, const Path& path)
{
  std::ifstream stream(path.name().c_str());
  if (stream.fail())
  {
    logError("Failed to open font %s", name.c_str());
    return nullptr;
  }

  pugi::xml_document document;

  const pugi::xml_parse_result result = document.load(stream);
  if (!result)
  {
    logError("Failed to load font %s: %s",
             name.c_str(),
             result.description());
    return nullptr;
  }

  pugi::xml_node root = document.child("font");
  if (!root || root.attribute("version").as_uint() != FONT_XML_VERSION)
  {
    logError("Font file format mismatch in %s", name.c_str());
    return nullptr;
  }

  const String faceName(root.attribute("face").value());
  if (faceName.empty())
  {
    logError("No typeface specified for font %s", faceName.c_str());
    return nullptr;
  }

  const uint height = root.attribute("height").as_uint();

  Ref<Face> face = Face::read(cache, faceName);
  if (!face)
    return nullptr;

  return Font::create(ResourceInfo(cache, name, path), *m_pool, *face, height);
}
Ejemplo n.º 4
0
wex::log::log(const pugi::xml_parse_result& r, level_t level)
  : m_level(level)
{
  if (r.status != pugi::xml_parse_status::status_ok)
  {
    m_ss << 
      "xml parse result:" << S() << r.description() << S() <<
      "at offset:" << S() << r.offset;
  }
  else 
  {
    m_level = VERBOSE;
    m_separator = false;
  }
}
Ejemplo n.º 5
0
namespace GM
{
	
	pugi::xml_parse_result m_system_config;
	pugi::xml_document m_system_doc;

	int LoadConfig(const char* filename)
	{
		m_system_config = m_system_doc.load_file(filename);
		cout << "xml loaded: "<<filename<<" -> "<<m_system_config.description()<<endl;
		return EXIT_SUCCESS;
	}
	const pugi::char_t* GetValue(const char* name)
	{
		return m_system_doc.child(name).child_value();
	}
}
Ejemplo n.º 6
0
	int LoadConfig(const char* filename)
	{
		m_system_config = m_system_doc.load_file(filename);
		cout << "xml loaded: "<<filename<<" -> "<<m_system_config.description()<<endl;
		return EXIT_SUCCESS;
	}
Ejemplo n.º 7
0
    void PugiXMLParseResultPrettifier ( const pugi::xml_parse_result& aLoadResult , const boost::filesystem::path& aPath , const std::vector<uint8_t>& aFile )
    {
      log ( Error() , "Failed to parse file " , aPath.c_str() , ". PugiXML returned the following description " , Quote ( aLoadResult.description() ) , "." );
      std::size_t lLineCounter ( 1 );
      std::vector<uint8_t>::const_iterator lIt0 ( aFile.begin() );
      std::vector<uint8_t>::const_iterator lIt1 ( aFile.begin() + aLoadResult.offset );
      std::vector<uint8_t>::const_iterator lIt2 ( lIt1 );

      for ( ; lIt0!=lIt1 ; ++lIt0 )
      {
        if ( *lIt0 == '\n' )
        {
          lLineCounter++;
        }
      }

      for ( ; lIt1 != aFile.begin() ; --lIt1 )
      {
        if ( *lIt1 == '\n' )
        {
          ++lIt1;
          break;
        }
      }

      for ( ; lIt2 != aFile.end() ; ++lIt2 )
      {
        if ( *lIt2 == '\n' )
        {
          --lIt2;
          break;
        }
      }

      std::size_t lDist0 ( lIt0 - lIt1 );
      std::size_t lDist1 ( lIt2 - lIt0 );
      std::string lLine;
      lLine.reserve ( lIt2 - lIt1 );

      for ( ; lIt1 != lIt2 ; ++lIt1 )
      {
        if ( isprint ( *lIt1 ) || *lIt1==10 )
        {
          lLine += *lIt1;
        }
        else
        {
          lLine += '#';
        }
      }

      log ( Error() , "Error occured at line number " , Integer ( lLineCounter ) ,
            ", character " , Integer ( lDist0+1 ) , "\n"
            "LINE           : " , lLine , "\n"
            "ERROR LOCATION : " , std::string ( lDist0 , '_' ) , "^" , std::string ( lDist1 , '_' ) );
    }