本文整理汇总了C++中BinaryNode::getChild方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryNode::getChild方法的具体用法?C++ BinaryNode::getChild怎么用?C++ BinaryNode::getChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryNode
的用法示例。
在下文中一共展示了BinaryNode::getChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receiveFloor
void LiveSocket::receiveFloor(NetworkMessage& message, Editor& editor, Action* action, int32_t ndx, int32_t ndy, int32_t z, QTreeNode* node, Floor* floor)
{
Map& map = editor.map;
uint16_t tileBits = message.read<uint16_t>();
if(tileBits == 0) {
for(uint_fast8_t x = 0; x < 4; ++x) {
for(uint_fast8_t y = 0; y < 4; ++y) {
action->addChange(new Change(map.allocator(node->createTile(ndx * 4 + x, ndy * 4 + y, z))));
}
}
return;
}
// -1 on address since we skip the first START_NODE when sending
const std::string& data = message.read<std::string>();
mapReader.assign(reinterpret_cast<const uint8_t*>(data.c_str() - 1), data.size());
BinaryNode* rootNode = mapReader.getRootNode();
BinaryNode* tileNode = rootNode->getChild();
Position position(0, 0, z);
for(uint_fast8_t x = 0; x < 4; ++x) {
for(uint_fast8_t y = 0; y < 4; ++y) {
position.x = (ndx * 4) + x;
position.y = (ndy * 4) + y;
if(testFlags(tileBits, 1 << ((x * 4) + y))) {
receiveTile(tileNode, editor, action, &position);
tileNode->advance();
} else {
action->addChange(new Change(map.allocator(node->createTile(position.x, position.y, z))));
}
}
}
mapReader.close();
}
示例2: OnReceiveChanges
void LiveServer::OnReceiveChanges(LivePeer* connection, NetworkMessage* nmsg)
{
std::string data = nmsg->ReadString();
// -1 on address since we skip the first START_NODE when sending
bn_reader.assign((uint8_t*)data.c_str() - 1, data.size());
BinaryNode* rootNode = bn_reader.getRootNode();
BinaryNode* tileNode = rootNode->getChild();
NetworkedAction* action = dynamic_cast<NetworkedAction*>(editor->actionQueue->createAction(ACTION_REMOTE));
action->owner = connection->GetClientID();
if (tileNode) do
{
Tile* t = ReadTile(tileNode, editor->map);
if(!t) continue;
action->addChange(newd Change(t));
} while (tileNode->advance());
bn_reader.close();
editor->actionQueue->addAction(action);
gui.RefreshView();
}
示例3: 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;
}
示例4: 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;
}
//.........这里部分代码省略.........