Пример #1
0
void pokemon_team_remove(){
    int index = *var_access(0x8004);
    int n = 0;
    cpuset(&n, &player_pokemon[index], 25 | CPUSET_FILL | CPUSET_WORD);
    int i;
    for(i = index; i < 5; i++){
        cpuset(&player_pokemon[i+1], &player_pokemon[i], 25 | CPUSET_COPY | CPUSET_WORD);
    }
}
Пример #2
0
bool script_cmd_x97_fadescreen(ow_script_state *ow_state){
    //dprintf("Script state is %x\n", ow_state->script);
    u8 type = *(ow_state->script++);
    //dprintf("Script state is %x\n", ow_state->script);
    if(type == 0 || type == 2){
        //Fade back from black or white
        cpuset(pal_tmp, pal_restore, 0x4000100);
    }else{
        cpuset(pal_restore, pal_tmp, 0x4000100);
    }
    fadescreen_all(type, 0);
    script_halt_and_callback(ow_state, fadescreen_is_active);
    return true;
}
Пример #3
0
void
setclasscpumask(login_cap_t *lc)
{
	const char *maskstr;
	cpuset_t maskset;
	cpusetid_t setid;

	maskstr = login_getcapstr(lc, "cpumask", NULL, NULL);
	CPU_ZERO(&maskset);
	if (maskstr == NULL)
		return;
	if (strcasecmp("default", maskstr) == 0)
		return;
	if (!list2cpuset(maskstr, &maskset)) {
		syslog(LOG_WARNING,
		    "list2cpuset(%s) invalid mask specification", maskstr);
		return;
	}

	if (cpuset(&setid) != 0) {
		syslog(LOG_ERR, "cpuset(): %s", strerror(errno));
		return;
	}

	if (cpuset_setaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1,
	    sizeof(maskset), &maskset) != 0)
		syslog(LOG_ERR, "cpuset_setaffinity(%s): %s", maskstr,
		    strerror(errno));
}
Пример #4
0
u8 *dungeon2_create_patch_layout(dungeon_generator2 *dg2, bool random_nodes){
    
    u8 *map1 = malloc((u32)(dg2->width * dg2->height));
    u8 *map2 = malloc((u32)(dg2->width * dg2->height));
    int _dg2_space = DG2_WALL | (DG2_WALL << 8);
    cpuset(&_dg2_space, map1, CPUSET_HALFWORD | CPUSET_FILL | 
            ((dg2->width * dg2->height) / 2));
    cpuset(&_dg2_space, map2, CPUSET_HALFWORD | CPUSET_FILL | 
            ((dg2->width * dg2->height) / 2));
    dungeon_init_unconnected_nodes(map1, dg2, random_nodes);
    dungeon2_enlarge(map1, map2, dg2);
    dungeon2_enlarge(map2, map1, dg2);
    dungeon2_iterate(map1, map2, 8, 1, dg2);
    free(map1);
    dungeon2_print_map(map2, dg2);
    return map2;
}
Пример #5
0
int dungeon2_flood_fill(u8 *map, u8 *map2, dungeon_generator2 *dg2){
    int width = dg2->width;
    int height = dg2->height;
    
    //Initialize map2 with walls only
    int _dg2_wall = DG2_WALL | (DG2_WALL << 8);
    cpuset(&_dg2_wall, map2, CPUSET_FILL | CPUSET_HALFWORD | (width * height / 2));
    
    //Find a root for flood fill (hope it is part of the biggest connected subgraph)
    s16 x, y;
    do{
        x = (s16)((int)dungeon2_rnd(dg2) % width);
        y = (s16)((int)dungeon2_rnd(dg2) % height);
    }while(map[y * height + x] == DG2_WALL);
    
    int filled_tiles = 0;
    coordinate_t *stack = malloc((size_t)((int)sizeof(coordinate_t) * width * height));
    stack[0].x = x;
    stack[0].y = y;
    int stack_size = 1;
    while(stack_size > 0){
        stack_size--;
        x = stack[stack_size].x;
        y = stack[stack_size].y;
        s16 _x = x;
        while(_x > 0 && map[y * height + _x] == DG2_SPACE) _x--;
        _x++;
        bool span_above = false;
        bool span_below = false;
        while(_x < width && map[y * height + _x] == DG2_SPACE){
            //Fill the span
            map[y * height + _x] = DG2_WALL;
            map2[y * height + _x] = DG2_SPACE;
            filled_tiles++;
            
            if(!span_above && y > 0 && map[(y - 1) * height + _x] == DG2_SPACE){
                stack[stack_size].x = _x;
                stack[stack_size].y = (s16)(y - 1);
                stack_size++;
                span_above = true;
            }else if(span_above && y > 0 && map[(y - 1) * height + _x] == DG2_WALL){
                span_above = false;
            }else if(!span_below && y < height - 1 && map[(y + 1) * height + _x] == DG2_SPACE){
                stack[stack_size].x = _x;
                stack[stack_size].y = (s16)(y + 1);
                stack_size++;
                span_below= true;
            }else if(span_below && y < height - 1 && map[(y + 1) * height + _x] == DG2_WALL){
                span_below = false;
            }
            _x++;
        }
    }
    free(stack);
    return filled_tiles;
    
}
Пример #6
0
void dungeon2_compute_blocks_cave(u8 *map, u8 *over, dungeon_generator2 *dg2){
  (void)over;

  // Remove the walls in over
  for (int x = 0; x < dg2->width; x++) {
    for (int y = 0; y < dg2->height; y++) {
      // We actually want the patches to be walls in order to render them, so we invert
      // wall -> space, space -> wall
      // Also remove overlaps with the map free space, so we will
      if (map[y * dg2->width + x] == DG2_WALL) {
        over[y * dg2->width + x] = DG2_SPACE;
      } else {
        if (over[y * dg2->width + x] == DG2_WALL)
          over[y * dg2->width + x] = DG2_SPACE;
        else
          over[y * dg2->width + x] = DG2_WALL;
      }
    }
  }

    //u8 *map2 = malloc(sizeof(u8) * (size_t)(dg2->width * dg2->height));
  dungeon2_cave_draw_map(map, WALL_SET_GROUND, dg2);
  // Allocate a map that can be manipulated in order to remove walls
  u8 *map2 = malloc(sizeof(u8) * (size_t)(dg2->width * dg2->height));
  int _dg2_wall = DG2_WALL | (DG2_WALL << 8);
  cpuset(&_dg2_wall, map2, CPUSET_HALFWORD | CPUSET_FILL |
          ((dg2->width * dg2->height) / 2));
  dungeon2_cave_remove_walls(map, map2, dg2);
  dungeon2_cave_draw_map(map2, WALL_SET_LEVEL, dg2);
  dungeon2_cave_remove_walls(map2, map, dg2);
  dungeon2_cave_remove_walls(map, map2, dg2);
  dungeon2_cave_draw_map(map2, WALL_SET_LEVEL, dg2);
  free(map2);

  // Draw the sand
  dungeon2_cave_draw_map(over, WALL_SET_SAND, dg2);

}
Пример #7
0
int
main(int argc, char *argv[])
{
	cpusetid_t setid;
	cpuset_t mask;
	lwpid_t tid;
	pid_t pid;
	int ch;

	CPU_ZERO(&mask);
	level = CPU_LEVEL_WHICH;
	which = CPU_WHICH_PID;
	id = pid = tid = setid = -1;
	while ((ch = getopt(argc, argv, "Ccgij:l:p:rs:t:x:")) != -1) {
		switch (ch) {
		case 'C':
			Cflag = 1;
			break;
		case 'c':
			if (rflag)
				usage();
			cflag = 1;
			level = CPU_LEVEL_CPUSET;
			break;
		case 'g':
			gflag = 1;
			break;
		case 'i':
			iflag = 1;
			break;
		case 'j':
			jflag = 1;
			which = CPU_WHICH_JAIL;
			id = atoi(optarg);
			break;
		case 'l':
			lflag = 1;
			parselist(optarg, &mask);
			break;
		case 'p':
			pflag = 1;
			which = CPU_WHICH_PID;
			id = pid = atoi(optarg);
			break;
		case 'r':
			if (cflag)
				usage();
			level = CPU_LEVEL_ROOT;
			rflag = 1;
			break;
		case 's':
			sflag = 1;
			which = CPU_WHICH_CPUSET;
			id = setid = atoi(optarg);
			break;
		case 't':
			tflag = 1;
			which = CPU_WHICH_TID;
			id = tid = atoi(optarg);
			break;
		case 'x':
			xflag = 1;
			which = CPU_WHICH_IRQ;
			id = atoi(optarg);
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;
	if (gflag) {
		if (argc || Cflag || lflag)
			usage();
		/* Only one identity specifier. */
		if (jflag + xflag + sflag + pflag + tflag > 1)
			usage();
		if (iflag)
			printsetid();
		else
			printaffinity();
		exit(EXIT_SUCCESS);
	}
	if (iflag)
		usage();
	/*
	 * The user wants to run a command with a set and possibly cpumask.
	 */
	if (argc) {
		if (Cflag | pflag | rflag | tflag | xflag | jflag)
			usage();
		if (sflag) {
			if (cpuset_setid(CPU_WHICH_PID, -1, setid))
				err(argc, "setid");
		} else {
			if (cpuset(&setid))
				err(argc, "newid");
		}
		if (lflag) {
			if (cpuset_setaffinity(level, CPU_WHICH_PID,
			    -1, sizeof(mask), &mask) != 0)
				err(EXIT_FAILURE, "setaffinity");
		}
		errno = 0;
		execvp(*argv, argv);
		err(errno == ENOENT ? 127 : 126, "%s", *argv);
	}
	/*
	 * We're modifying something that presently exists.
	 */
	if (Cflag && (sflag || rflag || !pflag || tflag || xflag || jflag))
		usage();
	if (!lflag && (cflag || rflag))
		usage();
	if (!lflag && !(Cflag || sflag))
		usage();
	/* You can only set a mask on a thread. */
	if (tflag && (sflag | pflag | xflag | jflag))
		usage();
	/* You can only set a mask on an irq. */
	if (xflag && (jflag | pflag | sflag | tflag))
		usage();
	if (Cflag) {
		/*
		 * Create a new cpuset and move the specified process
		 * into the set.
		 */
		if (cpuset(&setid) < 0)
			err(EXIT_FAILURE, "newid");
		sflag = 1;
	}
	if (pflag && sflag) {
		if (cpuset_setid(CPU_WHICH_PID, pid, setid))
			err(EXIT_FAILURE, "setid");
		/*
		 * If the user specifies a set and a list we want the mask
		 * to effect the pid and not the set.
		 */
		which = CPU_WHICH_PID;
		id = pid;
	}
	if (lflag) {
		if (cpuset_setaffinity(level, which, id, sizeof(mask),
		    &mask) != 0)
			err(EXIT_FAILURE, "setaffinity");
	}

	exit(EXIT_SUCCESS);
}