void TacheUnitaire::xml_ajouterAttributs(rapidxml::xml_document<> & doc, rapidxml::xml_node<> & node_tache) { using namespace rapidxml; xml_attribute<> * attribute = doc.allocate_attribute("type", "u"); node_tache.append_attribute(attribute); if(getPreempte() == true) { attribute = doc.allocate_attribute("pre", "true"); node_tache.append_attribute(attribute); } char * node_name = doc.allocate_string( duree.toChar() ); attribute = doc.allocate_attribute( "duree", node_name ); node_tache.append_attribute(attribute); }
void TiledMapLoader::loadLayers(Map &map, rapidxml::xml_node<> &rootNode) { rapidxml::xml_node<> *layerNode = nullptr; rapidxml::xml_node<> *layerDataNode = nullptr; int layerId = 0; layerNode = rootNode.first_node("layer"); if (!layerNode) { throw std::logic_error("Invalid tiled map: no layer tag"); } while (layerNode) { Layer::Ptr layer(new Layer); layerDataNode = layerNode->first_node("data"); if (!layerDataNode) { throw std::logic_error("Invalid tiled map : no layer data tag"); } XMLElement layerElement(*layerNode); layer->setId(layerId); layer->setName(layerElement.getString("name")); layer->setWidth(layerElement.getInt("width")); layer->setHeight(layerElement.getInt("height")); layer->setVisible(layerElement.getInt("visible", 1)); layer->setOpacity(layerElement.getFloat("opacity", 1)); layer->parseProperties(*layerNode); loadLayerTiles(map, *layer.get(), *layerDataNode); map.addLayer(std::move(layer)); layerNode = layerNode->next_sibling("layer"); ++layerId; } }
void experiment_datasets::decode_xml_node(rapidxml::xml_node<> & node) { using namespace rapidxml; assert (string("experiment_datasets") == node.name()); train_test_pairs.resize(0); xml_node<> * train_test_pairs_node = node.first_node("train_test_pairs"); for (xml_node<> * train_test_pair_node = train_test_pairs_node->first_node("train_test_pair"); train_test_pair_node != 0 ; train_test_pair_node = train_test_pair_node->next_sibling("train_test_pair")) { shared_ptr<train_test_pair> p_train_test_pair = deserialize<train_test_pair>(train_test_pair_node); train_test_pairs.push_back(*p_train_test_pair); } }
void parseItem( const rapidxml::xml_node<> &node, XmlTree *parent, XmlTree *result, const XmlTree::ParseOptions &options ) { *result = XmlTree( node.name(), node.value(), parent ); for( const rapidxml::xml_node<> *item = node.first_node(); item; item = item->next_sibling() ) { XmlTree::NodeType type; switch( item->type() ) { case rapidxml::node_element: type = XmlTree::NODE_ELEMENT; break; case rapidxml::node_cdata: { if( options.getCollapseCData() ) { result->setValue( result->getValue() + item->value() ); continue; } else { type = XmlTree::NODE_CDATA; } } break; case rapidxml::node_comment: type = XmlTree::NODE_COMMENT; break; case rapidxml::node_doctype: { result->setDocType( item->value() ); continue; } case rapidxml::node_data: { if( ! options.getIgnoreDataChildren() ) type = XmlTree::NODE_DATA; else continue; } break; default: continue; } result->getChildren().push_back( unique_ptr<XmlTree>( new XmlTree ) ); parseItem( *item, result, result->getChildren().back().get(), options ); result->getChildren().back()->setNodeType( type ); } for( rapidxml::xml_attribute<> *attr = node.first_attribute(); attr; attr = attr->next_attribute() ) result->getAttributes().push_back( XmlTree::Attr( result, attr->name(), attr->value() ) ); }
_NAMESPACE_REALSPACE2_BEGIN bool RDummyList::Open(rapidxml::xml_node<>& parent) { for (auto* node = parent.first_node(); node; node = node->next_sibling()) { auto* szTagName = node->name(); if (!szTagName) continue; if (szTagName[0] == '#') continue; if (_stricmp(szTagName, RTOK_DUMMY) != 0) continue; auto name_attr = node->first_attribute(RTOK_NAME); if (!name_attr) continue; auto* name = name_attr->value(); if (!name) continue; emplace_back(); auto& Dummy = back(); Dummy.Name = name; for (auto* prop_node = node->first_node(); prop_node; prop_node = prop_node->next_sibling()) { auto* szTagName = prop_node->name(); if (!szTagName) continue; const char* szContents = prop_node->value(); if (!szContents) szContents = ""; auto ReadVector = [&]() { v3 vec; if (sscanf(szContents, "%f %f %f", &vec.x, &vec.y, &vec.z) != 3) vec = { 0, 0, 0 }; return vec; }; if (_stricmp(szTagName, RTOK_POSITION) == 0) Dummy.Position = ReadVector(); else if (_stricmp(szTagName, RTOK_DIRECTION) == 0) Dummy.Direction = ReadVector(); } } return true; }
void TiledMapLoader::addTileset(Map &map, int tilesetId, rapidxml::xml_node<> &tilesetNode, unsigned firstGid) { Tileset::Ptr tileset(new Tileset); rapidxml::xml_node<> *tilesetImageNode = nullptr; rapidxml::xml_node<> *tilesetOffsetNode = nullptr; tilesetImageNode = tilesetNode.first_node("image"); if (!tilesetImageNode) { throw std::logic_error("Invalid tiled map: no tileset image tag"); } XMLElement tilesetElement(tilesetNode); XMLElement tilesetImageElement(*tilesetImageNode); tilesetOffsetNode = tilesetNode.first_node("tileoffset"); if (tilesetOffsetNode) { XMLElement element(*tilesetOffsetNode); tileset->setOffsetX(element.getInt("x")); tileset->setOffsetY(element.getInt("y")); } else { tileset->setOffsetX(0); tileset->setOffsetY(0); } tileset->setId(tilesetId); if (firstGid) { tileset->setFirstGid(firstGid); } else { tileset->setFirstGid(tilesetElement.getInt("firstgid")); } tileset->setName(tilesetElement.getString("name")); tileset->setTileWidth(tilesetElement.getInt("tilewidth")); tileset->setTileHeight(tilesetElement.getInt("tileheight")); tileset->setSpacing(tilesetElement.getInt("spacing")); tileset->setMargin(tilesetElement.getInt("margin")); tileset->setImageSource(tilesetImageElement.getString("source")); tileset->setWidth(tilesetImageElement.getInt("width")); tileset->setHeight(tilesetImageElement.getInt("height")); tileset->parseProperties(tilesetNode); parseTilesetsTileProperties(map, *(tileset.get()), tilesetNode); map.addTileset(std::move(tileset)); }
void Level::addCuboid(const rapidxml::xml_node<> &cuboidNode) { osg::Vec3 from = getVectorFromXMLNode("position", cuboidNode); osg::Vec3 size = getVectorFromXMLNode("size", cuboidNode); Cuboid *cuboid = NULL; if(cuboidNode.first_attribute("type") != 0) { std::string type = cuboidNode.first_attribute("type")->value(); if(type == "accelerate") cuboid = new AccelerationCuboid(from, size); else if(type == "decelerate") cuboid = new DecelerationCuboid(from, size); } if(cuboid == NULL) { cuboid = new Cuboid(from, size); } _level->addChild(cuboid->getNode()); _collisionObjects.push_back(cuboid->getRigidBody()); // save minimal x values for buckets of close y values // needed for detection whether player is falling to dead int yBucketIndex = (int)((from.y() + size.y()) / 20.0f); while(_minZValues.size() <= yBucketIndex) _minZValues.push_back(from.z()); // if current cuboid is lower then z -> adjust bucket value if(from.z() < _minZValues[yBucketIndex]) _minZValues[yBucketIndex] = from.z(); }
void TiledMapLoader::loadObjectGroups(Map &map, rapidxml::xml_node<> &rootNode) { rapidxml::xml_node<> *objectGroupNode = nullptr; objectGroupNode = rootNode.first_node("objectgroup"); while (objectGroupNode) { ObjectGroup::Ptr objectGroup(new ObjectGroup); XMLElement objectGroupElement(*objectGroupNode); objectGroup->setName(objectGroupElement.getString("name")); objectGroup->setDrawOrder(objectGroupElement.getString("draworder")); objectGroup->setWidth(objectGroupElement.getInt("width")); objectGroup->setHeight(objectGroupElement.getInt("height")); objectGroup->setVisible(objectGroupElement.getInt("visible", 1)); objectGroup->setOpacity(objectGroupElement.getFloat("opacity", 1)); objectGroup->parseProperties(*objectGroupNode); loadObjectGroupObjects(map, *objectGroup.get(), *objectGroupNode); map.addObjectGroup(std::move(objectGroup)); objectGroupNode = objectGroupNode->next_sibling("objectgroup"); } }
void TiledMapLoader::loadLayerTiles(Map &map, Layer &layer, rapidxml::xml_node<> &layerDataNode) { rapidxml::xml_node<> *tileNode = nullptr; XMLElement layerDataElement(layerDataNode); unsigned mapIterator = 0; unsigned gid = 0; if (!strncmp(layerDataElement.getString("encoding"), "base64", 6) && !strncmp(layerDataElement.getString("compression"), "zlib", 4)) { auto base64Tiles = Base64::decode(trim(layerDataElement.getValue())); unsigned numberOfGids = layer.getWidth() *layer.getHeight(); unsigned tileIndex = 0; mz_ulong uncompressSize = numberOfGids << 2; auto gids = new unsigned char[uncompressSize]; if (!gids) { throw std::logic_error("Uncompression failed: can't allocate memory"); } if (mz_uncompress(gids, &uncompressSize, (unsigned char *) base64Tiles.c_str(), base64Tiles.length()) != MZ_OK) { throw std::logic_error("Zlib error: uncompression failed"); } while (mapIterator < numberOfGids) { gid = gids[tileIndex] | gids[tileIndex + 1] << 8 | gids[tileIndex + 2] << 16 | gids[tileIndex + 3] << 24; if (gid) createTileFromGid(map, layer, gid, mapIterator); tileIndex += 4; ++mapIterator; } delete[] gids; } else { tileNode = layerDataNode.first_node("tile"); if (!tileNode) { throw std::logic_error("Invalid tiled map: no tiles (only plain XML or ZLIB supported)"); } while (tileNode) { XMLElement tileElement(*tileNode); gid = tileElement.getUnsignedInt("gid"); if (gid) { createTileFromGid(map, layer, gid, mapIterator); } tileNode = tileNode->next_sibling("tile"); ++mapIterator; } } }
void TiledMapLoader::loadTilesets(Map &map, rapidxml::xml_node<> &rootNode) { auto tilesetNode = rootNode.first_node("tileset"); char *tilesetSource = nullptr; auto tilesetId = 0; if (!tilesetNode) { throw std::logic_error("Invalid tiled map: no tileset tag"); } while (tilesetNode) { XMLElement tilesetElement(*tilesetNode); tilesetSource = tilesetElement.getString("source", nullptr); if (tilesetSource) { loadExternalTileset(map, tilesetId, tilesetSource, tilesetElement.getInt("firstgid")); } else { addTileset(map, tilesetId, *tilesetNode); } tilesetNode = tilesetNode->next_sibling("tileset"); ++tilesetId; } }
void Level::addTunnel(const rapidxml::xml_node<> &tunnelNode) { osg::Node *tunnelModel = osgDB::readNodeFile(TUNNEL_MODEL_FILE); osg::PositionAttitudeTransform *tunnelTransform = new osg::PositionAttitudeTransform(); osg::Vec3 position = getVectorFromXMLNode("position", tunnelNode); tunnelTransform->addChild(tunnelModel); tunnelTransform->setPosition(position); tunnelTransform->setScale(osg::Vec3f(1.0f, atof(tunnelNode.first_attribute("length")->value()), 1.0f)); tunnelTransform->setNodeMask(RECEIVE_SHADOW_MASK); _level->addChild(tunnelTransform); /* btConvexTriangleMeshShape* mesh = osgbBullet::btConvexTriMeshCollisionShapeFromOSG(tunnelPat); btTransform shapeTransform; shapeTransform.setIdentity(); cs->addChildShape(shapeTransform, mesh); */ }
void TiledMapLoader::loadObjectGroupObjects(Map &map, ObjectGroup &objectGroup, rapidxml::xml_node<> &objectGroupNode) { rapidxml::xml_node<> *objectNode = nullptr; rapidxml::xml_node<> *objectNature = nullptr; objectNode = objectGroupNode.first_node("object"); while (objectNode) { Object::Ptr object(new Object); XMLElement objectGroupElement(*objectNode); object->setGid(objectGroupElement.getInt("gid", -1)); object->setId(objectGroupElement.getInt("id", -1)); object->setName(objectGroupElement.getString("name")); object->setType(objectGroupElement.getString("type")); object->setX(objectGroupElement.getFloat("x")); object->setY(objectGroupElement.getFloat("y")); object->setWidth(objectGroupElement.getFloat("width")); object->setHeight(objectGroupElement.getFloat("height")); object->setRotation(objectGroupElement.getFloat("rotation")); object->setVisible(objectGroupElement.getInt("visible", 1)); objectNature = objectNode->first_node("ellipse"); if (objectNature) { object->setPolygonType("ellipse"); } objectNature = objectNode->first_node("polygon"); if (objectNature) { XMLElement objectNatureElement(*objectNature); object->setPolygonType("polygon"); object->setVertices(objectNatureElement.getString("points")); } objectNature = objectNode->first_node("polyline"); if (objectNature) { XMLElement objectNatureElement(*objectNature); object->setPolygonType("polyline"); object->setVertices(objectNatureElement.getString("points")); } object->parseProperties(*objectNode); objectGroup.addObject(std::move(object)); objectNode = objectNode->next_sibling("object"); } }
osg::Vec3 Level::getVectorFromXMLNode(const std::string &name, const rapidxml::xml_node<> &node) const { rapidxml::xml_node<> *vectorNode = node.first_node(name.c_str()); if(!vectorNode) { throw std::runtime_error("Error: Level element missing vector node!"); } float x, y, z; try { x = atof(vectorNode->first_attribute("x")->value()); y = atof(vectorNode->first_attribute("y")->value()); z = atof(vectorNode->first_attribute("z")->value()); } catch(...) { throw std::runtime_error("Error: " + name + " node missing either x, y or z attribute!"); } return osg::Vec3(x, y, z); }
void TiledMapLoader::parseTilesetsTileProperties(Map &map, Tileset &tileset, rapidxml::xml_node<> &tilesetNode) { rapidxml::xml_node<> *tilesetTileNode = nullptr; rapidxml::xml_node<> *tilesetTileNodeProperties = nullptr; rapidxml::xml_node<> *tilesetTileNodeProperty = nullptr; tilesetTileNode = tilesetNode.first_node("tile"); while (tilesetTileNode) { tilesetTileNodeProperties = tilesetTileNode->first_node("properties"); if (tilesetTileNodeProperties) { tilesetTileNodeProperty = tilesetTileNodeProperties->first_node("property"); while (tilesetTileNodeProperty) { XMLElement tileNode(*tilesetTileNode); XMLElement tileNodeProperty(*tilesetTileNodeProperty); char *name = tileNodeProperty.getString("name"); char *value = tileNodeProperty.getString("value"); if (name && value) { tileset.addTileProperties(tileNode.getInt("id"), name, value); } tilesetTileNodeProperty = tilesetTileNodeProperty->next_sibling("property"); } } tilesetTileNode = tilesetTileNode->next_sibling("tile"); } }
bool Frame::parseXml(const rapidxml::xml_node<char> &node, std::string const &rootPath) { //read name rapidxml::xml_node<char> *nameNode = node.first_node("name"); if (!nameNode) { std::cerr << "Error: Invalid Spriter file: Frame without name!" << std::endl; return false; } this->name_ = nameNode->value(); //read and create sprites for (rapidxml::xml_node<char> *curNode = node.first_node("sprite"); curNode; curNode = curNode->next_sibling("sprite")) { Sprite *sprite; sprite = new Sprite; if (!sprite) return false; //get <image> rapidxml::xml_node<char> *node = curNode->first_node("image"); if (!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <image> node!" << std::endl; return false; } if (!sprite->setBitmap(node->value(), rootPath)) { return false; } //get <color> [0x000000 ; 0xffffff] node = curNode->first_node("color"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <color> node!" << std::endl; return false; } int intColor = atoi(node->value()); //get <opacity> [0.f ; 100.f] node = curNode->first_node("opacity"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <opacity> node!" << std::endl; return false; } float opacity = atof(node->value()); int colorR = (intColor & 0xff0000) >> 16; int colorG = (intColor & 0x00ff00) >> 8; int colorB = (intColor & 0x0000ff) >> 0; int colorA = opacity / 100.f * 255.f; sprite->setColor(al_map_rgba(colorR, colorG, colorB, colorA)); //get <angle> (in degrees, around upper left corner) node = curNode->first_node("angle"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <angle> node!" << std::endl; return false; } sprite->setRotation(atof(node->value())); //get <width> (in pixels) node = curNode->first_node("width"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <width> node!" << std::endl; return false; } sprite->setWidth(atoi(node->value())); //get <height> (in pixels) node = curNode->first_node("height"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <height> node!" << std::endl; return false; } sprite->setHeight(atof(node->value())); // //get <xflip> // node = curNode->first_node("xflip"); // if(!node) // { // sf::err() << "Error: Invalid Spriter file: Frame \"" << mName << "\" lacks <xflip> node!" << std::endl; // return false; // } // // if(atoi(node->value())) width *= -1; // //get <yflip> // node = curNode->first_node("yflip"); // if(!node) // { // sf::err() << "Error: Invalid Spriter file: Frame \"" << mName << "\" lacks <yflip> node!" << std::endl; // return false; // } // // if(atoi(node->value())) height *= -1; //get <x> (in pixels) node = curNode->first_node("x"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <x> node!" << std::endl; return false; } sprite->setX(atoi(node->value())); //get <y> (in pixels) node = curNode->first_node("y"); if(!node) { std::cerr << "Error: Invalid Spriter file: Frame \"" << this->name_ << "\" lacks <y> node!" << std::endl; return false; } sprite->setY(atoi(node->value())); // //create Sprite // //width/height is negative if the axis is flipped, in that case we need to reposition the origin to upper left // sprite->setOrigin((width < 0 ? width : 0), (height < 0 ? height : 0)); // sprite->setPosition(x, y); // sprite->setScale(width / float(tex->getSize().x), height / float(tex->getSize().y)); // sprite->setRotation(-angle); // sprite->setColor(color); this->list_.push_back(sprite); } return true; }
//=========================================== // XmlNode::nextSibling //=========================================== inline XmlNode XmlNode::nextSibling() const { if (isNull()) throw XmlException("Node is NULL", __FILE__, __LINE__); return XmlNode(m_doc, m_node->next_sibling(), m_file); }
//=========================================== // XmlNode::firstChild //=========================================== inline XmlNode XmlNode::firstChild() const { if (isNull()) throw XmlException("Node is NULL", __FILE__, __LINE__); return XmlNode(m_doc, m_node->first_node(), m_file); }
//=========================================== // XmlNode::getString //=========================================== inline std::string XmlNode::getString() const { if (isNull()) throw XmlException("Node is NULL", __FILE__, __LINE__); return std::string(m_node->value(), m_node->value_size()); }