本文整理汇总了C++中MMap::GetMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ MMap::GetMemory方法的具体用法?C++ MMap::GetMemory怎么用?C++ MMap::GetMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MMap
的用法示例。
在下文中一共展示了MMap::GetMemory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
SpritePack *SpriteLoader::Load(const std::string &pack)
{
auto loaded_it = loaded_packs_.find(pack);
if (loaded_it != loaded_packs_.end())
return loaded_it->second.get();
fs::path pack_folder = fs::current_path() / "Assets" / "Sprites" / pack;
fs::path desc_path = pack_folder / "Pack.toml";
MMap mmap;
if (!mmap.Open(desc_path))
{
auto msg = "Failed to open pack `" + pack +
"` (" + desc_path.generic_string() + ")";
throw std::runtime_error{ msg };
}
auto config = TOML::Value::Parse((const char *)mmap.GetMemory(), mmap.GetLength());
auto &config_root = config->GetTable();
// Read the Pack info
auto &pack_desc = config_root["Pack"]->GetTable();
auto pack_type_str = pack_desc["Type"]->GetString();
SpritePackType pack_type;
if (pack_type_str == "Sprites")
pack_type = SpritePackType::Sprites;
else if (pack_type_str == "AnimatedGif")
pack_type = SpritePackType::AnimatedGif;
else
throw std::runtime_error{ "Pack `" + pack + "` has an invalid Pack.Type" };
// Read in the sprite list / animated gif
std::unique_ptr<SpritePack> pack_ptr;
if (pack_type == SpritePackType::Sprites)
{
pack_ptr = SpritePack::LoadPack(device_.p, pack_folder, config_root);
}
else if (pack_type == SpritePackType::AnimatedGif)
{
pack_ptr = GifPack::LoadGif(device_.p, pack_folder, config_root);
}
auto ppack = pack_ptr.get();
loaded_packs_[pack] = std::move(pack_ptr);
return ppack;
}