本文整理汇总了C++中FileStreamPtr::addU8方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStreamPtr::addU8方法的具体用法?C++ FileStreamPtr::addU8怎么用?C++ FileStreamPtr::addU8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStreamPtr
的用法示例。
在下文中一共展示了FileStreamPtr::addU8方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveSpr
void SpriteManager::saveSpr(std::string fileName)
{
if(!m_loaded)
stdext::throw_exception("failed to save, spr is not loaded");
try {
FileStreamPtr fin = g_resources.createFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
fin->cache();
fin->addU32(m_signature);
if(g_game.getFeature(Otc::GameSpritesU32))
fin->addU32(m_spritesCount);
else
fin->addU16(m_spritesCount);
uint32 offset = fin->tell();
uint32 spriteAddress = offset + 4 * m_spritesCount;
for(int i = 1; i <= m_spritesCount; i++)
fin->addU32(0);
for(int i = 1; i <= m_spritesCount; i++) {
m_spritesFile->seek((i - 1) * 4 + m_spritesOffset);
uint32 fromAdress = m_spritesFile->getU32();
if(fromAdress != 0) {
fin->seek(offset + (i - 1) * 4);
fin->addU32(spriteAddress);
fin->seek(spriteAddress);
m_spritesFile->seek(fromAdress);
fin->addU8(m_spritesFile->getU8());
fin->addU8(m_spritesFile->getU8());
fin->addU8(m_spritesFile->getU8());
uint16 dataSize = m_spritesFile->getU16();
fin->addU16(dataSize);
char spriteData[SPRITE_DATA_SIZE];
m_spritesFile->read(spriteData, dataSize);
fin->write(spriteData, dataSize);
spriteAddress = fin->tell();
}
//TODO: Check for overwritten sprites.
}
fin->flush();
fin->close();
} catch(std::exception& e) {
g_logger.error(stdext::format("Failed to save '%s': %s", fileName, e.what()));
}
}
示例2: saveOtcm
void Map::saveOtcm(const std::string& fileName)
{
#if 0
try {
g_clock.update();
FileStreamPtr fin = g_resources.createFile(fileName);
fin->cache();
//TODO: compression flag with zlib
uint32 flags = 0;
// header
fin->addU32(OTCM_SIGNATURE);
fin->addU16(0); // data start, will be overwritten later
fin->addU16(OTCM_VERSION);
fin->addU32(flags);
// version 1 header
fin->addString("OTCM 1.0"); // map description
fin->addU32(g_things.getDatSignature());
fin->addU16(g_game.getClientVersion());
fin->addString(g_game.getWorldName());
// go back and rewrite where the map data starts
uint32 start = fin->tell();
fin->seek(4);
fin->addU16(start);
fin->seek(start);
for(auto& pair : m_tiles) {
const TilePtr& tile = pair.second;
if(!tile || tile->isEmpty())
continue;
Position pos = pair.first;
fin->addU16(pos.x);
fin->addU16(pos.y);
fin->addU8(pos.z);
const auto& list = tile->getThings();
auto first = std::find_if(list.begin(), list.end(), [](const ThingPtr& thing) { return thing->isItem(); });
for(auto it = first, end = list.end(); it != end; ++it) {
const ThingPtr& thing = *it;
if(thing->isItem()) {
ItemPtr item = thing->static_self_cast<Item>();
fin->addU16(item->getId());
fin->addU8(item->getCountOrSubType());
}
}
// end of tile
fin->addU16(0xFFFF);
}
// end of file
Position invalidPos;
fin->addU16(invalidPos.x);
fin->addU16(invalidPos.y);
fin->addU8(invalidPos.z);
fin->flush();
fin->close();
} catch(stdext::exception& e) {
g_logger.error(stdext::format("failed to save OTCM map: %s", e.what()));
}
#endif
}
示例3: saveOtcm
void Map::saveOtcm(const std::string& fileName)
{
try {
stdext::timer saveTimer;
FileStreamPtr fin = g_resources.createFile(fileName);
fin->cache();
//TODO: compression flag with zlib
uint32 flags = 0;
// header
fin->addU32(OTCM_SIGNATURE);
fin->addU16(0); // data start, will be overwritten later
fin->addU16(OTCM_VERSION);
fin->addU32(flags);
// version 1 header
fin->addString("OTCM 1.0"); // map description
fin->addU32(g_things.getDatSignature());
fin->addU16(g_game.getProtocolVersion());
fin->addString(g_game.getWorldName());
// go back and rewrite where the map data starts
uint32 start = fin->tell();
fin->seek(4);
fin->addU16(start);
fin->seek(start);
for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) {
for(const auto& it : m_tileBlocks[z]) {
const TileBlock& block = it.second;
for(const TilePtr& tile : block.getTiles()) {
if(!tile || tile->isEmpty())
continue;
Position pos = tile->getPosition();
fin->addU16(pos.x);
fin->addU16(pos.y);
fin->addU8(pos.z);
for(const ThingPtr& thing : tile->getThings()) {
if(thing->isItem()) {
ItemPtr item = thing->static_self_cast<Item>();
fin->addU16(item->getId());
fin->addU8(item->getCountOrSubType());
}
}
// end of tile
fin->addU16(0xFFFF);
}
}
}
// end of file
Position invalidPos;
fin->addU16(invalidPos.x);
fin->addU16(invalidPos.y);
fin->addU8(invalidPos.z);
fin->flush();
fin->close();
} catch(stdext::exception& e) {
g_logger.error(stdext::format("failed to save OTCM map: %s", e.what()));
}
}
示例4: serialize
void ThingType::serialize(const FileStreamPtr& fin)
{
for(int i = 0; i < ThingLastAttr; ++i) {
if(!hasAttr((ThingAttr)i))
continue;
int attr = i;
if(g_game.getClientVersion() >= 780) {
if(attr == ThingAttrChargeable)
attr = ThingAttrWritable;
else if(attr >= ThingAttrWritable)
attr += 1;
} else if(g_game.getClientVersion() >= 1000) {
if(attr == ThingAttrNoMoveAnimation)
attr = 16;
else if(attr >= ThingAttrPickupable)
attr += 1;
}
fin->addU8(attr);
switch(attr) {
case ThingAttrDisplacement: {
fin->addU16(m_displacement.x);
fin->addU16(m_displacement.y);
break;
}
case ThingAttrLight: {
Light light = m_attribs.get<Light>(attr);
fin->addU16(light.intensity);
fin->addU16(light.color);
break;
}
case ThingAttrMarket: {
MarketData market = m_attribs.get<MarketData>(attr);
fin->addU16(market.category);
fin->addU16(market.tradeAs);
fin->addU16(market.showAs);
fin->addString(market.name);
fin->addU16(market.restrictVocation);
fin->addU16(market.requiredLevel);
break;
}
case ThingAttrUsable:
case ThingAttrElevation:
case ThingAttrGround:
case ThingAttrWritable:
case ThingAttrWritableOnce:
case ThingAttrMinimapColor:
case ThingAttrCloth:
case ThingAttrLensHelp:
fin->addU16(m_attribs.get<uint16>(attr));
break;
default:
break;
};
}
fin->addU8(ThingLastAttr);
fin->addU8(m_size.width());
fin->addU8(m_size.height());
if(m_size.width() > 1 || m_size.height() > 1)
fin->addU8(m_realSize);
fin->addU8(m_layers);
fin->addU8(m_numPatternX);
fin->addU8(m_numPatternY);
fin->addU8(m_numPatternZ);
fin->addU8(m_animationPhases);
if(g_game.getFeature(Otc::GameEnhancedAnimations)) {
if(m_animationPhases > 1 && m_animator != nullptr) {
m_animator->serialize(fin);
}
}
for(uint i = 0; i < m_spritesIndex.size(); i++) {
if(g_game.getFeature(Otc::GameSpritesU32))
fin->addU32(m_spritesIndex[i]);
else
fin->addU16(m_spritesIndex[i]);
}
}