Example #1
0
    void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode) 
    {
        const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();

        // Read all the attributes into local variables.
        first_gid = tilesetElem->IntAttribute("firstgid");
        tile_width = tilesetElem->IntAttribute("tilewidth");
        tile_height = tilesetElem->IntAttribute("tileheight");
        margin = tilesetElem->IntAttribute("margin");
        spacing = tilesetElem->IntAttribute("spacing");

        name = tilesetElem->Attribute("name");

        // Parse the image.
        const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
        
        if (imageNode) 
        {
            image = new Image();
            image->Parse(imageNode);
        }

        // Populate the tile list
        int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);

        int tId = tiles.size();
        while (tId < tileCount)
        {
            Tile* tile = new Tile(tId);
            tiles.push_back(tile);
            tId++;
        }


        // Iterate through all of the tile elements and parse each.
        const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
        while (tileNode)
        {
            // Parse it to get the tile id.
            Tile tile;
            tile.Parse(tileNode);

            // Using the ID in the temporary tile get the real tile and parse for real.
            tiles[tile.GetId()]->Parse(tileNode);

            //tileNode = tilesetNode->IterateChildren("tile", tileNode); FIXME MAYBE
            tileNode = tileNode->NextSiblingElement("tile");
        }

        
        // Parse the properties if any.
        const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
        
        if (propertiesNode) 
        {
            properties.Parse(propertiesNode);
        }
    }
Example #2
0
  /**
   * (Partially) prefill the given tiles with data already cached with data of the given types.
   *
   * Currently prefill is done by looking for the parent tile in the cache
   * and copying data that intersects the bounding box of the given tile.
   */
  void DataTileCache::PrefillDataFromCache(Tile& tile,
                                            const TypeInfoSet& nodeTypes,
                                            const TypeInfoSet& wayTypes,
                                            const TypeInfoSet& areaTypes,
                                            const TypeInfoSet& optimizedWayTypes,
                                            const TypeInfoSet& optimizedAreaTypes)
  {
    if (tile.GetId().GetLevel()>0) {
      TileId parentTileId=tile.GetId().GetParent();
      TileRef parentTile=GetCachedTile(parentTileId);

      GeoBox boundingBox=tile.GetBoundingBox();

      if (parentTile) {
        ResolveNodesFromParent(tile,*parentTile,boundingBox,nodeTypes);
        ResolveOptimizedWaysFromParent(tile,*parentTile,boundingBox,optimizedWayTypes,wayTypes);
        ResolveWaysFromParent(tile,*parentTile,boundingBox,wayTypes);
        ResolveOptimizedAreasFromParent(tile,*parentTile,boundingBox,optimizedAreaTypes,areaTypes);
        ResolveAreasFromParent(tile,*parentTile,boundingBox,areaTypes);

        return;
      }
    }

    /*
    Magnification zoomedInMagnification;

    zoomedInMagnification.SetLevel(tile.GetId().GetLevel()+1);

    TileId childIds[4]={TileId(zoomedInMagnification,tile.GetId().GetX()*2,tile.GetId().GetY()*2),
                        TileId(zoomedInMagnification,tile.GetId().GetX()*2+1,tile.GetId().GetY()*2),
                        TileId(zoomedInMagnification,tile.GetId().GetX()*2,tile.GetId().GetY()*2+1),
                        TileId(zoomedInMagnification,tile.GetId().GetX()*2+1,tile.GetId().GetY()*2+1)};

    TileRef childTiles[4];

    for (size_t i=0; i<4; i++) {
      childTiles[i]=GetCachedTile(childIds[i]);
    }

    if (childTiles[0] && childTiles[1] && childTiles[2] && childTiles[3]) {
      std::cout << "Prefilling from children..." << std::endl;
    }*/
  }
