当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryNode::getByte方法代码示例

本文整理汇总了C++中BinaryNode::getByte方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryNode::getByte方法的具体用法?C++ BinaryNode::getByte怎么用?C++ BinaryNode::getByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryNode的用法示例。


在下文中一共展示了BinaryNode::getByte方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: unserializeItemNode_OTMM

bool Container::unserializeItemNode_OTMM(const IOMap& maphandle, BinaryNode* node)
{
	bool ret = Item::unserializeAttributes_OTMM(maphandle, node);

	if(ret) {
		BinaryNode* child = node->getChild();
		if(child) do {
			uint8_t type;
			if(!child->getByte(type)) {
				return false;
			}
			//load container items
			if(type == OTMM_ITEM) {
				Item* item = Item::Create_OTMM(maphandle, child);
				if(!item) {
					return false;
				}
				if(!item->unserializeItemNode_OTMM(maphandle, child)) {
					delete item;
					return false;
				}
				contents.push_back(item);
			} else {
				// corrupted file data!
				return false;
			}
		} while(child->advance());
		return true;
	}
	return false;
}
开发者ID:mattyx14,项目名称:rme,代码行数:31,代码来源:iomap_otmm.cpp

示例2: readTile

Tile* LiveSocket::readTile(BinaryNode* node, Editor& editor, const Position* position)
{
	ASSERT(node != nullptr);

	Map& map = editor.map;

	uint8_t tileType;
	node->getByte(tileType);

	if(tileType != OTBM_TILE && tileType != OTBM_HOUSETILE) {
		return nullptr;
	}

	Position pos;
	if(position) {
		pos = *position;
	} else {
		uint16_t x; node->getU16(x); pos.x = x;
		uint16_t y; node->getU16(y); pos.y = y;
		uint8_t z; node->getU8(z); pos.z = z;
	}

	Tile* tile = map.allocator(
		map.createTileL(pos)
	);

	if(tileType == OTBM_HOUSETILE) {
		uint32_t houseId;
		if(!node->getU32(houseId)) {
			//warning(wxT("House tile without house data, discarding tile"));
			delete tile;
			return nullptr;
		}

		if(houseId) {
			House* house = map.houses.getHouse(houseId);
			if(house) {
				tile->setHouse(house);
			}
		} else {
			//warning(wxT("Invalid house id from tile %d:%d:%d"), pos.x, pos.y, pos.z);
		}
	}

	uint8_t attribute;
	while(node->getU8(attribute)) {
		switch (attribute) {
			case OTBM_ATTR_TILE_FLAGS: {
				uint32_t flags = 0;
				if(!node->getU32(flags)) {
					//warning(wxT("Invalid tile flags of tile on %d:%d:%d"), pos.x, pos.y, pos.z);
				}
				tile->setMapFlags(flags);
				break;
			}
			case OTBM_ATTR_ITEM: {
				Item* item = Item::Create_OTBM(mapVersion, node);
				if(!item) {
					//warning(wxT("Invalid item at tile %d:%d:%d"), pos.x, pos.y, pos.z);
				}
				tile->addItem(item);
				break;
			}
			default:
				//warning(wxT("Unknown tile attribute at %d:%d:%d"), pos.x, pos.y, pos.z);
				break;
		}
	}

	//for(BinaryNode* itemNode = node->getChild(); itemNode; itemNode->advance()) {
	BinaryNode* itemNode = node->getChild();
	if(itemNode) do {
		uint8_t itemType;
		if(!itemNode->getByte(itemType)) {
			//warning(wxT("Unknown item type %d:%d:%d"), pos.x, pos.y, pos.z);
			delete tile;
			return nullptr;
		}

		if(itemType == OTBM_ITEM) {
			Item* item = Item::Create_OTBM(mapVersion, itemNode);
			if(item) {
				if(!item->unserializeItemNode_OTBM(mapVersion, itemNode)) {
					//warning(wxT("Couldn't unserialize item attributes at %d:%d:%d"), pos.x, pos.y, pos.z);
				}
				tile->addItem(item);
			}
		} else {
			//warning(wxT("Unknown type of tile child node"));
		}
	//}
	} while(itemNode->advance());

	return tile;
}
开发者ID:Codex-NG,项目名称:rme,代码行数:95,代码来源:live_socket.cpp

示例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;
					}
					
//.........这里部分代码省略.........
开发者ID:mattyx14,项目名称:rme,代码行数:101,代码来源:iomap_otmm.cpp


注:本文中的BinaryNode::getByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。