当前位置: 首页>>代码示例>>C++>>正文


C++ optional::get_ptr方法代码示例

本文整理汇总了C++中boost::optional::get_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ optional::get_ptr方法的具体用法?C++ optional::get_ptr怎么用?C++ optional::get_ptr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::optional的用法示例。


在下文中一共展示了optional::get_ptr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: params

cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, boost::optional<uint32_t> randomseed)
	: params(pparams)
	, flipx_(false)
	, flipy_(false)
	, map_(t_translation::ter_map(params.width_ + 2 * gamemap::default_border, params.height_ + 2 * gamemap::default_border/*, params.wall_*/))
	, starting_positions_()
	, chamber_ids_()
	, chambers_()
	, passages_()
	, res_(params.cfg_.child_or_empty("settings"))
	, rng_() //initialises with rand()
{
	res_.add_child("event", config_of
		("name", "start")
		("message", config_of
			("message", "scenario_generation=cave is deprecated and will be removed soon.")
		)
	);
	uint32_t seed = randomseed.get_ptr() ? *randomseed.get_ptr() : seed_rng::next_seed();
	rng_.seed(seed);
	LOG_NG << "creating random cave with seed: " << seed << '\n';
	flipx_ = int(rng_() % 100) < params.flipx_chance_;
	flipy_ = int(rng_() % 100) < params.flipy_chance_;

	LOG_NG << "creating scenario....\n";
	generate_chambers();

	LOG_NG << "placing chambers...\n";
	for(std::vector<chamber>::const_iterator c = chambers_.begin(); c != chambers_.end(); ++c) {
		place_chamber(*c);
	}

	LOG_NG << "placing passages...\n";

	for(std::vector<passage>::const_iterator p = passages_.begin(); p != passages_.end(); ++p) {
		place_passage(*p);
	}
	LOG_NG << "outputting map....\n";

	res_["map_data"] = t_translation::write_game_map(map_, starting_positions_);
}
开发者ID:doofus-01,项目名称:wesnoth,代码行数:41,代码来源:cave_map_generator.cpp

示例2: params

cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, boost::optional<boost::uint32_t> randomseed)
	: params(pparams)
	, flipx_(false)
	, flipy_(false)
	, map_(t_translation::t_map(params.width_ + 2 * gamemap::default_border,
	       t_translation::t_list(params.height_ + 2 * gamemap::default_border, params.wall_)))
	, starting_positions_()
	, chamber_ids_()
	, chambers_()
	, passages_()
	, res_(params.cfg_.child_or_empty("settings"))
	, rng_() //initialises with rand()
{
	uint32_t seed = randomseed.get_ptr() ? *randomseed.get_ptr() : seed_rng::next_seed();
	rng_.seed(seed);
	std::cerr << "creating random cave with seed:" << seed;
	flipx_ = int(rng_() % 100) < params.flipx_chance_;
	flipy_ = int(rng_() % 100) < params.flipy_chance_;

	LOG_NG << "creating scenario....\n";
	generate_chambers();

	LOG_NG << "placing chambers...\n";
	for(std::vector<chamber>::const_iterator c = chambers_.begin(); c != chambers_.end(); ++c) {
		place_chamber(*c);
	}

	LOG_NG << "placing passages...\n";

	for(std::vector<passage>::const_iterator p = passages_.begin(); p != passages_.end(); ++p) {
		place_passage(*p);
	}
	LOG_NG << "outputting map....\n";

	config& map = res_.add_child("map");
	map["data"] = t_translation::write_game_map(map_, starting_positions_);
	map["usage"] = "map";
	map["border_size"] = gamemap::default_border;
}
开发者ID:Martin9295,项目名称:wesnoth,代码行数:39,代码来源:cave_map_generator.cpp

示例3: generate_map

std::string default_map_generator::generate_map(std::map<map_location,std::string>* labels, boost::optional<uint32_t> randomseed)
{
    uint32_t seed;
    if(const uint32_t* pseed = randomseed.get_ptr()) {
        seed = *pseed;
    }
    else {
        seed = seed_rng::next_seed();
    }

    // Suppress labels?
    if ( !show_labels_ )
        labels = nullptr;

    // the random generator thinks odd widths are nasty, so make them even
    if (is_odd(width_))
        ++width_;

    size_t iterations = (iterations_*width_*height_)/(default_width_*default_height_);
    size_t island_size = 0;
    size_t island_off_center = 0;
    size_t max_lakes = max_lakes_;

    if(island_size_ >= max_coastal) {

        //islands look good with much fewer iterations than normal, and fewer lake
        iterations /= 10;
        max_lakes /= 9;

        //the radius of the island should be up to half the width of the map
        const size_t island_radius = 50 + ((max_island - island_size_)*50)/(max_island - max_coastal);
        island_size = (island_radius*(width_/2))/100;
    } else if(island_size_ > 0) {
        DBG_NG << "coastal...\n";
        //the radius of the island should be up to twice the width of the map
        const size_t island_radius = 40 + ((max_coastal - island_size_)*40)/max_coastal;
        island_size = (island_radius*width_*2)/100;
        island_off_center = std::min<size_t>(width_,height_);
        DBG_NG << "calculated coastal params...\n";
    }

    // A map generator can fail so try a few times to get a map before aborting.
    std::string map;
    // Keep a copy of labels as it can be written to by the map generator func
    std::map<map_location,std::string> labels_copy;
    std::map<map_location,std::string> * labels_ptr =  labels ? &labels_copy : nullptr;
    std::string error_message;
    //initilize the job outside the loop so that we really get a different result everytime we run the loop.
    default_map_generator_job job(seed);
    int tries = 10;
    do {
        if (labels) {
            // Reset the labels.
            labels_copy = *labels;
        }
        try {
            map = job.default_generate_map(width_, height_, island_size, island_off_center,
                                           iterations, hill_size_, max_lakes, (nvillages_ * width_ * height_) / 1000,
                                           castle_size_, nplayers_, link_castles_, labels_ptr, cfg_);
            error_message = "";
        }
        catch (mapgen_exception& exc) {
            error_message = exc.message;
        }
        --tries;
    } while (tries && map.empty());
    if (labels) {
        labels->swap(labels_copy);
    }

    if (error_message != "")
        throw mapgen_exception(error_message);

    return map;
}
开发者ID:CliffsDover,项目名称:wesnoth,代码行数:75,代码来源:default_map_generator.cpp

示例4: onInit

		const Label* onInit() const { return _on_init.get_ptr(); }
开发者ID:florian-asche,项目名称:hexabus,代码行数:1,代码来源:builder.hpp

示例5: onPeriodic

		const Label* onPeriodic() const { return _on_periodic.get_ptr(); }
开发者ID:florian-asche,项目名称:hexabus,代码行数:1,代码来源:builder.hpp

示例6: onPacket

		const Label* onPacket() const { return _on_packet.get_ptr(); }
开发者ID:florian-asche,项目名称:hexabus,代码行数:1,代码来源:builder.hpp


注:本文中的boost::optional::get_ptr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。