本文整理汇总了C++中BinaryNode::skip方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryNode::skip方法的具体用法?C++ BinaryNode::skip怎么用?C++ BinaryNode::skip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryNode
的用法示例。
在下文中一共展示了BinaryNode::skip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getVersionInfo
ClientVersionID IOMapOTMM::getVersionInfo(const FileName& filename)
{
wxString wpath = filename.GetFullPath();
DiskNodeFileReadHandle f((const char*)wpath.mb_str(wxConvUTF8));
if(f.isOk() == false) {
return CLIENT_VERSION_NONE;
}
BinaryNode* root = f.getRootNode();
if(!root) {return CLIENT_VERSION_NONE;}
root->skip(1); // Skip the type byte
uint16_t u16;
uint32_t u32;
if(!root->getU32(u32) || u32 != 1) { // Version
return CLIENT_VERSION_NONE;
}
root->getU16(u16);
root->getU16(u16);
root->getU32(u32);
if(root->getU32(u32)) { // OTB minor version
return ClientVersionID(u32);
}
return CLIENT_VERSION_NONE;
}
示例2: loadFromOtb
bool ItemDatabase::loadFromOtb(const FileName& datafile, wxString& error, wxArrayString& warnings)
{
std::string filename = nstr((datafile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + datafile.GetFullName()));
DiskNodeFileReadHandle f(filename, StringVector(1, "OTBI"));
if(!f.isOk()) {
error = wxT("Couldn't open file \"") + wxstr(filename) + wxT("\":") + wxstr(f.getErrorMessage());
return false;
}
BinaryNode* root = f.getRootNode();
#define safe_get(node, func, ...) do {\
if(!node->get##func(__VA_ARGS__)) {\
error = wxstr(f.getErrorMessage()); \
return false; \
} \
} while(false)
// Read root flags
root->skip(1); // Type info
//uint32_t flags =
root->skip(4); // Unused?
uint8_t attr;
safe_get(root, U8, attr);
if(attr == ROOT_ATTR_VERSION) {
uint16_t datalen;
if(!root->getU16(datalen) || datalen != 4 + 4 + 4 + 1*128) {
error = wxT("items.otb: Size of version header is invalid, updated .otb version?");
return false;
}
safe_get(root, U32, MajorVersion); // items otb format file version
safe_get(root, U32, MinorVersion); // client version
safe_get(root, U32, BuildNumber); // revision
std::string csd;
csd.resize(128);
if(!root->getRAW((uint8_t*)csd.data(), 128)) { // CSDVersion ??
error = wxstr(f.getErrorMessage());
return false;
}
} else {
error = wxT("Expected ROOT_ATTR_VERSION as first node of items.otb!");
}
if(settings.getInteger(Config::CHECK_SIGNATURES)) {
if(gui.GetCurrentVersion().getOTBVersion().format_version != MajorVersion) {
error = wxT("Unsupported items.otb version (version ") + i2ws(MajorVersion) + wxT(")");
return false;
}
}
BinaryNode* itemNode = root->getChild();
switch(MajorVersion) {
case 1: return loadFromOtbVer1(itemNode, error, warnings);
case 2: return loadFromOtbVer2(itemNode, error, warnings);
case 3: return loadFromOtbVer3(itemNode, error, warnings);
}
return true;
}
示例3: loadMap
bool IOMapOTMM::loadMap(Map& map, NodeFileReadHandle& f, const FileName& identifier, bool showdialog) {
BinaryNode* root = f.getRootNode();
if(!root) {
error(wxT("Could not read root node."));
return false;
}
root->skip(1); // Skip the type byte
uint8_t u8;
uint16_t u16;
uint32_t u32;
if(!root->getU32(u32) || u32 != 1) { // Version
error(wxT("Unsupported or damaged map version."));
return false;
}
if(!root->getU16(u16)) {
error(wxT("Could not read root header."));
return false;
}
map.width = u16;
if(!root->getU16(u16)) {
error(wxT("Could not read root header."));
return false;
}
map.height = u16;
if(!root->getU32(u32) || u32 > (unsigned long)item_db.MajorVersion) { // OTB major version
if(queryUser(wxT("Map error"), wxT("The loaded map appears to be a items.otb format that deviates from the items.otb loaded by the editor. Do you still want to attempt to load the map?"))) {
warning(wxT("Unsupported or damaged map version"));
} else {
error(wxT("Outdated items.otb, could not load map."));
return false;
}
}
if(!root->getU32(u32) || u32 > (unsigned long)item_db.MinorVersion) { // OTB minor version
warning(wxT("The editor needs an updated items.otb version."));
}
BinaryNode* mapHeaderNode = root->getChild();
if(mapHeaderNode == NULL || !mapHeaderNode->getByte(u8) || u8 != OTMM_MAP_DATA) {
error(wxT("Could not get root child node. Cannot recover from fatal error!"));
return false;
}
int nodes_loaded = 0;
BinaryNode* mapNode = mapHeaderNode->getChild();
if(mapNode) do {
++nodes_loaded;
if(showdialog && nodes_loaded % 15 == 0) {
gui.SetLoadDone(int(100.0 * f.tell() / f.size()));
}
uint8_t node_type;
if(!mapNode->getByte(node_type)) {
warning(wxT("Invalid map node"));
continue;
}
switch(node_type) {
case OTMM_EDITOR: {
} break;
case OTMM_DESCRIPTION: {
std::string desc;
mapNode->getString(desc);
map.setMapDescription(desc);
} break;
case OTMM_TILE_DATA: {
BinaryNode* tileNode = mapNode->getChild();
if(tileNode) do {
Tile* tile = NULL;
uint8_t tile_type;
if(!tileNode->getByte(tile_type)) {
warning(wxT("Invalid tile type"));
continue;
}
if(tile_type != OTMM_TILE && tile_type != OTMM_HOUSETILE) {
warning(wxT("Unknown type of tile node"));
continue;
}
uint16_t x_offset, y_offset;
uint8_t z_offset;
if(!tileNode->getU16(x_offset) ||
!tileNode->getU16(y_offset) ||
!tileNode->getU8(z_offset)
)
{
warning(wxT("Could not read position of tile"));
continue;
}
const Position pos(x_offset, y_offset, z_offset);
if(map.getTile(pos)) {
warning(wxT("Duplicate tile at %d:%d:%d, discarding duplicate"), pos.x, pos.y, pos.z);
continue;
}
//.........这里部分代码省略.........