本文整理汇总了C++中FileLoader::getChildNode方法的典型用法代码示例。如果您正苦于以下问题:C++ FileLoader::getChildNode方法的具体用法?C++ FileLoader::getChildNode怎么用?C++ FileLoader::getChildNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileLoader
的用法示例。
在下文中一共展示了FileLoader::getChildNode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unserializeItemNode
bool Container::unserializeItemNode(FileLoader& f, NODE node, PropStream& propStream)
{
if(!Item::unserializeItemNode(f, node, propStream))
return false;
uint32_t type;
for(NODE nodeItem = f.getChildNode(node, type); nodeItem; nodeItem = f.getNextNode(nodeItem, type))
{
//load container items
if(type != OTBM_ITEM)
return false;
PropStream itemPropStream;
f.getProps(nodeItem, itemPropStream);
Item* item = Item::CreateItem(itemPropStream);
if(!item)
return false;
if(!item->unserializeItemNode(f, nodeItem, itemPropStream))
return false;
addItem(item);
updateItemWeight(item->getWeight());
}
return true;
}
示例2: unserializeItemNode
bool Container::unserializeItemNode(FileLoader& f, NODE node, PropStream& propStream)
{
bool ret = Item::unserializeItemNode(f, node, propStream);
if(ret){
unsigned long type;
NODE nodeItem = f.getChildNode(node, type);
while(nodeItem){
//load container items
if(type == OTBM_ITEM){
PropStream itemPropStream;
f.getProps(nodeItem, itemPropStream);
Item* item = Item::CreateItem(itemPropStream);
if(!item){
return false;
}
if(!item->unserializeItemNode(f, nodeItem, itemPropStream)){
return false;
}
addItem(item);
}
else /*unknown type*/
return false;
nodeItem = f.getNextNode(nodeItem, type);
}
return true;
}
return false;
}
示例3: unserializeItemNode
bool Container::unserializeItemNode(FileLoader& f, NODE node, PropStream& propStream)
{
bool ret = Item::unserializeItemNode(f, node, propStream);
if(ret){
unsigned long type;
NODE nodeItem = f.getChildNode(node, type);
while(nodeItem){
//load container items
if(type == OTBM_ITEM){
PropStream itemPropStream;
f.getProps(nodeItem, itemPropStream);
Item* item = Item::CreateItem(itemPropStream);
if(!item){
return false;
}
if(!item->unserializeItemNode(f, nodeItem, itemPropStream)){
return false;
}
addItem(item);
//deepness
if (item->getContainer()){
if (getParentContainer())
item->getContainer()->setDeepness(getDeepness() + 1);
else{ //we only update deepness when a container get inside of another, so it means that deepness is not updated
setDeepness(1);
item->getContainer()->setDeepness(2);
}
}
updateAmountOfItems(item->getTotalAmountOfItemsInside());
total_weight += item->getWeight();
if(Container* parent_container = getParentContainer()) {
parent_container->updateItemWeight(item->getWeight());
}
}
else /*unknown type*/
return false;
nodeItem = f.getNextNode(nodeItem, type);
}
return true;
}
return false;
}
示例4: unserializeItemNode
bool Container::unserializeItemNode(FileLoader& f, NODE node, PropStream& propStream)
{
bool ret = Item::unserializeItemNode(f, node, propStream);
if (!ret) {
return false;
}
uint32_t type;
NODE nodeItem = f.getChildNode(node, type);
while (nodeItem) {
//load container items
if (type != OTBM_ITEM) {
// unknown type
return false;
}
PropStream itemPropStream;
if (!f.getProps(nodeItem, itemPropStream)) {
return false;
}
Item* item = Item::CreateItem(itemPropStream);
if (!item) {
return false;
}
if (!item->unserializeItemNode(f, nodeItem, itemPropStream)) {
return false;
}
addItem(item);
totalWeight += item->getWeight();
if (Container* parent_container = getParentContainer()) {
parent_container->updateItemWeight(item->getWeight());
}
nodeItem = f.getNextNode(nodeItem, type);
}
return true;
}
示例5: unserializeItemNode
bool Container::unserializeItemNode(FileLoader& f, NODE node, PropStream& propStream)
{
if(Item::unserializeItemNode(f, node, propStream))
{
uint32_t type;
NODE nodeItem = f.getChildNode(node, type);
while(nodeItem)
{
//load container items
if(type == OTBM_ITEM)
{
PropStream itemPropStream;
f.getProps(nodeItem, itemPropStream);
Item* item = Item::CreateItem(itemPropStream);
if(!item)
return false;
if(!item->unserializeItemNode(f, nodeItem, itemPropStream))
return false;
addItem(item);
totalWeight += item->getWeight();
if(Container* parent = getParentContainer())
parent->updateItemWeight(item->getWeight());
}
else/*unknown type*/
return false;
nodeItem = f.getNextNode(nodeItem, type);
}
return true;
}
return false;
}
示例6: loadFromOtb
FILELOADER_ERRORS Items::loadFromOtb(const std::string& file)
{
FileLoader f;
if (!f.openFile(file.c_str(), "OTBI")) {
return f.getError();
}
uint32_t type;
NODE node = f.getChildNode(NO_NODE, type);
PropStream props;
if (f.getProps(node, props)) {
//4 byte flags
//attributes
//0x01 = version data
uint32_t flags;
if (!props.read<uint32_t>(flags)) {
return ERROR_INVALID_FORMAT;
}
uint8_t attr;
if (!props.read<uint8_t>(attr)) {
return ERROR_INVALID_FORMAT;
}
if (attr == ROOT_ATTR_VERSION) {
uint16_t datalen;
if (!props.read<uint16_t>(datalen)) {
return ERROR_INVALID_FORMAT;
}
if (datalen != sizeof(VERSIONINFO)) {
return ERROR_INVALID_FORMAT;
}
VERSIONINFO vi;
if (!props.read(vi)) {
return ERROR_INVALID_FORMAT;
}
Items::dwMajorVersion = vi.dwMajorVersion; //items otb format file version
Items::dwMinorVersion = vi.dwMinorVersion; //client version
Items::dwBuildNumber = vi.dwBuildNumber; //revision
}
}
if (Items::dwMajorVersion == 0xFFFFFFFF) {
std::cout << "[Warning - Items::loadFromOtb] items.otb using generic client version." << std::endl;
} else if (Items::dwMajorVersion != 2) {
std::cout << "Old version detected, a newer version of items.otb is required." << std::endl;
return ERROR_INVALID_FORMAT;
} else if (Items::dwMinorVersion < CLIENT_VERSION_800) {
std::cout << "A newer version of items.otb is required." << std::endl;
return ERROR_INVALID_FORMAT;
}
node = f.getChildNode(node, type);
while (node != NO_NODE) {
PropStream stream;
if (!f.getProps(node, stream)) {
return f.getError();
}
uint32_t flags;
if (!stream.read<uint32_t>(flags)) {
return ERROR_INVALID_FORMAT;
}
uint16_t serverId = 0;
uint16_t clientId = 0;
uint16_t speed = 0;
uint16_t wareId = 0;
uint8_t lightLevel = 0;
uint8_t lightColor = 0;
uint8_t alwaysOnTopOrder = 0;
uint8_t attrib;
while (stream.read<uint8_t>(attrib)) {
uint16_t datalen;
if (!stream.read<uint16_t>(datalen)) {
return ERROR_INVALID_FORMAT;
}
switch (attrib) {
case ITEM_ATTR_SERVERID: {
if (datalen != sizeof(uint16_t)) {
return ERROR_INVALID_FORMAT;
}
if (!stream.read<uint16_t>(serverId)) {
return ERROR_INVALID_FORMAT;
}
if (serverId > 30000 && serverId < 30100) {
serverId -= 30000;
}
break;
}
case ITEM_ATTR_CLIENTID: {
//.........这里部分代码省略.........
示例7: loadMap
bool IOMap::loadMap(Map* map, const std::string& identifier)
{
FileLoader f;
if(!f.openFile(identifier.c_str(), false, true))
{
std::stringstream ss;
ss << "Could not open the file " << identifier << ".";
setLastErrorString(ss.str());
return false;
}
uint32_t type = 0;
NODE root = f.getChildNode((NODE)NULL, type);
PropStream propStream;
if(!f.getProps(root, propStream))
{
setLastErrorString("Could not read root property.");
return false;
}
OTBM_root_header* rootHeader;
if(!propStream.GET_STRUCT(rootHeader))
{
setLastErrorString("Could not read header.");
return false;
}
uint32_t headerVersion = rootHeader->version;
if(headerVersion <= 0)
{
//In otbm version 1 the count variable after splashes/fluidcontainers and stackables
//are saved as attributes instead, this solves alot of problems with items
//that is changed (stackable/charges/fluidcontainer/splash) during an update.
setLastErrorString("This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if(headerVersion > 2)
{
setLastErrorString("Unknown OTBM version detected.");
return false;
}
uint32_t headerMajorItems = rootHeader->majorVersionItems;
if(headerMajorItems < 3)
{
setLastErrorString("This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if(headerMajorItems > (uint32_t)Items::dwMajorVersion)
{
setLastErrorString("The map was saved with a different items.otb version, an upgraded items.otb is required.");
return false;
}
uint32_t headerMinorItems = rootHeader->minorVersionItems;
if(headerMinorItems < CLIENT_VERSION_810)
{
setLastErrorString("This map needs an updated items.otb.");
return false;
}
if(headerMinorItems > (uint32_t)Items::dwMinorVersion)
setLastErrorString("This map needs an updated items.otb.");
std::cout << "> Map size: " << rootHeader->width << "x" << rootHeader->height << "." << std::endl;
map->mapWidth = rootHeader->width;
map->mapHeight = rootHeader->height;
NODE nodeMap = f.getChildNode(root, type);
if(type != OTBM_MAP_DATA)
{
setLastErrorString("Could not read data node.");
return false;
}
if(!f.getProps(nodeMap, propStream))
{
setLastErrorString("Could not read map data attributes.");
return false;
}
std::string tmp;
uint8_t attribute;
while(propStream.GET_UCHAR(attribute))
{
switch(attribute)
{
case OTBM_ATTR_DESCRIPTION:
{
if(!propStream.GET_STRING(tmp))
{
setLastErrorString("Invalid description tag.");
return false;
}
map->descriptions.push_back(tmp);
break;
//.........这里部分代码省略.........
示例8: loadMap
bool IOMap::loadMap(Map* map, const std::string& identifier)
{
int64_t start = OTSYS_TIME();
FileLoader f;
if (!f.openFile(identifier.c_str(), "OTBM")) {
std::ostringstream ss;
ss << "Could not open the file " << identifier << '.';
setLastErrorString(ss.str());
return false;
}
uint32_t type;
PropStream propStream;
NODE root = f.getChildNode(nullptr, type);
if (!f.getProps(root, propStream)) {
setLastErrorString("Could not read root property.");
return false;
}
const OTBM_root_header* root_header;
if (!propStream.readStruct(root_header)) {
setLastErrorString("Could not read header.");
return false;
}
uint32_t headerVersion = root_header->version;
if (headerVersion <= 0) {
//In otbm version 1 the count variable after splashes/fluidcontainers and stackables
//are saved as attributes instead, this solves alot of problems with items
//that is changed (stackable/charges/fluidcontainer/splash) during an update.
setLastErrorString("This map need to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if (headerVersion > 2) {
setLastErrorString("Unknown OTBM version detected.");
return false;
}
if (root_header->majorVersionItems < 3) {
setLastErrorString("This map need to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if (root_header->majorVersionItems > Items::dwMajorVersion) {
setLastErrorString("The map was saved with a different items.otb version, an upgraded items.otb is required.");
return false;
}
if (root_header->minorVersionItems < CLIENT_VERSION_810) {
setLastErrorString("This map needs to be updated.");
return false;
}
if (root_header->minorVersionItems > Items::dwMinorVersion) {
std::cout << "[Warning - IOMap::loadMap] This map needs an updated items.otb." << std::endl;
}
std::cout << "> Map size: " << root_header->width << "x" << root_header->height << '.' << std::endl;
map->width = root_header->width;
map->height = root_header->height;
NODE nodeMap = f.getChildNode(root, type);
if (type != OTBM_MAP_DATA) {
setLastErrorString("Could not read data node.");
return false;
}
if (!f.getProps(nodeMap, propStream)) {
setLastErrorString("Could not read map data attributes.");
return false;
}
std::string mapDescription;
std::string tmp;
uint8_t attribute;
while (propStream.read<uint8_t>(attribute)) {
switch (attribute) {
case OTBM_ATTR_DESCRIPTION:
if (!propStream.readString(mapDescription)) {
setLastErrorString("Invalid description tag.");
return false;
}
break;
case OTBM_ATTR_EXT_SPAWN_FILE:
if (!propStream.readString(tmp)) {
setLastErrorString("Invalid spawn tag.");
return false;
}
map->spawnfile = identifier.substr(0, identifier.rfind('/') + 1);
map->spawnfile += tmp;
break;
case OTBM_ATTR_EXT_HOUSE_FILE:
if (!propStream.readString(tmp)) {
//.........这里部分代码省略.........
示例9: loadMap
bool IOMapOTBM::loadMap(Map* map, const std::string& identifier)
{
int64_t start = OTSYS_TIME();
FileLoader f;
if(!f.openFile(identifier.c_str(), "OTBM", false, true)){
std::stringstream ss;
ss << "Could not open the file " << identifier << ".";
setLastErrorString(ss.str());
return false;
}
unsigned long type;
PropStream propStream;
NODE root = f.getChildNode((NODE)NULL, type);
if(!f.getProps(root, propStream)){
setLastErrorString("Could not read root property.");
return false;
}
OTBM_root_header root_header;
if( !propStream.GET_UINT32(root_header.version) ||
!propStream.GET_UINT16(root_header.width) ||
!propStream.GET_UINT16(root_header.height) ||
!propStream.GET_UINT32(root_header.majorVersionItems) ||
!propStream.GET_UINT32(root_header.minorVersionItems))
{
setLastErrorString("Could not read header.");
return false;
}
int header_version = root_header.version;
if(header_version <= 0){
//In otbm version 1 the count variable after splashes/fluidcontainers and stackables
//are saved as attributes instead, this solves alot of problems with items
//that is changed (stackable/charges/fluidcontainer/splash) during an update.
setLastErrorString("This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if(header_version > 2){
setLastErrorString("Unknown OTBM version detected, please update your server.");
return false;
}
if(root_header.majorVersionItems < 3){
setLastErrorString("This map needs to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if(root_header.majorVersionItems > (unsigned long)Items::dwMajorVersion){
setLastErrorString("The map was saved with a different items.otb version, an upgraded items.otb is required.");
return false;
}
// Prevent load maps saved with items.otb previous to
// version 800, because of the change to stackable of
// itemid 3965
if(root_header.minorVersionItems < CLIENT_VERSION_810){
setLastErrorString("This map needs to be updated.");
return false;
}
if(root_header.minorVersionItems > (unsigned long)Items::dwMinorVersion){
std::cout << "Warning: [OTBM loader] This map needs an updated items.otb." <<std::endl;
}
if(root_header.minorVersionItems == CLIENT_VERSION_854_BAD){
std::cout << "Warning: [OTBM loader] This map needs uses an incorrect version of items.otb." <<std::endl;
}
std::cout << "Map size: " << root_header.width << "x" << root_header.height << std::endl;
map->mapWidth = root_header.width;
map->mapHeight = root_header.height;
NODE nodeMap = f.getChildNode(root, type);
if(type != OTBM_MAP_DATA){
setLastErrorString("Could not read data node.");
return false;
}
if(!f.getProps(nodeMap, propStream)){
setLastErrorString("Could not read map data attributes.");
return false;
}
unsigned char attribute;
std::string mapDescription;
std::string tmp;
while(propStream.GET_UINT8(attribute)){
switch(attribute){
case OTBM_ATTR_DESCRIPTION:
if(!propStream.GET_STRING(mapDescription)){
setLastErrorString("Invalid description tag.");
return false;
}
std::cout << "Map description: " << mapDescription << std::endl;
//.........这里部分代码省略.........