コード例 #1
0
ファイル: InputDevice.cpp プロジェクト: Bennieboj/ppsspp
std::list<std::shared_ptr<InputDevice>> getInputDevices() {
	std::list<std::shared_ptr<InputDevice>> list;
	PUSH_BACK(XinputDevice);
	PUSH_BACK(DinputDevice);
	PUSH_BACK(KeyboardDevice);
	return list;
}
コード例 #2
0
ファイル: testlist.c プロジェクト: Oooocean/chuck
int main(){
	list l;
	list_init(&l);
	int i = 0;
	for(;i < 10;++i){
		PUSH_BACK(&l,i);
	}

	int size = list_size(&l);
	for(i = 0;i < size;++i){
		printf("%d\n",POP(&l));
	}

	printf("-----------reverse---------\n");

	for(i = 0;i < 10;++i){
		PUSH_BACK(&l,i);
	}
	size = list_size(&l);
	for(i = 0;i < size;++i){
		printf("%d\n",POP(&l));
	}


	printf("-----------pushlist---------\n");	

	for(i = 0;i < 10;++i){
		PUSH_BACK(&l,i);
	}

	list ll;
	list_init(&ll);
	for(i = 0;i < 10;++i){
		PUSH_BACK(&ll,i*10);
	}

	list_pushlist(&l,&ll);

	printf("size ll:%d",list_size(&ll));
	size = list_size(&l);
	for(i = 0;i < size;++i){
		printf("%d\n",POP(&l));
	}




	return 0;
}
コード例 #3
0
ファイル: ls_route.c プロジェクト: lally/ioquake
bool pathFind(int_vec_t *destpath,
              struct position pos, 
              struct position dest,
              const waypoint_vec_t* wmap,
              const region_map_t* regs) {
    path_bitmap_t seen;
    init_path_bitmap(&seen);
    //
    // find the closest positions for 'pos' and 'dest'
    double min_p = INFINITY, min_d = INFINITY;
    int i_p = -1, i_d = -1;
    int i;
    for (i=0; i<SIZE(*wmap); ++i) {
        if (GET(*wmap,i).flags & LPR_ROUTEONLY)
            continue;
        double pdist = distance(pos, GET(*wmap,i).pos, regs);
        double ddist = distance(dest, GET(*wmap,i).pos, regs);
        if (min_p == INFINITY || (pdist != INFINITY && min_p > pdist)) {
            min_p = pdist; i_p = i;
        }

        if (min_d == INFINITY || (ddist != INFINITY && min_d > ddist)) {
            min_d = ddist; i_d = i;
        }
    }
    PUSH_BACK(*destpath,i_p);
    set(&seen, i_p);
    return pathFindWork(destpath, i_p, i_d, seen, wmap, regs) != INFINITY;
}
コード例 #4
0
ファイル: ls_route.c プロジェクト: lally/ioquake
bool makeWaypointTable(waypoint_vec_t		*dest,
                       const region_map_t*	 regs,
                       int			 nwaypoints,
                       struct waypoint_init*     inits) {
    struct waypoint init = {{0.0, 0.0}, 0, {INFINITY, INFINITY}};
    assert(dest);
    assert(inits);
    if (nwaypoints > NR_POINTS) 
        return false;
    int i;
    for (i=0; i<NR_POINTS; ++i) 
        init.distances[i] = INFINITY;

    CLEAR(*dest);
    int w;
    for (w=0; w<nwaypoints; w++) {
        PUSH_BACK(*dest, init);
        GET(*dest,w).pos = inits[w].p;
        GET(*dest,w).flags = inits[w].flags;
        int r;
        int offset;
        for (r=0; r<nwaypoints; ++r) {
            int r_local = r;
            if (r > 31) {
                offset = 0;
                r_local -= 32;
            } else {
                offset = 1;
            }
            if(inits[w].reachable_bitmap[offset] & (1 << r_local)) {
                //	iprintf ("  %s: bit %d of 0x%x is set, connecting to %s\n", 
                //		inits[w].comment, r, inits[w].reachable_bitmap, inits[r].comment);
                GET(*dest,w).distances[r] = rawDistance(GET(*dest,w).pos, inits[r].p);
            } 
            else {
                GET(*dest, w).distances[r] = INFINITY;
            }
            // all routing is now explicit.
            /*else {
              GET(*dest,w).distances[r] = distance(GET(*dest,w).pos, inits[r].p, regs);
              }*/
        }
    }
  
    return true;
}
コード例 #5
0
ファイル: ls_route.c プロジェクト: lally/ioquake
void sortedWaypoints(int_vec_t* dest,
                     int start, int end,
                     const waypoint_vec_t* wmap,
                     const region_map_t* regs) {
    // Return, heuristically-sorted, the waypoints.
    BEGIN_DEPTH;
    assert(start >=0);
    assert(end >=0);
    double distances[NR_POINTS];
    int w;
    for (w=0; w<NR_POINTS; w++) {
        if (start != w) {
            if ((distances[w] = GET(*wmap,start).distances[w]) 
                != INFINITY)
                PUSH_BACK(*dest, w);
        } else {
            distances[w] = INFINITY;
        }
    }
    qhsort(BEGIN(*dest), SIZE(*dest), sizeof(int), comparator, (void*) distances);
    END_DEPTH;
}
コード例 #6
0
ファイル: ls_route.c プロジェクト: lally/ioquake
/* test routine */
int test_main(int args, char ** argv) {
    int i,j;
    waypoint_vec_t wmap;
    region_map_t regs;
    INIT(wmap);
    INIT(regs);
    bool ret;

    for (i=0; i<7; i++) {
        PUSH_BACK(regs, regions[i]);
    }

    int self_refs = 0;
    bool r = makeWaypointTable(&wmap, &regs, NR_POINTS, points);
    iprintf ("Waypoint Table: \n");
    iprintf ("          \t                   ");

    for (i=0; i<SIZE(wmap); ++i) {
        iprintf("%6d ", i);
    }
    iprintf("\n");


    for (i=0; i<SIZE(wmap); ++i) {
        iprintf ("%d: %5s\t (%7.1f,%7.1f) ", i, points[i].comment,
                 GET(wmap, i).pos.x, GET(wmap, i).pos.y);
        for (j=0; j<SIZE(wmap); j++) {
            double dist = GET(wmap, i).distances[j];
            char sep = ((j+1)%5) == 0? '|':' ';
            if (dist == INFINITY) {
                iprintf ("      %c", sep);
            } else if (dist < 0.01) {
                if (i == j) {
                    iprintf ("   *  %c", sep);
                    self_refs++;
                } else {
                    iprintf ("   X  %c", sep);
                }
            } else {
                iprintf ("%6.1f%c", GET(wmap, i).distances[j], sep);
            }
        }
        iprintf ("\n");
    }
    iprintf("\nSelf References: %d\n", self_refs);

    iprintf ("Starting waypoint-waypoint tests.\n");

    for (i=0; i<SIZE(wmap); ++i) {
        int_vec_t path;
        INIT(path);
        ret = pathFind(&path, GET(wmap,0).pos, GET(wmap, i).pos,
                       &wmap, &regs);
        iprintf ("RESULT:  %d to %d: ", 0, i);
        for (j=0; j<SIZE(path); ++j) {
            iprintf ("%s (%d) ", points[GET(path,j)].comment, 
                     GET(path,j));
        }
        iprintf ("\n");
    }


    char startbuffer[128];
    char endbuffer[128];
    iprintf ("Interactive mode. Hit Ctrl-C to exit.\n");
    while (true) {
        iprintf ("\nStart: ");
        fgets(startbuffer, 127, stdin);
        startbuffer[127] = 0;
        iprintf ("End: ");
        fgets(endbuffer, 127, stdin);
        endbuffer[127] = 0;

        char *s, *e;
        if (strchr(startbuffer, '\n')) {
            (*strchr(startbuffer, '\n')) = 0;
        }
        if (strchr(endbuffer, '\n')) {
            (*strchr(endbuffer, '\n')) = 0;
        }

        s = startbuffer;
        while (isspace(*s))
            s++;
        e = endbuffer;
        while (isspace(*e))
            e++;
    
    

    
        int start=-1, end=-1;
        for (i=0; i<SIZE(wmap) && start < 0; ++i) {
            if (!strcasecmp(s, points[i].comment)) {
                start = i;
            }
        }

        for (i=0; i<SIZE(wmap) && end < 0; ++i) {
            if (!strcasecmp(e, points[i].comment)) {
                end = i;
            }
        }

        if (start < 0) {
            iprintf("%s not found.\n", s);
            continue;
        }
    
        if (end < 0) {
            iprintf("%s not found.\n", e);
            continue;
        }
    
        iprintf ("Routing from %s to %s...\n", points[start].comment, 
                 points[end].comment);

        int_vec_t path;
        INIT(path);
        ret = pathFind(&path, GET(wmap, start).pos, GET(wmap, end).pos,
                       &wmap, &regs);
        for (j=0; j<SIZE(path); ++j) {
            iprintf ("%s (%d) ", points[GET(path,j)].comment, 
                     GET(path,j));
        }
    } 
}
コード例 #7
0
ファイル: ls_route.c プロジェクト: lally/ioquake
static double pathFindWork(int_vec_t *destpath,
                           int pos, int dest,
                           path_bitmap_t seen,
                           const waypoint_vec_t* wmap,
                           const region_map_t* regs) {
    BEGIN_DEPTH;
    int_vec_t wpoints;
    INIT(wpoints);
    assert(pos >=0);
    assert(dest >=0);

    // already there.
    if (pos == dest) {
        END_DEPTH;
        return 0.0;
    }

    if (full_set(&seen)) { 
        END_DEPTH;
        return INFINITY; 
    }

    if (GET(*wmap,pos).distances[dest] != INFINITY) {
        PUSH_BACK(*destpath, dest);
        END_DEPTH;
        return GET(*wmap,pos).distances[dest];
    }

    sortedWaypoints(&wpoints, pos, dest, wmap, regs);
    // remove those we've already seen.
    int j = 0;
    while (j < SIZE(wpoints)) {
        if (is_set(&seen, GET(wpoints,j))) {
            ERASE(wpoints, j);
        }
        else {
            ++j;
        }
    }

    if (SIZE(wpoints) == 0) {
        END_DEPTH;
        return INFINITY; 
    }

    const int offset = SIZE(*destpath);
    int lowest_idx = -1;
    double lowest_value = INFINITY;

    int_vec_t tmp;
    INIT(tmp);
    COPY(tmp, *destpath);
    int i;
    for (i=0; i<SIZE(wpoints); ++i) {
        if (!is_set(&seen, GET(wpoints,i))) {
            double val;

            PUSH_BACK(tmp, GET(wpoints,i));
            path_bitmap_t local_seen = seen;
            set(&local_seen, GET(wpoints,i));
            val = pathFindWork(&tmp, GET(wpoints,i), dest, local_seen, wmap, regs)
                + GET(*wmap,pos).distances[GET(wpoints,i)];

            if (lowest_value == INFINITY 
                || (val != INFINITY && val < lowest_value)) {
                lowest_value = val;
                lowest_idx = GET(wpoints,i);
                COPY(*destpath, tmp);
                END_DEPTH;
                // with this return, it's an A* search.  without, it's
                // a DFS.
                return val;
            } 

            RESIZE(tmp, offset);
        }
    }

    // at the end, destpath has the minimum path we've seen so far,
    // and now we're returning our distance to the path we've appended on.

    END_DEPTH;
    return lowest_value; // + distance(wmap[pos].pos, wmap[lowest_idx].pos, regs);
}