示例#1
0
/* start */
int random_start(ubx_block_t *b)
{
  DBG("in");
  uint32_t seed, ret;
  unsigned int clen;
  struct random_config* rndconf;
  struct rnd_info* inf;

  inf=(struct rnd_info*) b->private_data;

  /* get and store min_max_config */
  rndconf = (struct random_config*) ubx_config_get_data_ptr(b, "min_max_config", &clen);
  inf->info.min = rndconf->min;
  inf->info.max = (rndconf->max == 0) ? INT_MAX : rndconf->max;

  /* seed is allowed to change at runtime, check if new one available */
  ubx_port_t* seed_port = ubx_port_get(b, "seed");
  ret = read_seed(seed_port, &seed);

  if(ret>0) {
    DBG("starting component. Using seed: %d, min: %d, max: %d", seed, inf->info.min, inf->info.max);
    srandom(seed);
  } else {
    DBG("starting component. Using min: %d, max: %d", inf->info.min, inf->info.max);
  }
  return ret;
}
示例#2
0
void EmergeManager::loadParamsFromSettings(Settings *settings) {
	std::string seed_str;
	const char *setname = (settings == g_settings) ? "fixed_map_seed" : "seed";

	if (settings->getNoEx(setname, seed_str))
		params.seed = read_seed(seed_str.c_str());

	settings->getNoEx("mg_name",         params.mg_name);
	settings->getS16NoEx("water_level",  params.water_level);
	settings->getS16NoEx("chunksize",    params.chunksize);
	settings->getFlagStrNoEx("mg_flags", params.flags, flagdesc_mapgen);

	delete params.sparams;
	params.sparams = createMapgenParams(params.mg_name);
	if (params.sparams)
		params.sparams->readParams(settings);
}
示例#3
0
MapgenParams *EmergeManager::getParamsFromSettings(Settings *settings) {
	std::string mg_name = settings->get("mg_name");
	MapgenParams *mgparams = createMapgenParams(mg_name);
	if (!mgparams)
		return NULL;

	std::string seedstr = settings->get(settings == g_settings ?
									"fixed_map_seed" : "seed");

	mgparams->mg_name     = mg_name;
	mgparams->seed        = read_seed(seedstr.c_str());
	mgparams->water_level = settings->getS16("water_level");
	mgparams->chunksize   = settings->getS16("chunksize");
	mgparams->flags       = settings->getFlagStr("mg_flags", flagdesc_mapgen);

	if (!mgparams->readParams(settings)) {
		delete mgparams;
		return NULL;
	}
	return mgparams;
}
示例#4
0
static int load_seeds(struct globals *globals, int srows, int scols, int nseg)
{
    int row, col;
    SEGMENT seeds_seg;
    CELL *seeds_buf, seeds_val;
    int seeds_fd;
    int spos, sneg, have_seeds;
    struct rc Ri;

    G_debug(1, "load_seeds()");
    
    G_message(_("Loading seeds from raster map <%s>..."), globals->seeds);

    if (Segment_open
	(&seeds_seg, G_tempfile(), globals->nrows, globals->ncols,
	 srows, scols, sizeof(CELL), nseg) != TRUE)
	G_fatal_error("Unable to create bounds temporary files");

    seeds_fd = Rast_open_old(globals->seeds, "");
    seeds_buf = Rast_allocate_c_buf();
    
    have_seeds = 0;

    /* load seeds map to segment structure */
    for (row = 0; row < globals->nrows; row++) {
	Rast_get_c_row(seeds_fd, seeds_buf, row);
	for (col = 0; col < globals->ncols; col++) {
	    if (FLAG_GET(globals->null_flag, row, col)) {
		Rast_set_c_null_value(&seeds_val, 1);
	    }
	    else {
		seeds_val = seeds_buf[col];
		if (!Rast_is_c_null_value(&seeds_val))
		    have_seeds = 1;
	    }
	    if (Segment_put(&seeds_seg, &seeds_val, row, col) != 1)
		G_fatal_error(_("Unable to write to temporary file"));
	}
    }

    if (!have_seeds) {
	G_warning(_("No seeds found in '%s'!"), globals->seeds);
	G_free(seeds_buf);
	Rast_close(seeds_fd);
	Segment_close(&seeds_seg);
	return 0;
    }

    spos = 1;
    sneg = -1;

    /* convert seeds to regions */
    G_debug(1, "convert seeds to regions");
    Rast_set_c_null_value(&seeds_val, 1);
    for (row = 0; row < globals->nrows; row++) {
	Rast_get_c_row(seeds_fd, seeds_buf, row);
	for (col = 0; col < globals->ncols; col++) {
	    if (!(FLAG_GET(globals->null_flag, row, col)) && 
	        !(FLAG_GET(globals->candidate_flag, row, col))) {

		if (Rast_is_c_null_value(&(seeds_buf[col]))) {
		    if (Segment_put(&globals->rid_seg, &sneg, row, col) != 1)
			G_fatal_error(_("Unable to write to temporary file"));
		    sneg--;
		    globals->n_regions--;
		}
		else {
		    Ri.row = row;
		    Ri.col = col;
		    read_seed(globals, &seeds_seg, &Ri, spos);
		    spos++;
		}
	    }
	}
    }

    G_free(seeds_buf);
    Rast_close(seeds_fd);
    Segment_close(&seeds_seg);

    globals->n_regions = spos - 1;
    
    flag_clear_all(globals->candidate_flag);
    
    return 1;
}