/////////////////////////////////////////////////////////////////////////////// // // // Track status // // // /////////////////////////////////////////////////////////////////////////////// ATHENAError Track::GetName(char * _name, const ULong & max_char) { if (name) strncpy(_name, name, max_char); else { SLong s_id(GetSampleID(s_id)); if (_sample.IsValid(s_id)) strncpy(_name, _sample[s_id]->name, max_char); else *_name = 0; } return ATHENA_OK; }
ATHENAError Track::GetKeyLoopLength(const SLong & k_id, const ULong & loop_i, ULong & length) { Float f_lgt(0.0F); if (ULong(k_id) >= key_c || loop_i > key_l[k_id].loop) return ATHENA_ERROR_HANDLE; SLong s_id(GetSampleID(s_id)); if (_sample.IsNotValid(s_id)) { length = 0; return ATHENA_OK; } Sample * sample = _sample[s_id]; TrackKey * key = &key_l[k_id]; if (key->pitch.interval) { Float min, max, cur; Float size; length = sample->length; //length in bytes size = Float(length) * (key->loop + 1); min = key->pitch.min * sample->format.frequency * key->pitch.interval * 0.001F; max = key->pitch.max * sample->format.frequency * key->pitch.interval * 0.001F; cur = max; while (size > 0.0F) { f_lgt += key->pitch.interval; size -= cur = cur == min ? max : min; } if (size < 0.0F) f_lgt += key->pitch.interval * (size / cur); } else { sample->GetLength(length); length = ULong((loop_i & 0x00000001 ? key->pitch.max : key->pitch.min) * length); } return ATHENA_OK; }
bool ParserInsertQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) { Pos begin = pos; ParserWhiteSpaceOrComments ws; ParserString s_insert("INSERT", true, true); ParserString s_into("INTO", true, true); ParserString s_dot("."); ParserString s_id("ID"); ParserString s_eq("="); ParserStringLiteral id_p; ParserString s_values("VALUES", true, true); ParserString s_format("FORMAT", true, true); ParserString s_select("SELECT", true, true); ParserString s_lparen("("); ParserString s_rparen(")"); ParserIdentifier name_p; ParserList columns_p(std::make_unique<ParserCompoundIdentifier>(), std::make_unique<ParserString>(","), false); ASTPtr database; ASTPtr table; ASTPtr columns; ASTPtr format; ASTPtr select; ASTPtr id; /// Данные для вставки const char * data = nullptr; ws.ignore(pos, end); /// INSERT INTO if (!s_insert.ignore(pos, end, max_parsed_pos, expected) || !ws.ignore(pos, end) || !s_into.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!name_p.parse(pos, end, table, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (s_dot.ignore(pos, end, max_parsed_pos, expected)) { database = table; if (!name_p.parse(pos, end, table, max_parsed_pos, expected)) return false; ws.ignore(pos, end); } ws.ignore(pos, end); if (s_id.ignore(pos, end, max_parsed_pos, expected)) { if (!s_eq.ignore(pos, end, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!id_p.parse(pos, end, id, max_parsed_pos, expected)) return false; } ws.ignore(pos, end); /// Есть ли список столбцов if (s_lparen.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!columns_p.parse(pos, end, columns, max_parsed_pos, expected)) return false; ws.ignore(pos, end); if (!s_rparen.ignore(pos, end, max_parsed_pos, expected)) return false; } ws.ignore(pos, end); Pos before_select = pos; /// VALUES или FORMAT или SELECT if (s_values.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); data = pos; pos = end; } else if (s_format.ignore(pos, end, max_parsed_pos, expected)) { ws.ignore(pos, end); if (!name_p.parse(pos, end, format, max_parsed_pos, expected)) return false; /// Данные начинаются после первого перевода строки, если такой есть, или после всех пробельных символов, иначе. ParserWhiteSpaceOrComments ws_without_nl(false); ws_without_nl.ignore(pos, end); if (pos != end && *pos == ';') throw Exception("You have excessive ';' symbol before data for INSERT.\n" "Example:\n\n" "INSERT INTO t (x, y) FORMAT TabSeparated\n" "1\tHello\n" "2\tWorld\n" "\n" "Note that there is no ';' in first line.", ErrorCodes::SYNTAX_ERROR); if (pos != end && *pos == '\n') ++pos; data = pos; pos = end; } else if (s_select.ignore(pos, end, max_parsed_pos, expected)) { pos = before_select; ParserSelectQuery select_p; select_p.parse(pos, end, select, max_parsed_pos, expected); } else { expected = "VALUES or FORMAT or SELECT"; return false; } auto query = std::make_shared<ASTInsertQuery>(StringRange(begin, data ? data : pos)); node = query; if (database) query->database = typeid_cast<ASTIdentifier &>(*database).name; query->table = typeid_cast<ASTIdentifier &>(*table).name; if (id) query->insert_id = safeGet<const String &>(typeid_cast<ASTLiteral &>(*id).value); if (format) query->format = typeid_cast<ASTIdentifier &>(*format).name; query->columns = columns; query->select = select; query->data = data != end ? data : NULL; query->end = end; if (columns) query->children.push_back(columns); if (select) query->children.push_back(select); return true; }
bool ParserPartition::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ParserKeyword s_id("ID"); ParserStringLiteral parser_string_literal; ParserExpression parser_expr; Pos begin = pos; auto partition = std::make_shared<ASTPartition>(); if (s_id.ignore(pos, expected)) { ASTPtr partition_id; if (!parser_string_literal.parse(pos, partition_id, expected)) return false; partition->id = partition_id->as<ASTLiteral &>().value.get<String>(); } else { ASTPtr value; if (!parser_expr.parse(pos, value, expected)) return false; size_t fields_count; StringRef fields_str; const auto * tuple_ast = value->as<ASTFunction>(); if (tuple_ast && tuple_ast->name == "tuple") { const auto * arguments_ast = tuple_ast->arguments->as<ASTExpressionList>(); if (arguments_ast) fields_count = arguments_ast->children.size(); else fields_count = 0; Pos left_paren = begin; Pos right_paren = pos; while (left_paren != right_paren && left_paren->type != TokenType::OpeningRoundBracket) ++left_paren; if (left_paren->type != TokenType::OpeningRoundBracket) return false; while (right_paren != left_paren && right_paren->type != TokenType::ClosingRoundBracket) --right_paren; if (right_paren->type != TokenType::ClosingRoundBracket) return false; fields_str = StringRef(left_paren->end, right_paren->begin - left_paren->end); } else { fields_count = 1; fields_str = StringRef(begin->begin, pos->begin - begin->begin); } partition->value = value; partition->children.push_back(value); partition->fields_str = fields_str; partition->fields_count = fields_count; } node = partition; return true; }
void NPCMgr::init_OrderList(int i_RoomID) { string r_init_orderlist="2200"; int index=0; int index_1=0; string temp_msg=""; for(index=0;index<10;index++) { int id=index+(11-GlobalVar::TimeTracer[i_RoomID].second)*10; int product_id=rand()%5; int num=(rand()%401); if(num<100) num+=100; if(num>300) num-=100; int product_time=ceil(float(num/product[product_id].per_day))+20; float profit=float(rand()%8+8)/float(10); long money=(num*product[product_id].price)*profit; char c_id[4]; char c_product_id[4]; char c_num[8]; char c_product_time[4]; char c_money[8]; _itoa(id,c_id,10); _itoa(product_id,c_product_id,10); _itoa(num,c_num,10); _itoa(product_time,c_product_time,10); _itoa(money,c_money,10); string s_id(c_id); string s_product_id(c_product_id); string s_num(c_num); string s_product_time(c_product_time); string s_money(c_money); for(index_1=s_id.length();index_1<4;index_1++) { s_id+=" "; } for(index_1=s_product_id.length();index_1<4;index_1++) { s_product_id+=" "; } for(index_1=s_num.length();index_1<8;index_1++) { s_num+=" "; } for(index_1=s_product_time.length();index_1<4;index_1++) { s_product_time+=" "; } for(index_1=s_money.length();index_1<8;index_1++) { s_money+=" "; } temp_msg+=s_id+s_product_id+s_num+s_product_time+s_money; } char c_msg[2048]; //string msg=string(r_init_orderlist)+Order_0+Order_1+Order_2+Order_3+Order_4+Order_5+Order_6+Order_7+Order_8+Order_9; string msg=r_init_orderlist+temp_msg; memcpy(c_msg,msg.c_str(),msg.length()); map<long,string>::iterator ite=GlobalVar::Lobby.LobbyRoom[i_RoomID].Room_Client_Namemap.begin(); for(;ite!=GlobalVar::Lobby.LobbyRoom[i_RoomID].Room_Client_Namemap.end();ite++) { GlobalVar::m_Server.SendMsg(ite->first,c_msg,msg.length()); } }
std::vector<Proposals> nms( const std::vector<Proposals> & proposals, const std::vector<int> & order, float max_iou ) { int N = 0; for( const Proposals & p: proposals ) N += p.p.rows(); std::vector<int> s_id( N ), p_id( N ); for( int i=0, k=0; i<proposals.size(); i++ ) for( int j=0; j<proposals[i].p.rows(); j++, k++ ) { s_id[k] = i; p_id[k] = j; } std::vector<RMatrixXs> s; std::vector<int> Ns; for( int i=0; i<proposals.size(); i++ ) { s.push_back( proposals[i].s ); Ns.push_back( proposals[i].s.maxCoeff()+1 ); } const RMatrixXi ms = mergeOverSegmentations(s); const int Nms = ms.maxCoeff()+1; VectorXu ms_area = VectorXu::Zero( Nms ); for( int j=0; j<ms.rows(); j++ ) for( int i=0; i<ms.cols(); i++ ) ms_area[ ms(j,i) ]++; std::vector<IOUSet> iou_set; std::vector<VectorXs> ids; for( int i=0; i<s.size(); i++ ) { iou_set.push_back( s[i] ); ids.push_back( map_id( ms, s[i] ) ); } std::vector<int> pb; pb.reserve( Nms ); std::vector< std::vector< VectorXb > > r( proposals.size() ); for( int i: order ) { VectorXb p = proposals[ s_id[i] ].p.row( p_id[i] ); // Run NMS if( !p.any() || iou_set[ s_id[i] ].intersects(p,max_iou) ) continue; Vector4s bbox = iou_set[ s_id[i] ].computeBBox( p ); // Project each segmentation onto the common OS pb.clear(); for( int j=0; j<Nms; j++ ) if( p[ ids[ s_id[i] ][j] ] ) pb.push_back( j ); bool intersects = false; for( int k=0; !intersects && k<iou_set.size(); k++ ) if( s_id[i] != k ){ // Reproject the common OS to the current os VectorXu p_area = VectorXu::Zero( Ns[k] ); for( int j: pb ) p_area[ ids[ k ][j] ] += ms_area[ j ]; // Run more NMS intersects = iou_set[k].intersects(p_area, bbox, max_iou); } if( !intersects ) { // Add the segment iou_set[ s_id[i] ].add( p ); r[ s_id[i] ].push_back( p ); } } std::vector<Proposals> res( proposals.size() ); for( int i=0; i<proposals.size(); i++ ) { res[i].s = proposals[i].s; res[i].p = RMatrixXb( r[i].size(), proposals[i].p.cols() ); for( int j=0; j<r[i].size(); j++ ) res[i].p.row(j) = r[i][j]; } return res; }