Example #1
0
void ompl::control::Syclop::buildGraph(void)
{
    VertexIndexMap index = get(boost::vertex_index, graph_);
    std::vector<int> neighbors;
    for (int i = 0; i < decomp_->getNumRegions(); ++i)
    {
        const RegionGraph::vertex_descriptor v = boost::add_vertex(graph_);
        Region& r = graph_[boost::vertex(v,graph_)];
        initRegion(r);
        r.index = index[v];
    }
    VertexIter vi, vend;
    for (boost::tie(vi,vend) = boost::vertices(graph_); vi != vend; ++vi)
    {
        /* Create an edge between this vertex and each of its neighboring regions in the decomposition,
            and initialize the edge's Adjacency object. */
        decomp_->getNeighbors(index[*vi], neighbors);
        for (std::vector<int>::const_iterator j = neighbors.begin(); j != neighbors.end(); ++j)
        {
            RegionGraph::edge_descriptor edge;
            bool ignore;
            boost::tie(edge, ignore) = boost::add_edge(*vi, boost::vertex(*j,graph_), graph_);
            initEdge(graph_[edge], &graph_[*vi], &graph_[boost::vertex(*j,graph_)]);
        }
        neighbors.clear();
    }
}
void WorldMap::generate()
{
	int i, j;
	Vector2D pos;

    /* generate terrain */
	terrain = new char*[size.x];
	for ( i = 0; i < size.x; i++ )
	{
		terrain[i] = new char[size.y];
		for ( j = 0; j < size.y; j++ )	terrain[i][j] = ( rand() % 1000 < blocks ) ? 1 : 0;
	}

	players = new PlayerBucket[ sd->num_threads ];
	n_players = 0;

	list<Player*> pls;
	list<GameObject*> objs;
	
	n_regs.x = size.x / regmin.x;
	n_regs.y = size.y / regmin.y;
	int regions_per_thread = (n_regs.x * n_regs.y - 1) / sd->num_threads + 1;
	regions = new Region*[ n_regs.x ];
	for( i = 0, pos.x = 0; i < n_regs.x; i++, pos.x += regmin.x )
	{
		regions[i] = new Region[ n_regs.y ];
		for( j = 0, pos.y = 0; j < n_regs.y; j++, pos.y += regmin.y )
			initRegion( &regions[i][j], pos, regmin, (i*n_regs.y + j)/regions_per_thread, objs, pls);
	}

	/* generate objects */
	#ifndef NO_QUESTS
	GameObject *o;
	Region* r;
			
	for ( i = 0; i < resources * size.x * size.y / 1000; i++ )
	{
		o = new GameObject();			
        while(1){
			o->pos.x = rand() % size.x;
			o->pos.y = rand() % size.y;
			if( terrain[o->pos.x][o->pos.y] != 0  )				continue;
			r = getRegionByLocation( o->pos );					assert(r);
			if( Region_addObject( r, o, min_res, max_res ) )	break;
		}
	}
	#endif
}