/** * Show credits with list of contributors. * * Names of people are shown scrolling up like in movie-credits.\n * Uses map from wesnoth or campaign as background. */ void show_about(CVideo &video, const std::string &campaign) { boost::scoped_ptr<cursor::setter> cur(new cursor::setter(cursor::WAIT)); surface& screen = video.getSurface(); if (screen == nullptr) return; // If the title is multi-line, we need to split it accordingly or we // get slight scrolling glitches in the credits screen. std::vector<std::string> text = about::get_text(campaign, true); SDL_Rect screen_rect = sdl::create_rect(0, 0, screen->w, screen->h); const surface_restorer restorer(&video, screen_rect); cur.reset(); std::vector<std::string> image_list; if(campaign.size() && !images[campaign].empty()){ image_list = utils::parenthetical_split(images[campaign], ','); } else{ image_list = utils::parenthetical_split(images_default, ','); } surface map_image, map_image_scaled; if(!image_list.empty()) { map_image = image::get_image(image_list[0]); } else { image_list.push_back(""); } if(!map_image){ image_list[0]=game_config::images::game_title_background; map_image=image::get_image(image_list[0]); } gui::button close(video,_("Close")); close.set_location((screen->w/2)-(close.width()/2), screen->h - 30); const int def_size = font::SIZE_XLARGE; const SDL_Color def_color = font::NORMAL_COLOR; //substitute in the correct control characters for '+' and '-' std::string before_header(2, ' '); before_header[0] = font::LARGE_TEXT; for(unsigned i = 0; i < text.size(); ++i) { std::string &s = text[i]; if (s.empty()) continue; char &first = s[0]; if (first == '-') first = font::SMALL_TEXT; else if (first == '+') { first = font::LARGE_TEXT; text.insert(text.begin() + i, before_header); ++i; } } text.insert(text.begin(), 10, before_header); int startline = 0; //TODO: use values proportional to screen ? // distance from top of map image to top of scrolling text const int top_margin = 60; // distance from bottom of scrolling text to bottom of map image const int bottom_margin = 40; // distance from left of scrolling text to the frame border const int text_left_padding = screen->w/32; int offset = 0; bool is_new_line = true; int first_line_height = 0; SDL_Rect frame_area; // we use a dialog to contains the text. Strange idea but at least the style // will be consistent with the titlescreen gui::dialog_frame f(video, "", gui::dialog_frame::titlescreen_style, false); // the text area's dimensions SDL_Rect text_rect = { 0, 0, 0, 0 }; // we'll retain a copy to prevent SDL_blit to change its w and h SDL_Rect text_rect_blit; surface text_surf; CKey key; bool last_escape; int image_count = 0; int scroll_speed = 4; // scroll_speed*50 = speed of scroll in pixel per second // Initially redraw all bool redraw_mapimage = true; bool update_dimensions = true; int max_text_width = 0; do { last_escape = key[SDLK_ESCAPE] != 0; // check to see if background image has changed if(text.size() && (image_count < ((startline * static_cast<int>(image_list.size())) / static_cast<int>(text.size())))){ image_count++; surface temp=image::get_image(image_list[image_count]); map_image=temp?temp:map_image; redraw_mapimage = true; } if (update_dimensions) { // rescale the background map_image_scaled = scale_surface(map_image, screen->w, screen->h); screen_rect = sdl::create_rect(0, 0, screen->w, screen->h); redraw_mapimage = true; // update the frame frame_area = sdl::create_rect( screen->w * 3 / 32 , top_margin , screen->w * 13 / 16 , screen->h - top_margin - bottom_margin); text_rect = f.layout(frame_area).interior; // update the text area text_rect.x += text_left_padding; text_rect.w -= text_left_padding; text_rect_blit = text_rect; text_surf = create_compatible_surface(screen, text_rect.w, text_rect.h); SDL_SetAlpha(text_surf, SDL_RLEACCEL, SDL_ALPHA_OPAQUE); // relocate the close button close.set_location((screen->w/2)-(close.width()/2), screen->h - 30); update_dimensions = false; } if (redraw_mapimage) { // draw map to screen, thus erasing all text sdl_blit(map_image_scaled, nullptr, screen, nullptr); update_rect(screen_rect); // redraw the dialog f.draw_background(); f.draw_border(); // cache the dialog background (alpha blending + blurred map) sdl_blit(screen, &text_rect, text_surf, nullptr); redraw_mapimage = false; } else { // redraw the saved part of the dialog where text scrolled // thus erasing all text SDL_Rect modified = sdl::create_rect(0, 0, max_text_width, text_rect.h); sdl_blit(text_surf, &modified, screen, &text_rect_blit); update_rect(text_rect); } int y = text_rect.y - offset; int line = startline; max_text_width = 0; { // clip to keep text into the frame (thus the new code block) clip_rect_setter set_clip_rect(screen, &text_rect); const int line_spacing = 5; do { // draw the text (with ellipsis if needed) // update the max_text_width for future cleaning int w = font::draw_text(&video, text_rect, def_size, def_color, text[line], text_rect.x, y).w; max_text_width = std::max<int>(max_text_width, w); // since the real drawing on screen is clipped, // we do a dummy one to get the height of the not clipped line. // (each time because special format characters may change it) const int line_height = font::draw_text(nullptr, text_rect, def_size, def_color, text[line], 0,0).h; if(is_new_line) { is_new_line = false; first_line_height = line_height + line_spacing; } line++; if(size_t(line) > text.size()-1) line = 0; y += line_height + line_spacing; } while(y < text_rect.y + text_rect.h); } // performs the actual scrolling offset += scroll_speed; if (offset>=first_line_height) { offset -= first_line_height; is_new_line = true; startline++; if(size_t(startline) == text.size()){ startline = 0; image_count = -1; } } // handle events if (key[SDLK_UP] && scroll_speed < 20) { ++scroll_speed; } if (key[SDLK_DOWN] && scroll_speed > 0) { --scroll_speed; } if (screen->w != screen_rect.w || screen->h != screen_rect.h) { update_dimensions = true; } events::pump(); events::raise_process_event(); events::raise_draw_event(); // flip screen and wait, so the text does not scroll too fast video.flip(); CVideo::delay(20); } while(!close.pressed() && (last_escape || !key[SDLK_ESCAPE])); }
void create::process_event_impl(const process_event_data & data) { if (data.quit) { set_result(QUIT); return; } if (data.create) { if (engine_.current_level().can_launch_game()) { engine_.prepare_for_era_and_mods(); if (engine_.current_level_type() == ng::level::TYPE::CAMPAIGN || engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) { std::string difficulty = engine_.select_campaign_difficulty(); if (difficulty == "CANCEL") { return; } engine_.prepare_for_campaign(difficulty); } else if (engine_.current_level_type() == ng::level::TYPE::SCENARIO) { engine_.prepare_for_scenario(); } else { //This means define= doesn't work for random generated scenarios engine_.prepare_for_other(); } engine_.prepare_for_new_level(); set_result(CREATE); return; } else { gui2::show_transient_message(disp_.video(), "", _("The level is invalid.")); } } if (level_type_combo_.changed()) { init_level_type_changed(0); } if (data.load) { try { savegame::loadgame load(disp_, game_config_manager::get()->game_config(), engine_.get_state()); if (data.filename) { if (!load.load_game(*data.filename, false, false, false, "", true)) { return ; } } else { if (!load.load_multiplayer_game()) { return ; } } if (load.cancel_orders()) engine_.get_state().cancel_orders(); engine_.prepare_for_saved_game(); set_result(LOAD_GAME); return; } catch(config::error&) { } } if (mod_selection_ != mods_menu_.selection()) { mod_selection_ = mods_menu_.selection(); engine_.set_current_mod_index(mod_selection_); set_description(engine_.current_extra(ng::create_engine::MOD).description); } int changed_mod = mods_menu_.last_changed(); if (changed_mod != -1) { engine_.set_current_mod_index(changed_mod); engine_.toggle_current_mod(); synchronize_selections(); } bool era_changed = era_selection_ != eras_menu_.selection(); era_selection_ = eras_menu_.selection(); if (era_changed) { engine_.set_current_era_index(era_selection_); set_description(engine_.current_extra(ng::create_engine::ERA).description); synchronize_selections(); } if (filter_name_.text() != engine_.level_name_filter()) { engine_.apply_level_filter(filter_name_.text()); init_level_type_changed(0); } bool level_changed = level_selection_ != levels_menu_.selection(); level_selection_ = levels_menu_.selection(); if (level_changed && level_selection_ >= 0) { init_level_changed(level_selection_); synchronize_selections(); } if (engine_.generator_assigned() && generator_settings_.pressed()) { engine_.generator_user_config(disp_); level_changed = true; } if(engine_.generator_assigned() && (level_changed || regenerate_map_.pressed())) { const cursor::setter cursor_setter(cursor::WAIT); cursor::setter cur(cursor::WAIT); engine_.init_generated_level_data(); if (!engine_.current_level().data()["error_message"].empty()) gui2::show_message(disp().video(), "map generation error", engine_.current_level().data()["error_message"]); level_changed = true; } if(level_changed) { std::stringstream players; std::stringstream map_size; players << _("Players: "); engine_.current_level().set_metadata(); draw_level_image(); set_description(engine_.current_level().description()); switch (engine_.current_level_type().v) { case ng::level::TYPE::SCENARIO: case ng::level::TYPE::USER_MAP: case ng::level::TYPE::USER_SCENARIO: case ng::level::TYPE::RANDOM_MAP: { ng::scenario* current_scenario = dynamic_cast<ng::scenario*>(&engine_.current_level()); assert(current_scenario); players << current_scenario->num_players(); map_size << _("Size: ") << current_scenario->map_size(); break; } case ng::level::TYPE::CAMPAIGN: case ng::level::TYPE::SP_CAMPAIGN: { ng::campaign* current_campaign = dynamic_cast<ng::campaign*>(&engine_.current_level()); assert(current_campaign); players << current_campaign->min_players(); if (current_campaign->max_players() != current_campaign->min_players()) { players << " to " << current_campaign->max_players(); } break; } } // end switch map_size_label_.set_text(map_size.str()); num_players_label_.set_text(players.str()); launch_game_.enable(engine_.current_level().can_launch_game()); generator_settings_.enable(engine_.generator_assigned()); regenerate_map_.enable(engine_.generator_assigned()); } if (filter_num_players_slider_.value() != engine_.player_num_filter()) { const int val = filter_num_players_slider_.value(); engine_.apply_level_filter(val); std::stringstream ss; if (val == 1) { ss << _("Number of players: any"); } else { ss << _("Number of players: ") << val; } filter_num_players_label_.set_text(ss.str()); init_level_type_changed(0); } }
/*#define TOPARSE_DEBUG #include <QtDebug>*/ toSQLParse::statement toSQLParse::parseStatement(tokenizer &tokens, bool declare, bool lst) { statement ret(statement::Statement); // toSyntaxAnalyzer &syntax = tokens.analyzer(); QString first; QString realfirst; bool nokey = false; bool block = false; for (QString token = tokens.getToken(true, true); !token.isNull(); token = tokens.getToken(true, true)) { QString upp = token.toUpper(); if (first.isNull() && !token.startsWith(("/*")) && !token.startsWith("--") && !token.startsWith("//")) realfirst = first = upp; #ifdef TOPARSE_DEBUG printf("%s (%d)\n", (const char*)token.toUtf8(), tokens.line()); printf(" %s - %s\n", (const char*)first.toUtf8(), (const char*)realfirst.toUtf8()); #endif // SQLITEMAN if (upp == ("PROCEDURE") || upp == ("FUNCTION") || upp == ("PACKAGE")) { // qDebug() << "PROCEDURE"; block = true; } if (upp == ("SELF")) { // qDebug() << "SELF"; block = false; } if (upp == "BEGIN" && (first.isNull() || first == "BEGIN")) { // qDebug() << "plain BEGIN"; ret.subTokens().insert(ret.subTokens().end(), statement(statement::Keyword, token, tokens.line())); nokey = false; } else if (first != ("END") && ((first == ("IF") && upp == ("THEN")) || upp == ("LOOP") || upp == ("DO") || (/*syntax.declareBlock()*/true && upp == ("DECLARE")) || (block && upp == ("AS")) || (block && upp == ("IS")) || ((!declare || block) && upp == ("BEGIN")))) { // qDebug() << "first != (\"END\") "; block = false; statement blk(statement::Block); ret.subTokens().insert(ret.subTokens().end(), statement(statement::Keyword, token, tokens.line())); blk.subTokens().insert(blk.subTokens().end(), ret); statement cur(statement::Statement); bool dcl = (upp == ("DECLARE") || upp == ("IS") || upp == ("AS")); do { cur = parseStatement(tokens, dcl, false); if (cur.Type == statement::List) { QMessageBox::warning(QApplication::activeWindow(), "Sqliteman", "toSQLparse: Unbalanced parenthesis (Too many ')')"); } blk.subTokens().insert(blk.subTokens().end(), cur); if (cur.subTokens().begin() != cur.subTokens().end() && (*(cur.subTokens().begin())).String.toUpper() == ("BEGIN")) dcl = false; } while (cur.subTokens().begin() != cur.subTokens().end() && (*cur.subTokens().begin()).String.toUpper() != ("END")); return blk; } else if (((first == "IF" && upp == "THEN") || (first == "WHEN" && upp == "THEN") || (first == "ELSIF" && upp == "THEN") || upp == ("BEGIN") || upp == ("EXCEPTION") || first == ("ELSE")) && !lst) { // qDebug() << "else if first==IF"; ret.subTokens().insert(ret.subTokens().end(), statement(statement::Keyword, token, tokens.line())); return ret; } else if (first == ("ASSIGN") || first == ("SET") || first == ("PROMPT") || first == ("COLUMN") || first == ("SPOOL") || first == ("STORE") || first == ("REMARK") || first == ("REM")) { // qDebug() << "ASSIGN"; ret.subTokens().insert(ret.subTokens().end(), statement(statement::Keyword, token, tokens.line())); int line = tokens.line(); int offset = tokens.offset(); for (QString tmp = tokens.getToken(true, true);line == tokens.line();tmp = tokens.getToken(true, true)) ret.subTokens().insert(ret.subTokens().end(), statement(statement::Token, tmp, line)); tokens.setLine(line); tokens.setOffset(offset); tokens.remaining(true); return ret; } else if (upp == (",") || // if (upp == (",") || // (syntax.reservedWord(upp) && (isKeyword(upp) && upp != ("NOT") && upp != ("IS") && upp != ("LIKE") && upp != ("IN") && upp != ("ELSE") && upp != ("ELSIF") && upp != ("END") && upp != ("BETWEEN") && upp != ("ASC") && upp != ("DESC") && upp != ("NULL")) && !nokey) { } else if (upp == ("(")) { // qDebug() << "start ("; ret.subTokens().insert(ret.subTokens().end(), statement(statement::Token, token, tokens.line())); statement lst = parseStatement(tokens, false, true); statement t = toPop(lst.subTokens()); if (lst.Type != statement::List) { QMessageBox::warning(QApplication::activeWindow(), "Sqliteman", "toSQLparse: Unbalanced parenthesis (Too many '(')"); } nokey = false; if (first == ("CREATE") && !block) { statement end = parseStatement(tokens, false, true); statement blk(statement::Block); blk.subTokens().insert(blk.subTokens().end(), ret); blk.subTokens().insert(blk.subTokens().end(), lst); end.subTokens().insert(end.subTokens().begin(), t); blk.subTokens().insert(blk.subTokens().end(), end); return blk; } else { ret.subTokens().insert(ret.subTokens().end(), lst); ret.subTokens().insert(ret.subTokens().end(), t); } } else if (upp == (")")) { // qDebug() << "end )"; ret.Type = statement::List; ret.subTokens().insert(ret.subTokens().end(), statement(statement::Token, token, tokens.line())); return ret; } else if (upp == (";")) { // qDebug() << "bodkociarka"; ret.subTokens().insert(ret.subTokens().end(), statement(statement::Token, token, tokens.line())); return ret; } else if (upp.startsWith(("/*+")) || upp.startsWith(("--+"))) { // qDebug() << "hint --+"; QString com = token; if (com.startsWith(("--+"))) com = ("/*+ ") + com.mid(3) + (" */"); ret.subTokens().insert(ret.subTokens().end(), statement(statement::Token, com.simplified(), tokens.line())); } else if (upp.startsWith(("/*")) || upp.startsWith(("--")) || upp.startsWith("//")) { // qDebug() << "comment"; if ( ret.subTokens().empty() ) { if (ret.Comment.isNull()) ret.Comment = token; else ret.Comment += ("\n") + token; } else { QString &com = (*ret.subTokens().rbegin()).Comment; if (com.isEmpty()) com = token; else com += ("\n") + token; } } else { // qDebug() << "plain else" <<token<< tokens.line(); ret.subTokens().insert(ret.subTokens().end(), statement(statement::Token, token, tokens.line())); nokey = (token == (".")); } if (upp == ("AS") || upp == ("IS")) { // qDebug() << "setting first: " << upp; first = upp; } else if (first == ("IS") && upp == ("NULL")) { // qDebug() << "setting first (real): " << realfirst; first = realfirst; } } return ret; }
void create::process_event() { int mousex, mousey; SDL_GetMouseState(&mousex,&mousey); tooltips::process(mousex, mousey); if (cancel_game_.pressed()) { set_result(QUIT); return; } if (launch_game_.pressed() || levels_menu_.double_clicked()) { if (engine_.current_level().can_launch_game()) { if (engine_.current_level_type() == level::CAMPAIGN || engine_.current_level_type() == level::SP_CAMPAIGN) { std::string difficulty = select_campaign_difficulty(); if (difficulty == "CANCEL") { return; } engine_.prepare_for_campaign(difficulty); } engine_.prepare_for_new_level(); set_result(CREATE); return; } else { gui2::show_transient_message(disp_.video(), "", _("The level is invalid.")); } } if (level_type_combo_.changed()) { init_level_type_changed(0); } if (load_game_.pressed()) { engine_.prepare_for_saved_game(); set_result(LOAD_GAME); return; } bool update_mod_button_label = mod_selection_ != mods_menu_.selection(); if (select_mod_.pressed() || mods_menu_.double_clicked()) { int index = mods_menu_.selection(); engine_.set_current_mod_index(index); engine_.toggle_current_mod(); update_mod_button_label = true; synchronize_selections(); } if (update_mod_button_label) { mod_selection_ = mods_menu_.selection(); engine_.set_current_mod_index(mod_selection_); set_description(engine_.current_extra(create_engine::MOD).description); if (engine_.dependency_manager().is_modification_active(mod_selection_)) { select_mod_.set_label(_("Deactivate")); } else { select_mod_.set_label(_("Activate")); } } bool era_changed = era_selection_ != eras_menu_.selection(); era_selection_ = eras_menu_.selection(); if (era_changed) { engine_.set_current_era_index(era_selection_); set_description(engine_.current_extra(create_engine::ERA).description); synchronize_selections(); } if (filter_name_.text() != engine_.level_name_filter()) { engine_.apply_level_filter(filter_name_.text()); init_level_type_changed(0); } bool level_changed = level_selection_ != levels_menu_.selection(); level_selection_ = levels_menu_.selection(); if (level_changed && level_selection_ >= 0) { init_level_changed(level_selection_); synchronize_selections(); } if (engine_.generator_assigned() && generator_settings_.pressed()) { engine_.generator_user_config(disp_); level_changed = true; } if(engine_.generator_assigned() && (level_changed || regenerate_map_.pressed())) { const cursor::setter cursor_setter(cursor::WAIT); cursor::setter cur(cursor::WAIT); engine_.init_generated_level_data(); if (!engine_.current_level().data()["error_message"].empty()) gui2::show_message(disp().video(), "map generation error", engine_.current_level().data()["error_message"]); level_changed = true; } if(level_changed) { std::stringstream players; std::stringstream map_size; players << _("Players: "); engine_.current_level().set_metadata(); draw_level_image(); set_description(engine_.current_level().description()); switch (engine_.current_level_type()) { case level::SCENARIO: case level::USER_MAP: case level::USER_SCENARIO: case level::RANDOM_MAP: { scenario* current_scenario = dynamic_cast<scenario*>(&engine_.current_level()); players << current_scenario->num_players(); map_size << _("Size: ") << current_scenario->map_size(); break; } case level::CAMPAIGN: case level::SP_CAMPAIGN: { campaign* current_campaign = dynamic_cast<campaign*>(&engine_.current_level()); players << current_campaign->min_players(); if (current_campaign->max_players() != current_campaign->min_players()) { players << " to " << current_campaign->max_players(); } break; } } // end switch map_size_label_.set_text(map_size.str()); num_players_label_.set_text(players.str()); launch_game_.enable(engine_.current_level().can_launch_game()); generator_settings_.enable(engine_.generator_assigned()); regenerate_map_.enable(engine_.generator_assigned()); } if (filter_num_players_slider_.value() != engine_.player_num_filter()) { const int val = filter_num_players_slider_.value(); engine_.apply_level_filter(val); std::stringstream ss; if (val == 0) { ss << _("Number of players: any"); } else { ss << _("Number of players: ") << val; } filter_num_players_label_.set_text(ss.str()); init_level_type_changed(0); } }
virtual void enumDir(StrLen dir_name,Function<void (StrLen name,FileType type)> func) { FileSystem::DirCursor cur(fs,dir_name); cur.apply( [func] (StrLen name,FileType type) { func(name,type); } ); }
//------------------------------------------------ void ofxBox2dConvexPoly::setup(b2World * b2dworld, ofPolyline & _line){ ofPolyline line = convexHull(_line); line.getVertices().erase(line.getVertices().end()-1); b2Vec2 * vertices; int32 vertexCount = line.getVertices().size(); vertices = new b2Vec2[vertexCount]; ofPoint pos; ghettoRadius = 0; for (int i = 0; i < vertexCount; i++){ vertices[i].x = line.getVertices()[i].x; vertices[i].y = line.getVertices()[i].y; pos.x += line.getVertices()[i].x; pos.y += line.getVertices()[i].y; } pos /= (float)vertexCount; for (int i = 0; i < vertexCount; i++){ float dist = (pos - line.getVertices()[i]).length(); if (dist > ghettoRadius){ ghettoRadius = dist; } } for (int i = 0; i < vertexCount; i++){ vertices[i].x /= OFX_BOX2D_SCALE; vertices[i].y /= OFX_BOX2D_SCALE; } ofPoint posCent = ofPoint(200,200) - pos; pos /= OFX_BOX2D_SCALE; posCent /= OFX_BOX2D_SCALE; ghettoRadius /= OFX_BOX2D_SCALE; ofPath path; for (int i = 0; i < vertexCount; i++){ vertices[i].x -= pos.x; vertices[i].y -= pos.y; glm::vec3 cur(vertices[i].x, vertices[i].y, 0.0); polyPts.addVertex(cur); path.lineTo(cur); } gpuCachedTesselation = path.getTessellation(); float x = pos.x ; float y = pos.y ; if(b2dworld == NULL) { ofLog(OF_LOG_NOTICE, "ofxBox2dConvexPoly :: setup : - must have a valid world -"); return; } // these are used to create the shape shape.Set(vertices, vertexCount); delete vertices; fixture.shape = &shape; fixture.density = density; fixture.friction = friction; fixture.restitution = bounce; if(density == 0.f) bodyDef.type = b2_staticBody; else bodyDef.type = b2_dynamicBody; bodyDef.position.Set(x,y); body = b2dworld->CreateBody(&bodyDef); body->CreateFixture(&fixture); scale = 1; }
void deprecated_include_check::inspect( const string & library_name, const path & full_path, // example: c:/foo/boost/filesystem/path.hpp const string & contents) // contents of file to be inspected { std::string::size_type p = contents.find( "hpxinspect:" "nodeprecatedinclude" ); if (p != string::npos) { // ignore this directive here (it is handled below) if it is followed // by a ':' if (p == contents.size() - 30 || (contents.size() > p + 30 && contents[p + 30] != ':')) { return; } } std::set<std::string> found_includes; // check for all given includes for (deprecated_includes_regex_data const& d : regex_data) { boost::sregex_iterator cur(contents.begin(), contents.end(), d.pattern), end; for(/**/; cur != end; ++cur) { auto m = *cur; if (m[1].matched || m[2].matched) { int idx = (m[1].matched ? 1 : 2); // avoid errors to be reported twice std::string found_include(m[1].first, m[1].second); if (found_includes.find(found_include) == found_includes.end()) { std::string tag("hpxinspect:" "nodeprecatedinclude:" + found_include); if (contents.find(tag) != string::npos) continue; // name was found found_includes.insert(found_include); // include is missing auto it = contents.begin(); auto match_it = m[idx].first; auto line_start = it; string::size_type line_number = 1; for (/**/; it != match_it; ++it) { if (string::traits_type::eq(*it, '\n')) { ++line_number; line_start = it + 1; // could be end() } } ++m_errors; error(library_name, full_path, string(name()) + " deprecated #include (" + found_include + ") on line " + linelink(full_path, boost::lexical_cast<string>(line_number)) + " use " + m.format(d.data->use_instead) + " instead"); } } } } }
void Parser::eat(Location &loc) { loc << cur()->loc(); eat(); }
TEST_P(TestGetSubPatch1D, SubPatch) { Go::SplineCurve cur(GetParam().n, GetParam().p+1, GetParam().knots.begin(), GetParam().coefs.begin(), GetParam().dim, GetParam().rational); size_t numcoefs0 = cur.basis().numCoefs()/2 + GetParam().p; Go::SplineCurve cur0 = MultiPatchModelGenerator1D::getSubPatch(&cur, 0, numcoefs0, GetParam().p+1); size_t numcoefs1 = cur.basis().numCoefs() - numcoefs0 + GetParam().p; size_t start1 = numcoefs0 - GetParam().p; Go::SplineCurve cur1 = MultiPatchModelGenerator1D::getSubPatch(&cur, start1, numcoefs1, GetParam().p+1); // Check first sub-knot-vector std::vector<double> arr0(GetParam().knots.begin(), GetParam().knots.begin()+GetParam().lknots0); std::vector<double> arr1(cur0.basis().begin(), cur0.basis().end()); std::cout << "sub-knot-vector 0" << std::endl; check_vector_double_near(arr0, arr1); // Check second sub-knot-vector std::vector<double> arr2(GetParam().knots.end()-GetParam().lknots1, GetParam().knots.end()); std::vector<double> arr3(cur1.basis().begin(), cur1.basis().end()); std::cout << "sub-knot-vector 1" << std::endl; check_vector_double_near(arr2, arr3); // Check first sub-control net std::vector<double>::const_iterator i0 = GetParam().rational ? cur0.rcoefs_begin() : cur0.coefs_begin(); std::vector<double>::const_iterator i1 = GetParam().rational ? cur0.rcoefs_end() : cur0.coefs_end(); std::vector<double> arr4(i0, i1); std::cout << "sub-node-vector 0" << std::endl; check_vector_double_near(GetParam().coefs0, arr4); // Check second sub-control net std::vector<double>::const_iterator i2 = GetParam().rational ? cur1.rcoefs_begin() : cur1.coefs_begin(); std::vector<double>::const_iterator i3 = GetParam().rational ? cur1.rcoefs_end() : cur1.coefs_end(); std::vector<double> arr5(i2, i3); std::cout << "sub-node-vector 1" << std::endl; check_vector_double_near(GetParam().coefs1, arr5); // Evaluate function at points double xiA(0.3333), xiB(GetParam().p+1), xiC(4.2); std::string fstr = (GetParam().p == 2) ? "(1-x)*(3.14159-x)" : "x*(1-x)*(3.14159-x)"; RealFunc* f = utl::parseRealFunc(fstr, "expression"); Go::SplineCurve* fh = SplineUtils::project(&cur, *f); Go::SplineCurve fh0 = MultiPatchModelGenerator1D::getSubPatch(fh, 0, numcoefs0, GetParam().p+1); Go::SplineCurve fh1 = MultiPatchModelGenerator1D::getSubPatch(fh, start1, numcoefs1, GetParam().p+1); Go::Point fA, fB, fC, fA0, fB0, fB1, fC1; fh->point(fA, xiA); fh->point(fB, xiB); fh->point(fC, xiC); std::cout << "point evaluation" << std::endl; fh0.point(fA0, xiA); check_point_near(fA, fA0); fh0.point(fB0, xiB); check_point_near(fB, fB0); fh1.point(fB1, xiB); check_point_near(fB, fB1); fh1.point(fC1, xiC); check_point_near(fC, fC1); // Check FEM topology std::stringstream str0, str1; str0 << "100 1 0 0\n" << cur0; str1 << "100 1 0 0\n" << cur1; ASMs1D pch0, pch1; pch0.resetNumbering(); pch0.read(str0); pch1.read(str1); std::cout << "element/node numbers" << std::endl; ASSERT_TRUE(pch0.generateFEMTopology()); ASSERT_TRUE(pch1.generateFEMTopology()); std::vector<int> myMLGE = pch1.getMyElementNums(); check_vector_int_equals_range(myMLGE, GetParam().mlge1); std::vector<int> myMLGN = pch1.getMyNodeNums(); check_vector_int_equals_range(myMLGN, GetParam().mlgn1); }
void Parser::parse_enum() { if (cur()->type() != '{') { log_expect(cur()->loc(), "{"); } eat(); int64_t v = 0; while (1) { ptr<Token> token = cur(); if (token->type() == '}') { eat(); if (cur()->type() != ';') { log_expect(cur()->loc(), ";"); } eat(); return; } if (!token->is_iden()) { log_expect(token->loc(), "identifier"); } Location loc; ptr<Token> iden_token = token; loc << iden_token->loc(); eat(); token = cur(); object<ExprTree> expr; if (token->type() == '=') { eat(); expr->parse(this); if (expr->exprType() != EXPR_INT) { log_expect(expr->loc, "integer expr"); } v = expr->vint() + 1; loc << expr->loc; } else { expr->vint(v++); } object<DefineTree> def_tree(iden_token, expr); def_tree->loc = loc; if (def_tree != _symbols.probe(def_tree->name()->text(), def_tree, _input.is_root())) { log_error(def_tree->name()->loc(), "dup define name '%s'", def_tree->name()->text()); } if (cur()->type() == ',') { eat(); continue; } if (cur()->type() == '}') { continue; } log_expect(cur()->loc(), "',' or '}'"); } }
bool Parser::parse() { skip_newline(false); while (1) { ptr<Token> token = cur(); if (!token->type()) { break; } eat(); if (*token == '\n') { continue; } if (*token == TOKEN_INCLUDE) { bool old_skip_newline = skip_newline(); skip_newline(false); token = cur(); if (*token == TOKEN_CONST_STRING && look()->is_eol()) { eat(); eat(); skip_newline(old_skip_newline); ptr<Path> path = object<Path>(token->text()); if (_input.is_root()) { _symbols.exportSymbol(object<IncludeTree>(path)); } _input.load(path); } else { log_expect(token->loc(), "string eol"); } continue; } SegmentToken *seg = nullptr; if (token->type() == TOKEN_SEGMENT) { seg = static_cast<SegmentToken*>(token.get()); if (!seg->name()) { bool old_skip_newline = skip_newline(); skip_newline(false); if (!look()->is_eol()) { log_expect(token->loc(), "eol"); } skip_newline(old_skip_newline); eat(); } else { seg = nullptr; } } switch (_phase) { case PARSE_PHASE_HEAD: if (seg) { _phase = PARSE_PHASE_BODY; continue; } skip_newline(false); parse_head(token); break; case PARSE_PHASE_BODY: if (seg) { _phase = PARSE_PHASE_TAIL; continue; } skip_newline(true); parse_body(token); break; case PARSE_PHASE_TAIL: if (seg) { log_error(token->loc(), "too more segment declear."); } skip_newline(false); parse_tail(token); break; } } return true; }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); ofEnableDepthTest(); ofBackground(50, 50, 50, 0); //we need to call this for textures to work on models ofDisableArbTex(); ofLoadImage(heightMap, "heightmap.png"); normalFbo.allocate(ofGetWidth(), ofGetHeight()); ofEnableArbTex(); normalShader.load("","normal.frag"); terrainShader.load("terrain"); mesh.setMode(OF_PRIMITIVE_TRIANGLES); int rings = 32, resolution = 32; float length = 512, maxRadius = 256; for(int i = 0; i < rings; i++) { float radius = ofNoise(i / 5.) * maxRadius; ofVec3f offset(0, 0, ofMap(i, 0, rings, -length, length) / 2); for(int j = 0; j < resolution; j++) { float theta = ofMap(j, 0, resolution, 0, 360); //j/PI * 32; ofVec2f cur(radius, 0); cur.rotate(theta); mesh.addVertex(offset+cur); mesh.addColor(ofFloatColor((i * j) % 2 == 0 ? 255 : 0)); // mesh.addVertex(offset+cur); // mesh.addColor(ofFloatColor(1.0, 0.0, 0.0)); } } for(int i = 0; i < rings - 1; i++) { for(int j = 0; j < resolution; j++) { int sw = i * resolution + j, se = sw + 1; if(j + 1 == resolution) { se -= resolution; } int nw = sw + resolution, ne = se + resolution; mesh.addTriangle(sw, se, nw); mesh.addTriangle(nw, se, ne); mesh.addTriangle(nw, sw, se); } } light.enable(); }
// Fills the stack, but only checks a maximum number of maxToCheck points at a time. // Further calls to this function will continue the expand/check neighbors algorithm. void GeoBrowse::fillStack(int maxToCheck, int maxToAdd, bool onlyExpand) { if(maxToAdd < 0) maxToAdd = maxToCheck; int maxFound = _foundInExp + maxToCheck; verify(maxToCheck > 0); verify(maxFound > 0); verify(_found <= 0x7fffffff); // conversion to int int maxAdded = static_cast<int>(_found) + maxToAdd; verify(maxAdded >= 0); // overflow check bool isNeighbor = _centerPrefix.constrains(); // Starting a box expansion if (_state == START) { // Get the very first hash point, if required if(! isNeighbor) _prefix = expandStartHash(); if (!BtreeLocation::initial(_descriptor, _params, _min, _max, _prefix)) { _state = isNeighbor ? DONE_NEIGHBOR : DONE; } else { _state = DOING_EXPAND; _lastPrefix.reset(); } } // Doing the actual box expansion if (_state == DOING_EXPAND) { while (true) { // Record the prefix we're actively exploring... _expPrefix.reset(new GeoHash(_prefix)); // Find points inside this prefix while (checkAndAdvance(&_min, _prefix, _foundInExp) && _foundInExp < maxFound && _found < maxAdded) {} while (checkAndAdvance(&_max, _prefix, _foundInExp) && _foundInExp < maxFound && _found < maxAdded) {} if(_foundInExp >= maxFound || _found >= maxAdded) return; // We've searched this prefix fully, remember _lastPrefix.reset(new GeoHash(_prefix)); // If we've searched the entire space, we're finished. if (! _prefix.constrains()) { _state = DONE; notePrefix(); return; } // If we won't fit in the box, and we're not doing a sub-scan, increase the size if (! fitsInBox(_converter->sizeEdge(_prefix)) && _fringe.size() == 0) { // If we're still not expanded bigger than the box size, expand again _prefix = _prefix.up(); continue; } // We're done and our size is large enough _state = DONE_NEIGHBOR; // Go to the next sub-box, if applicable if(_fringe.size() > 0) _fringe.pop_back(); // Go to the next neighbor if this was the last sub-search if(_fringe.size() == 0) _neighbor++; break; } notePrefix(); } // If we doeighbors if(onlyExpand) return; // If we're done expanding the current box... if(_state == DONE_NEIGHBOR) { // Iterate to the next neighbor // Loop is useful for cases where we want to skip over boxes entirely, // otherwise recursion increments the neighbors. for (; _neighbor < 9; _neighbor++) { // If we have no fringe for the neighbor, make sure we have the default fringe if(_fringe.size() == 0) _fringe.push_back(""); if(! isNeighbor) { _centerPrefix = _prefix; _centerBox = _converter->unhashToBox(_centerPrefix); isNeighbor = true; } int i = (_neighbor / 3) - 1; int j = (_neighbor % 3) - 1; if ((i == 0 && j == 0) || (i < 0 && _centerPrefix.atMinX()) || (i > 0 && _centerPrefix.atMaxX()) || (j < 0 && _centerPrefix.atMinY()) || (j > 0 && _centerPrefix.atMaxY())) { continue; // main box or wrapped edge // TODO: We may want to enable wrapping in future, probably best as layer // on top of this search. } // Make sure we've got a reasonable center verify(_centerPrefix.constrains()); GeoHash _neighborPrefix = _centerPrefix; _neighborPrefix.move(i, j); while(_fringe.size() > 0) { _prefix = _neighborPrefix + _fringe.back(); Box cur(_converter->unhashToBox(_prefix)); double intAmt = intersectsBox(cur); // No intersection if(intAmt <= 0) { _fringe.pop_back(); continue; } else if(intAmt < 0.5 && _prefix.canRefine() && _fringe.back().size() < 4 /* two bits */) { // Small intersection, refine search string lastSuffix = _fringe.back(); _fringe.pop_back(); _fringe.push_back(lastSuffix + "00"); _fringe.push_back(lastSuffix + "01"); _fringe.push_back(lastSuffix + "11"); _fringe.push_back(lastSuffix + "10"); continue; } // Restart our search from a diff box. _state = START; verify(! onlyExpand); verify(_found <= 0x7fffffff); fillStack(maxFound - _foundInExp, maxAdded - static_cast<int>(_found)); // When we return from the recursive fillStack call, we'll either have // checked enough points or be entirely done. Max recurse depth is < 8 * // 16. // If we're maxed out on points, return if(_foundInExp >= maxFound || _found >= maxAdded) { // Make sure we'll come back to add more points verify(_state == DOING_EXPAND); return; } // Otherwise we must be finished to return verify(_state == DONE); return; } } // Finished with neighbors _state = DONE; } }
/** * Called by YAPF to calculate the cost from the origin to the given node. * Calculates only the cost of given node, adds it to the parent node cost * and stores the result into Node::m_cost member */ inline bool PfCalcCost(Node &n, const TrackFollower *tf) { assert(!n.flags_u.flags_s.m_targed_seen); assert(tf->m_new_tile == n.m_key.m_tile); assert((TrackdirToTrackdirBits(n.m_key.m_td) & tf->m_new_td_bits) != TRACKDIR_BIT_NONE); CPerfStart perf_cost(Yapf().m_perf_cost); /* Does the node have some parent node? */ bool has_parent = (n.m_parent != NULL); /* Do we already have a cached segment? */ CachedData &segment = *n.m_segment; bool is_cached_segment = (segment.m_cost >= 0); int parent_cost = has_parent ? n.m_parent->m_cost : 0; /* Each node cost contains 2 or 3 main components: * 1. Transition cost - cost of the move from previous node (tile): * - curve cost (or zero for straight move) * 2. Tile cost: * - base tile cost * - YAPF_TILE_LENGTH for diagonal tiles * - YAPF_TILE_CORNER_LENGTH for non-diagonal tiles * - tile penalties * - tile slope penalty (upward slopes) * - red signal penalty * - level crossing penalty * - speed-limit penalty (bridges) * - station platform penalty * - penalty for reversing in the depot * - etc. * 3. Extra cost (applies to the last node only) * - last red signal penalty * - penalty for too long or too short platform on the destination station */ int transition_cost = 0; int extra_cost = 0; /* Segment: one or more tiles connected by contiguous tracks of the same type. * Each segment cost includes 'Tile cost' for all its tiles (including the first * and last), and the 'Transition cost' between its tiles. The first transition * cost of segment entry (move from the 'parent' node) is not included! */ int segment_entry_cost = 0; int segment_cost = 0; const Train *v = Yapf().GetVehicle(); /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */ TILE cur(n.m_key.m_tile, n.m_key.m_td); /* the previous tile will be needed for transition cost calculations */ TILE prev = !has_parent ? TILE() : TILE(n.m_parent->GetLastTile(), n.m_parent->GetLastTrackdir()); EndSegmentReasonBits end_segment_reason = ESRB_NONE; TrackFollower tf_local(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost); if (!has_parent) { /* We will jump to the middle of the cost calculator assuming that segment cache is not used. */ assert(!is_cached_segment); /* Skip the first transition cost calculation. */ goto no_entry_cost; } for (;;) { /* Transition cost (cost of the move from previous tile) */ transition_cost = Yapf().CurveCost(prev.td, cur.td); transition_cost += Yapf().SwitchCost(prev.tile, cur.tile, TrackdirToExitdir(prev.td)); /* First transition cost counts against segment entry cost, other transitions * inside segment will come to segment cost (and will be cached) */ if (segment_cost == 0) { /* We just entered the loop. First transition cost goes to segment entry cost)*/ segment_entry_cost = transition_cost; transition_cost = 0; /* It is the right time now to look if we can reuse the cached segment cost. */ if (is_cached_segment) { /* Yes, we already know the segment cost. */ segment_cost = segment.m_cost; /* We know also the reason why the segment ends. */ end_segment_reason = segment.m_end_segment_reason; /* We will need also some information about the last signal (if it was red). */ if (segment.m_last_signal_tile != INVALID_TILE) { assert(HasSignalOnTrackdir(segment.m_last_signal_tile, segment.m_last_signal_td)); SignalState sig_state = GetSignalStateByTrackdir(segment.m_last_signal_tile, segment.m_last_signal_td); bool is_red = (sig_state == SIGNAL_STATE_RED); n.flags_u.flags_s.m_last_signal_was_red = is_red; if (is_red) { n.m_last_red_signal_type = GetSignalType(segment.m_last_signal_tile, TrackdirToTrack(segment.m_last_signal_td)); } } /* No further calculation needed. */ cur = TILE(n.GetLastTile(), n.GetLastTrackdir()); break; } } else { /* Other than first transition cost count as the regular segment cost. */ segment_cost += transition_cost; } no_entry_cost: // jump here at the beginning if the node has no parent (it is the first node) /* All other tile costs will be calculated here. */ segment_cost += Yapf().OneTileCost(cur.tile, cur.td); /* If we skipped some tunnel/bridge/station tiles, add their base cost */ segment_cost += YAPF_TILE_LENGTH * tf->m_tiles_skipped; /* Slope cost. */ segment_cost += Yapf().SlopeCost(cur.tile, cur.td); /* Signal cost (routine can modify segment data). */ segment_cost += Yapf().SignalCost(n, cur.tile, cur.td); /* Reserved tiles. */ segment_cost += Yapf().ReservationCost(n, cur.tile, cur.td, tf->m_tiles_skipped); end_segment_reason = segment.m_end_segment_reason; /* Tests for 'potential target' reasons to close the segment. */ if (cur.tile == prev.tile) { /* Penalty for reversing in a depot. */ assert(IsRailDepot(cur.tile)); segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty; /* We will end in this pass (depot is possible target) */ end_segment_reason |= ESRB_DEPOT; } else if (cur.tile_type == MP_STATION && IsRailWaypoint(cur.tile)) { if (v->current_order.IsType(OT_GOTO_WAYPOINT) && GetStationIndex(cur.tile) == v->current_order.GetDestination() && !Waypoint::Get(v->current_order.GetDestination())->IsSingleTile()) { /* This waypoint is our destination; maybe this isn't an unreserved * one, so check that and if so see that as the last signal being * red. This way waypoints near stations should work better. */ CFollowTrackRail ft(v); TileIndex t = cur.tile; Trackdir td = cur.td; while (ft.Follow(t, td)) { assert(t != ft.m_new_tile); t = ft.m_new_tile; if (KillFirstBit(ft.m_new_td_bits) != TRACKDIR_BIT_NONE) { /* We encountered a junction; it's going to be too complex to * handle this perfectly, so just bail out. There is no simple * free path, so try the other possibilities. */ td = INVALID_TRACKDIR; break; } td = RemoveFirstTrackdir(&ft.m_new_td_bits); /* If this is a safe waiting position we're done searching for it */ if (IsSafeWaitingPosition(v, t, td, true, _settings_game.pf.forbid_90_deg)) break; } /* In the case this platform is (possibly) occupied we add penalty so the * other platforms of this waypoint are evaluated as well, i.e. we assume * that there is a red signal in the waypoint when it's occupied. */ if (td == INVALID_TRACKDIR || !IsSafeWaitingPosition(v, t, td, true, _settings_game.pf.forbid_90_deg) || !IsWaitingPositionFree(v, t, td, _settings_game.pf.forbid_90_deg)) { extra_cost += Yapf().PfGetSettings().rail_lastred_penalty; } } /* Waypoint is also a good reason to finish. */ end_segment_reason |= ESRB_WAYPOINT; } else if (tf->m_is_station) { /* Station penalties. */ uint platform_length = tf->m_tiles_skipped + 1; /* We don't know yet if the station is our target or not. Act like * if it is pass-through station (not our destination). */ segment_cost += Yapf().PfGetSettings().rail_station_penalty * platform_length; /* We will end in this pass (station is possible target) */ end_segment_reason |= ESRB_STATION; } else if (TrackFollower::DoTrackMasking() && cur.tile_type == MP_RAILWAY) { /* Searching for a safe tile? */ if (HasSignalOnTrackdir(cur.tile, cur.td) && !IsPbsSignal(GetSignalType(cur.tile, TrackdirToTrack(cur.td)))) { end_segment_reason |= ESRB_SAFE_TILE; } } /* Apply min/max speed penalties only when inside the look-ahead radius. Otherwise * it would cause desync in MP. */ if (n.m_num_signals_passed < m_sig_look_ahead_costs.Size()) { int min_speed = 0; int max_speed = tf->GetSpeedLimit(&min_speed); int max_veh_speed = v->GetDisplayMaxSpeed(); if (max_speed < max_veh_speed) { extra_cost += YAPF_TILE_LENGTH * (max_veh_speed - max_speed) * (4 + tf->m_tiles_skipped) / max_veh_speed; } if (min_speed > max_veh_speed) { extra_cost += YAPF_TILE_LENGTH * (min_speed - max_veh_speed); } } /* Finish if we already exceeded the maximum path cost (i.e. when * searching for the nearest depot). */ if (m_max_cost > 0 && (parent_cost + segment_entry_cost + segment_cost) > m_max_cost) { end_segment_reason |= ESRB_PATH_TOO_LONG; } /* Move to the next tile/trackdir. */ tf = &tf_local; tf_local.Init(v, Yapf().GetCompatibleRailTypes(), &Yapf().m_perf_ts_cost); if (!tf_local.Follow(cur.tile, cur.td)) { assert(tf_local.m_err != TrackFollower::EC_NONE); /* Can't move to the next tile (EOL?). */ if (tf_local.m_err == TrackFollower::EC_RAIL_TYPE) { end_segment_reason |= ESRB_RAIL_TYPE; } else { end_segment_reason |= ESRB_DEAD_END; } if (TrackFollower::DoTrackMasking() && !HasOnewaySignalBlockingTrackdir(cur.tile, cur.td)) { end_segment_reason |= ESRB_SAFE_TILE; } break; } /* Check if the next tile is not a choice. */ if (KillFirstBit(tf_local.m_new_td_bits) != TRACKDIR_BIT_NONE) { /* More than one segment will follow. Close this one. */ end_segment_reason |= ESRB_CHOICE_FOLLOWS; break; } /* Gather the next tile/trackdir/tile_type/rail_type. */ TILE next(tf_local.m_new_tile, (Trackdir)FindFirstBit2x64(tf_local.m_new_td_bits)); if (TrackFollower::DoTrackMasking() && IsTileType(next.tile, MP_RAILWAY)) { if (HasSignalOnTrackdir(next.tile, next.td) && IsPbsSignal(GetSignalType(next.tile, TrackdirToTrack(next.td)))) { /* Possible safe tile. */ end_segment_reason |= ESRB_SAFE_TILE; } else if (HasSignalOnTrackdir(next.tile, ReverseTrackdir(next.td)) && GetSignalType(next.tile, TrackdirToTrack(next.td)) == SIGTYPE_PBS_ONEWAY) { /* Possible safe tile, but not so good as it's the back of a signal... */ end_segment_reason |= ESRB_SAFE_TILE | ESRB_DEAD_END; extra_cost += Yapf().PfGetSettings().rail_lastred_exit_penalty; } } /* Check the next tile for the rail type. */ if (next.rail_type != cur.rail_type) { /* Segment must consist from the same rail_type tiles. */ end_segment_reason |= ESRB_RAIL_TYPE; break; } /* Avoid infinite looping. */ if (next.tile == n.m_key.m_tile && next.td == n.m_key.m_td) { end_segment_reason |= ESRB_INFINITE_LOOP; break; } if (segment_cost > s_max_segment_cost) { /* Potentially in the infinite loop (or only very long segment?). We should * not force it to finish prematurely unless we are on a regular tile. */ if (IsTileType(tf->m_new_tile, MP_RAILWAY)) { end_segment_reason |= ESRB_SEGMENT_TOO_LONG; break; } } /* Any other reason bit set? */ if (end_segment_reason != ESRB_NONE) { break; } /* For the next loop set new prev and cur tile info. */ prev = cur; cur = next; } // for (;;) bool target_seen = false; if ((end_segment_reason & ESRB_POSSIBLE_TARGET) != ESRB_NONE) { /* Depot, station or waypoint. */ if (Yapf().PfDetectDestination(cur.tile, cur.td)) { /* Destination found. */ target_seen = true; } } /* Update the segment if needed. */ if (!is_cached_segment) { /* Write back the segment information so it can be reused the next time. */ segment.m_cost = segment_cost; segment.m_end_segment_reason = end_segment_reason & ESRB_CACHED_MASK; /* Save end of segment back to the node. */ n.SetLastTileTrackdir(cur.tile, cur.td); } /* Do we have an excuse why not to continue pathfinding in this direction? */ if (!target_seen && (end_segment_reason & ESRB_ABORT_PF_MASK) != ESRB_NONE) { /* Reason to not continue. Stop this PF branch. */ return false; } /* Special costs for the case we have reached our target. */ if (target_seen) { n.flags_u.flags_s.m_targed_seen = true; /* Last-red and last-red-exit penalties. */ if (n.flags_u.flags_s.m_last_signal_was_red) { if (n.m_last_red_signal_type == SIGTYPE_EXIT) { /* last signal was red pre-signal-exit */ extra_cost += Yapf().PfGetSettings().rail_lastred_exit_penalty; } else if (!IsPbsSignal(n.m_last_red_signal_type)) { /* Last signal was red, but not exit or path signal. */ extra_cost += Yapf().PfGetSettings().rail_lastred_penalty; } } /* Station platform-length penalty. */ if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) { const BaseStation *st = BaseStation::GetByTile(n.GetLastTile()); assert(st != NULL); uint platform_length = st->GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir()))); /* Reduce the extra cost caused by passing-station penalty (each station receives it in the segment cost). */ extra_cost -= Yapf().PfGetSettings().rail_station_penalty * platform_length; /* Add penalty for the inappropriate platform length. */ extra_cost += PlatformLengthPenalty(platform_length); } } /* total node cost */ n.m_cost = parent_cost + segment_entry_cost + segment_cost + extra_cost; return true; }
//@zh void CGprsSynthesize::AttachRequest(SPcapSignal& signal) { ++ CStatistics::count_attach_request; //@zh CUserInfo* pUserInfo = NULL; CKey cur(signal.currai, signal.curtlli); TLLI_TYPE tllitp = getTLLIType(signal.curtlli); if(tllitp == TLLI_FOREIGN) { unsigned int localtlli = signal.curtlli | 0x40000000; CKey old(signal.oldrai, localtlli); pUserInfo = m_InfoDB.ChangeKey(old, cur); } else if(tllitp == TLLI_LOCAL) { //FOR DEBUG printf("WARN: GPRS Attach Request using local TLLI!\n"); } else if(tllitp == TLLI_RANDOM) {} if(!pUserInfo) pUserInfo = m_InfoDB.FindUserInfo(cur); if(!pUserInfo) pUserInfo = m_InfoDB.CreateUserInfo(cur); //pUserInfo->TDR.SetBeginTime(); pUserInfo->TDR.SetBeginTime(getTime(signal.pdu)); pUserInfo->TDR.SetImsi(getImsi(signal.pdu)); pUserInfo->TDR.SetType(GPRS_ATTACH_EVENT); pUserInfo->TDR.SetDlci(getDlci(signal.pdu)); pUserInfo->TDR.SetBvci(getBvci(signal.pdu)); pUserInfo->TDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->TDR.SetCgi(getCgi(signal.pdu)); unsigned char gmmtp = getGMMType(signal.pdu); if(gmmtp == 2 || gmmtp == 3) gmmtp = 1; else gmmtp = 0; pUserInfo->TDR.SetGMMType(gmmtp); pUserInfo->CDR.SetImsi(getImsi(signal.pdu)); pUserInfo->CDR.SetDlci(getDlci(signal.pdu)); pUserInfo->CDR.SetBvci(getBvci(signal.pdu)); pUserInfo->CDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->CDR.SetOriCgi(getCgi(signal.pdu)); return; //@zh /* //@zh comment //MS----->network CKey cur(signal.currai, signal.curtlli); CKey old(signal.oldrai, signal.curtlli); CUserInfo* pUserInfo = m_InfoDB.ChangeKey(old, cur); if(!pUserInfo) pUserInfo = m_InfoDB.FindUserInfo(cur); if(!pUserInfo) pUserInfo = m_InfoDB.CreateUserInfo(cur); //pUserInfo->TDR.SetBeginTime(); pUserInfo->TDR.SetBeginTime(getTime(signal.pdu)); pUserInfo->TDR.SetImsi(getImsi(signal.pdu)); pUserInfo->TDR.SetType(GPRS_ATTACH_EVENT); pUserInfo->TDR.SetDlci(getDlci(signal.pdu)); pUserInfo->TDR.SetBvci(getBvci(signal.pdu)); pUserInfo->TDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->TDR.SetCgi(getCgi(signal.pdu)); pUserInfo->CDR.SetImsi(getImsi(signal.pdu)); pUserInfo->CDR.SetDlci(getDlci(signal.pdu)); pUserInfo->CDR.SetBvci(getBvci(signal.pdu)); pUserInfo->CDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->CDR.SetOriCgi(getCgi(signal.pdu)); return; *///@zh comment }
bool LightgrepController::addUserPatterns(PatternScanner& scanner, CallbackFnType* callbackPtr, const FindOptsStruct& user) { unsigned int patBegin = lg_pattern_map_size(PatternInfo), patEnd = 0; LG_KeyOptions opts; opts.FixedString = 0; opts.CaseInsensitive = 0; LG_Error *err = 0; for (vector<string>::const_iterator itr(user.Files.begin()); itr != user.Files.end(); ++itr) { ifstream file(itr->c_str(), ios::in); if (!file.is_open()) { cerr << "Could not open pattern file '" << *itr << "'." << endl; return false; } string contents = string(istreambuf_iterator<char>(file), istreambuf_iterator<char>()); const char* contentsCStr = contents.c_str(); if (lg_add_pattern_list(Fsm, PatternInfo, contentsCStr, DefaultEncodingsCStrings, 2, &opts, &err) < 0) { vector<string> lines; istringstream input(contents); string line; while (input) { getline(input, line); lines.push_back(line); } LG_Error* cur(err); while (cur) { cerr << "Error in " << *itr << ", line " << cur->Index+1 << ", pattern '" << lines[cur->Index] << "': " << cur->Message << endl; cur = cur->Next; } lg_free_error(err); return false; } } for (vector<string>::const_iterator itr(user.Patterns.begin()); itr != user.Patterns.end(); ++itr) { bool good = false; if (lg_parse_pattern(ParsedPattern, itr->c_str(), &opts, &err)) { for (unsigned int i = 0; i < NumDefaultEncodings; ++i) { if (lg_add_pattern(Fsm, PatternInfo, ParsedPattern, DefaultEncodingsCStrings[i], &err) >= 0) { good = true; } } } if (!good) { cerr << "Error on '" << *itr << "': " << err->Message << endl; lg_free_error(err); return false; } } patEnd = lg_pattern_map_size(PatternInfo); for (unsigned int i = patBegin; i < patEnd; ++i) { lg_pattern_info(PatternInfo, i)->UserData = const_cast<void*>(static_cast<const void*>(callbackPtr)); } scanner.patternRange() = make_pair(patBegin, patEnd); Scanners.push_back(&scanner); return true; }
//路由区更新请求, 更新相应用户数据 void CGprsSynthesize::RoutingAreaUpdateRuequest(SPcapSignal& signal) { //MS----->network CUserInfo* pUserInfo = NULL; CKey cur(signal.currai, signal.curtlli); TLLI_TYPE tllitp = getTLLIType(signal.curtlli); if(tllitp == TLLI_FOREIGN) { unsigned int localtlli = signal.curtlli | 0x40000000; CKey old(signal.oldrai, localtlli); pUserInfo = m_InfoDB.ChangeKey(old, cur); } else if(tllitp == TLLI_LOCAL) { } else if(tllitp == TLLI_RANDOM) { //for test printf("WARN: RoutingAreaUpdate Request using RANDOM TLLI!\n"); } if(!pUserInfo) pUserInfo = m_InfoDB.FindUserInfo(cur); if(!pUserInfo) { //@zh add new user printf("GPRS ra update request, can not find userinfo: rai[%lld] tlli[%d], add new userinfo!\n", signal.currai.value, signal.curtlli); pUserInfo = m_InfoDB.CreateUserInfo(cur); //return; } if(pUserInfo) { //pUserInfo->TDR.SetBeginTime(); pUserInfo->TDR.SetBeginTime(getTime(signal.pdu)); pUserInfo->TDR.SetImsi(getImsi(signal.pdu)); pUserInfo->TDR.SetType(GPRS_RA_UPDATE_EVENT); pUserInfo->TDR.SetDlci(getDlci(signal.pdu)); pUserInfo->TDR.SetBvci(getBvci(signal.pdu)); pUserInfo->TDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->TDR.SetCgi(getCgi(signal.pdu)); unsigned char gmmtp = getGMMType(signal.pdu); if(gmmtp > 3) gmmtp = 3; pUserInfo->TDR.SetGMMType(gmmtp); pUserInfo->CDR.SetImsi(getImsi(signal.pdu)); pUserInfo->CDR.SetDlci(getDlci(signal.pdu)); pUserInfo->CDR.SetBvci(getBvci(signal.pdu)); pUserInfo->CDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->CDR.SetOriCgi(getCgi(signal.pdu)); return; } /*//@zh comment CKey cur(signal.currai, signal.curtlli); CKey old(signal.oldrai, signal.curtlli); CUserInfo* pUserInfo = m_InfoDB.ChangeKey(old, cur); if(!pUserInfo) pUserInfo = m_InfoDB.FindUserInfo(cur); if(!pUserInfo) return; //pUserInfo->TDR.SetBeginTime(); pUserInfo->TDR.SetBeginTime(getTime(signal.pdu)); pUserInfo->TDR.SetImsi(getImsi(signal.pdu)); pUserInfo->TDR.SetType(GPRS_RA_UPDATE_EVENT); pUserInfo->TDR.SetDlci(getDlci(signal.pdu)); pUserInfo->TDR.SetBvci(getBvci(signal.pdu)); pUserInfo->TDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->TDR.SetCgi(getCgi(signal.pdu)); pUserInfo->CDR.SetImsi(getImsi(signal.pdu)); pUserInfo->CDR.SetDlci(getDlci(signal.pdu)); pUserInfo->CDR.SetBvci(getBvci(signal.pdu)); pUserInfo->CDR.SetTlli(getCurTlli(signal.pdu)); pUserInfo->CDR.SetOriCgi(getCgi(signal.pdu)); return; *///@zh comment }
void BinghamRendererThread::run() { const Matrix* vertices = tess::vertices( m_lod ); int numVerts = tess::n_vertices( m_lod ); Matrix base = ( FMath::sh_base( (*vertices), m_order ) ); int numThreads = GLFunctions::idealThreadCount; double radius( 0.0 ); QMatrix4x4 mvp = m_pMatrix * m_mvMatrix; if ( ( m_orient & 1 ) == 1 ) { int glyphs = m_nx * m_ny; m_verts->reserve( numVerts * glyphs * 7 ); QVector4D pos( 0, 0, m_z, 1.0 ); for( int yy = m_id; yy < m_ny; yy += numThreads ) { for ( int xx = 0; xx < m_nx; ++xx ) { int dataPos = xx + yy * m_nx + m_zi * m_nx * m_ny; if ( ( fabs( m_data->at( dataPos )[8] ) > 0.0001 ) ) { float locX = xx * m_dx + m_ax; float locY = yy * m_dy + m_ay; pos.setX( locX ); pos.setY( locY ); QVector4D test = mvp * pos; if ( fabs( test.x() / 2.0 ) < 1.0 && fabs( test.y() / 2.0 ) < 1.0 ) { for ( int k = 0; k < 3; ++k ) { if ( k == 0 && m_render1 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( locX ); m_verts->push_back( locY ); m_verts->push_back( m_z ); m_verts->push_back( radius ); } } if ( k == 1 && m_render2 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( locX ); m_verts->push_back( locY ); m_verts->push_back( m_z ); m_verts->push_back( radius ); } } if ( k == 2 && m_render3 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( locX ); m_verts->push_back( locY ); m_verts->push_back( m_z ); m_verts->push_back( radius ); } } } } } } } } if ( ( m_orient & 2 ) == 2 ) { int glyphs = m_nx * m_nz; m_verts->reserve( numVerts * glyphs * 7 ); QVector4D pos( 0, m_y, 0, 1.0 ); for( int zz = m_id; zz < m_nz; zz += numThreads ) { for ( int xx = 0; xx < m_nx; ++xx ) { int dataPos = xx + m_yi * m_nx + zz * m_nx * m_ny; if ( ( fabs( m_data->at( dataPos )[8] ) > 0.0001 ) ) { float locX = xx * m_dx + m_ax; float locZ = zz * m_dz + m_az; pos.setX( locX ); pos.setZ( locZ ); QVector4D test = mvp * pos; if ( fabs( test.x() / 2.0 ) < 1.0 && fabs( test.y() / 2.0 ) < 1.0 ) { for ( int k = 0; k < 3; ++k ) { if ( k == 0 && m_render1 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( locX ); m_verts->push_back( m_y ); m_verts->push_back( locZ ); m_verts->push_back( radius ); } } if ( k == 1 && m_render2 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( locX ); m_verts->push_back( m_y ); m_verts->push_back( locZ ); m_verts->push_back( radius ); } } if ( k == 2 && m_render3 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( locX ); m_verts->push_back( m_y ); m_verts->push_back( locZ ); m_verts->push_back( radius ); } } } } } } } } if ( ( m_orient & 4 ) == 4 ) { int glyphs = m_ny * m_nz; m_verts->reserve( numVerts * glyphs * 10 ); QVector4D pos( m_x, 0, 0, 1.0 ); for( int yy = m_id; yy < m_ny; yy += numThreads ) { for ( int zz = 0; zz < m_nz; ++zz ) { int dataPos = m_xi + yy * m_nx + zz * m_nx * m_ny; if ( ( fabs( m_data->at( dataPos )[8] ) > 0.0001 ) ) { float locZ = zz * m_dz + m_az; float locY = yy * m_dy + m_ay; pos.setY( locY ); pos.setZ( locZ ); QVector4D test = mvp * pos; if ( fabs( test.x() / 2.0 ) < 1.0 && fabs( test.y() / 2.0 ) < 1.0 ) { for ( int k = 0; k < 3; ++k ) { if ( k == 0 && m_render1 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( m_x ); m_verts->push_back( locY ); m_verts->push_back( locZ ); m_verts->push_back( radius ); } } if ( k == 1 && m_render2 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( m_x ); m_verts->push_back( locY ); m_verts->push_back( locZ ); m_verts->push_back( radius ); } } if ( k == 2 && m_render3 ) { for( int i = 0; i < numVerts; ++i ) { ColumnVector cur( 3 ); cur( 1 ) = (*vertices)( i+1, 1 ); cur( 2 ) = (*vertices)( i+1, 2 ); cur( 3 ) = (*vertices)( i+1, 3 ); ColumnVector m1( 3 ); m1( 1 ) = m_data->at( dataPos )[k*9]; m1( 2 ) = m_data->at( dataPos )[k*9+1]; m1( 3 ) = m_data->at( dataPos )[k*9+2]; ColumnVector m2( 3 ); m2( 1 ) = m_data->at( dataPos )[k*9+3]; m2( 2 ) = m_data->at( dataPos )[k*9+4]; m2( 3 ) = m_data->at( dataPos )[k*9+5]; double val_1( FMath::iprod( m1, cur ) ); double val_2( FMath::iprod( m2, cur ) ); double k1 = m_data->at( dataPos )[k*9+6]; double k2 = m_data->at( dataPos )[k*9+7]; double f0 = m_data->at( dataPos )[k*9+8]; radius = f0 * exp( -( k1 * val_1 * val_1 + k2 * val_2 * val_2 ) ) ; m_verts->push_back( (*vertices)( i+1, 1 ) ); m_verts->push_back( (*vertices)( i+1, 2 ) ); m_verts->push_back( (*vertices)( i+1, 3 ) ); m_verts->push_back( m_x ); m_verts->push_back( locY ); m_verts->push_back( locZ ); m_verts->push_back( radius ); } } } } } } } } else { return; } }
void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload) { // Make sure that 'debug mode' symbol is set // if command line parameter is selected // also if we're in multiplayer and actual debug mode is disabled. game_config::scoped_preproc_define debug_mode("DEBUG_MODE", game_config::debug || game_config::mp_debug); // Game_config already holds requested config in memory. if(!game_config_.empty() && (force_reload == NO_FORCE_RELOAD) && old_defines_map_ == cache_.get_preproc_map()) { return; } loadscreen::global_loadscreen_manager loadscreen_manager(disp_.video()); cursor::setter cur(cursor::WAIT); // The loadscreen will erase the titlescreen. // NOTE: even without loadscreen, needed after MP lobby. try { // Read all game configs. // First we should load data/, // then handle terrains so that they are last loaded from data/. // 2nd everything in userdata. loadscreen::start_stage("verify cache"); data_tree_checksum(); loadscreen::start_stage("create cache"); // Start transaction so macros are shared. game_config::config_cache_transaction main_transaction; cache_.get_config(game_config::path +"/data", game_config_); main_transaction.lock(); // Put the gfx rules aside so that we can prepend the add-on // rules to them. config core_terrain_rules; core_terrain_rules.splice_children(game_config_, "terrain_graphics"); load_addons_cfg(); // Extract the Lua scripts at toplevel. extract_preload_scripts(game_config_); game_config_.clear_children("lua"); // Put the gfx rules back to game config. game_config_.splice_children(core_terrain_rules, "terrain_graphics"); set_multiplayer_hashes(); set_color_info(); set_unit_data(); terrain_builder::set_terrain_rules_cfg(game_config()); ::init_strings(game_config()); theme::set_known_themes(&game_config()); } catch(game::error& e) { ERR_CONFIG << "Error loading game configuration files\n"; gui2::show_error_message(disp_.video(), _("Error loading game configuration files: '") + e.message + _("' (The game will now exit)")); throw; } old_defines_map_ = cache_.get_preproc_map(); // Set new binary paths. paths_manager_.set_paths(game_config()); }
void GLTouchScreen::recordTrack(float x, float y, bool stop) { uint64_t time = currentTimeMillis(); GLTouchPoint cur(x, y, time); if (trackLast == NULL) { trackSpeed.update(0, 0, 0); _trackLast = cur; trackLast = &_trackLast; } else { uint64_t elapsed = (time - trackLast->time); if (elapsed > 50) { if (elapsed > 250) { trackSpeed.update(0, 0, 0); } else { GLfloat xs = ((x - trackLast->x) + trackSpeed.x * trackSpeed.time) / (elapsed + trackSpeed.time); GLfloat ys = ((y - trackLast->y) + trackSpeed.y * trackSpeed.time) / (elapsed + trackSpeed.time); trackSpeed.update(xs, ys, elapsed); } _trackLast = cur; trackLast = &_trackLast; } } bool processed = false; int32_t count = trackList.count(); GLTouchObject** items = trackList.items(); for (int i = 0; i < count; i++) { GLTouchObject* track = items[i]; int32_t idx = trackingList.search(track); CString name; if (track->name.m_length > 0) { name = L" "; name += track->name; } if ((!stop) && (x >= track->x) && (x < (track->x + track->w)) && (y >= track->y) && (y < (track->y + track->h)) ) { if (idx < 0) { if (!processed) { // Track In (Enter) trackingList.push(track); trackingLast.push(cur); processed |= track->onevent(CString::format(L"enter%ls", (wchar_t*)name), &cur, NULL, &trackSpeed, track->userData); } } else { if (!processed) { // Track Move GLTouchPoint last = trackingLast[idx]; GLTouchPoint delta = GLTouchPoint( (x - last.x), (y - last.y), (time - last.time) ); processed |= track->onevent(CString::format(L"move%ls", (wchar_t*)name), &cur, &delta, &trackSpeed, track->userData); trackingLast[idx] = cur; } } } else if (idx >= 0) { // Track Out (Leave) GLTouchPoint last = trackingLast[idx]; GLTouchPoint delta = GLTouchPoint( (x - last.x), (y - last.y), (time - last.time) ); track->onevent(CString::format(L"leave%ls", (wchar_t*)name), &cur, &delta, &trackSpeed, track->userData); trackingList.remove(idx); trackingLast.remove(idx); } } if (stop) { trackSpeed.update(0, 0, 0); trackLast = NULL; } }
static int test_and_skip(struct frozen *f, int expected) { int ch = cur(f); if (ch == expected) { f->cur++; return 0; } return ch == END_OF_STRING ? JSON_STRING_INCOMPLETE : JSON_STRING_INVALID; }
void cbStyledTextCtrl::HighlightRightBrace() { if (m_bracePosition == wxSCI_INVALID_POSITION) return; int pos = GetCurrentPos(); if (pos == wxSCI_INVALID_POSITION) return; const static wxColour caretForeground = GetCaretForeground(); const static int caretWidth = GetCaretWidth(); const int curLine = GetCurrentLine(); const int len = GetLength(); if (m_tabSmartJump && (curLine == LineFromPosition(m_bracePosition))) { SetIndicatorCurrent(s_indicHighlight); const int indPos = GetLineIndentPosition(curLine); IndicatorClearRange(indPos, GetLineEndPosition(curLine)-indPos); do { if (pos >= len) break; wxString cur((wxChar)GetCharAt(pos)); if (cur == _T("\n")) break; int style = GetStyleAt(pos); if (IsComment(style)) continue; if (IsString(style) || IsCharacter(style)) { const int nextOne = (pos == len) ? GetStyleAt(pos) : GetStyleAt(pos + 1); if (IsCharacter(nextOne) || IsString(nextOne)) continue; } if (s_rightBrace.Contains(cur)) { SetCaretForeground(wxColour(255, 0, 0)); SetCaretWidth(caretWidth + 1); IndicatorSetForeground(s_indicHighlight, wxColour(80, 236, 120)); IndicatorSetStyle(s_indicHighlight, wxSCI_INDIC_HIGHLIGHT); #ifndef wxHAVE_RAW_BITMAP IndicatorSetUnder(s_indicHighlight, true); #endif SetIndicatorCurrent(s_indicHighlight); IndicatorFillRange(pos, 1); m_bracePosition = pos + 1; return; } } while (++pos); } m_bracePosition = wxSCI_INVALID_POSITION; m_lastPosition = wxSCI_INVALID_POSITION; m_tabSmartJump = false; SetIndicatorCurrent(s_indicHighlight); IndicatorClearRange(0, len); SetCaretForeground(caretForeground); SetCaretWidth(caretWidth); }
void include_check::inspect( const string & library_name, const path & full_path, // example: c:/foo/boost/filesystem/path.hpp const string & contents) // contents of file to be inspected { if (contents.find( "hpxinspect:" "noinclude" ) != string::npos) return; // first, collect all #includes in this file std::set<std::string> includes; boost::sregex_iterator cur(contents.begin(), contents.end(), include_regex), end; for( ; cur != end; ++cur /*, ++m_errors*/ ) { auto m = *cur; if (m[1].matched) includes.insert(std::string(m[1].first, m[1].second)); else if (m[2].matched) includes.insert(std::string(m[2].first, m[2].second)); } // for all given names, check whether corresponding include was found std::set<std::string> checked_includes; std::set<std::string> found_names; for (names_regex_data const& d : regex_data) { boost::sregex_iterator cur(contents.begin(), contents.end(), d.pattern), end; for(/**/; cur != end; ++cur) { auto m = *cur; if (m[1].matched) { // avoid checking the same include twice auto checked_includes_it = checked_includes.find(m.format(d.data->include)); if (checked_includes_it != checked_includes.end()) continue; // avoid errors to be reported twice std::string found_name(m[1].first, m[1].second); if (found_names.find(found_name) != found_names.end()) continue; found_names.insert(found_name); auto include_it = includes.find(m.format(d.data->include)); if (include_it == includes.end()) { // include is missing auto it = contents.begin(); auto match_it = m[1].first; auto line_start = it; string::size_type line_number = 1; for (/**/; it != match_it; ++it) { if (string::traits_type::eq(*it, '\n')) { ++line_number; line_start = it + 1; // could be end() } } ++m_errors; error(library_name, full_path, string(name()) + " missing #include (" + m.format(d.data->include) + ") for symbol " + m.format(d.data->name) + " on line " + linelink(full_path, boost::lexical_cast<string>(line_number))); } checked_includes.insert(m.format(d.data->include)); } } } }
void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, game_classification const* classification) { // Make sure that 'debug mode' symbol is set // if command line parameter is selected // also if we're in multiplayer and actual debug mode is disabled. game_config::scoped_preproc_define debug_mode("DEBUG_MODE", game_config::debug || game_config::mp_debug); // Game_config already holds requested config in memory. if(!game_config_.empty() && (force_reload == NO_FORCE_RELOAD) && old_defines_map_ == cache_.get_preproc_map()) { return; } loadscreen::global_loadscreen_manager loadscreen_manager(disp_.video()); cursor::setter cur(cursor::WAIT); // The loadscreen will erase the titlescreen. // NOTE: even without loadscreen, needed after MP lobby. try { // Read all game configs. // First we should load data/, // then handle terrains so that they are last loaded from data/. // 2nd everything in userdata. loadscreen::start_stage("verify cache"); data_tree_checksum(); loadscreen::start_stage("create cache"); // Start transaction so macros are shared. game_config::config_cache_transaction main_transaction; // Load the selected core cache_.get_config(get_wml_location(preferences::wml_tree_root()), game_config_); // Load the mainline core definitions to make sure switching back is always possible. config default_core_cfg; cache_.get_config(game_config::path + "/data/cores.cfg", default_core_cfg); game_config_.append(default_core_cfg); main_transaction.lock(); // Put the gfx rules aside so that we can prepend the add-on // rules to them. config core_terrain_rules; core_terrain_rules.splice_children(game_config_, "terrain_graphics"); load_addons_cfg(); // If multiplayer campaign is being loaded, [scenario] tags should // become [multiplayer] tags and campaign's id should be added to them // to allow to recognize which scenarios belongs to a loaded campaign. if (classification != NULL) { if (classification->campaign_type == game_classification::MULTIPLAYER && !classification->campaign_define.empty()) { const config& campaign = game_config().find_child("campaign", "define", classification->campaign_define); const std::string& campaign_id = campaign["id"]; const bool require_campaign = campaign["require_campaign"].to_bool(true); const config::const_child_itors &ci = game_config().child_range("scenario"); std::vector<config> scenarios(ci.first, ci.second); game_config_.clear_children("scenario"); BOOST_FOREACH(config& cfg, scenarios) { cfg["campaign_id"] = campaign_id; cfg["require_scenario"] = require_campaign; game_config_.add_child(lexical_cast<std::string>(game_classification::MULTIPLAYER), cfg); } } } // Extract the Lua scripts at toplevel. extract_preload_scripts(game_config_); game_config_.clear_children("lua"); // Put the gfx rules back to game config. game_config_.splice_children(core_terrain_rules, "terrain_graphics"); set_multiplayer_hashes(); set_color_info(); set_unit_data(); terrain_builder::set_terrain_rules_cfg(game_config()); ::init_strings(game_config()); theme::set_known_themes(&game_config()); } catch(game::error& e) {
Field::Field(QWidget *parent, int n_arch, int n_knig, int n_mach) : QWidget(parent){ QWidget* wgt = new QWidget(this); QPalette pal1 = wgt->palette(); pal1.setColor(QPalette::Base, QColor(255, 255, 255, 0)); wgt->setFixedSize(1350, 750); Sound* snd = new Sound(this, SOUND_GAME); QPixmap p(HUMAN_CURSOR); QCursor cur(p, 0, 0); setCursor(cur); whose_turn_wgt = new QPushButton; whose_turn_wgt->setFixedSize(97, 97); QPixmap pix_w(PALADIN_ICON); whose_turn_wgt->setIcon(pix_w); whose_turn_wgt->setIconSize(pix_w.size()); scene = new BattleScene(30, 33, 930, 496, n_arch, n_knig, n_mach); scene->setBackgroundBrush(QPixmap(LANDSCAPE)); end_turn = new QPushButton; QPixmap pix(FINISH_TURN_BUTTON); end_turn->setIcon(pix); end_turn->setIconSize(pix.size()); end_turn->setFixedSize(pix.width(), pix.height()); quit = new QPushButton; QPixmap pix1(EXIT_BUTTON); quit->setIcon(pix1); quit->setIconSize(pix1.size()); quit->setFixedSize(pix1.width(), pix1.height()); view = new FieldView; view->setScene(scene); view->setFixedSize(scene->width()+90, scene->height()+90); QPalette pal; pal.setBrush(this->backgroundRole(), QBrush(QPixmap(FIELD_BACKGROUND))); setPalette(pal); UnitInfo* uinf = new UnitInfo(this, scene); MovesLeft* ml = new MovesLeft(this, scene); QGridLayout* qglt = new QGridLayout; qglt->setMargin(20); qglt->setSpacing(15); if(QApplication::desktop()->width() >= 1366){ qglt->addWidget(ml, 0, 1, Qt::AlignCenter); qglt->addWidget(uinf, 1, 0, Qt::AlignTop); qglt->addWidget(whose_turn_wgt, 1, 0, Qt::AlignCenter); qglt->addWidget(quit, 2, 1, Qt::AlignRight); qglt->addWidget(view, 1, 1); qglt->addWidget(end_turn, 2, 0, Qt::AlignCenter); qglt->addWidget(snd, 2, 1, Qt::AlignCenter); } else if(QApplication::desktop()->width() < 1366){ wgt->setFixedSize(1240, 960); qglt->addWidget(uinf, 0, 1, Qt::AlignRight); qglt->addWidget(ml, 0, 1, Qt::AlignBottom); qglt->addWidget(whose_turn_wgt, 0, 1, Qt::AlignLeft); qglt->addWidget(quit, 2, 2, Qt::AlignCenter); qglt->addWidget(view, 1, 1); qglt->addWidget(end_turn, 2, 0, Qt::AlignCenter); qglt->addWidget(snd, 2, 1, Qt::AlignCenter); } wgt->setLayout(qglt); QVBoxLayout* main_lo = new QVBoxLayout; main_lo->addWidget(wgt); setLayout(main_lo); setWindowState(Qt::WindowFullScreen); connect(scene, SIGNAL(signal_end_turn()), end_turn, SIGNAL(clicked())); connect(scene, SIGNAL(signal_dead_humans_army()), this, SLOT(slot_orcs_victory())); connect(scene, SIGNAL(signal_dead_orcs_army()), this, SLOT(slot_humans_victory())); connect(scene, SIGNAL(signal_change_current_unit_icon()), this, SLOT(slot_change_icon())); connect(scene, SIGNAL(signal_press_next_turn_button()), end_turn, SIGNAL(clicked())); connect(end_turn, SIGNAL(clicked()), scene, SIGNAL(signal_click_count())); connect(end_turn, SIGNAL(clicked()), scene, SIGNAL(signal_move_end())); connect(end_turn, SIGNAL(clicked()), scene, SLOT(slot_null_to_turns_summ())); connect(end_turn, SIGNAL(clicked()), this, SLOT(slot_change_cursor())); connect(end_turn, SIGNAL(clicked()), ml, SLOT(slot_update_turns_info())); connect(end_turn, SIGNAL(clicked()), uinf, SLOT(slot_clear_field())); connect(quit, SIGNAL(clicked()), snd->med_obj, SLOT(stop())); connect(quit, SIGNAL(clicked()), this, SLOT(close())); connect(quit, SIGNAL(clicked()), this, SLOT(slot_start_window())); }
// Will work only for unwrappable hosizontal toolbars // Fixes MFC bug with drop-down buttons when system metrics are changed // It's a copy of CalcSize() protected function: fixed drop-down width CSize CIVToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { CToolBarCtrl & tb = GetToolBarCtrl(); int nCount = tb.GetButtonCount(); ASSERT(nCount > 0); CPoint cur(0,0); CSize sizeResult(0,0); DWORD dwExtendedStyle = tb.GetExtendedStyle(); for (int i = 0; i < nCount; i++) { TBBUTTON btn; tb.GetButton(i, &btn); //WINBUG: The IE4 version of COMCTL32.DLL calculates the separation // on a TBSTYLE_WRAP button as 100% of the value in iBitmap compared // to the other versions which calculate it at 2/3 of that value. // This is actually a bug which should be fixed in IE 4.01, so we // only do the 100% calculation specifically for IE4. int cySep = btn.iBitmap; if (!(GetStyle() & TBSTYLE_FLAT) && _AfxGetComCtlVersion() != VERSION_IE4) cySep = cySep * 2 / 3; if (btn.fsState & TBSTATE_HIDDEN) continue; int cx = m_sizeButton.cx; if (btn.fsStyle & TBSTYLE_SEP) { // a separator represents either a height or width if (btn.fsState & TBSTATE_WRAP) sizeResult.cy = max(cur.y + m_sizeButton.cy + cySep, sizeResult.cy); else sizeResult.cx = max(cur.x + btn.iBitmap, sizeResult.cx); } else { // check for dropdown style, but only if the buttons are being drawn if ((btn.fsStyle & TBSTYLE_DROPDOWN) && (dwExtendedStyle & TBSTYLE_EX_DRAWDDARROWS)) { cx += _AfxGetDropDownWidth(); } sizeResult.cx = max(cur.x + cx, sizeResult.cx); sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy); } if (btn.fsStyle & TBSTYLE_SEP) cur.x += btn.iBitmap; else cur.x += cx - CX_OVERLAP; if (btn.fsState & TBSTATE_WRAP) { cur.x = 0; cur.y += m_sizeButton.cy; if (btn.fsStyle & TBSTYLE_SEP) cur.y += cySep; } } return sizeResult; }
void ChrGetListAction::run_indbpool( otl_connect *pconn) { try { pconn->auto_commit_off(); #ifdef OTL_ODBC pconn->set_transaction_isolation_level( otl_tran_serializable); #endif otl_stream cur( 50, DBPROC_CHRGETLIST, *pconn, otl_implicit_select); cur << uuid_.userid_ << (short)GLOBALCONFIG_INS->get_regionsn(); //获取角色列表 while( !cur.eof()) { short sv, rc, pf; NS_STL::string strname, petname; ChrListInfo* chr =FRAMEWK_NEW ChrListInfo(); cur >> chr->chrid_ >> strname >> rc >> pf >> sv >> chr->lastposx_ >> chr->lastposy_ >> chr->lastposz_ >> chr->lastfacing_ >> chr->hp_ >> chr->mp_ >> chr->exp_ >> chr->level_ >> chr->moneys_ >> chr->petid_ >> chr->petcode_ >> petname; chr->name_ =strname; chr->petname_ =petname; chr->race_ =rc; chr->sex_ =sv; chr->profession_ =pf; chr->equiplen_ =CHRITEMS_MAX; chrs_.push_back( chr); } cur.close(); //获取avatar列表 otl_stream cur2( 50, DBPROC_CHRGETAVLIST, *pconn, otl_implicit_select); cur2 << uuid_.userid_ << (short)GLOBALCONFIG_INS->get_regionsn(); int cid, icode; short iav, inp; while( !cur2.eof()) { cur2 >> cid >> iav >> icode >> inp; ChrListInfo* pc =get_chrinfo( cid); if( pc == 0) continue; if( inp < 0 || inp >= CHRITEMS_MAX) continue; pc->equips_[inp] =icode; } pconn->commit(); } catch( otl_exception& e){ pconn->rollback(); MODULE_LOG_ERROR( MODULE_DATABASE, "ChrGetListAction::run_indbpool exception code:%d msg:%s ", e.code, e.msg); } }
void CGprsSynthesize::HandleBSSGP(SPcapSignal& signal) { //得到bvci const UINT16* bvci = getBvci(signal.pdu); if(bvci) signal.bvci = *bvci; else { printf("HandleBSSGP no bvci\n"); return; } const UINT8* type = getBssgpPduType(signal.pdu); if(!type) { printf("wrong format signal\n"); return; } switch(*type) { default: break; case 0x00: //CGBPdu::DL_UNITDATA //SGSN to BSS havn't Cell Indentifier { //根据link和bvci找到所在RAI //找到当前TLLI //如果有旧的TLLI,则用新的TLLI更新旧的TLLI if(!m_RaiMap.FindRai(signal.link, signal.bvci, signal.currai)) { printf("Handle BSSGP DL_UNITDATA can't find rai in routemap:link[%hd] bvci[%hd] ai[%lld]\n", signal.link, signal.bvci, signal.currai.value); return; } const UINT32* curtlli = getCurTlli(signal.pdu); if(curtlli) signal.curtlli = *curtlli; else { printf("Handle BSSGP DL_UNITDATA no cur tlli\n"); return; } const UINT32* oldtlli = getOldTlli(signal.pdu); if(oldtlli) { signal.oldtlli = *oldtlli; CKey cur(signal.currai, signal.curtlli); CKey old(signal.currai, signal.oldtlli); m_InfoDB.ChangeKey(old, cur); } HandleLLC(signal); } break; case 0x01: //CGBPdu::UL_UNITDATA //BSS to SGSN have Cell Indentifier { //@zh //attatch request/route area update request const char* oldrai = getOldRai(signal.pdu); if(oldrai) { signal.oldrai(oldrai); } //@zh //可以获得CGI RAI TLLI(当前) const char* rai = getCurRai(signal.pdu); if(!rai) { printf("Handle BSSGP UL_UNITDATA no rai\n"); return; } signal.currai(rai); const UINT32* curtlli = getCurTlli(signal.pdu); if(curtlli) signal.curtlli = *curtlli; else { printf("Handle BSSGP UL_UNITDATA no cur tlli\n"); return; } m_RaiMap.AddRai(signal.link, signal.bvci, signal.currai); //@zh for debug printf("Hadle BSSGP UL_UNITDATA: add rai -- link[%hd] bvci[%hd] rai[%lld]\n", signal.link, signal.bvci, signal.currai.value); HandleLLC(signal); } break; //@zh add case 0x59: //PS_HANDOVER_REQUIRED: { //BSS => SGSN const char* rai = getCurRai(signal.pdu); if(!rai) { printf("HandleBSSGP PS_HANDOVER_REQUIRED no rai\n"); return; } signal.currai(rai); // const UINT32* curtlli = getCurTlli(signal.pdu); if(curtlli) signal.curtlli = *curtlli; else { printf("HandleBSSGP PS_HANDOVER_REQUIRED no cur tlli\n"); return; } // CKey key(signal.currai, signal.curtlli); CUserInfo* pUserInfo = m_InfoDB.FindUserInfo(key); if(!pUserInfo) { //printf("can't find PS_HANDOVER_REQUIRED BVCI = %d, TLLI = 0x%04x\n", ntohs(bvci), ntohl(tlli)); return; } // pUserInfo->TDR.SetBeginTime(getTime(signal.pdu)); pUserInfo->TDR.SetImsi(getImsi(signal.pdu)); pUserInfo->TDR.SetType(GPRS_HANDOVER_EVENT); pUserInfo->TDR.SetDlci(getDlci(signal.pdu)); // 切换前DLCI pUserInfo->TDR.SetBvci(getBvci(signal.pdu)); // 切换前BVCI pUserInfo->TDR.SetTlli(getCurTlli(signal.pdu)); // tlli pUserInfo->TDR.SetCgi(getCgi(signal.pdu)); // 切换前CGI } break; case 0x5a: //PS_HANDOVER_REQUIRED_ACK { //SGSN => old BSS } break; case 0x5b: //PS_HANDOVER_REQUIRED_NACK { } break; case 0x5c: //PS_HANDOVER_REQUEST { } break; case 0x5d: //PS_HANDOVER_REQUEST_ACK { } break; case 0x5e: //PS_HANDOVER_REQUEST_NACK { } break; case 0x91: //PS_HANDOVER_COMPLETE { } break; case 0x92: //PS_HANDOVER_CANCEL { } break; //@zh add } }
ExecStatus IntBase<VY>::prune_lower(Space& home, int* dis, int n_dis) { assert(n_dis > 0); // At least one more value will be needed GECODE_ME_CHECK(y.gq(home,vs.size() + 1)); Region r(home); // Only one additional value is allowed if (y.max() == vs.size() + 1) { // Compute possible values ViewRanges<IntView>* r_dis = r.alloc<ViewRanges<IntView> >(n_dis); for (int i=n_dis; i--; ) r_dis[i] = ViewRanges<IntView>(x[dis[i]]); Iter::Ranges::NaryInter iv(r, r_dis, n_dis); // Is there a common value at all? if (!iv()) return ES_FAILED; ValSet::Ranges vsr(vs); Iter::Ranges::NaryUnion pv(r,iv,vsr); // Enforce common values for (int i=x.size(); i--; ) { pv.reset(); GECODE_ME_CHECK(x[i].inter_r(home, pv, false)); } return ES_OK; } // Compute independent set for lower bound // ovl is a bit-matrix defining whether two views overlap SymBitMatrix ovl(r,x.size()); // deg[i] is the degree of x[i] int* deg = r.alloc<int>(x.size()); // ovl_i[i] is an array of indices j such that x[j] overlaps with x[i] int** ovl_i = r.alloc<int*>(x.size()); // n_ovl_i[i] defines how many integers are stored for ovl_i[i] int* n_ovl_i = r.alloc<int>(x.size()); { #ifndef NDEBUG // Initialize all to null pointers so that things crash ;-) for (int i=x.size(); i--; ) ovl_i[i] = NULL; #endif // For each i there can be at most n_dis-1 entries in ovl_i[i] int* m = r.alloc<int>(n_dis*(n_dis-1)); for (int i=n_dis; i--; ) { deg[dis[i]] = 0; ovl_i[dis[i]] = m; m += n_dis-1; } } // Initialize overlap matrix by analyzing the view ranges { // Compute how many events are needed // One event for the end marker int n_re = 1; // Two events for each range for (int i=n_dis; i--; ) for (ViewRanges<IntView> rx(x[dis[i]]); rx(); ++rx) n_re += 2; // Allocate and initialize events RangeEvent* re = r.alloc<RangeEvent>(n_re); int j=0; for (int i=n_dis; i--; ) for (ViewRanges<IntView> rx(x[dis[i]]); rx(); ++rx) { // Event when a range starts re[j].ret=RET_FST; re[j].val=rx.min(); re[j].view=dis[i]; j++; // Event when a range ends re[j].ret=RET_LST; re[j].val=rx.max(); re[j].view=dis[i]; j++; } // Make this the last event re[j].ret=RET_END; re[j].val=Int::Limits::infinity; assert(j+1 == n_re); // Sort and process events Support::quicksort(re,n_re); // Current views with a range being active Support::BitSet<Region> cur(r,static_cast<unsigned int>(x.size())); // Process all events for (int i=0; true; i++) switch (re[i].ret) { case RET_FST: // Process all overlapping views for (Iter::Values::BitSet<Support::BitSet<Region> > j(cur); j(); ++j) { int di = re[i].view, dj = j.val(); if (!ovl.get(di,dj)) { ovl.set(di,dj); ovl_i[di][deg[di]++] = dj; ovl_i[dj][deg[dj]++] = di; } } cur.set(static_cast<unsigned int>(re[i].view)); break; case RET_LST: cur.clear(static_cast<unsigned int>(re[i].view)); break; case RET_END: goto done; default: GECODE_NEVER; } done: r.free<RangeEvent>(re,n_re); } // While deg changes, n_ovl_i remains unchanged and is needed, so copy it for (int i=n_dis; i--; ) { assert(deg[dis[i]] < n_dis); n_ovl_i[dis[i]] = deg[dis[i]]; } // Views in the independent set int* ind = r.alloc<int>(n_dis); int n_ind = 0; while (n_dis > 0) { int i_min = n_dis-1; int d_min = deg[dis[i_min]]; unsigned int s_min = x[dis[i_min]].size(); // Find view with smallest (degree,size) for (int i=n_dis-1; i--; ) if ((d_min > deg[dis[i]]) || ((d_min == deg[dis[i]]) && (s_min > x[dis[i]].size()))) { i_min = i; d_min = deg[dis[i]]; s_min = x[dis[i]].size(); } // i_min refers to view with smallest (degree,size) ind[n_ind++] = dis[i_min]; dis[i_min] = dis[--n_dis]; // Filter out non disjoint views for (int i=n_dis; i--; ) if (ovl.get(dis[i],ind[n_ind-1])) { // Update degree information for (int j=n_ovl_i[dis[i]]; j--; ) deg[ovl_i[dis[i]][j]]--; // Eliminate view dis[i] = dis[--n_dis]; } } // Enforce lower bound GECODE_ME_CHECK(y.gq(home,vs.size() + n_ind)); // Prune, if possible if (vs.size() + n_ind == y.max()) { // Only values from the indepent set a can be taken ViewRanges<IntView>* r_ind = r.alloc<ViewRanges<IntView> >(n_ind); for (int i=n_ind; i--; ) r_ind[i] = ViewRanges<IntView>(x[ind[i]]); Iter::Ranges::NaryUnion v_ind(r, r_ind, n_ind); ValSet::Ranges vsr(vs); v_ind |= vsr; for (int i=x.size(); i--; ) { v_ind.reset(); GECODE_ME_CHECK(x[i].inter_r(home,v_ind,false)); } } return ES_OK; }
void PhotoCropBox::mouseMoveEvent(QMouseEvent *e) { if (_downState && !(e->buttons() & Qt::LeftButton)) { mouseReleaseEvent(e); } if (_downState) { if (_downState == 1) { int32 dx = e->pos().x() - _fromposx, dy = e->pos().y() - _fromposy, d = (dx < dy) ? dx : dy; if (_fromcropx + d < 0) { d = -_fromcropx; } if (_fromcropy + d < 0) { d = -_fromcropy; } if (_fromcropw - d < st::cropMinSize) { d = _fromcropw - st::cropMinSize; } if (_cropx != _fromcropx + d || _cropy != _fromcropy + d || _cropw != _fromcropw - d) { _cropx = _fromcropx + d; _cropy = _fromcropy + d; _cropw = _fromcropw - d; update(); } } else if (_downState == 2) { int32 dx = _fromposx - e->pos().x(), dy = e->pos().y() - _fromposy, d = (dx < dy) ? dx : dy; if (_fromcropx + _fromcropw - d > _thumbw) { d = _fromcropx + _fromcropw - _thumbw; } if (_fromcropy + d < 0) { d = -_fromcropy; } if (_fromcropw - d < st::cropMinSize) { d = _fromcropw - st::cropMinSize; } if (_cropy != _fromcropy + d || _cropw != _fromcropw - d) { _cropy = _fromcropy + d; _cropw = _fromcropw - d; update(); } } else if (_downState == 3) { int32 dx = _fromposx - e->pos().x(), dy = _fromposy - e->pos().y(), d = (dx < dy) ? dx : dy; if (_fromcropx + _fromcropw - d > _thumbw) { d = _fromcropx + _fromcropw - _thumbw; } if (_fromcropy + _fromcropw - d > _thumbh) { d = _fromcropy + _fromcropw - _thumbh; } if (_fromcropw - d < st::cropMinSize) { d = _fromcropw - st::cropMinSize; } if (_cropw != _fromcropw - d) { _cropw = _fromcropw - d; update(); } } else if (_downState == 4) { int32 dx = e->pos().x() - _fromposx, dy = _fromposy - e->pos().y(), d = (dx < dy) ? dx : dy; if (_fromcropx + d < 0) { d = -_fromcropx; } if (_fromcropy + _fromcropw - d > _thumbh) { d = _fromcropy + _fromcropw - _thumbh; } if (_fromcropw - d < st::cropMinSize) { d = _fromcropw - st::cropMinSize; } if (_cropx != _fromcropx + d || _cropw != _fromcropw - d) { _cropx = _fromcropx + d; _cropw = _fromcropw - d; update(); } } else if (_downState == 5) { int32 dx = e->pos().x() - _fromposx, dy = e->pos().y() - _fromposy; if (_fromcropx + dx < 0) { dx = -_fromcropx; } else if (_fromcropx + _fromcropw + dx > _thumbw) { dx = _thumbw - _fromcropx - _fromcropw; } if (_fromcropy + dy < 0) { dy = -_fromcropy; } else if (_fromcropy + _fromcropw + dy > _thumbh) { dy = _thumbh - _fromcropy - _fromcropw; } if (_cropx != _fromcropx + dx || _cropy != _fromcropy + dy) { _cropx = _fromcropx + dx; _cropy = _fromcropy + dy; update(); } } } int32 cursorState = _downState ? _downState : mouseState(e->pos()); QCursor cur(style::cur_default); if (cursorState == 1 || cursorState == 3) { cur = style::cur_sizefdiag; } else if (cursorState == 2 || cursorState == 4) { cur = style::cur_sizebdiag; } else if (cursorState == 5) { cur = style::cur_sizeall; } setCursor(cur); }