Example #3
0
	void Tileset::Parse(const TiXmlNode *tilesetNode) 
	{
		const TiXmlElement *tilesetElem = tilesetNode->ToElement();

		// Read all the attributes into local variables.
		tilesetElem->Attribute("firstgid", &first_gid);
		tilesetElem->Attribute("tilewidth", &tile_width);
		tilesetElem->Attribute("tileheight", &tile_height);
		tilesetElem->Attribute("margin", &margin);
		tilesetElem->Attribute("spacing", &spacing);

		name = tilesetElem->Attribute("name");

		// IGNACIO CEA
		// Parser the offset
		const TiXmlNode *offsetNode = tilesetNode->FirstChild("tileoffset");

		if (offsetNode)
		{
			const TiXmlElement *offsetElement = offsetNode->ToElement();
			offsetElement->Attribute("x", &x_offset);
			offsetElement->Attribute("y", &y_offset);
		}
		// IGNACIO CEA

		// Parse the image.
		const TiXmlNode *imageNode = tilesetNode->FirstChild("image");
		
		if (imageNode) 
		{
			image = new Image();
			image->Parse(imageNode);
		}

        // Populate the tile list
        int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);

        int tId = tiles.size();
        while (tId < tileCount)
        {
            Tile* tile = new Tile(tId);
            tiles.push_back(tile);
            tId++;
        }


        // Iterate through all of the tile elements and parse each.
        const TiXmlNode *tileNode = tilesetNode->FirstChild("tile");
        while (tileNode)
		{
            // Parse it to get the tile id.
            Tile tile;
            tile.Parse(tileNode);

            // Using the ID in the temporary tile get the real tile and parse for real.
            tiles[tile.GetId()]->Parse(tileNode);

            tileNode = tilesetNode->IterateChildren("tile", tileNode);
		}

		
		// Parse the properties if any.
		const TiXmlNode *propertiesNode = tilesetNode->FirstChild("properties");
		
		if (propertiesNode) 
		{
			properties.Parse(propertiesNode);
		}
	}
Example #4
0
    void Tileset::Parse(const tinyxml2::XMLNode *tilesetNode, const std::string& file_path)
    {
        const tinyxml2::XMLElement *tilesetElem = tilesetNode->ToElement();

        // Read all the attributes into local variables.

        // The firstgid and source attribute are kept in the TMX map,
        // since they are map specific.
        first_gid = tilesetElem->IntAttribute("firstgid");

        // If the <tileset> node contains a 'source' tag,
        // the tileset config should be loaded from an external
        // TSX (Tile Set XML) file. That file has the same structure
        // as the <tileset> element in the TMX map.
        const char* source_name = tilesetElem->Attribute("source");

        tinyxml2::XMLDocument tileset_doc;
        if ( source_name )
        {
            std::string fileName = file_path + source_name;
            tileset_doc.LoadFile( fileName.c_str() );

            if ( tileset_doc.ErrorID() != 0)
            {
                fprintf(stderr, "failed to load tileset file '%s'\n", fileName.c_str());
                return;
            }

            // Update node and element references to the new node
            tilesetNode = tileset_doc.FirstChildElement("tileset");
            tilesetElem = tilesetNode->ToElement();
        }

        tile_width = tilesetElem->IntAttribute("tilewidth");
        tile_height = tilesetElem->IntAttribute("tileheight");
        margin = tilesetElem->IntAttribute("margin");
        spacing = tilesetElem->IntAttribute("spacing");

        name = tilesetElem->Attribute("name");

        // Parse the tile offset, if it exists.
        const tinyxml2::XMLNode *tileOffsetNode = tilesetNode->FirstChildElement("tileoffset");
        
        if (tileOffsetNode) 
        {
            tileOffset = new TileOffset();
            tileOffset->Parse(tileOffsetNode);
        }

        // Parse the terrain types if any.
        const tinyxml2::XMLNode *terrainTypesNode = tilesetNode->FirstChildElement("terraintypes");
        
        if (terrainTypesNode) 
        {
            TerrainArray terrainArray;
            terrainArray.Parse(&terrainTypes, terrainTypesNode);
        }

        // Parse the image.
        const tinyxml2::XMLNode *imageNode = tilesetNode->FirstChildElement("image");
        
        if (imageNode) 
        {
            image = new Image();
            image->Parse(imageNode);
        }

        // Populate the tile list
        int tileCount = (image->GetWidth() / tile_width) * (image->GetHeight() / tile_height);

        int tId = tiles.size();
        while (tId < tileCount)
        {
            Tile* tile = new Tile(tId);
            tiles.push_back(tile);
            tId++;
        }


        // Iterate through all of the tile elements and parse each.
        const tinyxml2::XMLNode *tileNode = tilesetNode->FirstChildElement("tile");
        while (tileNode)
        {
            // Parse it to get the tile id.
            Tile tile;
            tile.Parse(tileNode);

            // Using the ID in the temporary tile get the real tile and parse for real.
            tiles[tile.GetId()]->Parse(tileNode);

            //tileNode = tilesetNode->IterateChildren("tile", tileNode); FIXME MAYBE
            tileNode = tileNode->NextSiblingElement("tile");
        }

        
        // Parse the properties if any.
        const tinyxml2::XMLNode *propertiesNode = tilesetNode->FirstChildElement("properties");
        
        if (propertiesNode) 
        {
            properties.Parse(propertiesNode);
        }
    }