/** * Start the pipeline streaming according to the configuraion. * The pipeline streaming loop captures samples from the device, and delivers them to the attached computer vision modules * and processing blocks, according to each module requirements and threading model. * During the loop execution, the application can access the camera streams by calling \c wait_for_frames() or * \c poll_for_frames(). * The streaming loop runs until the pipeline is stopped. * Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised. * The pipeline selects and activates the device upon start, according to configuration or a default configuration. * When the rs2::config is provided to the method, the pipeline tries to activate the config \c resolve() result. * If the application requests are conflicting with pipeline computer vision modules or no matching device is available on * the platform, the method fails. * Available configurations and devices may change between config \c resolve() call and pipeline start, in case devices * are connected or disconnected, or another application acquires ownership of a device. * * \param[in] config A rs2::config with requested filters on the pipeline configuration. By default no filters are applied. * \return The actual pipeline device and streams profile, which was successfully configured to the streaming device. */ pipeline_profile start(const config& config) { rs2_error* e = nullptr; auto p = std::shared_ptr<rs2_pipeline_profile>( rs2_pipeline_start_with_config(_pipeline.get(), config.get().get(), &e), rs2_delete_pipeline_profile); error::handle(e); return pipeline_profile(p); }
pipeline_profile start(const config& config, S callback) { rs2_error* e = nullptr; auto p = std::shared_ptr<rs2_pipeline_profile>( rs2_pipeline_start_with_config_and_callback_cpp(_pipeline.get(), config.get().get(), new frame_callback<S>(callback), &e), rs2_delete_pipeline_profile); error::handle(e); return pipeline_profile(p); }
void schema_validator::validate(const config & cfg, const std::string & name, int start_line, const std::string &file){ //close previous errors and print them to output. message_map::iterator cache_it = cache_.top().begin(); for (;cache_it != cache_.top().end();++cache_it){ for (message_list::iterator i = cache_it->second.begin(); i != cache_it->second.end(); ++i){ print(*i); } } cache_.pop(); // clear cache cache_it = cache_.top().find(&cfg); if (cache_it != cache_.top().end()){ cache_it->second.clear(); } // Please note that validating unknown tag keys the result will be false // Checking all elements counters. if (!stack_.empty() && stack_.top() && config_read_){ class_tag::all_const_tag_iterators p = stack_.top()->tags(); for (class_tag::const_tag_iterator tag = p.first; tag != p.second ; ++tag){ int cnt = counter_.top()[tag->first].cnt; if (tag->second.get_min() > cnt){ cache_.top()[&cfg].push_back( message_info(MISSING_TAG,file,start_line, tag->second.get_min(),tag->first,"", name)); continue; } if (tag->second.get_max() < cnt){ cache_.top()[&cfg].push_back( message_info(EXTRA_TAG,file,start_line, tag->second.get_max(),tag->first,"", name)); } } // Checking if all mandatory keys are present class_tag::all_const_key_iterators k = stack_.top()->keys(); for (class_tag::const_key_iterator key = k.first; key != k.second ; ++key){ if (key->second.is_mandatory()){ if (cfg.get(key->first) == nullptr){ cache_.top()[&cfg].push_back( message_info(MISSING_KEY,file,start_line,0, name,key->first )); } } } } }
frame_builder::frame_builder(const config& cfg,const std::string& frame_string) : duration_(1), image_(cfg[frame_string + "image"]), image_diagonal_(cfg[frame_string + "image_diagonal"]), image_mod_(cfg[frame_string + "image_mod"]), halo_(cfg[frame_string + "halo"]), halo_x_(cfg[frame_string + "halo_x"]), halo_y_(cfg[frame_string + "halo_y"]), halo_mod_(cfg[frame_string + "halo_mod"]), sound_(cfg[frame_string + "sound"]), text_(cfg[frame_string + "text"]), text_color_(0), blend_with_(0), blend_ratio_(cfg[frame_string + "blend_ratio"]), highlight_ratio_(cfg[frame_string + "alpha"]), offset_(cfg[frame_string + "offset"]), submerge_(cfg[frame_string + "submerge"]), x_(cfg[frame_string + "x"]), y_(cfg[frame_string + "y"]), directional_x_(cfg[frame_string + "directional_x"]), directional_y_(cfg[frame_string + "directional_y"]), auto_vflip_(t_unset), auto_hflip_(t_unset), primary_frame_(t_unset), drawing_layer_(cfg[frame_string + "layer"]) { if(!cfg.has_attribute(frame_string + "auto_vflip")) { auto_vflip_ = t_unset; } else if(cfg[frame_string + "auto_vflip"].to_bool()) { auto_vflip_ = t_true; } else { auto_vflip_ = t_false; } if(!cfg.has_attribute(frame_string + "auto_hflip")) { auto_hflip_ = t_unset; } else if(cfg[frame_string + "auto_hflip"].to_bool()) { auto_hflip_ = t_true; } else { auto_hflip_ = t_false; } if(!cfg.has_attribute(frame_string + "primary")) { primary_frame_ = t_unset; } else if(cfg[frame_string + "primary"].to_bool()) { primary_frame_ = t_true; } else { primary_frame_ = t_false; } std::vector<std::string> color = utils::split(cfg[frame_string + "text_color"]); if (color.size() == 3) { text_color_ = display::rgb(atoi(color[0].c_str()), atoi(color[1].c_str()), atoi(color[2].c_str())); } if (const config::attribute_value *v = cfg.get(frame_string + "duration")) { duration(*v); } else if (!cfg.get(frame_string + "end")) { int halo_duration = (progressive_string(halo_,1)).duration(); int image_duration = (progressive_image(image_,1)).duration(); int image_diagonal_duration = (progressive_image(image_diagonal_,1)).duration(); duration(std::max(std::max(image_duration,image_diagonal_duration),halo_duration)); } else { duration(cfg[frame_string + "end"].to_int() - cfg[frame_string + "begin"].to_int()); } duration_ = std::max(duration_,1); color = utils::split(cfg[frame_string + "blend_color"]); if (color.size() == 3) { blend_with_ = display::rgb(atoi(color[0].c_str()), atoi(color[1].c_str()), atoi(color[2].c_str())); } }
frame_builder::frame_builder(const config& cfg,const std::string& frame_string) : duration_(1) , image_(cfg[frame_string + "image"]) , image_diagonal_(cfg[frame_string + "image_diagonal"]) , image_mod_(cfg[frame_string + "image_mod"]) , halo_(cfg[frame_string + "halo"]) , halo_x_(cfg[frame_string + "halo_x"]) , halo_y_(cfg[frame_string + "halo_y"]) , halo_mod_(cfg[frame_string + "halo_mod"]) , sound_(cfg[frame_string + "sound"]) , text_(cfg[frame_string + "text"]) , blend_ratio_(cfg[frame_string + "blend_ratio"]) , highlight_ratio_(cfg[frame_string + "alpha"]) , offset_(cfg[frame_string + "offset"]) , submerge_(cfg[frame_string + "submerge"]) , x_(cfg[frame_string + "x"]) , y_(cfg[frame_string + "y"]) , directional_x_(cfg[frame_string + "directional_x"]) , directional_y_(cfg[frame_string + "directional_y"]) , auto_vflip_(boost::logic::indeterminate) , auto_hflip_(boost::logic::indeterminate) , primary_frame_(boost::logic::indeterminate) , drawing_layer_(cfg[frame_string + "layer"]) { if(!cfg.has_attribute(frame_string + "auto_vflip")) { auto_vflip_ = boost::logic::indeterminate; } else { auto_vflip_ = cfg[frame_string + "auto_vflip"].to_bool(); } if(!cfg.has_attribute(frame_string + "auto_hflip")) { auto_hflip_ = boost::logic::indeterminate; } else { auto_hflip_ = cfg[frame_string + "auto_hflip"].to_bool(); } if(!cfg.has_attribute(frame_string + "primary")) { primary_frame_ = boost::logic::indeterminate; } else { primary_frame_ = cfg[frame_string + "primary"].to_bool(); } const auto& text_color_key = cfg[frame_string + "text_color"]; if(!text_color_key.empty()) { try { text_color_ = color_t::from_rgb_string(text_color_key); } catch(const std::invalid_argument& e) { // Might be thrown either due to an incorrect number of elements or std::stoul failure. ERR_NG << "Invalid RBG text color in unit animation: " << text_color_key.str() << "\n" << e.what() << "\n;"; } } if(const config::attribute_value* v = cfg.get(frame_string + "duration")) { duration(*v); } else if(!cfg.get(frame_string + "end")) { int halo_duration = (progressive_string(halo_, 1)).duration(); int image_duration = (progressive_image(image_, 1)).duration(); int image_diagonal_duration = (progressive_image(image_diagonal_, 1)).duration(); duration(std::max(std::max(image_duration, image_diagonal_duration), halo_duration)); } else { duration(cfg[frame_string + "end"].to_int() - cfg[frame_string + "begin"].to_int()); } duration_ = std::max(duration_, 1); const auto& blend_color_key = cfg[frame_string + "blend_color"]; if(!blend_color_key.empty()) { try { blend_with_ = color_t::from_rgb_string(blend_color_key); } catch(const std::invalid_argument& e) { // Might be thrown either due to an incorrect number of elements or std::stoul failure. ERR_NG << "Invalid RBG blend color in unit animation: " << blend_color_key.str() << "\n" << e.what() << "\n;"; } } }
void load_config(const config &v) { base_income = v["base_income"].to_int(2); village_income = v["village_income"].to_int(1); village_support = v["village_support"].to_int(1); poison_amount = v["poison_amount"].to_int(8); rest_heal_amount = v["rest_heal_amount"].to_int(2); recall_cost = v["recall_cost"].to_int(20); kill_experience = v["kill_experience"].to_int(8); combat_experience= v["combat_experience"].to_int(1); lobby_refresh = v["lobby_refresh"].to_int(2000); default_terrain = v["default_terrain"].str(); tile_size = v["tile_size"].to_int(72); std::vector<std::string> zoom_levels_str = utils::split(v["zoom_levels"]); if(!zoom_levels_str.empty()) { zoom_levels.clear(); std::transform(zoom_levels_str.begin(), zoom_levels_str.end(), std::back_inserter(zoom_levels), [](const std::string zoom) { return static_cast<int>(std::stold(zoom) * tile_size); }); } title_music = v["title_music"].str(); lobby_music = v["lobby_music"].str(); default_victory_music = utils::split(v["default_victory_music"].str()); default_defeat_music = utils::split(v["default_defeat_music"].str()); if(const config& i = v.child("colors")){ using namespace game_config::colors; moved_orb_color = i["moved_orb_color"].str(); unmoved_orb_color = i["unmoved_orb_color"].str(); partial_orb_color = i["partial_orb_color"].str(); enemy_orb_color = i["enemy_orb_color"].str(); ally_orb_color = i["ally_orb_color"].str(); } // colors show_ally_orb = v["show_ally_orb"].to_bool(true); show_enemy_orb = v["show_enemy_orb"].to_bool(false); show_moved_orb = v["show_moved_orb"].to_bool(true); show_partial_orb = v["show_partly_orb"].to_bool(true); show_unmoved_orb = v["show_unmoved_orb"].to_bool(true); if(const config& i = v.child("images")){ using namespace game_config::images; game_title = i["game_title"].str(); game_title_background = i["game_title_background"].str(); game_logo = i["game_logo"].str(); game_logo_background = i["game_logo_background"].str(); victory_laurel = i["victory_laurel"].str(); victory_laurel_hardest = i["victory_laurel_hardest"].str(); victory_laurel_easy = i["victory_laurel_easy"].str(); orb = i["orb"].str(); energy = i["energy"].str(); battery_icon = i["battery_icon"].str(); time_icon = i["time_icon"].str(); flag = i["flag"].str(); flag_icon = i["flag_icon"].str(); terrain_mask = i["terrain_mask"].str(); grid_top = i["grid_top"].str(); grid_bottom = i["grid_bottom"].str(); mouseover = i["mouseover"].str(); selected = i["selected"].str(); editor_brush = i["editor_brush"].str(); unreachable = i["unreachable"].str(); linger = i["linger"].str(); observer = i["observer"].str(); tod_bright = i["tod_bright"].str(); tod_dark = i["tod_dark"].str(); level = i["level"].str(); ellipsis = i["ellipsis"].str(); missing = i["missing"].str(); } // images hp_bar_scaling = v["hp_bar_scaling"].to_double(0.666); xp_bar_scaling = v["xp_bar_scaling"].to_double(0.5); hex_brightening = v["hex_brightening"].to_double(1.25); foot_speed_prefix = utils::split(v["footprint_prefix"]); foot_teleport_enter = v["footprint_teleport_enter"].str(); foot_teleport_exit = v["footprint_teleport_exit"].str(); shroud_prefix = v["shroud_prefix"].str(); fog_prefix = v["fog_prefix"].str(); add_color_info(v, true); if(const config::attribute_value* a = v.get("flag_rgb")) { flag_rgb = a->str(); } if(const config::attribute_value* a = v.get("unit_rgb")) { unit_rgb = a->str(); } const auto parse_config_color_list = [&]( const std::string& key, const color_t fallback)->std::vector<color_t> { std::vector<color_t> color_vec; for(const auto& s : utils::split(v[key].str())) { try { color_vec.push_back(color_t::from_hex_string(s)); } catch(const std::invalid_argument& e) { ERR_NG << "Error parsing color list '" << key << "'.\n" << e.what() << std::endl; color_vec.push_back(fallback); } } return color_vec; }; red_green_scale = parse_config_color_list("red_green_scale", {255, 255, 255}); red_green_scale_text = parse_config_color_list("red_green_scale_text", {255, 255, 255}); blue_white_scale = parse_config_color_list("blue_white_scale", {0 , 0 , 255}); blue_white_scale_text = parse_config_color_list("blue_white_scale_text", {0 , 0 , 255}); server_list.clear(); for(const config& server : v.child_range("server")) { server_info sinf; sinf.name = server["name"].str(); sinf.address = server["address"].str(); server_list.push_back(sinf); } if(const config& s = v.child("sounds")) { using namespace game_config::sounds; const auto load_attribute = [](const config& c, const std::string& key, std::string& member) { if(c.has_attribute(key)) { member = c[key].str(); } }; load_attribute(s, "turn_bell", turn_bell); load_attribute(s, "timer_bell", timer_bell); load_attribute(s, "public_message", public_message); load_attribute(s, "private_message", private_message); load_attribute(s, "friend_message", friend_message); load_attribute(s, "server_message", server_message); load_attribute(s, "player_joins", player_joins); load_attribute(s, "player_leaves", player_leaves); load_attribute(s, "game_user_arrive", game_user_arrive); load_attribute(s, "game_user_leave", game_user_leave); load_attribute(s, "ready_for_start", ready_for_start); load_attribute(s, "game_has_begun", game_has_begun); if(const config & ss = s.child("status")) { using namespace game_config::sounds::status; load_attribute(ss, "poisoned", poisoned); load_attribute(ss, "slowed", slowed); load_attribute(ss, "petrified", petrified); } } }
frame_builder::frame_builder(const config& cfg,const std::string& frame_string) : duration_(1), image_(cfg[frame_string + "image"]), image_diagonal_(cfg[frame_string + "image_diagonal"]), image_horizontal_(cfg[frame_string + "image_horizontal"]), image_mod_(cfg[frame_string + "image_mod"]), stext_(cfg[frame_string + "stext"]), halo_(cfg[frame_string + "halo"]), halo_x_(cfg[frame_string + "halo_x"]), halo_y_(cfg[frame_string + "halo_y"]), halo_mod_(cfg[frame_string + "halo_mod"]), sound_(cfg[frame_string + "sound"]), text_(cfg[frame_string + "text"]), text_color_(default_text_color), font_size_(cfg[frame_string + "font_size"].to_int(0)), blend_with_(0), blend_ratio_(cfg[frame_string + "blend_ratio"]), highlight_ratio_(cfg[frame_string + "alpha"]), offset_x_(cfg[frame_string + "offset_x"]), offset_y_(cfg[frame_string + "offset_y"]), submerge_(cfg[frame_string + "submerge"]), x_(cfg[frame_string + "x"]), y_(cfg[frame_string + "y"]), directional_x_(cfg[frame_string + "directional_x"]), directional_y_(cfg[frame_string + "directional_y"]), auto_vflip_(t_unset), auto_hflip_(t_unset), primary_frame_(t_unset), drawing_layer_(cfg[frame_string + "layer"]) { if(!cfg.has_attribute(frame_string + "auto_vflip")) { auto_vflip_ = t_unset; } else if(cfg[frame_string + "auto_vflip"].to_bool()) { auto_vflip_ = t_true; } else { auto_vflip_ = t_false; } if(!cfg.has_attribute(frame_string + "auto_hflip")) { auto_hflip_ = t_unset; } else if(cfg[frame_string + "auto_hflip"].to_bool()) { auto_hflip_ = t_true; } else { auto_hflip_ = t_false; } if(!cfg.has_attribute(frame_string + "primary")) { primary_frame_ = t_unset; } else if(cfg[frame_string + "primary"].to_bool()) { primary_frame_ = t_true; } else { primary_frame_ = t_false; } std::vector<std::string> color = utils::split(cfg[frame_string + "text_color"]); if (color.size() == 3) { text_color_ = display::rgb(atoi(color[0].c_str()), atoi(color[1].c_str()), atoi(color[2].c_str())); text_color_ &= 0xffffff; } if (const config::attribute_value *v = cfg.get(frame_string + "duration")) { duration(*v); } else { duration(cfg[frame_string + "end"].to_int() - cfg[frame_string + "begin"].to_int()); } color = utils::split(cfg[frame_string + "blend_color"]); if (color.size() == 3) { blend_with_ = display::rgb(atoi(color[0].c_str()), atoi(color[1].c_str()), atoi(color[2].c_str())); } }
void load_config(const config &v) { base_income = v["base_income"].to_int(2); village_income = v["village_income"].to_int(1); village_support = v["village_support"].to_int(1); poison_amount = v["poison_amount"].to_int(8); rest_heal_amount = v["rest_heal_amount"].to_int(2); recall_cost = v["recall_cost"].to_int(20); kill_experience = v["kill_experience"].to_int(8); lobby_refresh = v["lobby_refresh"].to_int(2000); default_terrain = v["default_terrain"].str(); tile_size = v["tile_size"].to_int(72); title_music = v["title_music"].str(); lobby_music = v["lobby_music"].str(); default_victory_music = v["default_victory_music"].str(); default_defeat_music = v["default_defeat_music"].str(); if(const config &i = v.child("colors")){ using namespace game_config::colors; moved_orb_color = i["moved_orb_color"].str(); unmoved_orb_color = i["unmoved_orb_color"].str(); partial_orb_color = i["partial_orb_color"].str(); enemy_orb_color = i["enemy_orb_color"].str(); ally_orb_color = i["ally_orb_color"].str(); } // colors show_ally_orb = v["show_ally_orb"].to_bool(true); show_enemy_orb = v["show_enemy_orb"].to_bool(false); show_moved_orb = v["show_moved_orb"].to_bool(true); show_partial_orb = v["show_partly_orb"].to_bool(true); show_unmoved_orb = v["show_unmoved_orb"].to_bool(true); if(const config &i = v.child("images")){ using namespace game_config::images; game_title = i["game_title"].str(); game_title_background = i["game_title_background"].str(); game_logo = i["game_logo"].str(); game_logo_background = i["game_logo_background"].str(); orb = i["orb"].str(); energy = i["energy"].str(); flag = i["flag"].str(); flag_icon = i["flag_icon"].str(); terrain_mask = i["terrain_mask"].str(); grid_top = i["grid_top"].str(); grid_bottom = i["grid_bottom"].str(); mouseover = i["mouseover"].str(); selected = i["selected"].str(); editor_brush = i["editor_brush"].str(); unreachable = i["unreachable"].str(); linger = i["linger"].str(); observer = i["observer"].str(); tod_bright = i["tod_bright"].str(); tod_dark = i["tod_dark"].str(); level = i["level"].str(); ellipsis = i["ellipsis"].str(); missing = i["missing"].str(); } // images hp_bar_scaling = v["hp_bar_scaling"].to_double(0.666); xp_bar_scaling = v["xp_bar_scaling"].to_double(0.5); hex_brightening = v["hex_brightening"].to_double(1.25); foot_speed_prefix = utils::split(v["footprint_prefix"]); foot_teleport_enter = v["footprint_teleport_enter"].str(); foot_teleport_exit = v["footprint_teleport_exit"].str(); shroud_prefix = v["shroud_prefix"].str(); fog_prefix = v["fog_prefix"].str(); add_color_info(v); if (const config::attribute_value *a = v.get("flag_rgb")) { flag_rgb = a->str(); } if (const config::attribute_value *a = v.get("unit_rgb")) { unit_rgb = a->str(); } std::string color_string = v["red_green_scale"].str(); if(!string2rgb(color_string, red_green_scale)) { ERR_NG << "can't parse color string red_green_scale, ignoring: " << color_string << std::endl; } if (red_green_scale.empty()) { red_green_scale.push_back(0x00FFFF00); } color_string = v["red_green_scale_text"].str(); if(!string2rgb(color_string, red_green_scale_text)) { ERR_NG << "can't parse color string red_green_scale_text, ignoring: " << color_string << std::endl; } if (red_green_scale_text.empty()) { red_green_scale_text.push_back(0x00FFFF00); } color_string = v["blue_white_scale"].str(); if(!string2rgb(color_string, blue_white_scale)) { ERR_NG << "can't parse color string blue_white_scale, ignoring: " << color_string << std::endl; } if (blue_white_scale.empty()) { blue_white_scale.push_back(0x00FFFFFF); } color_string = v["blue_white_scale_text"].str(); if(!string2rgb(color_string, blue_white_scale_text)) { ERR_NG << "can't parse color string blue_white_scale_text, ignoring: " << color_string << std::endl; } if (blue_white_scale_text.empty()) { blue_white_scale_text.push_back(0x00FFFFFF); } server_list.clear(); for (const config &server : v.child_range("server")) { server_info sinf; sinf.name = server["name"].str(); sinf.address = server["address"].str(); server_list.push_back(sinf); } if(const config & s = v.child("sounds")) { using namespace game_config::sounds; if (s.has_attribute("turn_bell")) turn_bell = s["turn_bell"].str(); if (s.has_attribute("timer_bell")) timer_bell = s["timer_bell"].str(); if (s.has_attribute("public_message")) public_message = s["public_message"].str(); if (s.has_attribute("private_message")) private_message = s["private_message"].str(); if (s.has_attribute("friend_message")) friend_message = s["friend_message"].str(); if (s.has_attribute("server_message")) server_message = s["server_message"].str(); if (s.has_attribute("player_joins")) player_joins = s["player_joins"].str(); if (s.has_attribute("player_leaves")) player_leaves = s["player_leaves"].str(); if (s.has_attribute("game_user_arrive")) game_user_arrive = s["game_user_arrive"].str(); if (s.has_attribute("game_user_leave")) game_user_leave = s["game_user_leave"].str(); if (s.has_attribute("ready_for_start")) ready_for_start = s["ready_for_start"].str(); if (s.has_attribute("game_has_begun")) game_has_begun = s["game_has_begun"].str(); if(const config & ss = s.child("status")) { using namespace game_config::sounds::status; if (ss.has_attribute("poisoned")) poisoned = ss["poisoned"].str(); if (ss.has_attribute("slowed")) slowed = ss["slowed"].str(); if (ss.has_attribute("petrified")) petrified = ss["petrified"].str(); } } }