Пример #1
0
void
MapFrame::refreshComputedValues()
{
    _highestMinLevel = 0;

    _elevationLayers.clear();

    for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i)
    {
        TerrainLayer* terrainLayer = dynamic_cast<TerrainLayer*>(i->get());
        if (terrainLayer)
        {
            const optional<unsigned>& minLevel = terrainLayer->getTerrainLayerRuntimeOptions().minLevel();
            if (minLevel.isSet() && minLevel.value() > _highestMinLevel)
            {
                _highestMinLevel = minLevel.value();
            }

            ElevationLayer* elevation = dynamic_cast<ElevationLayer*>(terrainLayer);
            if (elevation)
            {
                _elevationLayers.push_back(elevation);
            }
        }
    }
}
int
TerrainPatch::CalcLayer(Poly* poly)
{
	if (terrain && poly) {
		if (water)
		return 0;

		double y = 1e6;

		for (int i = 0; i < poly->nverts; i++) {
			double h = poly->vertex_set->loc[ poly->verts[i] ].y;

			if (h >= 0 && h < y) {
				y = h;
			}
		}

		if (y <= terrain->GetLayers().first()->GetMinHeight())
		return 0;

		for (int i = 0; i < terrain->GetLayers().size(); i++) {
			TerrainLayer* layer = terrain->GetLayers().at(i);

			if (y >= layer->GetMinHeight() && y < layer->GetMaxHeight()) {
				return i;
			}
		}
	}

	return -1;
}
Пример #3
0
void DungeonGenerator::InitMap(Display &MainDisplay)
{
	
	std::vector<std::vector<TerrainTile>> Layer;
	Layer.resize(cm_DungeonWidth, std::vector<TerrainTile>(cm_DungeonHeight, TerrainTile(NULL,0,0,Floor,0,0)));

	for (int x = 0; x < m_Dungeon.size(); x++)
	{
		for (int y = 0; y < m_Dungeon[0].size(); y++)
		{
			TILE CurTileType = Get_Tile(Vec2i(x, y));
			
			if (CurTileType == Wall)
			{
				Layer[x][y] = TerrainTile(NULL, x * cm_TileSize, y * cm_TileSize, Wall, cm_TileSize, cm_TileSize, true);
			}
			else if (CurTileType == Floor)
			{
				//Layer[x][y] = TerrainTile(NULL, x * cm_TileSize, y * cm_TileSize, Floor, cm_TileSize, cm_TileSize, false);
				Layer[x][y] = TerrainTile(m_GroundImage, x * cm_TileSize, y * cm_TileSize, Floor, cm_TileSize, cm_TileSize, false);
			}
			else if (CurTileType == Door)
			{
				Layer[x][y] = TerrainTile(NULL, x * cm_TileSize, y * cm_TileSize, Door, cm_TileSize, cm_TileSize, false);
			}
		}
	}
	TerrainLayer *Temp = new TerrainLayer(Layer);
	Temp->CreateBitmap(MainDisplay);
	m_Map = new TerrainMap(Temp);
	
	
}
Пример #4
0
int
list( osg::ArgumentParser& args )
{
    osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles( args );
    if ( !node.valid() )
        return usage( "Failed to read .earth file." );

    MapNode* mapNode = MapNode::findMapNode( node.get() );
    if ( !mapNode )
        return usage( "Input file was not a .earth file" );

    Map* map = mapNode->getMap();
    const Cache* cache = map->getCache();

    if ( !cache )
        return message( "Earth file does not contain a cache." );

    std::cout 
        << "Cache config: " << std::endl
        << cache->getCacheOptions().getConfig().toJSON(true) << std::endl;

    MapFrame mapf( mapNode->getMap() );

    TerrainLayerVector layers;
    std::copy( mapf.imageLayers().begin(), mapf.imageLayers().end(), std::back_inserter(layers) );
    std::copy( mapf.elevationLayers().begin(), mapf.elevationLayers().end(), std::back_inserter(layers) );

    for( TerrainLayerVector::iterator i =layers.begin(); i != layers.end(); ++i )
    {
        TerrainLayer* layer = i->get();
        TerrainLayer::CacheBinMetadata meta;

        if ( layer->getCacheBinMetadata( map->getProfile(), meta ) )
        {
            Config conf = meta.getConfig();
            std::cout << "Layer \"" << layer->getName() << "\", cache metadata =" << std::endl
                << conf.toJSON(true) << std::endl;
        }
        else
        {
            std::cout << "Layer \"" << layer->getName() << "\": no cache information" 
                << std::endl;
        }
    }

    return 0;
}
Пример #5
0
void
MapFrame::refreshComputedValues()
{
    // cache the min LOD based on all image/elev layers
    _highestMinLevel = 0;

    for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i)
    {
        TerrainLayer* terrainLayer = dynamic_cast<TerrainLayer*>(i->get());
        if (terrainLayer)
        {
            const optional<unsigned>& minLevel = terrainLayer->getTerrainLayerRuntimeOptions().minLevel();
            if (minLevel.isSet() && minLevel.value() > _highestMinLevel)
            {
                _highestMinLevel = minLevel.value();
            }
        }
    }
}
DWORD
TerrainPatch::BlendValue(double y)
{
	if (terrain && y >= 0 && !water) {
		// find the proper layer:
		for (int i = 0; i < terrain->GetLayers().size(); i++) {
			TerrainLayer* layer = terrain->GetLayers().at(i);

			if (y >= layer->GetMinHeight() && y < layer->GetMaxHeight()) {
				double scale = (y-layer->GetMinHeight()) / (layer->GetMaxHeight()-layer->GetMinHeight());

				if (scale < 0.2)
				scale = 0;
				else if (scale > 0.8)
				scale = 1;
				else
				scale = (scale - 0.2) / 0.6;

				if ((i & 1) == 0) {
					scale = 1 - scale;
				}

				DWORD val = (DWORD) (scale*255);

				return val << 24;
			}
		}
	}

	return 0;
}
Пример #7
0
int list( osg::ArgumentParser& args )
{
    osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles( args );
    if ( !node.valid() )
        return usage( "Failed to read .earth file." );

    MapNode* mapNode = MapNode::findMapNode( node.get() );
    if ( !mapNode )
        return usage( "Input file was not a .earth file" );
    
    const Map* map = mapNode->getMap();
    const Cache* cache = map->getCache();

    if ( !cache )
        return message( "Earth file does not contain a cache." );

    std::cout 
        << "Cache config: " << std::endl
        << cache->getCacheOptions().getConfig().toJSON(true) << std::endl;


    TerrainLayerVector layers;
    map->getLayers(layers);

    for( TerrainLayerVector::iterator i =layers.begin(); i != layers.end(); ++i )
    {
        TerrainLayer* layer = i->get();

        bool useMFP =
            layer->getProfile() &&
            layer->getProfile()->getSRS()->isSphericalMercator() &&
            mapNode->getMapNodeOptions().getTerrainOptions().enableMercatorFastPath() == true;

        const Profile* cacheProfile = useMFP ? layer->getProfile() : map->getProfile();

        TerrainLayer::CacheBinMetadata* meta = layer->getCacheBinMetadata(cacheProfile);
        if (meta)
        {
            Config conf = meta->getConfig();
            std::cout << "Layer \"" << layer->getName() << "\", cache metadata =" << std::endl
                << conf.toJSON(true) << std::endl;
        }
        else
        {
            std::cout << "Layer \"" << layer->getName() << "\": no cache information" 
                << std::endl;
        }
    }

    return 0;
}
Пример #8
0
bool
MapFrame::isCached( const TileKey& key ) const
{
    // is there a map cache at all?
    osg::ref_ptr<const Map> map;
    if (_map.lock(map) && map->getCache() == 0L)
        return false;

    for (LayerVector::const_iterator i = _layers.begin(); i != _layers.end(); ++i)
    {
        TerrainLayer* layer = dynamic_cast<TerrainLayer*>(i->get());
        if (layer)
        {
            if (!layer->getEnabled())
                continue;

            // If we're cache only we should be fast
            if (layer->getCacheSettings()->cachePolicy()->isCacheOnly())
                continue;

            // no-cache? always slow
            if (layer->getCacheSettings()->cachePolicy()->isCacheDisabled())
                return false;

            //If no data is available on this tile, we'll be fast
            if (!layer->mayHaveData(key))
                continue;

            // No tile source? skip it
            osg::ref_ptr< TileSource > source = layer->getTileSource();
            if (!source.valid())
                continue;

            //If the tile is blacklisted, it should also be fast.
            if (source->getBlacklist()->contains(key))
                continue;

            if (!layer->isCached(key))
                return false;
        }
    }
    return true;
}