int main() { auto range = irange(4); auto pos = is_sorted_until(range.begin(), range.end(), std::greater<int>()); assert(pos == range.end()); auto pos2 = is_sorted_until(range.begin(), range.end(), std::less<int>()); assert(pos2 == range.end()); }
/// \brief TODOCUMENT vcie_vcie_vec_pair view_cache_index_entry_test_suite_fixture::build_alignment_vcies_pair(const size_t &arg_num_entries, ///< TODOCUMENT const protein &arg_protein_a, ///< TODOCUMENT const protein &arg_protein_b, ///< TODOCUMENT const alignment &arg_alignment, ///< TODOCUMENT mt19937 &arg_rng ///< TODOCUMENT ) { const auto &present_posn_indices = indices_of_present_positions_of_both_entries( arg_alignment ); const auto num_present_posn_indices = present_posn_indices.size(); if ( num_present_posn_indices < 2 ) { BOOST_THROW_EXCEPTION(invalid_argument_exception("Cannot build random_vcie pairs if the alignment has fewer than two residues")); } vcie_vcie_vec_pair results; for (const auto &entry_ctr : irange( 0_z, arg_num_entries ) ) { ignore_unused( entry_ctr ); const auto index_pair = pick_random_pair( 0_z, num_present_posn_indices - 1, arg_rng ); const auto &index_1 = present_posn_indices[ index_pair.first ]; const auto &index_2 = present_posn_indices[ index_pair.second ]; results.first.push_back( make_view_cache_index_entry( arg_protein_a, get_a_position_of_index( arg_alignment, index_1 ), get_a_position_of_index( arg_alignment, index_2 ) ) ); results.second.push_back( make_view_cache_index_entry( arg_protein_b, get_b_position_of_index( arg_alignment, index_1 ), get_b_position_of_index( arg_alignment, index_2 ) ) ); } return results; }
static auto compute_strides(const cell_t shape) { // boost::partial_sum(shape.cast<int>(), begin(strides), std::multiplies<int>()); // doesnt work somehow cell_t strides; strides(0) = 1; for (auto i : irange(1, n_dim)) strides(i) = strides(i - 1) * shape(i - 1); return strides; }
void mult(const VectorIn& v, VectorOut& w, Assign) const { MTL_DEBUG_THROW_IF(std::size_t(size(v)) != n, incompatible_size()); MTL_DEBUG_THROW_IF(size(w) != 0 && std::size_t(size(w)) != m, incompatible_size()); if (size(w) == 0) w.change_dim(m); if (m == n) Assign::first_update(w, v); else if (m < n) Assign::first_update(w, v[irange(m)]); else { VectorOut w1(w[irange(n)]), w2(w[irange(n, imax)]); Assign::first_update(w1, v); Assign::init(w2); } }
bool KeypointMatcher::matchPoint(const cv::Mat& src, const cv::Point2d src_pt, const cv::Mat& target, cv::Point2d& target_pt) const { const int wx = irange(static_cast<int>(src_pt.x)-ncc_winsize,0,src.cols), wy = irange(static_cast<int>(src_pt.y)-ncc_winsize,0,src.rows), ww = wx+ncc_winsize_dbl>src.cols? src.cols-wx:ncc_winsize_dbl, wh = wy+ncc_winsize_dbl>src.rows? src.rows-wy:ncc_winsize_dbl; cv::Mat win(src, cv::Rect(wx,wy,ww,wh)); bool found = matchPatch(win, target, target_pt); if (!found) return false; target_pt.x += ncc_winsize; target_pt.y += ncc_winsize; return true; }
// searches for a specific edge EdgeIterator FindEdge(const NodeIterator from, const NodeIterator to) const { for (const auto i : irange(BeginEdges(from), EndEdges(from))) { if (to == edge_array[i].target) { return i; } } return SPECIAL_EDGEID; }
void *executor(void*arg) { double st=now(); int *n=(int*)arg; fprintf(stderr,"executor start:%d\n",*n); int local_n=N/NUMTHREAD; for(int i=0;i<local_n;i++) { int at=irange(0,SZ); g_buf[at]++; } double et=now(); fprintf(stderr,"executor finished:%d elt:%.3f\n",*n,et-st); return NULL; }
static array helper(const array &n, intptr_t i) { // Get the nd::array 'self' parameter intptr_t undim = n.get_ndim(); ndt::type udt = n.get_dtype(); if (udt.get_kind() == expr_kind) { std::string field_name = udt.value_type().extended<ndt::struct_type>()->get_field_name(i); return n.replace_dtype(ndt::make_type<ndt::adapt_type>( udt.value_type().extended<ndt::struct_type>()->get_field_type(i), udt, nd::callable(), nd::callable())); } else { if (undim == 0) { return n(i); } else { shortvector<irange> idx(undim + 1); idx[undim] = irange(i); return n.at_array(undim + 1, idx.get()); } } }
bool KeypointMatcher::matchPatch(const cv::Mat& patch, const cv::Mat& target, cv::Point2d& target_pt) const { const int rx = irange(static_cast<int>(target_pt.x)-ncc_range,0,target.cols), ry = irange(static_cast<int>(target_pt.y)-ncc_range,0,target.rows), rw = rx+ncc_range_dbl>target.cols? target.cols-rx:ncc_range_dbl, rh = ry+ncc_range_dbl>target.rows? target.rows-ry:ncc_range_dbl; cv::Mat search_range(target, cv::Rect(rx,ry,rw,rh)); if (rw < patch.cols || rh < patch.rows) return false; double peak; cv::Mat result; cv::Point peak_pt; /* */ cv::matchTemplate(search_range, patch, result, CV_TM_CCORR_NORMED); cv::minMaxLoc(result, NULL, &peak, NULL, &peak_pt); if (peak < threshold) { return false; } /* * cv::matchTemplate(search_range, patch, result, CV_TM_SQDIFF_NORMED); cv::minMaxLoc(result, &peak, NULL, &peak_pt, NULL); /* */ double peak_x = static_cast<double>(peak_pt.x); double peak_y = static_cast<double>(peak_pt.y); if (refine_subpx) { //Quadratic Interpolation const double z_00 = static_cast<double>( result.at<float>(peak_y,peak_x) ); const double z_p10 = static_cast<double>( result.at<float>(peak_y,peak_x+1) ); const double z_m10 = static_cast<double>( result.at<float>(peak_y,peak_x-1) ); const double z_0m1 = static_cast<double>( result.at<float>(peak_y-1,peak_x) ); //const double z_p1m1 = static_cast<double>( result.at<float>(peak_y-1,peak_x+1) ); //const double z_m1m1 = static_cast<double>( result.at<float>(peak_y-1,peak_x-1) ); const double z_0p1 = static_cast<double>( result.at<float>(peak_y+1,peak_x) ); //const double z_p1p1 = static_cast<double>( result.at<float>(peak_y+1,peak_x+1) ); //const double z_m1p1 = static_cast<double>( result.at<float>(peak_y+1,peak_x-1) ); //const double a = z_00; const double b = (z_p10 - z_m10) / 2; const double c = (z_0p1 - z_0m1) / 2; const double d = -z_00 + (z_p10 + z_m10) / 2; const double e = -z_00 + (z_0p1 + z_0m1) / 2; target_pt.x = rx + peak_x + b/(2*d); target_pt.y = ry + peak_y + c/(2*e); //std::cout << "===" << std::endl; //std::cout << target_pt.x << std::endl; //std::cout << rx+peak_x << std::endl; } else { target_pt.x = rx + peak_x; target_pt.y = ry + peak_y; } return true; }
LikertHCI::LikertHCI(MinVR::AbstractCameraRef camera, CFrameMgrRef cFrameMgr, TextureMgrRef texMan, FeedbackRef feedback) : AbstractHCI(cFrameMgr, feedback) { done = false; offAxisCamera = std::dynamic_pointer_cast<MinVR::CameraOffAxis>(camera); this->texMan = texMan; _cycleCount = 0; _questions = MinVR::splitStringIntoArray(MinVR::ConfigVal("LikertQuestions", "")); _answers = MinVR::splitStringIntoArray(MinVR::ConfigVal("LikertAnswers", "")); _maxNumLinesInQuestions = 0; for(int i=0; i < _questions.size(); i++) { _questions[i] = boost::replace_all_copy(_questions[i], "*", "\n"); std::stringstream ss(_questions[i]); std::string line; int lineCount = 0; while(std::getline(ss, line, '\n')){ lineCount++; } if (lineCount > _maxNumLinesInQuestions) { _maxNumLinesInQuestions = lineCount; } } std::vector<std::string> questionRangeStrings = MinVR::splitStringIntoArray(MinVR::ConfigVal("LikertQuestionRanges", "", false)); for(int i=0; i< questionRangeStrings.size(); i++){ glm::dvec2 range; std::string text = boost::replace_all_copy(questionRangeStrings[i], "_", ", "); MinVR::retypeString(text, range); glm::ivec2 irange ((int)range.x, (int)range.y); _questionRanges.push_back(irange); } std::vector<std::string> answerRangeStrings = MinVR::splitStringIntoArray(MinVR::ConfigVal("LikertAnswerRanges", "", false)); for(int i=0; i < answerRangeStrings.size(); i++) { glm::dvec2 range; std::string text = boost::replace_all_copy(answerRangeStrings[i], "_", ", "); MinVR::retypeString(text, range); glm::ivec2 irange ((int)range.x, (int)range.y); _answerRanges.push_back(irange); } //Make all answers the same number of characters int maxSize = 0; _maxNumLinesInAnswers = 0; for(int i=0; i < _answers.size(); i++) { _answers[i] = boost::replace_all_copy(_answers[i], "*", "\n"); std::stringstream ss(_answers[i]); std::string line; int lineCount = 0; while(std::getline(ss, line, '\n')){ lineCount++; if (line.size() > maxSize) { maxSize = line.size(); } } if (lineCount > _maxNumLinesInAnswers) { _maxNumLinesInAnswers = lineCount; } } for(int i=0; i < _answers.size(); i++) { std::stringstream ss(_answers[i]); std::string line; std::string fullLine; std::getline(ss, line, '\n'); // We only need to make the first line be the correct width int size = line.size(); if (size < maxSize) { int lettersToAdd = maxSize - size; int prepend = glm::floor(lettersToAdd/2.0); std::string prependString = ""; for(int j = 0; j < prepend; j++) { prependString += " "; } fullLine=prependString + line; std:string postString = ""; for(int j=0; j < lettersToAdd-prepend; j++) { postString += " "; } fullLine += postString+ _answers[i].substr(line.size()); _answers[i] = fullLine; } } _currentQuestion = _questionRanges[0].x; int numThreads = 1; _questionTextures.resize(numThreads); _questionSizes.resize(numThreads); _answerTextures.resize(numThreads); _answerSizes.resize(numThreads); for(int i=0; i < numThreads; i++) { _questionTextures[i].resize(_questions.size()); _answerTextures[i].resize(_answers.size()); } boost::posix_time::time_facet* facet = new boost::posix_time::time_facet(); facet->format("%Y-%m-%d.%H.%M.%S"); std::stringstream stream; stream.imbue(std::locale(stream.getloc(), facet)); stream << boost::posix_time::second_clock::local_time(); std::string eventStreamFile = "QuestionAnswers-" + stream.str() + ".txt"; _answerRecorder.open(eventStreamFile); }
/** * The notation "irange().by(step)" is a way to specify * the step of the range. */ DYND_CONSTEXPR irange by(intptr_t step) const { return irange(m_start, m_finish, step); }
/** * The notation "irange() < finish" is a way to specify * the end of a range with a positive step. */ DYND_CONSTEXPR irange operator<(intptr_t finish) const { return irange(m_start, finish, m_step); }
/** * The notation "upper > irange()" is a way to specify * the beginning of a range with a negative step. */ inline DYND_CONSTEXPR irange operator>(intptr_t start_plus_one, const irange& i) { return irange(start_plus_one - 1, i.m_finish, i.m_step); }
/** * The notation "start >= irange()" is a way to specify * the beginning of a range with a negative step. */ inline DYND_CONSTEXPR irange operator>=(intptr_t start, const irange& i) { return irange(start, i.m_finish, i.m_step); }
/** * The notation "irange() >= last" is a way to specify * the end of a range with a negative step. */ DYND_CONSTEXPR irange operator>=(intptr_t last) const { return irange(m_start, (last != 0) ? (last-1) : std::numeric_limits<intptr_t>::max(), m_step); }
static auto spaces_after(int amount) { return irange(0, amount) | transformed(construct<string>(_1, ' ')); }
int main(int argc, char **argv ) { bool headless_mode=false; for(int i=0;;i++) { if(!argv[i])break; if(strcmp(argv[i], "--headless") == 0 ) headless_mode = true; } print("program start"); #ifdef __APPLE__ setlocale( LC_ALL, "ja_JP"); #endif #ifdef WIN32 setlocale( LC_ALL, "jpn"); #endif // glfw if( !glfwInit() ) { print("can't init glfw"); return 1; } GLFWwindow *window; glfwSetErrorCallback( glfw_error_cb ); window = glfwCreateWindow( SCRW, SCRH, "min2d", NULL, NULL ); if(window == NULL ) { print("can't open glfw window"); glfwTerminate(); return 1; } glfwMakeContextCurrent(window); glfwSetWindowCloseCallback( window, winclose_callback ); glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); glfwSwapInterval(0); // set 1 to use vsync. Use 0 for fast screen capturing and headless glfwSetKeyCallback( window, kbdCallback ); #ifdef WIN32 glewInit(); #endif glClearColor(0.2,0.2,0.2,1); SoundSystem *ss = new SoundSystem(); Sound *bgm = ss->newSound( "assets/gymno1short.wav" ); bgm->play(); g_keyboard = new Keyboard(); MoyaiClient *moyai_client = new MoyaiClient(window,SCRW,SCRH); if( headless_mode ) { Moyai::globalInitNetwork(); RemoteHead *rh = new RemoteHead(); int port = 22222; if( rh->startServer(port) == false ) { print("headless server: can't start server. port:%d", 22222 ); exit(1); } else { print("Start headless server port:%d",port); } rh->enableSpriteStream(); rh->enableReprecation(REPRECATOR_SERVER_PORT); moyai_client->setRemoteHead(rh); rh->setTargetMoyaiClient(moyai_client); ss->setRemoteHead(rh); rh->setTargetSoundSystem(ss); rh->setOnKeyboardCallback(onRemoteKeyboardCallback); } Viewport *viewport = new Viewport(); int retina = 1; #if defined(__APPLE__) retina = 2; #endif viewport->setSize(SCRW*retina,SCRH*retina); // set actual framebuffer size to output viewport->setScale2D(SCRW,SCRH); // set scale used by props that will be rendered float zoom_rate = 1.0f; Vec2 center(0,0); Camera *camera = new Camera(); camera->setLoc(0,0); Layer *l = new Layer(); moyai_client->insertLayer(l); l->setViewport(viewport); l->setCamera(camera); Texture *t = new Texture(); t->load( "./assets/base.png" ); TileDeck *deck = new TileDeck(); deck->setTexture(t); deck->setSize(32,32,8,8); Prop2D *p=NULL, *pp=NULL; Grid *g=NULL; CharGrid *cg=NULL; // normal single p = new Prop2D(); p->setDeck(deck); p->setIndex(1); p->setScl(64,64); p->setLoc(0,0); l->insertProp(p); #if 0 // with prim pp = new Prop2D(); pp->setScl(1.0f); pp->setLoc(100,0); pp->addRect( Vec2(0,0), Vec2(-100,-100), Color(0,0,1,0.5) ); pp->addLine( Vec2(0,0), Vec2(100,100), Color(1,0,0,1) ); pp->addLine( Vec2(0,0), Vec2(100,-100), Color(0,1,0,1), 5 ); l->insertProp(pp); // grid g = new Grid(4,4); for(int x=0;x<4;x++) { for(int y=0;y<4;y++) { // g->set(x,y,80+((x+y)%10)); g->set(x,y,((x+y)%3)); } } g->setXFlip(0,0,true); g->setYFlip(0,1,true); g->setUVRot(0,2,true); Prop2D *gp = new Prop2D(); gp->setDeck(deck); gp->addGrid(g); gp->setScl(32) ; gp->setLoc(50,0); gp->setRot(20); gp->setIndex(0); l->insertProp(gp); // uvrot Prop2D *rotp = new Prop2D(); rotp->setDeck(deck); rotp->setScl(32); rotp->setLoc(-300,-100); rotp->setUVRot(true); rotp->setIndex(0); l->insertProp(rotp); // chargrid Texture *ft = new Texture(); ft->load("./assets/font_only.png"); TileDeck *fdeck =new TileDeck(); fdeck->setTexture(ft); fdeck->setSize(32,32,8,8); cg = new CharGrid(8,8); cg->ascii_offset = -32; cg->setDeck(fdeck); cg->printf(0,0,Color(1,1,1,1), "WHITE" ); cg->printf(1,1,Color(1,0,0,1), "RED" ); cg->printf(2,2,Color(0,1,0,1), "GREEN" ); cg->printf(3,3,Color(0,0,1,1), "BLUE" ); Prop2D *cgp = new Prop2D(); cgp->addGrid(cg); cgp->setScl(16); cgp->setLoc(50,-100); l->insertProp(cgp); // children Prop2D *chp = new Prop2D(); chp->setLoc(-200,-200); chp->setDeck(deck); chp->setScl(48); chp->setIndex(0); for(int i=0;i<8;i++) { Prop2D *p = new Prop2D(); p->setDeck(deck); p->setLoc( chp->loc + Vec2( (i+1)*30,0 ) ); p->setIndex(0); p->setScl( 36-i*3 ); chp->addChild(p); } Prop2D *dynchp = new Prop2D(); dynchp->setLoc( chp->loc + Vec2(0,-30) ); dynchp->setIndex(0); dynchp->setScl(32); dynchp->setDeck(deck); chp->addChild(dynchp); l->insertProp(chp); #endif #if 0 // text wchar_t charcodes[] = L" !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~あいうえお"; Font *font = new Font(); font->loadFromTTF("./assets/cinecaption227.ttf", charcodes, 24 ); TextBox *tbs[20]; for(int i=0;i<20;i++) { tbs[i] = new TextBox(); tbs[i]->setFont(font); tbs[i]->setString("A"); tbs[i]->setScl(1+(float)i/10.0f); tbs[i]->setLoc(i*10-250,0); l->insertProp(tbs[i]); } TextBox *movtb = new TextBox(); movtb->setFont(font); movtb->setString("ABCabc\n01234あいうえお"); movtb->setScl(3); movtb->setLoc(0,-150); l->insertProp(movtb); // multiple viewport and layer Viewport *vp2 = new Viewport(); // testing multiple viewport scaling vp2->setSize(SCRW*retina,SCRH*retina); vp2->setScale2D(SCRW*2,SCRH*2); Camera *cam2 = new Camera(); Layer *l2 = new Layer(); l2->setViewport(vp2); l2->setCamera(cam2); Prop2D *p2 = new Prop2D(); p2->setDeck(deck); p2->setScl(48,48); p2->setIndex(0); p2->setLoc(200,-200); l2->insertProp(p2); moyai_client->insertLayer(l2); #endif // main loop while( !glfwWindowShouldClose(window) ){ static int frame_counter = 0; static int loop_counter = 0; static double last_t = now(); double t = now(); double dt = t -last_t; last_t = t; double loop_start_at = t; frame_counter ++; loop_counter++; Vec2 at(::sin(t)*100,0); if(p){ p->setLoc(at); if( loop_counter%21==0 ) p->setIndex( irange(0,3)); static float rot=0; rot+=0.05; p->setRot(rot); p->setScl( 40 + ::sin(t/2) * 30 ); if(pp) { pp->setRot(rot/2.0f); } if( loop_counter % 50 == 0 ) { float alpha = range(0.2, 1.0f); Color col(range(0,1),range(0,1),range(0,1),alpha); p->setColor(col); } if( loop_counter % 120 == 0 ) { switch(irange(0,3)) { case 0: p->setXFlip( irange(0,2)); break; case 1: p->setYFlip( irange(0,2)); break; case 2: p->setUVRot( irange(0,2)); break; } } } int cnt = moyai_client->poll(dt); if(g) { g->set( irange(0,4), irange(0,4), irange(0,3) ); g->setColor( irange(0,4), irange(0,4), Color( range(0,1), range(0,1), range(0,1), range(0,1) ) ); } #if 0 float tbr = 4 + ::sin(t)*3; movtb->setScl(tbr); Format fmt("%d", loop_counter); tbs[19]->setString(fmt.buf); #endif // fps disp static double last_print_at = 0; if(last_print_at == 0){ last_print_at = t; } else if( last_print_at < t-1 ){ fprintf(stderr,"FPS:%d prop:%d drawcall:%d\n", frame_counter, cnt, moyai_client->last_draw_call_count ); frame_counter = 0; last_print_at = t; } moyai_client->render(); // print("drawcnt:%d", moyai_client->last_draw_call_count ); if( g_keyboard->getKey( 'Q') ) { print("Q pressed"); exit(0); break; } if( g_keyboard->getKey( 'L' ) ) { zoom_rate += 0.2; if( zoom_rate > 8 ) zoom_rate = 8; } if( g_keyboard->getKey( 'K' ) ) { zoom_rate -= 0.1; if( zoom_rate < 0.1 ) zoom_rate = 0.1; } viewport->setScale2D(SCRW * zoom_rate,SCRH * zoom_rate); float scrollspeed = 10; if( g_keyboard->getKey( 'W' ) ) { center.y -= scrollspeed; } if( g_keyboard->getKey( 'S' ) ) { center.y += scrollspeed; } if( g_keyboard->getKey( 'A' ) ) { center.x += scrollspeed; } if( g_keyboard->getKey( 'D' ) ) { center.x -= scrollspeed; } camera->setLoc(center); if( g_keyboard->getKey( '1' ) ) { for(int i=0;i<50;i++) { Prop *p = new Particle(deck); l->insertProp(p); } } if( g_keyboard->getKey( '2' ) ) { if(cg) cg->printf(0,4, Color(1,1,1,1), Format( "CNT:%d", loop_counter).buf); } #if 0 if( loop_counter % 25 == 0 ) { if( dynchp ) { bool res = chp->clearChild(dynchp); assert(res); delete dynchp; dynchp = NULL; } else { dynchp = new Prop2D(); dynchp->setLoc( chp->loc + Vec2(0,-30) ); dynchp->setIndex(0); dynchp->setScl(32); dynchp->setDeck(deck); chp->addChild(dynchp); } } #endif glfwPollEvents(); double loop_end_at = now(); double loop_time = loop_end_at - loop_start_at; double ideal_frame_time = 1.0f / 60.0f; if(loop_time < ideal_frame_time ) { double to_sleep_sec = ideal_frame_time - loop_time; int to_sleep_msec = (int) (to_sleep_sec*1000); if( to_sleep_msec > 0 ) sleepMilliSec(to_sleep_msec); } } glfwTerminate(); print("program finished"); return 0; }
bool Beam::charPoll( double dt ) { // Shifter tile bends beam Cell *c = g_fld->get(loc); if( c->gt == GT_SHIFTER && c->st == ST_NONE && c->bt == BT_AIR ) { Vec2 dv = dirToVec2(c->dir) * PPC* SHIFTER_ACCEL; v += dv * dt; if( v.len() > BEAM_NORMAL_VEL ) { v = v.normalize(BEAM_NORMAL_VEL); } setRot( atan2(v.y,v.x)); // print("v:%f %f dv:%f %f d:%d",v.x,v.y, dv.x, dv.y, c->dir ); } loc += v * dt; // Stronger is bigger float s = PPC; if( ene >= 64 ) s *= 3; else if( ene >= 16 ) s *= 2; else if( ene >= 4 ) s *= 1.5; setScl(s); // Shoot on blocks Vec2 rt,lt,rb,lb; Cell *rtc = g_fld->get( rt = loc + Vec2(hitsz,hitsz)); Cell *ltc = g_fld->get( lt = loc + Vec2(-hitsz,hitsz)); Cell *rbc = g_fld->get( rb = loc + Vec2(hitsz,-hitsz)); Cell *lbc = g_fld->get( lb = loc + Vec2(-hitsz,-hitsz)); Cell *tgtc = NULL; Vec2 tgtat; Vec2 candat[4]; Cell *cands[4]; int candi=0; // if(rtc&&rtc->isBeamHit() && rtc->isImmutableAgainstBeam()==false ) { cands[candi] = rtc; candat[candi] = rt; candi++; } if(rbc&&rbc->isBeamHit() && rbc->isImmutableAgainstBeam()==false ) { cands[candi] = rbc; candat[candi] = rb; candi++; } if(ltc&<c->isBeamHit() && ltc->isImmutableAgainstBeam()==false ) { cands[candi] = ltc; candat[candi] = lt; candi++; } if(lbc&&lbc->isBeamHit() && lbc->isImmutableAgainstBeam()==false ) { cands[candi] = lbc; candat[candi] = lb; candi++; } if( candi > 0 ) { int ind = irange(0,candi); tgtc = cands[ind]; tgtat = candat[ind]; } // Out of the world if(!rtc)return false; if( rtc && rtc->gt == GT_JUNGLE && range(0,100) < 1 ) { createLeafEffect(loc); } updateIndex(); if( isRemote() ) return true; if(tgtc) { int consumed; BLOCKTYPE orig_bt = tgtc->bt; if( g_fld->damage(tgtat,ene,&consumed,this) ) { createSparkEffect(); if( orig_bt == BT_CELL || orig_bt == BT_FLYGEN ) { soundPlayAt(g_wormdamage_sound,loc,1); } else if( orig_bt != BT_SNOW && orig_bt != BT_IVY && orig_bt != BT_TREE && orig_bt != BT_BOMBFLOWER ) { soundPlayAt(g_beamhithard_sound,loc,1); } if( orig_bt == BT_BARRIER && tgtc->hyper_count > 0 ) { Vec2 tgt; if( g_fld->findEnemyAttackTarget(loc,&tgt, MACHINE_SHOOT_DISTANCE ) ) { int n = irange(1,4); for(int i=0;i<n;i++) Bullet::shootAt( BLT_SPARIO, loc, tgt ); } } ene -= consumed; if( ene <= 0 ) return false; else return true; } } else { // Immutable cells Cell *cells[4]; g_fld->getCorner4( loc, 1, &cells[0], &cells[1], &cells[2], &cells[3] ); for(int i=0;i<4;i++) { if(cells[i] && cells[i]->isImmutableAgainstBeam()) { soundPlayAt(g_beamhithard_sound,loc,1); createSparkEffect(); return false; } } } if( type == BEAMTYPE_BLASTER ) { float s = PPC; g_fld->meltSnow(loc + Vec2(-s,-s) ); g_fld->meltSnow(loc + Vec2(-s,s) ); g_fld->meltSnow(loc + Vec2(s,-s) ); g_fld->meltSnow(loc + Vec2(s,s) ); } else { if( range(0,100) < (float)(ene)/2.0 ) { g_fld->meltSnow(loc); } } // Shoot on enemies Char *cur = (Char*) g_char_layer->prop_top; while(cur) { if( cur->isEnemyCategory() ) { Enemy *e = (Enemy*) cur; if( e->hitWithFlyHeight(this,PPC/2) && e->beam_hits ) { int dmg = ene; if( dmg > e->hp ) dmg = e->hp; e->notifyHitBeam(this, dmg); createSparkEffect(); // ene -= dmg; if(ene<=0) to_clean = true; g_fld->meltSnow(loc); } } else if( cur->category == CAT_PC ) { // recharging other player characters PC *pc = (PC*) cur; if( pc->hit(this,PPC/2)) { // print("pcid:%d shooter:%d ene:%d/%d", pc->id, shooter_id, pc->ene, pc->maxene ); if( pc->id != shooter_id && shooter_id == g_pc->id ) { // print("PC:E:%d id:%d max:%d", pc->ene, pc->id, pc->maxene ); int charged = pc->charge(ene); if(charged>0) { pc->energy_chain_heat_count ++; // print("sending E-chain e:%d(%d>%d) to: %d-%d heat:%d", // ene, charged, pc->ene, pc->client_id, pc->internal_id ,pc->energy_chain_heat_count ); realtimeEnergyChainSend(pc,charged); return false; } } } } cur = (Char*) cur->next; } return true; }
EdgeRange GetAdjacentEdgeRange(const NodeID node) const { return irange(BeginEdges(node), EndEdges(node)); }
static DF1(jtfindrange){I base,n,top; RZ(w); n=AN(w); irange(n,AV(w),&base,&top); R v2(base,top); }
void FontRendererImpl::DrawText(const std::string& text, const Rect& rect, const RGBA& color, float fontSize, float fontScale, const std::string& fontRef) { // wait for a swap to complete FrpSeqAllocatorWaitForSwap(); m_mutex.lock(); // create or find a text format ComPtr<IDWriteTextFormat> textFormat; auto formatKey = std::make_pair(fontRef, fontSize); auto formatIter = m_textFormatCache.find(formatKey); if (formatIter != m_textFormatCache.end()) { textFormat = formatIter->second; } else { m_dwFactory->CreateTextFormat(ToWide(fontRef).c_str(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", textFormat.GetAddressOf()); m_textFormatCache[formatKey] = textFormat; } // create or find a cached text layout ComPtr<IDWriteTextLayout> textLayout; auto layoutKey = std::make_pair(textFormat.Get(), std::make_pair(color.AsARGB(), text)); auto layoutIter = m_textLayoutCache.find(layoutKey); if (layoutIter != m_textLayoutCache.end()) { textLayout = layoutIter->second; } else { std::wstring wideText = ToWide(text); // parse colors and the lot std::wstring noColorTextString; std::vector<DWRITE_TEXT_RANGE> textRanges; std::vector<RGBA> textColors; { std::wstringstream noColorText; int count = 0; static const RGBA colors[] = { RGBA(0, 0, 0), RGBA(255, 0, 0), RGBA(0, 255, 0), RGBA(255, 255, 0), RGBA(0, 0, 255), RGBA(0, 255, 255), RGBA(255, 0, 255), RGBA(255, 255, 255), RGBA(100, 0, 0), RGBA(0, 0, 100) }; textRanges.reserve(50); textColors.reserve(50); textRanges.push_back({ 0, UINT32_MAX }); textColors.push_back(color); for (int i = 0; i < wideText.length(); i++) { if (wideText[i] == '^' && (i + 1) < wideText.length() && isdigit(wideText[i + 1])) { textRanges.back().length = count - textRanges.back().startPosition; textRanges.push_back({ (UINT32)count, UINT32_MAX }); textColors.push_back(colors[wideText[i + 1] - '0']); ++i; continue; } noColorText << wideText[i]; ++count; } textRanges.back().length = count - textRanges.back().startPosition; noColorTextString = noColorText.str(); } m_dwFactory->CreateTextLayout(noColorTextString.c_str(), static_cast<UINT32>(noColorTextString.length()), textFormat.Get(), rect.Width(), rect.Height(), textLayout.GetAddressOf()); m_textLayoutCache[layoutKey] = textLayout; // set effect for (size_t i : irange(textRanges.size())) { DWRITE_TEXT_RANGE effectRange = textRanges[i]; RGBA color = textColors[i]; static thread_local std::map<uint32_t, ComPtr<FrDrawingEffect>> effects; auto it = effects.find(color.AsARGB()); if (it == effects.end()) { ComPtr<FrDrawingEffect> effect = Make<FrDrawingEffect>(); effect->SetColor(textColors[i]); it = effects.insert({ color.AsARGB(), effect }).first; } check(SUCCEEDED(textLayout->SetDrawingEffect((IUnknown*)it->second.Get(), effectRange))); } } // draw auto drawingContext = new FrDrawingContext(); textLayout->Draw(drawingContext, m_textRenderer.Get(), rect.Left(), rect.Top()); auto numRuns = drawingContext->glyphRuns.size(); if (numRuns) { for (auto& run : drawingContext->glyphRuns) { m_queuedRenderables.push_back(std::make_unique<FrGlyphRunRenderable>(run)); //m_queuedGlyphRuns.push_back(run); } } delete drawingContext; m_mutex.unlock(); }