Exemplo n.º 1
0
Trail *Path::searchPath(void *o,int x1,int y1,int x2,int y2,int l) {
	int i,d,x,y,c;
	PathNode *p1 = 0,*p2 = 0;
debug_output("Path::searchPath(x1=%d,y1=%d,x2=%d,y2=%d)\n",x1,y1,x2,y2);

	clear();

	obj = o,sx = x1,sy = y1,dx = x2,dy = y2;
	if(sx==dx && sy==dy) return 0;

debug_output("Path::searchPath(x1=%d,y1=%d,x2=%d,y2=%d)\n",x1,y1,x2,y2);
	cap = heur(*this,sx,sy)*8+1;
	p1 = new PathNode(sx,sy,0,heur(*this,sx,sy),0);
	closest = p1;
	put(p1);
	push(p1);

debug_output("Path::searchPath(x1=%d,y1=%d,x2=%d,y2=%d)\n",x1,y1,x2,y2);

	while(open) {
		if(step) step(*this,*open);
		p1 = pop();
debug_output("key=%08x\tx1=%d\ty1=%d\tx2=%d\ty2=%d\ts=%d\tg=%d\th=%d\n",p1->key,p1->x,p1->y,
p1->parent? p1->parent->x : -1,p1->parent? p1->parent->y : -1,p1->s,p1->g,p1->h);
		if(!l || p1->s<l) for(i=0,d=0; d!=-1; ++i) {
			d = move(*this,*p1,x,y,i);
			c = weight(*this,*p1,x,y);
			if(x==dx && y==dy) {
				if(c!=PATH_CANNOT_MOVE) {
					p1 = new PathNode(x,y,p1->g+1,0,p1);
					closest = p1;
					put(p1);
				}
				goto finished;
			} else if(c!=PATH_CANNOT_MOVE && c!=PATH_AVOID_MOVE) {
				if((p2=get(x,y))) {
					if(p1->g+c<p2->g) {
						remove(p2);
						p2->parent = p1,p2->g = p1->g+c,p2->s = p1->s+1;
						push(p2);
					}
				} else {
					p2 = new PathNode(x,y,p1->g+c,heur(*this,x,y),p1);
					if(p2->h<closest->h || (p2->h==closest->h && p2->g<closest->g)) closest = p2;
					put(p2);
					push(p2);
				}
			}
		}
	}

finished:

	return getTrail(closest);
}
Exemplo n.º 2
0
    void mouseDrag (const MouseEvent& e) override
    {
        Trail* t = getTrail (e.source);

        if (t == nullptr)
        {
            t = new Trail (e.source);
            t->path.startNewSubPath (e.getPosition().toFloat());
            trails.add (t);
        }

        t->pushPoint (e.getPosition().toFloat(), e.mods);
        repaint();
    }
Exemplo n.º 3
0
    void mouseDrag (const MouseEvent& e) override
    {
        Trail* t = getTrail (e.source);

        if (t == nullptr)
        {
            t = new Trail (e.source);
            t->path.startNewSubPath (e.position);
            trails.add (t);
        }

        t->pushPoint (e.position, e.mods, e.pressure);
        repaint();
    }
Exemplo n.º 4
0
 void mouseUp (const MouseEvent& e) override
 {
     trails.removeObject (getTrail (e.source));
     repaint();
 }