本文整理汇总了C++中AssetManager::OpenStream方法的典型用法代码示例。如果您正苦于以下问题:C++ AssetManager::OpenStream方法的具体用法?C++ AssetManager::OpenStream怎么用?C++ AssetManager::OpenStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetManager
的用法示例。
在下文中一共展示了AssetManager::OpenStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Reset
//-----------------------------------------------------------------------
void TrueTypeFont::Impl::LoadFont(AssetManager const& assets, std::string const& fontPath)
{
auto binaryFile = assets.OpenStream(fontPath);
if (!binaryFile.Stream) {
POMDOG_THROW_EXCEPTION(std::runtime_error, "Failed to open file");
}
if (binaryFile.SizeInBytes <= 0) {
POMDOG_THROW_EXCEPTION(std::runtime_error, "The file is too small");
}
Reset();
using Pomdog::Detail::BinaryReader;
ttfBinary = BinaryReader::ReadArray<std::uint8_t>(binaryFile.Stream, binaryFile.SizeInBytes);
const auto offset = stbtt_GetFontOffsetForIndex(ttfBinary.data(), 0);
if (!stbtt_InitFont(&fontInfo, ttfBinary.data(), offset)) {
ttfBinary.clear();
// FUS RO DAH
POMDOG_THROW_EXCEPTION(std::runtime_error,
"Failed to initialize truetype font");
}
}
示例2: LoadFromJson
ParticleClip ParticleLoader::LoadFromJson(AssetManager & assets, std::string const& assetName)
{
POMDOG_ASSERT(!assetName.empty());
using Detail::BinaryReader;
auto binaryFile = assets.OpenStream(assetName);
if (!binaryFile.Stream) {
POMDOG_THROW_EXCEPTION(std::runtime_error, "Failed to open file");
}
if (binaryFile.SizeInBytes <= 0) {
POMDOG_THROW_EXCEPTION(std::runtime_error, "The file is too small");
}
auto json = BinaryReader::ReadString<char>(binaryFile.Stream, binaryFile.SizeInBytes);
POMDOG_ASSERT(!json.empty());
if (json.empty()) {
POMDOG_THROW_EXCEPTION(std::runtime_error, "The file is too small");
}
rapidjson::Document doc;
doc.Parse(json.data());
if (doc.HasParseError() || !doc.IsObject() || doc.MemberBegin() == doc.MemberEnd()) {
// FUS RO DAH
POMDOG_THROW_EXCEPTION(std::runtime_error, "Failed to parse JSON");
}
auto member = doc.MemberBegin();
if (!member->name.IsString() || !member->value.IsObject()) {
// FUS RO DAH
POMDOG_THROW_EXCEPTION(std::runtime_error, "Invalid file format");
}
POMDOG_ASSERT(member->name.IsString());
POMDOG_ASSERT(member->value.IsObject());
return ReadParticleClip(member->value);
}