Exemple #1
0
Fichier : poi.C Projet : wixor/ewo
void ProximityMap::build(const POIvec &pois)
{
    /* how many entries we still have to fill */
    int allToDo = widet * hedet * entries,
        leftToDo = allToDo;

    int npois = (int)pois.size();
    assert(npois < 65536); /* because poiid_t is unsigned short */
    assert(entries <= npois);

    progress(0);

    /* this is temporary array that keeps track of how many entries were added
     * to each field. when the algoritm finishes, all fields have 'entries'
     * entries, so this array can be safely discarded */
    usedEntries = Array2D<poiid_t>(widet, hedet);
    usedEntries.fill(0);

    std::priority_queue<djk> Q;

    for(poiid_t i=0; i<npois; i++)
    {
        int xi = roundf(pois[i].x*detail),
            yi = roundf(pois[i].y*detail);
        Q.push(djk(0, xi, yi, i));
    }

    while(leftToDo)
    {
        assert(Q.size());
        djk o = Q.top();
        Q.pop();

        if(!canVisit(o))
            continue;
        pushEntry(o);
        leftToDo--;

        if(leftToDo % 20000 == 0) 
            progress((float)(allToDo - leftToDo) / (float)allToDo);

        for(int dx=-1; dx<=1; dx++)
            for(int dy=-1; dy<=1; dy++)
            {
                djk u;
                u.xi = o.xi + dx;
                u.yi = o.yi + dy;
                u.id = o.id;
                u.dist = (Point((float)u.xi / detail, (float)u.yi / detail) - pois[u.id]).dist();
                if(canVisit(u))
                    Q.push(u);
            }
    }

    /* free usedEntries' memory */
    usedEntries = Array2D<poiid_t>();
}
Exemple #2
0
//-------------------------- CreatePathDijkstra --------------------------
//
//  creates a path from m_iSourceCell to m_iTargetCell using Dijkstra's algorithm
//------------------------------------------------------------------------
void BattleMap::createPathDijkstra()
{
	//set current algorithm
	m_CurrentAlgorithm = AT_DIJKSTRA;

	//create and start a timer
	PrecisionTimer timer; timer.Start();

	Graph_SearchDijkstra<NavGraph> djk(*m_pGraph, m_iSourceCell, m_iTargetCell);

	//record the time taken  
	m_dTimeTaken = timer.TimeElapsed();

	m_Path = djk.GetPathToTarget();

	m_SubTree = djk.GetSPT();

	m_dCostToTarget = djk.GetCostToTarget();
}